mail[Wesnoth-commits] r43974 - in /trunk/src/whiteboard: action.hpp manager.cpp move.cpp move.hpp side_actions.cpp side_actions.hpp


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

Header


Content

Posted by gabrielmorin on July 07, 2010 - 07:42:
Author: gabba
Date: Wed Jul  7 07:42:28 2010
New Revision: 43974

URL: http://svn.gna.org/viewcvs/wesnoth?rev=43974&view=rev
Log:
Whiteboard: various tweaks and moving code around.

Modified:
    trunk/src/whiteboard/action.hpp
    trunk/src/whiteboard/manager.cpp
    trunk/src/whiteboard/move.cpp
    trunk/src/whiteboard/move.hpp
    trunk/src/whiteboard/side_actions.cpp
    trunk/src/whiteboard/side_actions.hpp

Modified: trunk/src/whiteboard/action.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/action.hpp?rev=43974&r1=43973&r2=43974&view=diff
==============================================================================
--- trunk/src/whiteboard/action.hpp (original)
+++ trunk/src/whiteboard/action.hpp Wed Jul  7 07:42:28 2010
@@ -51,17 +51,18 @@
        /** Removes the result of this action from the specified unit map. */
        virtual void remove_temp_modifier(unit_map& unit_map) = 0;
 
-       /**
-        * Indicates whether this action is related to the specified hex.
-        * "Related" means the action affects this hex or draws a visual 
symbol in it
-        * at some point. Ex.: a move is related to this hex if its path goes 
through it.
-        */
-       virtual bool is_related_to(const map_location& hex) const = 0;
+       /** Gets called by display when drawing a hex, to allow actions to 
draw to the screen. */
+       virtual void draw_hex(const map_location& hex) = 0;
 
        /**
         * Indicates whether this actions targets the specified unit.
         */
        virtual bool is_related_to(const unit& unit) const = 0;
+
+       /**
+        * Answers whether the specified hex is the main target of action for 
this action.
+        */
+       virtual bool is_target_hex(const map_location& hex) const = 0;
 
        /** Return the unit targeted by this action. */
        virtual unit& get_unit() = 0;

Modified: trunk/src/whiteboard/manager.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/manager.cpp?rev=43974&r1=43973&r2=43974&view=diff
==============================================================================
--- trunk/src/whiteboard/manager.cpp (original)
+++ trunk/src/whiteboard/manager.cpp Wed Jul  7 07:42:28 2010
@@ -32,9 +32,16 @@
 #include "team.hpp"
 #include "unit_display.hpp"
 
-#include <sstream>
-
 namespace wb {
+
+
+static side_actions_ptr current_actions()
+{
+       int current_side = resources::controller->current_side();
+       team& current_team = (*resources::teams)[current_side - 1];
+       side_actions_ptr side_actions = current_team.get_side_actions();
+       return side_actions;
+}
 
 manager::manager():
                active_(false),
@@ -47,18 +54,11 @@
                selected_unit_(NULL),
                planned_unit_map_active_(false)
 {
+       highlighter_.reset(new highlight_visitor(*resources::units, 
current_actions()));
 }
 
 manager::~manager()
 {
-}
-
-static side_actions_ptr current_actions()
-{
-       int current_side = resources::controller->current_side();
-       team& current_team = (*resources::teams)[current_side - 1];
-       side_actions_ptr side_actions = current_team.get_side_actions();
-       return side_actions;
 }
 
 void manager::set_planned_unit_map()
@@ -98,26 +98,7 @@
 
 void manager::draw_hex(const map_location& hex)
 {
-       const action_queue& actions = current_actions()->actions();
-       action_queue::const_iterator it = actions.begin();
-       for(; it != actions.end(); ++it)
-       {
-               if((*it)->is_related_to(hex))
-               {
-                       //draw number corresponding to iterator's position + 1
-                       size_t number = (it - actions.begin()) + 1;
-                       std::stringstream number_text;
-                       number_text << number;
-                       const size_t font_size = 12;
-                       SDL_Color color; color.r = 255; color.g = 255; 
color.b = 0; //yellow
-                       // position 0,0 in the hex is the upper left corner
-                       const double x_in_hex = 0.80; // 0.80 = horizontal 
coord., close to the right side of the hex
-                       const double y_in_hex = 0.5; //0.5 = halfway in the 
hex vertically
-                       resources::screen->draw_text_in_hex(hex, 
display::LAYER_ACTIONS_NUMBERING,
-                                       number_text.str(), font_size, color, 
x_in_hex, y_in_hex);
-                       return;
-               }
-       }
+       current_actions()->draw_hex(hex);
 }
 
 void manager::on_mouseover_change(const map_location& hex)
@@ -126,10 +107,6 @@
        // Acting otherwise causes a crash.
        if (active_ && !selected_unit_)
        {
-               if (!highlighter_)
-               {
-                       highlighter_.reset(new 
highlight_visitor(*resources::units, current_actions()));
-               }
                highlighter_->set_mouseover_hex(hex);
                highlighter_->highlight();
        }
@@ -258,17 +235,15 @@
                erase_temp_move();
 
                //TODO: catch end_turn_exception somewhere here?
+               action_ptr action;
                if (selected_unit_)
                {
                                
current_actions()->execute(current_actions()->find_first_action_of(*selected_unit_));
                }
-               else if (highlighter_)
-               {
-                       action_ptr action = 
highlighter_->get_execute_target();
-                       if (action)
-                       {
-                               
current_actions()->execute(current_actions()->get_position_of(action));
-                       }
+               else if (highlighter_
+                               && (action = 
highlighter_->get_execute_target())) //intentional assignment of action with 
'='
+               {
+                       
current_actions()->execute(current_actions()->get_position_of(action));
                }
                else
                {
@@ -283,17 +258,14 @@
        {
                erase_temp_move();
 
+               action_ptr action;
                if (selected_unit_)
                {
-                               
current_actions()->remove_action(current_actions()->find_first_action_of(*selected_unit_));
-               }
-               else if (highlighter_)
-               {
-                       action_ptr action = highlighter_->get_delete_target();
-                       if (action)
-                       {
-                               
current_actions()->remove_action(current_actions()->get_position_of(action));
-                       }
+                       
current_actions()->remove_action(current_actions()->find_first_action_of(*selected_unit_));
+               }
+               else if (highlighter_ && (action = 
highlighter_->get_delete_target()))
+               {
+                       
current_actions()->remove_action(current_actions()->get_position_of(action));
                }
                else
                {

Modified: trunk/src/whiteboard/move.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/move.cpp?rev=43974&r1=43973&r2=43974&view=diff
==============================================================================
--- trunk/src/whiteboard/move.cpp (original)
+++ trunk/src/whiteboard/move.cpp Wed Jul  7 07:42:28 2010
@@ -149,7 +149,7 @@
        //Modify movement points accordingly
        DBG_WB <<"Changing movement points for unit " << unit_.name() << " [" 
<< unit_.underlying_id()
                        << "] from " << unit_.movement_left() <<" to "
-                       << unit_.movement_left() - movement_cost_ << "\n.";
+                       << unit_.movement_left() - movement_cost_ << ".\n";
        unit_.set_movement(unit_.movement_left() - movement_cost_);
 
 }
@@ -165,10 +165,14 @@
        unit_.set_movement(unit_.movement_left() + movement_cost_);
 }
 
-bool move::is_related_to(const map_location& hex) const
+void move::draw_hex(const map_location& hex)
 {
-       //bool is_related = arrow_->path_contains(hex);
-       bool is_related = hex == source_hex_ || hex == dest_hex_;
+       (void) hex; //temporary to avoid unused param warning
+}
+
+bool move::is_target_hex(const map_location& hex) const
+{
+       bool is_related = hex == dest_hex_;
        return is_related;
 }
 

Modified: trunk/src/whiteboard/move.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/move.hpp?rev=43974&r1=43973&r2=43974&view=diff
==============================================================================
--- trunk/src/whiteboard/move.hpp (original)
+++ trunk/src/whiteboard/move.hpp Wed Jul  7 07:42:28 2010
@@ -62,7 +62,10 @@
        /** Removes the result of this action from the specified unit map. */
        virtual void remove_temp_modifier(unit_map& unit_map);
 
-       virtual bool is_related_to(const map_location& hex) const;
+       /** Gets called by display when drawing a hex, to allow actions to 
draw to the screen. */
+       virtual void draw_hex(const map_location& hex);
+
+       virtual bool is_target_hex(const map_location& hex) const;
        virtual bool is_related_to(const unit& unit) const;
 
        virtual void set_valid(bool valid);

Modified: trunk/src/whiteboard/side_actions.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/side_actions.cpp?rev=43974&r1=43973&r2=43974&view=diff
==============================================================================
--- trunk/src/whiteboard/side_actions.cpp (original)
+++ trunk/src/whiteboard/side_actions.cpp Wed Jul  7 07:42:28 2010
@@ -23,8 +23,11 @@
 #include "validate_visitor.hpp"
 
 #include "foreach.hpp"
+#include "game_display.hpp"
 #include "resources.hpp"
+
 #include <set>
+#include <sstream>
 
 namespace wb
 {
@@ -38,9 +41,27 @@
 {
 }
 
-const action_queue& side_actions::actions() const
-{
-       return actions_;
+void side_actions::draw_hex(const map_location& hex)
+{
+       const_iterator it;
+       for(it = begin(); it != end(); ++it)
+       {
+               if((*it)->is_target_hex(hex))
+               {
+                       //draw number corresponding to iterator's position + 1
+                       size_t number = (it - begin()) + 1;
+                       std::stringstream number_text;
+                       number_text << number;
+                       const size_t font_size = 12;
+                       SDL_Color color; color.r = 255; color.g = 255; 
color.b = 0; //yellow
+                       // position 0,0 in the hex is the upper left corner
+                       const double x_in_hex = 0.80; // 0.80 = horizontal 
coord., close to the right side of the hex
+                       const double y_in_hex = 0.5; //0.5 = halfway in the 
hex vertically
+                       resources::screen->draw_text_in_hex(hex, 
display::LAYER_ACTIONS_NUMBERING,
+                                       number_text.str(), font_size, color, 
x_in_hex, y_in_hex);
+                       return; //since we found the appropriate hex
+               }
+       }
 }
 
 side_actions::iterator side_actions::execute_next()

Modified: trunk/src/whiteboard/side_actions.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/side_actions.hpp?rev=43974&r1=43973&r2=43974&view=diff
==============================================================================
--- trunk/src/whiteboard/side_actions.hpp (original)
+++ trunk/src/whiteboard/side_actions.hpp Wed Jul  7 07:42:28 2010
@@ -42,7 +42,10 @@
        side_actions();
        virtual ~side_actions();
 
-       const action_queue& actions() const;
+       const action_queue& actions() const { return actions_; }
+
+       /** Gets called when display is drawing a hex, to allow drawing 
symbols to the screen */
+       void draw_hex(const map_location& hex);
 
        /**
         * Executes the first action in the queue, and then deletes it.




Related Messages


Powered by MHonArc, Updated Wed Jul 07 08:00:07 2010