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));
}
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

View File

@@ -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

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()
{
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);
}
}

View File

@@ -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();
}
/**

View File

@@ -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

View File

@@ -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;
@@ -229,9 +227,9 @@ static void window_shortcut_scrollpaint()
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) {
@@ -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);
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){
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);
}
}