From 880ae7cb940d95422151cb1d7c94ebf4f94127c3 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Tue, 7 Oct 2014 19:12:19 +0100 Subject: [PATCH] Added the ability to read the current keyboard assignment --- data/language/english_uk.txt | 1 + src/config.h | 2 +- src/osinterface.c | 11 +++++++++++ src/osinterface.h | 1 + src/string_ids.h | 9 +++++++++ src/window_shortcut_keys.c | 36 +++++++++++++++++++++++++----------- 6 files changed, 48 insertions(+), 12 deletions(-) diff --git a/data/language/english_uk.txt b/data/language/english_uk.txt index 23535f2a06..a6b4cc889a 100644 --- a/data/language/english_uk.txt +++ b/data/language/english_uk.txt @@ -2526,6 +2526,7 @@ STR_2521 :Show staff list STR_2522 :Show recent messages STR_2523 :Show map STR_2524 :Screenshot +### The following need to be reordered to match SDL_keycode layout. STR_2525 :??? STR_2526 :??? STR_2527 :??? diff --git a/src/config.h b/src/config.h index 8bd7510ad4..49d5f2c1ac 100644 --- a/src/config.h +++ b/src/config.h @@ -154,8 +154,8 @@ static const struct { const char *key; int value; } _currencyLookupTable[] = { }; typedef struct shortcut_entry{ - uint8 shortcut; uint8 key; + uint8 modifier; }shortcut_entry; //typedef struct hotkey_configuration{ diff --git a/src/osinterface.c b/src/osinterface.c index 59b5a887c0..f1e5a8207d 100644 --- a/src/osinterface.c +++ b/src/osinterface.c @@ -70,6 +70,17 @@ void osinterface_init() // RCT2_CALLPROC(0x00404584); // dinput_init() } +int osinterface_scancode_to_rct_keycode(int sdl_key){ + char keycode = (char)SDL_GetKeyFromScancode((SDL_Scancode)sdl_key); + + // Until we reshufle the text files to use the new positions + // this will suffice to move the majority to the correct positions. + // Note any special buttons PgUp PgDwn are mapped wrong. + if (keycode >= 'a' && keycode <= 'z')keycode = toupper(keycode); + + return keycode; +} + /** * This is not quite the same as the below function as we don't want to * derfererence the cursor before the function. diff --git a/src/osinterface.h b/src/osinterface.h index 7c08580483..14b08d4251 100644 --- a/src/osinterface.h +++ b/src/osinterface.h @@ -112,5 +112,6 @@ int osinterface_directory_exists(const char *path); int osinterface_ensure_directory_exists(const char *path); char osinterface_get_path_separator(); +int osinterface_scancode_to_rct_keycode(int sdl_key); #endif diff --git a/src/string_ids.h b/src/string_ids.h index 6613531b67..2a2612ceee 100644 --- a/src/string_ids.h +++ b/src/string_ids.h @@ -997,6 +997,15 @@ enum { STR_REAL_NAME_TIP = 2488, STR_HOTKEY = 2489, + STR_SHORTCUT_DESCRIPTION_0 = 2493, + + STR_SHORTCUT_DESCRIPTION_31 = 2524, + STR_INDIVIDUAL_KEYS_BASE = 2525, + + STR_SHORTCUT_ENTRY_FORMAT = 2781, + STR_SHIFT_PLUS = 2782, + STR_CTRL_PLUS = 2783, + STR_FINACNES_PARK_VALUE = 2787, STR_ENTER_NAME_INTO_SCENARIO_CHART = 2790, diff --git a/src/window_shortcut_keys.c b/src/window_shortcut_keys.c index 54e2710781..52ed422a8a 100644 --- a/src/window_shortcut_keys.c +++ b/src/window_shortcut_keys.c @@ -22,6 +22,7 @@ #include "config.h" #include "window.h" #include "widget.h" +#include "osinterface.h" #define WW 340 #define WH 240 @@ -237,23 +238,36 @@ static void window_shortcut_scrollpaint() gfx_fill_rect(dpi, 0, y, 800, y + 9, 0x2000031); } - RCT2_GLOBAL(0x13CE954, uint16) = i + 2493; + RCT2_GLOBAL(0x13CE954, uint16) = i + STR_SHORTCUT_DESCRIPTION_0; RCT2_GLOBAL(0x13CE956, uint16) = 0; RCT2_GLOBAL(0x13CE958, uint16) = 0; - - shortcut_entry sc_entry = RCT2_ADDRESS(RCT2_ADDRESS_CONFIG_KEYBOARD_SHORTCUTS, shortcut_entry)[i]; + // This is the original version that will not take into account remapped keys. + //shortcut_entry sc_entry = RCT2_ADDRESS(RCT2_ADDRESS_CONFIG_KEYBOARD_SHORTCUTS, shortcut_entry)[i]; + //if (sc_entry.key != 255){ + // RCT2_GLOBAL(0x13CE958, uint16) = sc_entry.key + 2525; + // if (sc_entry.modifier){ + // RCT2_GLOBAL(0x13CE956, uint16) = 2782; + // if (sc_entry.key != 1){ + // RCT2_GLOBAL(0x13CE956, uint16) = 2783; + // } + // } + //} - if (sc_entry.shortcut != 255){ - RCT2_GLOBAL(0x13CE958, uint16) = sc_entry.shortcut + 2525; - if (sc_entry.key){ - RCT2_GLOBAL(0x13CE956, uint16) = 2782; - if (sc_entry.key != 1){ - RCT2_GLOBAL(0x13CE956, uint16) = 2783; - } + uint16 shortcut_entry = gShortcutKeys[i]; + if (shortcut_entry != 0xFFFF){ + RCT2_GLOBAL(0x13CE958, uint16) = STR_INDIVIDUAL_KEYS_BASE + osinterface_scancode_to_rct_keycode(shortcut_entry & 0xFF); + //Display the modifer + if (shortcut_entry & 0x100){ + RCT2_GLOBAL(0x13CE956, uint16) = STR_SHIFT_PLUS; + } + else if (shortcut_entry & 0x200){ + RCT2_GLOBAL(0x13CE956, uint16) = STR_CTRL_PLUS; } } - RCT2_GLOBAL(0x13CE952, uint16) = 2781; + + + RCT2_GLOBAL(0x13CE952, uint16) = STR_SHORTCUT_ENTRY_FORMAT; gfx_draw_string_left(dpi, format, (void*)0x13CE952, 0, 0, y - 1); }