The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
game_events::wml_menu_item Class Reference

#include <menu_item.hpp>

Public Member Functions

 wml_menu_item (const std::string &id, const config &cfg)
 Constructor for when read from a saved config. More...
 
 wml_menu_item (const std::string &id, const vconfig &definition)
 Constructor for when defined in an event. More...
 
 wml_menu_item (const std::string &id, const vconfig &definition, const wml_menu_item &original)
 Constructor for when modified by an event. More...
 
const std::stringid () const
 The id of this item. More...
 
const std::stringimage () const
 The image associated with this menu item. More...
 
bool use_wml_menu () const
 If true, allow using the menu to trigger this item. More...
 
bool can_show (const map_location &hex, const game_data &data, filter_context &context) const
 Returns whether or not *this is applicable given the context. More...
 
void fire_event (const map_location &event_hex, const game_data &data) const
 Causes the event associated with this item to fire. More...
 
void finish_handler () const
 Removes the implicit event handler for an inlined [command]. More...
 
void init_handler () const
 Initializes the implicit event handler for an inlined [command]. More...
 
std::string menu_text () const
 The text to put in a menu for this item. More...
 
void to_config (config &cfg) const
 Writes *this to the provided config. More...
 
bool is_synced () const
 

Private Member Functions

void update (const vconfig &vcfg)
 Updates *this based on vcfg. More...
 
void update_command (const config &new_command)
 Updates our command to new_command. More...
 

Private Attributes

const std::string item_id_
 The id of this menu item. More...
 
const std::string event_name_
 The name of this item's event(s); based on the item's id. More...
 
const std::string hotkey_id_
 The id for this item's hotkey; based on the item's id. More...
 
std::string image_
 The image to display in the menu next to this item's description. More...
 
t_string description_
 The text to display in the menu for this item. More...
 
bool needs_select_
 Whether or not this event says it makes use of the last selected unit. More...
 
vconfig show_if_
 A condition that must hold in order for this menu item to be visible. More...
 
vconfig filter_location_
 A location filter to be applied to the hex where the menu is invoked. More...
 
config command_
 Actions to take when this item is chosen. More...
 
config default_hotkey_
 Config object containing the default hotkey. More...
 
bool use_hotkey_
 If true, allow using a hotkey to trigger this item. More...
 
bool use_wml_menu_
 If true, allow using the menu to trigger this item. More...
 
bool is_synced_
 If true, this item will be sended ot ther clients. More...
 

Detailed Description

Definition at line 35 of file menu_item.hpp.

Constructor & Destructor Documentation

game_events::wml_menu_item::wml_menu_item ( const std::string id,
const config cfg 
)

Constructor for when read from a saved config.

This is the reverse of to_config() and corresponds to reading [menu_item]. Handlers are not initialized.

Definition at line 83 of file menu_item.cpp.

game_events::wml_menu_item::wml_menu_item ( const std::string id,
const vconfig definition 
)

Constructor for when defined in an event.

This is where default values are defined (the other constructors should have all values to work with).

Parameters
[in]idThe id of the menu item.
[in]definitionThe WML defining this menu item.

Definition at line 107 of file menu_item.cpp.

References hotkey::add_wml_hotkey(), default_hotkey_, description_, hotkey_id_, and update().

game_events::wml_menu_item::wml_menu_item ( const std::string id,
const vconfig definition,
const wml_menu_item original 
)

Constructor for when modified by an event.

(To avoid problems with a menu item's command changing itself, we make a new menu item instead of modifying the existing one.)

Parameters
[in]idThe id of the menu item.
[in]definitionThe WML defining this menu item.
[in]originalThe previous version of the menu item with this id.

Definition at line 138 of file menu_item.cpp.

References update().

Member Function Documentation

bool game_events::wml_menu_item::can_show ( const map_location hex,
const game_data data,
filter_context filter_con 
) const

Returns whether or not *this is applicable given the context.

Assumes game variables x1, y1, and unit have been set.

Parameters
[in]hexThe hex where the menu will appear.

Definition at line 174 of file menu_item.cpp.

References game_events::conditional_passed(), vconfig::empty(), filter_location_, game_data::last_selected, needs_select_, show_if_, and map_location::valid().

Referenced by game_events::wmi_container::fire_item().

void game_events::wml_menu_item::finish_handler ( ) const

Removes the implicit event handler for an inlined [command].

Definition at line 233 of file menu_item.cpp.

References command_, config::empty(), resources::game_events, hotkey_id_, game_events::manager::remove_event_handler(), hotkey::remove_wml_hotkey(), and use_hotkey_.

void game_events::wml_menu_item::fire_event ( const map_location event_hex,
const game_data data 
) const
const std::string& game_events::wml_menu_item::id ( ) const
inline

The id of this item.

Definition at line 47 of file menu_item.hpp.

References item_id_.

Referenced by wmi_pager::capture().

const std::string & game_events::wml_menu_item::image ( ) const

The image associated with this menu item.

The returned string will not be empty; a default will be supplied if needed.

Definition at line 163 of file menu_item.cpp.

References image_, and game_config::images::wml_menu.

void game_events::wml_menu_item::init_handler ( ) const

Initializes the implicit event handler for an inlined [command].

Definition at line 248 of file menu_item.cpp.

References game_events::manager::add_event_handler(), hotkey::add_wml_hotkey(), command_, default_hotkey_, description_, config::empty(), resources::game_events, hotkey_id_, and use_hotkey_.

bool game_events::wml_menu_item::is_synced ( ) const
inline

Definition at line 67 of file menu_item.hpp.

References is_synced_.

Referenced by fire_event().

std::string game_events::wml_menu_item::menu_text ( ) const
inline

The text to put in a menu for this item.

This will be either translated text or a hotkey identifier.

Definition at line 63 of file menu_item.hpp.

References description_, hotkey_id_, t_string::str(), and use_hotkey_.

void game_events::wml_menu_item::to_config ( config cfg) const

Writes *this to the provided config.

This is the reverse of the constructor from a config and corresponds to what will appear in [menu_item].

Definition at line 267 of file menu_item.cpp.

References config::add_child(), command_, default_hotkey_, description_, vconfig::empty(), config::empty(), ERR_NG, filter_location_, vconfig::get_config(), image_, is_synced_, item_id_, needs_select_, show_if_, use_hotkey_, and use_wml_menu_.

void game_events::wml_menu_item::update ( const vconfig vcfg)
private
void game_events::wml_menu_item::update_command ( const config new_command)
private
bool game_events::wml_menu_item::use_wml_menu ( ) const
inline

If true, allow using the menu to trigger this item.

Definition at line 51 of file menu_item.hpp.

References use_wml_menu_.

Member Data Documentation

config game_events::wml_menu_item::command_
private

Actions to take when this item is chosen.

Definition at line 94 of file menu_item.hpp.

Referenced by finish_handler(), init_handler(), to_config(), and update_command().

config game_events::wml_menu_item::default_hotkey_
private

Config object containing the default hotkey.

Definition at line 96 of file menu_item.hpp.

Referenced by init_handler(), to_config(), update(), and wml_menu_item().

t_string game_events::wml_menu_item::description_
private

The text to display in the menu for this item.

Definition at line 84 of file menu_item.hpp.

Referenced by init_handler(), menu_text(), to_config(), update(), and wml_menu_item().

const std::string game_events::wml_menu_item::event_name_
private

The name of this item's event(s); based on the item's id.

Definition at line 78 of file menu_item.hpp.

Referenced by fire_event(), and update_command().

vconfig game_events::wml_menu_item::filter_location_
private

A location filter to be applied to the hex where the menu is invoked.

(An empty filter always passes.)

Definition at line 92 of file menu_item.hpp.

Referenced by can_show(), to_config(), and update().

const std::string game_events::wml_menu_item::hotkey_id_
private

The id for this item's hotkey; based on the item's id.

Definition at line 80 of file menu_item.hpp.

Referenced by finish_handler(), init_handler(), menu_text(), update(), and wml_menu_item().

std::string game_events::wml_menu_item::image_
private

The image to display in the menu next to this item's description.

Definition at line 82 of file menu_item.hpp.

Referenced by image(), to_config(), and update().

bool game_events::wml_menu_item::is_synced_
private

If true, this item will be sended ot ther clients.

The command shall not change the gamestate if !is_synced_

Definition at line 103 of file menu_item.hpp.

Referenced by is_synced(), to_config(), and update().

const std::string game_events::wml_menu_item::item_id_
private

The id of this menu item.

Definition at line 76 of file menu_item.hpp.

Referenced by id(), to_config(), and update_command().

bool game_events::wml_menu_item::needs_select_
private

Whether or not this event says it makes use of the last selected unit.

Definition at line 86 of file menu_item.hpp.

Referenced by can_show(), fire_event(), to_config(), and update().

vconfig game_events::wml_menu_item::show_if_
private

A condition that must hold in order for this menu item to be visible.

(An empty condition always holds.)

Definition at line 89 of file menu_item.hpp.

Referenced by can_show(), to_config(), and update().

bool game_events::wml_menu_item::use_hotkey_
private

If true, allow using a hotkey to trigger this item.

Definition at line 98 of file menu_item.hpp.

Referenced by finish_handler(), init_handler(), menu_text(), to_config(), and update().

bool game_events::wml_menu_item::use_wml_menu_
private

If true, allow using the menu to trigger this item.

Definition at line 100 of file menu_item.hpp.

Referenced by to_config(), update(), and use_wml_menu().


The documentation for this class was generated from the following files: