Whiteboard: various tweaks and moving code around.
This commit is contained in:
parent
7600ee4943
commit
653a9d0616
6 changed files with 65 additions and 61 deletions
|
@ -51,18 +51,19 @@ public:
|
|||
/** 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;
|
||||
|
||||
|
|
|
@ -32,10 +32,17 @@
|
|||
#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),
|
||||
mapbuilder_(),
|
||||
|
@ -47,20 +54,13 @@ manager::manager():
|
|||
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()
|
||||
{
|
||||
if (active_)
|
||||
|
@ -98,26 +98,7 @@ void manager::set_real_unit_map()
|
|||
|
||||
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 @@ void manager::on_mouseover_change(const map_location& hex)
|
|||
// 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 @@ void manager::contextual_execute()
|
|||
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_)
|
||||
else if (highlighter_
|
||||
&& (action = highlighter_->get_execute_target())) //intentional assignment of action with '='
|
||||
{
|
||||
action_ptr action = highlighter_->get_execute_target();
|
||||
if (action)
|
||||
{
|
||||
current_actions()->execute(current_actions()->get_position_of(action));
|
||||
}
|
||||
current_actions()->execute(current_actions()->get_position_of(action));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -283,17 +258,14 @@ void manager::contextual_delete()
|
|||
{
|
||||
erase_temp_move();
|
||||
|
||||
action_ptr action;
|
||||
if (selected_unit_)
|
||||
{
|
||||
current_actions()->remove_action(current_actions()->find_first_action_of(*selected_unit_));
|
||||
current_actions()->remove_action(current_actions()->find_first_action_of(*selected_unit_));
|
||||
}
|
||||
else if (highlighter_)
|
||||
else if (highlighter_ && (action = highlighter_->get_delete_target()))
|
||||
{
|
||||
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()->get_position_of(action));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -149,7 +149,7 @@ void move::apply_temp_modifier(unit_map& unit_map)
|
|||
//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 @@ void move::remove_temp_modifier(unit_map& unit_map)
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,10 @@ public:
|
|||
/** 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);
|
||||
|
|
|
@ -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 @@ side_actions::~side_actions()
|
|||
{
|
||||
}
|
||||
|
||||
const action_queue& side_actions::actions() const
|
||||
void side_actions::draw_hex(const map_location& hex)
|
||||
{
|
||||
return actions_;
|
||||
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()
|
||||
|
|
|
@ -42,7 +42,10 @@ public:
|
|||
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.
|
||||
|
|
Loading…
Add table
Reference in a new issue