fix shortcut reading and defaults

This commit is contained in:
IntelOrca 2016-01-24 16:09:45 +00:00
parent d0a95bc7b7
commit 0360a808c3
3 changed files with 13 additions and 4 deletions

View File

@ -20,6 +20,7 @@
#include "addresses.h"
#include "config.h"
#include "interface/keyboard_shortcut.h"
#include "interface/themes.h"
#include "interface/title_sequences.h"
#include "localisation/language.h"
@ -967,6 +968,8 @@ static const uint16 _defaultShortcutKeys[SHORTCUT_COUNT] = {
SDL_SCANCODE_RIGHT, // SHORTCUT_SCROLL_MAP_RIGHT
SDL_SCANCODE_C, // SHORTCUT_OPEN_CHAT_WINDOW
PLATFORM_MODIFIER | SDL_SCANCODE_F10, // SHORTCUT_QUICK_SAVE_GAME
SHORTCUT_UNDEFINED, // SHORTCUT_SHOW_OPTIONS
};
#define SHORTCUT_FILE_VERSION 1
@ -999,7 +1002,11 @@ bool config_shortcut_keys_load()
if (file != NULL) {
result = SDL_RWread(file, &version, sizeof(version), 1) == 1;
if (result && version == SHORTCUT_FILE_VERSION) {
result = SDL_RWread(file, gShortcutKeys, sizeof(gShortcutKeys), 1) == 1;
for (int i = 0; i < SHORTCUT_COUNT; i++) {
if (SDL_RWread(file, &gShortcutKeys[i], sizeof(uint16), 1) != 1) {
break;
}
}
} else {
result = false;
}

View File

@ -43,9 +43,9 @@ void keyboard_shortcut_set(int key)
int i;
// Unmap shortcut that already uses this key
for (i = 0; i < 32; i++) {
for (i = 0; i < SHORTCUT_COUNT; i++) {
if (key == gShortcutKeys[i]) {
gShortcutKeys[i] = 0xFFFF;
gShortcutKeys[i] = SHORTCUT_UNDEFINED;
break;
}
}
@ -87,7 +87,7 @@ void keyboard_shortcut_format_string(char *buffer, uint16 shortcutKey)
char formatBuffer[256];
*buffer = 0;
if (shortcutKey == 0xFFFF) return;
if (shortcutKey == SHORTCUT_UNDEFINED) return;
if (shortcutKey & 0x100) {
format_string(formatBuffer, STR_SHIFT_PLUS, NULL);
strcat(buffer, formatBuffer);

View File

@ -21,6 +21,8 @@
#ifndef _INTERFACE_KEYBOARD_SHORTCUT_H_
#define _INTERFACE_KEYBOARD_SHORTCUT_H_
#define SHORTCUT_UNDEFINED 0xFFFF
void keyboard_shortcut_set(int key);
void keyboard_shortcut_handle(int key);
void keyboard_shortcut_handle_command(int shortcutIndex);