1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-27 08:45:00 +01:00

Move Context fully into OpenRCT2 namespace; types into Input.h

This commit is contained in:
Aaron van Geffen
2025-09-12 14:03:44 +02:00
parent ffa2c3ab6c
commit 9b7ee06e0f
17 changed files with 283 additions and 293 deletions

View File

@@ -890,7 +890,7 @@ namespace OpenRCT2
auto windowManager = _uiContext->GetWindowManager();
auto ft = Formatter();
ft.Add<uint32_t>(result.TargetVersion);
ft.Add<uint32_t>(OpenRCT2::kParkFileCurrentVersion);
ft.Add<uint32_t>(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<uint32_t>(e.TargetVersion);
ft.Add<uint32_t>(OpenRCT2::kParkFileCurrentVersion);
ft.Add<uint32_t>(kParkFileCurrentVersion);
windowManager->ShowError(STR_ERROR_PARK_VERSION_TITLE, STR_ERROR_PARK_VERSION_TOO_NEW_MESSAGE_2, ft);
}
else
{
ft.Add<uint32_t>(e.TargetVersion);
ft.Add<uint32_t>(e.MinVersion);
ft.Add<uint32_t>(OpenRCT2::kParkFileCurrentVersion);
ft.Add<uint32_t>(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<IStream*>(stream), "");
}
void ContextSetCurrentCursor(CursorID cursor)
{
GetContext()->GetUiContext().SetCursor(cursor);
}
void ContextUpdateCursorScale()
{
GetContext()->GetUiContext().SetCursorScale(static_cast<uint8_t>(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<int32_t>(std::ceil(cursorCoords.x / Config::Get().general.WindowScale)),
static_cast<int32_t>(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<FullscreenMode>(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<IStream*>(stream), "");
}
void OpenRCT2Finish()
{
GetContext()->Finish();
}
void ContextSetCurrentCursor(CursorID cursor)
{
GetContext()->GetUiContext().SetCursor(cursor);
}
void ContextUpdateCursorScale()
{
GetContext()->GetUiContext().SetCursorScale(static_cast<uint8_t>(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<int32_t>(std::ceil(cursorCoords.x / Config::Get().general.WindowScale)),
static_cast<int32_t>(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<FullscreenMode>(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{};
}
}