Whiteboard: Block 'select' event on units that...

...have a planned action defined. WB still crashes on exit.
This commit is contained in:
Gabriel Morin 2010-06-17 02:28:07 +00:00
parent 91d47a0da5
commit 2a370d0796
3 changed files with 41 additions and 5 deletions

View file

@ -554,7 +554,23 @@ void mouse_handler::select_hex(const map_location& hex, const bool browse) {
if (!browse && !commands_disabled && u->side() == gui().viewing_side()) {
sound::play_UI_sound("select-unit.wav");
u->set_selecting();
game_events::fire("select", hex);
if (!(resources::whiteboard->active() && resources::whiteboard->has_action(*u))) {
bool modifiers_applied = false;
if (resources::whiteboard->active()) {
modifiers_applied = resources::whiteboard->temp_modifiers_applied();
if (modifiers_applied) {
resources::whiteboard->remove_temp_modifiers();
}
}
game_events::fire("select", hex);
if (resources::whiteboard->active() && modifiers_applied) {
resources::whiteboard->apply_temp_modifiers();
}
}
if (resources::whiteboard->active()) {
resources::whiteboard->select_unit(*u);
}

View file

@ -90,6 +90,14 @@ void manager::remove_temp_modifiers()
temp_modifiers_applied_ = false;
}
void manager::toggle_temp_modifiers()
{
if (temp_modifiers_applied_)
remove_temp_modifiers();
else
apply_temp_modifiers();
}
void manager::highlight_action(const unit& unit)
{
find_visitor finder;
@ -171,7 +179,7 @@ void manager::create_temp_move(const std::vector<map_location> &steps)
}
}
bool manager::has_temp_move()
bool manager::during_move_creation() const
{
bool has_it = selected_unit_ != NULL;
return has_it;
@ -203,8 +211,7 @@ void manager::save_temp_move()
// TODO: implement a find_and_erase method in find_visitor to avoid iterating twice over actions
{
find_visitor finder;
action_ptr action = finder.find_first_action_of(*selected_unit_, get_current_side_actions()->actions());
action_ptr action = has_action(*selected_unit_);
if (action)
{
//FIXME: temporary for testing: if move created twice on same hex, execute instead
@ -247,4 +254,11 @@ void manager::execute_first()
get_current_side_actions()->execute_first();
}
action_ptr manager::has_action(const unit& unit) const
{
find_visitor finder;
action_ptr action = finder.find_first_action_of(unit, get_current_side_actions()->actions());
return action;
}
} // end namespace wb

View file

@ -57,6 +57,8 @@ public:
*/
void apply_temp_modifiers();
void remove_temp_modifiers();
void toggle_temp_modifiers();
bool temp_modifiers_applied() { return temp_modifiers_applied_; }
/**
* Highlights the action for this unit,
@ -72,7 +74,7 @@ public:
/** Creates a temporary visual arrow, that follows the cursor, for move creation purposes */
void create_temp_move(const std::vector<map_location> &steps);
/** Informs whether an arrow is being displayed for move creation purposes */
bool has_temp_move();
bool during_move_creation() const;
void erase_temp_move();
@ -86,6 +88,10 @@ public:
/** Executes first action in the queue for current side */
void execute_first();
/** Checks whether the specified unit has at least one planned action,
* and returns the first action found. */
boost::shared_ptr<action> has_action(const unit& unit) const;
private:
/**
* Tracks whether the whiteboard is active.