#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::string & | id () const |
The id of this item. More... | |
const std::string & | image () 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... | |
Definition at line 35 of file menu_item.hpp.
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).
[in] | id | The id of the menu item. |
[in] | definition | The 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.)
[in] | id | The id of the menu item. |
[in] | definition | The WML defining this menu item. |
[in] | original | The previous version of the menu item with this id. |
Definition at line 138 of file menu_item.cpp.
References update().
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.
[in] | hex | The 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 |
Causes the event associated with this item to fire.
Definition at line 203 of file menu_item.cpp.
References event_name_, game_events::t_pump::fire(), resources::game_events, replay_helper::get_event(), is_synced(), game_data::last_selected, needs_select_, game_events::manager::pump(), synced_context::run_and_throw(), synced_context::run_in_synced_context_if_not_already(), and map_location::valid().
Referenced by game_events::wmi_container::fire_item().
|
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_.
|
inline |
|
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_.
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_.
Updates *this based on vcfg.
This corresponds to what can appear in [set_menu_item].
Definition at line 300 of file menu_item.cpp.
References hotkey::add_wml_hotkey(), vconfig::child(), default_hotkey_, description_, filter_location_, vconfig::has_attribute(), hotkey_id_, image_, is_synced_, vconfig::make_safe(), needs_select_, hotkey::remove_wml_hotkey(), show_if_, config::attribute_value::str(), config::attribute_value::to_bool(), update_command(), use_hotkey_, and use_wml_menu_.
Referenced by wml_menu_item().
Updates our command to new_command.
Definition at line 365 of file menu_item.cpp.
References game_events::manager::add_event_handler(), config::clear(), command_, config::attribute_value::empty(), config::empty(), event_name_, resources::game_events, item_id_, LOG_NG, and game_events::manager::remove_event_handler().
Referenced by update().
|
inline |
If true, allow using the menu to trigger this item.
Definition at line 51 of file menu_item.hpp.
References use_wml_menu_.
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
private |
The id of this menu item.
Definition at line 76 of file menu_item.hpp.
Referenced by id(), to_config(), and update_command().
|
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().
|
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().
|
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().
|
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().