mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-23 07:43:01 +01:00
Link back shortcut functions
Some of this will be temporary until input and windows move over to libopenrct2ui.
This commit is contained in:
@@ -32,6 +32,23 @@ public:
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HandleKeyboardShortcut(sint32 key) override
|
||||||
|
{
|
||||||
|
rct_window * w = window_find_by_class(WC_CHANGE_KEYBOARD_SHORTCUT);
|
||||||
|
if (w != NULL) {
|
||||||
|
keyboard_shortcuts_set(key);
|
||||||
|
window_close_by_class(WC_CHANGE_KEYBOARD_SHORTCUT);
|
||||||
|
window_invalidate_by_class(WC_KEYBOARD_SHORTCUT_LIST);
|
||||||
|
} else {
|
||||||
|
keyboard_shortcut_handle(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GetKeyboardMapScroll(const uint8 * keysState, sint32 * x, sint32 * y) override
|
||||||
|
{
|
||||||
|
get_keyboard_map_scroll(keysState, x, y);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
IWindowManager * OpenRCT2::Ui::CreateWindowManager()
|
IWindowManager * OpenRCT2::Ui::CreateWindowManager()
|
||||||
|
|||||||
@@ -109,8 +109,6 @@ void KeyboardShortcuts::Set(sint32 key)
|
|||||||
|
|
||||||
// Map shortcut to this key
|
// Map shortcut to this key
|
||||||
_keys[gKeyboardShortcutChangeId] = key;
|
_keys[gKeyboardShortcutChangeId] = key;
|
||||||
// window_close_by_class(WC_CHANGE_KEYBOARD_SHORTCUT);
|
|
||||||
// window_invalidate_by_class(WC_KEYBOARD_SHORTCUT_LIST);
|
|
||||||
Save();
|
Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,6 +158,54 @@ std::string KeyboardShortcuts::GetShortcutString(sint32 shortcut) const
|
|||||||
return std::string(buffer);
|
return std::string(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KeyboardShortcuts::GetKeyboardMapScroll(const uint8 * keysState, sint32 * x, sint32 * y) const
|
||||||
|
{
|
||||||
|
for (sint32 shortcutId = SHORTCUT_SCROLL_MAP_UP; shortcutId <= SHORTCUT_SCROLL_MAP_RIGHT; shortcutId++)
|
||||||
|
{
|
||||||
|
uint16 shortcutKey = _keys[shortcutId];
|
||||||
|
uint8 scancode = shortcutKey & 0xFF;
|
||||||
|
|
||||||
|
if (shortcutKey == 0xFFFF) continue;
|
||||||
|
if (!keysState[scancode]) continue;
|
||||||
|
|
||||||
|
if (shortcutKey & SHIFT) {
|
||||||
|
if (!keysState[SDL_SCANCODE_LSHIFT] && !keysState[SDL_SCANCODE_RSHIFT]) continue;
|
||||||
|
}
|
||||||
|
if (shortcutKey & CTRL) {
|
||||||
|
if (!keysState[SDL_SCANCODE_LCTRL] && !keysState[SDL_SCANCODE_RCTRL]) continue;
|
||||||
|
}
|
||||||
|
if (shortcutKey & ALT) {
|
||||||
|
if (!keysState[SDL_SCANCODE_LALT] && !keysState[SDL_SCANCODE_RALT]) continue;
|
||||||
|
}
|
||||||
|
#ifdef __MACOSX__
|
||||||
|
if (shortcutKey & CMD) {
|
||||||
|
if (!keysState[SDL_SCANCODE_LGUI] && !keysState[SDL_SCANCODE_RGUI]) continue;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
switch (shortcutId) {
|
||||||
|
case SHORTCUT_SCROLL_MAP_UP:
|
||||||
|
*x = 0;
|
||||||
|
*y = -1;
|
||||||
|
break;
|
||||||
|
case SHORTCUT_SCROLL_MAP_LEFT:
|
||||||
|
*x = -1;
|
||||||
|
*y = 0;
|
||||||
|
break;
|
||||||
|
case SHORTCUT_SCROLL_MAP_DOWN:
|
||||||
|
*x = 0;
|
||||||
|
*y = 1;
|
||||||
|
break;
|
||||||
|
case SHORTCUT_SCROLL_MAP_RIGHT:
|
||||||
|
*x = 1;
|
||||||
|
*y = 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
*x = 0;
|
||||||
|
*y = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
void keyboard_shortcuts_reset()
|
void keyboard_shortcuts_reset()
|
||||||
@@ -192,6 +238,11 @@ extern "C"
|
|||||||
auto str = _instance->GetShortcutString(shortcut);
|
auto str = _instance->GetShortcutString(shortcut);
|
||||||
String::Set(buffer, bufferSize, str.c_str());
|
String::Set(buffer, bufferSize, str.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void get_keyboard_map_scroll(const uint8 * keysState, sint32 * x, sint32 * y)
|
||||||
|
{
|
||||||
|
_instance->GetKeyboardMapScroll(keysState, x, y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default keyboard shortcuts
|
// Default keyboard shortcuts
|
||||||
|
|||||||
@@ -130,6 +130,7 @@ namespace OpenRCT2
|
|||||||
|
|
||||||
void Set(sint32 key);
|
void Set(sint32 key);
|
||||||
sint32 GetFromKey(sint32 key);
|
sint32 GetFromKey(sint32 key);
|
||||||
|
void GetKeyboardMapScroll(const uint8 * keysState, sint32 * x, sint32 * y) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -155,10 +156,11 @@ extern "C"
|
|||||||
rct_window * window_shortcut_keys_open();
|
rct_window * window_shortcut_keys_open();
|
||||||
rct_window * window_shortcut_change_open(sint32 selected_key);
|
rct_window * window_shortcut_change_open(sint32 selected_key);
|
||||||
|
|
||||||
void keyboard_shortcut_set(sint32 key);
|
|
||||||
void keyboard_shortcut_handle(sint32 key);
|
void keyboard_shortcut_handle(sint32 key);
|
||||||
void keyboard_shortcut_handle_command(sint32 shortcutIndex);
|
void keyboard_shortcut_handle_command(sint32 shortcutIndex);
|
||||||
void keyboard_shortcut_format_string(char *buffer, size_t size, uint16 shortcutKey);
|
void keyboard_shortcut_format_string(char *buffer, size_t size, uint16 shortcutKey);
|
||||||
|
|
||||||
|
void get_keyboard_map_scroll(const uint8 * keysState, sint32 * x, sint32 * y);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -48,6 +48,7 @@
|
|||||||
<ClCompile Include="UiContext.cpp" />
|
<ClCompile Include="UiContext.cpp" />
|
||||||
<ClCompile Include="UiContext.Linux.cpp" />
|
<ClCompile Include="UiContext.Linux.cpp" />
|
||||||
<ClCompile Include="UiContext.Win32.cpp" />
|
<ClCompile Include="UiContext.Win32.cpp" />
|
||||||
|
<ClCompile Include="WindowManager.cpp" />
|
||||||
<ClCompile Include="windows\shortcut_keys.c" />
|
<ClCompile Include="windows\shortcut_keys.c" />
|
||||||
<ClCompile Include="windows\shortcut_key_change.c" />
|
<ClCompile Include="windows\shortcut_key_change.c" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@@ -72,6 +73,7 @@
|
|||||||
<ClInclude Include="TextComposition.h" />
|
<ClInclude Include="TextComposition.h" />
|
||||||
<ClInclude Include="Ui.h" />
|
<ClInclude Include="Ui.h" />
|
||||||
<ClInclude Include="UiContext.h" />
|
<ClInclude Include="UiContext.h" />
|
||||||
|
<ClInclude Include="WindowManager.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
<ProjectGuid>{8DD8AB7D-2EA6-44E3-8265-BAF08E832951}</ProjectGuid>
|
<ProjectGuid>{8DD8AB7D-2EA6-44E3-8265-BAF08E832951}</ProjectGuid>
|
||||||
|
|||||||
@@ -659,6 +659,18 @@ extern "C"
|
|||||||
return windowManager->OpenWindow(wc);
|
return windowManager->OpenWindow(wc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void context_handle_keyboard_shortcut(sint32 key)
|
||||||
|
{
|
||||||
|
auto windowManager = GetContext()->GetUiContext()->GetWindowManager();
|
||||||
|
windowManager->HandleKeyboardShortcut(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
void context_get_keyboard_map_scroll(const uint8 * keysState, sint32 * x, sint32 * y)
|
||||||
|
{
|
||||||
|
auto windowManager = GetContext()->GetUiContext()->GetWindowManager();
|
||||||
|
windowManager->GetKeyboardMapScroll(keysState, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
bool platform_open_common_file_dialog(utf8 * outFilename, file_dialog_desc * desc, size_t outSize)
|
bool platform_open_common_file_dialog(utf8 * outFilename, file_dialog_desc * desc, size_t outSize)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -128,6 +128,8 @@ extern "C"
|
|||||||
bool context_has_focus();
|
bool context_has_focus();
|
||||||
void context_set_cursor_trap(bool value);
|
void context_set_cursor_trap(bool value);
|
||||||
rct_window * context_open_window(rct_windowclass wc);
|
rct_window * context_open_window(rct_windowclass wc);
|
||||||
|
void context_handle_keyboard_shortcut(sint32 key);
|
||||||
|
void context_get_keyboard_map_scroll(const uint8 * keysState, sint32 * x, sint32 * y);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1434,89 +1434,21 @@ static void input_handle_chat(sint32 key)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static void input_handle_keyboard(bool isTitle)
|
||||||
*
|
|
||||||
* rct2: 0x006E3B43
|
|
||||||
*/
|
|
||||||
void title_handle_keyboard_input()
|
|
||||||
{
|
{
|
||||||
rct_window *w;
|
|
||||||
sint32 key;
|
|
||||||
|
|
||||||
if (gOpenRCT2Headless) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!gConsoleOpen) {
|
|
||||||
// Handle modifier keys and key scrolling
|
|
||||||
gInputPlaceObjectModifier = PLACE_OBJECT_MODIFIER_NONE;
|
|
||||||
const uint8 * keysState = context_get_keys_state();
|
|
||||||
if (keysState[SDL_SCANCODE_LSHIFT] || keysState[SDL_SCANCODE_RSHIFT])
|
|
||||||
gInputPlaceObjectModifier |= PLACE_OBJECT_MODIFIER_SHIFT_Z;
|
|
||||||
if (keysState[SDL_SCANCODE_LCTRL] || keysState[SDL_SCANCODE_RCTRL])
|
|
||||||
gInputPlaceObjectModifier |= PLACE_OBJECT_MODIFIER_COPY_Z;
|
|
||||||
if (keysState[SDL_SCANCODE_LALT] || keysState[SDL_SCANCODE_RALT])
|
|
||||||
gInputPlaceObjectModifier |= 4;
|
|
||||||
#ifdef __MACOSX__
|
|
||||||
if (keysState[SDL_SCANCODE_LGUI] || keysState[SDL_SCANCODE_RGUI]) {
|
|
||||||
gInputPlaceObjectModifier |= 8;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((key = get_next_key()) != 0) {
|
|
||||||
if (key == 255)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Reserve backtick for console
|
|
||||||
if (key == SDL_SCANCODE_GRAVE) {
|
|
||||||
if ((gConfigGeneral.debugging_tools && !context_is_input_active()) || gConsoleOpen) {
|
|
||||||
window_cancel_textbox();
|
|
||||||
console_toggle();
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
} else if (gConsoleOpen) {
|
|
||||||
input_handle_console(key);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
key |= gInputPlaceObjectModifier << 8;
|
|
||||||
|
|
||||||
w = window_find_by_class(WC_CHANGE_KEYBOARD_SHORTCUT);
|
|
||||||
if (w != NULL) {
|
|
||||||
// keyboard_shortcut_set(key);
|
|
||||||
} else {
|
|
||||||
w = window_find_by_class(WC_TEXTINPUT);
|
|
||||||
if (w != NULL) {
|
|
||||||
window_text_input_key(w, key);
|
|
||||||
}
|
|
||||||
else if (!gUsingWidgetTextBox) {
|
|
||||||
// keyboard_shortcut_handle(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* rct2: 0x006E3B43
|
|
||||||
*/
|
|
||||||
void game_handle_keyboard_input()
|
|
||||||
{
|
|
||||||
rct_window *w;
|
|
||||||
sint32 key;
|
|
||||||
|
|
||||||
if (gOpenRCT2Headless) {
|
if (gOpenRCT2Headless) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gConsoleOpen) {
|
if (!gConsoleOpen) {
|
||||||
|
if (!isTitle) {
|
||||||
// Handle mouse scrolling
|
// Handle mouse scrolling
|
||||||
if (_inputState == INPUT_STATE_NORMAL && gConfigGeneral.edge_scrolling) {
|
if (_inputState == INPUT_STATE_NORMAL && gConfigGeneral.edge_scrolling) {
|
||||||
if (!(gInputPlaceObjectModifier & (PLACE_OBJECT_MODIFIER_SHIFT_Z | PLACE_OBJECT_MODIFIER_COPY_Z))) {
|
if (!(gInputPlaceObjectModifier & (PLACE_OBJECT_MODIFIER_SHIFT_Z | PLACE_OBJECT_MODIFIER_COPY_Z))) {
|
||||||
game_handle_edge_scroll();
|
game_handle_edge_scroll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Handle modifier keys and key scrolling
|
// Handle modifier keys and key scrolling
|
||||||
gInputPlaceObjectModifier = PLACE_OBJECT_MODIFIER_NONE;
|
gInputPlaceObjectModifier = PLACE_OBJECT_MODIFIER_NONE;
|
||||||
@@ -1535,11 +1467,13 @@ void game_handle_keyboard_input()
|
|||||||
gInputPlaceObjectModifier |= 8;
|
gInputPlaceObjectModifier |= 8;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
if (!isTitle) {
|
||||||
game_handle_key_scroll();
|
game_handle_key_scroll();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Handle key input
|
// Handle key input
|
||||||
|
sint32 key;
|
||||||
while (!gOpenRCT2Headless && (key = get_next_key()) != 0) {
|
while (!gOpenRCT2Headless && (key = get_next_key()) != 0) {
|
||||||
if (key == 255)
|
if (key == 255)
|
||||||
continue;
|
continue;
|
||||||
@@ -1554,25 +1488,38 @@ void game_handle_keyboard_input()
|
|||||||
} else if (gConsoleOpen) {
|
} else if (gConsoleOpen) {
|
||||||
input_handle_console(key);
|
input_handle_console(key);
|
||||||
continue;
|
continue;
|
||||||
} else if (gChatOpen) {
|
} else if (!isTitle && gChatOpen) {
|
||||||
input_handle_chat(key);
|
input_handle_chat(key);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
key |= gInputPlaceObjectModifier << 8;
|
key |= gInputPlaceObjectModifier << 8;
|
||||||
|
|
||||||
w = window_find_by_class(WC_CHANGE_KEYBOARD_SHORTCUT);
|
rct_window * w = window_find_by_class(WC_TEXTINPUT);
|
||||||
if (w != NULL) {
|
|
||||||
// keyboard_shortcut_set(key);
|
|
||||||
} else {
|
|
||||||
w = window_find_by_class(WC_TEXTINPUT);
|
|
||||||
if (w != NULL) {
|
if (w != NULL) {
|
||||||
window_text_input_key(w, key);
|
window_text_input_key(w, key);
|
||||||
} else if (!gUsingWidgetTextBox) {
|
} else if (!gUsingWidgetTextBox) {
|
||||||
// keyboard_shortcut_handle(key);
|
context_handle_keyboard_shortcut(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* rct2: 0x006E3B43
|
||||||
|
*/
|
||||||
|
void title_handle_keyboard_input()
|
||||||
|
{
|
||||||
|
input_handle_keyboard(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* rct2: 0x006E3B43
|
||||||
|
*/
|
||||||
|
void game_handle_keyboard_input()
|
||||||
|
{
|
||||||
|
input_handle_keyboard(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1704,45 +1651,8 @@ void game_handle_key_scroll()
|
|||||||
|
|
||||||
scrollX = 0;
|
scrollX = 0;
|
||||||
scrollY = 0;
|
scrollY = 0;
|
||||||
|
const uint8 * keysState = context_get_keys_state();
|
||||||
// const uint8 * keysState = context_get_keys_state();
|
context_get_keyboard_map_scroll(keysState, &scrollX, &scrollY);
|
||||||
// for (sint32 shortcutId = SHORTCUT_SCROLL_MAP_UP; shortcutId <= SHORTCUT_SCROLL_MAP_RIGHT; shortcutId++) {
|
|
||||||
// uint16 shortcutKey = gShortcutKeys[shortcutId];
|
|
||||||
// uint8 scancode = shortcutKey & 0xFF;
|
|
||||||
//
|
|
||||||
// if (shortcutKey == 0xFFFF) continue;
|
|
||||||
// if (!keysState[scancode]) continue;
|
|
||||||
//
|
|
||||||
// if (shortcutKey & SHIFT) {
|
|
||||||
// if (!keysState[SDL_SCANCODE_LSHIFT] && !keysState[SDL_SCANCODE_RSHIFT]) continue;
|
|
||||||
// }
|
|
||||||
// if (shortcutKey & CTRL) {
|
|
||||||
// if (!keysState[SDL_SCANCODE_LCTRL] && !keysState[SDL_SCANCODE_RCTRL]) continue;
|
|
||||||
// }
|
|
||||||
// if (shortcutKey & ALT) {
|
|
||||||
// if (!keysState[SDL_SCANCODE_LALT] && !keysState[SDL_SCANCODE_RALT]) continue;
|
|
||||||
// }
|
|
||||||
// #ifdef __MACOSX__
|
|
||||||
// if (shortcutKey & CMD) {
|
|
||||||
// if (!keysState[SDL_SCANCODE_LGUI] && !keysState[SDL_SCANCODE_RGUI]) continue;
|
|
||||||
// }
|
|
||||||
// #endif
|
|
||||||
//
|
|
||||||
// switch (shortcutId) {
|
|
||||||
// case SHORTCUT_SCROLL_MAP_UP:
|
|
||||||
// scrollY = -1;
|
|
||||||
// break;
|
|
||||||
// case SHORTCUT_SCROLL_MAP_LEFT:
|
|
||||||
// scrollX = -1;
|
|
||||||
// break;
|
|
||||||
// case SHORTCUT_SCROLL_MAP_DOWN:
|
|
||||||
// scrollY = 1;
|
|
||||||
// break;
|
|
||||||
// case SHORTCUT_SCROLL_MAP_RIGHT:
|
|
||||||
// scrollX = 1;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Scroll viewport
|
// Scroll viewport
|
||||||
if (scrollX != 0) {
|
if (scrollX != 0) {
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ namespace OpenRCT2 { namespace Ui
|
|||||||
class DummyWindowManager final : public IWindowManager
|
class DummyWindowManager final : public IWindowManager
|
||||||
{
|
{
|
||||||
rct_window * OpenWindow(rct_windowclass wc) override { return nullptr; }
|
rct_window * OpenWindow(rct_windowclass wc) override { return nullptr; }
|
||||||
|
void HandleKeyboardShortcut(sint32 key) override { }
|
||||||
|
void GetKeyboardMapScroll(const uint8 * keysState, sint32 * x, sint32 * y) override { }
|
||||||
};
|
};
|
||||||
|
|
||||||
IWindowManager * CreateDummyWindowManager()
|
IWindowManager * CreateDummyWindowManager()
|
||||||
|
|||||||
@@ -34,6 +34,9 @@ namespace OpenRCT2
|
|||||||
{
|
{
|
||||||
virtual ~IWindowManager() = default;
|
virtual ~IWindowManager() = default;
|
||||||
virtual rct_window * OpenWindow(rct_windowclass wc) abstract;
|
virtual rct_window * OpenWindow(rct_windowclass wc) abstract;
|
||||||
|
|
||||||
|
virtual void HandleKeyboardShortcut(sint32 key) abstract;
|
||||||
|
virtual void GetKeyboardMapScroll(const uint8 * keysState, sint32 * x, sint32 * y) abstract;
|
||||||
};
|
};
|
||||||
|
|
||||||
IWindowManager * CreateDummyWindowManager();
|
IWindowManager * CreateDummyWindowManager();
|
||||||
|
|||||||
Reference in New Issue
Block a user