mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-07 09:14:21 +00:00
Arrows: solved problem with setting color or other parameter...
...before the path was valid. Also, in the past few commits I moved some members to "protected" instead of "private", to allow subclassing. Whiteboard: adapted to the change of interface in arrows. Now setting the arrows to white during creation, then to team color when created.
This commit is contained in:
parent
5cf0ff90c4
commit
0d45df6bec
@ -31,34 +31,54 @@ static lg::log_domain log_arrows("arrows");
|
||||
#define DBG_ARR LOG_STREAM(debug, log_arrows)
|
||||
|
||||
arrow::arrow(display* screen)
|
||||
:screen_(screen), layer_(display::LAYER_ARROWS), color_("red"), style_("")
|
||||
:screen_(screen),
|
||||
layer_(display::LAYER_ARROWS),
|
||||
color_("red"),
|
||||
style_("")
|
||||
{
|
||||
}
|
||||
|
||||
void arrow::set_path(const arrow_path_t &path)
|
||||
bool arrow::set_path(const arrow_path_t &path)
|
||||
{
|
||||
previous_path_ = path_;
|
||||
path_ = path;
|
||||
update_symbols(previous_path_);
|
||||
if (valid_path())
|
||||
{
|
||||
update_symbols(previous_path_);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void arrow::set_color(const std::string& color)
|
||||
{
|
||||
color_ = color;
|
||||
update_symbols(path_);
|
||||
if (valid_path())
|
||||
{
|
||||
update_symbols(path_);
|
||||
}
|
||||
}
|
||||
|
||||
void arrow::set_style(const std::string& style)
|
||||
{
|
||||
style_ = style;
|
||||
update_symbols(path_);
|
||||
if (valid_path())
|
||||
{
|
||||
update_symbols(path_);
|
||||
}
|
||||
}
|
||||
|
||||
void arrow::set_layer(const display::tdrawing_layer & layer)
|
||||
{
|
||||
layer_ = layer;
|
||||
invalidate_arrow_path(path_);
|
||||
notify_arrow_changed();
|
||||
if (valid_path())
|
||||
{
|
||||
invalidate_arrow_path(path_);
|
||||
notify_arrow_changed();
|
||||
}
|
||||
}
|
||||
|
||||
const arrow_path_t & arrow::get_path() const
|
||||
@ -66,7 +86,6 @@ const arrow_path_t & arrow::get_path() const
|
||||
return path_;
|
||||
}
|
||||
|
||||
|
||||
const arrow_path_t & arrow::get_previous_path() const
|
||||
{
|
||||
return previous_path_;
|
||||
@ -78,6 +97,14 @@ void arrow::draw_hex(const map_location & loc)
|
||||
loc, image::get_image(symbols_map_[loc], image::SCALED_TO_ZOOM));
|
||||
}
|
||||
|
||||
bool arrow::valid_path() const
|
||||
{
|
||||
if (path_.size() >= 2)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void arrow::add_observer(arrow_observer & observer)
|
||||
{
|
||||
observers_.push_back(&observer);
|
||||
@ -90,6 +117,12 @@ void arrow::remove_observer(arrow_observer & observer)
|
||||
|
||||
void arrow::update_symbols(arrow_path_t old_path)
|
||||
{
|
||||
if (!valid_path())
|
||||
{
|
||||
WRN_ARR << "arrow::update_symbols called with invalid path\n";
|
||||
return;
|
||||
}
|
||||
|
||||
foreach(map_location loc, old_path)
|
||||
{
|
||||
symbols_map_.erase(loc);
|
||||
|
@ -47,7 +47,8 @@ public:
|
||||
notify_arrow_deleted();
|
||||
}
|
||||
|
||||
virtual void set_path(const arrow_path_t &path);
|
||||
/// returns false if the received path is invalid
|
||||
virtual bool set_path(const arrow_path_t &path);
|
||||
|
||||
/**
|
||||
* The string color parameter is in the same format expected by the
|
||||
@ -72,6 +73,9 @@ public:
|
||||
|
||||
void draw_hex(const map_location & hex);
|
||||
|
||||
/// Checks that the path is not of length 0 or 1
|
||||
bool valid_path() const;
|
||||
|
||||
void add_observer(arrow_observer & observer);
|
||||
|
||||
void remove_observer(arrow_observer & observer);
|
||||
@ -84,16 +88,16 @@ protected:
|
||||
*/
|
||||
void update_symbols(arrow_path_t old_path);
|
||||
|
||||
void invalidate_arrow_path(arrow_path_t path);
|
||||
|
||||
private:
|
||||
//operations
|
||||
|
||||
void invalidate_arrow_path(arrow_path_t path);
|
||||
|
||||
void notify_arrow_changed();
|
||||
|
||||
void notify_arrow_deleted();
|
||||
|
||||
private:
|
||||
protected:
|
||||
//properties
|
||||
|
||||
display* screen_;
|
||||
@ -110,6 +114,8 @@ private:
|
||||
|
||||
arrow_symbols_map_t symbols_map_;
|
||||
|
||||
private:
|
||||
//properties
|
||||
std::list<arrow_observer*> observers_;
|
||||
|
||||
};
|
||||
|
@ -58,18 +58,25 @@ void manager::set_route(const std::vector<map_location> &steps)
|
||||
{
|
||||
display *screen = (display*) resources::screen;
|
||||
move_arrow_ = new arrow(screen);
|
||||
move_arrow_->set_color("white");
|
||||
screen->add_arrow(*move_arrow_);
|
||||
}
|
||||
|
||||
move_arrow_->set_path(route_);
|
||||
}
|
||||
}
|
||||
|
||||
void manager::create_move_from_route(unit& subject)
|
||||
{
|
||||
team& current_team = (*resources::teams)[resources::controller->current_side()];
|
||||
int current_side = resources::controller->current_side();
|
||||
team& current_team = (*resources::teams)[current_side];
|
||||
|
||||
LOG_WB << "Creating move for unit " << subject.name() << " [" << subject.id() << "]"
|
||||
<< " from " << subject.get_location()
|
||||
<< " to " << route_.back() << "\n";
|
||||
|
||||
move_arrow_->set_color(team::get_side_color_index(current_side));
|
||||
|
||||
current_team.get_side_actions().queue_move(subject, route_.back(), *move_arrow_);
|
||||
//ownership of the arrow transferred to the new move action
|
||||
move_arrow_ = NULL;
|
||||
|
@ -45,7 +45,6 @@ public:
|
||||
* Determine whether the whiteboard is activated.
|
||||
*/
|
||||
bool active(){ return active_; }
|
||||
|
||||
void set_active(bool active){ active_ = active; }
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user