diff --git a/src/openrct2-ui/UiContext.cpp b/src/openrct2-ui/UiContext.cpp index 7fa89d74d3..22a551d5b9 100644 --- a/src/openrct2-ui/UiContext.cpp +++ b/src/openrct2-ui/UiContext.cpp @@ -36,6 +36,7 @@ #include "SDLException.h" #include "TextComposition.h" #include "UiContext.h" +#include "WindowManager.h" extern "C" { @@ -62,6 +63,7 @@ private: constexpr static uint32 TOUCH_DOUBLE_TIMEOUT = 300; IPlatformUiContext * const _platformUiContext; + IWindowManager * const _windowManager; CursorRepository _cursorRepository; @@ -89,6 +91,7 @@ private: public: UiContext(IPlatformEnvironment * env) : _platformUiContext(CreatePlatformUiContext()), + _windowManager(CreateWindowManager()), _keyboardShortcuts(env) { if (SDL_Init(SDL_INIT_VIDEO) < 0) @@ -566,6 +569,11 @@ public: return _platformUiContext->ShowDirectoryDialog(_window, title); } + IWindowManager * GetWindowManager() override + { + return _windowManager; + } + private: void OnResize(sint32 width, sint32 height) { diff --git a/src/openrct2-ui/WindowManager.cpp b/src/openrct2-ui/WindowManager.cpp new file mode 100644 index 0000000000..c62d264eb0 --- /dev/null +++ b/src/openrct2-ui/WindowManager.cpp @@ -0,0 +1,40 @@ +#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers +/***************************************************************************** +* OpenRCT2, an open source clone of Roller Coaster Tycoon 2. +* +* OpenRCT2 is the work of many authors, a full list can be found in contributors.md +* For more information, visit https://github.com/OpenRCT2/OpenRCT2 +* +* OpenRCT2 is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* A full copy of the GNU General Public License can be found in licence.txt +*****************************************************************************/ +#pragma endregion + +#include +#include "input/KeyboardShortcuts.h" +#include "WindowManager.h" + +using namespace OpenRCT2::Ui; + +class WindowManager final : public IWindowManager +{ +public: + rct_window * OpenWindow(rct_windowclass wc) override + { + switch (wc) { + case WC_KEYBOARD_SHORTCUT_LIST: + return window_shortcut_keys_open(); + default: + return nullptr; + } + } +}; + +IWindowManager * OpenRCT2::Ui::CreateWindowManager() +{ + return new WindowManager(); +} diff --git a/src/openrct2-ui/WindowManager.h b/src/openrct2-ui/WindowManager.h new file mode 100644 index 0000000000..9828776397 --- /dev/null +++ b/src/openrct2-ui/WindowManager.h @@ -0,0 +1,24 @@ +#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers +/***************************************************************************** +* OpenRCT2, an open source clone of Roller Coaster Tycoon 2. +* +* OpenRCT2 is the work of many authors, a full list can be found in contributors.md +* For more information, visit https://github.com/OpenRCT2/OpenRCT2 +* +* OpenRCT2 is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* A full copy of the GNU General Public License can be found in licence.txt +*****************************************************************************/ +#pragma endregion + +#include + +namespace OpenRCT2 { namespace Ui +{ + interface IWindowManager; + + IWindowManager * CreateWindowManager(); +} } diff --git a/src/openrct2-ui/input/KeyboardShortcuts.h b/src/openrct2-ui/input/KeyboardShortcuts.h index f8bab0aa27..f08038d80a 100644 --- a/src/openrct2-ui/input/KeyboardShortcuts.h +++ b/src/openrct2-ui/input/KeyboardShortcuts.h @@ -67,12 +67,17 @@ namespace OpenRCT2 extern "C" { #endif + typedef struct rct_window rct_window; + void keyboard_shortcuts_reset(); bool keyboard_shortcuts_load(); bool keyboard_shortcuts_save(); void keyboard_shortcuts_set(sint32 key); sint32 keyboard_shortcuts_get_from_key(sint32 key); void keyboard_shortcuts_format_string(char * buffer, size_t bufferSize, sint32 shortcut); + + rct_window * window_shortcut_keys_open(); + rct_window * window_shortcut_change_open(sint32 selected_key); #ifdef __cplusplus } #endif diff --git a/src/openrct2-ui/windows/shortcut_key_change.c b/src/openrct2-ui/windows/shortcut_key_change.c index c5686caf5c..3c7c106225 100644 --- a/src/openrct2-ui/windows/shortcut_key_change.c +++ b/src/openrct2-ui/windows/shortcut_key_change.c @@ -18,7 +18,7 @@ #include #include #include -#include "../input/keyboard_shortcut.h" +#include "../input/KeyboardShortcuts.h" extern const rct_string_id ShortcutStringIds[]; @@ -74,16 +74,18 @@ static rct_window_event_list window_shortcut_change_events = { NULL }; -void window_shortcut_change_open(sint32 selected_key){ +rct_window * window_shortcut_change_open(sint32 selected_key) +{ // Move this to window_shortcut_change_open window_close_by_class(WC_CHANGE_KEYBOARD_SHORTCUT); // Save the item we are selecting for new window gKeyboardShortcutChangeId = selected_key; - rct_window* w = window_create_centred(WW, WH, &window_shortcut_change_events, WC_CHANGE_KEYBOARD_SHORTCUT, 0); + rct_window * w = window_create_centred(WW, WH, &window_shortcut_change_events, WC_CHANGE_KEYBOARD_SHORTCUT, 0); w->widgets = window_shortcut_change_widgets; w->enabled_widgets = (1ULL << WIDX_CLOSE); window_init_scroll_widgets(w); + return w; } /** diff --git a/src/openrct2-ui/windows/shortcut_keys.c b/src/openrct2-ui/windows/shortcut_keys.c index 023596334d..08609264e7 100644 --- a/src/openrct2-ui/windows/shortcut_keys.c +++ b/src/openrct2-ui/windows/shortcut_keys.c @@ -155,26 +155,25 @@ const rct_string_id ShortcutStringIds[] = { * * rct2: 0x006E3884 */ -void window_shortcut_keys_open() +rct_window * window_shortcut_keys_open() { - rct_window* w; + rct_window * w = window_bring_to_front_by_class(WC_KEYBOARD_SHORTCUT_LIST); + if (w == NULL) + { + w = window_create_auto_pos(WW, WH, &window_shortcut_events, WC_KEYBOARD_SHORTCUT_LIST, WF_RESIZABLE); - w = window_bring_to_front_by_class(WC_KEYBOARD_SHORTCUT_LIST); + w->widgets = window_shortcut_widgets; + w->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_RESET); + window_init_scroll_widgets(w); - if (w) return; - - w = window_create_auto_pos(WW, WH, &window_shortcut_events, WC_KEYBOARD_SHORTCUT_LIST, WF_RESIZABLE); - - w->widgets = window_shortcut_widgets; - w->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_RESET); - window_init_scroll_widgets(w); - - w->no_list_items = SHORTCUT_COUNT; - w->selected_list_item = -1; - w->min_width = WW; - w->min_height = WH; - w->max_width = WW_SC_MAX; - w->max_height = WH_SC_MAX; + w->no_list_items = SHORTCUT_COUNT; + w->selected_list_item = -1; + w->min_width = WW; + w->min_height = WH; + w->max_width = WW_SC_MAX; + w->max_height = WH_SC_MAX; + } + return w; } /** diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index 2ec3bb7684..659e6a67ef 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -37,6 +37,7 @@ #include "scenario/ScenarioRepository.h" #include "title/TitleScreen.h" #include "title/TitleSequenceManager.h" +#include "ui/WindowManager.h" #include "Version.h" extern "C" @@ -652,6 +653,12 @@ extern "C" GetContext()->GetUiContext()->SetCursorTrap(value); } + rct_window * context_open_window(rct_windowclass wc) + { + auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + return windowManager->OpenWindow(wc); + } + bool platform_open_common_file_dialog(utf8 * outFilename, file_dialog_desc * desc, size_t outSize) { try diff --git a/src/openrct2/Context.h b/src/openrct2/Context.h index 62cee65864..8b027da6fc 100644 --- a/src/openrct2/Context.h +++ b/src/openrct2/Context.h @@ -18,6 +18,16 @@ #include "common.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + #include "interface/window.h" +#ifdef __cplusplus +} +#endif + typedef struct CursorState { sint32 x, y; @@ -117,7 +127,7 @@ extern "C" sint32 context_get_height(); bool context_has_focus(); void context_set_cursor_trap(bool value); - + rct_window * context_open_window(rct_windowclass wc); #ifdef __cplusplus } #endif diff --git a/src/openrct2/interface/window.h b/src/openrct2/interface/window.h index adfc81acae..2d634391ee 100644 --- a/src/openrct2/interface/window.h +++ b/src/openrct2/interface/window.h @@ -702,8 +702,6 @@ void window_guest_list_open(); void window_guest_list_open_with_filter(sint32 type, sint32 index); void window_map_open(); void window_options_open(); -void window_shortcut_keys_open(); -void window_shortcut_change_open(sint32 selected_key); void window_guest_open(rct_peep* peep); rct_window *window_staff_open(rct_peep* peep); void window_staff_fire_prompt_open(rct_peep* peep); diff --git a/src/openrct2/ui/DummyUiContext.cpp b/src/openrct2/ui/DummyUiContext.cpp index ce666cd405..3ca2c013ba 100644 --- a/src/openrct2/ui/DummyUiContext.cpp +++ b/src/openrct2/ui/DummyUiContext.cpp @@ -16,6 +16,7 @@ #include "../drawing/X8DrawingEngine.h" #include "UiContext.h" +#include "WindowManager.h" using namespace OpenRCT2::Drawing; @@ -26,6 +27,10 @@ namespace OpenRCT2 { namespace Ui */ class DummyUiContext final : public IUiContext { + private: + IWindowManager * const _windowManager = CreateDummyWindowManager(); + + public: void CreateWindow() override { } void CloseWindow() override { } void * GetWindow() override { return nullptr; } @@ -39,32 +44,38 @@ namespace OpenRCT2 { namespace Ui void ProcessMessages() override { } void TriggerResize() override { } - virtual void ShowMessageBox(const std::string &message) override { } - virtual std::string ShowFileDialog(const FileDialogDesc &desc) override { return std::string(); } - virtual std::string ShowDirectoryDialog(const std::string &title) override { return std::string(); } + void ShowMessageBox(const std::string &message) override { } + std::string ShowFileDialog(const FileDialogDesc &desc) override { return std::string(); } + std::string ShowDirectoryDialog(const std::string &title) override { return std::string(); } // Input - virtual const CursorState * GetCursorState() override { return nullptr; } - virtual CURSOR_ID GetCursor() override { return CURSOR_ARROW; } - virtual void SetCursor(CURSOR_ID cursor) override { } - virtual void SetCursorVisible(bool value) override { } - virtual void GetCursorPosition(sint32 * x, sint32 * y) override { } - virtual void SetCursorPosition(sint32 x, sint32 y) override { } - virtual void SetCursorTrap(bool value) override { } - virtual const uint8 * GetKeysState() override { return nullptr; } - virtual const uint8 * GetKeysPressed() override { return nullptr; } - virtual void SetKeysPressed(uint32 keysym, uint8 scancode) override { } + const CursorState * GetCursorState() override { return nullptr; } + CURSOR_ID GetCursor() override { return CURSOR_ARROW; } + void SetCursor(CURSOR_ID cursor) override { } + void SetCursorVisible(bool value) override { } + void GetCursorPosition(sint32 * x, sint32 * y) override { } + void SetCursorPosition(sint32 x, sint32 y) override { } + void SetCursorTrap(bool value) override { } + const uint8 * GetKeysState() override { return nullptr; } + const uint8 * GetKeysPressed() override { return nullptr; } + void SetKeysPressed(uint32 keysym, uint8 scancode) override { } // Drawing - virtual Drawing::IDrawingEngine * CreateDrawingEngine(Drawing::DRAWING_ENGINE_TYPE type) override + Drawing::IDrawingEngine * CreateDrawingEngine(Drawing::DRAWING_ENGINE_TYPE type) override { return new X8DrawingEngine(); } // Text input - virtual bool IsTextInputActive() override { return false; } - virtual TextInputSession * StartTextInput(utf8 * buffer, size_t bufferSize) override { return nullptr; } - virtual void StopTextInput() override { } + bool IsTextInputActive() override { return false; } + TextInputSession * StartTextInput(utf8 * buffer, size_t bufferSize) override { return nullptr; } + void StopTextInput() override { } + + // In-game UI + IWindowManager * GetWindowManager() override + { + return _windowManager; + } }; IUiContext * CreateDummyUiContext() diff --git a/src/openrct2/ui/DummyWindowManager.cpp b/src/openrct2/ui/DummyWindowManager.cpp new file mode 100644 index 0000000000..5ffdc361e9 --- /dev/null +++ b/src/openrct2/ui/DummyWindowManager.cpp @@ -0,0 +1,30 @@ +#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers +/***************************************************************************** +* OpenRCT2, an open source clone of Roller Coaster Tycoon 2. +* +* OpenRCT2 is the work of many authors, a full list can be found in contributors.md +* For more information, visit https://github.com/OpenRCT2/OpenRCT2 +* +* OpenRCT2 is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* A full copy of the GNU General Public License can be found in licence.txt +*****************************************************************************/ +#pragma endregion + +#include "WindowManager.h" + +namespace OpenRCT2 { namespace Ui +{ + class DummyWindowManager final : public IWindowManager + { + rct_window * OpenWindow(rct_windowclass wc) override { return nullptr; } + }; + + IWindowManager * CreateDummyWindowManager() + { + return new DummyWindowManager(); + } +} } diff --git a/src/openrct2/ui/UiContext.h b/src/openrct2/ui/UiContext.h index 201bd290ae..df3c89f862 100644 --- a/src/openrct2/ui/UiContext.h +++ b/src/openrct2/ui/UiContext.h @@ -32,6 +32,8 @@ namespace OpenRCT2 namespace Ui { + interface IWindowManager; + enum class FULLSCREEN_MODE { WINDOWED, @@ -126,6 +128,9 @@ namespace OpenRCT2 virtual bool IsTextInputActive() abstract; virtual TextInputSession * StartTextInput(utf8 * buffer, size_t bufferSize) abstract; virtual void StopTextInput() abstract; + + // In-game UI + virtual IWindowManager * GetWindowManager() abstract; }; IUiContext * CreateDummyUiContext(); diff --git a/src/openrct2/ui/WindowManager.h b/src/openrct2/ui/WindowManager.h new file mode 100644 index 0000000000..96db0dae17 --- /dev/null +++ b/src/openrct2/ui/WindowManager.h @@ -0,0 +1,41 @@ +#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers +/***************************************************************************** +* OpenRCT2, an open source clone of Roller Coaster Tycoon 2. +* +* OpenRCT2 is the work of many authors, a full list can be found in contributors.md +* For more information, visit https://github.com/OpenRCT2/OpenRCT2 +* +* OpenRCT2 is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* A full copy of the GNU General Public License can be found in licence.txt +*****************************************************************************/ +#pragma endregion + +#pragma once + +#include "../common.h" + +extern "C" +{ + #include "../interface/window.h" +} + +namespace OpenRCT2 +{ + namespace Ui + { + /** + * Manager of in-game windows and widgets. + */ + interface IWindowManager + { + virtual ~IWindowManager() = default; + virtual rct_window * OpenWindow(rct_windowclass wc) abstract; + }; + + IWindowManager * CreateDummyWindowManager(); + } +} diff --git a/src/openrct2/windows/options.c b/src/openrct2/windows/options.c index d1de6a6231..474b6db8dd 100644 --- a/src/openrct2/windows/options.c +++ b/src/openrct2/windows/options.c @@ -738,7 +738,7 @@ static void window_options_mouseup(rct_window *w, rct_widgetindex widgetIndex) case WINDOW_OPTIONS_PAGE_CONTROLS_AND_INTERFACE: switch (widgetIndex) { case WIDX_HOTKEY_DROPDOWN: - window_shortcut_keys_open(); + context_open_window(WC_KEYBOARD_SHORTCUT_LIST); break; case WIDX_SCREEN_EDGE_SCROLLING: gConfigGeneral.edge_scrolling ^= 1;