1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-24 00:03:11 +01:00

fix shortcuts, fixes #824, fixes #512...

- add saving of shortcut configuration
- allow setting of shortcuts in title screen
This commit is contained in:
IntelOrca
2015-02-27 17:28:45 +00:00
parent b8f81b2c29
commit 4268c930e8
6 changed files with 83 additions and 44 deletions

View File

@@ -900,4 +900,48 @@ void config_reset_shortcut_keys()
memcpy(gShortcutKeys, _defaultShortcutKeys, sizeof(gShortcutKeys)); 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 #pragma endregion

View File

@@ -154,6 +154,9 @@ bool config_save_default();
uint16 getLanguage(); uint16 getLanguage();
void config_reset_shortcut_keys(); void config_reset_shortcut_keys();
bool config_shortcut_keys_load();
bool config_shortcut_keys_save();
bool config_find_or_browse_install_directory(); bool config_find_or_browse_install_directory();
#endif #endif

View File

@@ -1095,6 +1095,7 @@ static void input_update_tooltip(rct_window *w, int widgetIndex, int x, int y)
*/ */
void title_handle_keyboard_input() void title_handle_keyboard_input()
{ {
rct_window *w;
int key; int key;
// Handle modifier keys and key scrolling // 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; 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); 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; key |= RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) << 8;
w = window_find_by_class(WC_CHANGE_KEYBOARD_SHORTCUT); w = window_find_by_class(WC_CHANGE_KEYBOARD_SHORTCUT);
if (w != NULL) if (w != NULL) {
keyboard_shortcut_set(key); 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(); tutorial_stop();
else{ } else {
w = window_find_by_class(WC_TEXTINPUT); w = window_find_by_class(WC_TEXTINPUT);
if (w != NULL){ if (w != NULL){
((void(*)(int, rct_window*))w->event_handlers[WE_TEXT_INPUT])(key,w); ((void(*)(int, rct_window*))w->event_handlers[WE_TEXT_INPUT])(key,w);
} } else {
else{
keyboard_shortcut_handle(key); keyboard_shortcut_handle(key);
} }
} }

View File

@@ -50,7 +50,7 @@ void keyboard_shortcut_set(int key)
gShortcutKeys[RCT2_GLOBAL(0x009DE511, uint8)] = key; gShortcutKeys[RCT2_GLOBAL(0x009DE511, uint8)] = key;
window_close_by_class(WC_CHANGE_KEYBOARD_SHORTCUT); window_close_by_class(WC_CHANGE_KEYBOARD_SHORTCUT);
window_invalidate_by_class(WC_KEYBOARD_SHORTCUT_LIST); window_invalidate_by_class(WC_KEYBOARD_SHORTCUT_LIST);
config_save_default(); config_shortcut_keys_save();
} }
/** /**

View File

@@ -80,6 +80,7 @@ int rct2_init()
return 0; return 0;
config_reset_shortcut_keys(); config_reset_shortcut_keys();
config_shortcut_keys_load();
RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) = 0; RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) = 0;
// config_load(); // config_load();
// RCT2_CALLPROC_EBPSAFE(0x00674B81); // pointless expansion pack crap // RCT2_CALLPROC_EBPSAFE(0x00674B81); // pointless expansion pack crap

View File

@@ -128,7 +128,7 @@ static void window_shortcut_mouseup()
break; break;
case WIDX_RESET: case WIDX_RESET:
config_reset_shortcut_keys(); config_reset_shortcut_keys();
config_save_default(); config_shortcut_keys_save();
window_invalidate(w); window_invalidate(w);
break; break;
} }
@@ -163,17 +163,15 @@ static void window_shortcut_tooltip()
*/ */
static void window_shortcut_scrollgetsize() static void window_shortcut_scrollgetsize()
{ {
int y;
rct_window *w; rct_window *w;
int width, height;
window_get_register(w); window_get_register(w);
y = 32 * 10; width = 0;
height = 32 * 10;
#ifdef _MSC_VER window_scrollsize_set_registers(width, height);
__asm mov edx, y
#else
__asm__("mov edx, %[y] " : [y] "+m" (y));
#endif
} }
/** /**
@@ -188,8 +186,8 @@ static void window_shortcut_scrollmousedown()
window_scrollmouse_get_registers(w, scrollIndex, x, y); window_scrollmouse_get_registers(w, scrollIndex, x, y);
int selected_item = y / 10; int selected_item = y / 10;
if (selected_item >= w->no_list_items)
if (selected_item >= w->no_list_items)return; return;
window_shortcut_change_open(selected_item); window_shortcut_change_open(selected_item);
} }
@@ -206,8 +204,8 @@ static void window_shortcut_scrollmouseover()
window_scrollmouse_get_registers(w, scrollIndex, x, y); window_scrollmouse_get_registers(w, scrollIndex, x, y);
int selected_item = y / 10; int selected_item = y / 10;
if (selected_item >= w->no_list_items)
if (selected_item >= w->no_list_items)return; return;
w->selected_list_item = selected_item; 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]); 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; int y = i * 10;
if (y > dpi->y + dpi->height) { if (y > dpi->y + dpi->height)
break; break;
}
if (y + 10 < dpi->y)continue; if (y + 10 < dpi->y)continue;
int format = STR_BLACK_STRING; int format = STR_BLACK_STRING;
if (i == w->selected_list_item){ if (i == w->selected_list_item) {
format = STR_WINDOW_COLOUR_2_STRING; format = STR_WINDOW_COLOUR_2_STRING;
gfx_fill_rect(dpi, 0, y, 800, y + 9, 0x2000031); 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(0x13CE956, uint16) = 0;
RCT2_GLOBAL(0x13CE958, 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]; uint16 shortcut_entry = gShortcutKeys[i];
if (shortcut_entry != 0xFFFF){ if (shortcut_entry != 0xFFFF) {
RCT2_GLOBAL(0x13CE958, uint16) = STR_INDIVIDUAL_KEYS_BASE + platform_scancode_to_rct_keycode(shortcut_entry & 0xFF); rct_string_id templateStringId = 2525;
//Display the modifer const char *scanCodeName = SDL_GetScancodeName(shortcut_entry & 0xFF);
if (shortcut_entry & 0x100){ 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; 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(0x13CE956, uint16) = STR_CTRL_PLUS;
}
} }
RCT2_GLOBAL(0x13CE952, uint16) = STR_SHORTCUT_ENTRY_FORMAT; RCT2_GLOBAL(0x13CE952, uint16) = STR_SHORTCUT_ENTRY_FORMAT;
gfx_draw_string_left(dpi, format, (void*)0x13CE952, 0, 0, y - 1); gfx_draw_string_left(dpi, format, (void*)0x13CE952, 0, 0, y - 1);
} }
} }