37 #define ERR_NG LOG_STREAM(err, log_engine)
38 #define LOG_NG LOG_STREAM(info, log_engine)
51 inline std::string make_item_name(
const std::string&
id)
53 return std::string(
"menu item") + (
id.empty() ?
"" :
' ' +
id);
61 inline std::string make_item_hotkey(
const std::string&
id)
71 , event_name_(make_item_name(
id))
72 , hotkey_id_(make_item_hotkey(
id))
74 , image_(cfg[
"image"].str())
75 , description_(cfg[
"description"].t_str())
76 , needs_select_(cfg[
"needs_select"].to_bool(false))
77 , show_if_(cfg.child_or_empty(
"show_if"), true)
78 , filter_location_(cfg.child_or_empty(
"filter_location"), true)
79 , command_(cfg.child_or_empty(
"command"))
80 , default_hotkey_(cfg.child_or_empty(
"default_hotkey"))
81 , use_hotkey_(cfg[
"use_hotkey"].to_bool(true))
82 , use_wml_menu_(cfg[
"use_hotkey"].str() !=
"only")
83 , is_synced_(cfg[
"synced"].to_bool(true))
84 , persistent_(cfg[
"persistent"].to_bool(true))
94 , event_name_(make_item_name(
id))
95 , hotkey_id_(make_item_hotkey(
id))
99 , needs_select_(false)
100 , show_if_(
vconfig::empty_vconfig())
101 , filter_location_(
vconfig::empty_vconfig())
105 , use_wml_menu_(true)
120 , event_name_(make_item_name(
id))
121 , hotkey_id_(make_item_hotkey(
id))
122 , hotkey_record_(std::move(original.hotkey_record_))
123 , image_(original.image_)
124 , description_(original.description_)
125 , needs_select_(original.needs_select_)
126 , show_if_(original.show_if_)
127 , filter_location_(original.filter_location_)
128 , command_(original.command_)
129 , default_hotkey_(original.default_hotkey_)
130 , use_hotkey_(original.use_hotkey_)
131 , use_wml_menu_(original.use_wml_menu_)
132 , is_synced_(original.is_synced_)
133 , persistent_(original.persistent_)
230 cfg[
"needs_select"] =
true;
234 cfg[
"use_hotkey"] =
true;
238 cfg[
"use_hotkey"] =
"only";
242 cfg[
"use_hotkey"] =
false;
246 ERR_NG <<
"Bad data: wml_menu_item with both use_wml_menu and "
247 "use_hotkey set to false is not supposed to be possible.";
248 cfg[
"use_hotkey"] =
false;
272 bool hotkey_updated =
false;
275 image_ = vcfg[
"image"].str();
280 hotkey_updated =
true;
301 if(
const vconfig& child = vcfg.
child(
"filter_location")) {
306 if(
const vconfig& child = vcfg.
child(
"default_hotkey")) {
308 hotkey_updated =
true;
319 const bool delayed = cmd[
"delayed_variable_substitution"].to_bool(
true);
320 update_command(delayed ? cmd.get_config() : cmd.get_parsed_config());
345 if(ptr->is_menu_item()) {
346 LOG_NG <<
"Removing command for " << event_name_ <<
".";
347 man.remove_event_handler(command_[
"id"].str());
352 if(new_command.
empty()) {
364 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_and_throw(const std::string &commandname, const config &data, bool use_undo=true, bool show=true, synced_command::error_handler_function error_handler=default_error_function)
static bool run_in_synced_context_if_not_already(const std::string &commandname, const config &data, bool use_undo=true, bool show=true, synced_command::error_handler_function error_handler=default_error_function)
Checks whether we are currently running in a synced context, and if not we enters it.
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)
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.