The Battle for Wesnoth  1.19.7+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, 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_recordhotkey_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...
 

Detailed Description

Definition at line 36 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 70 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 93 of file menu_item.cpp.

References default_hotkey_, description_, hotkey_id_, hotkey_record_, and update().

◆ wml_menu_item() [3/3]

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

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 119 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.
[in]dataUsed to check whether to show if selecting is required.
[in]contextUsed 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_.

◆ finish_handler()

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

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

◆ hotkey_id()

std::string game_events::wml_menu_item::hotkey_id ( ) const
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_.

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

References default_hotkey_.

◆ id()

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

The id of this item.

Definition at line 66 of file menu_item.hpp.

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

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

◆ init_handler()

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

◆ is_synced()

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

Definition at line 139 of file menu_item.hpp.

References is_synced_.

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.

Definition at line 118 of file menu_item.hpp.

References description_, and t_string::str().

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

◆ 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 78 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 193 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 196 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 171 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 159 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 190 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 162 of file menu_item.hpp.

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

◆ hotkey_record_

utils::optional<hotkey::wml_hotkey_record> game_events::wml_menu_item::hotkey_record_
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().

◆ 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 168 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 208 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 156 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 174 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 211 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 182 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 199 of file menu_item.hpp.

Referenced by finish_handler(), init_handler(), 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 202 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: