#include <menu_item.hpp>
Public Member Functions | |
wml_menu_item (const std::string &id, const config &cfg) | |
Constructor for reading from a saved config. More... | |
wml_menu_item (const std::string &id, const vconfig &definition) | |
Constructor for items defined in an event. More... | |
wml_menu_item (const std::string &id, const vconfig &definition, wml_menu_item &original) | |
Constructor for items 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 | hotkey_repeat () const |
If true, holding the hotkey will trigger this item repeatedly. 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 () |
Removes the implicit event handler for an inlined [command]. More... | |
void | init_handler (game_lua_kernel &lk) |
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... | |
std::string | hotkey_id () const |
The UI action id to be used in theme wml, menu items and hotkeys . 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... | |
utils::optional< hotkey::wml_hotkey_record > | hotkey_record_ |
Controls the lifetime of the associate hotkey's hotkey_command. 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 sent to the clients. More... | |
bool | persistent_ |
If true, keep this menu item in later scenarios. More... | |
Definition at line 36 of file menu_item.hpp.
game_events::wml_menu_item::wml_menu_item | ( | const std::string & | id, |
const config & | cfg | ||
) |
Constructor for reading from a saved config.
This is the reverse of to_config() and corresponds to reading [menu_item]. Handlers are not initialized.
Definition at line 70 of file menu_item.cpp.
References deprecated_message(), config::has_attribute(), and INDEFINITE.
game_events::wml_menu_item::wml_menu_item | ( | const std::string & | id, |
const vconfig & | definition | ||
) |
Constructor for items 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 93 of file menu_item.cpp.
References default_hotkey_, description_, hotkey_id_, hotkey_record_, and update().
game_events::wml_menu_item::wml_menu_item | ( | const std::string & | id, |
const vconfig & | definition, | ||
wml_menu_item & | original | ||
) |
Constructor for items 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 119 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 & | context | ||
) | 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. |
[in] | data | Used to check whether to show if selecting is required. |
[in] | context | Used to check whether the menu's filter matches. |
Definition at line 147 of file menu_item.cpp.
References game_events::conditional_passed(), data, vconfig::empty(), resources::filter_con, filter_location_, needs_select_, and show_if_.
void game_events::wml_menu_item::finish_handler | ( | ) |
Removes the implicit event handler for an inlined [command].
Definition at line 196 of file menu_item.cpp.
References command_, config::empty(), resources::game_events, hotkey_record_, game_events::manager::remove_event_handler(), 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.
Also records the event. This includes recording the previous select event, if applicable. The undo stack will be cleared if the event mutated the gamestate.
[in] | event_hex | The location of the event (where the menu was opened). |
[in] | data | The game data for the most recent "select" event. |
Definition at line 168 of file menu_item.cpp.
References data, event_name_, game_events::wml_event_pump::fire(), resources::game_events, replay_helper::get_event(), is_synced(), needs_select_, game_events::manager::pump(), synced_context::run_and_throw(), synced_context::run_in_synced_context_if_not_already(), and map_location::valid().
|
inline |
The UI action id to be used in theme wml, menu items and hotkeys .
Definition at line 126 of file menu_item.hpp.
References hotkey_id_.
|
inline |
If true, holding the hotkey will trigger this item repeatedly.
Definition at line 84 of file menu_item.hpp.
References default_hotkey_.
|
inline |
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 140 of file menu_item.cpp.
References image_, and game_config::images::wml_menu.
void game_events::wml_menu_item::init_handler | ( | game_lua_kernel & | lk | ) |
Initializes the implicit event handler for an inlined [command].
Definition at line 209 of file menu_item.cpp.
References game_events::manager::add_event_handler_from_wml(), command_, default_hotkey_, description_, config::empty(), resources::game_events, hotkey_id_, hotkey_record_, and use_hotkey_.
|
inline |
|
inline |
The text to put in a menu for this item.
Definition at line 118 of file menu_item.hpp.
References description_, and t_string::str().
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 223 of file menu_item.cpp.
References config::add_child(), command_, default_hotkey_, description_, config::empty(), vconfig::empty(), ERR_NG, filter_location_, vconfig::get_config(), image_, is_synced_, item_id_, needs_select_, show_if_, use_hotkey_, and use_wml_menu_.
|
private |
Updates *this based on vcfg.
This corresponds to what can appear in [set_menu_item].
Definition at line 269 of file menu_item.cpp.
References vconfig::child(), default_hotkey_, deprecated_message(), description_, filter_location_, vconfig::has_attribute(), hotkey_id_, hotkey_record_, image_, INDEFINITE, is_synced_, vconfig::make_safe(), needs_select_, persistent_, show_if_, config_attribute_value::str(), config_attribute_value::to_bool(), update_command(), use_hotkey_, and use_wml_menu_.
Referenced by wml_menu_item().
|
private |
Updates our command to new_command.
Definition at line 340 of file menu_item.cpp.
References game_events::manager::add_event_handler_from_wml(), config::clear(), command_, config::empty(), config_attribute_value::empty(), event_name_, game_events::manager::execute_on_events(), resources::game_events, item_id_, LOG_NG, and resources::lua_kernel.
Referenced by update().
|
inline |
If true, allow using the menu to trigger this item.
Definition at line 78 of file menu_item.hpp.
References use_wml_menu_.
|
private |
Actions to take when this item is chosen.
Definition at line 193 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 196 of file menu_item.hpp.
Referenced by hotkey_repeat(), init_handler(), to_config(), update(), and wml_menu_item().
|
private |
The text to display in the menu for this item.
Definition at line 171 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 159 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.)
When used, we need a vconfig instead of a config.
Definition at line 190 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 162 of file menu_item.hpp.
Referenced by hotkey_id(), init_handler(), update(), and wml_menu_item().
|
private |
Controls the lifetime of the associate hotkey's hotkey_command.
Definition at line 165 of file menu_item.hpp.
Referenced by finish_handler(), init_handler(), update(), and wml_menu_item().
|
private |
The image to display in the menu next to this item's description.
Definition at line 168 of file menu_item.hpp.
Referenced by image(), to_config(), and update().
|
private |
If true, this item will be sent to the clients.
The command shall not change the gamestate if !is_synced_
Definition at line 208 of file menu_item.hpp.
Referenced by is_synced(), to_config(), and update().
|
private |
The id of this menu item.
Definition at line 156 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 174 of file menu_item.hpp.
Referenced by can_show(), fire_event(), to_config(), and update().
|
private |
If true, keep this menu item in later scenarios.
Definition at line 211 of file menu_item.hpp.
Referenced by update().
|
private |
A condition that must hold in order for this menu item to be visible.
(An empty condition always holds.)
When used, we need a vconfig instead of a config.
Definition at line 182 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 199 of file menu_item.hpp.
Referenced by finish_handler(), init_handler(), to_config(), and update().
|
private |
If true, allow using the menu to trigger this item.
Definition at line 202 of file menu_item.hpp.
Referenced by to_config(), update(), and use_wml_menu().