mirror of https://github.com/OpenRCT2/OpenRCT2.git
Remove old shortcut code and fix issues
This commit is contained in:
parent
f2f658bf28
commit
2b3aabb8e4
|
@ -9,11 +9,11 @@
|
|||
|
||||
#include "WindowManager.h"
|
||||
|
||||
#include "input/KeyboardShortcuts.h"
|
||||
#include "interface/Theme.h"
|
||||
#include "windows/Window.h"
|
||||
|
||||
#include <openrct2-ui/input/InputManager.h>
|
||||
#include <openrct2-ui/input/ShortcutManager.h>
|
||||
#include <openrct2-ui/windows/Window.h>
|
||||
#include <openrct2/Input.h>
|
||||
#include <openrct2/config/Config.h>
|
||||
|
@ -520,11 +520,11 @@ public:
|
|||
inputManager.Process();
|
||||
}
|
||||
|
||||
std::string GetKeyboardShortcutString(int32_t shortcut) override
|
||||
std::string GetKeyboardShortcutString(std::string_view shortcutId) override
|
||||
{
|
||||
utf8 buffer[256];
|
||||
KeyboardShortcutsFormatString(buffer, sizeof(buffer), shortcut);
|
||||
return std::string(buffer);
|
||||
auto& shortcutManager = GetShortcutManager();
|
||||
auto* shortcut = shortcutManager.GetShortcut(shortcutId);
|
||||
return shortcut != nullptr ? shortcut->GetDisplayString() : std::string();
|
||||
}
|
||||
|
||||
void SetMainView(const ScreenCoordsXY& viewPos, ZoomLevel zoom, int32_t rotation) override
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include <openrct2/world/Location.hpp>
|
||||
#include <queue>
|
||||
#include <string_view>
|
||||
|
||||
typedef struct _SDL_Joystick SDL_Joystick;
|
||||
typedef union SDL_Event SDL_Event;
|
||||
|
|
|
@ -1,378 +0,0 @@
|
|||
/*****************************************************************************
|
||||
* Copyright (c) 2014-2020 OpenRCT2 developers
|
||||
*
|
||||
* For a complete list of all authors, please refer to contributors.md
|
||||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||
*
|
||||
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "KeyboardShortcuts.h"
|
||||
|
||||
#include <SDL.h>
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <openrct2/PlatformEnvironment.h>
|
||||
#include <openrct2/common.h>
|
||||
#include <openrct2/core/Console.hpp>
|
||||
#include <openrct2/core/File.h>
|
||||
#include <openrct2/core/FileStream.h>
|
||||
#include <openrct2/core/Path.hpp>
|
||||
#include <openrct2/core/String.hpp>
|
||||
#include <openrct2/localisation/Localisation.h>
|
||||
#include <openrct2/world/Location.hpp>
|
||||
|
||||
using namespace OpenRCT2;
|
||||
using namespace OpenRCT2::Input;
|
||||
|
||||
// Remove when the C calls are removed
|
||||
static KeyboardShortcuts* _instance;
|
||||
|
||||
static const std::map<const SDL_Scancode, const rct_string_id> specialCharNames = {
|
||||
{ SDL_SCANCODE_BACKSPACE, STR_SHORTCUT_BACKSPACE },
|
||||
{ SDL_SCANCODE_TAB, STR_SHORTCUT_TAB },
|
||||
{ SDL_SCANCODE_CLEAR, STR_SHORTCUT_CLEAR },
|
||||
{ SDL_SCANCODE_RETURN, STR_SHORTCUT_RETURN },
|
||||
{ SDL_SCANCODE_LALT, STR_SHORTCUT_ALT },
|
||||
{ SDL_SCANCODE_PAUSE, STR_SHORTCUT_PAUSE },
|
||||
{ SDL_SCANCODE_CAPSLOCK, STR_SHORTCUT_CAPS },
|
||||
{ SDL_SCANCODE_ESCAPE, STR_SHORTCUT_ESCAPE },
|
||||
{ SDL_SCANCODE_SPACE, STR_SHORTCUT_SPACEBAR },
|
||||
{ SDL_SCANCODE_PAGEUP, STR_SHORTCUT_PGUP },
|
||||
{ SDL_SCANCODE_PAGEDOWN, STR_SHORTCUT_PGDN },
|
||||
{ SDL_SCANCODE_END, STR_SHORTCUT_END },
|
||||
{ SDL_SCANCODE_HOME, STR_SHORTCUT_HOME },
|
||||
{ SDL_SCANCODE_LEFT, STR_SHORTCUT_LEFT },
|
||||
{ SDL_SCANCODE_UP, STR_SHORTCUT_UP },
|
||||
{ SDL_SCANCODE_RIGHT, STR_SHORTCUT_RIGHT },
|
||||
{ SDL_SCANCODE_DOWN, STR_SHORTCUT_DOWN },
|
||||
{ SDL_SCANCODE_SELECT, STR_SHORTCUT_SELECT },
|
||||
{ SDL_SCANCODE_PRINTSCREEN, STR_SHORTCUT_PRINT },
|
||||
{ SDL_SCANCODE_EXECUTE, STR_SHORTCUT_EXECUTE },
|
||||
{ SDL_SCANCODE_SYSREQ, STR_SHORTCUT_SNAPSHOT },
|
||||
{ SDL_SCANCODE_INSERT, STR_SHORTCUT_INSERT },
|
||||
{ SDL_SCANCODE_DELETE, STR_SHORTCUT_DELETE },
|
||||
{ SDL_SCANCODE_HELP, STR_SHORTCUT_HELP },
|
||||
{ SDL_SCANCODE_APPLICATION, STR_SHORTCUT_MENU },
|
||||
{ SDL_SCANCODE_KP_0, STR_SHORTCUT_NUMPAD_0 },
|
||||
{ SDL_SCANCODE_KP_1, STR_SHORTCUT_NUMPAD_1 },
|
||||
{ SDL_SCANCODE_KP_2, STR_SHORTCUT_NUMPAD_2 },
|
||||
{ SDL_SCANCODE_KP_3, STR_SHORTCUT_NUMPAD_3 },
|
||||
{ SDL_SCANCODE_KP_4, STR_SHORTCUT_NUMPAD_4 },
|
||||
{ SDL_SCANCODE_KP_5, STR_SHORTCUT_NUMPAD_5 },
|
||||
{ SDL_SCANCODE_KP_6, STR_SHORTCUT_NUMPAD_6 },
|
||||
{ SDL_SCANCODE_KP_7, STR_SHORTCUT_NUMPAD_7 },
|
||||
{ SDL_SCANCODE_KP_8, STR_SHORTCUT_NUMPAD_8 },
|
||||
{ SDL_SCANCODE_KP_9, STR_SHORTCUT_NUMPAD_9 },
|
||||
{ SDL_SCANCODE_KP_MULTIPLY, STR_SHORTCUT_NUMPAD_MULTIPLY },
|
||||
{ SDL_SCANCODE_KP_PLUS, STR_SHORTCUT_NUMPAD_PLUS },
|
||||
{ SDL_SCANCODE_KP_MINUS, STR_SHORTCUT_NUMPAD_MINUS },
|
||||
{ SDL_SCANCODE_KP_PERIOD, STR_SHORTCUT_NUMPAD_PERIOD },
|
||||
{ SDL_SCANCODE_KP_DIVIDE, STR_SHORTCUT_NUMPAD_DIVIDE },
|
||||
{ SDL_SCANCODE_NUMLOCKCLEAR, STR_SHORTCUT_NUMLOCK },
|
||||
{ SDL_SCANCODE_SCROLLLOCK, STR_SHORTCUT_SCROLL },
|
||||
};
|
||||
|
||||
KeyboardShortcuts::KeyboardShortcuts(const std::shared_ptr<IPlatformEnvironment>& env)
|
||||
: _env(env)
|
||||
{
|
||||
_instance = this;
|
||||
}
|
||||
|
||||
KeyboardShortcuts::~KeyboardShortcuts()
|
||||
{
|
||||
_instance = nullptr;
|
||||
}
|
||||
|
||||
void KeyboardShortcuts::Reset()
|
||||
{
|
||||
for (size_t i = 0; i < ShortcutsCount; i++)
|
||||
{
|
||||
_keys[i] = DefaultKeys[i];
|
||||
}
|
||||
}
|
||||
|
||||
bool KeyboardShortcuts::Load()
|
||||
{
|
||||
bool result = false;
|
||||
Reset();
|
||||
try
|
||||
{
|
||||
std::string path = _env->GetFilePath(PATHID::CONFIG_SHORTCUTS_LEGACY);
|
||||
if (File::Exists(path))
|
||||
{
|
||||
auto fs = FileStream(path, FILE_MODE_OPEN);
|
||||
uint16_t version = fs.ReadValue<uint16_t>();
|
||||
if (version == KeyboardShortcuts::CURRENT_FILE_VERSION)
|
||||
{
|
||||
int32_t numShortcutsInFile = (fs.GetLength() - sizeof(uint16_t)) / sizeof(uint16_t);
|
||||
auto numShortcutsToRead = std::min<size_t>(ShortcutsCount, numShortcutsInFile);
|
||||
for (size_t i = 0; i < numShortcutsToRead; i++)
|
||||
{
|
||||
_keys[i] = fs.ReadValue<uint16_t>();
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
Console::WriteLine("Error reading shortcut keys: %s", ex.what());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool KeyboardShortcuts::Save()
|
||||
{
|
||||
bool result = false;
|
||||
try
|
||||
{
|
||||
std::string path = _env->GetFilePath(PATHID::CONFIG_SHORTCUTS_LEGACY);
|
||||
auto fs = FileStream(path, FILE_MODE_WRITE);
|
||||
fs.WriteValue<uint16_t>(KeyboardShortcuts::CURRENT_FILE_VERSION);
|
||||
for (size_t i = 0; i < ShortcutsCount; i++)
|
||||
{
|
||||
fs.WriteValue<uint16_t>(_keys[i]);
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
Console::WriteLine("Error writing shortcut keys: %s", ex.what());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void KeyboardShortcuts::Set(int32_t key)
|
||||
{
|
||||
// Unmap shortcut that already uses this key
|
||||
auto shortcut = GetFromKey(key);
|
||||
if (shortcut != Input::Shortcut::Undefined)
|
||||
{
|
||||
_keys[static_cast<size_t>(shortcut)] = static_cast<uint16_t>(Input::ScanCodeUndefined);
|
||||
}
|
||||
|
||||
// Map shortcut to this key
|
||||
// _keys[static_cast<size_t>(gKeyboardShortcutChangeId)] = key;
|
||||
Save();
|
||||
}
|
||||
|
||||
Shortcut KeyboardShortcuts::GetFromKey(int32_t key)
|
||||
{
|
||||
for (size_t i = 0; i < ShortcutsCount; i++)
|
||||
{
|
||||
if (key == _keys[i])
|
||||
{
|
||||
return static_cast<Shortcut>(i);
|
||||
}
|
||||
}
|
||||
return Input::Shortcut::Undefined;
|
||||
}
|
||||
|
||||
std::string KeyboardShortcuts::GetShortcutString(int32_t shortcut) const
|
||||
{
|
||||
utf8 buffer[256] = { 0 };
|
||||
utf8 formatBuffer[256] = { 0 };
|
||||
uint16_t shortcutKey = _keys[shortcut];
|
||||
if (shortcutKey == Input::ScanCodeUndefined)
|
||||
return std::string();
|
||||
if (shortcutKey & SHIFT)
|
||||
{
|
||||
format_string(formatBuffer, sizeof(formatBuffer), STR_SHIFT_PLUS, nullptr);
|
||||
String::Append(buffer, sizeof(buffer), formatBuffer);
|
||||
}
|
||||
if (shortcutKey & CTRL)
|
||||
{
|
||||
format_string(formatBuffer, sizeof(formatBuffer), STR_CTRL_PLUS, nullptr);
|
||||
String::Append(buffer, sizeof(buffer), formatBuffer);
|
||||
}
|
||||
if (shortcutKey & ALT)
|
||||
{
|
||||
#ifdef __MACOSX__
|
||||
format_string(formatBuffer, sizeof(formatBuffer), STR_OPTION_PLUS, nullptr);
|
||||
#else
|
||||
format_string(formatBuffer, sizeof(formatBuffer), STR_ALT_PLUS, nullptr);
|
||||
#endif
|
||||
String::Append(buffer, sizeof(buffer), formatBuffer);
|
||||
}
|
||||
if (shortcutKey & CMD)
|
||||
{
|
||||
format_string(formatBuffer, sizeof(formatBuffer), STR_CMD_PLUS, nullptr);
|
||||
String::Append(buffer, sizeof(buffer), formatBuffer);
|
||||
}
|
||||
|
||||
SDL_Scancode scanCode = static_cast<SDL_Scancode>(shortcutKey & 0xFF);
|
||||
auto keyPair = specialCharNames.find(scanCode);
|
||||
if (keyPair != specialCharNames.end())
|
||||
{
|
||||
format_string(formatBuffer, sizeof(formatBuffer), keyPair->second, nullptr);
|
||||
String::Append(buffer, sizeof(buffer), formatBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
String::Append(buffer, sizeof(buffer), SDL_GetKeyName(SDL_GetKeyFromScancode(scanCode)));
|
||||
}
|
||||
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
ScreenCoordsXY KeyboardShortcuts::GetKeyboardMapScroll(const uint8_t* keysState) const
|
||||
{
|
||||
ScreenCoordsXY screenCoords;
|
||||
for (int32_t shortcutId = static_cast<int32_t>(Input::Shortcut::ScrollMapUp);
|
||||
shortcutId <= static_cast<int32_t>(Input::Shortcut::ScrollMapRight); shortcutId++)
|
||||
{
|
||||
uint16_t shortcutKey = _keys[shortcutId];
|
||||
uint8_t scancode = shortcutKey & 0xFF;
|
||||
|
||||
if (shortcutKey == Input::ScanCodeUndefined)
|
||||
continue;
|
||||
if (!keysState[scancode])
|
||||
continue;
|
||||
|
||||
// Check if SHIFT is either set in the shortcut key and currently pressed,
|
||||
// or not set in the shortcut key and not currently pressed (in other words: check if they match).
|
||||
if (static_cast<bool>(shortcutKey & SHIFT) != (keysState[SDL_SCANCODE_LSHIFT] || keysState[SDL_SCANCODE_RSHIFT]))
|
||||
continue;
|
||||
if (static_cast<bool>(shortcutKey & CTRL) != (keysState[SDL_SCANCODE_LCTRL] || keysState[SDL_SCANCODE_RCTRL]))
|
||||
continue;
|
||||
if (static_cast<bool>(shortcutKey & ALT) != (keysState[SDL_SCANCODE_LALT] || keysState[SDL_SCANCODE_RALT]))
|
||||
continue;
|
||||
#ifdef __MACOSX__
|
||||
if (static_cast<bool>(shortcutKey & CMD) != (keysState[SDL_SCANCODE_LGUI] || keysState[SDL_SCANCODE_RGUI]))
|
||||
continue;
|
||||
#endif
|
||||
auto convertedShortcut = static_cast<Input::Shortcut>(shortcutId);
|
||||
switch (convertedShortcut)
|
||||
{
|
||||
case Input::Shortcut::ScrollMapUp:
|
||||
screenCoords.y = -1;
|
||||
break;
|
||||
case Input::Shortcut::ScrollMapLeft:
|
||||
screenCoords.x = -1;
|
||||
break;
|
||||
case Input::Shortcut::ScrollMapDown:
|
||||
screenCoords.y = 1;
|
||||
break;
|
||||
case Input::Shortcut::ScrollMapRight:
|
||||
screenCoords.x = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return screenCoords;
|
||||
}
|
||||
|
||||
void KeyboardShortcutsReset()
|
||||
{
|
||||
_instance->Reset();
|
||||
}
|
||||
|
||||
bool KeyboardShortcutsLoad()
|
||||
{
|
||||
return _instance->Load();
|
||||
}
|
||||
|
||||
bool KeyboardShortcutsSave()
|
||||
{
|
||||
return _instance->Save();
|
||||
}
|
||||
|
||||
void KeyboardShortcutsSet(int32_t key)
|
||||
{
|
||||
return _instance->Set(key);
|
||||
}
|
||||
|
||||
Shortcut KeyboardShortcutsGetFromKey(int32_t key)
|
||||
{
|
||||
return _instance->GetFromKey(key);
|
||||
}
|
||||
|
||||
void KeyboardShortcutsFormatString(char* buffer, size_t bufferSize, int32_t shortcut)
|
||||
{
|
||||
auto str = _instance->GetShortcutString(shortcut);
|
||||
String::Set(buffer, bufferSize, str.c_str());
|
||||
}
|
||||
|
||||
ScreenCoordsXY GetKeyboardMapScroll(const uint8_t* keysState)
|
||||
{
|
||||
return _instance->GetKeyboardMapScroll(keysState);
|
||||
}
|
||||
|
||||
// Default keyboard shortcuts
|
||||
const uint16_t KeyboardShortcuts::DefaultKeys[Input::ShortcutsCount] = {
|
||||
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
|
||||
Input::ScanCodeUndefined, // SHORTCUT_SHOW_OPTIONS
|
||||
Input::ScanCodeUndefined, // SHORTCUT_MUTE_SOUND
|
||||
ALT | SDL_SCANCODE_RETURN, // SHORTCUT_WINDOWED_MODE_TOGGLE
|
||||
Input::ScanCodeUndefined, // SHORTCUT_SHOW_MULTIPLAYER
|
||||
Input::ScanCodeUndefined, // SHORTCUT_PAINT_ORIGINAL_TOGGLE
|
||||
Input::ScanCodeUndefined, // SHORTCUT_DEBUG_PAINT_TOGGLE
|
||||
Input::ScanCodeUndefined, // 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
|
||||
PLATFORM_MODIFIER | SDL_SCANCODE_L, // SHORTCUT_LOAD_GAME
|
||||
SDL_SCANCODE_B, // SHORTCUT_CLEAR_SCENERY
|
||||
SDL_SCANCODE_7, // SHORTCUT_GRIDLINES_DISPLAY_TOGGLE
|
||||
Input::ScanCodeUndefined, // SHORTCUT_VIEW_CLIPPING
|
||||
SDL_SCANCODE_I, // SHORTCUT_HIGHLIGHT_PATH_ISSUES_TOGGLE
|
||||
Input::ScanCodeUndefined, // SHORTCUT_TILE_INSPECTOR
|
||||
Input::ScanCodeUndefined, // SHORTCUT_ADVANCE_TO_NEXT_TICK
|
||||
Input::ScanCodeUndefined, // SHORTCUT_SCENERY_PICKER
|
||||
Input::ScanCodeUndefined, // SHORTCUT_SCALE_UP
|
||||
Input::ScanCodeUndefined, // SHORTCUT_SCALE_DOWN
|
||||
Input::ScanCodeUndefined, // SHORTCUT_TOGGLE_CLEARANCE_CHECKS
|
||||
};
|
|
@ -1,165 +0,0 @@
|
|||
/*****************************************************************************
|
||||
* Copyright (c) 2014-2020 OpenRCT2 developers
|
||||
*
|
||||
* For a complete list of all authors, please refer to contributors.md
|
||||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||
*
|
||||
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||
*****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <openrct2/common.h>
|
||||
|
||||
#define SHIFT 0x100
|
||||
#define CTRL 0x200
|
||||
#define ALT 0x400
|
||||
#define CMD 0x800
|
||||
#ifdef __MACOSX__
|
||||
# define PLATFORM_MODIFIER CMD
|
||||
#else
|
||||
# define PLATFORM_MODIFIER CTRL
|
||||
#endif
|
||||
|
||||
struct ScreenCoordsXY;
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OpenRCT2
|
||||
{
|
||||
struct IPlatformEnvironment;
|
||||
|
||||
namespace Input
|
||||
{
|
||||
enum class Shortcut : size_t
|
||||
{
|
||||
CloseTopMostWindow,
|
||||
CloseAllFloatingWindows,
|
||||
CancelConstructionMode,
|
||||
PauseGame,
|
||||
ZoomViewOut,
|
||||
ZoomViewIn,
|
||||
RotateViewClockwise,
|
||||
RotateViewAnticlockwise,
|
||||
RotateConstructionObject,
|
||||
UndergroundViewToggle,
|
||||
RemoveBaseLandToggle,
|
||||
RemoveVerticalLandToggle,
|
||||
SeeThroughRidesToggle,
|
||||
SeeThroughSceneryToggle,
|
||||
InvisibleSupportsToggle,
|
||||
InvisiblePeopleToggle,
|
||||
HeightMarksOnLandToggle,
|
||||
HeightMarksOnRideTracksToggle,
|
||||
HeightMarksOnPathsToggle,
|
||||
AdjustLand,
|
||||
AdjustWater,
|
||||
BuildScenery,
|
||||
BuildPaths,
|
||||
BuildNewRide,
|
||||
ShowFinancialInformation,
|
||||
ShowResearchInformation,
|
||||
ShowRidesList,
|
||||
ShowParkInformation,
|
||||
ShowGuestList,
|
||||
ShowStaffList,
|
||||
ShowRecentMessages,
|
||||
ShowMap,
|
||||
Screenshot,
|
||||
|
||||
// New
|
||||
ReduceGameSpeed,
|
||||
IncreaseGameSpeed,
|
||||
OpenCheatWindow,
|
||||
RemoveTopBottomToolbarToggle,
|
||||
ScrollMapUp,
|
||||
ScrollMapLeft,
|
||||
ScrollMapDown,
|
||||
ScrollMapRight,
|
||||
OpenChatWindow,
|
||||
QuickSaveGame,
|
||||
ShowOptions,
|
||||
MuteSound,
|
||||
WindowedModeToggle,
|
||||
ShowMultiplayer,
|
||||
PaintOriginalToggle,
|
||||
DebugPaintToggle,
|
||||
SeeThroughPathsToggle,
|
||||
RideConstructionTurnLeft,
|
||||
RideConstructionTurnRight,
|
||||
RideConstructionUseTrackDefault,
|
||||
RideConstructionSlopeDown,
|
||||
RideConstructionSlopeUp,
|
||||
RideConstructionChainLiftToggle,
|
||||
RideConstructionBankLeft,
|
||||
RideConstructionBankRight,
|
||||
RideConstructionPreviousTrack,
|
||||
RideConstructionNextTrack,
|
||||
RideConstructionBuildCurrent,
|
||||
RideConstructionDemolishCurrent,
|
||||
LoadGame,
|
||||
ClearScenery,
|
||||
GridlinesDisplayToggle,
|
||||
ViewClipping,
|
||||
HighlightPathIssuesToggle,
|
||||
TileInspector,
|
||||
AdvanceToNextTick,
|
||||
SceneryPicker,
|
||||
ScaleUp,
|
||||
ScaleDown,
|
||||
InsertCorruptElement,
|
||||
CopyElement,
|
||||
PasteElement,
|
||||
RemoveElement,
|
||||
MoveElementUp,
|
||||
MoveElementDown,
|
||||
IncreaseXCoord,
|
||||
DecreaseXCoord,
|
||||
IncreaseYCoord,
|
||||
DecreaseYCoord,
|
||||
IncreaseElementHeight,
|
||||
DecreaseElementHeight,
|
||||
ToggleClearanceChecks,
|
||||
|
||||
Count,
|
||||
|
||||
Undefined = 0xFFFF,
|
||||
};
|
||||
constexpr size_t ShortcutsCount = static_cast<size_t>(Shortcut::Count);
|
||||
|
||||
class KeyboardShortcuts
|
||||
{
|
||||
private:
|
||||
constexpr static int32_t CURRENT_FILE_VERSION = 1;
|
||||
static const uint16_t DefaultKeys[ShortcutsCount];
|
||||
|
||||
std::shared_ptr<IPlatformEnvironment> const _env;
|
||||
uint16_t _keys[ShortcutsCount];
|
||||
|
||||
public:
|
||||
KeyboardShortcuts(const std::shared_ptr<IPlatformEnvironment>& env);
|
||||
~KeyboardShortcuts();
|
||||
|
||||
void Reset();
|
||||
bool Load();
|
||||
bool Save();
|
||||
|
||||
std::string GetShortcutString(int32_t shortcut) const;
|
||||
|
||||
void Set(int32_t key);
|
||||
Shortcut GetFromKey(int32_t key);
|
||||
ScreenCoordsXY GetKeyboardMapScroll(const uint8_t* keysState) const;
|
||||
};
|
||||
const uint16_t ScanCodeUndefined = 0xFFFF;
|
||||
} // namespace Input
|
||||
} // namespace OpenRCT2
|
||||
|
||||
void KeyboardShortcutsReset();
|
||||
bool KeyboardShortcutsLoad();
|
||||
bool KeyboardShortcutsSave();
|
||||
void KeyboardShortcutsSet(int32_t key);
|
||||
OpenRCT2::Input::Shortcut KeyboardShortcutsGetFromKey(int32_t key);
|
||||
void KeyboardShortcutsFormatString(char* buffer, size_t bufferSize, int32_t shortcut);
|
||||
|
||||
ScreenCoordsXY GetKeyboardMapScroll(const uint8_t* keysState);
|
|
@ -10,6 +10,7 @@
|
|||
#include "ShortcutManager.h"
|
||||
|
||||
#include <SDL.h>
|
||||
#include <cstring>
|
||||
#include <openrct2/core/String.hpp>
|
||||
|
||||
using namespace OpenRCT2::Ui;
|
||||
|
|
|
@ -91,6 +91,23 @@ bool RegisteredShortcut::IsSuitableInputEvent(const InputEvent& e) const
|
|||
return true;
|
||||
}
|
||||
|
||||
std::string RegisteredShortcut::GetDisplayString() const
|
||||
{
|
||||
std::string result;
|
||||
auto numChords = Current.size();
|
||||
for (size_t i = 0; i < numChords; i++)
|
||||
{
|
||||
const auto& kc = Current[i];
|
||||
result += kc.ToString();
|
||||
if (i < numChords - 1)
|
||||
{
|
||||
// TODO localise...
|
||||
result += " or ";
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ShortcutManager::ShortcutManager(const std::shared_ptr<IPlatformEnvironment>& env)
|
||||
: _env(env)
|
||||
{
|
||||
|
@ -147,6 +164,7 @@ void ShortcutManager::ProcessEvent(const InputEvent& e)
|
|||
}
|
||||
_pendingShortcutChange.clear();
|
||||
window_close_by_class(WC_CHANGE_KEYBOARD_SHORTCUT);
|
||||
SaveUserBindings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -274,16 +292,19 @@ void ShortcutManager::LoadUserBindings(const fs::path& path)
|
|||
const auto& value = it.value();
|
||||
|
||||
const auto& shortcut = GetShortcut(key);
|
||||
shortcut->Current.clear();
|
||||
if (value.is_string())
|
||||
if (shortcut != nullptr)
|
||||
{
|
||||
shortcut->Current.emplace_back(value.get<std::string>());
|
||||
}
|
||||
else if (value.is_array())
|
||||
{
|
||||
for (auto& subValue : value)
|
||||
shortcut->Current.clear();
|
||||
if (value.is_string())
|
||||
{
|
||||
shortcut->Current.emplace_back(subValue.get<std::string>());
|
||||
shortcut->Current.emplace_back(value.get<std::string>());
|
||||
}
|
||||
else if (value.is_array())
|
||||
{
|
||||
for (auto& subValue : value)
|
||||
{
|
||||
shortcut->Current.emplace_back(subValue.get<std::string>());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,6 +98,7 @@ namespace OpenRCT2::Ui
|
|||
std::string_view GetGroup() const;
|
||||
bool Matches(const InputEvent& e) const;
|
||||
bool IsSuitableInputEvent(const InputEvent& e) const;
|
||||
std::string GetDisplayString() const;
|
||||
|
||||
private:
|
||||
};
|
||||
|
|
|
@ -7,16 +7,15 @@
|
|||
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "KeyboardShortcuts.h"
|
||||
#include "ShortcutIds.h"
|
||||
#include "ShortcutManager.h"
|
||||
|
||||
#include <iterator>
|
||||
#include <openrct2-ui/UiContext.h>
|
||||
#include <openrct2-ui/interface/InGameConsole.h>
|
||||
#include <openrct2-ui/interface/Viewport.h>
|
||||
#include <openrct2-ui/interface/Widget.h>
|
||||
#include <openrct2-ui/interface/Window.h>
|
||||
#include <openrct2-ui/windows/Window.h>
|
||||
#include <openrct2/Context.h>
|
||||
#include <openrct2/Editor.h>
|
||||
#include <openrct2/Game.h>
|
||||
|
@ -41,8 +40,6 @@
|
|||
#include <openrct2/world/Park.h>
|
||||
#include <openrct2/world/Scenery.h>
|
||||
|
||||
extern bool gWindowSceneryEyedropperEnabled;
|
||||
|
||||
using namespace OpenRCT2;
|
||||
using namespace OpenRCT2::Ui;
|
||||
|
|
@ -41,7 +41,6 @@
|
|||
<ClInclude Include="drawing\engines\opengl\TextureCache.h" />
|
||||
<ClInclude Include="drawing\engines\opengl\TransparencyDepth.h" />
|
||||
<ClInclude Include="input\InputManager.h" />
|
||||
<ClInclude Include="input\KeyboardShortcuts.h" />
|
||||
<ClInclude Include="input\ShortcutIds.h" />
|
||||
<ClInclude Include="input\ShortcutManager.h" />
|
||||
<ClInclude Include="interface\Dropdown.h" />
|
||||
|
@ -93,8 +92,7 @@
|
|||
<ClCompile Include="drawing\engines\opengl\TransparencyDepth.cpp" />
|
||||
<ClCompile Include="drawing\engines\SoftwareDrawingEngine.cpp" />
|
||||
<ClCompile Include="input\InputManager.cpp" />
|
||||
<ClCompile Include="input\KeyboardShortcut.cpp" />
|
||||
<ClCompile Include="input\KeyboardShortcuts.cpp" />
|
||||
<ClCompile Include="input\Shortcuts.cpp" />
|
||||
<ClCompile Include="input\MouseInput.cpp" />
|
||||
<ClCompile Include="input\ShortcutInput.cpp" />
|
||||
<ClCompile Include="input\ShortcutManager.cpp" />
|
||||
|
|
|
@ -42,6 +42,7 @@ namespace OpenRCT2::Scripting
|
|||
registeredShortcut.Default.emplace_back(binding);
|
||||
}
|
||||
shortcutManager.RegisterShortcut(std::move(registeredShortcut));
|
||||
shortcutManager.LoadUserBindings();
|
||||
}
|
||||
|
||||
CustomShortcut::~CustomShortcut()
|
||||
|
|
|
@ -358,11 +358,12 @@ private:
|
|||
ssp.ShortcutId = shortcut->Id;
|
||||
ssp.StringId = shortcut->LocalisedName;
|
||||
ssp.CustomString = shortcut->CustomName;
|
||||
ssp.Binding = FormatKeyChordsString(*shortcut);
|
||||
ssp.Binding = shortcut->GetDisplayString();
|
||||
_list.push_back(std::move(ssp));
|
||||
index++;
|
||||
}
|
||||
|
||||
WindowInitScrollWidgets(this);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
|
@ -505,22 +506,6 @@ private:
|
|||
DrawTextEllipsised(&dpi, { bindingOffset, y - 1 }, 150, format, ft, COLOUR_BLACK);
|
||||
}
|
||||
}
|
||||
|
||||
static std::string FormatKeyChordsString(const RegisteredShortcut& shortcut)
|
||||
{
|
||||
std::string result;
|
||||
auto numChords = shortcut.Current.size();
|
||||
for (size_t i = 0; i < numChords; i++)
|
||||
{
|
||||
const auto& kc = shortcut.Current[i];
|
||||
result += kc.ToString();
|
||||
if (i < numChords - 1)
|
||||
{
|
||||
result += " or ";
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
void ChangeShortcutWindow::NotifyShortcutKeysWindow()
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <openrct2-ui/input/KeyboardShortcuts.h>
|
||||
#include <openrct2-ui/interface/Window.h>
|
||||
#include <openrct2/common.h>
|
||||
#include <openrct2/ride/Ride.h>
|
||||
|
|
|
@ -3447,7 +3447,7 @@ const char* network_get_group_name(uint32_t index)
|
|||
void network_chat_show_connected_message()
|
||||
{
|
||||
auto windowManager = GetContext()->GetUiContext()->GetWindowManager();
|
||||
std::string s = windowManager->GetKeyboardShortcutString(41 /* SHORTCUT_OPEN_CHAT_WINDOW */);
|
||||
std::string s = windowManager->GetKeyboardShortcutString("interface.misc.multiplayer_chat");
|
||||
const char* sptr = s.c_str();
|
||||
|
||||
utf8 buffer[256];
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace OpenRCT2::Ui
|
|||
void HandleKeyboard(bool /*isTitle*/) override
|
||||
{
|
||||
}
|
||||
std::string GetKeyboardShortcutString(int32_t /*shortcut*/) override
|
||||
std::string GetKeyboardShortcutString(std::string_view /*shortcutId*/) override
|
||||
{
|
||||
return std::string();
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "../windows/Intent.h"
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
class Formatter;
|
||||
|
||||
|
@ -37,7 +38,7 @@ namespace OpenRCT2::Ui
|
|||
virtual void UpdateMapTooltip() abstract;
|
||||
virtual void HandleInput() abstract;
|
||||
virtual void HandleKeyboard(bool isTitle) abstract;
|
||||
virtual std::string GetKeyboardShortcutString(int32_t shortcut) abstract;
|
||||
virtual std::string GetKeyboardShortcutString(std::string_view shortcutId) abstract;
|
||||
virtual void SetMainView(const ScreenCoordsXY& viewPos, ZoomLevel zoom, int32_t rotation) abstract;
|
||||
virtual void UpdateMouseWheel() abstract;
|
||||
virtual rct_window* GetOwner(const rct_viewport* viewport) abstract;
|
||||
|
|
Loading…
Reference in New Issue