New controll hotkey actions for the base game handling.

This commit is contained in:
fendrin 2013-11-27 02:15:32 +01:00
parent f85d83a5d7
commit 7e46df9191
6 changed files with 295 additions and 47 deletions

View file

@ -67,8 +67,10 @@ namespace hotkey {
hotkey_command_temp hotkey_list_[] = {
{ hotkey::HOTKEY_CANCEL, N_("cancel"), N_("Cancel"), false, hotkey::SCOPE_GENERAL, "" },
{ hotkey::HOTKEY_LEFT_MOUSE_CLICK, "leftmouseclick", N_("Left Mouse Click"), false, hotkey::SCOPE_GENERAL, "" },
{ hotkey::HOTKEY_RIGHT_MOUSE_CLICK, "rightmouseclick", N_("Right Mouse Click"), false, hotkey::SCOPE_GENERAL, "" },
{ hotkey::HOTKEY_SELECT_HEX, "selecthex", N_("Select Hex"), false, hotkey::SCOPE_GAME, "" },
{ hotkey::HOTKEY_DESELECT_HEX, "deselecthex", N_("Deselect Hex"), false, hotkey::SCOPE_GAME, "" },
{ hotkey::HOTKEY_MOVE_ACTION, "moveaction", N_("Move/Attack"), false, hotkey::SCOPE_GAME, "" },
{ hotkey::HOTKEY_SELECT_AND_ACTION, "selectmoveaction", N_("Select/Move/Attack"), false, hotkey::SCOPE_GAME, "" },
{ hotkey::HOTKEY_ANIMATE_MAP, "animatemap", N_("Animate Map"), false, hotkey::SCOPE_GENERAL, "" },
{ hotkey::HOTKEY_CYCLE_UNITS, "cycle", N_("Next Unit"), false, hotkey::SCOPE_GAME, "" },
{ hotkey::HOTKEY_CYCLE_BACK_UNITS, "cycleback", N_("Previous Unit"), false, hotkey::SCOPE_GAME, "" },
@ -1314,11 +1316,17 @@ bool command_executor::execute_command(const hotkey_command& cmd, int /*index*/
case HOTKEY_WB_SUPPOSE_DEAD:
whiteboard_suppose_dead();
break;
case HOTKEY_LEFT_MOUSE_CLICK:
left_mouse_click();
case HOTKEY_SELECT_HEX:
select_hex();
break;
case HOTKEY_RIGHT_MOUSE_CLICK:
right_mouse_click();
case HOTKEY_DESELECT_HEX:
deselect_hex();
break;
case HOTKEY_MOVE_ACTION:
move_action();
break;
case HOTKEY_SELECT_AND_ACTION:
select_and_action();
break;
case HOTKEY_ACCELERATED:
toggle_accelerated_speed();

View file

@ -72,7 +72,8 @@ enum HOTKEY_COMMAND {
HOTKEY_REPLAY_SHOW_EACH, HOTKEY_REPLAY_SHOW_TEAM1,
HOTKEY_REPLAY_SKIP_ANIMATION,
HOTKEY_ANIMATE_MAP,
HOTKEY_LEFT_MOUSE_CLICK, HOTKEY_RIGHT_MOUSE_CLICK,
HOTKEY_SELECT_HEX, HOTKEY_DESELECT_HEX,
HOTKEY_MOVE_ACTION, HOTKEY_SELECT_AND_ACTION,
HOTKEY_CANCEL, HOTKEY_OKAY,
// Whiteboard commands
@ -469,6 +470,10 @@ public:
virtual void whiteboard_bump_up_action() {}
virtual void whiteboard_bump_down_action() {}
virtual void whiteboard_suppose_dead() {}
virtual void select_hex() {}
virtual void deselect_hex() {}
virtual void move_action() {}
virtual void select_and_action() {}
virtual void left_mouse_click() {}
virtual void right_mouse_click() {}
virtual void toggle_accelerated_speed() {}

View file

@ -421,42 +421,68 @@ void mouse_handler::mouse_press(const SDL_MouseButtonEvent& event, const bool br
mouse_handler_base::mouse_press(event, browse);
}
bool mouse_handler::right_click_show_menu(int x, int y, const bool browse)
bool mouse_handler::right_click_show_menu(int x, int y, const bool /*browse*/)
{
// The first right-click cancel the selection if any,
// the second open the context menu
unit_map::iterator unit;
{
wb::future_map_if_active raii;
unit = find_unit(selected_hex_);
}
if (selected_hex_.valid() && unit != units_.end()) {
select_hex(map_location(), browse);
// unit_map::iterator unit;
// {
// wb::future_map_if_active raii;
// unit = find_unit(selected_hex_);
// }
if (selected_hex_.valid() && selected_hex_ != last_hex_) { // && unit != units_.end()) {
// select_hex(map_location(), browse);
return false;
} else {
return point_in_rect(x, y, gui().map_area());
}
return false;
}
bool mouse_handler::left_click(int x, int y, const bool browse)
void mouse_handler::select_or_action()
{
if (mouse_handler_base::left_click(x, y, browse)) return false;
unit_map::iterator clicked_u = find_unit(last_hex_);
if (clicked_u != resources::units->end() && clicked_u->side() == side_num_)
select_hex(last_hex_, true);
else
move_action();
}
// Lock whiteboard activation state to avoid problems due to
// its changing while an animation takes place.
void mouse_handler::move_action()
{
bool browse = false;
// if (mouse_handler_base::left_click(x, y, browse)) return false;
//
// // Clicks on border hexes mean to deselect.
// // (Check this before doing processing that might not be needed.)
// if ( !resources::game_map->on_board(hex) ) {
// deselect_hex();
// return false;
// }
//
// if (hex == selected_hex_)
// deselect_hex();
// else
// select_hex(hex, browse);
// return false;
// // Lock whiteboard activation state to avoid problems due to
// // its changing while an animation takes place.
wb::whiteboard_lock wb_lock = resources::whiteboard->get_activation_state_lock();
//we use the last registered highlighted hex
//since it's what update our global state
//
// //we use the last registered highlighted hex
// //since it's what update our global state
map_location hex = last_hex_;
// Clicks on border hexes mean to deselect.
// (Check this before doing processing that might not be needed.)
if ( !resources::game_map->on_board(hex) ) {
deselect_hex();
return false;
}
//
// // Clicks on border hexes mean to deselect.
// // (Check this before doing processing that might not be needed.)
// if ( !resources::game_map->on_board(hex) ) {
// deselect_hex();
// return false;
// }
//
unit_map::iterator u;
unit_map::iterator clicked_u;
map_location src;
@ -484,7 +510,7 @@ bool mouse_handler::left_click(int x, int y, const bool browse)
// Ignore this command if commands are disabled.
if ( commands_disabled )
return false;
return;
if (((u.valid() && u->side() == side_num_) || resources::whiteboard->is_active()) && clicked_u.valid() ) {
if (attack_from == selected_hex_) { //no move needed
@ -499,7 +525,7 @@ bool mouse_handler::left_click(int x, int y, const bool browse)
attack_enemy(u->get_location(), clicked_u->get_location(), choice);
}
}
return false;
return;
}
else {
@ -512,7 +538,7 @@ bool mouse_handler::left_click(int x, int y, const bool browse)
if(itor == current_paths_.destinations.end()) {
// can't reach the attacking location
// not supposed to happen, so abort
return false;
return;
}
// block where we temporary move the unit
@ -524,7 +550,7 @@ bool mouse_handler::left_click(int x, int y, const bool browse)
if (choice < 0) {
// user hit cancel, don't start move+attack
return false;
return;
}
} // end planned unit map scope
@ -536,7 +562,7 @@ bool mouse_handler::left_click(int x, int y, const bool browse)
}
//TODO: Maybe store the attack choice so "press t to continue"
// can also continue the attack?
return false;
return;
}
}
}
@ -551,7 +577,7 @@ bool mouse_handler::left_click(int x, int y, const bool browse)
// Ignore this command if commands are disabled.
if ( commands_disabled )
return false;
return;
// If the whiteboard is active, it intercepts any unit movement
if (resources::whiteboard->is_active()) {
@ -572,7 +598,7 @@ bool mouse_handler::left_click(int x, int y, const bool browse)
//Don't move if the unit already has actions
//from the whiteboard.
if (resources::whiteboard->unit_has_actions(&*u)) {
return false;
return;
}
move_unit_along_current_route();
@ -583,28 +609,204 @@ bool mouse_handler::left_click(int x, int y, const bool browse)
select_hex(selected_hex_, browse);
}
}
return false;
return;
} else if(!commands_disabled) {
// we select a (maybe empty) hex
// we block selection during attack+move (because motion is blocked)
select_hex(hex, browse);
// select_hex(hex, browse);
}
return false;
//return false;
//FIXME: clean all these "return false"
}
//bool mouse_handler::left_click(int x, int y, const bool browse)
//{
// if (mouse_handler_base::left_click(x, y, browse)) return false;
// map_location hex = last_hex_;
//
// // Clicks on border hexes mean to deselect.
// // (Check this before doing processing that might not be needed.)
// if ( !resources::game_map->on_board(hex) ) {
// deselect_hex();
// return false;
// }
//
// if (hex == selected_hex_)
// deselect_hex();
// else
// select_hex(hex, browse);
// return false;
// // Lock whiteboard activation state to avoid problems due to
// // its changing while an animation takes place.
// wb::whiteboard_lock wb_lock = resources::whiteboard->get_activation_state_lock();
//
// //we use the last registered highlighted hex
// //since it's what update our global state
// map_location hex = last_hex_;
//
// // Clicks on border hexes mean to deselect.
// // (Check this before doing processing that might not be needed.)
// if ( !resources::game_map->on_board(hex) ) {
// deselect_hex();
// return false;
// }
//
// unit_map::iterator u;
// unit_map::iterator clicked_u;
// map_location src;
// pathfind::paths orig_paths;
// map_location attack_from;
// { // start planned unit map scope
// wb::future_map_if_active planned_unit_map;
// u = find_unit(selected_hex_);
//
// //if the unit is selected and then itself clicked on,
// //any goto command is canceled
// if (u != units_.end() && !browse && selected_hex_ == hex && u->side() == side_num_) {
// u->set_goto(map_location());
// }
//
// clicked_u = find_unit(hex);
//
// src = selected_hex_;
// orig_paths = current_paths_;
// attack_from = current_unit_attacks_from(hex);
// } // end planned unit map scope
//
// //see if we're trying to do a attack or move-and-attack
// if((!browse || resources::whiteboard->is_active()) && attack_from.valid()) {
//
// // Ignore this command if commands are disabled.
// if ( commands_disabled )
// return false;
//
// if (((u.valid() && u->side() == side_num_) || resources::whiteboard->is_active()) && clicked_u.valid() ) {
// if (attack_from == selected_hex_) { //no move needed
// int choice = -1;
// { wb::future_map_if_active planned_unit_map; //start planned unit map scope
// choice = show_attack_dialog(attack_from, clicked_u->get_location());
// } // end planned unit map scope
// if (choice >=0 ) {
// if (resources::whiteboard->is_active()) {
// save_whiteboard_attack(attack_from, clicked_u->get_location(), choice);
// } else {
// attack_enemy(u->get_location(), clicked_u->get_location(), choice);
// }
// }
// return false;
// }
// else {
//
// int choice = -1; //for the attack dialog
//
// { wb::future_map_if_active planned_unit_map; //start planned unit map scope
// // we will now temporary move next to the enemy
// pathfind::paths::dest_vect::const_iterator itor =
// current_paths_.destinations.find(attack_from);
// if(itor == current_paths_.destinations.end()) {
// // can't reach the attacking location
// // not supposed to happen, so abort
// return false;
// }
//
// // block where we temporary move the unit
// {
// temporary_unit_mover temp_mover(units_, src, attack_from,
// itor->move_left);
// choice = show_attack_dialog(attack_from, clicked_u->get_location());
// }
//
// if (choice < 0) {
// // user hit cancel, don't start move+attack
// return false;
// }
// } // end planned unit map scope
//
// if (resources::whiteboard->is_active()) {
// save_whiteboard_attack(attack_from, hex, choice);
// }
// else if ( move_unit_along_current_route() ) {
// attack_enemy(attack_from, hex, choice); // Fight !!
// }
// //TODO: Maybe store the attack choice so "press t to continue"
// // can also continue the attack?
// return false;
// }
// }
// }
// //otherwise we're trying to move to a hex
// else if((!browse || resources::whiteboard->is_active()) &&
// selected_hex_.valid() && selected_hex_ != hex &&
// u != units_.end() && u.valid() &&
// (u->side() == side_num_ || resources::whiteboard->is_active()) &&
// clicked_u == units_.end() &&
// !current_route_.steps.empty() &&
// current_route_.steps.front() == selected_hex_) {
//
// // Ignore this command if commands are disabled.
// if ( commands_disabled )
// return false;
//
// // If the whiteboard is active, it intercepts any unit movement
// if (resources::whiteboard->is_active()) {
// // deselect the current hex, and create planned move for whiteboard
// selected_hex_ = map_location();
// gui().select_hex(map_location());
// gui().clear_attack_indicator();
// gui().set_route(NULL);
// show_partial_move_ = false;
// gui().unhighlight_reach();
// current_paths_ = pathfind::paths();
// current_route_.steps.clear();
//
// resources::whiteboard->save_temp_move();
//
// // Otherwise proceed to normal unit movement
// } else {
// //Don't move if the unit already has actions
// //from the whiteboard.
// if (resources::whiteboard->unit_has_actions(&*u)) {
// return false;
// }
//
// move_unit_along_current_route();
// // during the move, we may have selected another unit
// // (but without triggering a select event (command was disabled)
// // in that case reselect it now to fire the event (+ anim & sound)
// if (selected_hex_ != src) {
// select_hex(selected_hex_, browse);
// }
// }
// return false;
// } else if(!commands_disabled) {
// // we select a (maybe empty) hex
// // we block selection during attack+move (because motion is blocked)
//select_hex(hex, browse);
// }
// return false;
// //FIXME: clean all these "return false"
//}
void mouse_handler::select_hex(const map_location& hex, const bool browse, const bool highlight, const bool fire_event) {
selected_hex_ = hex;
gui().select_hex(hex);
if (selected_hex_ == hex)
selected_hex_ = map_location::null_location;
else
selected_hex_ = hex;
gui().select_hex(selected_hex_);
gui().clear_attack_indicator();
gui().set_route(NULL);
show_partial_move_ = false;
wb::future_map_if_active planned_unit_map; //lasts for whole method
unit_map::iterator u = find_unit(hex);
unit_map::iterator u = find_unit(selected_hex_);
if (hex.valid() && u != units_.end() && u.valid() && !u->get_hidden()) {
if (selected_hex_.valid() && u != units_.end() && u.valid() && !u->get_hidden()) {
next_unit_ = u->get_location();
@ -636,9 +838,16 @@ void mouse_handler::select_hex(const map_location& hex, const bool browse, const
}
} else {
gui().unhighlight_reach();
current_paths_ = pathfind::paths();
current_route_.steps.clear();
if (selected_hex_.valid()) {
current_paths_.destinations.insert(hex);
gui().highlight_reach(current_paths_);
}
resources::whiteboard->on_deselect_hex();
}
}

View file

@ -72,6 +72,11 @@ public:
void select_hex(const map_location& hex, const bool browse,
const bool highlight = true,
const bool fire_event = true);
void move_action();
void select_or_action();
protected:
/**
* Due to the way this class is constructed we can assume that the
@ -91,7 +96,7 @@ protected:
*/
void mouse_motion(int x, int y, const bool browse, bool update=false, map_location loc = map_location::null_location);
bool right_click_show_menu(int x, int y, const bool browse);
bool left_click(int x, int y, const bool browse);
// bool left_click(int x, int y, const bool browse);
bool move_unit_along_current_route();
void save_whiteboard_attack(const map_location& attacker_loc, const map_location& defender_loc, int weapon_choice);

View file

@ -458,6 +458,21 @@ void play_controller::left_mouse_click(){
mouse_handler_.mouse_press(event, false);
}
void play_controller::select_and_action() {
mouse_handler_.select_or_action();
}
void play_controller::move_action(){
mouse_handler_.move_action();
}
void play_controller::deselect_hex(){
mouse_handler_.deselect_hex();
}
void play_controller::select_hex(){
mouse_handler_.select_hex(gui_->mouseover_hex(), true, true, true);
}
void play_controller::right_mouse_click(){
int x = gui_->get_location_x(gui_->mouseover_hex());
int y = gui_->get_location_y(gui_->mouseover_hex());
@ -875,8 +890,10 @@ bool play_controller::can_execute_command(const hotkey::hotkey_command& cmd, int
case hotkey::HOTKEY_CUSTOM_CMD:
case hotkey::HOTKEY_AI_FORMULA:
case hotkey::HOTKEY_CLEAR_MSG:
case hotkey::HOTKEY_LEFT_MOUSE_CLICK:
case hotkey::HOTKEY_RIGHT_MOUSE_CLICK:
case hotkey::HOTKEY_SELECT_HEX:
case hotkey::HOTKEY_DESELECT_HEX:
case hotkey::HOTKEY_MOVE_ACTION:
case hotkey::HOTKEY_SELECT_AND_ACTION:
case hotkey::HOTKEY_MINIMAP_COLOR_CODING:
return true;

View file

@ -84,6 +84,10 @@ public:
virtual void show_statistics();
virtual void unit_list();
virtual void left_mouse_click();
virtual void move_action();
virtual void select_and_action();
virtual void select_hex();
virtual void deselect_hex();
virtual void right_mouse_click();
virtual void status_table();
virtual void save_game();