mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-23 15:52:55 +01:00
support map scroll keyboard shortcuts, e.g. WASD. Closes #757
This commit is contained in:
@@ -3802,3 +3802,7 @@ STR_5465 :Climate
|
|||||||
STR_5466 :Staff
|
STR_5466 :Staff
|
||||||
STR_5467 :ALT +
|
STR_5467 :ALT +
|
||||||
STR_5468 :Show recent messages button on toolbar
|
STR_5468 :Show recent messages button on toolbar
|
||||||
|
STR_5469 :Scroll map up
|
||||||
|
STR_5470 :Scroll map left
|
||||||
|
STR_5471 :Scroll map down
|
||||||
|
STR_5472 :Scroll map right
|
||||||
|
|||||||
@@ -964,6 +964,10 @@ static const uint16 _defaultShortcutKeys[SHORTCUT_COUNT] = {
|
|||||||
SDL_SCANCODE_EQUALS, // SHORTCUT_INCREASE_GAME_SPEED,
|
SDL_SCANCODE_EQUALS, // SHORTCUT_INCREASE_GAME_SPEED,
|
||||||
CTRL | ALT | SDL_SCANCODE_C, // SHORTCUT_OPEN_CHEAT_WINDOW,
|
CTRL | ALT | SDL_SCANCODE_C, // SHORTCUT_OPEN_CHEAT_WINDOW,
|
||||||
SDL_SCANCODE_T, // SHORTCUT_REMOVE_TOP_BOTTOM_TOOLBAR_TOGGLE,
|
SDL_SCANCODE_T, // SHORTCUT_REMOVE_TOP_BOTTOM_TOOLBAR_TOGGLE,
|
||||||
|
SDL_SCANCODE_UP, // SHORTCUT_SCROLL_MAP_UP
|
||||||
|
SDL_SCANCODE_LEFT, // SHORTCUT_SCROLL_MAP_LEFT
|
||||||
|
SDL_SCANCODE_DOWN, // SHORTCUT_SCROLL_MAP_DOWN
|
||||||
|
SDL_SCANCODE_RIGHT, // SHORTCUT_SCROLL_MAP_RIGHT
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SHORTCUT_FILE_VERSION 1
|
#define SHORTCUT_FILE_VERSION 1
|
||||||
|
|||||||
@@ -72,7 +72,10 @@ enum {
|
|||||||
SHORTCUT_INCREASE_GAME_SPEED,
|
SHORTCUT_INCREASE_GAME_SPEED,
|
||||||
SHORTCUT_OPEN_CHEAT_WINDOW,
|
SHORTCUT_OPEN_CHEAT_WINDOW,
|
||||||
SHORTCUT_REMOVE_TOP_BOTTOM_TOOLBAR_TOGGLE,
|
SHORTCUT_REMOVE_TOP_BOTTOM_TOOLBAR_TOGGLE,
|
||||||
|
SHORTCUT_SCROLL_MAP_UP,
|
||||||
|
SHORTCUT_SCROLL_MAP_LEFT,
|
||||||
|
SHORTCUT_SCROLL_MAP_DOWN,
|
||||||
|
SHORTCUT_SCROLL_MAP_RIGHT,
|
||||||
|
|
||||||
SHORTCUT_COUNT
|
SHORTCUT_COUNT
|
||||||
};
|
};
|
||||||
|
|||||||
45
src/input.c
45
src/input.c
@@ -1583,17 +1583,42 @@ void game_handle_key_scroll()
|
|||||||
scrollX = 0;
|
scrollX = 0;
|
||||||
scrollY = 0;
|
scrollY = 0;
|
||||||
|
|
||||||
// Scroll left / right
|
for (int shortcutId = SHORTCUT_SCROLL_MAP_UP; shortcutId <= SHORTCUT_SCROLL_MAP_RIGHT; shortcutId++) {
|
||||||
if (gKeysState[SDL_SCANCODE_LEFT])
|
const int SHIFT = 0x100;
|
||||||
scrollX = -1;
|
const int CTRL = 0x200;
|
||||||
else if (gKeysState[SDL_SCANCODE_RIGHT])
|
const int ALT = 0x400;
|
||||||
scrollX = 1;
|
|
||||||
|
|
||||||
// Scroll up / down
|
uint16 shortcutKey = gShortcutKeys[shortcutId];
|
||||||
if (gKeysState[SDL_SCANCODE_UP])
|
uint8 scancode = shortcutKey & 0xFF;
|
||||||
scrollY = -1;
|
|
||||||
else if (gKeysState[SDL_SCANCODE_DOWN])
|
if (shortcutKey == 0xFFFF) continue;
|
||||||
scrollY = 1;
|
if (!gKeysState[scancode]) continue;
|
||||||
|
|
||||||
|
if (shortcutKey & SHIFT) {
|
||||||
|
if (!gKeysState[SDL_SCANCODE_LSHIFT] && !gKeysState[SDL_SCANCODE_RSHIFT]) continue;
|
||||||
|
}
|
||||||
|
if (shortcutKey & CTRL) {
|
||||||
|
if (!gKeysState[SDL_SCANCODE_LCTRL] && !gKeysState[SDL_SCANCODE_RCTRL]) continue;
|
||||||
|
}
|
||||||
|
if (shortcutKey & ALT) {
|
||||||
|
if (!gKeysState[SDL_SCANCODE_LALT] && !gKeysState[SDL_SCANCODE_RALT]) continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (shortcutId) {
|
||||||
|
case SHORTCUT_SCROLL_MAP_UP:
|
||||||
|
scrollY = -1;
|
||||||
|
break;
|
||||||
|
case SHORTCUT_SCROLL_MAP_LEFT:
|
||||||
|
scrollX = -1;
|
||||||
|
break;
|
||||||
|
case SHORTCUT_SCROLL_MAP_DOWN:
|
||||||
|
scrollY = 1;
|
||||||
|
break;
|
||||||
|
case SHORTCUT_SCROLL_MAP_RIGHT:
|
||||||
|
scrollX = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Scroll viewport
|
// Scroll viewport
|
||||||
if (scrollX != 0) {
|
if (scrollX != 0) {
|
||||||
|
|||||||
@@ -72,8 +72,12 @@ void keyboard_shortcut_handle(int key)
|
|||||||
|
|
||||||
void keyboard_shortcut_handle_command(int shortcutIndex)
|
void keyboard_shortcut_handle_command(int shortcutIndex)
|
||||||
{
|
{
|
||||||
if (shortcutIndex >= 0 && shortcutIndex < countof(shortcut_table))
|
if (shortcutIndex >= 0 && shortcutIndex < countof(shortcut_table)) {
|
||||||
shortcut_table[shortcutIndex]();
|
shortcut_action action = shortcut_table[shortcutIndex];
|
||||||
|
if (action != NULL) {
|
||||||
|
action();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void keyboard_shortcut_format_string(char *buffer, uint16 shortcutKey)
|
void keyboard_shortcut_format_string(char *buffer, uint16 shortcutKey)
|
||||||
@@ -81,6 +85,7 @@ void keyboard_shortcut_format_string(char *buffer, uint16 shortcutKey)
|
|||||||
char formatBuffer[256];
|
char formatBuffer[256];
|
||||||
|
|
||||||
*buffer = 0;
|
*buffer = 0;
|
||||||
|
if (shortcutKey == 0xFFFF) return;
|
||||||
if (shortcutKey & 0x100) {
|
if (shortcutKey & 0x100) {
|
||||||
format_string(formatBuffer, STR_SHIFT_PLUS, NULL);
|
format_string(formatBuffer, STR_SHIFT_PLUS, NULL);
|
||||||
strcat(buffer, formatBuffer);
|
strcat(buffer, formatBuffer);
|
||||||
@@ -528,6 +533,10 @@ static const shortcut_action shortcut_table[SHORTCUT_COUNT] = {
|
|||||||
shortcut_increase_game_speed,
|
shortcut_increase_game_speed,
|
||||||
shortcut_open_cheat_window,
|
shortcut_open_cheat_window,
|
||||||
shortcut_remove_top_bottom_toolbar_toggle,
|
shortcut_remove_top_bottom_toolbar_toggle,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|||||||
@@ -1798,6 +1798,11 @@ enum {
|
|||||||
STR_ALT_PLUS = 5467,
|
STR_ALT_PLUS = 5467,
|
||||||
STR_SHOW_RECENT_MESSAGES_ON_TOOLBAR = 5468,
|
STR_SHOW_RECENT_MESSAGES_ON_TOOLBAR = 5468,
|
||||||
|
|
||||||
|
STR_SHORTCUT_SCROLL_MAP_UP = 5469,
|
||||||
|
STR_SHORTCUT_SCROLL_MAP_LEFT = 5470,
|
||||||
|
STR_SHORTCUT_SCROLL_MAP_DOWN = 5471,
|
||||||
|
STR_SHORTCUT_SCROLL_MAP_RIGHT = 5472,
|
||||||
|
|
||||||
// Have to include resource strings (from scenarios and objects) for the time being now that language is partially working
|
// Have to include resource strings (from scenarios and objects) for the time being now that language is partially working
|
||||||
STR_COUNT = 32768
|
STR_COUNT = 32768
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -126,6 +126,10 @@ const rct_string_id ShortcutStringIds[] = {
|
|||||||
STR_SHORTCUT_INCREASE_GAME_SPEED,
|
STR_SHORTCUT_INCREASE_GAME_SPEED,
|
||||||
STR_SHORTCUT_OPEN_CHEATS_WINDOW,
|
STR_SHORTCUT_OPEN_CHEATS_WINDOW,
|
||||||
STR_SHORTCUT_TOGGLE_VISIBILITY_OF_TOOLBARS,
|
STR_SHORTCUT_TOGGLE_VISIBILITY_OF_TOOLBARS,
|
||||||
|
STR_SHORTCUT_SCROLL_MAP_UP,
|
||||||
|
STR_SHORTCUT_SCROLL_MAP_LEFT,
|
||||||
|
STR_SHORTCUT_SCROLL_MAP_DOWN,
|
||||||
|
STR_SHORTCUT_SCROLL_MAP_RIGHT
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user