Whiteboard: Contextual delete of actions. Also fixed up contextual execution.

This commit is contained in:
Gabriel Morin 2010-07-01 10:22:56 +00:00
parent b1b1fa87a4
commit e36e796c79
5 changed files with 60 additions and 12 deletions

View file

@ -452,7 +452,7 @@ void play_controller::execute_next_action(){
}
void play_controller::delete_last_action(){
whiteboard_manager_->delete_last();
whiteboard_manager_->contextual_delete();
}
void play_controller::fire_prestart(bool execute){

View file

@ -68,6 +68,7 @@ void manager::set_planned_unit_map()
{
if (active_)
{
wb_scoped_lock lock(actions_modification_mutex_);
assert (!planned_unit_map_active_);
if (!planned_unit_map_active_)
{
@ -88,6 +89,7 @@ void manager::set_real_unit_map()
{
if (active_)
{
wb_scoped_lock lock(actions_modification_mutex_);
assert (planned_unit_map_active_);
if (planned_unit_map_active_)
{
@ -294,11 +296,11 @@ void manager::contextual_execute()
//TODO: properly handle movement points, probably through the mapbuilder_visitor
current_actions()->set_future_view(false);
if (selected_unit_)
if (selected_unit_ && unit_has_actions(*selected_unit_))
{
current_actions()->execute(current_actions()->find_first_action_of(*selected_unit_));
}
else if (highlighted_unit_)
else if (highlighted_unit_ && unit_has_actions(*highlighted_unit_))
{
current_actions()->execute(current_actions()->find_first_action_of(*highlighted_unit_));
}
@ -312,15 +314,29 @@ void manager::contextual_execute()
}
}
//TODO: transfer most of this function into side_actions
void manager::delete_last()
void manager::contextual_delete()
{
wb_scoped_lock try_lock(actions_modification_mutex_, boost::interprocess::try_to_lock);
if (!try_lock)
return;
if (!current_actions()->empty())
current_actions()->remove_action(current_actions()->end() - 1);
{
if (selected_unit_ && unit_has_actions(*selected_unit_))
{
remove_highlight();
erase_temp_move();
current_actions()->remove_action(current_actions()->find_last_action_of(*selected_unit_));
}
else if (highlighted_unit_ && unit_has_actions(*highlighted_unit_))
{
current_actions()->remove_action(current_actions()->find_last_action_of(*highlighted_unit_));
}
else
{
current_actions()->remove_action(current_actions()->end() - 1);
}
}
}
bool manager::unit_has_actions(const unit& unit) const

View file

@ -93,7 +93,7 @@ public:
void contextual_execute();
/** Deletes last action in the queue for current side */
void delete_last();
void contextual_delete();
/** Checks whether the specified unit has at least one planned action */
bool unit_has_actions(const unit& unit) const;

View file

@ -132,18 +132,44 @@ side_actions::iterator side_actions::get_position_of(action_ptr action)
side_actions::iterator side_actions::find_first_action_of(const unit& unit, side_actions::iterator start_position)
{
if (start_position == side_actions::iterator())
{
start_position = begin();
}
side_actions::iterator position;
for (position = start_position; position != end(); ++position)
if (validate_iterator(start_position))
{
action_ptr& action = *position;
if (&action->get_unit() == &unit)
side_actions::iterator position;
for (position = start_position; position != end(); ++position)
{
return position;
action_ptr& action = *position;
if (&action->get_unit() == &unit)
{
return position;
}
}
}
return end();
}
side_actions::iterator side_actions::find_last_action_of(const unit& unit, side_actions::iterator start_position)
{
if (start_position == side_actions::iterator())
{
start_position = end() - 1;
}
if (validate_iterator(start_position))
{
side_actions::iterator position;
for (position = start_position; position != begin() - 1; --position)
{
action_ptr& action = *position;
if (&action->get_unit() == &unit)
{
return position;
}
}
}
return end();

View file

@ -124,6 +124,12 @@ public:
*/
iterator find_first_action_of(const unit& unit, iterator start_position = iterator());
/**
* Finds the last action that belongs to this unit, starting the search backwards from the specified position.
* @return The position, or end() if not found.
*/
iterator find_last_action_of(const unit& unit, iterator start_position = iterator());
/**
* future_view = true : units are shown at their future positions
* future_view = false: units' future positions are shown with ghosts