From 499af7983111c5e16e4315138633ba9addae6ab4 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Fri, 12 Sep 2025 13:42:30 +0200 Subject: [PATCH 1/3] Move Resolution struct from Context to UiContext --- src/openrct2/Context.h | 6 ------ src/openrct2/ui/UiContext.h | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/openrct2/Context.h b/src/openrct2/Context.h index 343718a42f..eb693a81a0 100644 --- a/src/openrct2/Context.h +++ b/src/openrct2/Context.h @@ -63,12 +63,6 @@ struct TextInputSession const utf8* ImeBuffer; // IME UTF-8 stream }; -struct Resolution -{ - int32_t Width; - int32_t Height; -}; - enum { CURSOR_UP = 0, diff --git a/src/openrct2/ui/UiContext.h b/src/openrct2/ui/UiContext.h index 0d3a3bfd97..3dfe29b190 100644 --- a/src/openrct2/ui/UiContext.h +++ b/src/openrct2/ui/UiContext.h @@ -43,6 +43,12 @@ namespace OpenRCT2 fullscreenDesktop, }; + struct Resolution + { + int32_t Width; + int32_t Height; + }; + inline bool operator<(const Resolution& lhs, const Resolution& rhs) { int32_t areaA = lhs.Width * lhs.Height; From ffa2c3ab6c2e609bac1fa2658f87c9e6fc60a32e Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Fri, 12 Sep 2025 13:45:16 +0200 Subject: [PATCH 2/3] Move game tick time constants from Context.h to Game.h --- src/openrct2/Context.h | 15 --------------- src/openrct2/Game.h | 14 +++++++++++++- src/openrct2/scenes/title/Command/Wait.cpp | 2 +- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/openrct2/Context.h b/src/openrct2/Context.h index eb693a81a0..316f35f3c0 100644 --- a/src/openrct2/Context.h +++ b/src/openrct2/Context.h @@ -187,21 +187,6 @@ namespace OpenRCT2 [[nodiscard]] IContext* GetContext(); } // namespace OpenRCT2 -namespace -{ - // The number of logical update / ticks per second. - constexpr uint32_t kGameUpdateFPS = 40; - // The maximum amount of updates in case rendering is slower - constexpr uint32_t kGameMaxUpdates = 4; - // The game update interval in milliseconds, (1000 / 40fps) = 25ms - constexpr float kGameUpdateTimeMS = 1.0f / kGameUpdateFPS; - // The maximum threshold to advance. - constexpr float kGameUpdateMaxThreshold = kGameUpdateTimeMS * kGameMaxUpdates; -}; // namespace - -constexpr float kGameMinTimeScale = 0.1f; -constexpr float kGameMaxTimeScale = 5.0f; - void ContextInit(); void ContextSetCurrentCursor(CursorID cursor); void ContextUpdateCursorScale(); diff --git a/src/openrct2/Game.h b/src/openrct2/Game.h index 68ef7e65df..9b08cf16c3 100644 --- a/src/openrct2/Game.h +++ b/src/openrct2/Game.h @@ -16,7 +16,19 @@ namespace OpenRCT2 { class Intent; -} + + // The number of logical update / ticks per second. + constexpr uint32_t kGameUpdateFPS = 40; + // The maximum amount of updates in case rendering is slower + constexpr uint32_t kGameMaxUpdates = 4; + // The game update interval in milliseconds, (1000 / 40fps) = 25ms + constexpr float kGameUpdateTimeMS = 1.0f / kGameUpdateFPS; + // The maximum threshold to advance. + constexpr float kGameUpdateMaxThreshold = kGameUpdateTimeMS * kGameMaxUpdates; + + constexpr float kGameMinTimeScale = 0.1f; + constexpr float kGameMaxTimeScale = 5.0f; +} // namespace OpenRCT2 struct ParkLoadResult; diff --git a/src/openrct2/scenes/title/Command/Wait.cpp b/src/openrct2/scenes/title/Command/Wait.cpp index e2876ebc78..b754bb1072 100644 --- a/src/openrct2/scenes/title/Command/Wait.cpp +++ b/src/openrct2/scenes/title/Command/Wait.cpp @@ -9,7 +9,7 @@ #include "Wait.h" -#include "../../../Context.h" +#include "../../../Game.h" namespace OpenRCT2::Title { From 9b7ee06e0fd0a81ed462b4377cfbd5ed64cd6d3a Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Fri, 12 Sep 2025 14:03:44 +0200 Subject: [PATCH 3/3] Move Context fully into OpenRCT2 namespace; types into Input.h --- src/openrct2-ui/TextComposition.h | 2 +- src/openrct2-ui/interface/InGameConsole.cpp | 1 + src/openrct2-ui/interface/Widget.cpp | 1 - src/openrct2-ui/interface/Window.h | 5 +- .../windows/EditorObjectSelection.cpp | 1 + src/openrct2-ui/windows/Error.cpp | 1 + src/openrct2-ui/windows/TextInput.cpp | 1 + src/openrct2/Context.cpp | 380 +++++++++--------- src/openrct2/Context.h | 135 +++---- src/openrct2/Game.cpp | 2 +- src/openrct2/Input.h | 31 ++ src/openrct2/OpenRCT2.h | 2 - src/openrct2/interface/Chat.cpp | 1 + src/openrct2/interface/InteractiveConsole.h | 4 +- src/openrct2/interface/StdInOutConsole.cpp | 4 +- src/openrct2/scenes/intro/IntroScene.cpp | 1 + src/openrct2/ui/WindowManager.h | 4 +- 17 files changed, 283 insertions(+), 293 deletions(-) diff --git a/src/openrct2-ui/TextComposition.h b/src/openrct2-ui/TextComposition.h index 0d09d2be45..0160d8f1aa 100644 --- a/src/openrct2-ui/TextComposition.h +++ b/src/openrct2-ui/TextComposition.h @@ -9,7 +9,7 @@ #pragma once -#include +#include union SDL_Event; diff --git a/src/openrct2-ui/interface/InGameConsole.cpp b/src/openrct2-ui/interface/InGameConsole.cpp index 3b82741ee4..f9cc7649ee 100644 --- a/src/openrct2-ui/interface/InGameConsole.cpp +++ b/src/openrct2-ui/interface/InGameConsole.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2-ui/interface/Widget.cpp b/src/openrct2-ui/interface/Widget.cpp index 3df9c02f13..8db8c6aa2b 100644 --- a/src/openrct2-ui/interface/Widget.cpp +++ b/src/openrct2-ui/interface/Widget.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include diff --git a/src/openrct2-ui/interface/Window.h b/src/openrct2-ui/interface/Window.h index 7cfc33a97a..02c4c5a3f9 100644 --- a/src/openrct2-ui/interface/Window.h +++ b/src/openrct2-ui/interface/Window.h @@ -12,7 +12,10 @@ #include #include -struct TextInputSession; +namespace OpenRCT2 +{ + struct TextInputSession; +} namespace OpenRCT2::Ui { diff --git a/src/openrct2-ui/windows/EditorObjectSelection.cpp b/src/openrct2-ui/windows/EditorObjectSelection.cpp index d6a9cde99f..f1753006d6 100644 --- a/src/openrct2-ui/windows/EditorObjectSelection.cpp +++ b/src/openrct2-ui/windows/EditorObjectSelection.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2-ui/windows/Error.cpp b/src/openrct2-ui/windows/Error.cpp index 197b2a73a8..ecded9bc6b 100644 --- a/src/openrct2-ui/windows/Error.cpp +++ b/src/openrct2-ui/windows/Error.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2-ui/windows/TextInput.cpp b/src/openrct2-ui/windows/TextInput.cpp index a3ea6e4d08..00d3514e83 100644 --- a/src/openrct2-ui/windows/TextInput.cpp +++ b/src/openrct2-ui/windows/TextInput.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index cee23e502c..a0cde2667c 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -890,7 +890,7 @@ namespace OpenRCT2 auto windowManager = _uiContext->GetWindowManager(); auto ft = Formatter(); ft.Add(result.TargetVersion); - ft.Add(OpenRCT2::kParkFileCurrentVersion); + ft.Add(kParkFileCurrentVersion); windowManager->ShowError(STR_WARNING_PARK_VERSION_TITLE, STR_WARNING_PARK_VERSION_MESSAGE, ft); } else if (HasObjectsThatUseFallbackImages()) @@ -954,14 +954,14 @@ namespace OpenRCT2 if (e.MinVersion == e.TargetVersion) { ft.Add(e.TargetVersion); - ft.Add(OpenRCT2::kParkFileCurrentVersion); + ft.Add(kParkFileCurrentVersion); windowManager->ShowError(STR_ERROR_PARK_VERSION_TITLE, STR_ERROR_PARK_VERSION_TOO_NEW_MESSAGE_2, ft); } else { ft.Add(e.TargetVersion); ft.Add(e.MinVersion); - ft.Add(OpenRCT2::kParkFileCurrentVersion); + ft.Add(kParkFileCurrentVersion); windowManager->ShowError(STR_ERROR_PARK_VERSION_TITLE, STR_ERROR_PARK_VERSION_TOO_NEW_MESSAGE, ft); } } @@ -1591,194 +1591,188 @@ namespace OpenRCT2 return Context::Instance; } + void ContextInit() + { + GetWindowManager()->Init(); + } + + bool ContextLoadParkFromStream(void* stream) + { + return GetContext()->LoadParkFromStream(static_cast(stream), ""); + } + + void ContextSetCurrentCursor(CursorID cursor) + { + GetContext()->GetUiContext().SetCursor(cursor); + } + + void ContextUpdateCursorScale() + { + GetContext()->GetUiContext().SetCursorScale(static_cast(std::round(Config::Get().general.WindowScale))); + } + + void ContextHideCursor() + { + GetContext()->GetUiContext().SetCursorVisible(false); + } + + void ContextShowCursor() + { + GetContext()->GetUiContext().SetCursorVisible(true); + } + + ScreenCoordsXY ContextGetCursorPosition() + { + return GetContext()->GetUiContext().GetCursorPosition(); + } + + ScreenCoordsXY ContextGetCursorPositionScaled() + { + auto cursorCoords = ContextGetCursorPosition(); + // Compensate for window scaling. + return { static_cast(std::ceil(cursorCoords.x / Config::Get().general.WindowScale)), + static_cast(std::ceil(cursorCoords.y / Config::Get().general.WindowScale)) }; + } + + void ContextSetCursorPosition(const ScreenCoordsXY& cursorPosition) + { + GetContext()->GetUiContext().SetCursorPosition(cursorPosition); + } + + const CursorState* ContextGetCursorState() + { + return GetContext()->GetUiContext().GetCursorState(); + } + + const uint8_t* ContextGetKeysState() + { + return GetContext()->GetUiContext().GetKeysState(); + } + + const uint8_t* ContextGetKeysPressed() + { + return GetContext()->GetUiContext().GetKeysPressed(); + } + + TextInputSession* ContextStartTextInput(u8string& buffer, size_t maxLength) + { + return GetContext()->GetUiContext().StartTextInput(buffer, maxLength); + } + + void ContextStopTextInput() + { + GetContext()->GetUiContext().StopTextInput(); + } + + bool ContextIsInputActive() + { + return GetContext()->GetUiContext().IsTextInputActive(); + } + + void ContextTriggerResize() + { + return GetContext()->GetUiContext().TriggerResize(); + } + + void ContextSetFullscreenMode(int32_t mode) + { + return GetContext()->GetUiContext().SetFullscreenMode(static_cast(mode)); + } + + void ContextRecreateWindow() + { + GetContext()->GetUiContext().RecreateWindow(); + } + + int32_t ContextGetWidth() + { + return GetContext()->GetUiContext().GetWidth(); + } + + int32_t ContextGetHeight() + { + return GetContext()->GetUiContext().GetHeight(); + } + + bool ContextHasFocus() + { + return GetContext()->GetUiContext().HasFocus(); + } + + void ContextSetCursorTrap(bool value) + { + GetContext()->GetUiContext().SetCursorTrap(value); + } + + WindowBase* ContextOpenWindow(WindowClass wc) + { + auto windowManager = Ui::GetWindowManager(); + return windowManager->OpenWindow(wc); + } + + WindowBase* ContextOpenWindowView(uint8_t wc) + { + auto windowManager = Ui::GetWindowManager(); + return windowManager->OpenView(wc); + } + + WindowBase* ContextOpenDetailWindow(uint8_t type, int32_t id) + { + auto windowManager = Ui::GetWindowManager(); + return windowManager->OpenDetails(type, id); + } + + WindowBase* ContextOpenIntent(Intent* intent) + { + auto windowManager = Ui::GetWindowManager(); + return windowManager->OpenIntent(intent); + } + + void ContextBroadcastIntent(Intent* intent) + { + auto windowManager = Ui::GetWindowManager(); + windowManager->BroadcastIntent(*intent); + } + + void ContextForceCloseWindowByClass(WindowClass windowClass) + { + auto windowManager = Ui::GetWindowManager(); + windowManager->ForceClose(windowClass); + } + + WindowBase* ContextShowError(StringId title, StringId message, const Formatter& args, const bool autoClose /* = false */) + { + auto windowManager = Ui::GetWindowManager(); + return windowManager->ShowError(title, message, args, autoClose); + } + + void ContextHandleInput() + { + auto windowManager = Ui::GetWindowManager(); + windowManager->HandleInput(); + } + + void ContextInputHandleKeyboard(bool isTitle) + { + auto windowManager = Ui::GetWindowManager(); + windowManager->HandleKeyboard(isTitle); + } + + void ContextQuit() + { + GetContext()->Quit(); + } + + u8string ContextOpenCommonFileDialog(Ui::FileDialogDesc& desc) + { + try + { + return GetContext()->GetUiContext().ShowFileDialog(desc); + } + catch (const std::exception& ex) + { + LOG_ERROR(ex.what()); + return u8string{}; + } + } } // namespace OpenRCT2 - -void ContextInit() -{ - GetWindowManager()->Init(); -} - -bool ContextLoadParkFromStream(void* stream) -{ - return GetContext()->LoadParkFromStream(static_cast(stream), ""); -} - -void OpenRCT2Finish() -{ - GetContext()->Finish(); -} - -void ContextSetCurrentCursor(CursorID cursor) -{ - GetContext()->GetUiContext().SetCursor(cursor); -} - -void ContextUpdateCursorScale() -{ - GetContext()->GetUiContext().SetCursorScale(static_cast(std::round(Config::Get().general.WindowScale))); -} - -void ContextHideCursor() -{ - GetContext()->GetUiContext().SetCursorVisible(false); -} - -void ContextShowCursor() -{ - GetContext()->GetUiContext().SetCursorVisible(true); -} - -ScreenCoordsXY ContextGetCursorPosition() -{ - return GetContext()->GetUiContext().GetCursorPosition(); -} - -ScreenCoordsXY ContextGetCursorPositionScaled() -{ - auto cursorCoords = ContextGetCursorPosition(); - // Compensate for window scaling. - return { static_cast(std::ceil(cursorCoords.x / Config::Get().general.WindowScale)), - static_cast(std::ceil(cursorCoords.y / Config::Get().general.WindowScale)) }; -} - -void ContextSetCursorPosition(const ScreenCoordsXY& cursorPosition) -{ - GetContext()->GetUiContext().SetCursorPosition(cursorPosition); -} - -const CursorState* ContextGetCursorState() -{ - return GetContext()->GetUiContext().GetCursorState(); -} - -const uint8_t* ContextGetKeysState() -{ - return GetContext()->GetUiContext().GetKeysState(); -} - -const uint8_t* ContextGetKeysPressed() -{ - return GetContext()->GetUiContext().GetKeysPressed(); -} - -TextInputSession* ContextStartTextInput(u8string& buffer, size_t maxLength) -{ - return GetContext()->GetUiContext().StartTextInput(buffer, maxLength); -} - -void ContextStopTextInput() -{ - GetContext()->GetUiContext().StopTextInput(); -} - -bool ContextIsInputActive() -{ - return GetContext()->GetUiContext().IsTextInputActive(); -} - -void ContextTriggerResize() -{ - return GetContext()->GetUiContext().TriggerResize(); -} - -void ContextSetFullscreenMode(int32_t mode) -{ - return GetContext()->GetUiContext().SetFullscreenMode(static_cast(mode)); -} - -void ContextRecreateWindow() -{ - GetContext()->GetUiContext().RecreateWindow(); -} - -int32_t ContextGetWidth() -{ - return GetContext()->GetUiContext().GetWidth(); -} - -int32_t ContextGetHeight() -{ - return GetContext()->GetUiContext().GetHeight(); -} - -bool ContextHasFocus() -{ - return GetContext()->GetUiContext().HasFocus(); -} - -void ContextSetCursorTrap(bool value) -{ - GetContext()->GetUiContext().SetCursorTrap(value); -} - -WindowBase* ContextOpenWindow(WindowClass wc) -{ - auto windowManager = Ui::GetWindowManager(); - return windowManager->OpenWindow(wc); -} - -WindowBase* ContextOpenWindowView(uint8_t wc) -{ - auto windowManager = Ui::GetWindowManager(); - return windowManager->OpenView(wc); -} - -WindowBase* ContextOpenDetailWindow(uint8_t type, int32_t id) -{ - auto windowManager = Ui::GetWindowManager(); - return windowManager->OpenDetails(type, id); -} - -WindowBase* ContextOpenIntent(Intent* intent) -{ - auto windowManager = Ui::GetWindowManager(); - return windowManager->OpenIntent(intent); -} - -void ContextBroadcastIntent(Intent* intent) -{ - auto windowManager = Ui::GetWindowManager(); - windowManager->BroadcastIntent(*intent); -} - -void ContextForceCloseWindowByClass(WindowClass windowClass) -{ - auto windowManager = Ui::GetWindowManager(); - windowManager->ForceClose(windowClass); -} - -WindowBase* ContextShowError(StringId title, StringId message, const Formatter& args, const bool autoClose /* = false */) -{ - auto windowManager = Ui::GetWindowManager(); - return windowManager->ShowError(title, message, args, autoClose); -} - -void ContextHandleInput() -{ - auto windowManager = Ui::GetWindowManager(); - windowManager->HandleInput(); -} - -void ContextInputHandleKeyboard(bool isTitle) -{ - auto windowManager = Ui::GetWindowManager(); - windowManager->HandleKeyboard(isTitle); -} - -void ContextQuit() -{ - GetContext()->Quit(); -} - -u8string ContextOpenCommonFileDialog(OpenRCT2::Ui::FileDialogDesc& desc) -{ - try - { - return GetContext()->GetUiContext().ShowFileDialog(desc); - } - catch (const std::exception& ex) - { - LOG_ERROR(ex.what()); - return u8string{}; - } -} diff --git a/src/openrct2/Context.h b/src/openrct2/Context.h index 316f35f3c0..81283020ce 100644 --- a/src/openrct2/Context.h +++ b/src/openrct2/Context.h @@ -17,68 +17,28 @@ #include -struct IScenarioRepository; -enum class DrawingEngine : int32_t; enum class CursorID : uint8_t; - -namespace OpenRCT2 -{ - class Formatter; - class Intent; - struct IObjectManager; - struct IObjectRepository; - struct IStream; - struct WindowBase; -} // namespace OpenRCT2 - -struct ITrackDesignRepository; +enum class DrawingEngine : int32_t; struct IGameStateSnapshots; - +struct IScenarioRepository; +struct ITrackDesignRepository; struct NewVersionInfo; - struct TTFFontDescriptor; -namespace OpenRCT2::Ui -{ - struct FileDialogDesc; -} - -struct CursorState -{ - ScreenCoordsXY position; - uint8_t left, middle, right, any; - int32_t wheel; - int32_t old; - bool touch, touchIsDouble; - uint32_t touchDownTimestamp; -}; - -struct TextInputSession -{ - u8string* Buffer; // UTF-8 string buffer, non-owning. - size_t Length; // Number of codepoints - size_t MaxLength; // Maximum length of text, Length can't be larger than this. - size_t SelectionStart; // Selection start, in bytes - size_t SelectionSize; // Selection length in bytes - - const utf8* ImeBuffer; // IME UTF-8 stream -}; - -enum -{ - CURSOR_UP = 0, - CURSOR_DOWN = 1, - CURSOR_CHANGED = 2, - CURSOR_RELEASED = CURSOR_UP | CURSOR_CHANGED, - CURSOR_PRESSED = CURSOR_DOWN | CURSOR_CHANGED, -}; namespace OpenRCT2 { class AssetPackManager; - + class Formatter; + class Intent; + struct CursorState; + struct IObjectManager; + struct IObjectRepository; struct IPlatformEnvironment; struct IReplayManager; struct IScene; + struct IStream; + struct TextInputSession; + struct WindowBase; namespace Audio { @@ -107,8 +67,9 @@ namespace OpenRCT2 namespace Ui { + struct FileDialogDesc; struct IUiContext; - } + } // namespace Ui namespace Paint { @@ -185,39 +146,39 @@ namespace OpenRCT2 std::unique_ptr&& env, std::unique_ptr&& audioContext, std::unique_ptr&& uiContext); [[nodiscard]] IContext* GetContext(); -} // namespace OpenRCT2 -void ContextInit(); -void ContextSetCurrentCursor(CursorID cursor); -void ContextUpdateCursorScale(); -void ContextHideCursor(); -void ContextShowCursor(); -ScreenCoordsXY ContextGetCursorPosition(); -ScreenCoordsXY ContextGetCursorPositionScaled(); -void ContextSetCursorPosition(const ScreenCoordsXY& cursorPosition); -const CursorState* ContextGetCursorState(); -const uint8_t* ContextGetKeysState(); -const uint8_t* ContextGetKeysPressed(); -TextInputSession* ContextStartTextInput(u8string& buffer, size_t maxLength); -void ContextStopTextInput(); -bool ContextIsInputActive(); -void ContextTriggerResize(); -void ContextSetFullscreenMode(int32_t mode); -void ContextRecreateWindow(); -int32_t ContextGetWidth(); -int32_t ContextGetHeight(); -bool ContextHasFocus(); -void ContextSetCursorTrap(bool value); -OpenRCT2::WindowBase* ContextOpenWindow(WindowClass wc); -OpenRCT2::WindowBase* ContextOpenDetailWindow(uint8_t type, int32_t id); -OpenRCT2::WindowBase* ContextOpenWindowView(uint8_t view); -OpenRCT2::WindowBase* ContextShowError( - StringId title, StringId message, const class OpenRCT2::Formatter& args, bool autoClose = false); -OpenRCT2::WindowBase* ContextOpenIntent(OpenRCT2::Intent* intent); -void ContextBroadcastIntent(OpenRCT2::Intent* intent); -void ContextForceCloseWindowByClass(WindowClass wc); -void ContextHandleInput(); -void ContextInputHandleKeyboard(bool isTitle); -void ContextQuit(); -bool ContextLoadParkFromStream(void* stream); -u8string ContextOpenCommonFileDialog(OpenRCT2::Ui::FileDialogDesc& desc); + void ContextInit(); + void ContextSetCurrentCursor(CursorID cursor); + void ContextUpdateCursorScale(); + void ContextHideCursor(); + void ContextShowCursor(); + ScreenCoordsXY ContextGetCursorPosition(); + ScreenCoordsXY ContextGetCursorPositionScaled(); + void ContextSetCursorPosition(const ScreenCoordsXY& cursorPosition); + const CursorState* ContextGetCursorState(); + const uint8_t* ContextGetKeysState(); + const uint8_t* ContextGetKeysPressed(); + TextInputSession* ContextStartTextInput(u8string& buffer, size_t maxLength); + void ContextStopTextInput(); + bool ContextIsInputActive(); + void ContextTriggerResize(); + void ContextSetFullscreenMode(int32_t mode); + void ContextRecreateWindow(); + int32_t ContextGetWidth(); + int32_t ContextGetHeight(); + bool ContextHasFocus(); + void ContextSetCursorTrap(bool value); + OpenRCT2::WindowBase* ContextOpenWindow(WindowClass wc); + OpenRCT2::WindowBase* ContextOpenDetailWindow(uint8_t type, int32_t id); + OpenRCT2::WindowBase* ContextOpenWindowView(uint8_t view); + OpenRCT2::WindowBase* ContextShowError( + StringId title, StringId message, const class OpenRCT2::Formatter& args, bool autoClose = false); + OpenRCT2::WindowBase* ContextOpenIntent(OpenRCT2::Intent* intent); + void ContextBroadcastIntent(OpenRCT2::Intent* intent); + void ContextForceCloseWindowByClass(WindowClass wc); + void ContextHandleInput(); + void ContextInputHandleKeyboard(bool isTitle); + void ContextQuit(); + bool ContextLoadParkFromStream(void* stream); + u8string ContextOpenCommonFileDialog(OpenRCT2::Ui::FileDialogDesc& desc); +} // namespace OpenRCT2 diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 351c5f74f6..fa5b6c8c25 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -736,7 +736,7 @@ void GameLoadOrQuitNoSavePrompt() default: GameUnloadScripts(); getGameState().entities.ResetAllEntities(); - OpenRCT2Finish(); + GetContext()->Finish(); break; } } diff --git a/src/openrct2/Input.h b/src/openrct2/Input.h index 624aa36482..7817c44478 100644 --- a/src/openrct2/Input.h +++ b/src/openrct2/Input.h @@ -10,6 +10,7 @@ #pragma once #include "core/FlagHolder.hpp" +#include "core/StringTypes.h" #include "interface/Window.h" namespace OpenRCT2 @@ -54,6 +55,36 @@ namespace OpenRCT2 ScrollRight }; + struct CursorState + { + ScreenCoordsXY position; + uint8_t left, middle, right, any; + int32_t wheel; + int32_t old; + bool touch, touchIsDouble; + uint32_t touchDownTimestamp; + }; + + struct TextInputSession + { + u8string* Buffer; // UTF-8 string buffer, non-owning. + size_t Length; // Number of codepoints + size_t MaxLength; // Maximum length of text, Length can't be larger than this. + size_t SelectionStart; // Selection start, in bytes + size_t SelectionSize; // Selection length in bytes + + const utf8* ImeBuffer; // IME UTF-8 stream + }; + + enum + { + CURSOR_UP = 0, + CURSOR_DOWN = 1, + CURSOR_CHANGED = 2, + CURSOR_RELEASED = CURSOR_UP | CURSOR_CHANGED, + CURSOR_PRESSED = CURSOR_DOWN | CURSOR_CHANGED, + }; + extern WidgetRef gHoverWidget; extern WidgetRef gPressedWidget; diff --git a/src/openrct2/OpenRCT2.h b/src/openrct2/OpenRCT2.h index f24ef8b3dc..1ff3a8df52 100644 --- a/src/openrct2/OpenRCT2.h +++ b/src/openrct2/OpenRCT2.h @@ -67,6 +67,4 @@ extern LegacyScene gLegacyScene; extern uint32_t gScreenAge; extern PromptMode gSavePromptMode; -void OpenRCT2Finish(); - int32_t CommandLineRun(const char** argv, int32_t argc); diff --git a/src/openrct2/interface/Chat.cpp b/src/openrct2/interface/Chat.cpp index b1ef77c9c7..09c99a88ef 100644 --- a/src/openrct2/interface/Chat.cpp +++ b/src/openrct2/interface/Chat.cpp @@ -10,6 +10,7 @@ #include "Chat.h" #include "../Context.h" +#include "../Input.h" #include "../audio/Audio.h" #include "../audio/AudioMixer.h" #include "../core/UTF8.h" diff --git a/src/openrct2/interface/InteractiveConsole.h b/src/openrct2/interface/InteractiveConsole.h index b83f429489..842c5a07b1 100644 --- a/src/openrct2/interface/InteractiveConsole.h +++ b/src/openrct2/interface/InteractiveConsole.h @@ -14,7 +14,6 @@ #include struct RenderTarget; -struct TextInputSession; enum class ConsoleInput : uint8_t { @@ -30,7 +29,8 @@ enum class ConsoleInput : uint8_t namespace OpenRCT2 { enum class FormatToken : uint8_t; -} + struct TextInputSession; +} // namespace OpenRCT2 class InteractiveConsole { diff --git a/src/openrct2/interface/StdInOutConsole.cpp b/src/openrct2/interface/StdInOutConsole.cpp index 0b0ef2b5b4..2a0b5ca3ff 100644 --- a/src/openrct2/interface/StdInOutConsole.cpp +++ b/src/openrct2/interface/StdInOutConsole.cpp @@ -57,7 +57,7 @@ void StdInOutConsole::Start() { if (lastPromptQuit) { - OpenRCT2Finish(); + GetContext()->Finish(); break; } @@ -115,7 +115,7 @@ void StdInOutConsole::Clear() void StdInOutConsole::Close() { - OpenRCT2Finish(); + GetContext()->Finish(); } void StdInOutConsole::WriteLine(const std::string& s, FormatToken colourFormat) diff --git a/src/openrct2/scenes/intro/IntroScene.cpp b/src/openrct2/scenes/intro/IntroScene.cpp index 73f005d41d..04b81dc5b0 100644 --- a/src/openrct2/scenes/intro/IntroScene.cpp +++ b/src/openrct2/scenes/intro/IntroScene.cpp @@ -10,6 +10,7 @@ #include "IntroScene.h" #include "../../Context.h" +#include "../../Input.h" #include "../../SpriteIds.h" #include "../../audio/Audio.h" #include "../../audio/AudioChannel.h" diff --git a/src/openrct2/ui/WindowManager.h b/src/openrct2/ui/WindowManager.h index 210d4087d6..e1c6f05744 100644 --- a/src/openrct2/ui/WindowManager.h +++ b/src/openrct2/ui/WindowManager.h @@ -35,9 +35,7 @@ namespace OpenRCT2::Ui virtual WindowBase* OpenDetails(uint8_t type, int32_t id) = 0; virtual WindowBase* OpenIntent(Intent* intent) = 0; virtual void BroadcastIntent(const Intent& intent) = 0; - virtual WindowBase* ShowError( - StringId title, StringId message, const OpenRCT2::Formatter& formatter, bool autoClose = false) - = 0; + virtual WindowBase* ShowError(StringId title, StringId message, const Formatter& formatter, bool autoClose = false) = 0; virtual WindowBase* ShowError(std::string_view title, std::string_view message, bool autoClose = false) = 0; virtual void ForceClose(WindowClass windowClass) = 0; virtual void UpdateMapTooltip() = 0;