mail[Wesnoth-commits] r52632 - in /trunk/src: mouse_events.cpp mouse_events.hpp scripting/lua.cpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by strgaltent on January 17, 2012 - 15:56:
Author: anonymissimus
Date: Tue Jan 17 15:56:50 2012
New Revision: 52632

URL: http://svn.gna.org/viewcvs/wesnoth?rev=52632&view=rev
Log:
Rework wesnoth.select_hex implementation (bug #19224, bug #16819).

Bind it to mouse_handler::select_hex rather than game_display and
display functions. Matches more the original intention (work like
a user click).

Modified:
    trunk/src/mouse_events.cpp
    trunk/src/mouse_events.hpp
    trunk/src/scripting/lua.cpp

Modified: trunk/src/mouse_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/mouse_events.cpp?rev=52632&r1=52631&r2=52632&view=diff
==============================================================================
--- trunk/src/mouse_events.cpp (original)
+++ trunk/src/mouse_events.cpp Tue Jan 17 15:56:50 2012
@@ -586,7 +586,7 @@
        //FIXME: clean all these "return false"
 }
 
-void mouse_handler::select_hex(const map_location& hex, const bool browse) {
+void mouse_handler::select_hex(const map_location& hex, const bool browse, 
const bool highlight, const bool fire_event) {
        selected_hex_ = hex;
        gui().select_hex(hex);
        gui().clear_attack_indicator();
@@ -605,8 +605,10 @@
                        current_paths_ = pathfind::paths(map_, units_, hex, 
teams_,
                                false, true, viewing_team(), path_turns_);
                }
-               show_attack_options(u);
-               gui().highlight_reach(current_paths_);
+               if(highlight) {
+                       show_attack_options(u);
+                       gui().highlight_reach(current_paths_);
+               }
                // the highlight now comes from selection
                // and not from the mouseover on an enemy
                enemy_paths_ = false;
@@ -618,10 +620,12 @@
                        {
                                sound::play_UI_sound("select-unit.wav");
                                u->set_selecting();
-                               // ensure unit map is back to normal while 
event is fired
-                               { wb::real_map srum;
+                               if(fire_event) {
+                                       // ensure unit map is back to normal 
while event is fired
+                                       wb::real_map srum;
                                        game_events::fire("select", hex);
-                               } //end forced real unit map
+                                       //end forced real unit map
+                               }
                        }
                }
 

Modified: trunk/src/mouse_events.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/mouse_events.hpp?rev=52632&r1=52631&r2=52632&view=diff
==============================================================================
--- trunk/src/mouse_events.hpp (original)
+++ trunk/src/mouse_events.hpp Tue Jan 17 15:56:50 2012
@@ -75,6 +75,9 @@
        // output arg: sighted_result: if not NULL, indicates whether a "unit 
sighted" occurred
        bool move_unit_along_route(pathfind::marked_route const& route, 
map_location* next_unit, bool check_shroud, bool* sighted_result = NULL);
 
+       void select_hex(const map_location& hex, const bool browse,
+               const bool highlight = true,
+               const bool fire_event = true);
 protected:
        /**
         * Due to the way this class is constructed we can assume that the
@@ -95,7 +98,6 @@
        void mouse_motion(int x, int y, const bool browse, bool update=false, 
map_location loc = map_location::null_location);
        bool right_click_show_menu(int x, int y, const bool browse);
        bool left_click(int x, int y, const bool browse);
-       void select_hex(const map_location& hex, const bool browse);
        bool move_unit_along_current_route(bool check_shroud);
 
        void save_whiteboard_attack(const map_location& attacker_loc, const 
map_location& defender_loc, int weapon_choice);

Modified: trunk/src/scripting/lua.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/scripting/lua.cpp?rev=52632&r1=52631&r2=52632&view=diff
==============================================================================
--- trunk/src/scripting/lua.cpp (original)
+++ trunk/src/scripting/lua.cpp Tue Jan 17 15:56:50 2012
@@ -2689,14 +2689,25 @@
 }
 
 /**
- * Selects the given location on the map.
+ * Selects and highlights the given location on the map.
  * - Args 1,2: location.
+ * - Args 3,4: booleans
  */
 static int intf_select_hex(lua_State *L)
 {
-       int x = luaL_checkinteger(L, 1) - 1;
-       int y = luaL_checkinteger(L, 2) - 1;
-       resources::screen->select_hex(map_location(x, y));
+       const int x = luaL_checkinteger(L, 1) - 1;
+       const int y = luaL_checkinteger(L, 2) - 1;
+
+       map_location loc(x, y);
+       if(!resources::game_map->on_board(loc)) return luaL_argerror(L, 1, 
"not on board");
+       bool highlight = true;
+       if(!lua_isnoneornil(L, 3))
+               highlight = lua_toboolean(L, 3);
+       const bool fire_event = lua_toboolean(L, 4);
+       resources::controller->get_mouse_handler_base().select_hex(
+               map_location(x, y), false, highlight, fire_event);
+       if(highlight)
+               resources::screen->highlight_hex(loc);
        return 0;
 }
 




Related Messages


Powered by MHonArc, Updated Tue Jan 17 16:00:08 2012