mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 11:03:00 +01:00
Process keyboard input events
This commit is contained in:
@@ -420,6 +420,7 @@ public:
|
||||
{
|
||||
InputEvent ie;
|
||||
ie.DeviceKind = InputDeviceKind::Mouse;
|
||||
ie.Modifiers = SDL_GetModState();
|
||||
ie.Button = e.button.button;
|
||||
ie.State = InputEventState::Down;
|
||||
auto& inputManager = GetInputManager();
|
||||
@@ -456,6 +457,7 @@ public:
|
||||
{
|
||||
InputEvent ie;
|
||||
ie.DeviceKind = InputDeviceKind::Mouse;
|
||||
ie.Modifiers = SDL_GetModState();
|
||||
ie.Button = e.button.button;
|
||||
ie.State = InputEventState::Release;
|
||||
auto& inputManager = GetInputManager();
|
||||
@@ -517,7 +519,27 @@ public:
|
||||
#endif
|
||||
case SDL_KEYDOWN:
|
||||
_textComposition.HandleMessage(&e);
|
||||
{
|
||||
InputEvent ie;
|
||||
ie.DeviceKind = InputDeviceKind::Keyboard;
|
||||
ie.Modifiers = e.key.keysym.mod;
|
||||
ie.Button = e.key.keysym.sym;
|
||||
ie.State = InputEventState::Down;
|
||||
auto& inputManager = GetInputManager();
|
||||
inputManager.QueueInputEvent(std::move(ie));
|
||||
}
|
||||
break;
|
||||
case SDL_KEYUP:
|
||||
{
|
||||
InputEvent ie;
|
||||
ie.DeviceKind = InputDeviceKind::Keyboard;
|
||||
ie.Modifiers = e.key.keysym.mod;
|
||||
ie.Button = e.key.keysym.sym;
|
||||
ie.State = InputEventState::Release;
|
||||
auto& inputManager = GetInputManager();
|
||||
inputManager.QueueInputEvent(std::move(ie));
|
||||
}
|
||||
break;
|
||||
case SDL_MULTIGESTURE:
|
||||
if (e.mgesture.numFingers == 2)
|
||||
{
|
||||
|
||||
@@ -122,6 +122,10 @@ static int32_t InputScancodeToRCTKeycode(int32_t sdl_key)
|
||||
}
|
||||
|
||||
void InputHandleKeyboard(bool isTitle)
|
||||
{
|
||||
}
|
||||
|
||||
void InputHandleKeyboard2(bool isTitle)
|
||||
{
|
||||
if (gOpenRCT2Headless)
|
||||
{
|
||||
@@ -225,7 +229,7 @@ void InputHandleKeyboard(bool isTitle)
|
||||
}
|
||||
else
|
||||
{
|
||||
KeyboardShortcutHandle(key);
|
||||
// KeyboardShortcutHandle(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace OpenRCT2::Ui
|
||||
struct InputEvent
|
||||
{
|
||||
InputDeviceKind DeviceKind;
|
||||
uint32_t Modifiers;
|
||||
uint32_t Button;
|
||||
InputEventState State;
|
||||
};
|
||||
|
||||
@@ -40,43 +40,8 @@
|
||||
|
||||
extern bool gWindowSceneryEyedropperEnabled;
|
||||
|
||||
using shortcut_action = void (*)();
|
||||
using namespace OpenRCT2;
|
||||
|
||||
Input::Shortcut gKeyboardShortcutChangeId;
|
||||
|
||||
namespace
|
||||
{
|
||||
extern const shortcut_action shortcut_table[Input::ShortcutsCount];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x006E3E68
|
||||
*/
|
||||
using namespace OpenRCT2;
|
||||
void KeyboardShortcutHandle(int32_t key)
|
||||
{
|
||||
auto shortcut = KeyboardShortcutsGetFromKey(key);
|
||||
if (shortcut != Input::Shortcut::Undefined)
|
||||
{
|
||||
KeyboardShortcutHandleCommand(shortcut);
|
||||
}
|
||||
}
|
||||
|
||||
void KeyboardShortcutHandleCommand(Input::Shortcut shortcut)
|
||||
{
|
||||
size_t shortcutIndex = static_cast<size_t>(shortcut);
|
||||
if (shortcutIndex < std::size(shortcut_table))
|
||||
{
|
||||
shortcut_action action = shortcut_table[shortcutIndex];
|
||||
if (action != nullptr)
|
||||
{
|
||||
action();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma region Shortcut Commands
|
||||
|
||||
static void OpenWindow(rct_windowclass wc)
|
||||
@@ -461,102 +426,6 @@ static void ShortcutQuickSaveGame()
|
||||
}
|
||||
}
|
||||
|
||||
static void ShortcutRideConstructionTurnLeft()
|
||||
{
|
||||
if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)
|
||||
return;
|
||||
|
||||
window_ride_construction_keyboard_shortcut_turn_left();
|
||||
}
|
||||
|
||||
static void ShortcutRideConstructionTurnRight()
|
||||
{
|
||||
if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)
|
||||
return;
|
||||
|
||||
window_ride_construction_keyboard_shortcut_turn_right();
|
||||
}
|
||||
|
||||
static void ShortcutRideConstructionUseTrackDefault()
|
||||
{
|
||||
if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)
|
||||
return;
|
||||
|
||||
window_ride_construction_keyboard_shortcut_use_track_default();
|
||||
}
|
||||
|
||||
static void ShortcutRideConstructionSlopeDown()
|
||||
{
|
||||
if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)
|
||||
return;
|
||||
|
||||
window_ride_construction_keyboard_shortcut_slope_down();
|
||||
}
|
||||
|
||||
static void ShortcutRideConstructionSlopeUp()
|
||||
{
|
||||
if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)
|
||||
return;
|
||||
|
||||
window_ride_construction_keyboard_shortcut_slope_up();
|
||||
}
|
||||
|
||||
static void ShortcutRideConstructionChainLiftToggle()
|
||||
{
|
||||
if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)
|
||||
return;
|
||||
|
||||
window_ride_construction_keyboard_shortcut_chain_lift_toggle();
|
||||
}
|
||||
|
||||
static void ShortcutRideConstructionBankLeft()
|
||||
{
|
||||
if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)
|
||||
return;
|
||||
|
||||
window_ride_construction_keyboard_shortcut_bank_left();
|
||||
}
|
||||
|
||||
static void ShortcutRideConstructionBankRight()
|
||||
{
|
||||
if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)
|
||||
return;
|
||||
|
||||
window_ride_construction_keyboard_shortcut_bank_right();
|
||||
}
|
||||
|
||||
static void ShortcutRideConstructionPreviousTrack()
|
||||
{
|
||||
if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)
|
||||
return;
|
||||
|
||||
window_ride_construction_keyboard_shortcut_previous_track();
|
||||
}
|
||||
|
||||
static void ShortcutRideConstructionNextTrack()
|
||||
{
|
||||
if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)
|
||||
return;
|
||||
|
||||
window_ride_construction_keyboard_shortcut_next_track();
|
||||
}
|
||||
|
||||
static void ShortcutRideConstructionBuildCurrent()
|
||||
{
|
||||
if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)
|
||||
return;
|
||||
|
||||
window_ride_construction_keyboard_shortcut_build_current();
|
||||
}
|
||||
|
||||
static void ShortcutRideConstructionDemolishCurrent()
|
||||
{
|
||||
if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)
|
||||
return;
|
||||
|
||||
window_ride_construction_keyboard_shortcut_demolish_current();
|
||||
}
|
||||
|
||||
static void ShortcutLoadGame()
|
||||
{
|
||||
if (!(gScreenFlags & (SCREEN_FLAGS_TRACK_DESIGNER | SCREEN_FLAGS_TRACK_MANAGER)))
|
||||
@@ -725,58 +594,6 @@ static void ShortcutToggleClearanceChecks()
|
||||
GameActions::Execute(&setCheatAction);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
using namespace OpenRCT2::Input;
|
||||
const shortcut_action shortcut_table[ShortcutsCount] = {
|
||||
ShortcutAdjustLand,
|
||||
ShortcutAdjustWater,
|
||||
ShortcutBuildScenery,
|
||||
ShortcutBuildPaths,
|
||||
ShortcutBuildNewRide,
|
||||
ShortcutShowFinancialInformation,
|
||||
ShortcutShowResearchInformation,
|
||||
ShortcutShowRidesList,
|
||||
ShortcutShowParkInformation,
|
||||
ShortcutShowGuestList,
|
||||
ShortcutShowStaffList,
|
||||
ShortcutShowRecentMessages,
|
||||
ShortcutShowMap,
|
||||
|
||||
// new
|
||||
ShortcutReduceGameSpeed,
|
||||
ShortcutIncreaseGameSpeed,
|
||||
ShortcutOpenCheatWindow,
|
||||
ShortcutRemoveTopBottomToolbarToggle,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
ShortcutQuickSaveGame,
|
||||
nullptr,
|
||||
ShortcutRideConstructionTurnLeft,
|
||||
ShortcutRideConstructionTurnRight,
|
||||
ShortcutRideConstructionUseTrackDefault,
|
||||
ShortcutRideConstructionSlopeDown,
|
||||
ShortcutRideConstructionSlopeUp,
|
||||
ShortcutRideConstructionChainLiftToggle,
|
||||
ShortcutRideConstructionBankLeft,
|
||||
ShortcutRideConstructionBankRight,
|
||||
ShortcutRideConstructionPreviousTrack,
|
||||
ShortcutRideConstructionNextTrack,
|
||||
ShortcutRideConstructionBuildCurrent,
|
||||
ShortcutRideConstructionDemolishCurrent,
|
||||
ShortcutLoadGame,
|
||||
ShortcutClearScenery,
|
||||
ShortcutOpenSceneryPicker,
|
||||
ShortcutScaleUp,
|
||||
ShortcutScaleDown,
|
||||
ShortcutIncreaseElementHeight,
|
||||
ShortcutDecreaseElementHeight,
|
||||
ShortcutToggleClearanceChecks,
|
||||
};
|
||||
} // anonymous namespace
|
||||
|
||||
#pragma endregion
|
||||
|
||||
using namespace OpenRCT2::Ui;
|
||||
@@ -827,32 +644,16 @@ void ShortcutManager::RegisterDefaultShortcuts()
|
||||
}
|
||||
}
|
||||
});
|
||||
RegisterShortcut("interface1.decrease_speed", STR_SHORTCUT_REDUCE_GAME_SPEED , "-", []() {
|
||||
if (!(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) && network_get_mode() == NETWORK_MODE_NONE)
|
||||
{
|
||||
game_reduce_game_speed();
|
||||
}
|
||||
});
|
||||
RegisterShortcut("interface1.increase_speed", STR_SHORTCUT_INCREASE_GAME_SPEED , "=", []() {
|
||||
if (!(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) && network_get_mode() == NETWORK_MODE_NONE)
|
||||
{
|
||||
game_increase_game_speed();
|
||||
}
|
||||
});
|
||||
RegisterShortcut("interface1.load_game", STR_LOAD_GAME, "CTRL+L", []() {
|
||||
if (!(gScreenFlags & (SCREEN_FLAGS_TRACK_DESIGNER | SCREEN_FLAGS_TRACK_MANAGER)))
|
||||
{
|
||||
auto loadOrQuitAction = LoadOrQuitAction(LoadOrQuitModes::OpenSavePrompt);
|
||||
GameActions::Execute(&loadOrQuitAction);
|
||||
}
|
||||
});
|
||||
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(); });
|
||||
|
||||
// Interface 2
|
||||
RegisterShortcut("interface2.open_cheats", STR_SHORTCUT_OPEN_CHEATS_WINDOW, "CTRL+ALT+C", []() { OpenWindow(WC_CHEATS); });
|
||||
RegisterShortcut("interface2.open_cheats", STR_SHORTCUT_OPEN_CHEATS_WINDOW, "CTRL+ALT+C", []() { ShortcutOpenCheatWindow(); });
|
||||
RegisterShortcut("interface2.disable_clearance", STR_SHORTCUT_TOGGLE_CLEARANCE_CHECKS, []() { ShortcutToggleClearanceChecks(); });
|
||||
|
||||
// Interface 3
|
||||
@@ -871,13 +672,13 @@ void ShortcutManager::RegisterDefaultShortcuts()
|
||||
RegisterShortcut("interface4.build_new_ride", STR_SHORTCUT_BUILD_NEW_RIDE, "F5", []() { ShortcutBuildNewRide(); });
|
||||
|
||||
// Interface 5
|
||||
RegisterShortcut("interface5.show_finances", STR_SHORTCUT_SHOW_FINANCIAL_INFORMATION, "F", []() { OpenWindow(WC_FINANCES); });
|
||||
RegisterShortcut("interface5.show_research", STR_SHORTCUT_SHOW_RESEARCH_INFORMATION, "D", []() { OpenWindow(WC_RESEARCH); });
|
||||
RegisterShortcut("interface5.show_rides", STR_SHORTCUT_SHOW_RIDES_LIST, "R", []() { OpenWindow(WC_RIDE_LIST); });
|
||||
RegisterShortcut("interface5.show_park", STR_SHORTCUT_SHOW_PARK_INFORMATION, "P", []() { OpenWindow(WC_PARK_INFORMATION); });
|
||||
RegisterShortcut("interface5.show_guests", STR_SHORTCUT_SHOW_GUEST_LIST, "G", []() { OpenWindow(WC_GUEST_LIST); });
|
||||
RegisterShortcut("interface5.show_staff", STR_SHORTCUT_SHOW_STAFF_LIST, "S", []() { OpenWindow(WC_STAFF_LIST); });
|
||||
RegisterShortcut("interface5.show_messages", STR_SHORTCUT_SHOW_RECENT_MESSAGES, "M", []() { OpenWindow(WC_RECENT_NEWS); });
|
||||
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(); });
|
||||
|
||||
// Multiplayer
|
||||
RegisterShortcut("multiplayer.show", STR_SHORTCUT_SHOW_MULTIPLAYER, []() {
|
||||
@@ -910,7 +711,7 @@ void ShortcutManager::RegisterDefaultShortcuts()
|
||||
RegisterShortcut("view.show_gridlines", STR_SHORTCUT_GRIDLINES_DISPLAY_TOGGLE, "7", []() { ToggleViewFlag(VIEWPORT_FLAG_GRIDLINES); });
|
||||
|
||||
// Interface 6
|
||||
RegisterShortcut("interface6.open_scenery", STR_SHORTCUT_OPEN_SCENERY_PICKER, []() { ShortcutBuildScenery(); });
|
||||
RegisterShortcut("interface6.scenery_picker", STR_SHORTCUT_OPEN_SCENERY_PICKER, []() { ShortcutOpenSceneryPicker(); });
|
||||
RegisterShortcut("interface6.rotate_construction", STR_SHORTCUT_ROTATE_CONSTRUCTION_OBJECT, "Z", []() { ShortcutRotateConstructionObject(); });
|
||||
|
||||
// Ride construction
|
||||
|
||||
@@ -153,7 +153,7 @@ void KeyboardShortcuts::Set(int32_t key)
|
||||
}
|
||||
|
||||
// Map shortcut to this key
|
||||
_keys[static_cast<size_t>(gKeyboardShortcutChangeId)] = key;
|
||||
// _keys[static_cast<size_t>(gKeyboardShortcutChangeId)] = key;
|
||||
Save();
|
||||
}
|
||||
|
||||
|
||||
@@ -155,9 +155,6 @@ namespace OpenRCT2
|
||||
} // namespace Input
|
||||
} // namespace OpenRCT2
|
||||
|
||||
// The current shortcut being changed.
|
||||
extern OpenRCT2::Input::Shortcut gKeyboardShortcutChangeId;
|
||||
|
||||
void KeyboardShortcutsReset();
|
||||
bool KeyboardShortcutsLoad();
|
||||
bool KeyboardShortcutsSave();
|
||||
@@ -165,7 +162,4 @@ void KeyboardShortcutsSet(int32_t key);
|
||||
OpenRCT2::Input::Shortcut KeyboardShortcutsGetFromKey(int32_t key);
|
||||
void KeyboardShortcutsFormatString(char* buffer, size_t bufferSize, int32_t shortcut);
|
||||
|
||||
void KeyboardShortcutHandle(int32_t key);
|
||||
void KeyboardShortcutHandleCommand(OpenRCT2::Input::Shortcut shortcut);
|
||||
|
||||
ScreenCoordsXY GetKeyboardMapScroll(const uint8_t* keysState);
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
using namespace OpenRCT2::Ui;
|
||||
|
||||
constexpr uint32_t UsefulModifiers = KMOD_SHIFT | KMOD_CTRL | KMOD_ALT | KMOD_GUI;
|
||||
|
||||
static uint32_t ParseModifier(const std::string_view& text)
|
||||
{
|
||||
if (String::Equals(text, "CTRL", true))
|
||||
@@ -232,9 +234,7 @@ std::string ShortcutInput::ToString() const
|
||||
}
|
||||
else
|
||||
{
|
||||
char buffer[8]{};
|
||||
utf8_write_codepoint(buffer, Key);
|
||||
result += buffer;
|
||||
String::AppendCodepoint(result, std::toupper(Key));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -285,9 +285,17 @@ bool ShortcutInput::AppendModifier(std::string& s, const std::string_view& text,
|
||||
|
||||
bool ShortcutInput::Matches(const InputEvent& e) const
|
||||
{
|
||||
auto modifiers = e.Modifiers & UsefulModifiers;
|
||||
if (e.DeviceKind == InputDeviceKind::Mouse)
|
||||
{
|
||||
if (Kind == ShortcutInputKind::Mouse && Key == e.Button)
|
||||
if (Kind == ShortcutInputKind::Mouse && Modifiers == modifiers && Key == e.Button)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (e.DeviceKind == InputDeviceKind::Keyboard)
|
||||
{
|
||||
if (Kind == ShortcutInputKind::Keyboard && Modifiers == modifiers && Key == e.Button)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -297,10 +305,20 @@ bool ShortcutInput::Matches(const InputEvent& e) const
|
||||
|
||||
std::optional<ShortcutInput> ShortcutInput::FromInputEvent(const InputEvent& e)
|
||||
{
|
||||
auto modifiers = e.Modifiers & UsefulModifiers;
|
||||
if (e.DeviceKind == InputDeviceKind::Mouse)
|
||||
{
|
||||
ShortcutInput result;
|
||||
result.Kind = ShortcutInputKind::Mouse;
|
||||
result.Modifiers = modifiers;
|
||||
result.Key = e.Button;
|
||||
return result;
|
||||
}
|
||||
else if (e.DeviceKind == InputDeviceKind::Keyboard)
|
||||
{
|
||||
ShortcutInput result;
|
||||
result.Kind = ShortcutInputKind::Keyboard;
|
||||
result.Modifiers = modifiers;
|
||||
result.Key = e.Button;
|
||||
return result;
|
||||
}
|
||||
@@ -342,6 +360,13 @@ bool RegisteredShortcut::IsSuitableInputEvent(const InputEvent& e) const
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (e.DeviceKind == InputDeviceKind::Keyboard)
|
||||
{
|
||||
if (e.State == InputEventState::Down)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user