From e7ae9f9f15cc1d85ea2e026ad239484d1df7632e Mon Sep 17 00:00:00 2001 From: Ted John Date: Tue, 12 Jan 2021 22:34:30 +0000 Subject: [PATCH] Read legacy shortcuts and move to constants --- src/openrct2-ui/UiContext.cpp | 21 +- src/openrct2-ui/input/InputManager.cpp | 2 +- src/openrct2-ui/input/KeyboardShortcut.cpp | 171 +++++++-------- src/openrct2-ui/input/KeyboardShortcuts.cpp | 4 +- src/openrct2-ui/input/ShortcutManager.cpp | 224 +++++++++++++++++++- src/openrct2-ui/input/ShortcutManager.h | 112 +++++++++- src/openrct2/PlatformEnvironment.cpp | 6 +- src/openrct2/PlatformEnvironment.h | 29 +-- src/openrct2/core/DataSerialiser.h | 60 ++++++ src/openrct2/core/DataSerialiserTraits.h | 8 + 10 files changed, 520 insertions(+), 117 deletions(-) diff --git a/src/openrct2-ui/UiContext.cpp b/src/openrct2-ui/UiContext.cpp index d5247b500d..14eb4c0e56 100644 --- a/src/openrct2-ui/UiContext.cpp +++ b/src/openrct2-ui/UiContext.cpp @@ -14,7 +14,7 @@ #include "TextComposition.h" #include "WindowManager.h" #include "drawing/engines/DrawingEngineFactory.hpp" -#include "input/KeyboardShortcuts.h" +#include "input/ShortcutManager.h" #include "interface/InGameConsole.h" #include "interface/Theme.h" #include "scripting/UiExtensions.h" @@ -49,7 +49,6 @@ using namespace OpenRCT2; using namespace OpenRCT2::Drawing; -using namespace OpenRCT2::Input; using namespace OpenRCT2::Scripting; using namespace OpenRCT2::Ui; @@ -80,7 +79,7 @@ private: bool _steamOverlayActive = false; // Input - KeyboardShortcuts _keyboardShortcuts; + ShortcutManager _shortcutManager; TextComposition _textComposition; CursorState _cursorState = {}; uint32_t _lastKeyPressed = 0; @@ -98,18 +97,22 @@ public: return _inGameConsole; } + ShortcutManager& GetShortcutManager() + { + return _shortcutManager; + } + explicit UiContext(const std::shared_ptr& env) : _platformUiContext(CreatePlatformUiContext()) , _windowManager(CreateWindowManager()) - , _keyboardShortcuts(env) + , _shortcutManager(env) { if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) { SDLException::Throw("SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK)"); } _cursorRepository.LoadCursors(); - _keyboardShortcuts.Reset(); - _keyboardShortcuts.Load(); + _shortcutManager.LoadUserBindings(); } ~UiContext() override @@ -956,3 +959,9 @@ InGameConsole& OpenRCT2::Ui::GetInGameConsole() auto uiContext = std::static_pointer_cast(GetContext()->GetUiContext()); return uiContext->GetInGameConsole(); } + +ShortcutManager& OpenRCT2::Ui::GetShortcutManager() +{ + auto uiContext = std::static_pointer_cast(GetContext()->GetUiContext()); + return uiContext->GetShortcutManager(); +} diff --git a/src/openrct2-ui/input/InputManager.cpp b/src/openrct2-ui/input/InputManager.cpp index 1817e7dfd7..8f78da1e3e 100644 --- a/src/openrct2-ui/input/InputManager.cpp +++ b/src/openrct2-ui/input/InputManager.cpp @@ -178,7 +178,7 @@ void InputManager::Process(const InputEvent& e) auto& console = GetInGameConsole(); if (console.IsOpen()) { - if (!shortcutManager.ProcessEventForSpecificShortcut(e, SHORTCUT_ID_DEBUG_CONSOLE)) + if (!shortcutManager.ProcessEventForSpecificShortcut(e, ShortcutId::DebugToggleConsole)) { ProcessInGameConsole(e); } diff --git a/src/openrct2-ui/input/KeyboardShortcut.cpp b/src/openrct2-ui/input/KeyboardShortcut.cpp index 1b37aab851..0296eb1b5d 100644 --- a/src/openrct2-ui/input/KeyboardShortcut.cpp +++ b/src/openrct2-ui/input/KeyboardShortcut.cpp @@ -620,8 +620,8 @@ void ShortcutManager::RegisterDefaultShortcuts() // clang-format off // Interface 0 - RegisterShortcut("interface0.close_top", STR_SHORTCUT_CLOSE_TOP_MOST_WINDOW, "BACKSPACE", []() { window_close_top(); }); - RegisterShortcut("interface0.close_all", STR_SHORTCUT_CLOSE_ALL_FLOATING_WINDOWS, "SHIFT+BACKSPACE", []() { + RegisterShortcut(ShortcutId::InterfaceCloseTop, STR_SHORTCUT_CLOSE_TOP_MOST_WINDOW, "BACKSPACE", []() { window_close_top(); }); + RegisterShortcut(ShortcutId::InterfaceCloseAll, STR_SHORTCUT_CLOSE_ALL_FLOATING_WINDOWS, "SHIFT+BACKSPACE", []() { if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR)) { window_close_all(); @@ -631,7 +631,7 @@ void ShortcutManager::RegisterDefaultShortcuts() window_close_top(); } }); - RegisterShortcut("interface0.cancel_construction", STR_SHORTCUT_CANCEL_CONSTRUCTION_MODE, "ESCAPE", []() { + RegisterShortcut(ShortcutId::InterfaceCancelConstruction, STR_SHORTCUT_CANCEL_CONSTRUCTION_MODE, "ESCAPE", []() { if (!(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)) { auto window = window_find_by_class(WC_ERROR); @@ -645,12 +645,12 @@ void ShortcutManager::RegisterDefaultShortcuts() } } }); - RegisterShortcut("interface0.toggle_toolbars", STR_SHORTCUT_TOGGLE_VISIBILITY_OF_TOOLBARS, "T", []() { + RegisterShortcut(ShortcutId::InterfaceToggleToolbars, STR_SHORTCUT_TOGGLE_VISIBILITY_OF_TOOLBARS, "T", []() { ShortcutRemoveTopBottomToolbarToggle(); }); // Interface 1 - RegisterShortcut("interface1.pause", STR_SHORTCUT_PAUSE_GAME, "PAUSE", []() { + RegisterShortcut(ShortcutId::InterfacePause, STR_SHORTCUT_PAUSE_GAME, "PAUSE", []() { if (!(gScreenFlags & (SCREEN_FLAGS_TITLE_DEMO | SCREEN_FLAGS_SCENARIO_EDITOR | SCREEN_FLAGS_TRACK_MANAGER))) { auto window = window_find_by_class(WC_TOP_TOOLBAR); @@ -661,50 +661,50 @@ void ShortcutManager::RegisterDefaultShortcuts() } } }); - RegisterShortcut("interface1.decrease_speed", STR_SHORTCUT_REDUCE_GAME_SPEED , "-", []() { ShortcutReduceGameSpeed(); }); - RegisterShortcut("interface1.increase_speed", STR_SHORTCUT_INCREASE_GAME_SPEED , "=", []() { ShortcutIncreaseGameSpeed(); }); - RegisterShortcut("interface1.load_game", STR_LOAD_GAME, "CTRL+L", []() { ShortcutLoadGame(); }); - RegisterShortcut("interface1.save_game", STR_LOAD_GAME, "CTRL+F10", []() { ShortcutQuickSaveGame(); }); - RegisterShortcut("interface1.show_options", STR_SHORTCUT_SHOW_OPTIONS, []() { context_open_window(WC_OPTIONS); }); - RegisterShortcut("interface1.screenshot", STR_SHORTCUT_SCREENSHOT, "CTRL+S", []() { gScreenshotCountdown = 2; }); - RegisterShortcut("interface1.mute", STR_SHORTCUT_MUTE_SOUND, []() { OpenRCT2::Audio::ToggleAllSounds(); }); + RegisterShortcut(ShortcutId::InterfaceDecreaseSpeed, STR_SHORTCUT_REDUCE_GAME_SPEED , "-", []() { ShortcutReduceGameSpeed(); }); + RegisterShortcut(ShortcutId::InterfaceIncreaseSpeed, STR_SHORTCUT_INCREASE_GAME_SPEED , "=", []() { ShortcutIncreaseGameSpeed(); }); + RegisterShortcut(ShortcutId::InterfaceLoadGame, STR_LOAD_GAME, "CTRL+L", []() { ShortcutLoadGame(); }); + RegisterShortcut(ShortcutId::InterfaceSaveGame, STR_LOAD_GAME, "CTRL+F10", []() { ShortcutQuickSaveGame(); }); + RegisterShortcut(ShortcutId::InterfaceShowOptions, STR_SHORTCUT_SHOW_OPTIONS, []() { context_open_window(WC_OPTIONS); }); + RegisterShortcut(ShortcutId::InterfaceScreenshot, STR_SHORTCUT_SCREENSHOT, "CTRL+S", []() { gScreenshotCountdown = 2; }); + RegisterShortcut(ShortcutId::InterfaceMute, STR_SHORTCUT_MUTE_SOUND, []() { OpenRCT2::Audio::ToggleAllSounds(); }); // Interface 2 - RegisterShortcut("interface2.open_cheats", STR_SHORTCUT_OPEN_CHEATS_WINDOW, "CTRL+ALT+C", []() { ShortcutOpenCheatWindow(); }); - RegisterShortcut("interface2.disable_clearance", STR_SHORTCUT_TOGGLE_CLEARANCE_CHECKS, []() { ShortcutToggleClearanceChecks(); }); + RegisterShortcut(ShortcutId::InterfaceOpenCheats, STR_SHORTCUT_OPEN_CHEATS_WINDOW, "CTRL+ALT+C", []() { ShortcutOpenCheatWindow(); }); + RegisterShortcut(ShortcutId::InterfaceDisableClearance, STR_SHORTCUT_TOGGLE_CLEARANCE_CHECKS, []() { ShortcutToggleClearanceChecks(); }); // Interface 3 - RegisterShortcut("interface3.zoom_out", STR_SHORTCUT_ZOOM_VIEW_OUT, "PAGEUP", []() { main_window_zoom(false, false); }); - RegisterShortcut("interface3.zoom_in", STR_SHORTCUT_ZOOM_VIEW_IN, "PAGEDOWN", []() { main_window_zoom(true, false); }); - RegisterShortcut("interface3.rotate_clockwise", STR_SHORTCUT_ROTATE_VIEW_CLOCKWISE, "RETURN", "MOUSE:5", []() { RotateCamera(1); }); - RegisterShortcut("interface3.rotate_anticlockwise", STR_SHORTCUT_ROTATE_VIEW_ANTICLOCKWISE, "SHIFT+RETURN", "MOUSE:4", []() { RotateCamera(-1); }); - RegisterShortcut("interface3.show_map", STR_SHORTCUT_TOGGLE_CLEARANCE_CHECKS, "TAB", []() { ShortcutShowMap(); }); + RegisterShortcut(ShortcutId::InterfaceZoomOut, STR_SHORTCUT_ZOOM_VIEW_OUT, "PAGEUP", []() { main_window_zoom(false, false); }); + RegisterShortcut(ShortcutId::InterfaceZoomIn, STR_SHORTCUT_ZOOM_VIEW_IN, "PAGEDOWN", []() { main_window_zoom(true, false); }); + RegisterShortcut(ShortcutId::InterfaceRotateClockwise, STR_SHORTCUT_ROTATE_VIEW_CLOCKWISE, "RETURN", "MOUSE:5", []() { RotateCamera(1); }); + RegisterShortcut(ShortcutId::InterfaceRotateAnticlockwise, STR_SHORTCUT_ROTATE_VIEW_ANTICLOCKWISE, "SHIFT+RETURN", "MOUSE:4", []() { RotateCamera(-1); }); + RegisterShortcut(ShortcutId::InterfaceOpenMap, STR_SHORTCUT_TOGGLE_CLEARANCE_CHECKS, "TAB", []() { ShortcutShowMap(); }); // Interface 4 - RegisterShortcut("interface4.clear_scenery", STR_SHORTCUT_CLEAR_SCENERY, "B", []() { ShortcutClearScenery(); }); - RegisterShortcut("interface4.adjust_land", STR_SHORTCUT_ADJUST_LAND, "F1", []() { ShortcutAdjustLand(); }); - RegisterShortcut("interface4.adjust_water", STR_SHORTCUT_ADJUST_WATER, "F2", []() { ShortcutAdjustWater(); }); - RegisterShortcut("interface4.build_scenery", STR_SHORTCUT_BUILD_SCENERY, "F3", []() { ShortcutBuildScenery(); }); - RegisterShortcut("interface4.build_footpaths", STR_SHORTCUT_BUILD_PATHS, "F4", []() { ShortcutBuildPaths(); }); - RegisterShortcut("interface4.build_new_ride", STR_SHORTCUT_BUILD_NEW_RIDE, "F5", []() { ShortcutBuildNewRide(); }); + RegisterShortcut(ShortcutId::InterfaceClearScenery, STR_SHORTCUT_CLEAR_SCENERY, "B", []() { ShortcutClearScenery(); }); + RegisterShortcut(ShortcutId::InterfaceOpenLand, STR_SHORTCUT_ADJUST_LAND, "F1", []() { ShortcutAdjustLand(); }); + RegisterShortcut(ShortcutId::InterfaceOpenWater, STR_SHORTCUT_ADJUST_WATER, "F2", []() { ShortcutAdjustWater(); }); + RegisterShortcut(ShortcutId::InterfaceOpenScenery, STR_SHORTCUT_BUILD_SCENERY, "F3", []() { ShortcutBuildScenery(); }); + RegisterShortcut(ShortcutId::InterfaceOpenFootpaths, STR_SHORTCUT_BUILD_PATHS, "F4", []() { ShortcutBuildPaths(); }); + RegisterShortcut(ShortcutId::InterfaceOpenNewRide, STR_SHORTCUT_BUILD_NEW_RIDE, "F5", []() { ShortcutBuildNewRide(); }); // Interface 5 - RegisterShortcut("interface5.show_finances", STR_SHORTCUT_SHOW_FINANCIAL_INFORMATION, "F", []() { ShortcutShowFinancialInformation(); }); - RegisterShortcut("interface5.show_research", STR_SHORTCUT_SHOW_RESEARCH_INFORMATION, "D", []() { ShortcutShowResearchInformation(); }); - RegisterShortcut("interface5.show_rides", STR_SHORTCUT_SHOW_RIDES_LIST, "R", []() { ShortcutShowRidesList(); }); - RegisterShortcut("interface5.show_park", STR_SHORTCUT_SHOW_PARK_INFORMATION, "P", []() { ShortcutShowParkInformation(); }); - RegisterShortcut("interface5.show_guests", STR_SHORTCUT_SHOW_GUEST_LIST, "G", []() { ShortcutShowGuestList(); }); - RegisterShortcut("interface5.show_staff", STR_SHORTCUT_SHOW_STAFF_LIST, "S", []() { ShortcutShowStaffList(); }); - RegisterShortcut("interface5.show_messages", STR_SHORTCUT_SHOW_RECENT_MESSAGES, "M", []() { ShortcutShowRecentMessages(); }); + RegisterShortcut(ShortcutId::InterfaceOpenFinances, STR_SHORTCUT_SHOW_FINANCIAL_INFORMATION, "F", []() { ShortcutShowFinancialInformation(); }); + RegisterShortcut(ShortcutId::InterfaceOpenResearch, STR_SHORTCUT_SHOW_RESEARCH_INFORMATION, "D", []() { ShortcutShowResearchInformation(); }); + RegisterShortcut(ShortcutId::InterfaceOpenRides, STR_SHORTCUT_SHOW_RIDES_LIST, "R", []() { ShortcutShowRidesList(); }); + RegisterShortcut(ShortcutId::InterfaceOpenPark, STR_SHORTCUT_SHOW_PARK_INFORMATION, "P", []() { ShortcutShowParkInformation(); }); + RegisterShortcut(ShortcutId::InterfaceOpenGuests, STR_SHORTCUT_SHOW_GUEST_LIST, "G", []() { ShortcutShowGuestList(); }); + RegisterShortcut(ShortcutId::InterfaceOpenStaff, STR_SHORTCUT_SHOW_STAFF_LIST, "S", []() { ShortcutShowStaffList(); }); + RegisterShortcut(ShortcutId::InterfaceOpenMessages, STR_SHORTCUT_SHOW_RECENT_MESSAGES, "M", []() { ShortcutShowRecentMessages(); }); // Multiplayer - RegisterShortcut("multiplayer.show", STR_SHORTCUT_SHOW_MULTIPLAYER, []() { + RegisterShortcut(ShortcutId::MultiplayerShow, STR_SHORTCUT_SHOW_MULTIPLAYER, []() { if (network_get_mode() != NETWORK_MODE_NONE) { OpenWindow(WC_MULTIPLAYER); } }); - RegisterShortcut("multiplayer.chat", STR_SEND_MESSAGE, "C", []() { + RegisterShortcut(ShortcutId::MultiplayerChat, STR_SEND_MESSAGE, "C", []() { if (!(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)) { if (chat_available()) @@ -715,81 +715,82 @@ void ShortcutManager::RegisterDefaultShortcuts() }); // View - RegisterShortcut("view.show_underground", STR_SHORTCUT_UNDERGROUND_VIEW_TOGGLE, "1", []() { ToggleViewFlag(VIEWPORT_FLAG_UNDERGROUND_INSIDE); }); - RegisterShortcut("view.hide_base_land", STR_SHORTCUT_REMOVE_BASE_LAND_TOGGLE, "H", []() { ToggleViewFlag(VIEWPORT_FLAG_HIDE_BASE); }); - RegisterShortcut("view.hide_vertical_land", STR_SHORTCUT_REMOVE_VERTICAL_LAND_TOGGLE, "V", []() { ToggleViewFlag(VIEWPORT_FLAG_HIDE_BASE); }); - RegisterShortcut("view.transparent_rides", STR_SHORTCUT_SEE_THROUGH_RIDES_TOGGLE, "3", []() { ToggleViewFlag(VIEWPORT_FLAG_SEETHROUGH_RIDES); }); - RegisterShortcut("view.transparent_scenery", STR_SHORTCUT_SEE_THROUGH_SCENERY_TOGGLE, "4", []() { ToggleViewFlag(VIEWPORT_FLAG_SEETHROUGH_SCENERY); }); - RegisterShortcut("view.transparent_scenery", STR_SHORTCUT_SEE_THROUGH_PATHS_TOGGLE, []() { ToggleViewFlag(VIEWPORT_FLAG_SEETHROUGH_PATHS); }); - RegisterShortcut("view.hide_supports", STR_SHORTCUT_INVISIBLE_SUPPORTS_TOGGLE, "5", []() { ToggleViewFlag(VIEWPORT_FLAG_INVISIBLE_SUPPORTS); }); - RegisterShortcut("view.hide_peeps", STR_SHORTCUT_INVISIBLE_PEOPLE_TOGGLE, "6", []() { ToggleViewFlag(VIEWPORT_FLAG_INVISIBLE_PEEPS); }); - RegisterShortcut("view.show_land_height", STR_SHORTCUT_HEIGHT_MARKS_ON_LAND_TOGGLE, "8", []() { ToggleViewFlag(VIEWPORT_FLAG_LAND_HEIGHTS); }); - RegisterShortcut("view.show_track_height", STR_SHORTCUT_HEIGHT_MARKS_ON_RIDE_TRACKS_TOGGLE, "9", []() { ToggleViewFlag(VIEWPORT_FLAG_TRACK_HEIGHTS); }); - RegisterShortcut("view.show_footpath_height", STR_SHORTCUT_HEIGHT_MARKS_ON_PATHS_TOGGLE, "0", []() { ToggleViewFlag(VIEWPORT_FLAG_PATH_HEIGHTS); }); - RegisterShortcut("view.toggle_cut_away", STR_SHORTCUT_VIEW_CLIPPING, []() { OpenWindow(WC_VIEW_CLIPPING); }); - RegisterShortcut("view.highlight_path_issues", STR_SHORTCUT_HIGHLIGHT_PATH_ISSUES_TOGGLE, "I", []() { ToggleViewFlag(VIEWPORT_FLAG_PATH_HEIGHTS); }); - RegisterShortcut("view.show_gridlines", STR_SHORTCUT_GRIDLINES_DISPLAY_TOGGLE, "7", []() { ToggleViewFlag(VIEWPORT_FLAG_GRIDLINES); }); + RegisterShortcut(ShortcutId::ViewToggleUnderground, STR_SHORTCUT_UNDERGROUND_VIEW_TOGGLE, "1", []() { ToggleViewFlag(VIEWPORT_FLAG_UNDERGROUND_INSIDE); }); + RegisterShortcut(ShortcutId::ViewToggleBaseLand, STR_SHORTCUT_REMOVE_BASE_LAND_TOGGLE, "H", []() { ToggleViewFlag(VIEWPORT_FLAG_HIDE_BASE); }); + RegisterShortcut(ShortcutId::ViewToggleVerticalLand, STR_SHORTCUT_REMOVE_VERTICAL_LAND_TOGGLE, "V", []() { ToggleViewFlag(VIEWPORT_FLAG_HIDE_BASE); }); + RegisterShortcut(ShortcutId::ViewToggleRides, STR_SHORTCUT_SEE_THROUGH_RIDES_TOGGLE, "3", []() { ToggleViewFlag(VIEWPORT_FLAG_SEETHROUGH_RIDES); }); + RegisterShortcut(ShortcutId::ViewToggleScenery, STR_SHORTCUT_SEE_THROUGH_SCENERY_TOGGLE, "4", []() { ToggleViewFlag(VIEWPORT_FLAG_SEETHROUGH_SCENERY); }); + RegisterShortcut(ShortcutId::ViewToggleFootpaths, STR_SHORTCUT_SEE_THROUGH_PATHS_TOGGLE, []() { ToggleViewFlag(VIEWPORT_FLAG_SEETHROUGH_PATHS); }); + RegisterShortcut(ShortcutId::ViewToggleSupports, STR_SHORTCUT_INVISIBLE_SUPPORTS_TOGGLE, "5", []() { ToggleViewFlag(VIEWPORT_FLAG_INVISIBLE_SUPPORTS); }); + RegisterShortcut(ShortcutId::ViewTogglePeeps, STR_SHORTCUT_INVISIBLE_PEOPLE_TOGGLE, "6", []() { ToggleViewFlag(VIEWPORT_FLAG_INVISIBLE_PEEPS); }); + RegisterShortcut(ShortcutId::ViewToggleLandHeightMarkers, STR_SHORTCUT_HEIGHT_MARKS_ON_LAND_TOGGLE, "8", []() { ToggleViewFlag(VIEWPORT_FLAG_LAND_HEIGHTS); }); + RegisterShortcut(ShortcutId::ViewToggleTrackHeightMarkers, STR_SHORTCUT_HEIGHT_MARKS_ON_RIDE_TRACKS_TOGGLE, "9", []() { ToggleViewFlag(VIEWPORT_FLAG_TRACK_HEIGHTS); }); + RegisterShortcut(ShortcutId::ViewToggleFootpathHeightMarkers, STR_SHORTCUT_HEIGHT_MARKS_ON_PATHS_TOGGLE, "0", []() { ToggleViewFlag(VIEWPORT_FLAG_PATH_HEIGHTS); }); + RegisterShortcut(ShortcutId::ViewToggleCutAway, STR_SHORTCUT_VIEW_CLIPPING, []() { OpenWindow(WC_VIEW_CLIPPING); }); + RegisterShortcut(ShortcutId::ViewToogleFootpathIssues, STR_SHORTCUT_HIGHLIGHT_PATH_ISSUES_TOGGLE, "I", []() { ToggleViewFlag(VIEWPORT_FLAG_PATH_HEIGHTS); }); + RegisterShortcut(ShortcutId::ViewToggleGridlines, STR_SHORTCUT_GRIDLINES_DISPLAY_TOGGLE, "7", []() { ToggleViewFlag(VIEWPORT_FLAG_GRIDLINES); }); // Interface 6 - RegisterShortcut("interface6.scenery_picker", STR_SHORTCUT_OPEN_SCENERY_PICKER, []() { ShortcutOpenSceneryPicker(); }); - RegisterShortcut("interface6.rotate_construction", STR_SHORTCUT_ROTATE_CONSTRUCTION_OBJECT, "Z", []() { ShortcutRotateConstructionObject(); }); + RegisterShortcut(ShortcutId::InterfaceSceneryPicker, STR_SHORTCUT_OPEN_SCENERY_PICKER, []() { ShortcutOpenSceneryPicker(); }); + RegisterShortcut(ShortcutId::InterfaceRotateConstruction, STR_SHORTCUT_ROTATE_CONSTRUCTION_OBJECT, "Z", []() { ShortcutRotateConstructionObject(); }); // Ride construction // Map scrolling - RegisterShortcut("scroll.up", STR_SHORTCUT_SCROLL_MAP_UP, "UP", []() { }); - RegisterShortcut("scroll.left", STR_SHORTCUT_SCROLL_MAP_LEFT, "LEFT", []() { }); - RegisterShortcut("scroll.right", STR_SHORTCUT_SCROLL_MAP_RIGHT, "RIGHT", []() { }); - RegisterShortcut("scroll.down", STR_SHORTCUT_SCROLL_MAP_DOWN, "DOWN", []() { }); + RegisterShortcut(ShortcutId::ScrollUp, STR_SHORTCUT_SCROLL_MAP_UP, "UP", []() { }); + RegisterShortcut(ShortcutId::ScrollLeft, STR_SHORTCUT_SCROLL_MAP_LEFT, "LEFT", []() { }); + RegisterShortcut(ShortcutId::ScrollRight, STR_SHORTCUT_SCROLL_MAP_RIGHT, "RIGHT", []() { }); + RegisterShortcut(ShortcutId::ScrollDown, STR_SHORTCUT_SCROLL_MAP_DOWN, "DOWN", []() { }); // Window scale - RegisterShortcut("scale.toggle_window_mode", STR_SHORTCUT_WINDOWED_MODE_TOGGLE, "ALT+RETURN", []() { platform_toggle_windowed_mode(); }); - RegisterShortcut("scale.increase", STR_SHORTCUT_SCALE_UP, []() { ShortcutScaleUp(); }); - RegisterShortcut("scale.decrease", STR_SHORTCUT_SCALE_DOWN, []() { ShortcutScaleDown(); }); + RegisterShortcut(ShortcutId::ScaleToggleWindowMode, STR_SHORTCUT_WINDOWED_MODE_TOGGLE, "ALT+RETURN", []() { platform_toggle_windowed_mode(); }); + RegisterShortcut(ShortcutId::InterfaceScaleIncrease, STR_SHORTCUT_SCALE_UP, []() { ShortcutScaleUp(); }); + RegisterShortcut(ShortcutId::InterfaceScaleDecrease, STR_SHORTCUT_SCALE_DOWN, []() { ShortcutScaleDown(); }); // Ride construction - RegisterShortcut("rideconstruction.turn_left", STR_SHORTCUT_RIDE_CONSTRUCTION_TURN_LEFT, "KEYPAD 4", []() { window_ride_construction_keyboard_shortcut_turn_left(); }); - RegisterShortcut("rideconstruction.turn_right", STR_SHORTCUT_RIDE_CONSTRUCTION_TURN_RIGHT, "KEYPAD 6", []() { window_ride_construction_keyboard_shortcut_turn_right(); }); - RegisterShortcut("rideconstruction.default", STR_SHORTCUT_RIDE_CONSTRUCTION_USE_TRACK_DEFAULT, "KEYPAD 5", []() { window_ride_construction_keyboard_shortcut_use_track_default(); }); - RegisterShortcut("rideconstruction.slope_down", STR_SHORTCUT_RIDE_CONSTRUCTION_SLOPE_DOWN, "KEYPAD 2", []() { window_ride_construction_keyboard_shortcut_slope_down(); }); - RegisterShortcut("rideconstruction.slope_up", STR_SHORTCUT_RIDE_CONSTRUCTION_SLOPE_UP, "KEYPAD 8", []() { window_ride_construction_keyboard_shortcut_slope_up(); }); - RegisterShortcut("rideconstruction.chain_lift", STR_SHORTCUT_RIDE_CONSTRUCTION_CHAIN_LIFT_TOGGLE, "KEYPAD +", []() { window_ride_construction_keyboard_shortcut_chain_lift_toggle(); }); - RegisterShortcut("rideconstruction.bank_left", STR_SHORTCUT_RIDE_CONSTRUCTION_BANK_LEFT, "KEYPAD 1", []() { window_ride_construction_keyboard_shortcut_bank_left(); }); - RegisterShortcut("rideconstruction.bank_right", STR_SHORTCUT_RIDE_CONSTRUCTION_BANK_RIGHT, "KEYPAD 3", []() { window_ride_construction_keyboard_shortcut_bank_right(); }); - RegisterShortcut("rideconstruction.previous", STR_SHORTCUT_RIDE_CONSTRUCTION_PREVIOUS_TRACK, "KEYPAD 7", []() { window_ride_construction_keyboard_shortcut_previous_track(); }); - RegisterShortcut("rideconstruction.next", STR_SHORTCUT_RIDE_CONSTRUCTION_NEXT_TRACK, "KEYPAD 9", []() { window_ride_construction_keyboard_shortcut_next_track(); }); - RegisterShortcut("rideconstruction.build", STR_SHORTCUT_RIDE_CONSTRUCTION_BUILD_CURRENT, "KEYPAD 0", []() { window_ride_construction_keyboard_shortcut_build_current(); }); - RegisterShortcut("rideconstruction.demolish", STR_SHORTCUT_RIDE_CONSTRUCTION_DEMOLISH_CURRENT, "KEYPAD -", []() { window_ride_construction_keyboard_shortcut_demolish_current(); }); + RegisterShortcut(ShortcutId::WindowRideConstructionTurnLeft, STR_SHORTCUT_RIDE_CONSTRUCTION_TURN_LEFT, "KEYPAD 4", []() { window_ride_construction_keyboard_shortcut_turn_left(); }); + RegisterShortcut(ShortcutId::WindowRideConstructionTurnRight, STR_SHORTCUT_RIDE_CONSTRUCTION_TURN_RIGHT, "KEYPAD 6", []() { window_ride_construction_keyboard_shortcut_turn_right(); }); + RegisterShortcut(ShortcutId::WindowRideConstructionDefault, STR_SHORTCUT_RIDE_CONSTRUCTION_USE_TRACK_DEFAULT, "KEYPAD 5", []() { window_ride_construction_keyboard_shortcut_use_track_default(); }); + RegisterShortcut(ShortcutId::WindowRideConstructionSlopeDown, STR_SHORTCUT_RIDE_CONSTRUCTION_SLOPE_DOWN, "KEYPAD 2", []() { window_ride_construction_keyboard_shortcut_slope_down(); }); + RegisterShortcut(ShortcutId::WindowRideConstructionSlopeUp, STR_SHORTCUT_RIDE_CONSTRUCTION_SLOPE_UP, "KEYPAD 8", []() { window_ride_construction_keyboard_shortcut_slope_up(); }); + RegisterShortcut(ShortcutId::WindowRideConstructionChainLift, STR_SHORTCUT_RIDE_CONSTRUCTION_CHAIN_LIFT_TOGGLE, "KEYPAD +", []() { window_ride_construction_keyboard_shortcut_chain_lift_toggle(); }); + RegisterShortcut(ShortcutId::WindowRideConstructionBankLeft, STR_SHORTCUT_RIDE_CONSTRUCTION_BANK_LEFT, "KEYPAD 1", []() { window_ride_construction_keyboard_shortcut_bank_left(); }); + RegisterShortcut(ShortcutId::WindowRideConstructionBankRight, STR_SHORTCUT_RIDE_CONSTRUCTION_BANK_RIGHT, "KEYPAD 3", []() { window_ride_construction_keyboard_shortcut_bank_right(); }); + RegisterShortcut(ShortcutId::WindowRideConstructionPrevious, STR_SHORTCUT_RIDE_CONSTRUCTION_PREVIOUS_TRACK, "KEYPAD 7", []() { window_ride_construction_keyboard_shortcut_previous_track(); }); + RegisterShortcut(ShortcutId::WindowRideConstructionNext, STR_SHORTCUT_RIDE_CONSTRUCTION_NEXT_TRACK, "KEYPAD 9", []() { window_ride_construction_keyboard_shortcut_next_track(); }); + RegisterShortcut(ShortcutId::WindowRideConstructionBuild, STR_SHORTCUT_RIDE_CONSTRUCTION_BUILD_CURRENT, "KEYPAD 0", []() { window_ride_construction_keyboard_shortcut_build_current(); }); + RegisterShortcut(ShortcutId::WindowRideConstructionDemolish, STR_SHORTCUT_RIDE_CONSTRUCTION_DEMOLISH_CURRENT, "KEYPAD -", []() { window_ride_construction_keyboard_shortcut_demolish_current(); }); // Tile inspector - RegisterShortcut("tileinspector.open", STR_SHORTCUT_OPEN_TILE_INSPECTOR, []() { + RegisterShortcut(ShortcutId::InterfaceOpenTileInspector, STR_SHORTCUT_OPEN_TILE_INSPECTOR, []() { if (gConfigInterface.toolbar_show_cheats) { OpenWindow(WC_TILE_INSPECTOR); } }); - RegisterShortcut("tileinspector.insert_corrupt", STR_SHORTCUT_INSERT_CORRPUT_ELEMENT, []() { TileInspectorMouseUp(WC_TILE_INSPECTOR__WIDX_BUTTON_CORRUPT); }); - RegisterShortcut("tileinspector.copy", STR_SHORTCUT_COPY_ELEMENT, []() { TileInspectorMouseUp(WC_TILE_INSPECTOR__WIDX_BUTTON_COPY); }); - RegisterShortcut("tileinspector.paste", STR_SHORTCUT_PASTE_ELEMENT, []() { TileInspectorMouseUp(WC_TILE_INSPECTOR__WIDX_BUTTON_PASTE); }); - RegisterShortcut("tileinspector.remove", STR_SHORTCUT_REMOVE_ELEMENT, []() { TileInspectorMouseUp(WC_TILE_INSPECTOR__WIDX_BUTTON_REMOVE); }); - RegisterShortcut("tileinspector.move_up", STR_SHORTCUT_MOVE_ELEMENT_UP, []() { TileInspectorMouseUp(WC_TILE_INSPECTOR__WIDX_BUTTON_MOVE_UP); }); - RegisterShortcut("tileinspector.move_down", STR_SHORTCUT_MOVE_ELEMENT_DOWN, []() { TileInspectorMouseUp(WC_TILE_INSPECTOR__WIDX_BUTTON_MOVE_DOWN); }); - RegisterShortcut("tileinspector.increase_x", STR_SHORTCUT_INCREASE_X_COORD, []() { TileInspectorMouseDown(WC_TILE_INSPECTOR__WIDX_SPINNER_X_INCREASE); }); - RegisterShortcut("tileinspector.decrease_x", STR_SHORTCUT_DECREASE_X_COORD, []() { TileInspectorMouseDown(WC_TILE_INSPECTOR__WIDX_SPINNER_X_DECREASE); }); - RegisterShortcut("tileinspector.increase_y", STR_SHORTCUT_INCREASE_Y_COORD, []() { TileInspectorMouseDown(WC_TILE_INSPECTOR__WIDX_SPINNER_Y_INCREASE); }); - RegisterShortcut("tileinspector.decrease_y", STR_SHORTCUT_DECREASE_Y_COORD, []() { TileInspectorMouseDown(WC_TILE_INSPECTOR__WIDX_SPINNER_Y_DECREASE); }); - RegisterShortcut("tileinspector.increase_height", STR_SHORTCUT_INCREASE_ELEM_HEIGHT, []() { ShortcutIncreaseElementHeight(); }); - RegisterShortcut("tileinspector.decrease_height", STR_SHORTCUT_DECREASE_ELEM_HEIGHT, []() { ShortcutDecreaseElementHeight(); }); + + RegisterShortcut(ShortcutId::WindowTileInspectorInsertCorrupt, STR_SHORTCUT_INSERT_CORRPUT_ELEMENT, []() { TileInspectorMouseUp(WC_TILE_INSPECTOR__WIDX_BUTTON_CORRUPT); }); + RegisterShortcut(ShortcutId::WindowTileInspectorCopy, STR_SHORTCUT_COPY_ELEMENT, []() { TileInspectorMouseUp(WC_TILE_INSPECTOR__WIDX_BUTTON_COPY); }); + RegisterShortcut(ShortcutId::WindowTileInspectorPaste, STR_SHORTCUT_PASTE_ELEMENT, []() { TileInspectorMouseUp(WC_TILE_INSPECTOR__WIDX_BUTTON_PASTE); }); + RegisterShortcut(ShortcutId::WindowTileInspectorRemove, STR_SHORTCUT_REMOVE_ELEMENT, []() { TileInspectorMouseUp(WC_TILE_INSPECTOR__WIDX_BUTTON_REMOVE); }); + RegisterShortcut(ShortcutId::WindowTileInspectorMoveUp, STR_SHORTCUT_MOVE_ELEMENT_UP, []() { TileInspectorMouseUp(WC_TILE_INSPECTOR__WIDX_BUTTON_MOVE_UP); }); + RegisterShortcut(ShortcutId::WindowTileInspectorMoveDown, STR_SHORTCUT_MOVE_ELEMENT_DOWN, []() { TileInspectorMouseUp(WC_TILE_INSPECTOR__WIDX_BUTTON_MOVE_DOWN); }); + RegisterShortcut(ShortcutId::WindowTileInspectorIncreaseX, STR_SHORTCUT_INCREASE_X_COORD, []() { TileInspectorMouseDown(WC_TILE_INSPECTOR__WIDX_SPINNER_X_INCREASE); }); + RegisterShortcut(ShortcutId::WindowTileInspectorDecreaseX, STR_SHORTCUT_DECREASE_X_COORD, []() { TileInspectorMouseDown(WC_TILE_INSPECTOR__WIDX_SPINNER_X_DECREASE); }); + RegisterShortcut(ShortcutId::WindowTileInspectorIncreaseY, STR_SHORTCUT_INCREASE_Y_COORD, []() { TileInspectorMouseDown(WC_TILE_INSPECTOR__WIDX_SPINNER_Y_INCREASE); }); + RegisterShortcut(ShortcutId::WindowTileInspectorDecreaseY, STR_SHORTCUT_DECREASE_Y_COORD, []() { TileInspectorMouseDown(WC_TILE_INSPECTOR__WIDX_SPINNER_Y_DECREASE); }); + RegisterShortcut(ShortcutId::WindowTileInspectorIncreaseHeight, STR_SHORTCUT_INCREASE_ELEM_HEIGHT, []() { ShortcutIncreaseElementHeight(); }); + RegisterShortcut(ShortcutId::WindowTileInspectorDecreaseHeight, STR_SHORTCUT_DECREASE_ELEM_HEIGHT, []() { ShortcutDecreaseElementHeight(); }); // Debug - RegisterShortcut(SHORTCUT_ID_DEBUG_CONSOLE, STR_CONSOLE, "`", []() { ShortcutToggleConsole(); }); - RegisterShortcut("debug.advance_tick", STR_ADVANCE_TO_NEXT_TICK, []() { + RegisterShortcut(ShortcutId::DebugToggleConsole, STR_CONSOLE, "`", []() { ShortcutToggleConsole(); }); + RegisterShortcut(ShortcutId::DebugAdvanceTick, STR_ADVANCE_TO_NEXT_TICK, []() { if (!(gScreenFlags & (SCREEN_FLAGS_TITLE_DEMO | SCREEN_FLAGS_SCENARIO_EDITOR | SCREEN_FLAGS_TRACK_MANAGER))) { gDoSingleUpdate = true; } }); - RegisterShortcut("debug.toggle_paint_debug_window", STR_SHORTCUT_DEBUG_PAINT_TOGGLE, []() { + RegisterShortcut(ShortcutId::DebugTogglePaintDebugWindow, STR_SHORTCUT_DEBUG_PAINT_TOGGLE, []() { if (!(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)) { auto window = window_find_by_class(WC_DEBUG_PAINT); diff --git a/src/openrct2-ui/input/KeyboardShortcuts.cpp b/src/openrct2-ui/input/KeyboardShortcuts.cpp index 79bf0d28fc..1f98cb4432 100644 --- a/src/openrct2-ui/input/KeyboardShortcuts.cpp +++ b/src/openrct2-ui/input/KeyboardShortcuts.cpp @@ -98,7 +98,7 @@ bool KeyboardShortcuts::Load() Reset(); try { - std::string path = _env->GetFilePath(PATHID::CONFIG_KEYBOARD); + std::string path = _env->GetFilePath(PATHID::CONFIG_SHORTCUTS_LEGACY); if (File::Exists(path)) { auto fs = FileStream(path, FILE_MODE_OPEN); @@ -127,7 +127,7 @@ bool KeyboardShortcuts::Save() bool result = false; try { - std::string path = _env->GetFilePath(PATHID::CONFIG_KEYBOARD); + std::string path = _env->GetFilePath(PATHID::CONFIG_SHORTCUTS_LEGACY); auto fs = FileStream(path, FILE_MODE_WRITE); fs.WriteValue(KeyboardShortcuts::CURRENT_FILE_VERSION); for (size_t i = 0; i < ShortcutsCount; i++) diff --git a/src/openrct2-ui/input/ShortcutManager.cpp b/src/openrct2-ui/input/ShortcutManager.cpp index 8d6cf971ae..72139c1935 100644 --- a/src/openrct2-ui/input/ShortcutManager.cpp +++ b/src/openrct2-ui/input/ShortcutManager.cpp @@ -10,6 +10,11 @@ #include "ShortcutManager.h" #include +#include +#include +#include +#include +#include #include #include #include @@ -417,7 +422,8 @@ bool RegisteredShortcut::IsSuitableInputEvent(const InputEvent& e) const return true; } -ShortcutManager::ShortcutManager() +ShortcutManager::ShortcutManager(const std::shared_ptr& env) + : _env(env) { RegisterDefaultShortcuts(); } @@ -487,9 +493,217 @@ bool ShortcutManager::ProcessEventForSpecificShortcut(const InputEvent& e, std:: return false; } -static ShortcutManager _shortcutManager; - -ShortcutManager& OpenRCT2::Ui::GetShortcutManager() +void ShortcutManager::LoadUserBindings() { - return _shortcutManager; + try + { + auto path = fs::u8path(_env->GetFilePath(PATHID::CONFIG_SHORTCUTS)); + if (fs::exists(path)) + { + LoadUserBindings(path); + } + else + { + try + { + std::printf("Importing legacy shortcuts...\n"); + auto legacyPath = fs::u8path(_env->GetFilePath(PATHID::CONFIG_SHORTCUTS_LEGACY)); + if (fs::exists(legacyPath)) + { + LoadLegacyBindings(legacyPath); + SaveUserBindings(); + std::printf("Legacy shortcuts imported\n"); + } + } + catch (const std::exception& e) + { + std::fprintf(stderr, "Unable to import legacy shortcut bindings: %s\n", e.what()); + } + } + } + catch (const std::exception& e) + { + std::fprintf(stderr, "Unable to load shortcut bindings: %s\n", e.what()); + } +} + +std::optional ShortcutManager::ConvertLegacyBinding(uint16_t binding) +{ + constexpr uint16_t nullBinding = 0xFFFF; + constexpr uint16_t shift = 0x100; + constexpr uint16_t ctrl = 0x200; + constexpr uint16_t alt = 0x400; + constexpr uint16_t cmd = 0x800; + + if (binding == nullBinding) + { + return {}; + } + else + { + ShortcutInput result; + result.Kind = InputDeviceKind::Keyboard; + if (binding & shift) + result.Modifiers |= KMOD_SHIFT; + if (binding & ctrl) + result.Modifiers |= KMOD_CTRL; + if (binding & alt) + result.Modifiers |= KMOD_ALT; + if (binding & cmd) + result.Modifiers |= KMOD_GUI; + result.Button = SDL_GetKeyFromScancode(static_cast(binding & 0xFF)); + return result; + } +} + +void ShortcutManager::LoadLegacyBindings(const fs::path& path) +{ + constexpr int32_t SUPPORTED_FILE_VERSION = 1; + + auto fs = std::ifstream(path); + if (fs) + { + auto br = BinaryReader(&fs); + + uint16_t version{}; + br << version; + + if (version == SUPPORTED_FILE_VERSION) + { + for (size_t i = 0; i < 85; i++) + { + uint16_t value{}; + br << value; + + auto shortcutId = GetLegacyShortcutId(i); + if (!shortcutId.empty()) + { + auto shortcut = GetShortcut(shortcutId); + if (shortcut != nullptr) + { + shortcut->Current.clear(); + auto input = ConvertLegacyBinding(value); + if (input) + { + shortcut->Current.push_back(std::move(*input)); + } + } + } + } + } + } +} + +void ShortcutManager::LoadUserBindings(const fs::path& path) +{ +} + +void ShortcutManager::SaveUserBindings() +{ + try + { + auto path = fs::u8path(_env->GetFilePath(PATHID::CONFIG_SHORTCUTS)); + SaveUserBindings(path); + } + catch (const std::exception& e) + { + std::fprintf(stderr, "Unable to save shortcut bindings: %s\n", e.what()); + } +} + +void ShortcutManager::SaveUserBindings(const fs::path& path) +{ +} + +std::string_view ShortcutManager::GetLegacyShortcutId(size_t index) +{ + static constexpr const char* LegacyMap[] = { + ShortcutId::InterfaceCloseTop, + ShortcutId::InterfaceCloseAll, + ShortcutId::InterfaceCancelConstruction, + ShortcutId::InterfacePause, + ShortcutId::InterfaceZoomOut, + ShortcutId::InterfaceZoomIn, + ShortcutId::InterfaceRotateClockwise, + ShortcutId::InterfaceRotateAnticlockwise, + ShortcutId::InterfaceRotateConstruction, + ShortcutId::ViewToggleUnderground, + ShortcutId::ViewToggleBaseLand, + ShortcutId::ViewToggleVerticalLand, + ShortcutId::ViewToggleRides, + ShortcutId::ViewToggleScenery, + ShortcutId::ViewToggleSupports, + ShortcutId::ViewTogglePeeps, + ShortcutId::ViewToggleLandHeightMarkers, + ShortcutId::ViewToggleTrackHeightMarkers, + ShortcutId::ViewToggleFootpathHeightMarkers, + ShortcutId::InterfaceOpenLand, + ShortcutId::InterfaceOpenWater, + ShortcutId::InterfaceOpenScenery, + ShortcutId::InterfaceOpenFootpaths, + ShortcutId::InterfaceOpenNewRide, + ShortcutId::InterfaceOpenFinances, + ShortcutId::InterfaceOpenResearch, + ShortcutId::InterfaceOpenRides, + ShortcutId::InterfaceOpenPark, + ShortcutId::InterfaceOpenGuests, + ShortcutId::InterfaceOpenStaff, + ShortcutId::InterfaceOpenMessages, + ShortcutId::InterfaceOpenMap, + ShortcutId::InterfaceScreenshot, + ShortcutId::InterfaceDecreaseSpeed, + ShortcutId::InterfaceIncreaseSpeed, + ShortcutId::InterfaceOpenCheats, + ShortcutId::InterfaceToggleToolbars, + ShortcutId::ScrollUp, + ShortcutId::ScrollLeft, + ShortcutId::ScrollRight, + ShortcutId::ScrollDown, + ShortcutId::MultiplayerChat, + ShortcutId::InterfaceSaveGame, + ShortcutId::InterfaceShowOptions, + ShortcutId::InterfaceMute, + ShortcutId::ScaleToggleWindowMode, + ShortcutId::MultiplayerShow, + nullptr, + ShortcutId::DebugTogglePaintDebugWindow, + ShortcutId::ViewToggleFootpaths, + ShortcutId::WindowRideConstructionTurnLeft, + ShortcutId::WindowRideConstructionTurnRight, + ShortcutId::WindowRideConstructionDefault, + ShortcutId::WindowRideConstructionSlopeDown, + ShortcutId::WindowRideConstructionSlopeUp, + ShortcutId::WindowRideConstructionChainLift, + ShortcutId::WindowRideConstructionBankLeft, + ShortcutId::WindowRideConstructionBankRight, + ShortcutId::WindowRideConstructionPrevious, + ShortcutId::WindowRideConstructionNext, + ShortcutId::WindowRideConstructionBuild, + ShortcutId::WindowRideConstructionDemolish, + ShortcutId::InterfaceLoadGame, + ShortcutId::InterfaceClearScenery, + ShortcutId::ViewToggleGridlines, + ShortcutId::ViewToggleCutAway, + ShortcutId::ViewToogleFootpathIssues, + ShortcutId::InterfaceOpenTileInspector, + ShortcutId::DebugAdvanceTick, + ShortcutId::InterfaceSceneryPicker, + ShortcutId::InterfaceScaleIncrease, + ShortcutId::InterfaceScaleDecrease, + ShortcutId::WindowTileInspectorInsertCorrupt, + ShortcutId::WindowTileInspectorCopy, + ShortcutId::WindowTileInspectorPaste, + ShortcutId::WindowTileInspectorRemove, + ShortcutId::WindowTileInspectorMoveUp, + ShortcutId::WindowTileInspectorMoveDown, + ShortcutId::WindowTileInspectorIncreaseX, + ShortcutId::WindowTileInspectorDecreaseX, + ShortcutId::WindowTileInspectorIncreaseY, + ShortcutId::WindowTileInspectorDecreaseY, + ShortcutId::WindowTileInspectorIncreaseHeight, + ShortcutId::WindowTileInspectorDecreaseHeight, + ShortcutId::InterfaceDisableClearance, + }; + auto sz = index < std::size(LegacyMap) ? LegacyMap[index] : nullptr; + return sz == nullptr ? std::string_view() : std::string_view(sz); } diff --git a/src/openrct2-ui/input/ShortcutManager.h b/src/openrct2-ui/input/ShortcutManager.h index 5efd42fe92..a31b337bf8 100644 --- a/src/openrct2-ui/input/ShortcutManager.h +++ b/src/openrct2-ui/input/ShortcutManager.h @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -20,6 +21,11 @@ #include #include +namespace OpenRCT2 +{ + struct IPlatformEnvironment; +} + namespace OpenRCT2::Ui { struct ShortcutInput @@ -98,14 +104,23 @@ namespace OpenRCT2::Ui class ShortcutManager { private: + std::shared_ptr _env; std::string _pendingShortcutChange; + static std::optional ConvertLegacyBinding(uint16_t binding); + void LoadLegacyBindings(const fs::path& path); + void LoadUserBindings(const fs::path& path); + void SaveUserBindings(const fs::path& path); + public: std::vector Shortcuts; - ShortcutManager(); + ShortcutManager(const std::shared_ptr& env); ShortcutManager(const ShortcutManager&) = delete; + void LoadUserBindings(); + void SaveUserBindings(); + void RegisterShortcut(RegisteredShortcut&& shortcut); template void RegisterShortcut(Args&&... args) { @@ -117,10 +132,103 @@ namespace OpenRCT2::Ui void SetPendingShortcutChange(std::string_view id); void ProcessEvent(const InputEvent& e); bool ProcessEventForSpecificShortcut(const InputEvent& e, std::string_view id); + + static std::string_view GetLegacyShortcutId(size_t index); }; ShortcutManager& GetShortcutManager(); - constexpr const char* SHORTCUT_ID_DEBUG_CONSOLE = "debug.console"; + namespace ShortcutId + { + // original + constexpr const char* InterfaceCloseTop = "interface0.close_top"; + constexpr const char* InterfaceCloseAll = "interface0.close_all"; + constexpr const char* InterfaceCancelConstruction = "interface0.cancel_construction"; + constexpr const char* InterfacePause = "interface1.pause"; + constexpr const char* InterfaceZoomOut = "interface3.zoom_out"; + constexpr const char* InterfaceZoomIn = "interface3.zoom_in"; + constexpr const char* InterfaceRotateClockwise = "interface3.rotate_clockwise"; + constexpr const char* InterfaceRotateAnticlockwise = "interface3.rotate_anticlockwise"; + constexpr const char* InterfaceRotateConstruction = "interface6.rotate_construction"; + constexpr const char* ViewToggleUnderground = "view.show_underground"; + constexpr const char* ViewToggleBaseLand = "view.hide_base_land"; + constexpr const char* ViewToggleVerticalLand = "view.hide_vertical_land"; + constexpr const char* ViewToggleRides = "view.transparent_rides"; + constexpr const char* ViewToggleScenery = "view.transparent_scenery"; + constexpr const char* ViewToggleSupports = "view.hide_supports"; + constexpr const char* ViewTogglePeeps = "view.hide_peeps"; + constexpr const char* ViewToggleLandHeightMarkers = "view.show_land_height"; + constexpr const char* ViewToggleTrackHeightMarkers = "view.show_track_height"; + constexpr const char* ViewToggleFootpathHeightMarkers = "view.show_footpath_height"; + constexpr const char* InterfaceOpenLand = "interface4.adjust_land"; + constexpr const char* InterfaceOpenWater = "interface4.adjust_water"; + constexpr const char* InterfaceOpenScenery = "interface4.build_scenery"; + constexpr const char* InterfaceOpenFootpaths = "interface4.build_footpaths"; + constexpr const char* InterfaceOpenNewRide = "interface4.build_new_ride"; + constexpr const char* InterfaceOpenFinances = "interface5.show_finances"; + constexpr const char* InterfaceOpenResearch = "interface5.show_research"; + constexpr const char* InterfaceOpenRides = "interface5.show_rides"; + constexpr const char* InterfaceOpenPark = "interface5.show_park"; + constexpr const char* InterfaceOpenGuests = "interface5.show_guests"; + constexpr const char* InterfaceOpenStaff = "interface5.show_staff"; + constexpr const char* InterfaceOpenMessages = "interface5.show_messages"; + constexpr const char* InterfaceOpenMap = "interface3.show_map"; + constexpr const char* InterfaceScreenshot = "interface1.screenshot"; + // new + constexpr const char* InterfaceDecreaseSpeed = "interface1.decrease_speed"; + constexpr const char* InterfaceIncreaseSpeed = "interface1.increase_speed"; + constexpr const char* InterfaceOpenCheats = "interface2.open_cheats"; + constexpr const char* InterfaceToggleToolbars = "interface0.toggle_toolbars"; + constexpr const char* ScrollUp = "scroll.up"; + constexpr const char* ScrollLeft = "scroll.left"; + constexpr const char* ScrollRight = "scroll.right"; + constexpr const char* ScrollDown = "scroll.down"; + constexpr const char* MultiplayerChat = "multiplayer.chat"; + constexpr const char* InterfaceSaveGame = "interface1.save_game"; + constexpr const char* InterfaceShowOptions = "interface1.show_options"; + constexpr const char* InterfaceMute = "interface1.mute"; + constexpr const char* ScaleToggleWindowMode = "scale.toggle_window_mode"; + constexpr const char* MultiplayerShow = "multiplayer.show"; + // paint original + constexpr const char* DebugTogglePaintDebugWindow = "debug.toggle_paint_debug_window"; + constexpr const char* ViewToggleFootpaths = "view.transparent_footpaths"; + constexpr const char* WindowRideConstructionTurnLeft = "window.rideconstruction.turn_left"; + constexpr const char* WindowRideConstructionTurnRight = "window.rideconstruction.turn_right"; + constexpr const char* WindowRideConstructionDefault = "window.rideconstruction.default"; + constexpr const char* WindowRideConstructionSlopeDown = "window.rideconstruction.slope_down"; + constexpr const char* WindowRideConstructionSlopeUp = "window.rideconstruction.slope_up"; + constexpr const char* WindowRideConstructionChainLift = "window.rideconstruction.chain_lift"; + constexpr const char* WindowRideConstructionBankLeft = "window.rideconstruction.bank_left"; + constexpr const char* WindowRideConstructionBankRight = "window.rideconstruction.bank_right"; + constexpr const char* WindowRideConstructionPrevious = "window.rideconstruction.previous"; + constexpr const char* WindowRideConstructionNext = "window.rideconstruction.next"; + constexpr const char* WindowRideConstructionBuild = "window.rideconstruction.build"; + constexpr const char* WindowRideConstructionDemolish = "window.rideconstruction.demolish"; + constexpr const char* InterfaceLoadGame = "interface1.load_game"; + constexpr const char* InterfaceClearScenery = "interface4.clear_scenery"; + constexpr const char* ViewToggleGridlines = "view.show_gridlines"; + constexpr const char* ViewToggleCutAway = "view.toggle_cut_away"; + constexpr const char* ViewToogleFootpathIssues = "view.highlight_path_issues"; + constexpr const char* InterfaceOpenTileInspector = "tileinspector.open"; + constexpr const char* DebugAdvanceTick = "debug.advance_tick"; + constexpr const char* InterfaceSceneryPicker = "interface6.scenery_picker"; + constexpr const char* InterfaceScaleIncrease = "scale.increase"; + constexpr const char* InterfaceScaleDecrease = "scale.decrease"; + constexpr const char* WindowTileInspectorInsertCorrupt = "window.tileinspector.insert_corrupt"; + constexpr const char* WindowTileInspectorCopy = "window.tileinspector.copy"; + constexpr const char* WindowTileInspectorPaste = "window.tileinspector.paste"; + constexpr const char* WindowTileInspectorRemove = "window.tileinspector.remove"; + constexpr const char* WindowTileInspectorMoveUp = "window.tileinspector.move_up"; + constexpr const char* WindowTileInspectorMoveDown = "window.tileinspector.move_down"; + constexpr const char* WindowTileInspectorIncreaseX = "window.tileinspector.increase_x"; + constexpr const char* WindowTileInspectorDecreaseX = "window.tileinspector.decrease_x"; + constexpr const char* WindowTileInspectorIncreaseY = "window.tileinspector.increase_y"; + constexpr const char* WindowTileInspectorDecreaseY = "window.tileinspector.decrease_y"; + constexpr const char* WindowTileInspectorIncreaseHeight = "window.tileinspector.increase_height"; + constexpr const char* WindowTileInspectorDecreaseHeight = "window.tileinspector.decrease_height"; + constexpr const char* InterfaceDisableClearance = "interface2.disable_clearance"; + // even newer + constexpr const char* DebugToggleConsole = "debug.console"; + } // namespace ShortcutId } // namespace OpenRCT2::Ui diff --git a/src/openrct2/PlatformEnvironment.cpp b/src/openrct2/PlatformEnvironment.cpp index 243015f134..59480787a7 100644 --- a/src/openrct2/PlatformEnvironment.cpp +++ b/src/openrct2/PlatformEnvironment.cpp @@ -81,7 +81,8 @@ private: switch (pathid) { case PATHID::CONFIG: - case PATHID::CONFIG_KEYBOARD: + case PATHID::CONFIG_SHORTCUTS_LEGACY: + case PATHID::CONFIG_SHORTCUTS: return DIRBASE::CONFIG; case PATHID::CACHE_OBJECTS: case PATHID::CACHE_TRACKS: @@ -232,7 +233,8 @@ const char * PlatformEnvironment::DirectoryNamesOpenRCT2[] = const char * PlatformEnvironment::FileNames[] = { "config.ini", // CONFIG - "hotkeys.dat", // CONFIG_KEYBOARD + "hotkeys.dat", // CONFIG_SHORTCUTS_LEGACY + "shortcuts.json", // CONFIG_SHORTCUTS "objects.idx", // CACHE_OBJECTS "tracks.idx", // CACHE_TRACKS "scenarios.idx", // CACHE_SCENARIOS diff --git a/src/openrct2/PlatformEnvironment.h b/src/openrct2/PlatformEnvironment.h index fdd1dcdeb9..ad8dd64428 100644 --- a/src/openrct2/PlatformEnvironment.h +++ b/src/openrct2/PlatformEnvironment.h @@ -53,20 +53,21 @@ namespace OpenRCT2 enum class PATHID { - CONFIG, // Main configuration (config.ini). - CONFIG_KEYBOARD, // Keyboard shortcuts. (hotkeys.cfg) - CACHE_OBJECTS, // Object repository cache (objects.idx). - CACHE_TRACKS, // Track repository cache (tracks.idx). - CACHE_SCENARIOS, // Scenario repository cache (scenarios.idx). - MP_DAT, // Mega Park data, Steam RCT1 only (\RCTdeluxe_install\Data\mp.dat) - NETWORK_GROUPS, // Server groups with permissions (groups.json). - NETWORK_SERVERS, // Saved servers (servers.cfg). - NETWORK_USERS, // Users and their groups (users.json). - SCORES, // Scenario scores (highscores.dat). - SCORES_LEGACY, // Scenario scores, legacy (scores.dat). - SCORES_RCT2, // Scenario scores, rct2 (\Saved Games\scores.dat). - CHANGELOG, // Notable changes to the game between versions, distributed with the game. - PLUGIN_STORE, // Shared storage for plugins. + CONFIG, // Main configuration (config.ini). + CONFIG_SHORTCUTS_LEGACY, // Old keyboard shortcuts (hotkeys.cfg) + CONFIG_SHORTCUTS, // Shortcut bindings (shortcuts.json) + CACHE_OBJECTS, // Object repository cache (objects.idx). + CACHE_TRACKS, // Track repository cache (tracks.idx). + CACHE_SCENARIOS, // Scenario repository cache (scenarios.idx). + MP_DAT, // Mega Park data, Steam RCT1 only (\RCTdeluxe_install\Data\mp.dat) + NETWORK_GROUPS, // Server groups with permissions (groups.json). + NETWORK_SERVERS, // Saved servers (servers.cfg). + NETWORK_USERS, // Users and their groups (users.json). + SCORES, // Scenario scores (highscores.dat). + SCORES_LEGACY, // Scenario scores, legacy (scores.dat). + SCORES_RCT2, // Scenario scores, rct2 (\Saved Games\scores.dat). + CHANGELOG, // Notable changes to the game between versions, distributed with the game. + PLUGIN_STORE, // Shared storage for plugins. }; /** diff --git a/src/openrct2/core/DataSerialiser.h b/src/openrct2/core/DataSerialiser.h index 95622961ae..3a97c35bbd 100644 --- a/src/openrct2/core/DataSerialiser.h +++ b/src/openrct2/core/DataSerialiser.h @@ -12,7 +12,67 @@ #include "DataSerialiserTraits.h" #include "MemoryStream.h" +#include #include +#include + +class BinarySerialiser +{ +private: + std::variant _stream{}; + +public: + BinarySerialiser(std::istream* stream) + : _stream(stream) + { + } + + BinarySerialiser(std::ostream* stream) + : _stream(stream) + { + } + + bool IsReading() const + { + return std::holds_alternative(_stream); + } + + bool IsWriting() const + { + return std::holds_alternative(_stream); + } + + template BinarySerialiser& operator<<(const T& data) + { + if (auto istream = std::get_if(&_stream)) + { + DataSerializerTraits::decode(**istream, const_cast(data)); + } + else if (auto ostream = std::get_if(&_stream)) + { + DataSerializerTraits::encode(**ostream, data); + } + return *this; + } +}; + +class BinaryReader : public BinarySerialiser +{ +public: + BinaryReader(std::istream* stream) + : BinarySerialiser(stream) + { + } +}; + +class BinaryWriter : public BinarySerialiser +{ +public: + BinaryWriter(std::ostream* stream) + : BinarySerialiser(stream) + { + } +}; class DataSerialiser { diff --git a/src/openrct2/core/DataSerialiserTraits.h b/src/openrct2/core/DataSerialiserTraits.h index 6128404106..e8cb94beac 100644 --- a/src/openrct2/core/DataSerialiserTraits.h +++ b/src/openrct2/core/DataSerialiserTraits.h @@ -73,6 +73,14 @@ template struct DataSerializerTraitsIntegral stream->Read(&temp); val = ByteSwapBE(temp); } + static void encode(std::ostream& stream, const T& val) + { + stream.write(reinterpret_cast(&val), sizeof(val)); + } + static void decode(std::istream& stream, T& val) + { + stream.read(reinterpret_cast(&val), sizeof(val)); + } static void log(OpenRCT2::IStream* stream, const T& val) { std::stringstream ss;