The Battle for Wesnoth  1.15.2+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< std::shared_ptr< const wml_menu_item >> &items, std::vector< config > &descriptions, 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 () 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 38 of file wmi_manager.hpp.

Member Typedef Documentation

◆ item_ptr

wml_menu_item pointers

Definition at line 42 of file wmi_manager.hpp.

Constructor & Destructor Documentation

◆ wmi_manager()

game_events::wmi_manager::wmi_manager ( )

Definition at line 37 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 47 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 48 of file wmi_manager.hpp.

References erase(), fire_item(), resources::gamedata, get_item(), get_items(), init_handlers(), mp_ui_alerts::items, set_item(), set_menu_items(), to_config(), and 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 52 of file wmi_manager.cpp.

References wml_menu_items_, and WRN_NG.

Referenced by empty().

◆ 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 78 of file wmi_manager.cpp.

References get_item(), game_data::get_variable(), map_location::wml_x(), and map_location::wml_y().

Referenced by play_controller::hotkey_handler::do_execute_command(), and empty().

◆ 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 138 of file wmi_manager.cpp.

References wml_menu_items_.

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

◆ get_items()

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

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

Parameters
[out]itemsPointers to applicable menu items will be pushed onto items.
[out]descriptionsMenu item text will be pushed onto descriptions (in the same order as items).

Definition at line 107 of file wmi_manager.cpp.

References play_controller::can_use_synced_wml_menu(), resources::controller, empty(), game_data::get_variable(), mp_ui_alerts::items, wml_menu_items_, map_location::wml_x(), and map_location::wml_y().

Referenced by empty(), and play_controller::hotkey_handler::expand_wml_commands().

◆ init_handlers()

void game_events::wmi_manager::init_handlers ( ) const

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

Definition at line 151 of file wmi_manager.cpp.

References LOG_NG, and wml_menu_items_.

Referenced by empty(), and 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 191 of file wmi_manager.cpp.

References wml_menu_items_.

Referenced by empty().

◆ 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 210 of file wmi_manager.cpp.

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

Referenced by empty(), and 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 92 of file wmi_manager.hpp.

References wml_menu_items_.

◆ to_config()

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

Definition at line 179 of file wmi_manager.cpp.

References config::add_child(), and wml_menu_items_.

Referenced by empty(), and 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: