From 725a9076e618f2652b4cd59400efdf9d13980bbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=9Aniatowski?= Date: Tue, 19 Aug 2008 13:09:52 +0100 Subject: [PATCH] editor2: make number keys always scroll to starting position, ...alt+number always set the position under cursor. This reverses alt/no-alt behavior, imo more sensible now. --- data/core/editor2-tool-hints.cfg | 2 +- src/editor2/mouse_action.cpp | 65 +++++++++++++++----------------- src/editor2/mouse_action.hpp | 7 +--- 3 files changed, 32 insertions(+), 42 deletions(-) diff --git a/data/core/editor2-tool-hints.cfg b/data/core/editor2-tool-hints.cfg index 56bf3f72509..13881cd6734 100644 --- a/data/core/editor2-tool-hints.cfg +++ b/data/core/editor2-tool-hints.cfg @@ -18,5 +18,5 @@ [editor2_tool_hint] id="editor-tool-starting-position" - text= _ "Left mouse button displays player selection, right clears. Keys 1-9 set respectove starting position under cursor and delete clears, alt+key scrolls to the starting position." + text= _ "Left mouse button displays player selection, right clears. Number keys scroll to the starting position, alt+number sets respective starting position under cursor, delete clears." [/editor2_tool_hint] diff --git a/src/editor2/mouse_action.cpp b/src/editor2/mouse_action.cpp index 081a13c2488..06814f29af1 100644 --- a/src/editor2/mouse_action.cpp +++ b/src/editor2/mouse_action.cpp @@ -60,9 +60,34 @@ editor_action* mouse_action::drag_end( } editor_action* mouse_action::key_event( - editor_display& /*disp*/, const SDL_Event& /*e*/) + editor_display& disp, const SDL_Event& event) { - return NULL; + if (!has_alt_modifier() && (event.key.keysym.sym >= '1' && event.key.keysym.sym <= '9')) { + int side = event.key.keysym.sym - '0'; + if (side >= 1 && side <= gamemap::MAX_PLAYERS) { + gamemap::location pos = disp.get_map().starting_position(side); + if (pos.valid()) { + disp.scroll_to_tile(pos, display::WARP); + } + } + return NULL; + } + if (!disp.map().on_board(previous_move_hex_) || event.type != SDL_KEYUP) { + return NULL; + } + editor_action* a = NULL; + if ((has_alt_modifier() && (event.key.keysym.sym >= '1' && event.key.keysym.sym <= '9')) + || event.key.keysym.sym == SDLK_DELETE) { + int res = event.key.keysym.sym - '0'; + if (res > gamemap::MAX_PLAYERS || event.key.keysym.sym == SDLK_DELETE) res = 0; + int player_starting_at_hex = disp.map().is_starting_position(previous_move_hex_) + 1; + if (res == 0 && player_starting_at_hex != -1) { + a = new editor_action_starting_position(gamemap::location(), player_starting_at_hex); + } else if (res > 0 && res != player_starting_at_hex) { + a = new editor_action_starting_position(previous_move_hex_, res); + } + } + return a; } bool mouse_action::has_alt_modifier() const @@ -161,13 +186,13 @@ std::set mouse_action_select::affected_hexes( } editor_action* mouse_action_select::key_event( - editor_display& disp, const SDL_Event& /*e*/) + editor_display& disp, const SDL_Event& event) { - // Force an actual move + // Force an actual move event to update the brush gamemap::location tmp = previous_move_hex_; previous_move_hex_ = gamemap::location(); move(disp, tmp); - return NULL; + return mouse_action::key_event(disp, event); } editor_action* mouse_action_select::click_perform_left( @@ -266,34 +291,4 @@ editor_action* mouse_action_starting_position::click_right(editor_display& disp, } } -editor_action* mouse_action_starting_position::key_event(editor_display& disp, const SDL_Event& event) -{ - if (has_alt_modifier() && (event.key.keysym.sym >= '1' && event.key.keysym.sym <= '9')) { - int side = event.key.keysym.sym - '0'; - if (side >= 1 && side <= gamemap::MAX_PLAYERS) { - gamemap::location pos = disp.get_map().starting_position(side); - if (pos.valid()) { - disp.scroll_to_tile(pos, display::WARP); - } - } - return NULL; - } - if (!disp.map().on_board(previous_move_hex_) || event.type != SDL_KEYUP) { - return NULL; - } - editor_action* a = NULL; - if ((event.key.keysym.sym >= '1' && event.key.keysym.sym <= '9') || event.key.keysym.sym == SDLK_DELETE) { - int res = event.key.keysym.sym - '0'; - if (res > gamemap::MAX_PLAYERS || event.key.keysym.sym == SDLK_DELETE) res = 0; - int player_starting_at_hex = disp.map().is_starting_position(previous_move_hex_) + 1; - if (res == 0 && player_starting_at_hex != -1) { - a = new editor_action_starting_position(gamemap::location(), player_starting_at_hex); - } else if (res > 0 && res != player_starting_at_hex) { - a = new editor_action_starting_position(previous_move_hex_, res); - } - } - return a; -} - - } //end namespace editor2 diff --git a/src/editor2/mouse_action.hpp b/src/editor2/mouse_action.hpp index 358dceabe54..f6e8255360e 100644 --- a/src/editor2/mouse_action.hpp +++ b/src/editor2/mouse_action.hpp @@ -79,7 +79,7 @@ public: /** * Function called by the controller on a key event for the current mouse action. - * Defaults to no action. + * Defaults to starting position processing. */ virtual editor_action* key_event(editor_display& disp, const SDL_Event& e); @@ -330,11 +330,6 @@ public: { } - /** - * Allows setting/clearing the starting positions in the mouseover hexes via keyboard - */ - editor_action* key_event(editor_display& disp, const SDL_Event& e); - /** * Left click displays a player-number-selector dialog and then creates an action * or returns NULL if cancel was pressed or there would be no change.