Author: tschmitz
Date: Fri Jul 15 23:45:12 2011
New Revision: 50336

URL: http://svn.gna.org/viewcvs/wesnoth?rev=50336&view=rev
Log:
Made action numbers from different teams not overlap anymore.

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

Modified: trunk/src/whiteboard/manager.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/manager.cpp?rev=50336&r1=50335&r2=50336&view=diff
==============================================================================
--- trunk/src/whiteboard/manager.cpp (original)
+++ trunk/src/whiteboard/manager.cpp Fri Jul 15 23:45:12 2011
@@ -40,6 +40,7 @@
 #include "team.hpp"
 #include "unit_display.hpp"
 
+#include <boost/lexical_cast.hpp>
 #include <sstream>
 
 namespace wb {
@@ -307,12 +308,66 @@
        }
 }
 
+/* private */
+void draw_numbers(map_location const& hex, side_actions::numbers_t numbers)
+{
+       std::vector<int>& numbers_to_draw = numbers.numbers_to_draw;
+       ///@todo Use team_numbers to color the numbers appropriately.
+//     std::vector<size_t>& team_numbers = numbers.team_numbers;
+       int& main_number = numbers.main_number;
+       std::set<size_t>& secondary_numbers = numbers.secondary_numbers;
+
+       const double x_offset_base = 0.0;
+       const double y_offset_base = 0.2;
+       //position 0,0 in the hex is the upper left corner
+       //0.8 = horizontal coord., close to the right side of the hex
+       const double x_origin = 0.8 - numbers_to_draw.size() * x_offset_base;
+       //0.5 = halfway in the hex vertically
+       const double y_origin = 0.5 - numbers_to_draw.size() * (y_offset_base / 
2);
+       double x_offset = 0, y_offset = 0;
+
+       size_t size = numbers_to_draw.size();
+       for(size_t i=0; i<size; ++i)
+       {
+               int number = numbers_to_draw[i];
+
+               std::string number_text = 
boost::lexical_cast<std::string>(number);
+               size_t font_size;
+               if (int(i) == main_number) font_size = 19;
+               else if (secondary_numbers.find(i)!=secondary_numbers.end()) 
font_size = 17;
+               else font_size = 15;
+
+               ///@todo Use resources::teams->at(team_numbers[i]).color() to 
determine color
+               SDL_Color color; color.r = 255; color.g = 255; color.b = 0; 
//for now, always yellow
+               const double x_in_hex = x_origin + x_offset;
+               const double y_in_hex = y_origin + y_offset;
+               resources::screen->draw_text_in_hex(hex, 
display::LAYER_ACTIONS_NUMBERING,
+                               number_text, font_size, color, x_in_hex, 
y_in_hex);
+               x_offset += x_offset_base;
+               y_offset += y_offset_base;
+       }
+}
+
 void manager::draw_hex(const map_location& hex)
 {
        if (!wait_for_side_init_)
        {
-               foreach(team& t,*resources::teams)
-                       t.get_side_actions()->draw_hex(hex);
+               //Info about the action numbers to be displayed on screen.
+               side_actions::numbers_t numbers;
+
+               //Draw graphics from every team's actions, beginning with the 
current_team.
+               size_t current_team = resources::controller->current_side() - 1;
+               size_t num_teams = resources::teams->size();
+               for(size_t iteration = 0; iteration < num_teams; ++iteration)
+               {
+                       size_t team_index = (current_team+iteration) % 
num_teams;
+                       side_actions& sa = 
*resources::teams->at(team_index).get_side_actions();
+                       foreach(action_ptr act, sa)
+                               act->draw_hex(hex);
+                       sa.get_numbers(hex,numbers);
+               }
+
+               draw_numbers(hex,numbers);
        }
 
        //Little hack to make the TAB key work properly: check at every draw if 
it's pressed,

Modified: trunk/src/whiteboard/side_actions.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/side_actions.cpp?rev=50336&r1=50335&r2=50336&view=diff
==============================================================================
--- trunk/src/whiteboard/side_actions.cpp (original)
+++ trunk/src/whiteboard/side_actions.cpp Fri Jul 15 23:45:12 2011
@@ -76,67 +76,41 @@
        team_index_defined_ = true;
 }
 
-void side_actions::draw_hex(const map_location& hex)
-{
-       std::vector<int> numbers_to_draw;
-       int main_number = -1;
-       std::set<int> secondary_numbers;
+void side_actions::get_numbers(const map_location& hex, numbers_t& result)
+{
+       std::vector<int>& numbers_to_draw = result.numbers_to_draw;
+       std::vector<size_t>& team_numbers = result.team_numbers;
+       int& main_number = result.main_number;
+       std::set<size_t>& secondary_numbers = result.secondary_numbers;
        boost::shared_ptr<highlight_visitor> highlighter =
                                                
resources::whiteboard->get_highlighter().lock();
 
        const_iterator it;
        for(it = begin(); it != end(); ++it)
        {
-               //call the action's own draw_hex method
-               (*it)->draw_hex(hex);
-
                if((*it)->is_numbering_hex(hex))
                {
                        //store number corresponding to iterator's position + 1
                        size_t number = (it - begin()) + 1;
+                       size_t index = numbers_to_draw.size();
                        numbers_to_draw.push_back(number);
+                       team_numbers.push_back(team_index());
+
                        if (highlighter)
                        {
                                if (highlighter->get_main_highlight().lock() == 
*it) {
-                                       main_number = number;
+                                       main_number = index;
                                }
 
                                foreach(weak_action_ptr action, 
highlighter->get_secondary_highlights())
                                {
                                        if (action.lock() == *it)
                                        {
-                                               
secondary_numbers.insert(number);
+                                               secondary_numbers.insert(index);
                                        }
                                }
                        }
                }
-       }
-
-       const double x_offset_base = 0.0;
-       const double y_offset_base = 0.2;
-       //position 0,0 in the hex is the upper left corner
-       //0.8 = horizontal coord., close to the right side of the hex
-       const double x_origin = 0.8 - numbers_to_draw.size() * x_offset_base;
-       //0.5 = halfway in the hex vertically
-       const double y_origin = 0.5 - numbers_to_draw.size() * (y_offset_base / 
2);
-       double x_offset = 0, y_offset = 0;
-       foreach(int number, numbers_to_draw)
-       {
-               std::stringstream number_text;
-               number_text << number;
-               size_t font_size = 15;
-               if (number == main_number) font_size = 19;
-               foreach(int secondary_number, secondary_numbers)
-               {
-                       if (number == secondary_number) font_size = 17;
-               }
-               SDL_Color color; color.r = 255; color.g = 255; color.b = 0; 
//yellow
-               const double x_in_hex = x_origin + x_offset;
-               const double y_in_hex = y_origin + y_offset;
-               resources::screen->draw_text_in_hex(hex, 
display::LAYER_ACTIONS_NUMBERING,
-                               number_text.str(), font_size, color, x_in_hex, 
y_in_hex);
-               x_offset += x_offset_base;
-               y_offset += y_offset_base;
        }
 }
 

Modified: trunk/src/whiteboard/side_actions.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/side_actions.hpp?rev=50336&r1=50335&r2=50336&view=diff
==============================================================================
--- trunk/src/whiteboard/side_actions.hpp (original)
+++ trunk/src/whiteboard/side_actions.hpp Fri Jul 15 23:45:12 2011
@@ -55,8 +55,9 @@
        /// Get the underlying action container
        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);
+       struct numbers_t;
+       /** Gets called when display is drawing a hex to determine which 
numbers to draw on it */
+       void get_numbers(const map_location& hex, numbers_t& result);
 
        /**
         * Executes the first action in the queue, and then deletes it.
@@ -241,6 +242,21 @@
 /** Dumps side_actions on a stream, for debug purposes. */
 std::ostream &operator<<(std::ostream &s, wb::side_actions const& 
side_actions);
 
+struct side_actions::numbers_t
+{
+       std::vector<int> numbers_to_draw;
+       std::vector<size_t> team_numbers;
+       int main_number;
+       std::set<size_t> secondary_numbers;
+
+       numbers_t()
+                       : numbers_to_draw()
+                       , team_numbers()
+                       , main_number(-1)
+                       , secondary_numbers()
+               {}
+};
+
 }
 
 #endif /* WB_SIDE_ACTIONS_HPP_ */


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

Reply via email to