Whiteboard: highlight-on-hover for planned moves
This commit is contained in:
parent
dfedaa5376
commit
edb40ede64
9 changed files with 66 additions and 12 deletions
|
@ -445,6 +445,7 @@ set(wesnoth-main_SRC
|
|||
whiteboard/manager.cpp
|
||||
whiteboard/move.cpp
|
||||
whiteboard/find_visitor.cpp
|
||||
whiteboard/highlight_visitor.cpp
|
||||
whiteboard/mapbuilder_visitor.cpp
|
||||
whiteboard/side_actions.cpp
|
||||
whiteboard/validate_visitor.cpp
|
||||
|
|
|
@ -274,6 +274,7 @@ wesnoth_source = \
|
|||
whiteboard/move.cpp \
|
||||
whiteboard/manager.cpp \
|
||||
whiteboard/find_visitor.cpp \
|
||||
whiteboard/highlight_visitor.cpp \
|
||||
whiteboard/mapbuilder_visitor.cpp \
|
||||
whiteboard/side_actions.cpp \
|
||||
whiteboard/validate_visitor.cpp \
|
||||
|
|
|
@ -259,6 +259,7 @@ wesnoth_sources = Split("""
|
|||
whiteboard/manager.cpp
|
||||
whiteboard/move.cpp
|
||||
whiteboard/find_visitor.cpp
|
||||
whiteboard/highlight_visitor.cpp
|
||||
whiteboard/mapbuilder_visitor.cpp
|
||||
whiteboard/side_actions.cpp
|
||||
whiteboard/validate_visitor.cpp
|
||||
|
|
|
@ -158,6 +158,15 @@ void mouse_handler::mouse_motion(int x, int y, const bool browse, bool update)
|
|||
const unit_map::iterator selected_unit = find_unit(selected_hex_);
|
||||
const unit_map::iterator mouseover_unit = find_unit(new_hex);
|
||||
|
||||
if (resources::whiteboard) {
|
||||
if (update) {
|
||||
resources::whiteboard->remove_highlight();
|
||||
if (mouseover_unit != units_.end()) {
|
||||
resources::whiteboard->highlight_action(*mouseover_unit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// we search if there is an attack possibility and where
|
||||
map_location attack_from = current_unit_attacks_from(new_hex);
|
||||
|
||||
|
|
|
@ -34,10 +34,14 @@ struct temporary_unit_map_modifier;
|
|||
|
||||
namespace wb {
|
||||
|
||||
class action;
|
||||
class visitor;
|
||||
|
||||
typedef boost::shared_ptr<temporary_unit_map_modifier> modifier_ptr;
|
||||
|
||||
typedef boost::shared_ptr<action> action_ptr;
|
||||
|
||||
|
||||
/**
|
||||
* Superclass for all the whiteboard planned actions.
|
||||
*/
|
||||
|
|
|
@ -19,8 +19,10 @@
|
|||
#include "manager.hpp"
|
||||
|
||||
#include "action.hpp"
|
||||
#include "mapbuilder_visitor.hpp"
|
||||
#include "find_visitor.hpp"
|
||||
#include "highlight_visitor.hpp"
|
||||
#include "mapbuilder_visitor.hpp"
|
||||
#include "move.hpp"
|
||||
|
||||
#include "arrow.hpp"
|
||||
#include "foreach.hpp"
|
||||
|
@ -36,18 +38,16 @@ manager::manager():
|
|||
route_(),
|
||||
move_arrow_(),
|
||||
fake_unit_(),
|
||||
selected_unit_(NULL)
|
||||
selected_unit_(NULL),
|
||||
highlighted_action_()
|
||||
{
|
||||
}
|
||||
|
||||
manager::~manager()
|
||||
{
|
||||
if (resources::screen)
|
||||
if (resources::screen && fake_unit_)
|
||||
{
|
||||
if (fake_unit_)
|
||||
{
|
||||
resources::screen->remove_temporary_unit(fake_unit_.get());
|
||||
}
|
||||
resources::screen->remove_temporary_unit(fake_unit_.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,6 +79,28 @@ void manager::remove_temp_modifiers()
|
|||
mapbuilder_.reset();
|
||||
}
|
||||
|
||||
void manager::highlight_action(const unit& unit)
|
||||
{
|
||||
find_visitor finder;
|
||||
highlighted_action_ = finder.find_first_action_of(unit, get_current_side_actions().actions());
|
||||
if (highlighted_action_)
|
||||
{
|
||||
highlight_visitor highlighter(true);
|
||||
highlighted_action_->accept(highlighter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void manager::remove_highlight()
|
||||
{
|
||||
if (highlighted_action_)
|
||||
{
|
||||
highlight_visitor unhighlighter(false);
|
||||
highlighted_action_->accept(unhighlighter);
|
||||
highlighted_action_.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void manager::select_unit(unit& unit)
|
||||
{
|
||||
selected_unit_ = &unit;
|
||||
|
@ -107,7 +129,7 @@ void manager::create_temp_move(const std::vector<map_location> &steps)
|
|||
move_arrow_.reset(new arrow());
|
||||
int current_side = resources::controller->current_side();
|
||||
move_arrow_->set_color(team::get_side_color_index(current_side));
|
||||
move_arrow_->set_alpha(2.0);
|
||||
move_arrow_->set_alpha(move::ALPHA_HIGHLIGHT);
|
||||
resources::screen->add_arrow(*move_arrow_);
|
||||
|
||||
// Create temp ghost unit
|
||||
|
@ -157,7 +179,7 @@ void manager::save_temp_move()
|
|||
<< " from " << selected_unit_->get_location()
|
||||
<< " to " << route_.back() << "\n";
|
||||
|
||||
move_arrow_->set_alpha(0.6);
|
||||
move_arrow_->set_alpha(move::ALPHA_NORMAL);
|
||||
|
||||
get_current_side_actions().queue_move(*selected_unit_, route_.back(), move_arrow_, fake_unit_);
|
||||
move_arrow_.reset();
|
||||
|
|
|
@ -32,6 +32,7 @@ class unit;
|
|||
|
||||
namespace wb {
|
||||
|
||||
class action;
|
||||
class mapbuilder_visitor;
|
||||
|
||||
/**
|
||||
|
@ -57,6 +58,13 @@ public:
|
|||
void apply_temp_modifiers();
|
||||
void remove_temp_modifiers();
|
||||
|
||||
/**
|
||||
* Highlights the action for this unit,
|
||||
* for instance highlights the arrow if it's a move.
|
||||
*/
|
||||
void highlight_action(const unit& unit);
|
||||
void remove_highlight();
|
||||
|
||||
/** Choose the target unit for action creation */
|
||||
void select_unit(unit& unit);
|
||||
void deselect_unit();
|
||||
|
@ -87,6 +95,8 @@ private:
|
|||
boost::shared_ptr<unit> fake_unit_;
|
||||
|
||||
unit* selected_unit_;
|
||||
|
||||
boost::shared_ptr<action> highlighted_action_;
|
||||
};
|
||||
|
||||
} // end namespace wb
|
||||
|
|
|
@ -35,8 +35,12 @@ namespace wb {
|
|||
* A planned move, represented on the map by an arrow and
|
||||
* a ghosted unit in the destination hex.
|
||||
*/
|
||||
class move: public action, public boost::enable_shared_from_this<move>
|
||||
class move : public action, public boost::enable_shared_from_this<move>
|
||||
{
|
||||
public: //constants
|
||||
static const double ALPHA_HIGHLIGHT = 2.0;
|
||||
static const double ALPHA_NORMAL = 0.6;
|
||||
|
||||
public:
|
||||
move(unit& subject, const map_location& target_hex, boost::shared_ptr<arrow> arrow,
|
||||
boost::shared_ptr<unit> fake_unit);
|
||||
|
@ -46,6 +50,8 @@ public:
|
|||
|
||||
unit& get_unit() { return unit_; }
|
||||
|
||||
boost::shared_ptr<arrow> get_arrow() { return arrow_; }
|
||||
|
||||
/**
|
||||
* Applies temporarily the result of this move to the unit map, and returns
|
||||
* the corresponding modifier. Dropping the returned reference will revert
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#ifndef WB_SIDE_ACTIONS_HPP_
|
||||
#define WB_SIDE_ACTIONS_HPP_
|
||||
|
||||
#include "action.hpp"
|
||||
|
||||
#include "map_location.hpp"
|
||||
|
||||
#include <deque>
|
||||
|
@ -31,10 +33,8 @@ class arrow;
|
|||
namespace wb
|
||||
{
|
||||
|
||||
class action;
|
||||
class move;
|
||||
|
||||
typedef boost::shared_ptr<action> action_ptr;
|
||||
typedef std::deque<action_ptr> action_set;
|
||||
|
||||
class side_actions
|
||||
|
|
Loading…
Add table
Reference in a new issue