editor_action* mouse_action::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) { map_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(map_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; }
editor_action* mouse_action::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) { map_location pos = disp.get_map().starting_position(side); if (pos.valid()) { disp.scroll_to_tile(pos, display::WARP); } } return nullptr; } if (!disp.map().on_board(previous_move_hex_) || event.type != SDL_KEYUP) { return nullptr; } editor_action* a = nullptr; 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; const std::string* old_id = disp.map().is_starting_position(previous_move_hex_); if (res == 0 && old_id != nullptr) { a = new editor_action_starting_position(map_location(), *old_id); } else if (res > 0 && (old_id == nullptr || *old_id == std::to_string(res))) { a = new editor_action_starting_position(previous_move_hex_, std::to_string(res)); } } return a; }