diff --git a/src/openrct2-ui/UiContext.cpp b/src/openrct2-ui/UiContext.cpp index d9e275b3b1..7fa89d74d3 100644 --- a/src/openrct2-ui/UiContext.cpp +++ b/src/openrct2-ui/UiContext.cpp @@ -32,6 +32,7 @@ #include #include "CursorRepository.h" #include "drawing/engines/DrawingEngines.h" +#include "input/KeyboardShortcuts.h" #include "SDLException.h" #include "TextComposition.h" #include "UiContext.h" @@ -45,6 +46,7 @@ extern "C" using namespace OpenRCT2; using namespace OpenRCT2::Drawing; +using namespace OpenRCT2::Input; using namespace OpenRCT2::Ui; #ifdef __MACOSX__ @@ -59,7 +61,6 @@ class UiContext final : public IUiContext private: constexpr static uint32 TOUCH_DOUBLE_TIMEOUT = 300; - IPlatformEnvironment * const _env; IPlatformUiContext * const _platformUiContext; CursorRepository _cursorRepository; @@ -76,27 +77,27 @@ private: bool _steamOverlayActive = false; // Input - TextComposition _textComposition; - CursorState _cursorState = { 0 }; - uint32 _lastKeyPressed = 0; - const uint8 * _keysState = nullptr; - uint8 _keysPressed[256] = { 0 }; - uint32 _lastGestureTimestamp = 0; - float _gestureRadius = 0; + KeyboardShortcuts _keyboardShortcuts; + TextComposition _textComposition; + CursorState _cursorState = { 0 }; + uint32 _lastKeyPressed = 0; + const uint8 * _keysState = nullptr; + uint8 _keysPressed[256] = { 0 }; + uint32 _lastGestureTimestamp = 0; + float _gestureRadius = 0; public: UiContext(IPlatformEnvironment * env) - : _env(env), - _platformUiContext(CreatePlatformUiContext()) + : _platformUiContext(CreatePlatformUiContext()), + _keyboardShortcuts(env) { if (SDL_Init(SDL_INIT_VIDEO) < 0) { SDLException::Throw("SDL_Init(SDL_INIT_VIDEO)"); } _cursorRepository.LoadCursors(); - - // Temporary to prevent warning, will be used for keyboard shortcuts - UNUSED(_env); + _keyboardShortcuts.Reset(); + _keyboardShortcuts.Load(); } ~UiContext() override diff --git a/src/openrct2-ui/input/KeyboardShortcuts.cpp b/src/openrct2-ui/input/KeyboardShortcuts.cpp new file mode 100644 index 0000000000..4ae54c6597 --- /dev/null +++ b/src/openrct2-ui/input/KeyboardShortcuts.cpp @@ -0,0 +1,262 @@ +#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers +/***************************************************************************** + * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. + * + * OpenRCT2 is the work of many authors, a full list can be found in contributors.md + * For more information, visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * A full copy of the GNU General Public License can be found in licence.txt + *****************************************************************************/ +#pragma endregion + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KeyboardShortcuts.h" + +extern "C" +{ + #include +} + +using namespace OpenRCT2; +using namespace OpenRCT2::Input; + +// Remove when the C calls are removed +static KeyboardShortcuts * _instance; + +KeyboardShortcuts::KeyboardShortcuts(IPlatformEnvironment * env) + : _env(env) +{ + _instance = this; +} + +void KeyboardShortcuts::Reset() +{ + for (size_t i = 0; i < SHORTCUT_COUNT; i++) + { + _keys[i] = DefaultKeys[i]; + } +} + +bool KeyboardShortcuts::Load() +{ + bool result = false; + try + { + std::string path = _env->GetFilePath(PATHID::CONFIG_KEYBOARD); + if (File::Exists(path)) + { + auto fs = FileStream(path, FILE_MODE_OPEN); + uint16 version = fs.ReadValue(); + if (version == KeyboardShortcuts::CURRENT_FILE_VERSION) + { + for (sint32 i = 0; i < SHORTCUT_COUNT; i++) + { + _keys[i] = fs.ReadValue(); + } + result = true; + } + } + } + catch (const Exception &ex) + { + Console::WriteLine("Error reading shortcut keys: %s", ex.GetMessage()); + } + return result; +} + +bool KeyboardShortcuts::Save() +{ + bool result = false; + try + { + std::string path = _env->GetFilePath(PATHID::CONFIG_KEYBOARD); + auto fs = FileStream(path, FILE_MODE_WRITE); + fs.WriteValue(KeyboardShortcuts::CURRENT_FILE_VERSION); + for (sint32 i = 0; i < SHORTCUT_COUNT; i++) + { + fs.WriteValue(_keys[i]); + } + result = true; + } + catch (const Exception &ex) + { + Console::WriteLine("Error writing shortcut keys: %s", ex.GetMessage()); + } + return result; +} + +void KeyboardShortcuts::Set(sint32 key) +{ + // Unmap shortcut that already uses this key + sint32 shortcut = GetFromKey(key); + if (shortcut != SHORTCUT_UNDEFINED) + { + _keys[shortcut] = SHORTCUT_UNDEFINED; + } + + // Map shortcut to this key + _keys[gKeyboardShortcutChangeId] = key; + // window_close_by_class(WC_CHANGE_KEYBOARD_SHORTCUT); + // window_invalidate_by_class(WC_KEYBOARD_SHORTCUT_LIST); + Save(); +} + +sint32 KeyboardShortcuts::GetFromKey(sint32 key) +{ + for (sint32 i = 0; i < SHORTCUT_COUNT; i++) + { + if (key == _keys[i]) + { + return i; + } + } + return SHORTCUT_UNDEFINED; +} + +std::string KeyboardShortcuts::GetShortcutString(sint32 shortcut) const +{ + utf8 buffer[256] = { 0 }; + utf8 formatBuffer[256] = { 0 }; + uint16 shortcutKey = _keys[shortcut]; + if (shortcutKey == SHORTCUT_UNDEFINED) return std::string(); + if (shortcutKey & SHIFT) + { + format_string(formatBuffer, sizeof(formatBuffer), STR_SHIFT_PLUS, NULL); + String::Append(buffer, sizeof(buffer), formatBuffer); + } + if (shortcutKey & CTRL) + { + format_string(formatBuffer, sizeof(formatBuffer), STR_CTRL_PLUS, NULL); + String::Append(buffer, sizeof(buffer), formatBuffer); + } + if (shortcutKey & ALT) + { +#ifdef __MACOSX__ + format_string(formatBuffer, sizeof(formatBuffer), STR_OPTION_PLUS, NULL); +#else + format_string(formatBuffer, sizeof(formatBuffer), STR_ALT_PLUS, NULL); +#endif + String::Append(buffer, sizeof(buffer), formatBuffer); + } + if (shortcutKey & CMD) + { + format_string(formatBuffer, sizeof(formatBuffer), STR_CMD_PLUS, NULL); + String::Append(buffer, sizeof(buffer), formatBuffer); + } + String::Append(buffer, sizeof(buffer), SDL_GetScancodeName((SDL_Scancode)(shortcutKey & 0xFF))); + return std::string(buffer); +} + +extern "C" +{ + void keyboard_shortcuts_reset() + { + _instance->Reset(); + } + + bool keyboard_shortcuts_load() + { + return _instance->Load(); + } + + bool keyboard_shortcuts_save() + { + return _instance->Save(); + } + + void keyboard_shortcuts_set(sint32 key) + { + return _instance->Set(key); + } + + sint32 keyboard_shortcuts_get_from_key(sint32 key) + { + return _instance->GetFromKey(key); + } + + void keyboard_shortcuts_format_string(char * buffer, size_t bufferSize, sint32 shortcut) + { + auto str = _instance->GetShortcutString(shortcut); + String::Set(buffer, bufferSize, str.c_str()); + } +} + +// Default keyboard shortcuts +const uint16 KeyboardShortcuts::DefaultKeys[SHORTCUT_COUNT] = +{ + SDL_SCANCODE_BACKSPACE, // SHORTCUT_CLOSE_TOP_MOST_WINDOW + SHIFT | SDL_SCANCODE_BACKSPACE, // SHORTCUT_CLOSE_ALL_FLOATING_WINDOWS + SDL_SCANCODE_ESCAPE, // SHORTCUT_CANCEL_CONSTRUCTION_MODE + SDL_SCANCODE_PAUSE, // SHORTCUT_PAUSE_GAME + SDL_SCANCODE_PAGEUP, // SHORTCUT_ZOOM_VIEW_OUT + SDL_SCANCODE_PAGEDOWN, // SHORTCUT_ZOOM_VIEW_IN + SDL_SCANCODE_RETURN, // SHORTCUT_ROTATE_VIEW_CLOCKWISE + SHIFT | SDL_SCANCODE_RETURN, // SHORTCUT_ROTATE_VIEW_ANTICLOCKWISE + SDL_SCANCODE_Z, // SHORTCUT_ROTATE_CONSTRUCTION_OBJECT + SDL_SCANCODE_1, // SHORTCUT_UNDERGROUND_VIEW_TOGGLE + SDL_SCANCODE_H, // SHORTCUT_REMOVE_BASE_LAND_TOGGLE + SDL_SCANCODE_V, // SHORTCUT_REMOVE_VERTICAL_LAND_TOGGLE + SDL_SCANCODE_3, // SHORTCUT_SEE_THROUGH_RIDES_TOGGLE + SDL_SCANCODE_4, // SHORTCUT_SEE_THROUGH_SCENERY_TOGGLE + SDL_SCANCODE_5, // SHORTCUT_INVISIBLE_SUPPORTS_TOGGLE + SDL_SCANCODE_6, // SHORTCUT_INVISIBLE_PEOPLE_TOGGLE + SDL_SCANCODE_8, // SHORTCUT_HEIGHT_MARKS_ON_LAND_TOGGLE + SDL_SCANCODE_9, // SHORTCUT_HEIGHT_MARKS_ON_RIDE_TRACKS_TOGGLE + SDL_SCANCODE_0, // SHORTCUT_HEIGHT_MARKS_ON_PATHS_TOGGLE + SDL_SCANCODE_F1, // SHORTCUT_ADJUST_LAND + SDL_SCANCODE_F2, // SHORTCUT_ADJUST_WATER + SDL_SCANCODE_F3, // SHORTCUT_BUILD_SCENERY + SDL_SCANCODE_F4, // SHORTCUT_BUILD_PATHS + SDL_SCANCODE_F5, // SHORTCUT_BUILD_NEW_RIDE + SDL_SCANCODE_F, // SHORTCUT_SHOW_FINANCIAL_INFORMATION + SDL_SCANCODE_D, // SHORTCUT_SHOW_RESEARCH_INFORMATION + SDL_SCANCODE_R, // SHORTCUT_SHOW_RIDES_LIST + SDL_SCANCODE_P, // SHORTCUT_SHOW_PARK_INFORMATION + SDL_SCANCODE_G, // SHORTCUT_SHOW_GUEST_LIST + SDL_SCANCODE_S, // SHORTCUT_SHOW_STAFF_LIST + SDL_SCANCODE_M, // SHORTCUT_SHOW_RECENT_MESSAGES + SDL_SCANCODE_TAB, // SHORTCUT_SHOW_MAP + PLATFORM_MODIFIER | SDL_SCANCODE_S, // SHORTCUT_SCREENSHOT + SDL_SCANCODE_MINUS, // SHORTCUT_REDUCE_GAME_SPEED, + SDL_SCANCODE_EQUALS, // SHORTCUT_INCREASE_GAME_SPEED, + PLATFORM_MODIFIER | ALT | SDL_SCANCODE_C, // SHORTCUT_OPEN_CHEAT_WINDOW, + SDL_SCANCODE_T, // SHORTCUT_REMOVE_TOP_BOTTOM_TOOLBAR_TOGGLE, + SDL_SCANCODE_UP, // SHORTCUT_SCROLL_MAP_UP + SDL_SCANCODE_LEFT, // SHORTCUT_SCROLL_MAP_LEFT + SDL_SCANCODE_DOWN, // SHORTCUT_SCROLL_MAP_DOWN + 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 + SHORTCUT_UNDEFINED, // SHORTCUT_MUTE_SOUND + ALT | SDL_SCANCODE_RETURN, // SHORTCUT_WINDOWED_MODE_TOGGLE + SHORTCUT_UNDEFINED, // SHORTCUT_SHOW_MULTIPLAYER + SHORTCUT_UNDEFINED, // SHORTCUT_PAINT_ORIGINAL_TOGGLE + SHORTCUT_UNDEFINED, // SHORTCUT_DEBUG_PAINT_TOGGLE + SHORTCUT_UNDEFINED, // SHORTCUT_SEE_THROUGH_PATHS_TOGGLE + SDL_SCANCODE_KP_4, // SHORTCUT_RIDE_CONSTRUCTION_TURN_LEFT + SDL_SCANCODE_KP_6, // SHORTCUT_RIDE_CONSTRUCTION_TURN_RIGHT + SDL_SCANCODE_KP_5, // SHORTCUT_RIDE_CONSTRUCTION_USE_TRACK_DEFAULT + SDL_SCANCODE_KP_2, // SHORTCUT_RIDE_CONSTRUCTION_SLOPE_DOWN + SDL_SCANCODE_KP_8, // SHORTCUT_RIDE_CONSTRUCTION_SLOPE_UP + SDL_SCANCODE_KP_PLUS, // SHORTCUT_RIDE_CONSTRUCTION_CHAIN_LIFT_TOGGLE + SDL_SCANCODE_KP_1, // SHORTCUT_RIDE_CONSTRUCTION_BANK_LEFT + SDL_SCANCODE_KP_3, // SHORTCUT_RIDE_CONSTRUCTION_BANK_RIGHT + SDL_SCANCODE_KP_7, // SHORTCUT_RIDE_CONSTRUCTION_PREVIOUS_TRACK + SDL_SCANCODE_KP_9, // SHORTCUT_RIDE_CONSTRUCTION_NEXT_TRACK + SDL_SCANCODE_KP_0, // SHORTCUT_RIDE_CONSTRUCTION_BUILD_CURRENT + SDL_SCANCODE_KP_MINUS, // SHORTCUT_RIDE_CONSTRUCTION_DEMOLISH_CURRENT +}; diff --git a/src/openrct2-ui/input/KeyboardShortcuts.h b/src/openrct2-ui/input/KeyboardShortcuts.h new file mode 100644 index 0000000000..f8bab0aa27 --- /dev/null +++ b/src/openrct2-ui/input/KeyboardShortcuts.h @@ -0,0 +1,78 @@ +#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers +/***************************************************************************** +* OpenRCT2, an open source clone of Roller Coaster Tycoon 2. +* +* OpenRCT2 is the work of many authors, a full list can be found in contributors.md +* For more information, visit https://github.com/OpenRCT2/OpenRCT2 +* +* OpenRCT2 is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* A full copy of the GNU General Public License can be found in licence.txt +*****************************************************************************/ +#pragma endregion + +#pragma once + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + #include "../input/keyboard_shortcut.h" +#ifdef __cplusplus +} +#endif + +#ifdef __cplusplus + +#include + +namespace OpenRCT2 +{ + interface IPlatformEnvironment; + + namespace Input + { + class KeyboardShortcuts + { + private: + constexpr static sint32 CURRENT_FILE_VERSION = 1; + static const uint16 DefaultKeys[SHORTCUT_COUNT]; + + IPlatformEnvironment * const _env; + uint16 _keys[SHORTCUT_COUNT]; + + public: + KeyboardShortcuts(IPlatformEnvironment * env); + + void Reset(); + bool Load(); + bool Save(); + + std::string GetShortcutString(sint32 shortcut) const; + + void Set(sint32 key); + sint32 GetFromKey(sint32 key); + }; + } +} + +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + void keyboard_shortcuts_reset(); + bool keyboard_shortcuts_load(); + bool keyboard_shortcuts_save(); + void keyboard_shortcuts_set(sint32 key); + sint32 keyboard_shortcuts_get_from_key(sint32 key); + void keyboard_shortcuts_format_string(char * buffer, size_t bufferSize, sint32 shortcut); +#ifdef __cplusplus +} +#endif diff --git a/src/openrct2/interface/keyboard_shortcut.c b/src/openrct2-ui/input/keyboard_shortcut.c similarity index 89% rename from src/openrct2/interface/keyboard_shortcut.c rename to src/openrct2-ui/input/keyboard_shortcut.c index 486bc5d3f0..6f7adae9d6 100644 --- a/src/openrct2/interface/keyboard_shortcut.c +++ b/src/openrct2-ui/input/keyboard_shortcut.c @@ -14,24 +14,24 @@ *****************************************************************************/ #pragma endregion -#include "../audio/audio.h" -#include "../config/Config.h" -#include "../editor.h" -#include "../game.h" -#include "../input.h" -#include "../interface/chat.h" -#include "../interface/Screenshot.h" -#include "../localisation/localisation.h" -#include "../network/network.h" -#include "../platform/platform.h" -#include "../ride/track.h" -#include "../ride/track_paint.h" -#include "../title/TitleScreen.h" -#include "../util/util.h" -#include "keyboard_shortcut.h" -#include "viewport.h" -#include "widget.h" -#include "window.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KeyboardShortcuts.h" uint8 gKeyboardShortcutChangeId; @@ -39,46 +39,13 @@ typedef void (*shortcut_action)(); static const shortcut_action shortcut_table[SHORTCUT_COUNT]; -/** - * - * rct2: 0x006E3E91 - */ -void keyboard_shortcut_set(sint32 key) -{ - sint32 i; - - // Unmap shortcut that already uses this key - for (i = 0; i < SHORTCUT_COUNT; i++) { - if (key == gShortcutKeys[i]) { - gShortcutKeys[i] = SHORTCUT_UNDEFINED; - break; - } - } - - // Map shortcut to this key - gShortcutKeys[gKeyboardShortcutChangeId] = key; - window_close_by_class(WC_CHANGE_KEYBOARD_SHORTCUT); - window_invalidate_by_class(WC_KEYBOARD_SHORTCUT_LIST); - config_shortcut_keys_save(); -} - -static sint32 keyboard_shortcut_get_from_key(sint32 key) -{ - for (sint32 i = 0; i < SHORTCUT_COUNT; i++) { - if (key == gShortcutKeys[i]) { - return i; - } - } - return -1; -} - /** * * rct2: 0x006E3E68 */ void keyboard_shortcut_handle(sint32 key) { - sint32 shortcut = keyboard_shortcut_get_from_key(key); + sint32 shortcut = keyboard_shortcuts_get_from_key(key); if (shortcut != -1) { keyboard_shortcut_handle_command(shortcut); } @@ -94,36 +61,6 @@ void keyboard_shortcut_handle_command(sint32 shortcutIndex) } } -void keyboard_shortcut_format_string(char *buffer, size_t size, uint16 shortcutKey) -{ - char formatBuffer[256]; - - if (size == 0) return; - *buffer = 0; - if (shortcutKey == SHORTCUT_UNDEFINED) return; - if (shortcutKey & 0x100) { - format_string(formatBuffer, 256, STR_SHIFT_PLUS, NULL); - safe_strcat(buffer, formatBuffer, size); - } - if (shortcutKey & 0x200) { - format_string(formatBuffer, 256, STR_CTRL_PLUS, NULL); - safe_strcat(buffer, formatBuffer, size); - } - if (shortcutKey & 0x400) { -#ifdef __MACOSX__ - format_string(formatBuffer, 256, STR_OPTION_PLUS, NULL); -#else - format_string(formatBuffer, 256, STR_ALT_PLUS, NULL); -#endif - safe_strcat(buffer, formatBuffer, size); - } - if (shortcutKey & 0x800) { - format_string(formatBuffer, 256, STR_CMD_PLUS, NULL); - safe_strcat(buffer, formatBuffer, size); - } - safe_strcat(buffer, SDL_GetScancodeName(shortcutKey & 0xFF), size); -} - #pragma region Shortcut Commands static void toggle_view_flag(sint32 viewportFlag) diff --git a/src/openrct2/interface/keyboard_shortcut.h b/src/openrct2-ui/input/keyboard_shortcut.h similarity index 94% rename from src/openrct2/interface/keyboard_shortcut.h rename to src/openrct2-ui/input/keyboard_shortcut.h index 8b1dab7533..a897e2562c 100644 --- a/src/openrct2/interface/keyboard_shortcut.h +++ b/src/openrct2-ui/input/keyboard_shortcut.h @@ -17,7 +17,7 @@ #ifndef _INTERFACE_KEYBOARD_SHORTCUT_H_ #define _INTERFACE_KEYBOARD_SHORTCUT_H_ -#include "../common.h" +#include #define SHORTCUT_UNDEFINED 0xFFFF @@ -29,10 +29,6 @@ void keyboard_shortcut_handle(sint32 key); void keyboard_shortcut_handle_command(sint32 shortcutIndex); void keyboard_shortcut_format_string(char *buffer, size_t size, uint16 shortcutKey); -void config_reset_shortcut_keys(); -bool config_shortcut_keys_load(); -bool config_shortcut_keys_save(); - typedef struct shortcut_entry { uint8 key; uint8 modifier; @@ -107,6 +103,14 @@ enum { SHORTCUT_COUNT }; -extern uint16 gShortcutKeys[SHORTCUT_COUNT]; +#define SHIFT 0x100 +#define CTRL 0x200 +#define ALT 0x400 +#define CMD 0x800 +#ifdef __MACOSX__ +#define PLATFORM_MODIFIER CMD +#else +#define PLATFORM_MODIFIER CTRL +#endif #endif diff --git a/src/openrct2-ui/libopenrct2ui.vcxproj b/src/openrct2-ui/libopenrct2ui.vcxproj index 8f22ec0203..54b0ced030 100644 --- a/src/openrct2-ui/libopenrct2ui.vcxproj +++ b/src/openrct2-ui/libopenrct2ui.vcxproj @@ -41,11 +41,15 @@ + + + + @@ -63,6 +67,8 @@ + + diff --git a/src/openrct2/windows/shortcut_key_change.c b/src/openrct2-ui/windows/shortcut_key_change.c similarity index 93% rename from src/openrct2/windows/shortcut_key_change.c rename to src/openrct2-ui/windows/shortcut_key_change.c index 817b421186..c5686caf5c 100644 --- a/src/openrct2/windows/shortcut_key_change.c +++ b/src/openrct2-ui/windows/shortcut_key_change.c @@ -14,11 +14,11 @@ *****************************************************************************/ #pragma endregion -#include "../config/Config.h" -#include "../interface/keyboard_shortcut.h" -#include "../interface/window.h" -#include "../interface/widget.h" -#include "../localisation/localisation.h" +#include +#include +#include +#include +#include "../input/keyboard_shortcut.h" extern const rct_string_id ShortcutStringIds[]; diff --git a/src/openrct2/windows/shortcut_keys.c b/src/openrct2-ui/windows/shortcut_keys.c similarity index 96% rename from src/openrct2/windows/shortcut_keys.c rename to src/openrct2-ui/windows/shortcut_keys.c index 7652e69837..023596334d 100644 --- a/src/openrct2/windows/shortcut_keys.c +++ b/src/openrct2-ui/windows/shortcut_keys.c @@ -14,12 +14,12 @@ *****************************************************************************/ #pragma endregion -#include "../config/Config.h" -#include "../interface/window.h" -#include "../interface/widget.h" -#include "../localisation/localisation.h" -#include "../platform/platform.h" -#include "../interface/keyboard_shortcut.h" +#include +#include +#include +#include +#include +#include "../input/KeyboardShortcuts.h" #define WW 420 #define WH 280 @@ -188,8 +188,8 @@ static void window_shortcut_mouseup(rct_window *w, rct_widgetindex widgetIndex) window_close(w); break; case WIDX_RESET: - config_reset_shortcut_keys(); - config_shortcut_keys_save(); + keyboard_shortcuts_reset(); + keyboard_shortcuts_save(); window_invalidate(w); break; } @@ -289,7 +289,7 @@ static void window_shortcut_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, s } char templateString[128]; - keyboard_shortcut_format_string(templateString, 128, gShortcutKeys[i]); + keyboard_shortcuts_format_string(templateString, 128, i); set_format_arg(0, rct_string_id, STR_SHORTCUT_ENTRY_FORMAT); set_format_arg(2, rct_string_id, ShortcutStringIds[i]); diff --git a/src/openrct2/config/KeyboardShortcuts.cpp b/src/openrct2/config/KeyboardShortcuts.cpp deleted file mode 100644 index 7ef482ef40..0000000000 --- a/src/openrct2/config/KeyboardShortcuts.cpp +++ /dev/null @@ -1,173 +0,0 @@ -#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers -/***************************************************************************** - * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. - * - * OpenRCT2 is the work of many authors, a full list can be found in contributors.md - * For more information, visit https://github.com/OpenRCT2/OpenRCT2 - * - * OpenRCT2 is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * A full copy of the GNU General Public License can be found in licence.txt - *****************************************************************************/ -#pragma endregion - -#include "../common.h" -#include "../core/Console.hpp" -#include "../core/File.h" -#include "../core/FileStream.hpp" -#include "../core/Memory.hpp" -#include "../core/Path.hpp" -#include "../core/String.hpp" - -extern "C" -{ - #include "../interface/keyboard_shortcut.h" - #include "../platform/platform.h" -} - -// Current keyboard shortcuts -uint16 gShortcutKeys[SHORTCUT_COUNT]; - -namespace KeyboardShortcuts -{ - // Default keyboard shortcuts - static const uint16 _defaultShortcutKeys[SHORTCUT_COUNT] = - { - SDL_SCANCODE_BACKSPACE, // SHORTCUT_CLOSE_TOP_MOST_WINDOW - SHIFT | SDL_SCANCODE_BACKSPACE, // SHORTCUT_CLOSE_ALL_FLOATING_WINDOWS - SDL_SCANCODE_ESCAPE, // SHORTCUT_CANCEL_CONSTRUCTION_MODE - SDL_SCANCODE_PAUSE, // SHORTCUT_PAUSE_GAME - SDL_SCANCODE_PAGEUP, // SHORTCUT_ZOOM_VIEW_OUT - SDL_SCANCODE_PAGEDOWN, // SHORTCUT_ZOOM_VIEW_IN - SDL_SCANCODE_RETURN, // SHORTCUT_ROTATE_VIEW_CLOCKWISE - SHIFT | SDL_SCANCODE_RETURN, // SHORTCUT_ROTATE_VIEW_ANTICLOCKWISE - SDL_SCANCODE_Z, // SHORTCUT_ROTATE_CONSTRUCTION_OBJECT - SDL_SCANCODE_1, // SHORTCUT_UNDERGROUND_VIEW_TOGGLE - SDL_SCANCODE_H, // SHORTCUT_REMOVE_BASE_LAND_TOGGLE - SDL_SCANCODE_V, // SHORTCUT_REMOVE_VERTICAL_LAND_TOGGLE - SDL_SCANCODE_3, // SHORTCUT_SEE_THROUGH_RIDES_TOGGLE - SDL_SCANCODE_4, // SHORTCUT_SEE_THROUGH_SCENERY_TOGGLE - SDL_SCANCODE_5, // SHORTCUT_INVISIBLE_SUPPORTS_TOGGLE - SDL_SCANCODE_6, // SHORTCUT_INVISIBLE_PEOPLE_TOGGLE - SDL_SCANCODE_8, // SHORTCUT_HEIGHT_MARKS_ON_LAND_TOGGLE - SDL_SCANCODE_9, // SHORTCUT_HEIGHT_MARKS_ON_RIDE_TRACKS_TOGGLE - SDL_SCANCODE_0, // SHORTCUT_HEIGHT_MARKS_ON_PATHS_TOGGLE - SDL_SCANCODE_F1, // SHORTCUT_ADJUST_LAND - SDL_SCANCODE_F2, // SHORTCUT_ADJUST_WATER - SDL_SCANCODE_F3, // SHORTCUT_BUILD_SCENERY - SDL_SCANCODE_F4, // SHORTCUT_BUILD_PATHS - SDL_SCANCODE_F5, // SHORTCUT_BUILD_NEW_RIDE - SDL_SCANCODE_F, // SHORTCUT_SHOW_FINANCIAL_INFORMATION - SDL_SCANCODE_D, // SHORTCUT_SHOW_RESEARCH_INFORMATION - SDL_SCANCODE_R, // SHORTCUT_SHOW_RIDES_LIST - SDL_SCANCODE_P, // SHORTCUT_SHOW_PARK_INFORMATION - SDL_SCANCODE_G, // SHORTCUT_SHOW_GUEST_LIST - SDL_SCANCODE_S, // SHORTCUT_SHOW_STAFF_LIST - SDL_SCANCODE_M, // SHORTCUT_SHOW_RECENT_MESSAGES - SDL_SCANCODE_TAB, // SHORTCUT_SHOW_MAP - PLATFORM_MODIFIER | SDL_SCANCODE_S, // SHORTCUT_SCREENSHOT - SDL_SCANCODE_MINUS, // SHORTCUT_REDUCE_GAME_SPEED, - SDL_SCANCODE_EQUALS, // SHORTCUT_INCREASE_GAME_SPEED, - PLATFORM_MODIFIER | ALT | SDL_SCANCODE_C, // SHORTCUT_OPEN_CHEAT_WINDOW, - SDL_SCANCODE_T, // SHORTCUT_REMOVE_TOP_BOTTOM_TOOLBAR_TOGGLE, - SDL_SCANCODE_UP, // SHORTCUT_SCROLL_MAP_UP - SDL_SCANCODE_LEFT, // SHORTCUT_SCROLL_MAP_LEFT - SDL_SCANCODE_DOWN, // SHORTCUT_SCROLL_MAP_DOWN - 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 - SHORTCUT_UNDEFINED, // SHORTCUT_MUTE_SOUND - ALT | SDL_SCANCODE_RETURN, // SHORTCUT_WINDOWED_MODE_TOGGLE - SHORTCUT_UNDEFINED, // SHORTCUT_SHOW_MULTIPLAYER - SHORTCUT_UNDEFINED, // SHORTCUT_PAINT_ORIGINAL_TOGGLE - SHORTCUT_UNDEFINED, // SHORTCUT_DEBUG_PAINT_TOGGLE - SHORTCUT_UNDEFINED, // SHORTCUT_SEE_THROUGH_PATHS_TOGGLE - SDL_SCANCODE_KP_4, // SHORTCUT_RIDE_CONSTRUCTION_TURN_LEFT - SDL_SCANCODE_KP_6, // SHORTCUT_RIDE_CONSTRUCTION_TURN_RIGHT - SDL_SCANCODE_KP_5, // SHORTCUT_RIDE_CONSTRUCTION_USE_TRACK_DEFAULT - SDL_SCANCODE_KP_2, // SHORTCUT_RIDE_CONSTRUCTION_SLOPE_DOWN - SDL_SCANCODE_KP_8, // SHORTCUT_RIDE_CONSTRUCTION_SLOPE_UP - SDL_SCANCODE_KP_PLUS, // SHORTCUT_RIDE_CONSTRUCTION_CHAIN_LIFT_TOGGLE - SDL_SCANCODE_KP_1, // SHORTCUT_RIDE_CONSTRUCTION_BANK_LEFT - SDL_SCANCODE_KP_3, // SHORTCUT_RIDE_CONSTRUCTION_BANK_RIGHT - SDL_SCANCODE_KP_7, // SHORTCUT_RIDE_CONSTRUCTION_PREVIOUS_TRACK - SDL_SCANCODE_KP_9, // SHORTCUT_RIDE_CONSTRUCTION_NEXT_TRACK - SDL_SCANCODE_KP_0, // SHORTCUT_RIDE_CONSTRUCTION_BUILD_CURRENT - SDL_SCANCODE_KP_MINUS, // SHORTCUT_RIDE_CONSTRUCTION_DEMOLISH_CURRENT - }; - - constexpr sint32 CURRENT_FILE_VERSION = 1; - - static void Reset() - { - Memory::Copy(gShortcutKeys, _defaultShortcutKeys, sizeof(gShortcutKeys)); - } - - static std::string GetPath() - { - utf8 path[MAX_PATH]; - platform_get_user_directory(path, nullptr, sizeof(path)); - Path::Append(path, sizeof(path), "hotkeys.cfg"); - return path; - } -} - -extern "C" -{ - void config_reset_shortcut_keys() - { - KeyboardShortcuts::Reset(); - } - - bool config_shortcut_keys_load() - { - bool result = false; - try - { - std::string path = KeyboardShortcuts::GetPath(); - if (File::Exists(path)) - { - auto fs = FileStream(path, FILE_MODE_OPEN); - uint16 version = fs.ReadValue(); - if (version == KeyboardShortcuts::CURRENT_FILE_VERSION) - { - for (sint32 i = 0; i < SHORTCUT_COUNT; i++) - { - gShortcutKeys[i] = fs.ReadValue(); - } - result = true; - } - } - } - catch (const Exception &ex) - { - Console::WriteLine("Error reading shortcut keys: %s", ex.GetMessage()); - } - return result; - } - - bool config_shortcut_keys_save() - { - bool result = false; - try - { - std::string path = KeyboardShortcuts::GetPath(); - auto fs = FileStream(path, FILE_MODE_WRITE); - fs.WriteValue(KeyboardShortcuts::CURRENT_FILE_VERSION); - for (sint32 i = 0; i < SHORTCUT_COUNT; i++) - { - fs.WriteValue(gShortcutKeys[i]); - } - result = true; - } - catch (const Exception &ex) - { - Console::WriteLine("Error writing shortcut keys: %s", ex.GetMessage()); - } - return result; - } -} diff --git a/src/openrct2/input.c b/src/openrct2/input.c index f9a627d6e2..490bca269e 100644 --- a/src/openrct2/input.c +++ b/src/openrct2/input.c @@ -23,7 +23,6 @@ #include "interface/chat.h" #include "interface/console.h" #include "interface/Cursors.h" -#include "interface/keyboard_shortcut.h" #include "interface/viewport.h" #include "interface/widget.h" #include "interface/window.h" @@ -1485,14 +1484,14 @@ void title_handle_keyboard_input() w = window_find_by_class(WC_CHANGE_KEYBOARD_SHORTCUT); if (w != NULL) { - keyboard_shortcut_set(key); + // keyboard_shortcut_set(key); } else { w = window_find_by_class(WC_TEXTINPUT); if (w != NULL) { window_text_input_key(w, key); } else if (!gUsingWidgetTextBox) { - keyboard_shortcut_handle(key); + // keyboard_shortcut_handle(key); } } } @@ -1564,13 +1563,13 @@ void game_handle_keyboard_input() w = window_find_by_class(WC_CHANGE_KEYBOARD_SHORTCUT); if (w != NULL) { - keyboard_shortcut_set(key); + // keyboard_shortcut_set(key); } else { w = window_find_by_class(WC_TEXTINPUT); if (w != NULL) { window_text_input_key(w, key); } else if (!gUsingWidgetTextBox) { - keyboard_shortcut_handle(key); + // keyboard_shortcut_handle(key); } } } @@ -1706,44 +1705,44 @@ void game_handle_key_scroll() scrollX = 0; scrollY = 0; - const uint8 * keysState = context_get_keys_state(); - for (sint32 shortcutId = SHORTCUT_SCROLL_MAP_UP; shortcutId <= SHORTCUT_SCROLL_MAP_RIGHT; shortcutId++) { - uint16 shortcutKey = gShortcutKeys[shortcutId]; - uint8 scancode = shortcutKey & 0xFF; - - if (shortcutKey == 0xFFFF) continue; - if (!keysState[scancode]) continue; - - if (shortcutKey & SHIFT) { - if (!keysState[SDL_SCANCODE_LSHIFT] && !keysState[SDL_SCANCODE_RSHIFT]) continue; - } - if (shortcutKey & CTRL) { - if (!keysState[SDL_SCANCODE_LCTRL] && !keysState[SDL_SCANCODE_RCTRL]) continue; - } - if (shortcutKey & ALT) { - if (!keysState[SDL_SCANCODE_LALT] && !keysState[SDL_SCANCODE_RALT]) continue; - } -#ifdef __MACOSX__ - if (shortcutKey & CMD) { - if (!keysState[SDL_SCANCODE_LGUI] && !keysState[SDL_SCANCODE_RGUI]) continue; - } -#endif - - switch (shortcutId) { - case SHORTCUT_SCROLL_MAP_UP: - scrollY = -1; - break; - case SHORTCUT_SCROLL_MAP_LEFT: - scrollX = -1; - break; - case SHORTCUT_SCROLL_MAP_DOWN: - scrollY = 1; - break; - case SHORTCUT_SCROLL_MAP_RIGHT: - scrollX = 1; - break; - } - } +// const uint8 * keysState = context_get_keys_state(); +// for (sint32 shortcutId = SHORTCUT_SCROLL_MAP_UP; shortcutId <= SHORTCUT_SCROLL_MAP_RIGHT; shortcutId++) { +// uint16 shortcutKey = gShortcutKeys[shortcutId]; +// uint8 scancode = shortcutKey & 0xFF; +// +// if (shortcutKey == 0xFFFF) continue; +// if (!keysState[scancode]) continue; +// +// if (shortcutKey & SHIFT) { +// if (!keysState[SDL_SCANCODE_LSHIFT] && !keysState[SDL_SCANCODE_RSHIFT]) continue; +// } +// if (shortcutKey & CTRL) { +// if (!keysState[SDL_SCANCODE_LCTRL] && !keysState[SDL_SCANCODE_RCTRL]) continue; +// } +// if (shortcutKey & ALT) { +// if (!keysState[SDL_SCANCODE_LALT] && !keysState[SDL_SCANCODE_RALT]) continue; +// } +// #ifdef __MACOSX__ +// if (shortcutKey & CMD) { +// if (!keysState[SDL_SCANCODE_LGUI] && !keysState[SDL_SCANCODE_RGUI]) continue; +// } +// #endif +// +// switch (shortcutId) { +// case SHORTCUT_SCROLL_MAP_UP: +// scrollY = -1; +// break; +// case SHORTCUT_SCROLL_MAP_LEFT: +// scrollX = -1; +// break; +// case SHORTCUT_SCROLL_MAP_DOWN: +// scrollY = 1; +// break; +// case SHORTCUT_SCROLL_MAP_RIGHT: +// scrollX = 1; +// break; +// } +// } // Scroll viewport if (scrollX != 0) { diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index 4326c7dced..408bdb7eb7 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -59,8 +59,339 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/openrct2/network/network.cpp b/src/openrct2/network/network.cpp index 6f65c3c895..a7bcb1eb18 100644 --- a/src/openrct2/network/network.cpp +++ b/src/openrct2/network/network.cpp @@ -57,7 +57,6 @@ extern "C" { #include "../game.h" #include "../interface/chat.h" #include "../interface/window.h" -#include "../interface/keyboard_shortcut.h" #include "../localisation/date.h" #include "../localisation/localisation.h" #include "../management/finance.h" @@ -2364,7 +2363,7 @@ void network_chat_show_connected_message() { char templateBuffer[128]; char *templateString = templateBuffer; - keyboard_shortcut_format_string(templateBuffer, 128, gShortcutKeys[SHORTCUT_OPEN_CHAT_WINDOW]); + // keyboard_shortcuts_format_string(templateBuffer, sizeof(templateBuffer), SHORTCUT_OPEN_CHAT_WINDOW); utf8 buffer[256]; NetworkPlayer server; server.Name = "Server"; diff --git a/src/openrct2/platform/shared.c b/src/openrct2/platform/shared.c index 4529818f1a..6cbcd3856d 100644 --- a/src/openrct2/platform/shared.c +++ b/src/openrct2/platform/shared.c @@ -27,7 +27,6 @@ #include "../input.h" #include "../interface/console.h" #include "../interface/Cursors.h" -#include "../interface/keyboard_shortcut.h" #include "../interface/window.h" #include "../localisation/currency.h" #include "../localisation/localisation.h" diff --git a/src/openrct2/rct2.c b/src/openrct2/rct2.c index 2669ac7d7f..6e242fa305 100644 --- a/src/openrct2/rct2.c +++ b/src/openrct2/rct2.c @@ -28,7 +28,6 @@ #include "input.h" #include "interface/chat.h" #include "interface/console.h" -#include "interface/keyboard_shortcut.h" #include "interface/viewport.h" #include "intro.h" #include "localisation/date.h" @@ -151,10 +150,7 @@ bool rct2_init() gScenarioTicks = 0; util_srand((uint32)time(0)); - config_reset_shortcut_keys(); - config_shortcut_keys_load(); input_reset_place_obj_modifier(); - // config_load(); if (!gfx_load_g1()) { return false;