Author: alink
Date: Sun Nov  4 16:26:06 2007
New Revision: 21485

URL: http://svn.gna.org/viewcvs/wesnoth?rev=21485&view=rev
Log:
Reorganize/clean the code for selecting an unit.
This fix various little inconsistencies between mouse-select and 
next-unit-select
(directly update new foosteps, show attack options, select anim+sound...)
Probably fixed a not-confirmed bug allowing to fire select event on enemy units
(when observing its turn)
PS : good thing, these new select anim+sound show you when you fire such events

Modified:
    trunk/src/menu_events.cpp
    trunk/src/mouse_events.cpp
    trunk/src/mouse_events.hpp
    trunk/src/play_controller.cpp

Modified: trunk/src/menu_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/menu_events.cpp?rev=21485&r1=21484&r2=21485&view=diff
==============================================================================
--- trunk/src/menu_events.cpp (original)
+++ trunk/src/menu_events.cpp Sun Nov  4 16:26:06 2007
@@ -1722,7 +1722,7 @@
 
                        if(un->second.hold_position()) {
                                un->second.set_user_end_turn(true);
-                               mousehandler.cycle_units();
+                               mousehandler.cycle_units(false);
                        }
                }
        }
@@ -1741,7 +1741,7 @@
                        gui_->draw();
 
                        if(un->second.user_end_turn()) {
-                               mousehandler.cycle_units();
+                               mousehandler.cycle_units(false);
                        }
                }
        }

Modified: trunk/src/mouse_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/mouse_events.cpp?rev=21485&r1=21484&r2=21485&view=diff
==============================================================================
--- trunk/src/mouse_events.cpp (original)
+++ trunk/src/mouse_events.cpp Sun Nov  4 16:26:06 2007
@@ -1193,47 +1193,44 @@
                move_unit_along_current_route(check_shroud);
        } else {
                // we select a (maybe empty) hex
+               select_hex(hex, browse);
+       }
+}
+
+void mouse_handler::select_hex(const gamemap::location& hex, const bool 
browse) {
+       selected_hex_ = hex;
+       gui_->select_hex(hex);
+       gui_->clear_attack_indicator();
+       gui_->set_route(NULL);
+
+       unit_map::iterator u = find_unit(hex);
+       if(u != units_.end() ) {
+               next_unit_ = u->first;
+
+               // if it's not the unit's turn, we reset its moves
+               unit_movement_resetter move_reset(u->second, u->second.side() 
!= team_num_);
+               const bool teleport = 
u->second.get_ability_bool("teleport",u->first);
+               current_paths_ = paths(map_,status_,gameinfo_,units_,hex,teams_,
+                                                  
false,teleport,viewing_team(),path_turns_);
+               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;
+               gui_->set_route(NULL);
+
+               // selection have impact only if we are not observing and it's 
our unit
+               if (!browse && u->second.side() == gui_->viewing_team()+1) {
+                       sound::play_UI_sound("select-unit.wav");
+                       u->second.set_selecting(*gui_, u->first);
+
+                       game_events::fire("select", selected_hex_);
+               }
+
+       } else {
                gui_->unhighlight_reach();
-               gui_->clear_attack_indicator();
                current_paths_ = paths();
-
-               selected_hex_ = hex;
-               gui_->select_hex(hex);
                current_route_.steps.clear();
-               gui_->set_route(NULL);
-
-               u = clicked_u;
-
-               if(u != units_.end() && !gui_->fogged(u->first)) {
-                       const bool teleport = 
u->second.get_ability_bool("teleport",u->first);
-
-                       if (u->second.side() == team_num_) {
-                               current_paths_ = 
paths(map_,status_,gameinfo_,units_,hex,teams_,
-                                                          
false,teleport,viewing_team(),path_turns_);
-                               show_attack_options(u);
-                               gui_->highlight_reach(current_paths_);
-
-                               next_unit_ = u->first;
-
-                               const gamemap::location go_to = 
u->second.get_goto();
-                               if(map_.on_board(go_to)) {
-                                       paths::route route = get_route(u, 
go_to, current_team());
-                                       gui_->set_route(&route);
-                               }
-                               sound::play_UI_sound("select-unit.wav");
-                               u->second.set_selecting(*gui_, u->first);
-                               game_events::fire("select",hex);
-                       } else {
-                               unit_movement_resetter move_reset(u->second);
-                               current_paths_ = 
paths(map_,status_,gameinfo_,units_,hex,teams_,
-                                                          
false,teleport,viewing_team(),path_turns_);
-                               gui_->highlight_reach(current_paths_);
-                               // the highlight now comes from selection
-                               // and not anymore from the mouseover on an 
enemy
-                               enemy_paths_ = false; 
-                       }
-
-               }
        }
 }
 
@@ -1476,7 +1473,7 @@
 const unit_map::const_iterator begin = units_.begin();\
 const unit_map::const_iterator end = units_.end()
 
-void mouse_handler::cycle_units()
+void mouse_handler::cycle_units(const bool browse)
 {
        LOCAL_VARIABLES;
 
@@ -1488,11 +1485,17 @@
                        if (it == end) it = begin;
                } while (it != itx && !unit_in_cycle(it));
        }
-
-       select_unit(it, itx);
-}
-
-void mouse_handler::cycle_back_units()
+       if (it!=itx) {
+               gui_->scroll_to_tile(it->first,game_display::WARP);
+               select_hex(it->first, browse);
+       } else {
+               next_unit_ = gamemap::location();
+       }
+
+       mouse_update(browse);
+}
+
+void mouse_handler::cycle_back_units(const bool browse)
 {
        LOCAL_VARIABLES;
 
@@ -1506,32 +1509,14 @@
                } while (it != itx && !unit_in_cycle(it));
        }
 
-       select_unit(it, itx);
-}
-
-inline void mouse_handler::select_unit(const unit_map::const_iterator &it,
-                                                                          
const unit_map::const_iterator &itx) {
-       if (it != itx && !gui_->fogged(it->first)) {
-               const bool teleport = 
it->second.get_ability_bool("teleport",it->first);
-               current_paths_ = 
paths(map_,status_,gameinfo_,units_,it->first,teams_,false,teleport,viewing_team(),path_turns_);
-               gui_->highlight_reach(current_paths_);
-
+       if (it!=itx) {
                gui_->scroll_to_tile(it->first,game_display::WARP);
-       }
-
-       if (it == itx) {
+               select_hex(it->first, browse);
+       } else {
                next_unit_ = gamemap::location();
-       } else {
-               next_unit_ = it->first;
-               selected_hex_ = next_unit_;
-               gui_->select_hex(selected_hex_);
-               gui_->highlight_hex(selected_hex_);
-               current_route_.steps.clear();
-               gui_->set_route(NULL);
-               mouse_update(true);
-               show_attack_options(it);
-               game_events::fire("select",selected_hex_);
-       }
+       }
+
+       mouse_update(browse);
 }
 
 void mouse_handler::set_current_paths(paths new_paths) {

Modified: trunk/src/mouse_events.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/mouse_events.hpp?rev=21485&r1=21484&r2=21485&view=diff
==============================================================================
--- trunk/src/mouse_events.hpp (original)
+++ trunk/src/mouse_events.hpp Sun Nov  4 16:26:06 2007
@@ -44,8 +44,8 @@
        // update the mouse with a fake mouse motion
        void mouse_update(const bool browse);
        void mouse_press(const SDL_MouseButtonEvent& event, const bool browse);
-       void cycle_units();
-       void cycle_back_units();
+       void cycle_units(const bool browse);
+       void cycle_back_units(const bool browse);
 
        int get_path_turns() const { return path_turns_; }
        paths get_current_paths() { return current_paths_; }
@@ -73,6 +73,7 @@
        bool is_middle_click(const SDL_MouseButtonEvent& event);
        bool is_right_click(const SDL_MouseButtonEvent& event);
        void left_click(const SDL_MouseButtonEvent& event, const bool browse);
+       void select_hex(const gamemap::location& hex, const bool browse);
        void clear_undo_stack();
        bool move_unit_along_current_route(bool check_shroud=true);
        // wrapper to catch bad_alloc so this should be called
@@ -84,7 +85,6 @@
        unit_map::const_iterator find_unit(const gamemap::location& hex) const;
        unit_map::iterator find_unit(const gamemap::location& hex);
        bool unit_in_cycle(unit_map::const_iterator it);
-       void select_unit(const unit_map::const_iterator &it, const 
unit_map::const_iterator &bound);
 
        game_display* gui_;
        std::vector<team>& teams_;

Modified: trunk/src/play_controller.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/play_controller.cpp?rev=21485&r1=21484&r2=21485&view=diff
==============================================================================
--- trunk/src/play_controller.cpp (original)
+++ trunk/src/play_controller.cpp Sun Nov  4 16:26:06 2007
@@ -231,11 +231,11 @@
 }
 
 void play_controller::cycle_units(){
-       mouse_handler_.cycle_units();
+       mouse_handler_.cycle_units(browse_);
 }
 
 void play_controller::cycle_back_units(){
-       mouse_handler_.cycle_back_units();
+       mouse_handler_.cycle_back_units(browse_);
 }
 
 void play_controller::show_chat_log(){


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

Reply via email to