The Battle for Wesnoth  1.15.3+dev
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 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, const 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 () 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 sent to the clients. More...
 
bool persistent_
 If true, keep this menu item in later scenarios. More...
 

Detailed Description

Definition at line 31 of file menu_item.hpp.

Constructor & Destructor Documentation

◆ wml_menu_item() [1/3]

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 68 of file menu_item.cpp.

References deprecated_message(), config::has_attribute(), and INDEFINITE.

◆ wml_menu_item() [2/3]

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).

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

Definition at line 90 of file menu_item.cpp.

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

◆ wml_menu_item() [3/3]

game_events::wml_menu_item::wml_menu_item ( const std::string &  id,
const vconfig definition,
const 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.)

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 115 of file menu_item.cpp.

References update().

Member Function Documentation

◆ can_show()

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.

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

Definition at line 142 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 hotkey_repeat().

◆ finish_handler()

void game_events::wml_menu_item::finish_handler ( ) const

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

Definition at line 191 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_.

Referenced by hotkey_repeat().

◆ fire_event()

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.

Parameters
[in]event_hexThe location of the event (where the menu was opened).
[in]dataThe game data for the most recent "select" event.

Definition at line 163 of file menu_item.cpp.

References event_name_, game_events::wml_event_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 hotkey_repeat().

◆ hotkey_repeat()

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

If true, holding the hotkey will trigger this item repeatedly.

Definition at line 79 of file menu_item.hpp.

References can_show(), default_hotkey_, finish_handler(), fire_event(), and init_handler().

◆ id()

const std::string& game_events::wml_menu_item::id ( ) const
inline

The id of this item.

Definition at line 61 of file menu_item.hpp.

References image(), and item_id_.

◆ image()

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 135 of file menu_item.cpp.

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

Referenced by id().

◆ init_handler()

void game_events::wml_menu_item::init_handler ( ) const

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

Definition at line 204 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_.

Referenced by hotkey_repeat().

◆ is_synced()

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

Definition at line 125 of file menu_item.hpp.

References is_synced_, update(), and update_command().

Referenced by fire_event().

◆ menu_text()

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 112 of file menu_item.hpp.

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

◆ to_config()

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 218 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_.

Referenced by menu_text().

◆ update()

void game_events::wml_menu_item::update ( const vconfig vcfg)
private

◆ update_command()

void game_events::wml_menu_item::update_command ( const config new_command)
private

◆ use_wml_menu()

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

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

Definition at line 73 of file menu_item.hpp.

References use_wml_menu_.

Member Data Documentation

◆ command_

config game_events::wml_menu_item::command_
private

Actions to take when this item is chosen.

Definition at line 176 of file menu_item.hpp.

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

◆ default_hotkey_

config game_events::wml_menu_item::default_hotkey_
private

Config object containing the default hotkey.

Definition at line 179 of file menu_item.hpp.

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

◆ description_

t_string game_events::wml_menu_item::description_
private

The text to display in the menu for this item.

Definition at line 154 of file menu_item.hpp.

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

◆ event_name_

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 145 of file menu_item.hpp.

Referenced by fire_event(), and update_command().

◆ filter_location_

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.)

When used, we need a vconfig instead of a config.

Definition at line 173 of file menu_item.hpp.

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

◆ hotkey_id_

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 148 of file menu_item.hpp.

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

◆ image_

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 151 of file menu_item.hpp.

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

◆ is_synced_

bool game_events::wml_menu_item::is_synced_
private

If true, this item will be sent to the clients.

The command shall not change the gamestate if !is_synced_

Definition at line 191 of file menu_item.hpp.

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

◆ item_id_

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

The id of this menu item.

Definition at line 142 of file menu_item.hpp.

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

◆ needs_select_

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 157 of file menu_item.hpp.

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

◆ persistent_

bool game_events::wml_menu_item::persistent_
private

If true, keep this menu item in later scenarios.

Definition at line 194 of file menu_item.hpp.

Referenced by update().

◆ show_if_

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.)

When used, we need a vconfig instead of a config.

Definition at line 165 of file menu_item.hpp.

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

◆ use_hotkey_

bool game_events::wml_menu_item::use_hotkey_
private

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

Definition at line 182 of file menu_item.hpp.

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

◆ use_wml_menu_

bool game_events::wml_menu_item::use_wml_menu_
private

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

Definition at line 185 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: