Make the context-menu 'change unit side' allow to change village flag.

(cycle between teams and free. Supposed to fire the event but not tested)
Also rename 'Change unit side' to 'Change side' to better reflect this.
But not sure if not confusing.
This commit is contained in:
Ali El Gariani 2009-04-21 02:06:41 +00:00
parent 5d09f3eeba
commit dfcea60951
6 changed files with 30 additions and 20 deletions

View file

@ -73,7 +73,7 @@ const struct {
{ hotkey::HOTKEY_MUTE, "mute", N_("Mute"), false, hotkey::SCOPE_GENERAL },
{ hotkey::HOTKEY_SPEAK, "speak", N_("Speak"), false, hotkey::SCOPE_GAME },
{ hotkey::HOTKEY_CREATE_UNIT, "createunit", N_("Create Unit (Debug!)"), false, hotkey::SCOPE_GAME },
{ hotkey::HOTKEY_CHANGE_UNIT_SIDE, "changeside", N_("Change Unit Side (Debug!)"), false, hotkey::SCOPE_GAME },
{ hotkey::HOTKEY_CHANGE_SIDE, "changeside", N_("Change Side (Debug!)"), false, hotkey::SCOPE_GAME },
{ hotkey::HOTKEY_PREFERENCES, "preferences", N_("Preferences"), false, hotkey::SCOPE_GENERAL },
{ hotkey::HOTKEY_OBJECTIVES, "objectives", N_("Scenario Objectives"), false, hotkey::SCOPE_GAME },
{ hotkey::HOTKEY_UNIT_LIST, "unitlist", N_("Unit List"), false, hotkey::SCOPE_GAME },
@ -751,8 +751,8 @@ bool command_executor::execute_command(HOTKEY_COMMAND command, int /*index*/)
case HOTKEY_CREATE_UNIT:
create_unit();
break;
case HOTKEY_CHANGE_UNIT_SIDE:
change_unit_side();
case HOTKEY_CHANGE_SIDE:
change_side();
break;
case HOTKEY_PREFERENCES:
preferences();

View file

@ -50,7 +50,7 @@ enum HOTKEY_COMMAND {
HOTKEY_SAVE_GAME, HOTKEY_SAVE_REPLAY, HOTKEY_SAVE_MAP, HOTKEY_LOAD_GAME,
HOTKEY_RECRUIT, HOTKEY_REPEAT_RECRUIT, HOTKEY_RECALL, HOTKEY_ENDTURN,
HOTKEY_TOGGLE_GRID, HOTKEY_STATUS_TABLE, HOTKEY_MUTE, HOTKEY_MOUSE_SCROLL,
HOTKEY_SPEAK, HOTKEY_CREATE_UNIT, HOTKEY_CHANGE_UNIT_SIDE, HOTKEY_PREFERENCES,
HOTKEY_SPEAK, HOTKEY_CREATE_UNIT, HOTKEY_CHANGE_SIDE, HOTKEY_PREFERENCES,
HOTKEY_OBJECTIVES, HOTKEY_UNIT_LIST, HOTKEY_STATISTICS, HOTKEY_STOP_NETWORK, HOTKEY_START_NETWORK, HOTKEY_QUIT_GAME,
HOTKEY_LABEL_TEAM_TERRAIN, HOTKEY_LABEL_TERRAIN, HOTKEY_CLEAR_LABELS,HOTKEY_SHOW_ENEMY_MOVES, HOTKEY_BEST_ENEMY_MOVES,
HOTKEY_DELAY_SHROUD, HOTKEY_UPDATE_SHROUD, HOTKEY_CONTINUE_MOVE,
@ -262,7 +262,7 @@ public:
virtual void whisper() {}
virtual void shout() {}
virtual void create_unit() {}
virtual void change_unit_side() {}
virtual void change_side() {}
virtual void preferences() {}
virtual void objectives() {}
virtual void unit_list() {}

View file

@ -1424,20 +1424,30 @@ private:
}
}
void menu_handler::change_unit_side(mouse_handler& mousehandler)
void menu_handler::change_side(mouse_handler& mousehandler)
{
const unit_map::iterator i = units_.find(mousehandler.get_last_hex());
const map_location& loc = mousehandler.get_last_hex();
const unit_map::iterator i = units_.find(loc);
if(i == units_.end()) {
return;
}
if(!map_.is_village(loc))
return;
int side = i->second.side();
++side;
if(side > team::nteams()) {
side = 1;
// village_owner returns -1 for free village, so side 0 will get it
int side = village_owner(loc, teams_) + 1;
// side is 0-based so side=team::nteams() is not a side
// but this will make get_village free it
if(side > team::nteams()) {
side = 0;
}
get_village(loc, *gui_, teams_, side, units_);
} else {
int side = i->second.side();
++side;
if(side > team::nteams()) {
side = 1;
}
i->second.set_side(side);
}
i->second.set_side(side);
}
void menu_handler::label_terrain(mouse_handler& mousehandler, bool team_only)

View file

@ -89,7 +89,7 @@ public:
void unit_description(mouse_handler& mousehandler);
void rename_unit(mouse_handler& mousehandler);
void create_unit(mouse_handler& mousehandler);
void change_unit_side(mouse_handler& mousehandler);
void change_side(mouse_handler& mousehandler);
void label_terrain(mouse_handler& mousehandler, bool team_only);
void clear_labels();
void continue_move(mouse_handler& mousehandler, const unsigned int team_num);

View file

@ -133,8 +133,8 @@ void playsingle_controller::create_unit(){
menu_handler_.create_unit(mouse_handler_);
}
void playsingle_controller::change_unit_side(){
menu_handler_.change_unit_side(mouse_handler_);
void playsingle_controller::change_side(){
menu_handler_.change_side(mouse_handler_);
}
void playsingle_controller::label_terrain(bool team_only){
@ -885,7 +885,7 @@ bool playsingle_controller::can_execute_command(hotkey::HOTKEY_COMMAND command,
// Commands we can only do if in debug mode
case hotkey::HOTKEY_CREATE_UNIT:
case hotkey::HOTKEY_CHANGE_UNIT_SIDE:
case hotkey::HOTKEY_CHANGE_SIDE:
return !events::commands_disabled && game_config::debug && map_.on_board(mouse_handler_.get_last_hex());
case hotkey::HOTKEY_LABEL_TEAM_TERRAIN:

View file

@ -47,7 +47,7 @@ public:
virtual void end_turn();
virtual void rename_unit();
virtual void create_unit();
virtual void change_unit_side();
virtual void change_side();
virtual void label_terrain(bool);
virtual void continue_move();
virtual void unit_hold_position();