Author: sapient
Date: Thu Apr  5 08:16:33 2007
New Revision: 16596

URL: http://svn.gna.org/viewcvs/wesnoth?rev=16596&view=rev
Log:
*rename location_filter to filter_location
*hide the menu item if needs_select=yes and nothing was selected
*prevent crash if setting menu items while executing that same item

Modified:
    trunk/data/scenario-test.cfg
    trunk/src/game_events.cpp
    trunk/src/gamestatus.cpp
    trunk/src/gamestatus.hpp
    trunk/src/play_controller.cpp

Modified: trunk/data/scenario-test.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/scenario-test.cfg?rev=16596&r1=16595&r2=16596&view=diff
==============================================================================
--- trunk/data/scenario-test.cfg (original)
+++ trunk/data/scenario-test.cfg Thu Apr  5 08:16:33 2007
@@ -499,8 +499,8 @@
                                        [/have_unit]
                                [/not]
                        [/show_if]
-                       [location_filter]
-                       [/location_filter]
+                       [filter_location]
+                       [/filter_location]
                        [command]
                                {UNIT (Troll) (MagicTroll) ( "Magic Troll") 
$side_number $x1 $y1}
                                [sound]

Modified: trunk/src/game_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_events.cpp?rev=16596&r1=16595&r2=16596&view=diff
==============================================================================
--- trunk/src/game_events.cpp (original)
+++ trunk/src/game_events.cpp Thu Apr  5 08:16:33 2007
@@ -314,7 +314,6 @@
 namespace {
 
 std::set<std::string> used_items;
-
 /*
 jhinrichs, 12.11.2006:
 This variable controls the maximum number of hexes in a map, that can be 
parsed by an event.
@@ -402,9 +401,13 @@
 
        bool& rebuild_screen() {return rebuild_screen_;}
 
+       void commit_wmi_commands();
+
 private:
        bool handle_event_command(const queued_event& event_info, const 
std::string& cmd, const vconfig cfg, bool& mutated);
 
+       typedef std::pair< std::string, config* > wmi_command_change;
+       std::vector< wmi_command_change > wmi_command_changes_;
        std::string name_;
        bool first_time_only_;
        bool disabled_;
@@ -1730,8 +1733,8 @@
                                        [/have_unit]
                                [/not]
                        [/show_if]
-                       [location_filter]
-                       [/location_filter]
+                       [filter_location]
+                       [/filter_location]
                        [command]
                                {UNIT (Troll) (Myname) ( _ "Myname") 
$side_number $x1 $y1}
                        [/command]
@@ -1754,23 +1757,12 @@
                if(cfg.has_child("show_if")) {
                        mref->show_if = cfg.child("show_if").get_config();
                }
-               if(cfg.has_child("location_filter")) {
-                       mref->location_filter = 
cfg.child("location_filter").get_config();
+               if(cfg.has_child("filter_location")) {
+                       mref->filter_location = 
cfg.child("filter_location").get_config();
                }
                if(cfg.has_child("command")) {
-                       const bool no_current_handler = mref->command.empty();
-                       mref->command = cfg.child("command").get_config();
-                       if(no_current_handler) {
-                               if(!mref->command.empty()) {
-                                       mref->command["name"] = mref->name;
-                                       mref->command["first_time_only"] = "no";
-                                       event_handler 
new_handler(mref->command); 
-                                       
events_map.insert(std::pair<std::string,event_handler>(
-                                               new_handler.name(), 
new_handler));
-                               }
-                       } else if(mref->command.empty()) {
-                               mref->command.add_child("allow_undo");
-                       }
+                       config* new_command = new 
config(cfg.child("command").get_config());
+                       wmi_command_changes_.push_back(wmi_command_change(id, 
new_command));
                }
        }
        //unit serialization to and from variables
@@ -2127,16 +2119,42 @@
        return rval;
 }
 
+void event_handler::commit_wmi_commands() {
+       //commit WML Menu Item command changes
+       while(wmi_command_changes_.size() > 0) {
+               wmi_command_change wcc = wmi_command_changes_.back();
+               wml_menu_item*& mref = state_of_game->wml_menu_items[wcc.first];
+               const bool no_current_handler = mref->command.empty();
+               mref->command = *(wcc.second);
+               if(no_current_handler) {
+                       if(!mref->command.empty()) {
+                               mref->command["name"] = mref->name;
+                               mref->command["first_time_only"] = "no";
+                               event_handler new_handler(mref->command); 
+                               
events_map.insert(std::pair<std::string,event_handler>(
+                                       new_handler.name(), new_handler));
+                       }
+               } else if(mref->command.empty()) {
+                       mref->command["name"] = mref->name;
+                       mref->command["first_time_only"] = "no";
+                       mref->command.add_child("allow_undo");
+               }
+               LOG_NG << "setting command for " << name_ << "\n";
+               wcc.second->debug(lg::info(lg::engine));
+               delete wcc.second;
+               wmi_command_changes_.pop_back();
+       }
+}
+
 bool event_handler::handle_event(const queued_event& event_info, const vconfig 
conf)
 {
+       bool mutated = true;
+       bool skip_messages = false;
+
        vconfig cfg = conf;
-
-       if(cfg.null())
+       if(cfg.null()) {
                cfg = cfg_;
-
-       bool mutated = true;
-
-       bool skip_messages = false;
+       }
        for(config::all_children_iterator i = cfg.get_config().ordered_begin();
                        i != cfg.get_config().ordered_end(); ++i) {
 
@@ -2160,6 +2178,7 @@
 
        // We do this once event has completed any music alterations
        sound::commit_music_changes();
+
        return mutated;
 }
 
@@ -2235,6 +2254,9 @@
        if(ev.name == "select") {
                state_of_game->last_selected = ev.loc1;
        }
+
+       //wait until the handler finishes processing before changing menu items
+       handler.commit_wmi_commands();
 
        if(handler.rebuild_screen()) {
                handler.rebuild_screen() = false;

Modified: trunk/src/gamestatus.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gamestatus.cpp?rev=16596&r1=16595&r2=16596&view=diff
==============================================================================
--- trunk/src/gamestatus.cpp (original)
+++ trunk/src/gamestatus.cpp Thu Apr  5 08:16:33 2007
@@ -637,8 +637,8 @@
                new_cfg["needs_select"]= (j->second->needs_select) ? "yes" : 
"no";
                if(!j->second->show_if.empty())
                        new_cfg.add_child("show_if", j->second->show_if);
-               if(!j->second->location_filter.empty())
-                       new_cfg.add_child("location_filter", 
j->second->location_filter);
+               if(!j->second->filter_location.empty())
+                       new_cfg.add_child("filter_location", 
j->second->filter_location);
                if(!j->second->command.empty())
                        new_cfg.add_child("command", j->second->command);
                cfg.add_child("menu_item", new_cfg);
@@ -684,8 +684,8 @@
                out.write_key_val("needs_select", (j->second->needs_select) ? 
"yes" : "no");
                if(!j->second->show_if.empty())
                        out.write_child("show_if", j->second->show_if);
-               if(!j->second->location_filter.empty())
-                       out.write_child("location_filter", 
j->second->location_filter);
+               if(!j->second->filter_location.empty())
+                       out.write_child("filter_location", 
j->second->filter_location);
                if(!j->second->command.empty())
                        out.write_child("command", j->second->command);
                out.close_child("menu_item");
@@ -1420,7 +1420,7 @@
                needs_select = utils::string_bool((*cfg)["needs_select"], 
false);
                config const* temp;
                if((temp = (*cfg).child("show_if")) != NULL) show_if = *temp;
-               if((temp = (*cfg).child("location_filter")) != NULL) 
location_filter = *temp;
+               if((temp = (*cfg).child("filter_location")) != NULL) 
filter_location = *temp;
                if((temp = (*cfg).child("command")) != NULL) command = *temp;
        }
 }

Modified: trunk/src/gamestatus.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gamestatus.hpp?rev=16596&r1=16595&r2=16596&view=diff
==============================================================================
--- trunk/src/gamestatus.hpp (original)
+++ trunk/src/gamestatus.hpp Thu Apr  5 08:16:33 2007
@@ -60,7 +60,7 @@
        t_string description;
        bool needs_select;
        config show_if;
-       config location_filter;
+       config filter_location;
        config command;
 };
 

Modified: trunk/src/play_controller.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/play_controller.cpp?rev=16596&r1=16595&r2=16596&view=diff
==============================================================================
--- trunk/src/play_controller.cpp (original)
+++ trunk/src/play_controller.cpp Thu Apr  5 08:16:33 2007
@@ -323,6 +323,7 @@
        std::stringstream player_number_str;
        player_number_str << player_number_;
        gamestate_.set_variable("side_number",player_number_str.str());
+       gamestate_.last_selected = gamemap::location::null_location;
 
        /*  
                normally, events must not be actively fired through replays, 
because they have been 
@@ -792,11 +793,13 @@
                        for (itor = gs_wmi.begin(); itor != gs_wmi.end()
                                && newitems.size() < MAX_WML_COMMANDS; ++itor) {
                                config& show_if = itor->second->show_if;
-                               config location_filter = 
itor->second->location_filter;
+                               config filter_location = 
itor->second->filter_location;
                                if ((show_if.empty() 
                                        || 
game_events::conditional_passed(&units_, &show_if))
-                               && (location_filter.empty() 
-                                       || map_.terrain_matches_filter(hex, 
&location_filter, status_, units_)))
+                               && (filter_location.empty() 
+                                       || map_.terrain_matches_filter(hex, 
&filter_location, status_, units_))
+                               && (!itor->second->needs_select
+                                       || gamestate_.last_selected.valid()))
                                {
                                        wml_commands_.push_back(itor->second);
                                        std::string newitem = 
itor->second->description;


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to