hotkey_handler: add some helper functions to clean up syntax

This commit is contained in:
Chris Beck 2014-12-22 01:34:06 -05:00
parent ec22a8645a
commit 736bf298c0
3 changed files with 15 additions and 7 deletions

View file

@ -56,6 +56,9 @@ game_display * play_controller::hotkey_handler::gui() const {
bool play_controller::hotkey_handler::browse() const { return play_controller_.is_browsing(); }
bool play_controller::hotkey_handler::linger() const { return play_controller_.is_lingering(); }
const team & play_controller::hotkey_handler::viewing_team() const { return play_controller_.get_teams_const()[gui()->viewing_team()]; }
bool play_controller::hotkey_handler::viewing_team_is_playing() const { return gui()->viewing_team() == gui()->playing_team(); }
void play_controller::hotkey_handler::objectives(){
menu_handler_.objectives(gui()->viewing_team()+1);
}
@ -422,8 +425,8 @@ void play_controller::hotkey_handler::show_menu(const std::vector<std::string>&
}
// Remove WML commands if they would not be allowed here
if(*i == "wml") {
if(!context_menu || gui()->viewing_team() != gui()->playing_team()
|| events::commands_disabled || !play_controller_.get_teams_const()[gui()->viewing_team()].is_local_human()
if(!context_menu || !viewing_team_is_playing()
|| events::commands_disabled || !viewing_team().is_local_human()
|| (linger() && !game_config::debug)){
i = items.erase(i);
continue;
@ -513,7 +516,7 @@ hotkey::ACTION_STATE play_controller::hotkey_handler::get_action_state(hotkey::H
case hotkey::HOTKEY_ZOOM_DEFAULT:
return (gui()->get_zoom_factor() == 1.0) ? hotkey::ACTION_ON : hotkey::ACTION_OFF;
case hotkey::HOTKEY_DELAY_SHROUD:
return gamestate_.board_.teams()[gui()->viewing_team()].auto_shroud_updates() ? hotkey::ACTION_OFF : hotkey::ACTION_ON;
return viewing_team().auto_shroud_updates() ? hotkey::ACTION_OFF : hotkey::ACTION_ON;
default:
return hotkey::ACTION_STATELESS;
}

View file

@ -35,6 +35,8 @@ class game_state;
class saved_game;
class wmi_pager;
class team;
class play_controller::hotkey_handler : public hotkey::command_executor {
protected:
@ -68,6 +70,9 @@ protected:
bool browse() const;
bool linger() const;
const team & viewing_team() const;
bool viewing_team_is_playing() const;
public:
hotkey_handler(play_controller &, saved_game &, game_state &);
~hotkey_handler();

View file

@ -188,7 +188,7 @@ bool playsingle_controller::hotkey_handler::can_execute_command(const hotkey::ho
case hotkey::HOTKEY_WML:
//code mixed from play_controller::show_menu and code here
return (gui()->viewing_team() == gui()->playing_team()) && !events::commands_disabled && play_controller_.get_teams_const()[gui()->viewing_team()].is_local_human() && !linger() && !browse();
return viewing_team_is_playing() && !events::commands_disabled && viewing_team().is_local_human() && !linger() && !browse();
case hotkey::HOTKEY_UNIT_HOLD_POSITION:
case hotkey::HOTKEY_END_UNIT_TURN:
return !browse() && !linger() && !events::commands_disabled;
@ -200,13 +200,13 @@ bool playsingle_controller::hotkey_handler::can_execute_command(const hotkey::ho
return (!browse() || linger()) && !events::commands_disabled;
case hotkey::HOTKEY_DELAY_SHROUD:
return !linger() && (play_controller_.get_teams_const()[gui()->viewing_team()].uses_fog() || play_controller_.get_teams_const()[gui()->viewing_team()].uses_shroud())
return !linger() && (viewing_team().uses_fog() || viewing_team().uses_shroud())
&& !events::commands_disabled;
case hotkey::HOTKEY_UPDATE_SHROUD:
return !linger()
&& play_controller_.current_side() == gui()->viewing_side()
&& viewing_team_is_playing()
&& !events::commands_disabled
&& play_controller_.get_teams_const()[gui()->viewing_team()].auto_shroud_updates() == false;
&& viewing_team().auto_shroud_updates() == false;
// Commands we can only do if in debug mode
case hotkey::HOTKEY_CREATE_UNIT: