diff --git a/src/config.c b/src/config.c index fc8887a0d2..5aabc8fa98 100644 --- a/src/config.c +++ b/src/config.c @@ -900,4 +900,48 @@ void config_reset_shortcut_keys() memcpy(gShortcutKeys, _defaultShortcutKeys, sizeof(gShortcutKeys)); } +void config_shortcut_keys_get_path(char *outPath) +{ + platform_get_user_directory(outPath, NULL); + strcat(outPath, "hotkeys.cfg"); +} + +bool config_shortcut_keys_load() +{ + char path[MAX_PATH]; + FILE *file; + int result; + + config_shortcut_keys_get_path(path); + + file = fopen(path, "rb"); + if (file != NULL) { + result = fread(gShortcutKeys, sizeof(gShortcutKeys), 1, file) == 1; + fclose(file); + } else { + result = false; + } + + return result; +} + +bool config_shortcut_keys_save() +{ + char path[MAX_PATH]; + FILE *file; + int result; + + config_shortcut_keys_get_path(path); + + file = fopen(path, "wb"); + if (file != NULL) { + result = fwrite(gShortcutKeys, sizeof(gShortcutKeys), 1, file) == 1; + fclose(file); + } else { + result = false; + } + + return result; +} + #pragma endregion \ No newline at end of file diff --git a/src/config.h b/src/config.h index 258c5917ff..ced5018b4a 100644 --- a/src/config.h +++ b/src/config.h @@ -154,6 +154,9 @@ bool config_save_default(); uint16 getLanguage(); void config_reset_shortcut_keys(); +bool config_shortcut_keys_load(); +bool config_shortcut_keys_save(); + bool config_find_or_browse_install_directory(); #endif diff --git a/src/input.c b/src/input.c index 1bf782fd4a..a3d8884a7e 100644 --- a/src/input.c +++ b/src/input.c @@ -1095,6 +1095,7 @@ static void input_update_tooltip(rct_window *w, int widgetIndex, int x, int y) */ void title_handle_keyboard_input() { + rct_window *w; int key; // Handle modifier keys and key scrolling @@ -1114,7 +1115,10 @@ void title_handle_keyboard_input() key |= RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) << 8; - if (key == gShortcutKeys[SHORTCUT_SCREENSHOT]) { + w = window_find_by_class(WC_CHANGE_KEYBOARD_SHORTCUT); + if (w != NULL) { + keyboard_shortcut_set(key); + } else if (key == gShortcutKeys[SHORTCUT_SCREENSHOT]) { keyboard_shortcut_handle_command(SHORTCUT_SCREENSHOT); } } @@ -1158,16 +1162,15 @@ void game_handle_keyboard_input() key |= RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) << 8; w = window_find_by_class(WC_CHANGE_KEYBOARD_SHORTCUT); - if (w != NULL) + if (w != NULL) { keyboard_shortcut_set(key); - else if (RCT2_GLOBAL(RCT2_ADDRESS_ON_TUTORIAL, uint8) == 1) + } else if (RCT2_GLOBAL(RCT2_ADDRESS_ON_TUTORIAL, uint8) == 1) { tutorial_stop(); - else{ + } else { w = window_find_by_class(WC_TEXTINPUT); if (w != NULL){ ((void(*)(int, rct_window*))w->event_handlers[WE_TEXT_INPUT])(key,w); - } - else{ + } else { keyboard_shortcut_handle(key); } } diff --git a/src/interface/keyboard_shortcut.c b/src/interface/keyboard_shortcut.c index 0dd3980dc8..943c028a11 100644 --- a/src/interface/keyboard_shortcut.c +++ b/src/interface/keyboard_shortcut.c @@ -50,7 +50,7 @@ void keyboard_shortcut_set(int key) gShortcutKeys[RCT2_GLOBAL(0x009DE511, uint8)] = key; window_close_by_class(WC_CHANGE_KEYBOARD_SHORTCUT); window_invalidate_by_class(WC_KEYBOARD_SHORTCUT_LIST); - config_save_default(); + config_shortcut_keys_save(); } /** diff --git a/src/rct2.c b/src/rct2.c index 565bb1eb18..16f0ba06a1 100644 --- a/src/rct2.c +++ b/src/rct2.c @@ -80,6 +80,7 @@ int rct2_init() return 0; config_reset_shortcut_keys(); + config_shortcut_keys_load(); RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) = 0; // config_load(); // RCT2_CALLPROC_EBPSAFE(0x00674B81); // pointless expansion pack crap diff --git a/src/windows/shortcut_keys.c b/src/windows/shortcut_keys.c index a9a34d3f7d..2fb9c028c9 100644 --- a/src/windows/shortcut_keys.c +++ b/src/windows/shortcut_keys.c @@ -128,7 +128,7 @@ static void window_shortcut_mouseup() break; case WIDX_RESET: config_reset_shortcut_keys(); - config_save_default(); + config_shortcut_keys_save(); window_invalidate(w); break; } @@ -163,17 +163,15 @@ static void window_shortcut_tooltip() */ static void window_shortcut_scrollgetsize() { - int y; rct_window *w; + int width, height; + window_get_register(w); - y = 32 * 10; + width = 0; + height = 32 * 10; -#ifdef _MSC_VER - __asm mov edx, y -#else - __asm__("mov edx, %[y] " : [y] "+m" (y)); -#endif + window_scrollsize_set_registers(width, height); } /** @@ -188,8 +186,8 @@ static void window_shortcut_scrollmousedown() window_scrollmouse_get_registers(w, scrollIndex, x, y); int selected_item = y / 10; - - if (selected_item >= w->no_list_items)return; + if (selected_item >= w->no_list_items) + return; window_shortcut_change_open(selected_item); } @@ -206,8 +204,8 @@ static void window_shortcut_scrollmouseover() window_scrollmouse_get_registers(w, scrollIndex, x, y); int selected_item = y / 10; - - if (selected_item >= w->no_list_items)return; + if (selected_item >= w->no_list_items) + return; w->selected_list_item = selected_item; @@ -227,14 +225,14 @@ static void window_shortcut_scrollpaint() gfx_fill_rect(dpi, dpi->x, dpi->y, dpi->x + dpi->width - 1, dpi->y + dpi->height - 1, RCT2_ADDRESS(0x0141FC48,uint8)[w->colours[1] * 8]); - for (int i = 0; i < w->no_list_items; ++i){ + for (int i = 0; i < w->no_list_items; ++i) { int y = i * 10; - if (y > dpi->y + dpi->height) { + if (y > dpi->y + dpi->height) break; - } + if (y + 10 < dpi->y)continue; int format = STR_BLACK_STRING; - if (i == w->selected_list_item){ + if (i == w->selected_list_item) { format = STR_WINDOW_COLOUR_2_STRING; gfx_fill_rect(dpi, 0, y, 800, y + 9, 0x2000031); } @@ -243,33 +241,23 @@ static void window_shortcut_scrollpaint() RCT2_GLOBAL(0x13CE956, uint16) = 0; RCT2_GLOBAL(0x13CE958, uint16) = 0; - // 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; - // } - // } - //} - uint16 shortcut_entry = gShortcutKeys[i]; - if (shortcut_entry != 0xFFFF){ - RCT2_GLOBAL(0x13CE958, uint16) = STR_INDIVIDUAL_KEYS_BASE + platform_scancode_to_rct_keycode(shortcut_entry & 0xFF); - //Display the modifer - if (shortcut_entry & 0x100){ + if (shortcut_entry != 0xFFFF) { + rct_string_id templateStringId = 2525; + const char *scanCodeName = SDL_GetScancodeName(shortcut_entry & 0xFF); + char *templateString = (char*)language_get_string(templateStringId); + strcpy(templateString, scanCodeName); + + RCT2_GLOBAL(0x13CE958, uint16) = templateStringId; + + // Display the modifer + if (shortcut_entry & 0x100) RCT2_GLOBAL(0x13CE956, uint16) = STR_SHIFT_PLUS; - } - else if (shortcut_entry & 0x200){ + else if (shortcut_entry & 0x200) RCT2_GLOBAL(0x13CE956, uint16) = STR_CTRL_PLUS; - } } - RCT2_GLOBAL(0x13CE952, uint16) = STR_SHORTCUT_ENTRY_FORMAT; - gfx_draw_string_left(dpi, format, (void*)0x13CE952, 0, 0, y - 1); } } \ No newline at end of file