From 229d764a3e36c64e785784460568185820054b35 Mon Sep 17 00:00:00 2001 From: Anonymissimus Date: Sun, 29 Jan 2012 22:50:47 +0000 Subject: [PATCH] Let event handlers of menu item commands have an id. Unless both the menu item and its command tag didn't have an id. Makes it possible to remove the resulting event handler in the same way [event]remove=yes removes events. Unless I'm badly mistaken, event handlers caused by a menu item's command should already be unique, so no id collisions are expected. --- src/game_events.cpp | 6 ++++++ src/gamestatus.cpp | 1 + src/gamestatus.hpp | 1 + 3 files changed, 8 insertions(+) diff --git a/src/game_events.cpp b/src/game_events.cpp index 23f6116e96a..85c8c62cb72 100644 --- a/src/game_events.cpp +++ b/src/game_events.cpp @@ -2979,6 +2979,12 @@ static void commit_wmi_commands() { wml_menu_item*& mref = resources::state_of_game->wml_menu_items[wcc.first]; const bool has_current_handler = !mref->command.empty(); + config::attribute_value event_id = (*wcc.second)["id"]; + if(event_id.empty()) { + event_id = mref->event_id; + if(!event_id.empty()) + (*wcc.second)["id"] = event_id; + } mref->command = *(wcc.second); mref->command["name"] = mref->name; mref->command["first_time_only"] = false; diff --git a/src/gamestatus.cpp b/src/gamestatus.cpp index 2cb4f49acb2..0ebf4a5b1bd 100644 --- a/src/gamestatus.cpp +++ b/src/gamestatus.cpp @@ -1001,6 +1001,7 @@ void game_state::write_config(config_writer& out, bool write_variables) const wml_menu_item::wml_menu_item(const std::string& id, const config* cfg) : name(), + event_id(id), image(), description(), needs_select(false), diff --git a/src/gamestatus.hpp b/src/gamestatus.hpp index 235d5f72d5c..2153c7f2b04 100644 --- a/src/gamestatus.hpp +++ b/src/gamestatus.hpp @@ -69,6 +69,7 @@ struct wml_menu_item { wml_menu_item(const std::string& id, const config* cfg=NULL); std::string name; + const std::string event_id; std::string image; t_string description; bool needs_select;