Whiteboard: Action execution with the 'y' key.

This commit is contained in:
Gabriel Morin 2010-06-19 00:44:31 +00:00
parent 826134661f
commit d68bf1c9f0
8 changed files with 50 additions and 25 deletions

View file

@ -253,5 +253,9 @@
command=zoomout
key=-
[/hotkey]
[hotkey]
command=executenextaction
key=y
[/hotkey]
#undef IF_APPLE_CMD_ELSE_CTRL

View file

@ -100,6 +100,8 @@ const struct {
{ hotkey::HOTKEY_REPLAY_SHOW_TEAM1, "replayshowteam1",
N_("Team 1"), false, hotkey::SCOPE_GAME },
{ hotkey::HOTKEY_REPLAY_SKIP_ANIMATION, "replayskipanimation", N_("Skip animation"), false, hotkey::SCOPE_GAME },
//@todo 1.9 : unhide whiteboard hotkeys once whiteboard is mature enough
{ hotkey::HOTKEY_EXECUTE_NEXT_ACTION, "executenextaction", N_("Execute next planned action"), false, hotkey::SCOPE_GAME },
#ifndef DISABLE_EDITOR
{ hotkey::HOTKEY_EDITOR_QUIT_TO_DESKTOP, "editor-quit-to-desktop", N_("Quit to Desktop"), false, hotkey::SCOPE_EDITOR },
@ -856,6 +858,9 @@ bool command_executor::execute_command(HOTKEY_COMMAND command, int /*index*/)
case HOTKEY_REPLAY_SKIP_ANIMATION:
replay_skip_animation();
break;
case HOTKEY_EXECUTE_NEXT_ACTION:
execute_next_action();
break;
default:
return false;
}

View file

@ -61,6 +61,9 @@ enum HOTKEY_COMMAND {
HOTKEY_REPLAY_SHOW_EACH, HOTKEY_REPLAY_SHOW_TEAM1,
HOTKEY_REPLAY_SKIP_ANIMATION,
// Whiteboard commands
HOTKEY_EXECUTE_NEXT_ACTION,
#ifndef DISABLE_EDITOR
HOTKEY_EDITOR_QUIT_TO_DESKTOP,
HOTKEY_EDITOR_CLOSE_MAP, HOTKEY_EDITOR_SWITCH_MAP,
@ -296,6 +299,7 @@ public:
virtual void replay_show_each() {}
virtual void replay_show_team1() {}
virtual void replay_skip_animation() {}
virtual void execute_next_action() {}
//Gets the action's image (if any). Displayed left of the action text in menus.
virtual std::string get_action_image(hotkey::HOTKEY_COMMAND /*command*/, int /*index*/) const { return ""; }

View file

@ -447,6 +447,9 @@ void play_controller::search(){
menu_handler_.search();
}
void play_controller::execute_next_action(){
whiteboard_manager_->execute_next();
}
void play_controller::fire_prestart(bool execute){
// Run initialization scripts, even if loading from a snapshot.
@ -771,6 +774,9 @@ bool play_controller::can_execute_command(hotkey::HOTKEY_COMMAND command, int in
menu_handler_.current_unit(mouse_handler_)->side() == gui_->viewing_side() &&
teams_[menu_handler_.current_unit(mouse_handler_)->side() - 1].is_human();
case hotkey::HOTKEY_EXECUTE_NEXT_ACTION:
return resources::whiteboard->active();
default:
return false;
}

View file

@ -97,6 +97,7 @@ public:
virtual void toggle_ellipses();
virtual void toggle_grid();
virtual void search();
virtual void execute_next_action(); //part of whiteboard
virtual void do_init_side(const unsigned int team_index);
virtual void play_side(const unsigned int team_num, bool save) = 0;

View file

@ -211,26 +211,26 @@ void manager::save_temp_move()
//If selected unit already has a move defined, erase it first
// TODO: implement a find_and_erase method in find_visitor to avoid iterating twice over actions
{
action_ptr action = has_action(*selected_unit_);
if (action)
{
//FIXME: temporary for testing: if move created twice on same hex, execute instead
if (dynamic_cast<move*>(action.get())->get_arrow()->get_path().back()
== move_arrow_->get_path().back())
{
get_current_side_actions()->execute(action);
return;
}
else //erase move
{
//TEST: actually, don't erase it :P
// LOG_WB << "Previous action found for unit " << selected_unit_->name() << " [" << selected_unit_->id() << "]"
// << ", erasing action.\n";
// get_current_side_actions()->remove_action(action);
}
}
} // kill action shared_ptr by closing scope
// {
// action_ptr action = has_action(*selected_unit_);
// if (action)
// {
// //FIXME: temporary for testing: if move created twice on same hex, execute instead
// if (dynamic_cast<move*>(action.get())->get_arrow()->get_path().back()
// == move_arrow_->get_path().back())
// {
// get_current_side_actions()->execute(action);
// return;
// }
// else //erase move
// {
// //TEST: actually, don't erase it :P
//// LOG_WB << "Previous action found for unit " << selected_unit_->name() << " [" << selected_unit_->id() << "]"
//// << ", erasing action.\n";
//// get_current_side_actions()->remove_action(action);
// }
// }
// } // kill action shared_ptr by closing scope
//Define the new move
LOG_WB << "Creating move for unit " << selected_unit_->name() << " [" << selected_unit_->id() << "]"
@ -252,9 +252,11 @@ void manager::save_temp_move()
selected_unit_ = NULL;
}
void manager::execute_first()
void manager::execute_next()
{
remove_temp_modifiers();
get_current_side_actions()->execute_first();
apply_temp_modifiers();
}
action_ptr manager::has_action(const unit& unit) const

View file

@ -86,7 +86,7 @@ public:
void save_temp_move();
/** Executes first action in the queue for current side */
void execute_first();
void execute_next();
/** Checks whether the specified unit has at least one planned action,
* and returns the first action found. */

View file

@ -40,9 +40,12 @@ const action_set& side_actions::actions() const
void side_actions::execute_first()
{
actions_.front()->execute();
actions_.pop_front();
//TODO: Validate remaining actions here
if (!actions_.empty())
{
actions_.front()->execute();
actions_.pop_front();
//TODO: Validate remaining actions here
}
}
void side_actions::execute(action_ptr action)