The Battle for Wesnoth  1.19.5+dev
Public Types | Public Member Functions | Private Attributes | List of all members
game_events::wmi_manager Class Reference

#include <wmi_manager.hpp>

Public Types

using item_ptr = std::shared_ptr< wml_menu_item >
 wml_menu_item pointers More...
 

Public Member Functions

 wmi_manager ()
 
 ~wmi_manager ()
 Destructor. More...
 
bool empty () const
 Returns true if no menu items are being managed. More...
 
bool erase (const std::string &id)
 Erases the item with the provided id. More...
 
bool fire_item (const std::string &id, const map_location &hex, game_data &gamedata, filter_context &fc, unit_map &units, bool is_key_hold_repeat=false) const
 Fires the menu item with the given id. More...
 
item_ptr get_item (const std::string &id) const
 Gets the menu item with the specified ID. More...
 
void get_items (const map_location &hex, std::vector< config > &items, filter_context &fc, game_data &gamedata, unit_map &units) const
 Returns the menu items that can be shown for the given location. More...
 
void init_handlers (game_lua_kernel &lk) const
 Initializes the implicit event handlers for inlined [command]s. More...
 
void to_config (config &cfg) const
 
void set_item (const std::string &id, const vconfig &menu_item)
 Updates or creates (as appropriate) the menu item with the given id. More...
 
void set_menu_items (const config &cfg)
 Sets the current menu items to the "menu_item" children of cfg. More...
 
std::size_t size () const
 Gets the number of menu items owned. More...
 

Private Attributes

std::map< std::string, item_ptrwml_menu_items_
 

Detailed Description

Definition at line 40 of file wmi_manager.hpp.

Member Typedef Documentation

◆ item_ptr

wml_menu_item pointers

Definition at line 44 of file wmi_manager.hpp.

Constructor & Destructor Documentation

◆ wmi_manager()

game_events::wmi_manager::wmi_manager ( )

Definition at line 38 of file wmi_manager.cpp.

◆ ~wmi_manager()

game_events::wmi_manager::~wmi_manager ( )

Destructor.

Default implementation, but defined here because this function needs to be able to see wml_menu_item's destructor.

Definition at line 48 of file wmi_manager.cpp.

Member Function Documentation

◆ empty()

bool game_events::wmi_manager::empty ( ) const
inline

Returns true if no menu items are being managed.

Definition at line 50 of file wmi_manager.hpp.

References wml_menu_items_.

Referenced by get_items().

◆ erase()

bool game_events::wmi_manager::erase ( const std::string &  id)

Erases the item with the provided id.

Erases the item with id key.

Definition at line 53 of file wmi_manager.cpp.

References wml_menu_items_, and WRN_NG.

Referenced by game_lua_kernel::intf_clear_menu_item().

◆ fire_item()

bool game_events::wmi_manager::fire_item ( const std::string &  id,
const map_location hex,
game_data gamedata,
filter_context fc,
unit_map units,
bool  is_key_hold_repeat = false 
) const

Fires the menu item with the given id.

Returns
true if a matching item was found (even if it could not be fired). NOTE: The return value could be altered if it is decided that play_controller::execute_command() needs something different.

Definition at line 79 of file wmi_manager.cpp.

References gamedata, get_item(), map_location::wml_x(), and map_location::wml_y().

Referenced by play_controller::hotkey_handler::do_execute_command(), and game_lua_kernel::intf_fire_wml_menu_item().

◆ get_item()

wmi_manager::item_ptr game_events::wmi_manager::get_item ( const std::string &  id) const

Gets the menu item with the specified ID.

Parameters
idItem id.
Returns
Pointer to the relevant item, or nullptr if not found.

Definition at line 150 of file wmi_manager.cpp.

References wml_menu_items_.

Referenced by playsingle_controller::hotkey_handler::can_execute_command(), and fire_item().

◆ get_items()

void game_events::wmi_manager::get_items ( const map_location hex,
std::vector< config > &  items,
filter_context fc,
game_data gamedata,
unit_map units 
) const

Returns the menu items that can be shown for the given location.

Parameters
hexThe current hex.
[out]itemsMenu items. consisting of menu text, menu icons, and action ids.
fcUsed to check whether the menu's filter matches.
gamedataUsed to check whether to show if selecting is required.
unitsUsed to highlight a unit if needed.

Definition at line 115 of file wmi_manager.cpp.

References play_controller::can_use_synced_wml_menu(), resources::controller, empty(), gamedata, wml_menu_items_, map_location::wml_x(), and map_location::wml_y().

Referenced by play_controller::hotkey_handler::expand_wml_commands().

◆ init_handlers()

void game_events::wmi_manager::init_handlers ( game_lua_kernel lk) const

Initializes the implicit event handlers for inlined [command]s.

Definition at line 163 of file wmi_manager.cpp.

References LOG_NG, and wml_menu_items_.

Referenced by game_events::manager::read_scenario().

◆ set_item()

void game_events::wmi_manager::set_item ( const std::string &  id,
const vconfig menu_item 
)

Updates or creates (as appropriate) the menu item with the given id.

Definition at line 203 of file wmi_manager.cpp.

References wml_menu_items_.

Referenced by game_lua_kernel::intf_set_menu_item().

◆ set_menu_items()

void game_events::wmi_manager::set_menu_items ( const config cfg)

Sets the current menu items to the "menu_item" children of cfg.

Definition at line 219 of file wmi_manager.cpp.

References config::child_range(), wml_menu_items_, and WRN_NG.

Referenced by game_events::manager::read_scenario().

◆ size()

std::size_t game_events::wmi_manager::size ( ) const
inline

Gets the number of menu items owned.

Definition at line 93 of file wmi_manager.hpp.

References wml_menu_items_.

◆ to_config()

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

Definition at line 191 of file wmi_manager.cpp.

References config::add_child(), and wml_menu_items_.

Referenced by game_events::manager::write_events().

Member Data Documentation

◆ wml_menu_items_

std::map<std::string, item_ptr> game_events::wmi_manager::wml_menu_items_
private

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