38 #define ERR_NG LOG_STREAM(err, log_engine)
39 #define LOG_NG LOG_STREAM(info, log_engine)
52 inline std::string make_item_name(
const std::string&
id)
54 return std::string(
"menu item") + (
id.empty() ?
"" :
' ' +
id);
62 inline std::string make_item_hotkey(
const std::string&
id)
72 , event_name_(make_item_name(
id))
73 , hotkey_id_(make_item_hotkey(
id))
75 , image_(cfg[
"image"].str())
76 , description_(cfg[
"description"].t_str())
77 , needs_select_(cfg[
"needs_select"].to_bool(false))
78 , show_if_(cfg.child_or_empty(
"show_if"), true)
79 , filter_location_(cfg.child_or_empty(
"filter_location"), true)
80 , command_(cfg.child_or_empty(
"command"))
81 , default_hotkey_(cfg.child_or_empty(
"default_hotkey"))
82 , use_hotkey_(cfg[
"use_hotkey"].to_bool(true))
83 , use_wml_menu_(cfg[
"use_hotkey"].str() !=
"only")
84 , is_synced_(cfg[
"synced"].to_bool(true))
85 , persistent_(cfg[
"persistent"].to_bool(true))
95 , event_name_(make_item_name(
id))
96 , hotkey_id_(make_item_hotkey(
id))
100 , needs_select_(false)
101 , show_if_(
vconfig::empty_vconfig())
102 , filter_location_(
vconfig::empty_vconfig())
106 , use_wml_menu_(true)
121 , event_name_(make_item_name(
id))
122 , hotkey_id_(make_item_hotkey(
id))
123 , hotkey_record_(std::move(original.hotkey_record_))
124 , image_(original.image_)
125 , description_(original.description_)
126 , needs_select_(original.needs_select_)
127 , show_if_(original.show_if_)
128 , filter_location_(original.filter_location_)
129 , command_(original.command_)
130 , default_hotkey_(original.default_hotkey_)
131 , use_hotkey_(original.use_hotkey_)
132 , use_wml_menu_(original.use_wml_menu_)
133 , is_synced_(original.is_synced_)
134 , persistent_(original.persistent_)
231 cfg[
"needs_select"] =
true;
235 cfg[
"use_hotkey"] =
true;
239 cfg[
"use_hotkey"] =
"only";
243 cfg[
"use_hotkey"] =
false;
247 ERR_NG <<
"Bad data: wml_menu_item with both use_wml_menu and "
248 "use_hotkey set to false is not supposed to be possible.";
249 cfg[
"use_hotkey"] =
false;
273 bool hotkey_updated =
false;
276 image_ = vcfg[
"image"].str();
281 hotkey_updated =
true;
302 if(
const vconfig& child = vcfg.
child(
"filter_location")) {
307 if(
const vconfig& child = vcfg.
child(
"default_hotkey")) {
309 hotkey_updated =
true;
320 const bool delayed = cmd[
"delayed_variable_substitution"].to_bool(
true);
321 update_command(delayed ? cmd.get_config() : cmd.get_parsed_config());
346 if(ptr->is_menu_item()) {
347 LOG_NG <<
"Removing command for " << event_name_ <<
".";
348 man.remove_event_handler(command_[
"id"].str());
353 if(new_command.
empty()) {
365 command_[
"first_time_only"] =
false;
Variant for storing WML attributes.
std::string str(const std::string &fallback="") const
bool to_bool(bool def=false) const
bool empty() const
Tests for an attribute that either was never set or was set to "".
A config object defines a single node in a WML file, with access to child nodes.
bool has_attribute(config_key_type key) const
config & add_child(config_key_type key)
The game event manager loads the scenario configuration object, and ensures that events are handled a...
void execute_on_events(const std::string &event_id, event_func_t func)
game_events::wml_event_pump & pump()
void remove_event_handler(const std::string &id)
Removes an event handler.
void add_event_handler_from_wml(const config &handler, game_lua_kernel &lk, bool is_menu_item=false)
Create an event handler from an [event] tag.
pump_result_t fire(const std::string &event, const entity_location &loc1=entity_location::null_entity, const entity_location &loc2=entity_location::null_entity, const config &data=config())
Function to fire an event.
A RAII object to temporary leave the synced context like in wesnoth.synchronize_choice.
static const std::string wml_menu_hotkey_prefix
static config get_event(const std::string &name, const map_location &loc, const map_location *last_select_loc)
An object to leave the synced context during draw or unsynced wml items when we don’t know whether we...
static bool run_in_synced_context_if_not_already(const std::string &commandname, const config &data, action_spectator &spectator=get_default_spectator())
Checks whether we are currently running in a synced context, and if not we enters it.
static bool run_and_throw(const std::string &commandname, const config &data, action_spectator &spectator=get_default_spectator())
A variable-expanding proxy for the config class.
bool has_attribute(const std::string &key) const
< Synonym for operator[]
vconfig child(const std::string &key) const
Returns a child of *this whose key is key.
const config & get_config() const
const vconfig & make_safe() const
instruct the vconfig to make a private copy of its underlying data.
Define conditionals for the game's events mechanism, a.k.a.
std::string deprecated_message(const std::string &elem_name, DEP_LEVEL level, const version_info &version, const std::string &detail)
Interfaces for manipulating version numbers of engine, add-ons, etc.
std::string id
Text to match against addon_info.tags()
Define the handlers for the game's events mechanism.
This file implements all the hotkey handling and menu details for play controller.
Standard logging facilities (interface).
bool conditional_passed(const vconfig &cond)
std::shared_ptr< event_handler > handler_ptr
game_events::manager * game_events
game_lua_kernel * lua_kernel
filter_context * filter_con
Define the game's event mechanism.
Encapsulates the map of the game.