diff --git a/src/openrct2-ui/CursorRepository.cpp b/src/openrct2-ui/CursorRepository.cpp index 301f256246..eb4261faf0 100644 --- a/src/openrct2-ui/CursorRepository.cpp +++ b/src/openrct2-ui/CursorRepository.cpp @@ -27,7 +27,7 @@ CursorRepository::~CursorRepository() void CursorRepository::LoadCursors() { - SetCursorScale(static_cast(round(gConfigGeneral.WindowScale))); + SetCursorScale(static_cast(round(Config::Get().general.WindowScale))); SetCurrentCursor(CursorID::Arrow); } diff --git a/src/openrct2-ui/UiContext.cpp b/src/openrct2-ui/UiContext.cpp index dd87767c91..96a183041b 100644 --- a/src/openrct2-ui/UiContext.cpp +++ b/src/openrct2-ui/UiContext.cpp @@ -189,12 +189,13 @@ public: // Set window size UpdateFullscreenResolutions(); - Resolution resolution = GetClosestResolution(gConfigGeneral.FullscreenWidth, gConfigGeneral.FullscreenHeight); + Resolution resolution = GetClosestResolution( + Config::Get().general.FullscreenWidth, Config::Get().general.FullscreenHeight); SDL_SetWindowSize(_window, resolution.Width, resolution.Height); } else if (mode == FULLSCREEN_MODE::WINDOWED) { - SDL_SetWindowSize(_window, gConfigGeneral.WindowWidth, gConfigGeneral.WindowHeight); + SDL_SetWindowSize(_window, Config::Get().general.WindowWidth, Config::Get().general.WindowHeight); } if (SDL_SetWindowFullscreen(_window, windowFlags)) @@ -355,16 +356,16 @@ public: { // Update default display index int32_t displayIndex = SDL_GetWindowDisplayIndex(_window); - if (displayIndex != gConfigGeneral.DefaultDisplay) + if (displayIndex != Config::Get().general.DefaultDisplay) { - gConfigGeneral.DefaultDisplay = displayIndex; - ConfigSaveDefault(); + Config::Get().general.DefaultDisplay = displayIndex; + Config::Save(); } break; } } - if (gConfigSound.audio_focus) + if (Config::Get().sound.audio_focus) { if (e.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) { @@ -377,8 +378,8 @@ public: } break; case SDL_MOUSEMOTION: - _cursorState.position = { static_cast(e.motion.x / gConfigGeneral.WindowScale), - static_cast(e.motion.y / gConfigGeneral.WindowScale) }; + _cursorState.position = { static_cast(e.motion.x / Config::Get().general.WindowScale), + static_cast(e.motion.y / Config::Get().general.WindowScale) }; break; case SDL_MOUSEWHEEL: if (_inGameConsole.IsOpen()) @@ -394,8 +395,8 @@ public: { break; } - ScreenCoordsXY mousePos = { static_cast(e.button.x / gConfigGeneral.WindowScale), - static_cast(e.button.y / gConfigGeneral.WindowScale) }; + ScreenCoordsXY mousePos = { static_cast(e.button.x / Config::Get().general.WindowScale), + static_cast(e.button.y / Config::Get().general.WindowScale) }; switch (e.button.button) { case SDL_BUTTON_LEFT: @@ -430,8 +431,8 @@ public: { break; } - ScreenCoordsXY mousePos = { static_cast(e.button.x / gConfigGeneral.WindowScale), - static_cast(e.button.y / gConfigGeneral.WindowScale) }; + ScreenCoordsXY mousePos = { static_cast(e.button.x / Config::Get().general.WindowScale), + static_cast(e.button.y / Config::Get().general.WindowScale) }; switch (e.button.button) { case SDL_BUTTON_LEFT: @@ -585,7 +586,7 @@ public: { char scaleQualityBuffer[4]; _scaleQuality = ScaleQuality::SmoothNearestNeighbour; - if (gConfigGeneral.WindowScale == std::floor(gConfigGeneral.WindowScale)) + if (Config::Get().general.WindowScale == std::floor(Config::Get().general.WindowScale)) { _scaleQuality = ScaleQuality::NearestNeighbour; } @@ -605,10 +606,10 @@ public: void CreateWindow() override { - SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, gConfigGeneral.MinimizeFullscreenFocusLoss ? "1" : "0"); + SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, Config::Get().general.MinimizeFullscreenFocusLoss ? "1" : "0"); // Set window position to default display - int32_t defaultDisplay = std::clamp(gConfigGeneral.DefaultDisplay, 0, 0xFFFF); + int32_t defaultDisplay = std::clamp(Config::Get().general.DefaultDisplay, 0, 0xFFFF); auto windowPos = ScreenCoordsXY{ static_cast(SDL_WINDOWPOS_UNDEFINED_DISPLAY(defaultDisplay)), static_cast(SDL_WINDOWPOS_UNDEFINED_DISPLAY(defaultDisplay)) }; @@ -733,8 +734,8 @@ private: void CreateWindow(const ScreenCoordsXY& windowPos) { // Get saved window size - int32_t width = gConfigGeneral.WindowWidth; - int32_t height = gConfigGeneral.WindowHeight; + int32_t width = Config::Get().general.WindowWidth; + int32_t height = Config::Get().general.WindowHeight; if (width <= 0) width = 640; if (height <= 0) @@ -742,7 +743,7 @@ private: // Create window in window first rather than fullscreen so we have the display the window is on first uint32_t flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI; - if (gConfigGeneral.DrawingEngine == DrawingEngine::OpenGL) + if (Config::Get().general.DrawingEngine == DrawingEngine::OpenGL) { flags |= SDL_WINDOW_OPENGL; } @@ -756,7 +757,7 @@ private: ApplyScreenSaverLockSetting(); SDL_SetWindowMinimumSize(_window, 720, 480); - SetCursorTrap(gConfigGeneral.TrapCursor); + SetCursorTrap(Config::Get().general.TrapCursor); _platformUiContext->SetWindowIcon(_window); // Initialise the surface, palette and draw buffer @@ -765,15 +766,15 @@ private: UpdateFullscreenResolutions(); - SetFullscreenMode(static_cast(gConfigGeneral.FullscreenMode)); + SetFullscreenMode(static_cast(Config::Get().general.FullscreenMode)); TriggerResize(); } void OnResize(int32_t width, int32_t height) { // Scale the native window size to the game's canvas size - _width = static_cast(width / gConfigGeneral.WindowScale); - _height = static_cast(height / gConfigGeneral.WindowScale); + _width = static_cast(width / Config::Get().general.WindowScale); + _height = static_cast(height / Config::Get().general.WindowScale); DrawingEngineResize(); @@ -795,11 +796,11 @@ private: if (!(flags & nonWindowFlags)) { - if (width != gConfigGeneral.WindowWidth || height != gConfigGeneral.WindowHeight) + if (width != Config::Get().general.WindowWidth || height != Config::Get().general.WindowHeight) { - gConfigGeneral.WindowWidth = width; - gConfigGeneral.WindowHeight = height; - ConfigSaveDefault(); + Config::Get().general.WindowWidth = width; + Config::Get().general.WindowHeight = height; + Config::Save(); } } } @@ -844,10 +845,11 @@ private: resolutions.erase(last, resolutions.end()); // Update config fullscreen resolution if not set - if (!resolutions.empty() && (gConfigGeneral.FullscreenWidth == -1 || gConfigGeneral.FullscreenHeight == -1)) + if (!resolutions.empty() + && (Config::Get().general.FullscreenWidth == -1 || Config::Get().general.FullscreenHeight == -1)) { - gConfigGeneral.FullscreenWidth = resolutions.back().Width; - gConfigGeneral.FullscreenHeight = resolutions.back().Height; + Config::Get().general.FullscreenWidth = resolutions.back().Width; + Config::Get().general.FullscreenHeight = resolutions.back().Height; } _fsResolutions = resolutions; diff --git a/src/openrct2-ui/WindowManager.cpp b/src/openrct2-ui/WindowManager.cpp index 3e5ed0baa4..34f8835da2 100644 --- a/src/openrct2-ui/WindowManager.cpp +++ b/src/openrct2-ui/WindowManager.cpp @@ -28,6 +28,7 @@ #include #include +using namespace OpenRCT2; using namespace OpenRCT2::Ui; using namespace OpenRCT2::Ui::Windows; @@ -161,7 +162,7 @@ public: case WV_FINANCES_RESEARCH: return FinancesResearchOpen(); case WV_RIDE_RESEARCH: - if (gConfigInterface.ToolbarShowResearch) + if (Config::Get().interface.ToolbarShowResearch) { return this->OpenWindow(WindowClass::Research); } diff --git a/src/openrct2-ui/audio/AudioMixer.cpp b/src/openrct2-ui/audio/AudioMixer.cpp index 7390610a13..6606f10616 100644 --- a/src/openrct2-ui/audio/AudioMixer.cpp +++ b/src/openrct2-ui/audio/AudioMixer.cpp @@ -146,8 +146,8 @@ void AudioMixer::GetNextAudioChunk(uint8_t* dst, size_t length) else { auto group = channel->GetGroup(); - if ((group != MixerGroup::Sound || gConfigSound.SoundEnabled) && gConfigSound.MasterSoundEnabled - && gConfigSound.MasterVolume != 0) + if ((group != MixerGroup::Sound || Config::Get().sound.SoundEnabled) && Config::Get().sound.MasterSoundEnabled + && Config::Get().sound.MasterVolume != 0) { MixChannel(channel.get(), dst, length); } @@ -159,14 +159,14 @@ void AudioMixer::GetNextAudioChunk(uint8_t* dst, size_t length) void AudioMixer::UpdateAdjustedSound() { // Did the volume level get changed? Recalculate level in this case. - if (_settingSoundVolume != gConfigSound.SoundVolume) + if (_settingSoundVolume != Config::Get().sound.SoundVolume) { - _settingSoundVolume = gConfigSound.SoundVolume; + _settingSoundVolume = Config::Get().sound.SoundVolume; _adjustSoundVolume = powf(static_cast(_settingSoundVolume) / 100.f, 10.f / 6.f); } - if (_settingMusicVolume != gConfigSound.AudioFocus) + if (_settingMusicVolume != Config::Get().sound.AudioFocus) { - _settingMusicVolume = gConfigSound.AudioFocus; + _settingMusicVolume = Config::Get().sound.AudioFocus; _adjustMusicVolume = powf(static_cast(_settingMusicVolume) / 100.f, 10.f / 6.f); } } @@ -297,7 +297,8 @@ void AudioMixer::ApplyPan(const IAudioChannel* channel, void* buffer, size_t len int32_t AudioMixer::ApplyVolume(const IAudioChannel* channel, void* buffer, size_t len) { float volumeAdjust = _volume; - volumeAdjust *= gConfigSound.MasterSoundEnabled ? (static_cast(gConfigSound.MasterVolume) / 100.0f) : 0.0f; + volumeAdjust *= Config::Get().sound.MasterSoundEnabled ? (static_cast(Config::Get().sound.MasterVolume) / 100.0f) + : 0.0f; switch (channel->GetGroup()) { diff --git a/src/openrct2-ui/drawing/engines/HardwareDisplayDrawingEngine.cpp b/src/openrct2-ui/drawing/engines/HardwareDisplayDrawingEngine.cpp index 0ecc219d76..a75e9d9819 100644 --- a/src/openrct2-ui/drawing/engines/HardwareDisplayDrawingEngine.cpp +++ b/src/openrct2-ui/drawing/engines/HardwareDisplayDrawingEngine.cpp @@ -141,7 +141,7 @@ public: SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, scaleQualityBuffer); - uint32_t scale = std::ceil(gConfigGeneral.WindowScale); + uint32_t scale = std::ceil(Config::Get().general.WindowScale); _scaledScreenTexture = SDL_CreateTexture( _sdlRenderer, pixelFormat, SDL_TEXTUREACCESS_TARGET, width * scale, height * scale); @@ -169,7 +169,7 @@ public: _paletteHWMapped[i] = SDL_MapRGB(_screenTextureFormat, palette[i].Red, palette[i].Green, palette[i].Blue); } - if (gConfigGeneral.EnableLightFx) + if (Config::Get().general.EnableLightFx) { auto& lightPalette = LightFXGetPalette(); for (int32_t i = 0; i < 256; i++) @@ -210,7 +210,7 @@ protected: private: void Display() { - if (gConfigGeneral.EnableLightFx) + if (Config::Get().general.EnableLightFx) { void* pixels; int32_t pitch; @@ -244,14 +244,14 @@ private: } bool isSteamOverlayActive = GetContext()->GetUiContext()->IsSteamOverlayActive(); - if (isSteamOverlayActive && gConfigGeneral.SteamOverlayPause) + if (isSteamOverlayActive && Config::Get().general.SteamOverlayPause) { OverlayPreRenderCheck(); } SDL_RenderPresent(_sdlRenderer); - if (isSteamOverlayActive && gConfigGeneral.SteamOverlayPause) + if (isSteamOverlayActive && Config::Get().general.SteamOverlayPause) { OverlayPostRenderCheck(); } @@ -343,8 +343,8 @@ private: void RenderDirtyVisuals() { - float scaleX = gConfigGeneral.WindowScale; - float scaleY = gConfigGeneral.WindowScale; + float scaleX = Config::Get().general.WindowScale; + float scaleY = Config::Get().general.WindowScale; SDL_SetRenderDrawBlendMode(_sdlRenderer, SDL_BLENDMODE_BLEND); for (uint32_t y = 0; y < _dirtyGrid.BlockRows; y++) diff --git a/src/openrct2-ui/drawing/engines/SoftwareDrawingEngine.cpp b/src/openrct2-ui/drawing/engines/SoftwareDrawingEngine.cpp index 998cfefbcd..7a943bce4a 100644 --- a/src/openrct2-ui/drawing/engines/SoftwareDrawingEngine.cpp +++ b/src/openrct2-ui/drawing/engines/SoftwareDrawingEngine.cpp @@ -126,7 +126,7 @@ private: // https://github.com/OpenRCT2/OpenRCT2/issues/21772 #if !defined(__APPLE__) // Copy the surface to the window - if (gConfigGeneral.WindowScale == 1 || gConfigGeneral.WindowScale <= 0) + if (Config::Get().general.WindowScale == 1 || Config::Get().general.WindowScale <= 0) { SDL_Surface* windowSurface = SDL_GetWindowSurface(_window); if (SDL_BlitSurface(_surface, nullptr, windowSurface, nullptr)) diff --git a/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp b/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp index fc83719683..dd9b2cad1b 100644 --- a/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp @@ -449,7 +449,7 @@ private: } if (GetContext()->GetUiContext()->GetScaleQuality() == ScaleQuality::SmoothNearestNeighbour) { - uint32_t scale = std::ceil(gConfigGeneral.WindowScale); + uint32_t scale = std::ceil(Config::Get().general.WindowScale); _smoothScaleFramebuffer = std::make_unique(_width * scale, _height * scale, false, false); } } diff --git a/src/openrct2-ui/input/InputManager.cpp b/src/openrct2-ui/input/InputManager.cpp index 95ce7d9f3d..eb8f71bc5c 100644 --- a/src/openrct2-ui/input/InputManager.cpp +++ b/src/openrct2-ui/input/InputManager.cpp @@ -120,7 +120,7 @@ void InputManager::HandleViewScrolling() InputScrollViewport(_viewScroll); // Mouse edge scrolling - if (gConfigGeneral.EdgeScrolling) + if (Config::Get().general.EdgeScrolling) { if (InputGetState() != InputState::Normal) return; @@ -155,7 +155,7 @@ void InputManager::HandleModifiers() } #endif - if (gConfigGeneral.VirtualFloorStyle != VirtualFloorStyles::Off) + if (Config::Get().general.VirtualFloorStyle != VirtualFloorStyles::Off) { if (gInputPlaceObjectModifier & (PLACE_OBJECT_MODIFIER_COPY_Z | PLACE_OBJECT_MODIFIER_SHIFT_Z)) VirtualFloorEnable(); diff --git a/src/openrct2-ui/input/MouseInput.cpp b/src/openrct2-ui/input/MouseInput.cpp index d3774fd69f..e2600212ed 100644 --- a/src/openrct2-ui/input/MouseInput.cpp +++ b/src/openrct2-ui/input/MouseInput.cpp @@ -33,6 +33,7 @@ #include #include +using namespace OpenRCT2; using namespace OpenRCT2::Ui::Windows; struct RCTMouseData @@ -221,8 +222,10 @@ static void InputScrollDragContinue(const ScreenCoordsXY& screenCoords, WindowBa WidgetScrollUpdateThumbs(*w, widgetIndex); WindowInvalidateByNumber(w->classification, w->number); - ScreenCoordsXY fixedCursorPosition = { static_cast(std::ceil(gInputDragLast.x * gConfigGeneral.WindowScale)), - static_cast(std::ceil(gInputDragLast.y * gConfigGeneral.WindowScale)) }; + ScreenCoordsXY fixedCursorPosition = { + static_cast(std::ceil(gInputDragLast.x * Config::Get().general.WindowScale)), + static_cast(std::ceil(gInputDragLast.y * Config::Get().general.WindowScale)) + }; ContextSetCursorPosition(fixedCursorPosition); } @@ -474,7 +477,7 @@ static void InputWindowPositionContinue( { int32_t snapProximity; - snapProximity = (w.flags & WF_NO_SNAPPING) ? 0 : gConfigGeneral.WindowSnapProximity; + snapProximity = (w.flags & WF_NO_SNAPPING) ? 0 : Config::Get().general.WindowSnapProximity; WindowMoveAndSnap(w, newScreenCoords - lastScreenCoords, snapProximity); } @@ -529,7 +532,7 @@ static void InputViewportDragBegin(WindowBase& w) _ticksSinceDragStart = gCurrentRealTimeTicks; auto cursorPosition = ContextGetCursorPosition(); gInputDragLast = cursorPosition; - if (!gConfigGeneral.InvertViewportDrag) + if (!Config::Get().general.InvertViewportDrag) { ContextHideCursor(); } @@ -577,7 +580,7 @@ static void InputViewportDragContinue() differentialCoords.x = (viewport->zoom + 1).ApplyTo(differentialCoords.x); differentialCoords.y = (viewport->zoom + 1).ApplyTo(differentialCoords.y); - if (gConfigGeneral.InvertViewportDrag) + if (Config::Get().general.InvertViewportDrag) { w->savedViewPos -= differentialCoords; } @@ -589,7 +592,7 @@ static void InputViewportDragContinue() } const CursorState* cursorState = ContextGetCursorState(); - if (cursorState->touch || gConfigGeneral.InvertViewportDrag) + if (cursorState->touch || Config::Get().general.InvertViewportDrag) { gInputDragLast = newDragCoords; } @@ -1675,7 +1678,7 @@ void InputScrollViewport(const ScreenCoordsXY& scrollScreenCoords) if (viewport == nullptr) return; - const int32_t speed = gConfigGeneral.EdgeScrollingSpeed; + const int32_t speed = Config::Get().general.EdgeScrollingSpeed; int32_t multiplier = viewport->zoom.ApplyTo(speed); int32_t dx = scrollScreenCoords.x * multiplier; diff --git a/src/openrct2-ui/input/Shortcuts.cpp b/src/openrct2-ui/input/Shortcuts.cpp index 8652a7d985..7724b43041 100644 --- a/src/openrct2-ui/input/Shortcuts.cpp +++ b/src/openrct2-ui/input/Shortcuts.cpp @@ -475,8 +475,8 @@ static void ShortcutOpenSceneryPicker() static void ShortcutScaleUp() { - gConfigGeneral.WindowScale += 0.25f; - ConfigSaveDefault(); + Config::Get().general.WindowScale += 0.25f; + Config::Save(); GfxInvalidateScreen(); ContextTriggerResize(); ContextUpdateCursorScale(); @@ -484,9 +484,9 @@ static void ShortcutScaleUp() static void ShortcutScaleDown() { - gConfigGeneral.WindowScale -= 0.25f; - gConfigGeneral.WindowScale = std::max(0.5f, gConfigGeneral.WindowScale); - ConfigSaveDefault(); + Config::Get().general.WindowScale -= 0.25f; + Config::Get().general.WindowScale = std::max(0.5f, Config::Get().general.WindowScale); + Config::Save(); GfxInvalidateScreen(); ContextTriggerResize(); ContextUpdateCursorScale(); @@ -634,7 +634,7 @@ static void ShortcutToggleConsole() { console.Toggle(); } - else if (gConfigGeneral.DebuggingTools && !ContextIsInputActive()) + else if (Config::Get().general.DebuggingTools && !ContextIsInputActive()) { WindowCancelTextbox(); console.Toggle(); @@ -741,8 +741,8 @@ static void ShortcutToggleTransparentWater() if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) return; - gConfigGeneral.TransparentWater ^= 1; - ConfigSaveDefault(); + Config::Get().general.TransparentWater ^= 1; + Config::Save(); GfxInvalidateScreen(); } @@ -826,7 +826,7 @@ void ShortcutManager::RegisterDefaultShortcuts() RegisterShortcut(ShortcutId::InterfaceOpenTransparencyOptions, STR_SHORTCUT_OPEN_TRANSPARENCY_OPTIONS, "CTRL+T", ShortcutOpenTransparencyWindow); RegisterShortcut(ShortcutId::InterfaceOpenCheats, STR_SHORTCUT_OPEN_CHEATS_WINDOW, "CTRL+ALT+C", ShortcutOpenCheatWindow); RegisterShortcut(ShortcutId::InterfaceOpenTileInspector, STR_SHORTCUT_OPEN_TILE_INSPECTOR, []() { - if (gConfigInterface.ToolbarShowCheats) + if (Config::Get().interface.ToolbarShowCheats) { OpenWindow(WindowClass::TileInspector); } diff --git a/src/openrct2-ui/interface/InGameConsole.cpp b/src/openrct2-ui/interface/InGameConsole.cpp index 4c412faaee..b2dc5ca6c6 100644 --- a/src/openrct2-ui/interface/InGameConsole.cpp +++ b/src/openrct2-ui/interface/InGameConsole.cpp @@ -23,13 +23,14 @@ #include #include +using namespace OpenRCT2; using namespace OpenRCT2::Ui; static InGameConsole _inGameConsole; static FontStyle InGameConsoleGetFontStyle() { - return (gConfigInterface.ConsoleSmallFont ? FontStyle::Small : FontStyle::Medium); + return (Config::Get().interface.ConsoleSmallFont ? FontStyle::Small : FontStyle::Medium); } static int32_t InGameConsoleGetLineHeight() diff --git a/src/openrct2-ui/interface/Theme.cpp b/src/openrct2-ui/interface/Theme.cpp index c57bfa333a..2ff3f86fe1 100644 --- a/src/openrct2-ui/interface/Theme.cpp +++ b/src/openrct2-ui/interface/Theme.cpp @@ -617,9 +617,9 @@ namespace ThemeManager ActiveAvailableThemeIndex = 1; bool configValid = false; - if (!gConfigInterface.CurrentThemePreset.empty()) + if (!Config::Get().interface.CurrentThemePreset.empty()) { - if (LoadThemeByConfigName(gConfigInterface.CurrentThemePreset.c_str())) + if (LoadThemeByConfigName(Config::Get().interface.CurrentThemePreset.c_str())) { configValid = true; } @@ -627,7 +627,7 @@ namespace ThemeManager if (!configValid) { - gConfigInterface.CurrentThemePreset = ThemeManagerGetAvailableThemeConfigName(1); + Config::Get().interface.CurrentThemePreset = ThemeManagerGetAvailableThemeConfigName(1); } } @@ -709,7 +709,7 @@ void ThemeManagerSetActiveAvailableTheme(size_t index) } } ThemeManager::ActiveAvailableThemeIndex = index; - gConfigInterface.CurrentThemePreset = ThemeManagerGetAvailableThemeConfigName(index); + Config::Get().interface.CurrentThemePreset = ThemeManagerGetAvailableThemeConfigName(index); ColourSchemeUpdateAll(); } @@ -854,7 +854,7 @@ void ThemeRename(const utf8* name) if (Path::Equals(newPath, ThemeManager::AvailableThemes[i].Path)) { ThemeManager::ActiveAvailableThemeIndex = i; - gConfigInterface.CurrentThemePreset = ThemeManagerGetAvailableThemeConfigName(1); + Config::Get().interface.CurrentThemePreset = ThemeManagerGetAvailableThemeConfigName(1); break; } } @@ -879,7 +879,7 @@ void ThemeDuplicate(const utf8* name) if (Path::Equals(newPath, ThemeManager::AvailableThemes[i].Path)) { ThemeManager::ActiveAvailableThemeIndex = i; - gConfigInterface.CurrentThemePreset = ThemeManagerGetAvailableThemeConfigName(i); + Config::Get().interface.CurrentThemePreset = ThemeManagerGetAvailableThemeConfigName(i); break; } } @@ -890,7 +890,7 @@ void ThemeDelete() File::Delete(ThemeManager::CurrentThemePath); ThemeManager::LoadTheme(const_cast(&PredefinedThemeRCT2)); ThemeManager::ActiveAvailableThemeIndex = 1; - gConfigInterface.CurrentThemePreset = ThemeManagerGetAvailableThemeConfigName(1); + Config::Get().interface.CurrentThemePreset = ThemeManagerGetAvailableThemeConfigName(1); } void ThemeManagerInitialise() diff --git a/src/openrct2-ui/interface/Widget.cpp b/src/openrct2-ui/interface/Widget.cpp index 4a7b3134cc..729c260976 100644 --- a/src/openrct2-ui/interface/Widget.cpp +++ b/src/openrct2-ui/interface/Widget.cpp @@ -22,6 +22,8 @@ #include #include +using namespace OpenRCT2; + static void WidgetFrameDraw(DrawPixelInfo& dpi, WindowBase& w, WidgetIndex widgetIndex); static void WidgetResizeDraw(DrawPixelInfo& dpi, WindowBase& w, WidgetIndex widgetIndex); static void WidgetButtonDraw(DrawPixelInfo& dpi, WindowBase& w, WidgetIndex widgetIndex); @@ -570,7 +572,7 @@ static void WidgetCaptionDraw(DrawPixelInfo& dpi, WindowBase& w, WidgetIndex wid width -= CloseButtonWidth; } topLeft.x += width / 2; - if (gConfigInterface.WindowButtonsOnTheLeft) + if (Config::Get().interface.WindowButtonsOnTheLeft) topLeft.x += CloseButtonWidth; DrawTextEllipsised( diff --git a/src/openrct2-ui/interface/Window.cpp b/src/openrct2-ui/interface/Window.cpp index edb04c2542..eb16115823 100644 --- a/src/openrct2-ui/interface/Window.cpp +++ b/src/openrct2-ui/interface/Window.cpp @@ -224,7 +224,7 @@ WindowBase* WindowCreate( // Check if there are any window slots left // include kWindowLimitReserved for items such as the main viewport and toolbars to not appear to be counted. - if (g_window_list.size() >= static_cast(gConfigGeneral.WindowLimit + kWindowLimitReserved)) + if (g_window_list.size() >= static_cast(Config::Get().general.WindowLimit + kWindowLimitReserved)) { // Close least recently used window for (auto& w : g_window_list) @@ -570,7 +570,7 @@ void WindowAllWheelInput() void ApplyScreenSaverLockSetting() { - gConfigGeneral.DisableScreensaver ? SDL_DisableScreenSaver() : SDL_EnableScreenSaver(); + Config::Get().general.DisableScreensaver ? SDL_DisableScreenSaver() : SDL_EnableScreenSaver(); } /** @@ -828,7 +828,7 @@ void WindowAlignTabs(WindowBase* w, WidgetIndex start_tab_id, WidgetIndex end_ta ScreenCoordsXY WindowGetViewportSoundIconPos(WindowBase& w) { - const uint8_t buttonOffset = (gConfigInterface.WindowButtonsOnTheLeft) ? CloseButtonWidth + 2 : 0; + const uint8_t buttonOffset = (Config::Get().interface.WindowButtonsOnTheLeft) ? CloseButtonWidth + 2 : 0; return w.windowPos + ScreenCoordsXY{ 2 + buttonOffset, 2 }; } diff --git a/src/openrct2-ui/windows/Banner.cpp b/src/openrct2-ui/windows/Banner.cpp index c454f7c4d6..5f951e9bb3 100644 --- a/src/openrct2-ui/windows/Banner.cpp +++ b/src/openrct2-ui/windows/Banner.cpp @@ -86,7 +86,7 @@ static Widget window_banner_widgets[] = { (viewportWidget->width()) - 1, (viewportWidget->height()) - 1, Focus(_bannerViewPos)); if (viewport != nullptr) - viewport->flags = gConfigGeneral.AlwaysShowGridlines ? VIEWPORT_FLAG_GRIDLINES : VIEWPORT_FLAG_NONE; + viewport->flags = Config::Get().general.AlwaysShowGridlines ? VIEWPORT_FLAG_GRIDLINES : VIEWPORT_FLAG_NONE; Invalidate(); } diff --git a/src/openrct2-ui/windows/CustomCurrency.cpp b/src/openrct2-ui/windows/CustomCurrency.cpp index c59a5fc3d2..e0201b9f70 100644 --- a/src/openrct2-ui/windows/CustomCurrency.cpp +++ b/src/openrct2-ui/windows/CustomCurrency.cpp @@ -73,16 +73,16 @@ static Widget window_custom_currency_widgets[] = { break; case WIDX_RATE_UP: CurrencyDescriptors[EnumValue(CurrencyType::Custom)].rate += 1; - gConfigGeneral.CustomCurrencyRate = CurrencyDescriptors[EnumValue(CurrencyType::Custom)].rate; - ConfigSaveDefault(); + Config::Get().general.CustomCurrencyRate = CurrencyDescriptors[EnumValue(CurrencyType::Custom)].rate; + Config::Save(); WindowInvalidateAll(); break; case WIDX_RATE_DOWN: if (CurrencyDescriptors[EnumValue(CurrencyType::Custom)].rate > 1) { CurrencyDescriptors[EnumValue(CurrencyType::Custom)].rate -= 1; - gConfigGeneral.CustomCurrencyRate = CurrencyDescriptors[EnumValue(CurrencyType::Custom)].rate; - ConfigSaveDefault(); + Config::Get().general.CustomCurrencyRate = CurrencyDescriptors[EnumValue(CurrencyType::Custom)].rate; + Config::Save(); WindowInvalidateAll(); } break; @@ -146,8 +146,8 @@ static Widget window_custom_currency_widgets[] = { CurrencyDescriptors[EnumValue(CurrencyType::Custom)].affix_unicode = CurrencyAffix::Suffix; } - gConfigGeneral.CustomCurrencyAffix = CurrencyDescriptors[EnumValue(CurrencyType::Custom)].affix_unicode; - ConfigSaveDefault(); + Config::Get().general.CustomCurrencyAffix = CurrencyDescriptors[EnumValue(CurrencyType::Custom)].affix_unicode; + Config::Save(); WindowInvalidateAll(); } @@ -167,9 +167,10 @@ static Widget window_custom_currency_widgets[] = { CurrencyDescriptors[EnumValue(CurrencyType::Custom)].symbol_unicode, std::string(text).c_str(), kCurrencySymbolMaxSize); - gConfigGeneral.CustomCurrencySymbol = CurrencyDescriptors[EnumValue(CurrencyType::Custom)].symbol_unicode; + Config::Get().general.CustomCurrencySymbol = CurrencyDescriptors[EnumValue(CurrencyType::Custom)] + .symbol_unicode; - ConfigSaveDefault(); + Config::Save(); WindowInvalidateAll(); break; @@ -179,8 +180,8 @@ static Widget window_custom_currency_widgets[] = { { rate = res.value(); CurrencyDescriptors[EnumValue(CurrencyType::Custom)].rate = rate; - gConfigGeneral.CustomCurrencyRate = CurrencyDescriptors[EnumValue(CurrencyType::Custom)].rate; - ConfigSaveDefault(); + Config::Get().general.CustomCurrencyRate = CurrencyDescriptors[EnumValue(CurrencyType::Custom)].rate; + Config::Save(); WindowInvalidateAll(); } break; diff --git a/src/openrct2-ui/windows/EditorObjectSelection.cpp b/src/openrct2-ui/windows/EditorObjectSelection.cpp index 3bcd0ce3e0..cd340d92b1 100644 --- a/src/openrct2-ui/windows/EditorObjectSelection.cpp +++ b/src/openrct2-ui/windows/EditorObjectSelection.cpp @@ -272,7 +272,7 @@ static std::vector _window_editor_object_selection_widgets = { widgets[WIDX_FILTER_TEXT_BOX].string = _filter_string; - _filter_flags = gConfigInterface.ObjectSelectionFilterFlags; + _filter_flags = Config::Get().interface.ObjectSelectionFilterFlags; std::fill_n(_filter_string, sizeof(_filter_string), 0x00); WindowInitScrollWidgets(*this); @@ -374,8 +374,8 @@ static std::vector _window_editor_object_selection_widgets = { break; case WIDX_FILTER_RIDE_TAB_ALL: _filter_flags |= FILTER_RIDES; - gConfigInterface.ObjectSelectionFilterFlags = _filter_flags; - ConfigSaveDefault(); + Config::Get().interface.ObjectSelectionFilterFlags = _filter_flags; + Config::Save(); FilterUpdateCounts(); VisibleListRefresh(); @@ -392,8 +392,8 @@ static std::vector _window_editor_object_selection_widgets = { case WIDX_FILTER_RIDE_TAB_STALL: _filter_flags &= ~FILTER_RIDES; _filter_flags |= (1 << (widgetIndex - WIDX_FILTER_RIDE_TAB_TRANSPORT + _numSourceGameItems)); - gConfigInterface.ObjectSelectionFilterFlags = _filter_flags; - ConfigSaveDefault(); + Config::Get().interface.ObjectSelectionFilterFlags = _filter_flags; + Config::Save(); FilterUpdateCounts(); VisibleListRefresh(); @@ -566,8 +566,8 @@ static std::vector _window_editor_object_selection_widgets = { { _filter_flags ^= (1 << dropdownIndex); } - gConfigInterface.ObjectSelectionFilterFlags = _filter_flags; - ConfigSaveDefault(); + Config::Get().interface.ObjectSelectionFilterFlags = _filter_flags; + Config::Save(); FilterUpdateCounts(); scrolls->v_top = 0; @@ -906,7 +906,7 @@ static std::vector _window_editor_object_selection_widgets = { } } - if (gConfigGeneral.DebuggingTools) + if (Config::Get().general.DebuggingTools) widgets[WIDX_RELOAD_OBJECT].type = WindowWidgetType::ImgBtn; else widgets[WIDX_RELOAD_OBJECT].type = WindowWidgetType::Empty; diff --git a/src/openrct2-ui/windows/GameBottomToolbar.cpp b/src/openrct2-ui/windows/GameBottomToolbar.cpp index cc5980e985..392a4b50d2 100644 --- a/src/openrct2-ui/windows/GameBottomToolbar.cpp +++ b/src/openrct2-ui/windows/GameBottomToolbar.cpp @@ -194,7 +194,7 @@ static Widget window_game_bottom_toolbar_widgets[] = = (gHoverWidget.window_classification == WindowClass::BottomToolbar && gHoverWidget.widget_index == WIDX_DATE ? COLOUR_WHITE : NOT_TRANSLUCENT(colours[0])); - StringId stringId = DateFormatStringFormatIds[gConfigGeneral.DateFormat]; + StringId stringId = DateFormatStringFormatIds[Config::Get().general.DateFormat]; auto ft = Formatter(); ft.Add(DateDayNames[day]); ft.Add(month); @@ -210,7 +210,7 @@ static Widget window_game_bottom_toolbar_widgets[] = int32_t temperature = OpenRCT2::GetGameState().ClimateCurrent.Temperature; StringId format = STR_CELSIUS_VALUE; - if (gConfigGeneral.TemperatureFormat == TemperatureUnit::Fahrenheit) + if (Config::Get().general.TemperatureFormat == TemperatureUnit::Fahrenheit) { temperature = ClimateCelsiusToFahrenheit(temperature); format = STR_FAHRENHEIT_VALUE; diff --git a/src/openrct2-ui/windows/Guest.cpp b/src/openrct2-ui/windows/Guest.cpp index 5e7f519637..66fd20e284 100644 --- a/src/openrct2-ui/windows/Guest.cpp +++ b/src/openrct2-ui/windows/Guest.cpp @@ -474,7 +474,7 @@ static_assert(_guestWindowPageWidgets.size() == WINDOW_GUEST_PAGE_COUNT); { newDisabledWidgets |= (1uLL << WIDX_TAB_4); // Disable finance tab if no money } - if (!gConfigGeneral.DebuggingTools) + if (!Config::Get().general.DebuggingTools) { newDisabledWidgets |= (1uLL << WIDX_TAB_7); // Disable debug tab when debug tools not turned on } @@ -1924,7 +1924,7 @@ static_assert(_guestWindowPageWidgets.size() == WINDOW_GUEST_PAGE_COUNT); if (window == nullptr) { int32_t windowWidth = 192; - if (gConfigGeneral.DebuggingTools) + if (Config::Get().general.DebuggingTools) windowWidth += TabWidth; window = WindowCreate(WindowClass::Peep, windowWidth, 157, WF_RESIZABLE); diff --git a/src/openrct2-ui/windows/LoadSave.cpp b/src/openrct2-ui/windows/LoadSave.cpp index f155f6773f..b846b238bb 100644 --- a/src/openrct2-ui/windows/LoadSave.cpp +++ b/src/openrct2-ui/windows/LoadSave.cpp @@ -117,7 +117,7 @@ static Widget window_loadsave_widgets[] = if (a.type != b.type) return a.type - b.type < 0; - switch (gConfigGeneral.LoadSaveSort) + switch (Config::Get().general.LoadSaveSort) { case Sort::NameAscending: return StrLogicalCmp(a.name.c_str(), b.name.c_str()) < 0; @@ -134,7 +134,7 @@ static Widget window_loadsave_widgets[] = static void SetAndSaveConfigPath(u8string& config_str, u8string_view path) { config_str = Path::GetDirectory(path); - ConfigSaveDefault(); + Config::Save(); } static bool IsValidPath(const char* path) @@ -152,16 +152,16 @@ static Widget window_loadsave_widgets[] = switch (type & 0x0E) { case LOADSAVETYPE_GAME: - return gConfigGeneral.LastSaveGameDirectory; + return Config::Get().general.LastSaveGameDirectory; case LOADSAVETYPE_LANDSCAPE: - return gConfigGeneral.LastSaveLandscapeDirectory; + return Config::Get().general.LastSaveLandscapeDirectory; case LOADSAVETYPE_SCENARIO: - return gConfigGeneral.LastSaveScenarioDirectory; + return Config::Get().general.LastSaveScenarioDirectory; case LOADSAVETYPE_TRACK: - return gConfigGeneral.LastSaveTrackDirectory; + return Config::Get().general.LastSaveTrackDirectory; default: return u8string(); @@ -270,7 +270,7 @@ static Widget window_loadsave_widgets[] = switch (_type & 0x0F) { case (LOADSAVETYPE_LOAD | LOADSAVETYPE_GAME): - SetAndSaveConfigPath(gConfigGeneral.LastSaveGameDirectory, pathBuffer); + SetAndSaveConfigPath(Config::Get().general.LastSaveGameDirectory, pathBuffer); if (OpenRCT2::GetContext()->LoadParkFromFile(pathBuffer)) { InvokeCallback(MODAL_RESULT_OK, pathBuffer); @@ -286,8 +286,8 @@ static Widget window_loadsave_widgets[] = break; case (LOADSAVETYPE_SAVE | LOADSAVETYPE_GAME): - SetAndSaveConfigPath(gConfigGeneral.LastSaveGameDirectory, pathBuffer); - if (ScenarioSave(gameState, pathBuffer, gConfigGeneral.SavePluginData ? 1 : 0)) + SetAndSaveConfigPath(Config::Get().general.LastSaveGameDirectory, pathBuffer); + if (ScenarioSave(gameState, pathBuffer, Config::Get().general.SavePluginData ? 1 : 0)) { gScenarioSavePath = pathBuffer; gCurrentLoadedPath = pathBuffer; @@ -307,7 +307,7 @@ static Widget window_loadsave_widgets[] = break; case (LOADSAVETYPE_LOAD | LOADSAVETYPE_LANDSCAPE): - SetAndSaveConfigPath(gConfigGeneral.LastSaveLandscapeDirectory, pathBuffer); + SetAndSaveConfigPath(Config::Get().general.LastSaveLandscapeDirectory, pathBuffer); if (Editor::LoadLandscape(pathBuffer)) { gCurrentLoadedPath = pathBuffer; @@ -323,9 +323,9 @@ static Widget window_loadsave_widgets[] = break; case (LOADSAVETYPE_SAVE | LOADSAVETYPE_LANDSCAPE): - SetAndSaveConfigPath(gConfigGeneral.LastSaveLandscapeDirectory, pathBuffer); + SetAndSaveConfigPath(Config::Get().general.LastSaveLandscapeDirectory, pathBuffer); gScenarioFileName = std::string(String::ToStringView(pathBuffer, std::size(pathBuffer))); - if (ScenarioSave(gameState, pathBuffer, gConfigGeneral.SavePluginData ? 3 : 2)) + if (ScenarioSave(gameState, pathBuffer, Config::Get().general.SavePluginData ? 3 : 2)) { gCurrentLoadedPath = pathBuffer; WindowCloseByClass(WindowClass::Loadsave); @@ -341,12 +341,12 @@ static Widget window_loadsave_widgets[] = case (LOADSAVETYPE_SAVE | LOADSAVETYPE_SCENARIO): { - SetAndSaveConfigPath(gConfigGeneral.LastSaveScenarioDirectory, pathBuffer); + SetAndSaveConfigPath(Config::Get().general.LastSaveScenarioDirectory, pathBuffer); int32_t parkFlagsBackup = gameState.Park.Flags; gameState.Park.Flags &= ~PARK_FLAGS_SPRITES_INITIALISED; gameState.EditorStep = EditorStep::Invalid; gScenarioFileName = std::string(String::ToStringView(pathBuffer, std::size(pathBuffer))); - int32_t success = ScenarioSave(gameState, pathBuffer, gConfigGeneral.SavePluginData ? 3 : 2); + int32_t success = ScenarioSave(gameState, pathBuffer, Config::Get().general.SavePluginData ? 3 : 2); gameState.Park.Flags = parkFlagsBackup; if (success) @@ -368,7 +368,7 @@ static Widget window_loadsave_widgets[] = case (LOADSAVETYPE_LOAD | LOADSAVETYPE_TRACK): { - SetAndSaveConfigPath(gConfigGeneral.LastSaveTrackDirectory, pathBuffer); + SetAndSaveConfigPath(Config::Get().general.LastSaveTrackDirectory, pathBuffer); auto intent = Intent(WindowClass::InstallTrack); intent.PutExtra(INTENT_EXTRA_PATH, std::string{ pathBuffer }); ContextOpenIntent(&intent); @@ -379,7 +379,7 @@ static Widget window_loadsave_widgets[] = case (LOADSAVETYPE_SAVE | LOADSAVETYPE_TRACK): { - SetAndSaveConfigPath(gConfigGeneral.LastSaveTrackDirectory, pathBuffer); + SetAndSaveConfigPath(Config::Get().general.LastSaveTrackDirectory, pathBuffer); const auto withExtension = Path::WithExtension(pathBuffer, ".td6"); String::Set(pathBuffer, sizeof(pathBuffer), withExtension.c_str()); @@ -748,9 +748,9 @@ static Widget window_loadsave_widgets[] = // Name button text StringId id = STR_NONE; - if (gConfigGeneral.LoadSaveSort == Sort::NameAscending) + if (Config::Get().general.LoadSaveSort == Sort::NameAscending) id = STR_UP; - else if (gConfigGeneral.LoadSaveSort == Sort::NameDescending) + else if (Config::Get().general.LoadSaveSort == Sort::NameDescending) id = STR_DOWN; // Draw name button indicator. @@ -762,9 +762,9 @@ static Widget window_loadsave_widgets[] = { COLOUR_GREY }); // Date button text - if (gConfigGeneral.LoadSaveSort == Sort::DateAscending) + if (Config::Get().general.LoadSaveSort == Sort::DateAscending) id = STR_UP; - else if (gConfigGeneral.LoadSaveSort == Sort::DateDescending) + else if (Config::Get().general.LoadSaveSort == Sort::DateDescending) id = STR_DOWN; else id = STR_NONE; @@ -820,29 +820,29 @@ static Widget window_loadsave_widgets[] = break; case WIDX_SORT_NAME: - if (gConfigGeneral.LoadSaveSort == Sort::NameAscending) + if (Config::Get().general.LoadSaveSort == Sort::NameAscending) { - gConfigGeneral.LoadSaveSort = Sort::NameDescending; + Config::Get().general.LoadSaveSort = Sort::NameDescending; } else { - gConfigGeneral.LoadSaveSort = Sort::NameAscending; + Config::Get().general.LoadSaveSort = Sort::NameAscending; } - ConfigSaveDefault(); + Config::Save(); SortList(); Invalidate(); break; case WIDX_SORT_DATE: - if (gConfigGeneral.LoadSaveSort == Sort::DateDescending) + if (Config::Get().general.LoadSaveSort == Sort::DateDescending) { - gConfigGeneral.LoadSaveSort = Sort::DateAscending; + Config::Get().general.LoadSaveSort = Sort::DateAscending; } else { - gConfigGeneral.LoadSaveSort = Sort::DateDescending; + Config::Get().general.LoadSaveSort = Sort::DateDescending; } - ConfigSaveDefault(); + Config::Save(); SortList(); Invalidate(); break; @@ -1027,7 +1027,7 @@ static Widget window_loadsave_widgets[] = // Bypass the lot? auto hasFilePicker = OpenRCT2::GetContext()->GetUiContext()->HasFilePicker(); - if (gConfigGeneral.UseNativeBrowseDialog && hasFilePicker) + if (Config::Get().general.UseNativeBrowseDialog && hasFilePicker) { const u8string path = OpenSystemFileBrowser(isSave); if (!path.empty()) diff --git a/src/openrct2-ui/windows/Main.cpp b/src/openrct2-ui/windows/Main.cpp index ad1a749eee..35cbf27f5c 100644 --- a/src/openrct2-ui/windows/Main.cpp +++ b/src/openrct2-ui/windows/Main.cpp @@ -54,17 +54,17 @@ static Widget _mainWidgets[] = { void SetViewportFlags() { viewport->flags |= VIEWPORT_FLAG_SOUND_ON; - if (gConfigGeneral.InvisibleRides) + if (Config::Get().general.InvisibleRides) viewport->flags |= VIEWPORT_FLAG_INVISIBLE_RIDES; - if (gConfigGeneral.InvisibleVehicles) + if (Config::Get().general.InvisibleVehicles) viewport->flags |= VIEWPORT_FLAG_INVISIBLE_VEHICLES; - if (gConfigGeneral.InvisibleTrees) + if (Config::Get().general.InvisibleTrees) viewport->flags |= VIEWPORT_FLAG_INVISIBLE_VEGETATION; - if (gConfigGeneral.InvisibleScenery) + if (Config::Get().general.InvisibleScenery) viewport->flags |= VIEWPORT_FLAG_INVISIBLE_SCENERY; - if (gConfigGeneral.InvisiblePaths) + if (Config::Get().general.InvisiblePaths) viewport->flags |= VIEWPORT_FLAG_INVISIBLE_PATHS; - if (gConfigGeneral.InvisibleSupports) + if (Config::Get().general.InvisibleSupports) viewport->flags |= VIEWPORT_FLAG_INVISIBLE_SUPPORTS; } }; diff --git a/src/openrct2-ui/windows/Multiplayer.cpp b/src/openrct2-ui/windows/Multiplayer.cpp index ba69f6c8b5..875f13ce1a 100644 --- a/src/openrct2-ui/windows/Multiplayer.cpp +++ b/src/openrct2-ui/windows/Multiplayer.cpp @@ -137,7 +137,7 @@ static constexpr StringId WindowMultiplayerPageTitles[] = { static bool IsServerPlayerInvisible() { - return NetworkIsServerPlayerInvisible() && !gConfigGeneral.DebuggingTools; + return NetworkIsServerPlayerInvisible() && !Config::Get().general.DebuggingTools; } class MultiplayerWindow final : public Window @@ -272,16 +272,16 @@ static constexpr StringId WindowMultiplayerPageTitles[] = { switch (widgetIndex) { case WIDX_LOG_CHAT_CHECKBOX: - gConfigNetwork.LogChat = !gConfigNetwork.LogChat; - ConfigSaveDefault(); + Config::Get().network.LogChat = !Config::Get().network.LogChat; + Config::Save(); break; case WIDX_LOG_SERVER_ACTIONS_CHECKBOX: - gConfigNetwork.LogServerActions = !gConfigNetwork.LogServerActions; - ConfigSaveDefault(); + Config::Get().network.LogServerActions = !Config::Get().network.LogServerActions; + Config::Save(); break; case WIDX_KNOWN_KEYS_ONLY_CHECKBOX: - gConfigNetwork.KnownKeysOnly = !gConfigNetwork.KnownKeysOnly; - ConfigSaveDefault(); + Config::Get().network.KnownKeysOnly = !Config::Get().network.KnownKeysOnly; + Config::Save(); break; } break; @@ -430,9 +430,9 @@ static constexpr StringId WindowMultiplayerPageTitles[] = { widgets[WIDX_KNOWN_KEYS_ONLY_CHECKBOX].type = WindowWidgetType::Empty; } - SetCheckboxValue(WIDX_LOG_CHAT_CHECKBOX, gConfigNetwork.LogChat); - SetCheckboxValue(WIDX_LOG_SERVER_ACTIONS_CHECKBOX, gConfigNetwork.LogServerActions); - SetCheckboxValue(WIDX_KNOWN_KEYS_ONLY_CHECKBOX, gConfigNetwork.KnownKeysOnly); + SetCheckboxValue(WIDX_LOG_CHAT_CHECKBOX, Config::Get().network.LogChat); + SetCheckboxValue(WIDX_LOG_SERVER_ACTIONS_CHECKBOX, Config::Get().network.LogServerActions); + SetCheckboxValue(WIDX_KNOWN_KEYS_ONLY_CHECKBOX, Config::Get().network.KnownKeysOnly); break; } } diff --git a/src/openrct2-ui/windows/NewRide.cpp b/src/openrct2-ui/windows/NewRide.cpp index 5d2bfd2cfb..915e91ccd5 100644 --- a/src/openrct2-ui/windows/NewRide.cpp +++ b/src/openrct2-ui/windows/NewRide.cpp @@ -364,8 +364,8 @@ static Widget window_new_ride_widgets[] = { ContextOpenWindowView(WV_FINANCES_RESEARCH); break; case WIDX_GROUP_BY_TRACK_TYPE: - gConfigInterface.ListRideVehiclesSeparately = !gConfigInterface.ListRideVehiclesSeparately; - ConfigSaveDefault(); + Config::Get().interface.ListRideVehiclesSeparately = !Config::Get().interface.ListRideVehiclesSeparately; + Config::Save(); SetPage(_currentTab); break; case WIDX_FILTER_TEXT_BOX: @@ -391,7 +391,7 @@ static Widget window_new_ride_widgets[] = { { SetPressedTab(); - if (!gConfigInterface.ListRideVehiclesSeparately) + if (!Config::Get().interface.ListRideVehiclesSeparately) pressed_widgets |= (1LL << WIDX_GROUP_BY_TRACK_TYPE); else pressed_widgets &= ~(1LL << WIDX_GROUP_BY_TRACK_TYPE); @@ -684,7 +684,7 @@ static Widget window_new_ride_widgets[] = { const auto* rideEntry = GetRideEntryByIndex(rideEntryIndex); // Skip if the vehicle isn't the preferred vehicle for this generic track type - if (!gConfigInterface.ListRideVehiclesSeparately + if (!Config::Get().interface.ListRideVehiclesSeparately && !GetRideTypeDescriptor(rideType).HasFlag(RIDE_TYPE_FLAG_LIST_VEHICLES_SEPARATELY) && highestVehiclePriority > rideEntry->BuildMenuPriority) { @@ -699,7 +699,7 @@ static Widget window_new_ride_widgets[] = { highestVehiclePriority = rideEntry->BuildMenuPriority; // Determines how and where to draw a button for this ride type/vehicle. - if (gConfigInterface.ListRideVehiclesSeparately + if (Config::Get().interface.ListRideVehiclesSeparately || GetRideTypeDescriptor(rideType).HasFlag(RIDE_TYPE_FLAG_LIST_VEHICLES_SEPARATELY)) { // Separate, draw apart @@ -931,7 +931,7 @@ static Widget window_new_ride_widgets[] = { if (!_vehicleAvailability.empty()) { - if (gConfigInterface.ListRideVehiclesSeparately) + if (Config::Get().interface.ListRideVehiclesSeparately) { ft = Formatter(); ft.Add(rideEntry->naming.Name); diff --git a/src/openrct2-ui/windows/NewsOptions.cpp b/src/openrct2-ui/windows/NewsOptions.cpp index 91658f2599..d3e81e2c18 100644 --- a/src/openrct2-ui/windows/NewsOptions.cpp +++ b/src/openrct2-ui/windows/NewsOptions.cpp @@ -37,24 +37,24 @@ struct NotificationDef }; static constexpr NotificationDef NewsItemOptionDefinitions[] = { - { NOTIFICATION_CATEGORY_PARK, STR_NOTIFICATION_PARK_AWARD, offsetof(NotificationConfiguration, ParkAward) }, - { NOTIFICATION_CATEGORY_PARK, STR_NOTIFICATION_PARK_MARKETING_CAMPAIGN_FINISHED, offsetof(NotificationConfiguration, ParkMarketingCampaignFinished) }, - { NOTIFICATION_CATEGORY_PARK, STR_NOTIFICATION_PARK_WARNINGS, offsetof(NotificationConfiguration, ParkWarnings) }, - { NOTIFICATION_CATEGORY_PARK, STR_NOTIFICATION_PARK_RATING_WARNINGS, offsetof(NotificationConfiguration, ParkRatingWarnings) }, - { NOTIFICATION_CATEGORY_RIDE, STR_NOTIFICATION_RIDE_BROKEN_DOWN, offsetof(NotificationConfiguration, RideBrokenDown) }, - { NOTIFICATION_CATEGORY_RIDE, STR_NOTIFICATION_RIDE_CRASHED, offsetof(NotificationConfiguration, RideCrashed) }, - { NOTIFICATION_CATEGORY_RIDE, STR_NOTIFICATION_RIDE_CASUALTIES, offsetof(NotificationConfiguration, RideCasualties) }, - { NOTIFICATION_CATEGORY_RIDE, STR_NOTIFICATION_RIDE_WARNINGS, offsetof(NotificationConfiguration, RideWarnings) }, - { NOTIFICATION_CATEGORY_RIDE, STR_NOTIFICATION_RIDE_RESEARCHED, offsetof(NotificationConfiguration, RideResearched) }, - { NOTIFICATION_CATEGORY_RIDE, STR_NOTIFICATION_RIDE_VEHICLE_STALLED, offsetof(NotificationConfiguration, RideStalledVehicles) }, - { NOTIFICATION_CATEGORY_GUEST, STR_NOTIFICATION_GUEST_WARNINGS, offsetof(NotificationConfiguration, GuestWarnings) }, - { NOTIFICATION_CATEGORY_GUEST, STR_NOTIFICATION_GUEST_LEFT_PARK, offsetof(NotificationConfiguration, GuestLeftPark) }, - { NOTIFICATION_CATEGORY_GUEST, STR_NOTIFICATION_GUEST_QUEUING_FOR_RIDE, offsetof(NotificationConfiguration, GuestQueuingForRide) }, - { NOTIFICATION_CATEGORY_GUEST, STR_NOTIFICATION_GUEST_ON_RIDE, offsetof(NotificationConfiguration, GuestOnRide) }, - { NOTIFICATION_CATEGORY_GUEST, STR_NOTIFICATION_GUEST_LEFT_RIDE, offsetof(NotificationConfiguration, GuestLeftRide) }, - { NOTIFICATION_CATEGORY_GUEST, STR_NOTIFICATION_GUEST_BOUGHT_ITEM, offsetof(NotificationConfiguration, GuestBoughtItem) }, - { NOTIFICATION_CATEGORY_GUEST, STR_NOTIFICATION_GUEST_USED_FACILITY, offsetof(NotificationConfiguration, GuestUsedFacility) }, - { NOTIFICATION_CATEGORY_GUEST, STR_NOTIFICATION_GUEST_DIED, offsetof(NotificationConfiguration, GuestDied) }, + { NOTIFICATION_CATEGORY_PARK, STR_NOTIFICATION_PARK_AWARD, offsetof(Config::Notification, ParkAward) }, + { NOTIFICATION_CATEGORY_PARK, STR_NOTIFICATION_PARK_MARKETING_CAMPAIGN_FINISHED, offsetof(Config::Notification, ParkMarketingCampaignFinished) }, + { NOTIFICATION_CATEGORY_PARK, STR_NOTIFICATION_PARK_WARNINGS, offsetof(Config::Notification, ParkWarnings) }, + { NOTIFICATION_CATEGORY_PARK, STR_NOTIFICATION_PARK_RATING_WARNINGS, offsetof(Config::Notification, ParkRatingWarnings) }, + { NOTIFICATION_CATEGORY_RIDE, STR_NOTIFICATION_RIDE_BROKEN_DOWN, offsetof(Config::Notification, RideBrokenDown) }, + { NOTIFICATION_CATEGORY_RIDE, STR_NOTIFICATION_RIDE_CRASHED, offsetof(Config::Notification, RideCrashed) }, + { NOTIFICATION_CATEGORY_RIDE, STR_NOTIFICATION_RIDE_CASUALTIES, offsetof(Config::Notification, RideCasualties) }, + { NOTIFICATION_CATEGORY_RIDE, STR_NOTIFICATION_RIDE_WARNINGS, offsetof(Config::Notification, RideWarnings) }, + { NOTIFICATION_CATEGORY_RIDE, STR_NOTIFICATION_RIDE_RESEARCHED, offsetof(Config::Notification, RideResearched) }, + { NOTIFICATION_CATEGORY_RIDE, STR_NOTIFICATION_RIDE_VEHICLE_STALLED, offsetof(Config::Notification, RideStalledVehicles) }, + { NOTIFICATION_CATEGORY_GUEST, STR_NOTIFICATION_GUEST_WARNINGS, offsetof(Config::Notification, GuestWarnings) }, + { NOTIFICATION_CATEGORY_GUEST, STR_NOTIFICATION_GUEST_LEFT_PARK, offsetof(Config::Notification, GuestLeftPark) }, + { NOTIFICATION_CATEGORY_GUEST, STR_NOTIFICATION_GUEST_QUEUING_FOR_RIDE, offsetof(Config::Notification, GuestQueuingForRide) }, + { NOTIFICATION_CATEGORY_GUEST, STR_NOTIFICATION_GUEST_ON_RIDE, offsetof(Config::Notification, GuestOnRide) }, + { NOTIFICATION_CATEGORY_GUEST, STR_NOTIFICATION_GUEST_LEFT_RIDE, offsetof(Config::Notification, GuestLeftRide) }, + { NOTIFICATION_CATEGORY_GUEST, STR_NOTIFICATION_GUEST_BOUGHT_ITEM, offsetof(Config::Notification, GuestBoughtItem) }, + { NOTIFICATION_CATEGORY_GUEST, STR_NOTIFICATION_GUEST_USED_FACILITY, offsetof(Config::Notification, GuestUsedFacility) }, + { NOTIFICATION_CATEGORY_GUEST, STR_NOTIFICATION_GUEST_DIED, offsetof(Config::Notification, GuestDied) }, }; enum WindowNewsOptionsWidgetIdx @@ -131,7 +131,7 @@ static Widget WindowNewsOptionsWidgets[] = { bool* configValue = GetNotificationValuePtr(ndef); *configValue = !(*configValue); - ConfigSaveDefault(); + Config::Save(); InvalidateWidget(widgetIndex); break; @@ -257,7 +257,8 @@ static Widget WindowNewsOptionsWidgets[] = { bool* GetNotificationValuePtr(const NotificationDef* ndef) { - bool* configValue = reinterpret_cast(reinterpret_cast(&gConfigNotifications) + ndef->config_offset); + bool* configValue = reinterpret_cast( + reinterpret_cast(&Config::Get().notifications) + ndef->config_offset); return configValue; } diff --git a/src/openrct2-ui/windows/Options.cpp b/src/openrct2-ui/windows/Options.cpp index 5ca8942e7e..6a01166012 100644 --- a/src/openrct2-ui/windows/Options.cpp +++ b/src/openrct2-ui/windows/Options.cpp @@ -690,42 +690,42 @@ static Widget *window_options_page_widgets[] = { switch (widgetIndex) { case WIDX_UNCAP_FPS_CHECKBOX: - gConfigGeneral.UncapFPS ^= 1; - DrawingEngineSetVSync(gConfigGeneral.UseVSync); - ConfigSaveDefault(); + Config::Get().general.UncapFPS ^= 1; + DrawingEngineSetVSync(Config::Get().general.UseVSync); + Config::Save(); Invalidate(); break; case WIDX_USE_VSYNC_CHECKBOX: - gConfigGeneral.UseVSync ^= 1; - DrawingEngineSetVSync(gConfigGeneral.UseVSync); - ConfigSaveDefault(); + Config::Get().general.UseVSync ^= 1; + DrawingEngineSetVSync(Config::Get().general.UseVSync); + Config::Save(); Invalidate(); break; case WIDX_SHOW_FPS_CHECKBOX: - gConfigGeneral.ShowFPS ^= 1; - ConfigSaveDefault(); + Config::Get().general.ShowFPS ^= 1; + Config::Save(); Invalidate(); break; case WIDX_MULTITHREADING_CHECKBOX: - gConfigGeneral.MultiThreading ^= 1; - ConfigSaveDefault(); + Config::Get().general.MultiThreading ^= 1; + Config::Save(); Invalidate(); break; case WIDX_MINIMIZE_FOCUS_LOSS: - gConfigGeneral.MinimizeFullscreenFocusLoss ^= 1; + Config::Get().general.MinimizeFullscreenFocusLoss ^= 1; RefreshVideo(false); - ConfigSaveDefault(); + Config::Save(); Invalidate(); break; case WIDX_STEAM_OVERLAY_PAUSE: - gConfigGeneral.SteamOverlayPause ^= 1; - ConfigSaveDefault(); + Config::Get().general.SteamOverlayPause ^= 1; + Config::Save(); Invalidate(); break; case WIDX_DISABLE_SCREENSAVER_LOCK: - gConfigGeneral.DisableScreensaver ^= 1; + Config::Get().general.DisableScreensaver ^= 1; ApplyScreenSaverLockSetting(); - ConfigSaveDefault(); + Config::Save(); Invalidate(); break; } @@ -753,8 +753,8 @@ static Widget *window_options_page_widgets[] = { args[1] = resolution.Width; args[2] = resolution.Height; - if (resolution.Width == gConfigGeneral.FullscreenWidth - && resolution.Height == gConfigGeneral.FullscreenHeight) + if (resolution.Width == Config::Get().general.FullscreenWidth + && resolution.Height == Config::Get().general.FullscreenHeight) { selectedResolution = static_cast(i); } @@ -779,7 +779,7 @@ static Widget *window_options_page_widgets[] = { ShowDropdown(widget, 3); - Dropdown::SetChecked(gConfigGeneral.FullscreenMode, true); + Dropdown::SetChecked(Config::Get().general.FullscreenMode, true); break; case WIDX_DRAWING_ENGINE_DROPDOWN: { @@ -794,20 +794,20 @@ static Widget *window_options_page_widgets[] = { gDropdownItems[i].Args = DrawingEngineStringIds[i]; } ShowDropdown(widget, numItems); - Dropdown::SetChecked(EnumValue(gConfigGeneral.DrawingEngine), true); + Dropdown::SetChecked(EnumValue(Config::Get().general.DrawingEngine), true); break; } case WIDX_SCALE_UP: - gConfigGeneral.WindowScale += 0.25f; - ConfigSaveDefault(); + Config::Get().general.WindowScale += 0.25f; + Config::Save(); GfxInvalidateScreen(); ContextTriggerResize(); ContextUpdateCursorScale(); break; case WIDX_SCALE_DOWN: - gConfigGeneral.WindowScale -= 0.25f; - gConfigGeneral.WindowScale = std::max(0.5f, gConfigGeneral.WindowScale); - ConfigSaveDefault(); + Config::Get().general.WindowScale -= 0.25f; + Config::Get().general.WindowScale = std::max(0.5f, Config::Get().general.WindowScale); + Config::Save(); GfxInvalidateScreen(); ContextTriggerResize(); ContextUpdateCursorScale(); @@ -824,40 +824,41 @@ static Widget *window_options_page_widgets[] = { const auto& resolutions = OpenRCT2::GetContext()->GetUiContext()->GetFullscreenResolutions(); const Resolution& resolution = resolutions[dropdownIndex]; - if (resolution.Width != gConfigGeneral.FullscreenWidth - || resolution.Height != gConfigGeneral.FullscreenHeight) + if (resolution.Width != Config::Get().general.FullscreenWidth + || resolution.Height != Config::Get().general.FullscreenHeight) { - gConfigGeneral.FullscreenWidth = resolution.Width; - gConfigGeneral.FullscreenHeight = resolution.Height; + Config::Get().general.FullscreenWidth = resolution.Width; + Config::Get().general.FullscreenHeight = resolution.Height; - if (gConfigGeneral.FullscreenMode == static_cast(OpenRCT2::Ui::FULLSCREEN_MODE::FULLSCREEN)) + if (Config::Get().general.FullscreenMode + == static_cast(OpenRCT2::Ui::FULLSCREEN_MODE::FULLSCREEN)) ContextSetFullscreenMode(static_cast(OpenRCT2::Ui::FULLSCREEN_MODE::FULLSCREEN)); - ConfigSaveDefault(); + Config::Save(); GfxInvalidateScreen(); } } break; case WIDX_FULLSCREEN_DROPDOWN: - if (dropdownIndex != gConfigGeneral.FullscreenMode) + if (dropdownIndex != Config::Get().general.FullscreenMode) { ContextSetFullscreenMode(dropdownIndex); - gConfigGeneral.FullscreenMode = static_cast(dropdownIndex); - ConfigSaveDefault(); + Config::Get().general.FullscreenMode = static_cast(dropdownIndex); + Config::Save(); GfxInvalidateScreen(); } break; case WIDX_DRAWING_ENGINE_DROPDOWN: - if (dropdownIndex != EnumValue(gConfigGeneral.DrawingEngine)) + if (dropdownIndex != EnumValue(Config::Get().general.DrawingEngine)) { DrawingEngine srcEngine = drawing_engine_get_type(); DrawingEngine dstEngine = static_cast(dropdownIndex); - gConfigGeneral.DrawingEngine = dstEngine; + Config::Get().general.DrawingEngine = dstEngine; bool recreate_window = DrawingEngineRequiresNewWindow(srcEngine, dstEngine); RefreshVideo(recreate_window); - ConfigSaveDefault(); + Config::Save(); Invalidate(); } break; @@ -869,11 +870,11 @@ static Widget *window_options_page_widgets[] = { // Resolution dropdown caption. auto ft = Formatter::Common(); ft.Increment(16); - ft.Add(static_cast(gConfigGeneral.FullscreenWidth)); - ft.Add(static_cast(gConfigGeneral.FullscreenHeight)); + ft.Add(static_cast(Config::Get().general.FullscreenWidth)); + ft.Add(static_cast(Config::Get().general.FullscreenHeight)); // Disable resolution dropdown on "Windowed" and "Fullscreen (desktop)" - if (gConfigGeneral.FullscreenMode != static_cast(OpenRCT2::Ui::FULLSCREEN_MODE::FULLSCREEN)) + if (Config::Get().general.FullscreenMode != static_cast(OpenRCT2::Ui::FULLSCREEN_MODE::FULLSCREEN)) { disabled_widgets |= (1uLL << WIDX_RESOLUTION_DROPDOWN); disabled_widgets |= (1uLL << WIDX_RESOLUTION); @@ -887,8 +888,8 @@ static Widget *window_options_page_widgets[] = { } // Disable Steam Overlay checkbox when using software or OpenGL rendering. - if (gConfigGeneral.DrawingEngine == DrawingEngine::Software - || gConfigGeneral.DrawingEngine == DrawingEngine::OpenGL) + if (Config::Get().general.DrawingEngine == DrawingEngine::Software + || Config::Get().general.DrawingEngine == DrawingEngine::OpenGL) { disabled_widgets |= (1uLL << WIDX_STEAM_OVERLAY_PAUSE); } @@ -898,7 +899,7 @@ static Widget *window_options_page_widgets[] = { } // Disable changing VSync for Software engine, as we can't control its use of VSync - if (gConfigGeneral.DrawingEngine == DrawingEngine::Software) + if (Config::Get().general.DrawingEngine == DrawingEngine::Software) { disabled_widgets |= (1uLL << WIDX_USE_VSYNC_CHECKBOX); } @@ -907,23 +908,23 @@ static Widget *window_options_page_widgets[] = { disabled_widgets &= ~(1uLL << WIDX_USE_VSYNC_CHECKBOX); } - SetCheckboxValue(WIDX_UNCAP_FPS_CHECKBOX, gConfigGeneral.UncapFPS); - SetCheckboxValue(WIDX_USE_VSYNC_CHECKBOX, gConfigGeneral.UseVSync); - SetCheckboxValue(WIDX_SHOW_FPS_CHECKBOX, gConfigGeneral.ShowFPS); - SetCheckboxValue(WIDX_MULTITHREADING_CHECKBOX, gConfigGeneral.MultiThreading); - SetCheckboxValue(WIDX_MINIMIZE_FOCUS_LOSS, gConfigGeneral.MinimizeFullscreenFocusLoss); - SetCheckboxValue(WIDX_STEAM_OVERLAY_PAUSE, gConfigGeneral.SteamOverlayPause); - SetCheckboxValue(WIDX_DISABLE_SCREENSAVER_LOCK, gConfigGeneral.DisableScreensaver); + SetCheckboxValue(WIDX_UNCAP_FPS_CHECKBOX, Config::Get().general.UncapFPS); + SetCheckboxValue(WIDX_USE_VSYNC_CHECKBOX, Config::Get().general.UseVSync); + SetCheckboxValue(WIDX_SHOW_FPS_CHECKBOX, Config::Get().general.ShowFPS); + SetCheckboxValue(WIDX_MULTITHREADING_CHECKBOX, Config::Get().general.MultiThreading); + SetCheckboxValue(WIDX_MINIMIZE_FOCUS_LOSS, Config::Get().general.MinimizeFullscreenFocusLoss); + SetCheckboxValue(WIDX_STEAM_OVERLAY_PAUSE, Config::Get().general.SteamOverlayPause); + SetCheckboxValue(WIDX_DISABLE_SCREENSAVER_LOCK, Config::Get().general.DisableScreensaver); // Dropdown captions for straightforward strings. - widgets[WIDX_FULLSCREEN].text = FullscreenModeNames[gConfigGeneral.FullscreenMode]; - widgets[WIDX_DRAWING_ENGINE].text = DrawingEngineStringIds[EnumValue(gConfigGeneral.DrawingEngine)]; + widgets[WIDX_FULLSCREEN].text = FullscreenModeNames[Config::Get().general.FullscreenMode]; + widgets[WIDX_DRAWING_ENGINE].text = DrawingEngineStringIds[EnumValue(Config::Get().general.DrawingEngine)]; } void DisplayDraw(DrawPixelInfo& dpi) { auto ft = Formatter(); - ft.Add(static_cast(gConfigGeneral.WindowScale * 100)); + ft.Add(static_cast(Config::Get().general.WindowScale * 100)); DrawTextBasic( dpi, windowPos + ScreenCoordsXY{ widgets[WIDX_SCALE].left + 1, widgets[WIDX_SCALE].top + 1 }, STR_WINDOW_COLOUR_2_COMMA2DP32, ft, { colours[1] }); @@ -936,19 +937,19 @@ static Widget *window_options_page_widgets[] = { switch (widgetIndex) { case WIDX_TILE_SMOOTHING_CHECKBOX: - gConfigGeneral.LandscapeSmoothing ^= 1; - ConfigSaveDefault(); + Config::Get().general.LandscapeSmoothing ^= 1; + Config::Save(); GfxInvalidateScreen(); break; case WIDX_GRIDLINES_CHECKBOX: { - gConfigGeneral.AlwaysShowGridlines ^= 1; - ConfigSaveDefault(); + Config::Get().general.AlwaysShowGridlines ^= 1; + Config::Save(); GfxInvalidateScreen(); WindowBase* mainWindow = WindowGetMain(); if (mainWindow != nullptr) { - if (gConfigGeneral.AlwaysShowGridlines) + if (Config::Get().general.AlwaysShowGridlines) mainWindow->viewport->flags |= VIEWPORT_FLAG_GRIDLINES; else mainWindow->viewport->flags &= ~VIEWPORT_FLAG_GRIDLINES; @@ -956,46 +957,46 @@ static Widget *window_options_page_widgets[] = { break; } case WIDX_DAY_NIGHT_CHECKBOX: - gConfigGeneral.DayNightCycle ^= 1; - ConfigSaveDefault(); + Config::Get().general.DayNightCycle ^= 1; + Config::Save(); Invalidate(); break; case WIDX_ENABLE_LIGHT_FX_CHECKBOX: - gConfigGeneral.EnableLightFx ^= 1; - ConfigSaveDefault(); + Config::Get().general.EnableLightFx ^= 1; + Config::Save(); Invalidate(); break; case WIDX_ENABLE_LIGHT_FX_FOR_VEHICLES_CHECKBOX: - gConfigGeneral.EnableLightFxForVehicles ^= 1; - ConfigSaveDefault(); + Config::Get().general.EnableLightFxForVehicles ^= 1; + Config::Save(); Invalidate(); break; case WIDX_UPPER_CASE_BANNERS_CHECKBOX: - gConfigGeneral.UpperCaseBanners ^= 1; - ConfigSaveDefault(); + Config::Get().general.UpperCaseBanners ^= 1; + Config::Save(); Invalidate(); ScrollingTextInvalidate(); break; case WIDX_DISABLE_LIGHTNING_EFFECT_CHECKBOX: - gConfigGeneral.DisableLightningEffect ^= 1; - ConfigSaveDefault(); + Config::Get().general.DisableLightningEffect ^= 1; + Config::Save(); Invalidate(); break; case WIDX_RENDER_WEATHER_EFFECTS_CHECKBOX: - gConfigGeneral.RenderWeatherEffects ^= 1; - gConfigGeneral.RenderWeatherGloom = gConfigGeneral.RenderWeatherEffects; - ConfigSaveDefault(); + Config::Get().general.RenderWeatherEffects ^= 1; + Config::Get().general.RenderWeatherGloom = Config::Get().general.RenderWeatherEffects; + Config::Save(); Invalidate(); GfxInvalidateScreen(); break; case WIDX_SHOW_GUEST_PURCHASES_CHECKBOX: - gConfigGeneral.ShowGuestPurchases ^= 1; - ConfigSaveDefault(); + Config::Get().general.ShowGuestPurchases ^= 1; + Config::Save(); Invalidate(); break; case WIDX_TRANSPARENT_SCREENSHOTS_CHECKBOX: - gConfigGeneral.TransparentScreenshot ^= 1; - ConfigSaveDefault(); + Config::Get().general.TransparentScreenshot ^= 1; + Config::Save(); Invalidate(); break; } @@ -1016,7 +1017,7 @@ static Widget *window_options_page_widgets[] = { Widget* widget = &widgets[widgetIndex - 1]; ShowDropdown(widget, 3); - Dropdown::SetChecked(static_cast(gConfigGeneral.VirtualFloorStyle), true); + Dropdown::SetChecked(static_cast(Config::Get().general.VirtualFloorStyle), true); break; } } @@ -1026,20 +1027,20 @@ static Widget *window_options_page_widgets[] = { switch (widgetIndex) { case WIDX_VIRTUAL_FLOOR_DROPDOWN: - gConfigGeneral.VirtualFloorStyle = static_cast(dropdownIndex); - ConfigSaveDefault(); + Config::Get().general.VirtualFloorStyle = static_cast(dropdownIndex); + Config::Save(); break; } } void RenderingPrepareDraw() { - SetCheckboxValue(WIDX_TILE_SMOOTHING_CHECKBOX, gConfigGeneral.LandscapeSmoothing); - SetCheckboxValue(WIDX_GRIDLINES_CHECKBOX, gConfigGeneral.AlwaysShowGridlines); - SetCheckboxValue(WIDX_DAY_NIGHT_CHECKBOX, gConfigGeneral.DayNightCycle); - SetCheckboxValue(WIDX_SHOW_GUEST_PURCHASES_CHECKBOX, gConfigGeneral.ShowGuestPurchases); - SetCheckboxValue(WIDX_TRANSPARENT_SCREENSHOTS_CHECKBOX, gConfigGeneral.TransparentScreenshot); - SetCheckboxValue(WIDX_UPPER_CASE_BANNERS_CHECKBOX, gConfigGeneral.UpperCaseBanners); + SetCheckboxValue(WIDX_TILE_SMOOTHING_CHECKBOX, Config::Get().general.LandscapeSmoothing); + SetCheckboxValue(WIDX_GRIDLINES_CHECKBOX, Config::Get().general.AlwaysShowGridlines); + SetCheckboxValue(WIDX_DAY_NIGHT_CHECKBOX, Config::Get().general.DayNightCycle); + SetCheckboxValue(WIDX_SHOW_GUEST_PURCHASES_CHECKBOX, Config::Get().general.ShowGuestPurchases); + SetCheckboxValue(WIDX_TRANSPARENT_SCREENSHOTS_CHECKBOX, Config::Get().general.TransparentScreenshot); + SetCheckboxValue(WIDX_UPPER_CASE_BANNERS_CHECKBOX, Config::Get().general.UpperCaseBanners); static constexpr StringId _virtualFloorStyleStrings[] = { STR_VIRTUAL_FLOOR_STYLE_DISABLED, @@ -1047,36 +1048,38 @@ static Widget *window_options_page_widgets[] = { STR_VIRTUAL_FLOOR_STYLE_GLASSY, }; - widgets[WIDX_VIRTUAL_FLOOR].text = _virtualFloorStyleStrings[EnumValue(gConfigGeneral.VirtualFloorStyle)]; + widgets[WIDX_VIRTUAL_FLOOR].text = _virtualFloorStyleStrings[EnumValue(Config::Get().general.VirtualFloorStyle)]; - SetCheckboxValue(WIDX_ENABLE_LIGHT_FX_CHECKBOX, gConfigGeneral.EnableLightFx); - if (gConfigGeneral.DayNightCycle && gConfigGeneral.DrawingEngine == DrawingEngine::SoftwareWithHardwareDisplay) + SetCheckboxValue(WIDX_ENABLE_LIGHT_FX_CHECKBOX, Config::Get().general.EnableLightFx); + if (Config::Get().general.DayNightCycle + && Config::Get().general.DrawingEngine == DrawingEngine::SoftwareWithHardwareDisplay) { disabled_widgets &= ~(1uLL << WIDX_ENABLE_LIGHT_FX_CHECKBOX); } else { disabled_widgets |= (1uLL << WIDX_ENABLE_LIGHT_FX_CHECKBOX); - gConfigGeneral.EnableLightFx = false; + Config::Get().general.EnableLightFx = false; } - SetCheckboxValue(WIDX_ENABLE_LIGHT_FX_FOR_VEHICLES_CHECKBOX, gConfigGeneral.EnableLightFxForVehicles); - if (gConfigGeneral.DayNightCycle && gConfigGeneral.DrawingEngine == DrawingEngine::SoftwareWithHardwareDisplay - && gConfigGeneral.EnableLightFx) + SetCheckboxValue(WIDX_ENABLE_LIGHT_FX_FOR_VEHICLES_CHECKBOX, Config::Get().general.EnableLightFxForVehicles); + if (Config::Get().general.DayNightCycle + && Config::Get().general.DrawingEngine == DrawingEngine::SoftwareWithHardwareDisplay + && Config::Get().general.EnableLightFx) { disabled_widgets &= ~(1uLL << WIDX_ENABLE_LIGHT_FX_FOR_VEHICLES_CHECKBOX); } else { disabled_widgets |= (1uLL << WIDX_ENABLE_LIGHT_FX_FOR_VEHICLES_CHECKBOX); - gConfigGeneral.EnableLightFxForVehicles = false; + Config::Get().general.EnableLightFxForVehicles = false; } WidgetSetCheckboxValue( *this, WIDX_RENDER_WEATHER_EFFECTS_CHECKBOX, - gConfigGeneral.RenderWeatherEffects || gConfigGeneral.RenderWeatherGloom); - SetCheckboxValue(WIDX_DISABLE_LIGHTNING_EFFECT_CHECKBOX, gConfigGeneral.DisableLightningEffect); - if (!gConfigGeneral.RenderWeatherEffects && !gConfigGeneral.RenderWeatherGloom) + Config::Get().general.RenderWeatherEffects || Config::Get().general.RenderWeatherGloom); + SetCheckboxValue(WIDX_DISABLE_LIGHTNING_EFFECT_CHECKBOX, Config::Get().general.DisableLightningEffect); + if (!Config::Get().general.RenderWeatherEffects && !Config::Get().general.RenderWeatherGloom) { SetCheckboxValue(WIDX_DISABLE_LIGHTNING_EFFECT_CHECKBOX, true); disabled_widgets |= (1uLL << WIDX_DISABLE_LIGHTNING_EFFECT_CHECKBOX); @@ -1104,7 +1107,7 @@ static Widget *window_options_page_widgets[] = { ShowDropdown(widget, 2); - Dropdown::SetChecked(gConfigGeneral.ShowHeightAsUnits ? 0 : 1, true); + Dropdown::SetChecked(Config::Get().general.ShowHeightAsUnits ? 0 : 1, true); break; case WIDX_CURRENCY_DROPDOWN: { @@ -1128,13 +1131,13 @@ static Widget *window_options_page_widgets[] = { ShowDropdown(widget, numItems); - if (gConfigGeneral.CurrencyFormat == CurrencyType::Custom) + if (Config::Get().general.CurrencyFormat == CurrencyType::Custom) { - Dropdown::SetChecked(EnumValue(gConfigGeneral.CurrencyFormat) + 1, true); + Dropdown::SetChecked(EnumValue(Config::Get().general.CurrencyFormat) + 1, true); } else { - Dropdown::SetChecked(EnumValue(gConfigGeneral.CurrencyFormat), true); + Dropdown::SetChecked(EnumValue(Config::Get().general.CurrencyFormat), true); } break; } @@ -1148,7 +1151,7 @@ static Widget *window_options_page_widgets[] = { ShowDropdown(widget, 3); - Dropdown::SetChecked(static_cast(gConfigGeneral.MeasurementFormat), true); + Dropdown::SetChecked(static_cast(Config::Get().general.MeasurementFormat), true); break; case WIDX_TEMPERATURE_DROPDOWN: gDropdownItems[0].Format = STR_DROPDOWN_MENU_LABEL; @@ -1158,7 +1161,7 @@ static Widget *window_options_page_widgets[] = { ShowDropdown(widget, 2); - Dropdown::SetChecked(static_cast(gConfigGeneral.TemperatureFormat), true); + Dropdown::SetChecked(static_cast(Config::Get().general.TemperatureFormat), true); break; case WIDX_LANGUAGE_DROPDOWN: for (size_t i = 1; i < LANGUAGE_COUNT; i++) @@ -1176,7 +1179,7 @@ static Widget *window_options_page_widgets[] = { gDropdownItems[i].Args = DateFormatStringIDs[i]; } ShowDropdown(widget, 4); - Dropdown::SetChecked(gConfigGeneral.DateFormat, true); + Dropdown::SetChecked(Config::Get().general.DateFormat, true); break; } } @@ -1187,38 +1190,38 @@ static Widget *window_options_page_widgets[] = { { case WIDX_HEIGHT_LABELS_DROPDOWN: // reset flag and set it to 1 if height as units is selected - gConfigGeneral.ShowHeightAsUnits = 0; + Config::Get().general.ShowHeightAsUnits = 0; if (dropdownIndex == 0) { - gConfigGeneral.ShowHeightAsUnits = 1; + Config::Get().general.ShowHeightAsUnits = 1; } - ConfigSaveDefault(); + Config::Save(); UpdateHeightMarkers(); break; case WIDX_CURRENCY_DROPDOWN: if (dropdownIndex == EnumValue(CurrencyType::Custom) + 1) { // Add 1 because the separator occupies a position - gConfigGeneral.CurrencyFormat = static_cast(dropdownIndex - 1); + Config::Get().general.CurrencyFormat = static_cast(dropdownIndex - 1); ContextOpenWindow(WindowClass::CustomCurrencyConfig); } else { - gConfigGeneral.CurrencyFormat = static_cast(dropdownIndex); + Config::Get().general.CurrencyFormat = static_cast(dropdownIndex); } - ConfigSaveDefault(); + Config::Save(); GfxInvalidateScreen(); break; case WIDX_DISTANCE_DROPDOWN: - gConfigGeneral.MeasurementFormat = static_cast(dropdownIndex); - ConfigSaveDefault(); + Config::Get().general.MeasurementFormat = static_cast(dropdownIndex); + Config::Save(); UpdateHeightMarkers(); break; case WIDX_TEMPERATURE_DROPDOWN: - if (dropdownIndex != static_cast(gConfigGeneral.TemperatureFormat)) + if (dropdownIndex != static_cast(Config::Get().general.TemperatureFormat)) { - gConfigGeneral.TemperatureFormat = static_cast(dropdownIndex); - ConfigSaveDefault(); + Config::Get().general.TemperatureFormat = static_cast(dropdownIndex); + Config::Save(); GfxInvalidateScreen(); } break; @@ -1241,18 +1244,18 @@ static Widget *window_options_page_widgets[] = { } else { - gConfigGeneral.Language = dropdownIndex + 1; - ConfigSaveDefault(); + Config::Get().general.Language = dropdownIndex + 1; + Config::Save(); GfxInvalidateScreen(); } } } break; case WIDX_DATE_FORMAT_DROPDOWN: - if (dropdownIndex != gConfigGeneral.DateFormat) + if (dropdownIndex != Config::Get().general.DateFormat) { - gConfigGeneral.DateFormat = static_cast(dropdownIndex); - ConfigSaveDefault(); + Config::Get().general.DateFormat = static_cast(dropdownIndex); + Config::Save(); GfxInvalidateScreen(); } break; @@ -1266,12 +1269,12 @@ static Widget *window_options_page_widgets[] = { ft.Add(LanguagesDescriptors[LocalisationService_GetCurrentLanguage()].native_name); // Currency: pounds, dollars, etc. (10 total) - widgets[WIDX_CURRENCY].text = CurrencyDescriptors[EnumValue(gConfigGeneral.CurrencyFormat)].stringId; + widgets[WIDX_CURRENCY].text = CurrencyDescriptors[EnumValue(Config::Get().general.CurrencyFormat)].stringId; // Distance: metric / imperial / si { StringId stringId = STR_NONE; - switch (gConfigGeneral.MeasurementFormat) + switch (Config::Get().general.MeasurementFormat) { case MeasurementFormat::Imperial: stringId = STR_IMPERIAL; @@ -1287,14 +1290,15 @@ static Widget *window_options_page_widgets[] = { } // Date format - widgets[WIDX_DATE_FORMAT].text = DateFormatStringIDs[gConfigGeneral.DateFormat]; + widgets[WIDX_DATE_FORMAT].text = DateFormatStringIDs[Config::Get().general.DateFormat]; // Temperature: celsius/fahrenheit - widgets[WIDX_TEMPERATURE].text = gConfigGeneral.TemperatureFormat == TemperatureUnit::Fahrenheit ? STR_FAHRENHEIT - : STR_CELSIUS; + widgets[WIDX_TEMPERATURE].text = Config::Get().general.TemperatureFormat == TemperatureUnit::Fahrenheit + ? STR_FAHRENHEIT + : STR_CELSIUS; // Height: units/real values - widgets[WIDX_HEIGHT_LABELS].text = gConfigGeneral.ShowHeightAsUnits ? STR_HEIGHT_IN_UNITS : STR_REAL_VALUES; + widgets[WIDX_HEIGHT_LABELS].text = Config::Get().general.ShowHeightAsUnits ? STR_HEIGHT_IN_UNITS : STR_REAL_VALUES; } #pragma endregion @@ -1305,35 +1309,35 @@ static Widget *window_options_page_widgets[] = { switch (widgetIndex) { case WIDX_SOUND_CHECKBOX: - gConfigSound.SoundEnabled = !gConfigSound.SoundEnabled; - ConfigSaveDefault(); + Config::Get().sound.SoundEnabled = !Config::Get().sound.SoundEnabled; + Config::Save(); Invalidate(); break; case WIDX_MASTER_SOUND_CHECKBOX: - gConfigSound.MasterSoundEnabled = !gConfigSound.MasterSoundEnabled; - if (!gConfigSound.MasterSoundEnabled) + Config::Get().sound.MasterSoundEnabled = !Config::Get().sound.MasterSoundEnabled; + if (!Config::Get().sound.MasterSoundEnabled) OpenRCT2::Audio::Pause(); else OpenRCT2::Audio::Resume(); WindowInvalidateByClass(WindowClass::TopToolbar); - ConfigSaveDefault(); + Config::Save(); Invalidate(); break; case WIDX_MUSIC_CHECKBOX: - gConfigSound.RideMusicEnabled = !gConfigSound.RideMusicEnabled; - if (!gConfigSound.RideMusicEnabled) + Config::Get().sound.RideMusicEnabled = !Config::Get().sound.RideMusicEnabled; + if (!Config::Get().sound.RideMusicEnabled) { OpenRCT2::RideAudio::StopAllChannels(); } - ConfigSaveDefault(); + Config::Save(); Invalidate(); break; case WIDX_AUDIO_FOCUS_CHECKBOX: - gConfigSound.audio_focus = !gConfigSound.audio_focus; - ConfigSaveDefault(); + Config::Get().sound.audio_focus = !Config::Get().sound.audio_focus; + Config::Save(); Invalidate(); break; } @@ -1369,7 +1373,7 @@ static Widget *window_options_page_widgets[] = { if (theme.Kind == TitleMusicKind::RCT1 && !rct1MusicThemeIsAvailable) continue; - if (gConfigSound.TitleMusic == theme.Kind) + if (Config::Get().sound.TitleMusic == theme.Kind) checkedIndex = numItems; gDropdownItems[numItems].Format = STR_DROPDOWN_MENU_LABEL; @@ -1394,15 +1398,15 @@ static Widget *window_options_page_widgets[] = { if (dropdownIndex == 0) { audioContext->SetOutputDevice(""); - gConfigSound.Device = ""; + Config::Get().sound.Device = ""; } else { const auto& deviceName = GetDeviceName(dropdownIndex); audioContext->SetOutputDevice(deviceName); - gConfigSound.Device = deviceName; + Config::Get().sound.Device = deviceName; } - ConfigSaveDefault(); + Config::Save(); OpenRCT2::Audio::PlayTitleMusic(); } Invalidate(); @@ -1418,12 +1422,12 @@ static Widget *window_options_page_widgets[] = { dropdownIndex++; } - gConfigSound.TitleMusic = TitleThemeOptions[dropdownIndex].Kind; - ConfigSaveDefault(); + Config::Get().sound.TitleMusic = TitleThemeOptions[dropdownIndex].Kind; + Config::Save(); Invalidate(); OpenRCT2::Audio::StopTitleMusic(); - if (gConfigSound.TitleMusic != TitleMusicKind::None) + if (Config::Get().sound.TitleMusic != TitleMusicKind::None) { OpenRCT2::Audio::PlayTitleMusic(); } @@ -1437,30 +1441,30 @@ static Widget *window_options_page_widgets[] = { const auto& masterVolumeWidget = widgets[WIDX_MASTER_VOLUME]; const auto& masterVolumeScroll = scrolls[0]; uint8_t masterVolume = GetScrollPercentage(masterVolumeWidget, masterVolumeScroll); - if (masterVolume != gConfigSound.MasterVolume) + if (masterVolume != Config::Get().sound.MasterVolume) { - gConfigSound.MasterVolume = masterVolume; - ConfigSaveDefault(); + Config::Get().sound.MasterVolume = masterVolume; + Config::Save(); InvalidateWidget(WIDX_MASTER_VOLUME); } const auto& soundVolumeWidget = widgets[WIDX_MASTER_VOLUME]; const auto& soundVolumeScroll = scrolls[1]; uint8_t soundVolume = GetScrollPercentage(soundVolumeWidget, soundVolumeScroll); - if (soundVolume != gConfigSound.SoundVolume) + if (soundVolume != Config::Get().sound.SoundVolume) { - gConfigSound.SoundVolume = soundVolume; - ConfigSaveDefault(); + Config::Get().sound.SoundVolume = soundVolume; + Config::Save(); InvalidateWidget(WIDX_SOUND_VOLUME); } const auto& musicVolumeWidget = widgets[WIDX_MASTER_VOLUME]; const auto& musicVolumeScroll = scrolls[2]; uint8_t rideMusicVolume = GetScrollPercentage(musicVolumeWidget, musicVolumeScroll); - if (rideMusicVolume != gConfigSound.AudioFocus) + if (rideMusicVolume != Config::Get().sound.AudioFocus) { - gConfigSound.AudioFocus = rideMusicVolume; - ConfigSaveDefault(); + Config::Get().sound.AudioFocus = rideMusicVolume; + Config::Save(); InvalidateWidget(WIDX_MUSIC_VOLUME); } } @@ -1473,7 +1477,7 @@ static Widget *window_options_page_widgets[] = { StringId GetTitleMusicName() const { auto theme = std::find_if(std::begin(TitleThemeOptions), std::end(TitleThemeOptions), [](auto&& option) { - return gConfigSound.TitleMusic == option.Kind; + return Config::Get().sound.TitleMusic == option.Kind; }); if (theme != std::end(TitleThemeOptions)) return theme->Name; @@ -1511,19 +1515,19 @@ static Widget *window_options_page_widgets[] = { widgets[WIDX_TITLE_MUSIC].text = GetTitleMusicName(); - SetCheckboxValue(WIDX_SOUND_CHECKBOX, gConfigSound.SoundEnabled); - SetCheckboxValue(WIDX_MASTER_SOUND_CHECKBOX, gConfigSound.MasterSoundEnabled); - SetCheckboxValue(WIDX_MUSIC_CHECKBOX, gConfigSound.RideMusicEnabled); - SetCheckboxValue(WIDX_AUDIO_FOCUS_CHECKBOX, gConfigSound.audio_focus); - WidgetSetEnabled(*this, WIDX_SOUND_CHECKBOX, gConfigSound.MasterSoundEnabled); - WidgetSetEnabled(*this, WIDX_MUSIC_CHECKBOX, gConfigSound.MasterSoundEnabled); + SetCheckboxValue(WIDX_SOUND_CHECKBOX, Config::Get().sound.SoundEnabled); + SetCheckboxValue(WIDX_MASTER_SOUND_CHECKBOX, Config::Get().sound.MasterSoundEnabled); + SetCheckboxValue(WIDX_MUSIC_CHECKBOX, Config::Get().sound.RideMusicEnabled); + SetCheckboxValue(WIDX_AUDIO_FOCUS_CHECKBOX, Config::Get().sound.audio_focus); + WidgetSetEnabled(*this, WIDX_SOUND_CHECKBOX, Config::Get().sound.MasterSoundEnabled); + WidgetSetEnabled(*this, WIDX_MUSIC_CHECKBOX, Config::Get().sound.MasterSoundEnabled); // Initialize only on first frame, otherwise the scrollbars won't be able to be modified if (frame_no == 0) { - InitializeScrollPosition(WIDX_MASTER_VOLUME, 0, gConfigSound.MasterVolume); - InitializeScrollPosition(WIDX_SOUND_VOLUME, 1, gConfigSound.SoundVolume); - InitializeScrollPosition(WIDX_MUSIC_VOLUME, 2, gConfigSound.AudioFocus); + InitializeScrollPosition(WIDX_MASTER_VOLUME, 0, Config::Get().sound.MasterVolume); + InitializeScrollPosition(WIDX_SOUND_VOLUME, 1, Config::Get().sound.SoundVolume); + InitializeScrollPosition(WIDX_MUSIC_VOLUME, 2, Config::Get().sound.AudioFocus); } } @@ -1538,72 +1542,72 @@ static Widget *window_options_page_widgets[] = { ContextOpenWindow(WindowClass::KeyboardShortcutList); break; case WIDX_SCREEN_EDGE_SCROLLING: - gConfigGeneral.EdgeScrolling ^= 1; - ConfigSaveDefault(); + Config::Get().general.EdgeScrolling ^= 1; + Config::Save(); Invalidate(); break; case WIDX_TRAP_CURSOR: - gConfigGeneral.TrapCursor ^= 1; - ConfigSaveDefault(); - ContextSetCursorTrap(gConfigGeneral.TrapCursor); + Config::Get().general.TrapCursor ^= 1; + Config::Save(); + ContextSetCursorTrap(Config::Get().general.TrapCursor); Invalidate(); break; case WIDX_ZOOM_TO_CURSOR: - gConfigGeneral.ZoomToCursor ^= 1; - ConfigSaveDefault(); + Config::Get().general.ZoomToCursor ^= 1; + Config::Save(); Invalidate(); break; case WIDX_TOOLBAR_SHOW_FINANCES: - gConfigInterface.ToolbarShowFinances ^= 1; - ConfigSaveDefault(); + Config::Get().interface.ToolbarShowFinances ^= 1; + Config::Save(); Invalidate(); WindowInvalidateByClass(WindowClass::TopToolbar); break; case WIDX_TOOLBAR_SHOW_RESEARCH: - gConfigInterface.ToolbarShowResearch ^= 1; - ConfigSaveDefault(); + Config::Get().interface.ToolbarShowResearch ^= 1; + Config::Save(); Invalidate(); WindowInvalidateByClass(WindowClass::TopToolbar); break; case WIDX_TOOLBAR_SHOW_CHEATS: - gConfigInterface.ToolbarShowCheats ^= 1; - ConfigSaveDefault(); + Config::Get().interface.ToolbarShowCheats ^= 1; + Config::Save(); Invalidate(); WindowInvalidateByClass(WindowClass::TopToolbar); break; case WIDX_TOOLBAR_SHOW_NEWS: - gConfigInterface.ToolbarShowNews ^= 1; - ConfigSaveDefault(); + Config::Get().interface.ToolbarShowNews ^= 1; + Config::Save(); Invalidate(); WindowInvalidateByClass(WindowClass::TopToolbar); break; case WIDX_TOOLBAR_SHOW_MUTE: - gConfigInterface.ToolbarShowMute ^= 1; - ConfigSaveDefault(); + Config::Get().interface.ToolbarShowMute ^= 1; + Config::Save(); Invalidate(); WindowInvalidateByClass(WindowClass::TopToolbar); break; case WIDX_TOOLBAR_SHOW_CHAT: - gConfigInterface.ToolbarShowChat ^= 1; - ConfigSaveDefault(); + Config::Get().interface.ToolbarShowChat ^= 1; + Config::Save(); Invalidate(); WindowInvalidateByClass(WindowClass::TopToolbar); break; case WIDX_TOOLBAR_SHOW_ZOOM: - gConfigInterface.ToolbarShowZoom ^= 1; - ConfigSaveDefault(); + Config::Get().interface.ToolbarShowZoom ^= 1; + Config::Save(); Invalidate(); WindowInvalidateByClass(WindowClass::TopToolbar); break; case WIDX_WINDOW_BUTTONS_ON_THE_LEFT: - gConfigInterface.WindowButtonsOnTheLeft ^= 1; - ConfigSaveDefault(); + Config::Get().interface.WindowButtonsOnTheLeft ^= 1; + Config::Save(); Invalidate(); WindowInvalidateAll(); break; case WIDX_INVERT_DRAG: - gConfigGeneral.InvertViewportDrag ^= 1; - ConfigSaveDefault(); + Config::Get().general.InvertViewportDrag ^= 1; + Config::Save(); Invalidate(); break; case WIDX_THEMES_BUTTON: @@ -1647,25 +1651,25 @@ static Widget *window_options_page_widgets[] = { { ThemeManagerSetActiveAvailableTheme(dropdownIndex); } - ConfigSaveDefault(); + Config::Save(); break; } } void ControlsPrepareDraw() { - SetCheckboxValue(WIDX_SCREEN_EDGE_SCROLLING, gConfigGeneral.EdgeScrolling); - SetCheckboxValue(WIDX_TRAP_CURSOR, gConfigGeneral.TrapCursor); - SetCheckboxValue(WIDX_INVERT_DRAG, gConfigGeneral.InvertViewportDrag); - SetCheckboxValue(WIDX_ZOOM_TO_CURSOR, gConfigGeneral.ZoomToCursor); - SetCheckboxValue(WIDX_TOOLBAR_SHOW_FINANCES, gConfigInterface.ToolbarShowFinances); - SetCheckboxValue(WIDX_TOOLBAR_SHOW_RESEARCH, gConfigInterface.ToolbarShowResearch); - SetCheckboxValue(WIDX_TOOLBAR_SHOW_CHEATS, gConfigInterface.ToolbarShowCheats); - SetCheckboxValue(WIDX_TOOLBAR_SHOW_NEWS, gConfigInterface.ToolbarShowNews); - SetCheckboxValue(WIDX_TOOLBAR_SHOW_MUTE, gConfigInterface.ToolbarShowMute); - SetCheckboxValue(WIDX_TOOLBAR_SHOW_CHAT, gConfigInterface.ToolbarShowChat); - SetCheckboxValue(WIDX_TOOLBAR_SHOW_ZOOM, gConfigInterface.ToolbarShowZoom); - SetCheckboxValue(WIDX_WINDOW_BUTTONS_ON_THE_LEFT, gConfigInterface.WindowButtonsOnTheLeft); + SetCheckboxValue(WIDX_SCREEN_EDGE_SCROLLING, Config::Get().general.EdgeScrolling); + SetCheckboxValue(WIDX_TRAP_CURSOR, Config::Get().general.TrapCursor); + SetCheckboxValue(WIDX_INVERT_DRAG, Config::Get().general.InvertViewportDrag); + SetCheckboxValue(WIDX_ZOOM_TO_CURSOR, Config::Get().general.ZoomToCursor); + SetCheckboxValue(WIDX_TOOLBAR_SHOW_FINANCES, Config::Get().interface.ToolbarShowFinances); + SetCheckboxValue(WIDX_TOOLBAR_SHOW_RESEARCH, Config::Get().interface.ToolbarShowResearch); + SetCheckboxValue(WIDX_TOOLBAR_SHOW_CHEATS, Config::Get().interface.ToolbarShowCheats); + SetCheckboxValue(WIDX_TOOLBAR_SHOW_NEWS, Config::Get().interface.ToolbarShowNews); + SetCheckboxValue(WIDX_TOOLBAR_SHOW_MUTE, Config::Get().interface.ToolbarShowMute); + SetCheckboxValue(WIDX_TOOLBAR_SHOW_CHAT, Config::Get().interface.ToolbarShowChat); + SetCheckboxValue(WIDX_TOOLBAR_SHOW_ZOOM, Config::Get().interface.ToolbarShowZoom); + SetCheckboxValue(WIDX_WINDOW_BUTTONS_ON_THE_LEFT, Config::Get().interface.WindowButtonsOnTheLeft); size_t activeAvailableThemeIndex = ThemeManagerGetAvailableThemeIndex(); const utf8* activeThemeName = ThemeManagerGetAvailableThemeName(activeAvailableThemeIndex); @@ -1681,37 +1685,37 @@ static Widget *window_options_page_widgets[] = { switch (widgetIndex) { case WIDX_REAL_NAME_CHECKBOX: - gConfigGeneral.ShowRealNamesOfGuests ^= 1; - ConfigSaveDefault(); + Config::Get().general.ShowRealNamesOfGuests ^= 1; + Config::Save(); Invalidate(); - PeepUpdateNames(gConfigGeneral.ShowRealNamesOfGuests); + PeepUpdateNames(Config::Get().general.ShowRealNamesOfGuests); break; case WIDX_AUTO_STAFF_PLACEMENT: - gConfigGeneral.AutoStaffPlacement ^= 1; - ConfigSaveDefault(); + Config::Get().general.AutoStaffPlacement ^= 1; + Config::Save(); Invalidate(); break; case WIDX_SCENARIO_UNLOCKING: - gConfigGeneral.ScenarioUnlockingEnabled ^= 1; - ConfigSaveDefault(); + Config::Get().general.ScenarioUnlockingEnabled ^= 1; + Config::Save(); WindowCloseByClass(WindowClass::ScenarioSelect); break; case WIDX_AUTO_OPEN_SHOPS: - gConfigGeneral.AutoOpenShops = !gConfigGeneral.AutoOpenShops; - ConfigSaveDefault(); + Config::Get().general.AutoOpenShops = !Config::Get().general.AutoOpenShops; + Config::Save(); Invalidate(); break; case WIDX_ALLOW_EARLY_COMPLETION: - gConfigGeneral.AllowEarlyCompletion ^= 1; + Config::Get().general.AllowEarlyCompletion ^= 1; // Only the server can control this setting and needs to send the // current value of allow_early_completion to all clients if (NetworkGetMode() == NETWORK_MODE_SERVER) { auto setAllowEarlyCompletionAction = ScenarioSetSettingAction( - ScenarioSetSetting::AllowEarlyCompletion, gConfigGeneral.AllowEarlyCompletion); + ScenarioSetSetting::AllowEarlyCompletion, Config::Get().general.AllowEarlyCompletion); GameActions::Execute(&setAllowEarlyCompletionAction); } - ConfigSaveDefault(); + Config::Save(); Invalidate(); break; } @@ -1742,8 +1746,9 @@ static Widget *window_options_page_widgets[] = { { windowPos.x + widget->left, windowPos.y + widget->top }, widget->height() + 1, colours[1], Dropdown::Flag::StayOpen, numItems); - auto selectedIndex = gConfigInterface.RandomTitleSequence ? numItems - 1 - : static_cast(TitleGetCurrentSequence()); + auto selectedIndex = Config::Get().interface.RandomTitleSequence + ? numItems - 1 + : static_cast(TitleGetCurrentSequence()); Dropdown::SetChecked(selectedIndex, true); break; } @@ -1760,7 +1765,7 @@ static Widget *window_options_page_widgets[] = { { windowPos.x + widget->left, windowPos.y + widget->top }, widget->height() + 1, colours[1], 0, Dropdown::Flag::StayOpen, numItems, widget->width() - 3); - Dropdown::SetChecked(gConfigGeneral.ScenarioSelectMode, true); + Dropdown::SetChecked(Config::Get().general.ScenarioSelectMode, true); break; } case WIDX_DEFAULT_INSPECTION_INTERVAL_DROPDOWN: @@ -1771,7 +1776,7 @@ static Widget *window_options_page_widgets[] = { } ShowDropdown(widget, 7); - Dropdown::SetChecked(gConfigGeneral.DefaultInspectionInterval, true); + Dropdown::SetChecked(Config::Get().general.DefaultInspectionInterval, true); break; } } @@ -1785,33 +1790,33 @@ static Widget *window_options_page_widgets[] = { auto numItems = static_cast(TitleSequenceManagerGetCount()); if (dropdownIndex < numItems && dropdownIndex != static_cast(TitleGetCurrentSequence())) { - gConfigInterface.RandomTitleSequence = false; + Config::Get().interface.RandomTitleSequence = false; TitleSequenceChangePreset(static_cast(dropdownIndex)); - ConfigSaveDefault(); + Config::Save(); Invalidate(); } else if (dropdownIndex == numItems + 1) { - gConfigInterface.RandomTitleSequence = true; - ConfigSaveDefault(); + Config::Get().interface.RandomTitleSequence = true; + Config::Save(); Invalidate(); } break; } case WIDX_DEFAULT_INSPECTION_INTERVAL_DROPDOWN: - if (dropdownIndex != gConfigGeneral.DefaultInspectionInterval) + if (dropdownIndex != Config::Get().general.DefaultInspectionInterval) { - gConfigGeneral.DefaultInspectionInterval = static_cast(dropdownIndex); - ConfigSaveDefault(); + Config::Get().general.DefaultInspectionInterval = static_cast(dropdownIndex); + Config::Save(); Invalidate(); } break; case WIDX_SCENARIO_GROUPING_DROPDOWN: - if (dropdownIndex != gConfigGeneral.ScenarioSelectMode) + if (dropdownIndex != Config::Get().general.ScenarioSelectMode) { - gConfigGeneral.ScenarioSelectMode = dropdownIndex; - gConfigInterface.ScenarioselectLastTab = 0; - ConfigSaveDefault(); + Config::Get().general.ScenarioSelectMode = dropdownIndex; + Config::Get().interface.ScenarioselectLastTab = 0; + Config::Save(); Invalidate(); WindowCloseByClass(WindowClass::ScenarioSelect); } @@ -1822,7 +1827,7 @@ static Widget *window_options_page_widgets[] = { void MiscPrepareDraw() { auto ft = Formatter::Common(); - if (gConfigInterface.RandomTitleSequence) + if (Config::Get().interface.RandomTitleSequence) { ft.Add(STR_TITLE_SEQUENCE_RANDOM); } @@ -1849,19 +1854,19 @@ static Widget *window_options_page_widgets[] = { } } - SetCheckboxValue(WIDX_REAL_NAME_CHECKBOX, gConfigGeneral.ShowRealNamesOfGuests); - SetCheckboxValue(WIDX_AUTO_STAFF_PLACEMENT, gConfigGeneral.AutoStaffPlacement); - SetCheckboxValue(WIDX_AUTO_OPEN_SHOPS, gConfigGeneral.AutoOpenShops); - SetCheckboxValue(WIDX_ALLOW_EARLY_COMPLETION, gConfigGeneral.AllowEarlyCompletion); + SetCheckboxValue(WIDX_REAL_NAME_CHECKBOX, Config::Get().general.ShowRealNamesOfGuests); + SetCheckboxValue(WIDX_AUTO_STAFF_PLACEMENT, Config::Get().general.AutoStaffPlacement); + SetCheckboxValue(WIDX_AUTO_OPEN_SHOPS, Config::Get().general.AutoOpenShops); + SetCheckboxValue(WIDX_ALLOW_EARLY_COMPLETION, Config::Get().general.AllowEarlyCompletion); - if (gConfigGeneral.ScenarioSelectMode == SCENARIO_SELECT_MODE_DIFFICULTY) + if (Config::Get().general.ScenarioSelectMode == SCENARIO_SELECT_MODE_DIFFICULTY) widgets[WIDX_SCENARIO_GROUPING].text = STR_OPTIONS_SCENARIO_DIFFICULTY; else widgets[WIDX_SCENARIO_GROUPING].text = STR_OPTIONS_SCENARIO_ORIGIN; - SetCheckboxValue(WIDX_SCENARIO_UNLOCKING, gConfigGeneral.ScenarioUnlockingEnabled); + SetCheckboxValue(WIDX_SCENARIO_UNLOCKING, Config::Get().general.ScenarioUnlockingEnabled); - if (gConfigGeneral.ScenarioSelectMode == SCENARIO_SELECT_MODE_ORIGIN) + if (Config::Get().general.ScenarioSelectMode == SCENARIO_SELECT_MODE_ORIGIN) { disabled_widgets &= ~(1uLL << WIDX_SCENARIO_UNLOCKING); } @@ -1870,8 +1875,8 @@ static Widget *window_options_page_widgets[] = { disabled_widgets |= (1uLL << WIDX_SCENARIO_UNLOCKING); } - widgets[WIDX_DEFAULT_INSPECTION_INTERVAL].text = RideInspectionIntervalNames[gConfigGeneral - .DefaultInspectionInterval]; + widgets[WIDX_DEFAULT_INSPECTION_INTERVAL].text = RideInspectionIntervalNames + [Config::Get().general.DefaultInspectionInterval]; } #pragma endregion @@ -1882,23 +1887,23 @@ static Widget *window_options_page_widgets[] = { switch (widgetIndex) { case WIDX_DEBUGGING_TOOLS: - gConfigGeneral.DebuggingTools ^= 1; - ConfigSaveDefault(); + Config::Get().general.DebuggingTools ^= 1; + Config::Save(); GfxInvalidateScreen(); break; case WIDX_SAVE_PLUGIN_DATA_CHECKBOX: - gConfigGeneral.SavePluginData ^= 1; - ConfigSaveDefault(); + Config::Get().general.SavePluginData ^= 1; + Config::Save(); Invalidate(); break; case WIDX_STAY_CONNECTED_AFTER_DESYNC: - gConfigNetwork.StayConnected = !gConfigNetwork.StayConnected; - ConfigSaveDefault(); + Config::Get().network.StayConnected = !Config::Get().network.StayConnected; + Config::Save(); Invalidate(); break; case WIDX_ALWAYS_NATIVE_LOADSAVE: - gConfigGeneral.UseNativeBrowseDialog = !gConfigGeneral.UseNativeBrowseDialog; - ConfigSaveDefault(); + Config::Get().general.UseNativeBrowseDialog = !Config::Get().general.UseNativeBrowseDialog; + Config::Save(); Invalidate(); break; case WIDX_PATH_TO_RCT1_BUTTON: @@ -1914,9 +1919,9 @@ static Widget *window_options_page_widgets[] = { { if (CsgAtLocationIsUsable(rct1path)) { - gConfigGeneral.RCT1Path = std::move(rct1path); - gConfigInterface.ScenarioselectLastTab = 0; - ConfigSaveDefault(); + Config::Get().general.RCT1Path = std::move(rct1path); + Config::Get().interface.ScenarioselectLastTab = 0; + Config::Save(); ContextShowError(STR_RESTART_REQUIRED, STR_NONE, {}); } else @@ -1938,10 +1943,10 @@ static Widget *window_options_page_widgets[] = { break; } case WIDX_PATH_TO_RCT1_CLEAR: - if (!gConfigGeneral.RCT1Path.empty()) + if (!Config::Get().general.RCT1Path.empty()) { - gConfigGeneral.RCT1Path.clear(); - ConfigSaveDefault(); + Config::Get().general.RCT1Path.clear(); + Config::Save(); } Invalidate(); break; @@ -1965,20 +1970,20 @@ static Widget *window_options_page_widgets[] = { } ShowDropdown(widget, AUTOSAVE_NEVER + 1); - Dropdown::SetChecked(gConfigGeneral.AutosaveFrequency, true); + Dropdown::SetChecked(Config::Get().general.AutosaveFrequency, true); break; case WIDX_AUTOSAVE_AMOUNT_UP: - gConfigGeneral.AutosaveAmount += 1; - ConfigSaveDefault(); + Config::Get().general.AutosaveAmount += 1; + Config::Save(); InvalidateWidget(WIDX_AUTOSAVE_FREQUENCY); InvalidateWidget(WIDX_AUTOSAVE_FREQUENCY_DROPDOWN); InvalidateWidget(WIDX_AUTOSAVE_AMOUNT); break; case WIDX_AUTOSAVE_AMOUNT_DOWN: - if (gConfigGeneral.AutosaveAmount > 1) + if (Config::Get().general.AutosaveAmount > 1) { - gConfigGeneral.AutosaveAmount -= 1; - ConfigSaveDefault(); + Config::Get().general.AutosaveAmount -= 1; + Config::Save(); InvalidateWidget(WIDX_AUTOSAVE_FREQUENCY); InvalidateWidget(WIDX_AUTOSAVE_FREQUENCY_DROPDOWN); InvalidateWidget(WIDX_AUTOSAVE_AMOUNT); @@ -1991,10 +1996,10 @@ static Widget *window_options_page_widgets[] = { switch (widgetIndex) { case WIDX_AUTOSAVE_FREQUENCY_DROPDOWN: - if (dropdownIndex != gConfigGeneral.AutosaveFrequency) + if (dropdownIndex != Config::Get().general.AutosaveFrequency) { - gConfigGeneral.AutosaveFrequency = static_cast(dropdownIndex); - ConfigSaveDefault(); + Config::Get().general.AutosaveFrequency = static_cast(dropdownIndex); + Config::Save(); Invalidate(); } break; @@ -2003,23 +2008,23 @@ static Widget *window_options_page_widgets[] = { void AdvancedPrepareDraw() { - SetCheckboxValue(WIDX_DEBUGGING_TOOLS, gConfigGeneral.DebuggingTools); - SetCheckboxValue(WIDX_SAVE_PLUGIN_DATA_CHECKBOX, gConfigGeneral.SavePluginData); - SetCheckboxValue(WIDX_STAY_CONNECTED_AFTER_DESYNC, gConfigNetwork.StayConnected); - SetCheckboxValue(WIDX_ALWAYS_NATIVE_LOADSAVE, gConfigGeneral.UseNativeBrowseDialog); - widgets[WIDX_AUTOSAVE_FREQUENCY].text = AutosaveNames[gConfigGeneral.AutosaveFrequency]; + SetCheckboxValue(WIDX_DEBUGGING_TOOLS, Config::Get().general.DebuggingTools); + SetCheckboxValue(WIDX_SAVE_PLUGIN_DATA_CHECKBOX, Config::Get().general.SavePluginData); + SetCheckboxValue(WIDX_STAY_CONNECTED_AFTER_DESYNC, Config::Get().network.StayConnected); + SetCheckboxValue(WIDX_ALWAYS_NATIVE_LOADSAVE, Config::Get().general.UseNativeBrowseDialog); + widgets[WIDX_AUTOSAVE_FREQUENCY].text = AutosaveNames[Config::Get().general.AutosaveFrequency]; } void AdvancedDraw(DrawPixelInfo& dpi) { auto ft = Formatter(); - ft.Add(static_cast(gConfigGeneral.AutosaveAmount)); + ft.Add(static_cast(Config::Get().general.AutosaveAmount)); DrawTextBasic( dpi, windowPos + ScreenCoordsXY{ widgets[WIDX_AUTOSAVE_AMOUNT].left + 1, widgets[WIDX_AUTOSAVE_AMOUNT].top + 1 }, STR_WINDOW_COLOUR_2_COMMA32, ft, { colours[1] }); - const auto normalisedPath = Platform::StrDecompToPrecomp(gConfigGeneral.RCT1Path); + const auto normalisedPath = Platform::StrDecompToPrecomp(Config::Get().general.RCT1Path); ft = Formatter(); ft.Add(normalisedPath.c_str()); @@ -2038,14 +2043,14 @@ static Widget *window_options_page_widgets[] = { { if (widgetIndex == WIDX_PATH_TO_RCT1_BUTTON) { - if (gConfigGeneral.RCT1Path.empty()) + if (Config::Get().general.RCT1Path.empty()) { // No tooltip if the path is empty return { STR_NONE, {} }; } auto ft = Formatter(); - ft.Add(gConfigGeneral.RCT1Path.c_str()); + ft.Add(Config::Get().general.RCT1Path.c_str()); return { fallback, ft }; } return { fallback, {} }; @@ -2127,7 +2132,7 @@ static Widget *window_options_page_widgets[] = { void UpdateHeightMarkers() { - ConfigSaveDefault(); + Config::Save(); GfxInvalidateScreen(); } diff --git a/src/openrct2-ui/windows/Park.cpp b/src/openrct2-ui/windows/Park.cpp index 02a5bfebf4..d74ecc6657 100644 --- a/src/openrct2-ui/windows/Park.cpp +++ b/src/openrct2-ui/windows/Park.cpp @@ -632,7 +632,7 @@ static constexpr WindowParkAward _parkAwards[] = { int32_t viewportFlags{}; if (viewport == nullptr) { - viewportFlags = gConfigGeneral.AlwaysShowGridlines ? VIEWPORT_FLAG_GRIDLINES : VIEWPORT_FLAG_NONE; + viewportFlags = Config::Get().general.AlwaysShowGridlines ? VIEWPORT_FLAG_GRIDLINES : VIEWPORT_FLAG_NONE; } else { @@ -983,7 +983,7 @@ static constexpr WindowParkAward _parkAwards[] = { // Draw park size auto parkSize = gameState.Park.Size * 10; auto stringIndex = STR_PARK_SIZE_METRIC_LABEL; - if (gConfigGeneral.MeasurementFormat == MeasurementFormat::Imperial) + if (Config::Get().general.MeasurementFormat == MeasurementFormat::Imperial) { stringIndex = STR_PARK_SIZE_IMPERIAL_LABEL; parkSize = SquaredMetresToSquaredFeet(parkSize); diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index b904ec1955..f5e5602a37 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -1468,7 +1468,7 @@ static_assert(std::size(RatingNames) == 6); newViewportFlags = viewport->flags; RemoveViewport(); } - else if (gConfigGeneral.AlwaysShowGridlines) + else if (Config::Get().general.AlwaysShowGridlines) { newViewportFlags |= VIEWPORT_FLAG_GRIDLINES; } @@ -3940,7 +3940,7 @@ static_assert(std::size(RatingNames) == 6); AnchorBorderWidgets(); WindowAlignTabs(this, WIDX_TAB_1, WIDX_TAB_10); - if (gConfigGeneral.DebuggingTools && NetworkGetMode() == NETWORK_MODE_NONE) + if (Config::Get().general.DebuggingTools && NetworkGetMode() == NETWORK_MODE_NONE) { widgets[WIDX_FORCE_BREAKDOWN].type = WindowWidgetType::FlatBtn; } diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index a3383ddfa1..7a6d0f2d4c 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -270,7 +270,7 @@ static Widget _rideConstructionWidgets[] = { if (RideTryGetOriginElement(*currentRide, nullptr)) { // Auto open shops if required. - if (currentRide->mode == RideMode::ShopStall && gConfigGeneral.AutoOpenShops) + if (currentRide->mode == RideMode::ShopStall && Config::Get().general.AutoOpenShops) { // HACK: Until we find a good a way to defer the game command for opening the shop, stop this // from getting stuck in an infinite loop as opening the currentRide will try to close this window diff --git a/src/openrct2-ui/windows/SavePrompt.cpp b/src/openrct2-ui/windows/SavePrompt.cpp index d4c80757e2..d2344e9c2b 100644 --- a/src/openrct2-ui/windows/SavePrompt.cpp +++ b/src/openrct2-ui/windows/SavePrompt.cpp @@ -209,7 +209,7 @@ static constexpr StringId window_save_prompt_labels[][2] = { return nullptr; } - if (!gConfigGeneral.ConfirmationPrompt) + if (!Config::Get().general.ConfirmationPrompt) { /* game_load_or_quit_no_save_prompt() will exec requested task and close this window * immediately again. diff --git a/src/openrct2-ui/windows/ScenarioSelect.cpp b/src/openrct2-ui/windows/ScenarioSelect.cpp index bcc966df15..b7cbb22b0e 100644 --- a/src/openrct2-ui/windows/ScenarioSelect.cpp +++ b/src/openrct2-ui/windows/ScenarioSelect.cpp @@ -151,8 +151,8 @@ static Widget _scenarioSelectWidgets[] = { { selected_tab = widgetIndex - 4; _highlightedScenario = nullptr; - gConfigInterface.ScenarioselectLastTab = selected_tab; - ConfigSaveDefault(); + Config::Get().interface.ScenarioselectLastTab = selected_tab; + Config::Save(); InitialiseListItems(); Invalidate(); OnResize(); @@ -180,7 +180,7 @@ static Widget _scenarioSelectWidgets[] = { continue; auto ft = Formatter(); - if (gConfigGeneral.ScenarioSelectMode == SCENARIO_SELECT_MODE_ORIGIN) + if (Config::Get().general.ScenarioSelectMode == SCENARIO_SELECT_MODE_ORIGIN) { ft.Add(kScenarioOriginStringIds[i]); } @@ -219,7 +219,7 @@ static Widget _scenarioSelectWidgets[] = { } // Scenario path - if (gConfigGeneral.DebuggingTools) + if (Config::Get().general.DebuggingTools) { const auto shortPath = ShortenPath(scenario->Path, width - 6 - TabWidth, FontStyle::Medium); @@ -282,7 +282,7 @@ static Widget _scenarioSelectWidgets[] = { pressed_widgets |= 1LL << (selected_tab + WIDX_TAB1); ResizeFrameWithPage(); - const int32_t bottomMargin = gConfigGeneral.DebuggingTools ? 17 : 5; + const int32_t bottomMargin = Config::Get().general.DebuggingTools ? 17 : 5; widgets[WIDX_SCENARIOLIST].right = width - 179; widgets[WIDX_SCENARIOLIST].bottom = height - bottomMargin; } @@ -538,7 +538,7 @@ static Widget _scenarioSelectWidgets[] = { // Category heading StringId headingStringId = STR_NONE; - if (gConfigGeneral.ScenarioSelectMode == SCENARIO_SELECT_MODE_ORIGIN) + if (Config::Get().general.ScenarioSelectMode == SCENARIO_SELECT_MODE_ORIGIN) { if (selected_tab != static_cast(ScenarioSource::Real) && currentHeading != scenario->Category) { @@ -618,7 +618,7 @@ static Widget _scenarioSelectWidgets[] = { bool megaParkLocked = (rct1CompletedScenarios & rct1RequiredCompletedScenarios) != rct1RequiredCompletedScenarios; _listItems[megaParkListItemIndex.value()].scenario.is_locked = megaParkLocked; - if (megaParkLocked && gConfigGeneral.ScenarioHideMegaPark) + if (megaParkLocked && Config::Get().general.ScenarioHideMegaPark) { // Remove mega park _listItems.pop_back(); @@ -644,7 +644,7 @@ static Widget _scenarioSelectWidgets[] = { bool IsScenarioVisible(const ScenarioIndexEntry& scenario) const { - if (gConfigGeneral.ScenarioSelectMode == SCENARIO_SELECT_MODE_ORIGIN) + if (Config::Get().general.ScenarioSelectMode == SCENARIO_SELECT_MODE_ORIGIN) { if (static_cast(scenario.SourceGame) != selected_tab) { @@ -668,9 +668,9 @@ static Widget _scenarioSelectWidgets[] = { bool IsLockingEnabled() const { - if (gConfigGeneral.ScenarioSelectMode != SCENARIO_SELECT_MODE_ORIGIN) + if (Config::Get().general.ScenarioSelectMode != SCENARIO_SELECT_MODE_ORIGIN) return false; - if (!gConfigGeneral.ScenarioUnlockingEnabled) + if (!Config::Get().general.ScenarioUnlockingEnabled) return false; if (selected_tab >= 6) return false; @@ -685,7 +685,7 @@ static Widget _scenarioSelectWidgets[] = { for (size_t i = 0; i < numScenarios; i++) { const ScenarioIndexEntry* scenario = ScenarioRepositoryGetByIndex(i); - if (gConfigGeneral.ScenarioSelectMode == SCENARIO_SELECT_MODE_ORIGIN) + if (Config::Get().general.ScenarioSelectMode == SCENARIO_SELECT_MODE_ORIGIN) { showPages |= 1 << static_cast(scenario->SourceGame); } @@ -700,9 +700,9 @@ static Widget _scenarioSelectWidgets[] = { } } - if (showPages & (1 << gConfigInterface.ScenarioselectLastTab)) + if (showPages & (1 << Config::Get().interface.ScenarioselectLastTab)) { - selected_tab = gConfigInterface.ScenarioselectLastTab; + selected_tab = Config::Get().interface.ScenarioselectLastTab; } else { diff --git a/src/openrct2-ui/windows/ServerList.cpp b/src/openrct2-ui/windows/ServerList.cpp index 3809537699..b775b8a2d3 100644 --- a/src/openrct2-ui/windows/ServerList.cpp +++ b/src/openrct2-ui/windows/ServerList.cpp @@ -94,7 +94,7 @@ static Widget _serverListWidgets[] = { void OnOpen() override { - _playerName = gConfigNetwork.PlayerName; + _playerName = Config::Get().network.PlayerName; widgets = _serverListWidgets; _serverListWidgets[WIDX_PLAYER_NAME_INPUT].string = const_cast(_playerName.c_str()); InitScrollWidgets(); @@ -120,7 +120,7 @@ static Widget _serverListWidgets[] = { { _serverList = {}; _fetchFuture = {}; - ConfigSaveDefault(); + Config::Save(); } void OnMouseUp(WidgetIndex widgetIndex) override @@ -284,7 +284,7 @@ static Widget _serverListWidgets[] = { return; _playerName = temp; - gConfigNetwork.PlayerName = _playerName; + Config::Get().network.PlayerName = _playerName; widgets[WIDX_PLAYER_NAME_INPUT].string = const_cast(_playerName.c_str()); InvalidateWidget(WIDX_PLAYER_NAME_INPUT); diff --git a/src/openrct2-ui/windows/ServerStart.cpp b/src/openrct2-ui/windows/ServerStart.cpp index e7fa38135c..a796d08941 100644 --- a/src/openrct2-ui/windows/ServerStart.cpp +++ b/src/openrct2-ui/windows/ServerStart.cpp @@ -82,10 +82,10 @@ static Widget _windowServerStartWidgets[] = { page = 0; list_information_type = 0; - snprintf(_port, 7, "%u", gConfigNetwork.DefaultPort); - SafeStrCpy(_name, gConfigNetwork.ServerName.c_str(), sizeof(_name)); - SafeStrCpy(_description, gConfigNetwork.ServerDescription.c_str(), sizeof(_description)); - SafeStrCpy(_greeting, gConfigNetwork.ServerGreeting.c_str(), sizeof(_greeting)); + snprintf(_port, 7, "%u", Config::Get().network.DefaultPort); + SafeStrCpy(_name, Config::Get().network.ServerName.c_str(), sizeof(_name)); + SafeStrCpy(_description, Config::Get().network.ServerDescription.c_str(), sizeof(_description)); + SafeStrCpy(_greeting, Config::Get().network.ServerGreeting.c_str(), sizeof(_greeting)); } void OnMouseUp(WidgetIndex widgetIndex) override { @@ -110,24 +110,24 @@ static Widget _windowServerStartWidgets[] = { WindowStartTextbox(*this, widgetIndex, _password, 32); break; case WIDX_MAXPLAYERS_INCREASE: - if (gConfigNetwork.Maxplayers < 255) + if (Config::Get().network.Maxplayers < 255) { - gConfigNetwork.Maxplayers++; + Config::Get().network.Maxplayers++; } - ConfigSaveDefault(); + Config::Save(); Invalidate(); break; case WIDX_MAXPLAYERS_DECREASE: - if (gConfigNetwork.Maxplayers > 1) + if (Config::Get().network.Maxplayers > 1) { - gConfigNetwork.Maxplayers--; + Config::Get().network.Maxplayers--; } - ConfigSaveDefault(); + Config::Save(); Invalidate(); break; case WIDX_ADVERTISE_CHECKBOX: - gConfigNetwork.Advertise = !gConfigNetwork.Advertise; - ConfigSaveDefault(); + Config::Get().network.Advertise = !Config::Get().network.Advertise; + Config::Save(); Invalidate(); break; case WIDX_START_SERVER: @@ -147,10 +147,10 @@ static Widget _windowServerStartWidgets[] = { { ColourSchemeUpdateByClass(this, WindowClass::ServerList); - WidgetSetCheckboxValue(*this, WIDX_ADVERTISE_CHECKBOX, gConfigNetwork.Advertise); + WidgetSetCheckboxValue(*this, WIDX_ADVERTISE_CHECKBOX, Config::Get().network.Advertise); auto ft = Formatter::Common(); ft.Increment(18); - ft.Add(gConfigNetwork.Maxplayers); + ft.Add(Config::Get().network.Maxplayers); } void OnUpdate() override { @@ -180,8 +180,8 @@ static Widget _windowServerStartWidgets[] = { tempPort = atoi(_port); if (tempPort > 0) { - gConfigNetwork.DefaultPort = tempPort; - ConfigSaveDefault(); + Config::Get().network.DefaultPort = tempPort; + Config::Save(); } WidgetInvalidate(*this, WIDX_PORT_INPUT); @@ -195,8 +195,8 @@ static Widget _windowServerStartWidgets[] = { // Don't allow empty server names if (_name[0] != '\0') { - gConfigNetwork.ServerName = _name; - ConfigSaveDefault(); + Config::Get().network.ServerName = _name; + Config::Save(); } WidgetInvalidate(*this, WIDX_NAME_INPUT); @@ -206,8 +206,8 @@ static Widget _windowServerStartWidgets[] = { return; SafeStrCpy(_description, temp.c_str(), sizeof(_description)); - gConfigNetwork.ServerDescription = _description; - ConfigSaveDefault(); + Config::Get().network.ServerDescription = _description; + Config::Save(); WidgetInvalidate(*this, WIDX_DESCRIPTION_INPUT); break; @@ -216,8 +216,8 @@ static Widget _windowServerStartWidgets[] = { return; SafeStrCpy(_greeting, temp.c_str(), sizeof(_greeting)); - gConfigNetwork.ServerGreeting = _greeting; - ConfigSaveDefault(); + Config::Get().network.ServerGreeting = _greeting; + Config::Save(); WidgetInvalidate(*this, WIDX_GREETING_INPUT); break; @@ -266,7 +266,7 @@ static Widget _windowServerStartWidgets[] = { GameNotifyMapChange(); if (GetContext()->LoadParkFromFile(path, false, true)) { - NetworkBeginServer(gConfigNetwork.DefaultPort, gConfigNetwork.ListenAddress); + NetworkBeginServer(Config::Get().network.DefaultPort, Config::Get().network.ListenAddress); } } @@ -276,7 +276,7 @@ static Widget _windowServerStartWidgets[] = { { GameNotifyMapChange(); GetContext()->LoadParkFromFile(path); - NetworkBeginServer(gConfigNetwork.DefaultPort, gConfigNetwork.ListenAddress); + NetworkBeginServer(Config::Get().network.DefaultPort, Config::Get().network.ListenAddress); } } }; diff --git a/src/openrct2-ui/windows/Sign.cpp b/src/openrct2-ui/windows/Sign.cpp index 5e21545df7..eedbf51dc5 100644 --- a/src/openrct2-ui/windows/Sign.cpp +++ b/src/openrct2-ui/windows/Sign.cpp @@ -139,7 +139,7 @@ static Widget _signWidgets[] = { this, windowPos + ScreenCoordsXY{ viewportWidget.left + 1, viewportWidget.top + 1 }, viewportWidget.width() - 1, viewportWidget.height() - 1, Focus(CoordsXYZ{ signViewPosition, viewZ })); - viewport->flags = gConfigGeneral.AlwaysShowGridlines ? VIEWPORT_FLAG_GRIDLINES : VIEWPORT_FLAG_NONE; + viewport->flags = Config::Get().general.AlwaysShowGridlines ? VIEWPORT_FLAG_GRIDLINES : VIEWPORT_FLAG_NONE; Invalidate(); return true; @@ -317,7 +317,7 @@ static Widget _signWidgets[] = { this, windowPos + ScreenCoordsXY{ viewportWidget->left + 1, viewportWidget->top + 1 }, viewportWidget->width() - 1, viewportWidget->height() - 1, Focus(CoordsXYZ{ signViewPos })); if (viewport != nullptr) - viewport->flags = gConfigGeneral.AlwaysShowGridlines ? VIEWPORT_FLAG_GRIDLINES : VIEWPORT_FLAG_NONE; + viewport->flags = Config::Get().general.AlwaysShowGridlines ? VIEWPORT_FLAG_GRIDLINES : VIEWPORT_FLAG_NONE; Invalidate(); } diff --git a/src/openrct2-ui/windows/Staff.cpp b/src/openrct2-ui/windows/Staff.cpp index f9eceef08e..f8c5fb8ea7 100644 --- a/src/openrct2-ui/windows/Staff.cpp +++ b/src/openrct2-ui/windows/Staff.cpp @@ -1157,7 +1157,7 @@ static Widget _staffOptionsWidgets[] = { else { viewport_flags = 0; - if (gConfigGeneral.AlwaysShowGridlines) + if (Config::Get().general.AlwaysShowGridlines) viewport_flags |= VIEWPORT_FLAG_GRIDLINES; } diff --git a/src/openrct2-ui/windows/StaffList.cpp b/src/openrct2-ui/windows/StaffList.cpp index 3ec1d923ea..f9abb1fed2 100644 --- a/src/openrct2-ui/windows/StaffList.cpp +++ b/src/openrct2-ui/windows/StaffList.cpp @@ -517,7 +517,7 @@ static Widget _staffListWidgets[] = { */ void HireNewMember(StaffType staffType, EntertainerCostume entertainerType) { - bool autoPosition = gConfigGeneral.AutoStaffPlacement; + bool autoPosition = Config::Get().general.AutoStaffPlacement; if (gInputPlaceObjectModifier & PLACE_OBJECT_MODIFIER_SHIFT_Z) { autoPosition = autoPosition ^ 1; @@ -528,7 +528,7 @@ static Widget _staffListWidgets[] = { if (staffType == StaffType::Handyman) { staffOrders = STAFF_ORDERS_SWEEPING | STAFF_ORDERS_WATER_FLOWERS | STAFF_ORDERS_EMPTY_BINS; - if (gConfigGeneral.HandymenMowByDefault) + if (Config::Get().general.HandymenMowByDefault) { staffOrders |= STAFF_ORDERS_MOWING; } diff --git a/src/openrct2-ui/windows/TopToolbar.cpp b/src/openrct2-ui/windows/TopToolbar.cpp index b5f4492d07..e038f352ee 100644 --- a/src/openrct2-ui/windows/TopToolbar.cpp +++ b/src/openrct2-ui/windows/TopToolbar.cpp @@ -862,7 +862,7 @@ static Widget _topToolbarWidgets[] = { MapInvalidateSelectionRect(); MapInvalidateMapSelectionTiles(); - if (gConfigGeneral.VirtualFloorStyle != VirtualFloorStyles::Off) + if (Config::Get().general.VirtualFloorStyle != VirtualFloorStyles::Off) { VirtualFloorInvalidate(); } @@ -1795,7 +1795,7 @@ static Widget _topToolbarWidgets[] = { rotation -= GetCurrentRotation(); rotation &= 0x3; - if (gConfigGeneral.VirtualFloorStyle != VirtualFloorStyles::Off) + if (Config::Get().general.VirtualFloorStyle != VirtualFloorStyles::Off) { VirtualFloorSetHeight(gSceneryPlaceZ); } @@ -1879,7 +1879,7 @@ static Widget _topToolbarWidgets[] = { rotation -= GetCurrentRotation(); rotation &= 0x3; - if (gConfigGeneral.VirtualFloorStyle != VirtualFloorStyles::Off) + if (Config::Get().general.VirtualFloorStyle != VirtualFloorStyles::Off) { VirtualFloorSetHeight(gSceneryPlaceZ); } @@ -1913,7 +1913,7 @@ static Widget _topToolbarWidgets[] = { return; } - if (gConfigGeneral.VirtualFloorStyle != VirtualFloorStyles::Off) + if (Config::Get().general.VirtualFloorStyle != VirtualFloorStyles::Off) { VirtualFloorSetHeight(gSceneryPlaceZ); } @@ -2003,7 +2003,7 @@ static Widget _topToolbarWidgets[] = { if (gridPos.IsNull()) return; - if (gConfigGeneral.VirtualFloorStyle != VirtualFloorStyles::Off) + if (Config::Get().general.VirtualFloorStyle != VirtualFloorStyles::Off) { VirtualFloorSetHeight(gSceneryPlaceZ); } @@ -2103,7 +2103,7 @@ static Widget _topToolbarWidgets[] = { rotation -= GetCurrentRotation(); rotation &= 0x3; - if (gConfigGeneral.VirtualFloorStyle != VirtualFloorStyles::Off) + if (Config::Get().general.VirtualFloorStyle != VirtualFloorStyles::Off) { VirtualFloorSetHeight(gSceneryPlaceZ); } @@ -2151,7 +2151,7 @@ static Widget _topToolbarWidgets[] = { } } - if (gConfigGeneral.VirtualFloorStyle != VirtualFloorStyles::Off) + if (Config::Get().general.VirtualFloorStyle != VirtualFloorStyles::Off) { VirtualFloorSetHeight(gSceneryPlaceZ); } @@ -2945,26 +2945,27 @@ static Widget _topToolbarWidgets[] = { widgets[WIDX_RESEARCH].type = WindowWidgetType::TrnBtn; widgets[WIDX_FASTFORWARD].type = WindowWidgetType::TrnBtn; widgets[WIDX_CHEATS].type = WindowWidgetType::TrnBtn; - widgets[WIDX_DEBUG].type = gConfigGeneral.DebuggingTools ? WindowWidgetType::TrnBtn : WindowWidgetType::Empty; + widgets[WIDX_DEBUG].type = Config::Get().general.DebuggingTools ? WindowWidgetType::TrnBtn + : WindowWidgetType::Empty; widgets[WIDX_NEWS].type = WindowWidgetType::TrnBtn; widgets[WIDX_NETWORK].type = WindowWidgetType::TrnBtn; - if (!gConfigInterface.ToolbarShowMute) + if (!Config::Get().interface.ToolbarShowMute) widgets[WIDX_MUTE].type = WindowWidgetType::Empty; - if (!gConfigInterface.ToolbarShowChat) + if (!Config::Get().interface.ToolbarShowChat) widgets[WIDX_CHAT].type = WindowWidgetType::Empty; - if (!gConfigInterface.ToolbarShowResearch) + if (!Config::Get().interface.ToolbarShowResearch) widgets[WIDX_RESEARCH].type = WindowWidgetType::Empty; - if (!gConfigInterface.ToolbarShowCheats) + if (!Config::Get().interface.ToolbarShowCheats) widgets[WIDX_CHEATS].type = WindowWidgetType::Empty; - if (!gConfigInterface.ToolbarShowNews) + if (!Config::Get().interface.ToolbarShowNews) widgets[WIDX_NEWS].type = WindowWidgetType::Empty; - if (!gConfigInterface.ToolbarShowZoom) + if (!Config::Get().interface.ToolbarShowZoom) { widgets[WIDX_ZOOM_IN].type = WindowWidgetType::Empty; widgets[WIDX_ZOOM_OUT].type = WindowWidgetType::Empty; @@ -2975,7 +2976,7 @@ static Widget _topToolbarWidgets[] = { widgets[WIDX_PAUSE].type = WindowWidgetType::Empty; } - if ((GetGameState().Park.Flags & PARK_FLAGS_NO_MONEY) || !gConfigInterface.ToolbarShowFinances) + if ((GetGameState().Park.Flags & PARK_FLAGS_NO_MONEY) || !Config::Get().interface.ToolbarShowFinances) widgets[WIDX_FINANCES].type = WindowWidgetType::Empty; if (gScreenFlags & SCREEN_FLAGS_EDITOR) @@ -3362,7 +3363,7 @@ static Widget _topToolbarWidgets[] = { auto* mainViewport = WindowGetMain()->viewport; if (mainViewport->flags & VIEWPORT_FLAG_UNDERGROUND_INSIDE) Dropdown::SetChecked(DDIDX_UNDERGROUND_INSIDE, true); - if (gConfigGeneral.TransparentWater) + if (Config::Get().general.TransparentWater) Dropdown::SetChecked(DDIDX_TRANSPARENT_WATER, true); if (mainViewport->flags & VIEWPORT_FLAG_HIDE_BASE) Dropdown::SetChecked(DDIDX_HIDE_BASE, true); @@ -3415,8 +3416,8 @@ static Widget _topToolbarWidgets[] = { w->viewport->flags ^= VIEWPORT_FLAG_UNDERGROUND_INSIDE; break; case DDIDX_TRANSPARENT_WATER: - gConfigGeneral.TransparentWater ^= 1; - ConfigSaveDefault(); + Config::Get().general.TransparentWater ^= 1; + Config::Save(); break; case DDIDX_HIDE_BASE: w->viewport->flags ^= VIEWPORT_FLAG_HIDE_BASE; @@ -3566,7 +3567,7 @@ static Widget _topToolbarWidgets[] = { gDropdownItems[1].Format = STR_TOGGLE_OPTION; gDropdownItems[2].Format = STR_TOGGLE_OPTION; gDropdownItems[3].Format = STR_TOGGLE_OPTION; - if (gConfigGeneral.DebuggingTools) + if (Config::Get().general.DebuggingTools) { gDropdownItems[4].Format = STR_EMPTY; gDropdownItems[5].Format = STR_TOGGLE_OPTION; @@ -3592,7 +3593,7 @@ static Widget _topToolbarWidgets[] = { Dropdown::SetChecked(5, true); } - if (gConfigGeneral.DebuggingTools) + if (Config::Get().general.DebuggingTools) { gDropdownDefaultIndex = (gGameSpeed == 8 ? 0 : gGameSpeed); } diff --git a/src/openrct2-ui/windows/TrackList.cpp b/src/openrct2-ui/windows/TrackList.cpp index 9ad501a3e7..2f9a7cade7 100644 --- a/src/openrct2-ui/windows/TrackList.cpp +++ b/src/openrct2-ui/windows/TrackList.cpp @@ -422,7 +422,8 @@ static Widget _trackListWidgets[] = { } // When debugging tools are on, shift everything up a bit to make room for displaying the path. - const int32_t bottomMargin = gConfigGeneral.DebuggingTools ? (WINDOW_PADDING + DEBUG_PATH_HEIGHT) : WINDOW_PADDING; + const int32_t bottomMargin = Config::Get().general.DebuggingTools ? (WINDOW_PADDING + DEBUG_PATH_HEIGHT) + : WINDOW_PADDING; widgets[WIDX_TRACK_LIST].bottom = height - bottomMargin; widgets[WIDX_ROTATE].bottom = height - bottomMargin; widgets[WIDX_ROTATE].top = widgets[WIDX_ROTATE].bottom - ROTATE_AND_SCENERY_BUTTON_SIZE; @@ -469,7 +470,7 @@ static Widget _trackListWidgets[] = { u8string path = _trackDesigns[trackIndex].path; // Show track file path (in debug mode) - if (gConfigGeneral.DebuggingTools) + if (Config::Get().general.DebuggingTools) { const auto shortPath = ShortenPath(path, width, FontStyle::Medium); auto ft = Formatter(); diff --git a/src/openrct2-ui/windows/Transparency.cpp b/src/openrct2-ui/windows/Transparency.cpp index 6b817e6bbf..57e18fe124 100644 --- a/src/openrct2-ui/windows/Transparency.cpp +++ b/src/openrct2-ui/windows/Transparency.cpp @@ -236,13 +236,13 @@ static Widget _transparancyWidgets[] = void SaveInConfig(uint32_t wflags) { - gConfigGeneral.InvisibleRides = wflags & VIEWPORT_FLAG_INVISIBLE_RIDES; - gConfigGeneral.InvisibleVehicles = wflags & VIEWPORT_FLAG_INVISIBLE_VEHICLES; - gConfigGeneral.InvisibleScenery = wflags & VIEWPORT_FLAG_INVISIBLE_SCENERY; - gConfigGeneral.InvisibleTrees = wflags & VIEWPORT_FLAG_INVISIBLE_VEGETATION; - gConfigGeneral.InvisiblePaths = wflags & VIEWPORT_FLAG_INVISIBLE_PATHS; - gConfigGeneral.InvisibleSupports = wflags & VIEWPORT_FLAG_INVISIBLE_SUPPORTS; - ConfigSaveDefault(); + Config::Get().general.InvisibleRides = wflags & VIEWPORT_FLAG_INVISIBLE_RIDES; + Config::Get().general.InvisibleVehicles = wflags & VIEWPORT_FLAG_INVISIBLE_VEHICLES; + Config::Get().general.InvisibleScenery = wflags & VIEWPORT_FLAG_INVISIBLE_SCENERY; + Config::Get().general.InvisibleTrees = wflags & VIEWPORT_FLAG_INVISIBLE_VEGETATION; + Config::Get().general.InvisiblePaths = wflags & VIEWPORT_FLAG_INVISIBLE_PATHS; + Config::Get().general.InvisibleSupports = wflags & VIEWPORT_FLAG_INVISIBLE_SUPPORTS; + Config::Save(); } void OnResize() override diff --git a/src/openrct2-ui/windows/ViewClipping.cpp b/src/openrct2-ui/windows/ViewClipping.cpp index 513e5c463d..9a570dd4fb 100644 --- a/src/openrct2-ui/windows/ViewClipping.cpp +++ b/src/openrct2-ui/windows/ViewClipping.cpp @@ -299,7 +299,7 @@ static Widget _viewClippingWidgets[] = { case DisplayType::DisplayUnits: { // Print the value in the configured height label type: - if (gConfigGeneral.ShowHeightAsUnits) + if (Config::Get().general.ShowHeightAsUnits) { // Height label is Units. auto ft = Formatter(); @@ -312,7 +312,7 @@ static Widget _viewClippingWidgets[] = { { // Height label is Real Values. // Print the value in the configured measurement units. - switch (gConfigGeneral.MeasurementFormat) + switch (Config::Get().general.MeasurementFormat) { case MeasurementFormat::Metric: case MeasurementFormat::SI: diff --git a/src/openrct2/AssetPackManager.cpp b/src/openrct2/AssetPackManager.cpp index 193be7c807..1cc0dd278b 100644 --- a/src/openrct2/AssetPackManager.cpp +++ b/src/openrct2/AssetPackManager.cpp @@ -160,7 +160,7 @@ void AssetPackManager::LoadEnabledAssetPacks() { // Re-order asset packs std::vector> newAssetPacks; - EnumerateCommaSeparatedList(gConfigGeneral.AssetPackOrder, [&](std::string_view id) { + EnumerateCommaSeparatedList(Config::Get().general.AssetPackOrder, [&](std::string_view id) { auto index = GetAssetPackIndex(id); if (index != std::numeric_limits::max()) { @@ -177,7 +177,7 @@ void AssetPackManager::LoadEnabledAssetPacks() _assetPacks = std::move(newAssetPacks); // Set which asset packs are enabled - EnumerateCommaSeparatedList(gConfigGeneral.EnabledAssetPacks, [&](std::string_view id) { + EnumerateCommaSeparatedList(Config::Get().general.EnabledAssetPacks, [&](std::string_view id) { auto assetPack = GetAssetPack(id); if (assetPack != nullptr) { @@ -204,7 +204,7 @@ void AssetPackManager::SaveEnabledAssetPacks() orderList.pop_back(); if (enabledList.size() > 0) enabledList.pop_back(); - gConfigGeneral.AssetPackOrder = orderList; - gConfigGeneral.EnabledAssetPacks = enabledList; - ConfigSaveDefault(); + Config::Get().general.AssetPackOrder = orderList; + Config::Get().general.EnabledAssetPacks = enabledList; + Config::Save(); } diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index e2e671cbea..08ce5d777c 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -386,20 +386,20 @@ namespace OpenRCT2 CrashInit(); - if (String::Equals(gConfigGeneral.LastRunVersion, OPENRCT2_VERSION)) + if (String::Equals(Config::Get().general.LastRunVersion, OPENRCT2_VERSION)) { gOpenRCT2ShowChangelog = false; } else { gOpenRCT2ShowChangelog = true; - gConfigGeneral.LastRunVersion = OPENRCT2_VERSION; - ConfigSaveDefault(); + Config::Get().general.LastRunVersion = OPENRCT2_VERSION; + Config::Save(); } try { - _localisationService->OpenLanguage(gConfigGeneral.Language); + _localisationService->OpenLanguage(Config::Get().general.Language); } catch (const std::exception& e) { @@ -502,7 +502,7 @@ namespace OpenRCT2 Audio::Init(); Audio::PopulateDevices(); Audio::InitRideSoundsAndInfo(); - Audio::gGameSoundsOff = !gConfigSound.MasterSoundEnabled; + Audio::gGameSoundsOff = !Config::Get().sound.MasterSoundEnabled; } ChatInit(); @@ -535,7 +535,7 @@ namespace OpenRCT2 { assert(_drawingEngine == nullptr); - _drawingEngineType = gConfigGeneral.DrawingEngine; + _drawingEngineType = Config::Get().general.DrawingEngine; auto drawingEngineFactory = _uiContext->GetDrawingEngineFactory(); auto drawingEngine = drawingEngineFactory->Create(_drawingEngineType, _uiContext); @@ -553,8 +553,8 @@ namespace OpenRCT2 LOG_ERROR("Unable to create drawing engine. Falling back to software."); // Fallback to software - gConfigGeneral.DrawingEngine = DrawingEngine::Software; - ConfigSaveDefault(); + Config::Get().general.DrawingEngine = DrawingEngine::Software; + Config::Save(); DrawingEngineInit(); } } @@ -563,7 +563,7 @@ namespace OpenRCT2 try { drawingEngine->Initialise(); - drawingEngine->SetVSync(gConfigGeneral.UseVSync); + drawingEngine->SetVSync(Config::Get().general.UseVSync); _drawingEngine = std::move(drawingEngine); } catch (const std::exception& ex) @@ -581,8 +581,8 @@ namespace OpenRCT2 LOG_ERROR("Unable to initialise drawing engine. Falling back to software."); // Fallback to software - gConfigGeneral.DrawingEngine = DrawingEngine::Software; - ConfigSaveDefault(); + Config::Get().general.DrawingEngine = DrawingEngine::Software; + Config::Save(); DrawingEngineInit(); } } @@ -737,7 +737,7 @@ namespace OpenRCT2 } // This ensures that the newly loaded save reflects the user's // 'show real names of guests' option, now that it's a global setting - PeepUpdateNames(gConfigGeneral.ShowRealNamesOfGuests); + PeepUpdateNames(Config::Get().general.ShowRealNamesOfGuests); #ifndef DISABLE_NETWORK if (sendMap) { @@ -869,19 +869,20 @@ namespace OpenRCT2 if (gCustomRCT2DataPath.empty()) { // Check install directory - if (gConfigGeneral.RCT2Path.empty() || !Platform::OriginalGameDataExists(gConfigGeneral.RCT2Path)) + if (Config::Get().general.RCT2Path.empty() || !Platform::OriginalGameDataExists(Config::Get().general.RCT2Path)) { LOG_VERBOSE( - "install directory does not exist or invalid directory selected, %s", gConfigGeneral.RCT2Path.c_str()); - if (!ConfigFindOrBrowseInstallDirectory()) + "install directory does not exist or invalid directory selected, %s", + Config::Get().general.RCT2Path.c_str()); + if (!Config::FindOrBrowseInstallDirectory()) { - auto path = ConfigGetDefaultPath(); + auto path = Config::GetDefaultPath(); Console::Error::WriteLine( "An RCT2 install directory must be specified! Please edit \"game_path\" in %s.\n", path.c_str()); return std::string(); } } - result = gConfigGeneral.RCT2Path; + result = Config::Get().general.RCT2Path; } else { @@ -914,7 +915,7 @@ namespace OpenRCT2 } else { - if ((gOpenRCT2StartupAction == StartupAction::Title) && gConfigGeneral.PlayIntro) + if ((gOpenRCT2StartupAction == StartupAction::Title) && Config::Get().general.PlayIntro) { gOpenRCT2StartupAction = StartupAction::Intro; } @@ -1020,17 +1021,17 @@ namespace OpenRCT2 { if (gNetworkStartPort == 0) { - gNetworkStartPort = gConfigNetwork.DefaultPort; + gNetworkStartPort = Config::Get().network.DefaultPort; } if (gNetworkStartAddress.empty()) { - gNetworkStartAddress = gConfigNetwork.ListenAddress; + gNetworkStartAddress = Config::Get().network.ListenAddress; } if (gCustomPassword.empty()) { - _network.SetPassword(gConfigNetwork.DefaultPassword.c_str()); + _network.SetPassword(Config::Get().network.DefaultPassword.c_str()); } else { @@ -1051,7 +1052,7 @@ namespace OpenRCT2 { if (gNetworkStartPort == 0) { - gNetworkStartPort = gConfigNetwork.DefaultPort; + gNetworkStartPort = Config::Get().network.DefaultPort; } _network.BeginClient(gNetworkStartHost, gNetworkStartPort); } @@ -1074,7 +1075,7 @@ namespace OpenRCT2 { if (!ShouldDraw()) return false; - if (!gConfigGeneral.UncapFPS) + if (!Config::Get().general.UncapFPS) return false; if (gGameSpeed > 4) return false; @@ -1438,7 +1439,7 @@ void ContextSetCurrentCursor(CursorID cursor) void ContextUpdateCursorScale() { - GetContext()->GetUiContext()->SetCursorScale(static_cast(std::round(gConfigGeneral.WindowScale))); + GetContext()->GetUiContext()->SetCursorScale(static_cast(std::round(Config::Get().general.WindowScale))); } void ContextHideCursor() @@ -1460,8 +1461,8 @@ ScreenCoordsXY ContextGetCursorPositionScaled() { auto cursorCoords = ContextGetCursorPosition(); // Compensate for window scaling. - return { static_cast(std::ceil(cursorCoords.x / gConfigGeneral.WindowScale)), - static_cast(std::ceil(cursorCoords.y / gConfigGeneral.WindowScale)) }; + 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) diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 7645933d94..c2af39992c 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -105,7 +105,7 @@ void GameResetSpeed() void GameIncreaseGameSpeed() { - auto newSpeed = std::min(gConfigGeneral.DebuggingTools ? 5 : 4, gGameSpeed + 1); + auto newSpeed = std::min(Config::Get().general.DebuggingTools ? 5 : 4, gGameSpeed + 1); if (newSpeed == 5) newSpeed = 8; @@ -479,7 +479,7 @@ void SaveGameWithName(u8string_view name) LOG_VERBOSE("Saving to %s", u8string(name).c_str()); auto& gameState = GetGameState(); - if (ScenarioSave(gameState, name, gConfigGeneral.SavePluginData ? 1 : 0)) + if (ScenarioSave(gameState, name, Config::Get().general.SavePluginData ? 1 : 0)) { LOG_VERBOSE("Saved to %s", u8string(name).c_str()); gCurrentLoadedPath = name; @@ -585,7 +585,7 @@ void GameAutosave() timeName, sizeof(timeName), "autosave_%04u-%02u-%02u_%02u-%02u-%02u%s", currentDate.year, currentDate.month, currentDate.day, currentTime.hour, currentTime.minute, currentTime.second, fileExtension); - int32_t autosavesToKeep = gConfigGeneral.AutosaveAmount; + int32_t autosavesToKeep = Config::Get().general.AutosaveAmount; LimitAutosaveCount(autosavesToKeep - 1, (gScreenFlags & SCREEN_FLAGS_EDITOR)); auto env = GetContext()->GetPlatformEnvironment(); diff --git a/src/openrct2/GameState.cpp b/src/openrct2/GameState.cpp index 91ee2bc5de..ae59a0a87b 100644 --- a/src/openrct2/GameState.cpp +++ b/src/openrct2/GameState.cpp @@ -146,7 +146,7 @@ namespace OpenRCT2 } bool isPaused = GameIsPaused(); - if (NetworkGetMode() == NETWORK_MODE_SERVER && gConfigNetwork.PauseServerIfNoClients) + if (NetworkGetMode() == NETWORK_MODE_SERVER && Config::Get().network.PauseServerIfNoClients) { // If we are headless we always have 1 player (host), pause if no one else is around. if (gOpenRCT2Headless && NetworkGetNumPlayers() == 1) diff --git a/src/openrct2/PlatformEnvironment.cpp b/src/openrct2/PlatformEnvironment.cpp index 4924311d12..9fa88c09a4 100644 --- a/src/openrct2/PlatformEnvironment.cpp +++ b/src/openrct2/PlatformEnvironment.cpp @@ -259,18 +259,18 @@ std::unique_ptr OpenRCT2::CreatePlatformEnvironment() // Now load the config so we can get the RCT1 and RCT2 paths auto configPath = env->GetFilePath(PATHID::CONFIG); - ConfigSetDefaults(); - if (!ConfigOpen(configPath)) + Config::SetDefaults(); + if (!Config::OpenFromPath(configPath)) { - ConfigSave(configPath); + Config::SaveToPath(configPath); } if (gCustomRCT1DataPath.empty()) { - env->SetBasePath(DIRBASE::RCT1, gConfigGeneral.RCT1Path); + env->SetBasePath(DIRBASE::RCT1, Config::Get().general.RCT1Path); } if (gCustomRCT2DataPath.empty()) { - env->SetBasePath(DIRBASE::RCT2, gConfigGeneral.RCT2Path); + env->SetBasePath(DIRBASE::RCT2, Config::Get().general.RCT2Path); } // Log base paths diff --git a/src/openrct2/ReplayManager.cpp b/src/openrct2/ReplayManager.cpp index ccf52be267..06302995e6 100644 --- a/src/openrct2/ReplayManager.cpp +++ b/src/openrct2/ReplayManager.cpp @@ -669,7 +669,7 @@ namespace OpenRCT2 serialiser << gameState.GuestGenerationProbability; serialiser << gameState.SuggestedGuestMaximum; - serialiser << gConfigGeneral.ShowRealNamesOfGuests; + serialiser << Config::Get().general.ShowRealNamesOfGuests; // To make this a little bit less volatile against updates // we reserve some space for future additions. diff --git a/src/openrct2/Version.cpp b/src/openrct2/Version.cpp index 8d4cba9cc6..0b1863e608 100644 --- a/src/openrct2/Version.cpp +++ b/src/openrct2/Version.cpp @@ -16,6 +16,8 @@ #include +using namespace OpenRCT2; + #ifdef OPENRCT2_BUILD_INFO_HEADER # include OPENRCT2_BUILD_INFO_HEADER #endif @@ -61,7 +63,7 @@ NewVersionInfo GetLatestVersion() NewVersionInfo verinfo{ tag, "", "", "" }; #ifndef DISABLE_HTTP auto now = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); - auto then = gConfigGeneral.LastVersionCheckTime; + auto then = Config::Get().general.LastVersionCheckTime; if (then < now - 24 * 60 * 60) { Http::Request request; @@ -88,8 +90,8 @@ NewVersionInfo GetLatestVersion() verinfo.changelog = Json::GetString(root["body"]); verinfo.url = Json::GetString(root["html_url"]); - gConfigGeneral.LastVersionCheckTime = now; - ConfigSaveDefault(); + Config::Get().general.LastVersionCheckTime = now; + Config::Save(); } #endif return verinfo; diff --git a/src/openrct2/actions/CheatSetAction.cpp b/src/openrct2/actions/CheatSetAction.cpp index 98abfd4dbb..ed6875343e 100644 --- a/src/openrct2/actions/CheatSetAction.cpp +++ b/src/openrct2/actions/CheatSetAction.cpp @@ -274,7 +274,7 @@ GameActions::Result CheatSetAction::Execute() const if (NetworkGetMode() == NETWORK_MODE_NONE) { - ConfigSaveDefault(); + Config::Save(); } WindowInvalidateByClass(WindowClass::Cheats); diff --git a/src/openrct2/actions/GameSetSpeedAction.cpp b/src/openrct2/actions/GameSetSpeedAction.cpp index 258ba06df6..1d72b3320c 100644 --- a/src/openrct2/actions/GameSetSpeedAction.cpp +++ b/src/openrct2/actions/GameSetSpeedAction.cpp @@ -11,6 +11,8 @@ #include "../config/Config.h" +using namespace OpenRCT2; + GameSetSpeedAction::GameSetSpeedAction(int32_t speed) : _speed(speed) { @@ -66,5 +68,5 @@ GameActions::Result GameSetSpeedAction::Execute() const bool GameSetSpeedAction::IsValidSpeed(int32_t speed) const { - return (speed >= 1 && speed <= 4) || (gConfigGeneral.DebuggingTools && speed == 8); + return (speed >= 1 && speed <= 4) || (Config::Get().general.DebuggingTools && speed == 8); } diff --git a/src/openrct2/audio/Audio.cpp b/src/openrct2/audio/Audio.cpp index d3bb5947ea..0a749c5482 100644 --- a/src/openrct2/audio/Audio.cpp +++ b/src/openrct2/audio/Audio.cpp @@ -65,7 +65,7 @@ namespace OpenRCT2::Audio return false; if (gGameSoundsOff) return false; - if (!gConfigSound.SoundEnabled) + if (!Config::Get().sound.SoundEnabled) return false; if (gOpenRCT2Headless) return false; @@ -75,19 +75,19 @@ namespace OpenRCT2::Audio void Init() { auto audioContext = GetContext()->GetAudioContext(); - if (gConfigSound.Device.empty()) + if (Config::Get().sound.Device.empty()) { audioContext->SetOutputDevice(""); _currentAudioDevice = 0; } else { - audioContext->SetOutputDevice(gConfigSound.Device); + audioContext->SetOutputDevice(Config::Get().sound.Device); PopulateDevices(); for (int32_t i = 0; i < GetDeviceCount(); i++) { - if (_audioDevices[i] == gConfigSound.Device) + if (_audioDevices[i] == Config::Get().sound.Device) { _currentAudioDevice = i; } @@ -305,7 +305,7 @@ namespace OpenRCT2::Audio } // Load title sequence audio object - auto descriptor = GetTitleMusicDescriptor(gConfigSound.TitleMusic); + auto descriptor = GetTitleMusicDescriptor(Config::Get().sound.TitleMusic); auto& objManager = GetContext()->GetObjectManager(); auto* audioObject = static_cast(objManager.LoadObject(descriptor)); if (audioObject != nullptr) @@ -385,7 +385,7 @@ namespace OpenRCT2::Audio } _currentAudioDevice = device; - ConfigSaveDefault(); + Config::Save(); } void Close() @@ -399,8 +399,8 @@ namespace OpenRCT2::Audio void ToggleAllSounds() { - gConfigSound.MasterSoundEnabled = !gConfigSound.MasterSoundEnabled; - if (gConfigSound.MasterSoundEnabled) + Config::Get().sound.MasterSoundEnabled = !Config::Get().sound.MasterSoundEnabled; + if (Config::Get().sound.MasterSoundEnabled) { Resume(); } diff --git a/src/openrct2/command_line/RootCommands.cpp b/src/openrct2/command_line/RootCommands.cpp index 9bf01e9b9e..36642024e3 100644 --- a/src/openrct2/command_line/RootCommands.cpp +++ b/src/openrct2/command_line/RootCommands.cpp @@ -31,6 +31,8 @@ #include #include +using namespace OpenRCT2; + #ifdef USE_BREAKPAD # define IMPLIES_SILENT_BREAKPAD ", implies --silent-breakpad" #else @@ -365,10 +367,10 @@ static exitcode_t HandleCommandSetRCT2(CommandLineArgEnumerator* enumerator) // Update RCT2 path in config auto env = OpenRCT2::CreatePlatformEnvironment(); auto configPath = env->GetFilePath(OpenRCT2::PATHID::CONFIG); - ConfigSetDefaults(); - ConfigOpen(configPath); - gConfigGeneral.RCT2Path = path; - if (ConfigSave(configPath)) + Config::SetDefaults(); + Config::OpenFromPath(configPath); + Config::Get().general.RCT2Path = path; + if (Config::SaveToPath(configPath)) { Console::WriteFormat("Updating RCT2 path to '%s'.", path.c_str()); Console::WriteLine(); @@ -394,7 +396,7 @@ static exitcode_t HandleCommandScanObjects([[maybe_unused]] CommandLineArgEnumer auto context = OpenRCT2::CreateContext(); auto env = context->GetPlatformEnvironment(); auto objectRepository = CreateObjectRepository(env); - objectRepository->Construct(gConfigGeneral.Language); + objectRepository->Construct(Config::Get().general.Language); return EXITCODE_OK; } diff --git a/src/openrct2/config/Config.cpp b/src/openrct2/config/Config.cpp index 0e1ad04060..42d719f34d 100644 --- a/src/openrct2/config/Config.cpp +++ b/src/openrct2/config/Config.cpp @@ -44,8 +44,15 @@ static constexpr bool WindowButtonsOnTheLeftDefault = true; static constexpr bool WindowButtonsOnTheLeftDefault = false; #endif -namespace Config +namespace OpenRCT2::Config { + static Config _config{}; + + Config& Get() + { + return _config; + } + #pragma region Enums static const auto Enum_MeasurementFormat = ConfigEnum({ @@ -143,7 +150,7 @@ namespace Config { if (reader->ReadSection("general")) { - auto model = &gConfigGeneral; + auto model = &_config.general; model->AlwaysShowGridlines = reader->GetBoolean("always_show_gridlines", false); model->AutosaveFrequency = reader->GetInt32("autosave", AUTOSAVE_EVERY_5MINUTES); model->AutosaveAmount = reader->GetInt32("autosave_amount", kDefaultNumAutosavesToKeep); @@ -242,7 +249,7 @@ namespace Config static void WriteGeneral(IIniWriter* writer) { - auto model = &gConfigGeneral; + auto model = &_config.general; writer->WriteSection("general"); writer->WriteBoolean("always_show_gridlines", model->AlwaysShowGridlines); writer->WriteInt32("autosave", model->AutosaveFrequency); @@ -327,7 +334,7 @@ namespace Config { if (reader->ReadSection("interface")) { - auto model = &gConfigInterface; + auto model = &_config.interface; model->ToolbarShowFinances = reader->GetBoolean("toolbar_show_finances", true); model->ToolbarShowResearch = reader->GetBoolean("toolbar_show_research", true); model->ToolbarShowCheats = reader->GetBoolean("toolbar_show_cheats", false); @@ -348,7 +355,7 @@ namespace Config static void WriteInterface(IIniWriter* writer) { - auto model = &gConfigInterface; + auto model = &_config.interface; writer->WriteSection("interface"); writer->WriteBoolean("toolbar_show_finances", model->ToolbarShowFinances); writer->WriteBoolean("toolbar_show_research", model->ToolbarShowResearch); @@ -371,7 +378,7 @@ namespace Config { if (reader->ReadSection("sound")) { - auto model = &gConfigSound; + auto model = &_config.sound; model->Device = reader->GetString("audio_device", ""); model->MasterSoundEnabled = reader->GetBoolean("master_sound", true); model->MasterVolume = reader->GetInt32("master_volume", 100); @@ -387,7 +394,7 @@ namespace Config static void WriteSound(IIniWriter* writer) { - auto model = &gConfigSound; + auto model = &_config.sound; writer->WriteSection("sound"); writer->WriteString("audio_device", model->Device); writer->WriteBoolean("master_sound", model->MasterSoundEnabled); @@ -420,7 +427,7 @@ namespace Config // to avoid people pretending to be someone else playerName = String::Trim(playerName); - auto model = &gConfigNetwork; + auto model = &_config.network; model->PlayerName = std::move(playerName); model->DefaultPort = reader->GetInt32("default_port", kNetworkDefaultPort); model->ListenAddress = reader->GetString("listen_address", ""); @@ -446,7 +453,7 @@ namespace Config static void WriteNetwork(IIniWriter* writer) { - auto model = &gConfigNetwork; + auto model = &_config.network; writer->WriteSection("network"); writer->WriteString("player_name", model->PlayerName); writer->WriteInt32("default_port", model->DefaultPort); @@ -474,7 +481,7 @@ namespace Config { if (reader->ReadSection("notifications")) { - auto model = &gConfigNotifications; + auto model = &_config.notifications; model->ParkAward = reader->GetBoolean("park_award", true); model->ParkMarketingCampaignFinished = reader->GetBoolean("park_marketing_campaign_finished", true); model->ParkWarnings = reader->GetBoolean("park_warnings", true); @@ -498,7 +505,7 @@ namespace Config static void WriteNotifications(IIniWriter* writer) { - auto model = &gConfigNotifications; + auto model = &_config.notifications; writer->WriteSection("notifications"); writer->WriteBoolean("park_award", model->ParkAward); writer->WriteBoolean("park_marketing_campaign_finished", model->ParkMarketingCampaignFinished); @@ -524,7 +531,7 @@ namespace Config { if (reader->ReadSection("font")) { - auto model = &gConfigFonts; + auto model = &_config.fonts; model->FileName = reader->GetString("file_name", ""); model->FontName = reader->GetString("font_name", ""); model->OffsetX = reader->GetInt32("x_offset", false); @@ -544,7 +551,7 @@ namespace Config static void WriteFont(IIniWriter* writer) { - auto model = &gConfigFonts; + auto model = &_config.fonts; writer->WriteSection("font"); writer->WriteString("file_name", model->FileName); writer->WriteString("font_name", model->FontName); @@ -566,7 +573,7 @@ namespace Config { if (reader->ReadSection("plugin")) { - auto model = &gConfigPlugin; + auto model = &_config.plugin; model->EnableHotReloading = reader->GetBoolean("enable_hot_reloading", false); model->AllowedHosts = reader->GetString("allowed_hosts", ""); } @@ -574,13 +581,13 @@ namespace Config static void WritePlugin(IIniWriter* writer) { - auto model = &gConfigPlugin; + auto model = &_config.plugin; writer->WriteSection("plugin"); writer->WriteBoolean("enable_hot_reloading", model->EnableHotReloading); writer->WriteString("allowed_hosts", model->AllowedHosts); } - static bool SetDefaults() + bool SetDefaults() { try { @@ -777,171 +784,158 @@ namespace Config LOG_INFO("Exit status %d", exit_status); return exit_status == 0; } -} // namespace Config -GeneralConfiguration gConfigGeneral; -InterfaceConfiguration gConfigInterface; -SoundConfiguration gConfigSound; -NetworkConfiguration gConfigNetwork; -NotificationConfiguration gConfigNotifications; -FontConfiguration gConfigFonts; -PluginConfiguration gConfigPlugin; - -void ConfigSetDefaults() -{ - Config::SetDefaults(); -} - -bool ConfigOpen(u8string_view path) -{ - if (!File::Exists(path)) + bool OpenFromPath(u8string_view path) { - return false; - } - - auto result = Config::ReadFile(path); - if (result) - { - CurrencyLoadCustomCurrencyConfig(); - } - return result; -} - -bool ConfigSave(u8string_view path) -{ - return Config::WriteFile(path); -} - -u8string ConfigGetDefaultPath() -{ - auto env = GetContext()->GetPlatformEnvironment(); - return Path::Combine(env->GetDirectoryPath(DIRBASE::USER), u8"config.ini"); -} - -bool ConfigSaveDefault() -{ - auto path = ConfigGetDefaultPath(); - return ConfigSave(path); -} - -bool ConfigFindOrBrowseInstallDirectory() -{ - std::string path = Config::FindRCT2Path(); - if (!path.empty()) - { - gConfigGeneral.RCT2Path = path; - } - else - { - if (gOpenRCT2Headless) + if (!File::Exists(path)) { return false; } - auto uiContext = GetContext()->GetUiContext(); - if (!uiContext->HasFilePicker()) + auto result = ReadFile(path); + if (result) { - uiContext->ShowMessageBox(LanguageGetString(STR_NEEDS_RCT2_FILES_MANUAL)); - return false; + CurrencyLoadCustomCurrencyConfig(); } + return result; + } - try + u8string GetDefaultPath() + { + auto env = GetContext()->GetPlatformEnvironment(); + return Path::Combine(env->GetDirectoryPath(DIRBASE::USER), u8"config.ini"); + } + + bool SaveToPath(u8string_view path) + { + return WriteFile(path); + } + + bool Save() + { + auto path = GetDefaultPath(); + return SaveToPath(path); + } + + bool FindOrBrowseInstallDirectory() + { + std::string path = FindRCT2Path(); + if (!path.empty()) { - const char* g1DatPath = PATH_SEPARATOR "Data" PATH_SEPARATOR "g1.dat"; - while (true) + Get().general.RCT2Path = path; + } + else + { + if (gOpenRCT2Headless) { - uiContext->ShowMessageBox(LanguageGetString(STR_NEEDS_RCT2_FILES)); - std::string gog = LanguageGetString(STR_OWN_ON_GOG); - std::string hdd = LanguageGetString(STR_INSTALLED_ON_HDD); + return false; + } - std::vector options; - std::string chosenOption; + auto uiContext = GetContext()->GetUiContext(); + if (!uiContext->HasFilePicker()) + { + uiContext->ShowMessageBox(LanguageGetString(STR_NEEDS_RCT2_FILES_MANUAL)); + return false; + } - if (uiContext->HasMenuSupport()) + try + { + const char* g1DatPath = PATH_SEPARATOR "Data" PATH_SEPARATOR "g1.dat"; + while (true) { - options.push_back(hdd); - options.push_back(gog); - int optionIndex = uiContext->ShowMenuDialog( - options, LanguageGetString(STR_OPENRCT2_SETUP), LanguageGetString(STR_WHICH_APPLIES_BEST)); - if (optionIndex < 0 || static_cast(optionIndex) >= options.size()) + uiContext->ShowMessageBox(LanguageGetString(STR_NEEDS_RCT2_FILES)); + std::string gog = LanguageGetString(STR_OWN_ON_GOG); + std::string hdd = LanguageGetString(STR_INSTALLED_ON_HDD); + + std::vector options; + std::string chosenOption; + + if (uiContext->HasMenuSupport()) { - // graceful fallback if app errors or user exits out of window - chosenOption = hdd; + options.push_back(hdd); + options.push_back(gog); + int optionIndex = uiContext->ShowMenuDialog( + options, LanguageGetString(STR_OPENRCT2_SETUP), LanguageGetString(STR_WHICH_APPLIES_BEST)); + if (optionIndex < 0 || static_cast(optionIndex) >= options.size()) + { + // graceful fallback if app errors or user exits out of window + chosenOption = hdd; + } + else + { + chosenOption = options[optionIndex]; + } } else { - chosenOption = options[optionIndex]; - } - } - else - { - chosenOption = hdd; - } - - std::string installPath; - if (chosenOption == hdd) - { - installPath = uiContext->ShowDirectoryDialog(LanguageGetString(STR_PICK_RCT2_DIR)); - } - else if (chosenOption == gog) - { - // Check if innoextract is installed. If not, prompt the user to install it. - std::string dummy; - if (!Platform::FindApp("innoextract", &dummy)) - { - uiContext->ShowMessageBox(LanguageGetString(STR_INSTALL_INNOEXTRACT)); - return false; + chosenOption = hdd; } - const std::string dest = Path::Combine( - GetContext()->GetPlatformEnvironment()->GetDirectoryPath(DIRBASE::CONFIG), "rct2"); - - while (true) + std::string installPath; + if (chosenOption == hdd) { - uiContext->ShowMessageBox(LanguageGetString(STR_PLEASE_SELECT_GOG_INSTALLER)); - utf8 gogPath[4096]; - if (!Config::SelectGogInstaller(gogPath)) + installPath = uiContext->ShowDirectoryDialog(LanguageGetString(STR_PICK_RCT2_DIR)); + } + else if (chosenOption == gog) + { + // Check if innoextract is installed. If not, prompt the user to install it. + std::string dummy; + if (!Platform::FindApp("innoextract", &dummy)) { - // The user clicked "Cancel", so stop trying. + uiContext->ShowMessageBox(LanguageGetString(STR_INSTALL_INNOEXTRACT)); return false; } - uiContext->ShowMessageBox(LanguageGetString(STR_THIS_WILL_TAKE_A_FEW_MINUTES)); + const std::string dest = Path::Combine( + GetContext()->GetPlatformEnvironment()->GetDirectoryPath(DIRBASE::CONFIG), "rct2"); - if (Config::ExtractGogInstaller(gogPath, dest)) - break; + while (true) + { + uiContext->ShowMessageBox(LanguageGetString(STR_PLEASE_SELECT_GOG_INSTALLER)); + utf8 gogPath[4096]; + if (!SelectGogInstaller(gogPath)) + { + // The user clicked "Cancel", so stop trying. + return false; + } - uiContext->ShowMessageBox(LanguageGetString(STR_NOT_THE_GOG_INSTALLER)); + uiContext->ShowMessageBox(LanguageGetString(STR_THIS_WILL_TAKE_A_FEW_MINUTES)); + + if (ExtractGogInstaller(gogPath, dest)) + break; + + uiContext->ShowMessageBox(LanguageGetString(STR_NOT_THE_GOG_INSTALLER)); + } + + installPath = Path::Combine(dest, u8"app"); + } + if (installPath.empty()) + { + return false; + } + Get().general.RCT2Path = installPath; + + if (Platform::OriginalGameDataExists(installPath)) + { + return true; } - installPath = Path::Combine(dest, u8"app"); + uiContext->ShowMessageBox(FormatStringIDLegacy(STR_COULD_NOT_FIND_AT_PATH, &g1DatPath)); } - if (installPath.empty()) - { - return false; - } - gConfigGeneral.RCT2Path = installPath; - - if (Platform::OriginalGameDataExists(installPath)) - { - return true; - } - - uiContext->ShowMessageBox(FormatStringIDLegacy(STR_COULD_NOT_FIND_AT_PATH, &g1DatPath)); + } + catch (const std::exception& ex) + { + Console::Error::WriteLine(ex.what()); + return false; } } - catch (const std::exception& ex) + // While we're at it, also check if the player has RCT1 + std::string rct1Path = FindRCT1Path(); + if (!rct1Path.empty()) { - Console::Error::WriteLine(ex.what()); - return false; + Get().general.RCT1Path = std::move(rct1Path); } - } - // While we're at it, also check if the player has RCT1 - std::string rct1Path = Config::FindRCT1Path(); - if (!rct1Path.empty()) - { - gConfigGeneral.RCT1Path = std::move(rct1Path); - } - return true; -} + return true; + } +} // namespace OpenRCT2::Config diff --git a/src/openrct2/config/Config.h b/src/openrct2/config/Config.h index 6bcd921e76..f5a4c2905b 100644 --- a/src/openrct2/config/Config.h +++ b/src/openrct2/config/Config.h @@ -15,214 +15,226 @@ #include -struct GeneralConfiguration +namespace OpenRCT2::Config { - // Paths - u8string RCT1Path; - u8string RCT2Path; + struct General + { + // Paths + u8string RCT1Path; + u8string RCT2Path; - // Display - int32_t DefaultDisplay; - int32_t WindowWidth; - int32_t WindowHeight; - int32_t FullscreenMode; - int32_t FullscreenWidth; - int32_t FullscreenHeight; - float WindowScale; - ::DrawingEngine DrawingEngine; - bool UncapFPS; - bool UseVSync; - bool ShowFPS; - std::atomic_uint8_t MultiThreading; - bool MinimizeFullscreenFocusLoss; - bool DisableScreensaver; + // Display + int32_t DefaultDisplay; + int32_t WindowWidth; + int32_t WindowHeight; + int32_t FullscreenMode; + int32_t FullscreenWidth; + int32_t FullscreenHeight; + float WindowScale; + ::DrawingEngine DrawingEngine; + bool UncapFPS; + bool UseVSync; + bool ShowFPS; + std::atomic_uint8_t MultiThreading; + bool MinimizeFullscreenFocusLoss; + bool DisableScreensaver; - // Map rendering - bool LandscapeSmoothing; - bool AlwaysShowGridlines; - VirtualFloorStyles VirtualFloorStyle; - bool DayNightCycle; - bool EnableLightFx; - bool EnableLightFxForVehicles; - bool UpperCaseBanners; - bool RenderWeatherEffects; - bool RenderWeatherGloom; - bool DisableLightningEffect; - bool ShowGuestPurchases; - bool TransparentScreenshot; - bool TransparentWater; + // Map rendering + bool LandscapeSmoothing; + bool AlwaysShowGridlines; + VirtualFloorStyles VirtualFloorStyle; + bool DayNightCycle; + bool EnableLightFx; + bool EnableLightFxForVehicles; + bool UpperCaseBanners; + bool RenderWeatherEffects; + bool RenderWeatherGloom; + bool DisableLightningEffect; + bool ShowGuestPurchases; + bool TransparentScreenshot; + bool TransparentWater; - bool InvisibleRides; - bool InvisibleVehicles; - bool InvisibleTrees; - bool InvisibleScenery; - bool InvisiblePaths; - bool InvisibleSupports; + bool InvisibleRides; + bool InvisibleVehicles; + bool InvisibleTrees; + bool InvisibleScenery; + bool InvisiblePaths; + bool InvisibleSupports; - // Localisation - int32_t Language; - ::MeasurementFormat MeasurementFormat; - TemperatureUnit TemperatureFormat; - bool ShowHeightAsUnits; - int32_t DateFormat; - CurrencyType CurrencyFormat; - int32_t CustomCurrencyRate; - CurrencyAffix CustomCurrencyAffix; - u8string CustomCurrencySymbol; + // Localisation + int32_t Language; + ::MeasurementFormat MeasurementFormat; + TemperatureUnit TemperatureFormat; + bool ShowHeightAsUnits; + int32_t DateFormat; + CurrencyType CurrencyFormat; + int32_t CustomCurrencyRate; + CurrencyAffix CustomCurrencyAffix; + u8string CustomCurrencySymbol; - // Controls - bool EdgeScrolling; - int32_t EdgeScrollingSpeed; - bool TrapCursor; - bool InvertViewportDrag; - bool ZoomToCursor; + // Controls + bool EdgeScrolling; + int32_t EdgeScrollingSpeed; + bool TrapCursor; + bool InvertViewportDrag; + bool ZoomToCursor; - // Miscellaneous - bool PlayIntro; - int32_t WindowSnapProximity; - bool SavePluginData; - bool DebuggingTools; - int32_t AutosaveFrequency; - int32_t AutosaveAmount; - bool AutoStaffPlacement; - bool HandymenMowByDefault; - bool AutoOpenShops; - int32_t DefaultInspectionInterval; - int32_t WindowLimit; - int32_t ScenarioSelectMode; - bool ScenarioUnlockingEnabled; - bool ScenarioHideMegaPark; - bool SteamOverlayPause; - bool ShowRealNamesOfGuests; - bool AllowEarlyCompletion; - u8string AssetPackOrder; - u8string EnabledAssetPacks; + // Miscellaneous + bool PlayIntro; + int32_t WindowSnapProximity; + bool SavePluginData; + bool DebuggingTools; + int32_t AutosaveFrequency; + int32_t AutosaveAmount; + bool AutoStaffPlacement; + bool HandymenMowByDefault; + bool AutoOpenShops; + int32_t DefaultInspectionInterval; + int32_t WindowLimit; + int32_t ScenarioSelectMode; + bool ScenarioUnlockingEnabled; + bool ScenarioHideMegaPark; + bool SteamOverlayPause; + bool ShowRealNamesOfGuests; + bool AllowEarlyCompletion; + u8string AssetPackOrder; + u8string EnabledAssetPacks; - // Loading and saving - bool ConfirmationPrompt; - Sort LoadSaveSort; - u8string LastSaveGameDirectory; - u8string LastSaveLandscapeDirectory; - u8string LastSaveScenarioDirectory; - u8string LastSaveTrackDirectory; - u8string LastRunVersion; - bool UseNativeBrowseDialog; - int64_t LastVersionCheckTime; -}; + // Loading and saving + bool ConfirmationPrompt; + Sort LoadSaveSort; + u8string LastSaveGameDirectory; + u8string LastSaveLandscapeDirectory; + u8string LastSaveScenarioDirectory; + u8string LastSaveTrackDirectory; + u8string LastRunVersion; + bool UseNativeBrowseDialog; + int64_t LastVersionCheckTime; + }; -struct InterfaceConfiguration -{ - bool ToolbarShowFinances; - bool ToolbarShowResearch; - bool ToolbarShowCheats; - bool ToolbarShowNews; - bool ToolbarShowMute; - bool ToolbarShowChat; - bool ToolbarShowZoom; - bool ConsoleSmallFont; - bool RandomTitleSequence; - u8string CurrentThemePreset; - u8string CurrentTitleSequencePreset; - int32_t ObjectSelectionFilterFlags; - int32_t ScenarioselectLastTab; - bool ListRideVehiclesSeparately; - bool WindowButtonsOnTheLeft; -}; + struct Interface + { + bool ToolbarShowFinances; + bool ToolbarShowResearch; + bool ToolbarShowCheats; + bool ToolbarShowNews; + bool ToolbarShowMute; + bool ToolbarShowChat; + bool ToolbarShowZoom; + bool ConsoleSmallFont; + bool RandomTitleSequence; + u8string CurrentThemePreset; + u8string CurrentTitleSequencePreset; + int32_t ObjectSelectionFilterFlags; + int32_t ScenarioselectLastTab; + bool ListRideVehiclesSeparately; + bool WindowButtonsOnTheLeft; + }; -struct SoundConfiguration -{ - u8string Device; - bool MasterSoundEnabled; - uint8_t MasterVolume; - TitleMusicKind TitleMusic; - bool SoundEnabled; - uint8_t SoundVolume; - bool RideMusicEnabled; - uint8_t AudioFocus; - bool audio_focus; -}; + struct Sound + { + u8string Device; + bool MasterSoundEnabled; + uint8_t MasterVolume; + TitleMusicKind TitleMusic; + bool SoundEnabled; + uint8_t SoundVolume; + bool RideMusicEnabled; + uint8_t AudioFocus; + bool audio_focus; + }; -struct NetworkConfiguration -{ - u8string PlayerName; - int32_t DefaultPort; - u8string ListenAddress; - u8string DefaultPassword; - bool StayConnected; - bool Advertise; - u8string AdvertiseAddress; - int32_t Maxplayers; - u8string ServerName; - u8string ServerDescription; - u8string ServerGreeting; - u8string MasterServerUrl; - u8string ProviderName; - u8string ProviderEmail; - u8string ProviderWebsite; - bool KnownKeysOnly; - bool LogChat; - bool LogServerActions; - bool PauseServerIfNoClients; - bool DesyncDebugging; -}; + struct Network + { + u8string PlayerName; + int32_t DefaultPort; + u8string ListenAddress; + u8string DefaultPassword; + bool StayConnected; + bool Advertise; + u8string AdvertiseAddress; + int32_t Maxplayers; + u8string ServerName; + u8string ServerDescription; + u8string ServerGreeting; + u8string MasterServerUrl; + u8string ProviderName; + u8string ProviderEmail; + u8string ProviderWebsite; + bool KnownKeysOnly; + bool LogChat; + bool LogServerActions; + bool PauseServerIfNoClients; + bool DesyncDebugging; + }; -struct NotificationConfiguration -{ - bool ParkAward; - bool ParkMarketingCampaignFinished; - bool ParkWarnings; - bool ParkRatingWarnings; - bool RideBrokenDown; - bool RideCrashed; - bool RideCasualties; - bool RideWarnings; - bool RideResearched; - bool RideStalledVehicles; - bool GuestWarnings; - bool GuestLeftPark; - bool GuestQueuingForRide; - bool GuestOnRide; - bool GuestLeftRide; - bool GuestBoughtItem; - bool GuestUsedFacility; - bool GuestDied; -}; + struct Notification + { + bool ParkAward; + bool ParkMarketingCampaignFinished; + bool ParkWarnings; + bool ParkRatingWarnings; + bool RideBrokenDown; + bool RideCrashed; + bool RideCasualties; + bool RideWarnings; + bool RideResearched; + bool RideStalledVehicles; + bool GuestWarnings; + bool GuestLeftPark; + bool GuestQueuingForRide; + bool GuestOnRide; + bool GuestLeftRide; + bool GuestBoughtItem; + bool GuestUsedFacility; + bool GuestDied; + }; -struct FontConfiguration -{ - u8string FileName; - u8string FontName; - int32_t OffsetX; - int32_t OffsetY; - int32_t SizeTiny; - int32_t SizeSmall; - int32_t SizeMedium; - int32_t SizeBig; - int32_t HeightTiny; - int32_t HeightSmall; - int32_t HeightMedium; - int32_t HeightBig; - bool EnableHinting; - int32_t HintingThreshold; -}; + struct Font + { + u8string FileName; + u8string FontName; + int32_t OffsetX; + int32_t OffsetY; + int32_t SizeTiny; + int32_t SizeSmall; + int32_t SizeMedium; + int32_t SizeBig; + int32_t HeightTiny; + int32_t HeightSmall; + int32_t HeightMedium; + int32_t HeightBig; + bool EnableHinting; + int32_t HintingThreshold; + }; -struct PluginConfiguration -{ - bool EnableHotReloading; - u8string AllowedHosts; -}; + struct Plugin + { + bool EnableHotReloading; + u8string AllowedHosts; + }; -extern GeneralConfiguration gConfigGeneral; -extern InterfaceConfiguration gConfigInterface; -extern SoundConfiguration gConfigSound; -extern NetworkConfiguration gConfigNetwork; -extern NotificationConfiguration gConfigNotifications; -extern FontConfiguration gConfigFonts; -extern PluginConfiguration gConfigPlugin; + struct Config + { + Config() = default; -bool ConfigOpen(u8string_view path); -bool ConfigSave(u8string_view path); -u8string ConfigGetDefaultPath(); -void ConfigSetDefaults(); -bool ConfigSaveDefault(); -bool ConfigFindOrBrowseInstallDirectory(); + // Prevent accidental copies + Config(const Config&) = delete; + + General general; + Interface interface; + Sound sound; + Network network; + Notification notifications; + Font fonts; + Plugin plugin; + }; + + Config& Get(); + bool OpenFromPath(u8string_view path); + bool SaveToPath(u8string_view path); + u8string GetDefaultPath(); + bool SetDefaults(); + bool Save(); + bool FindOrBrowseInstallDirectory(); +} // namespace OpenRCT2::Config diff --git a/src/openrct2/drawing/Drawing.Sprite.cpp b/src/openrct2/drawing/Drawing.Sprite.cpp index 0c0e2e2713..7d5116f7d0 100644 --- a/src/openrct2/drawing/Drawing.Sprite.cpp +++ b/src/openrct2/drawing/Drawing.Sprite.cpp @@ -368,14 +368,14 @@ bool GfxLoadCsg() { LOG_VERBOSE("GfxLoadCsg()"); - if (gConfigGeneral.RCT1Path.empty()) + if (Config::Get().general.RCT1Path.empty()) { LOG_VERBOSE(" unable to load CSG, RCT1 path not set"); return false; } - auto pathHeaderPath = FindCsg1idatAtLocation(gConfigGeneral.RCT1Path); - auto pathDataPath = FindCsg1datAtLocation(gConfigGeneral.RCT1Path); + auto pathHeaderPath = FindCsg1idatAtLocation(Config::Get().general.RCT1Path); + auto pathDataPath = FindCsg1datAtLocation(Config::Get().general.RCT1Path); try { auto fileHeader = FileStream(pathHeaderPath, FILE_MODE_OPEN); diff --git a/src/openrct2/drawing/Drawing.String.cpp b/src/openrct2/drawing/Drawing.String.cpp index 95007c6204..86ca97f831 100644 --- a/src/openrct2/drawing/Drawing.String.cpp +++ b/src/openrct2/drawing/Drawing.String.cpp @@ -532,7 +532,7 @@ static void TTFDrawStringRawTTF(DrawPixelInfo& dpi, std::string_view text, TextD { int32_t drawX = info->x + fontDesc->offset_x; int32_t drawY = info->y + fontDesc->offset_y; - uint8_t hintThresh = gConfigFonts.EnableHinting ? fontDesc->hinting_threshold : 0; + uint8_t hintThresh = Config::Get().fonts.EnableHinting ? fontDesc->hinting_threshold : 0; OpenRCT2::Drawing::IDrawingContext* dc = drawingEngine->GetDrawingContext(); dc->DrawTTFBitmap(dpi, info, surface, drawX, drawY, hintThresh); } diff --git a/src/openrct2/drawing/Drawing.cpp b/src/openrct2/drawing/Drawing.cpp index 8a5de8f107..dcf00ed2f4 100644 --- a/src/openrct2/drawing/Drawing.cpp +++ b/src/openrct2/drawing/Drawing.cpp @@ -1029,7 +1029,7 @@ void UpdatePaletteEffects() // Animate the water/lava/chain movement palette uint32_t shade = 0; - if (gConfigGeneral.RenderWeatherGloom) + if (Config::Get().general.RenderWeatherGloom) { auto paletteId = ClimateGetWeatherGloomPaletteId(GetGameState().ClimateCurrent); if (paletteId != FilterPaletteID::PaletteNull) @@ -1143,8 +1143,8 @@ void RefreshVideo(bool recreateWindow) void ToggleWindowedMode() { - int32_t targetMode = gConfigGeneral.FullscreenMode == 0 ? 2 : 0; + int32_t targetMode = Config::Get().general.FullscreenMode == 0 ? 2 : 0; ContextSetFullscreenMode(targetMode); - gConfigGeneral.FullscreenMode = targetMode; - ConfigSaveDefault(); + Config::Get().general.FullscreenMode = targetMode; + Config::Save(); } diff --git a/src/openrct2/drawing/DrawingLock.hpp b/src/openrct2/drawing/DrawingLock.hpp index e7ea094616..44a7f5303e 100644 --- a/src/openrct2/drawing/DrawingLock.hpp +++ b/src/openrct2/drawing/DrawingLock.hpp @@ -11,6 +11,8 @@ #include "../config/Config.h" +using namespace OpenRCT2; + template class DrawingUniqueLock { T& _mutex; @@ -19,7 +21,7 @@ template class DrawingUniqueLock public: DrawingUniqueLock(T& mutex) : _mutex(mutex) - , _enabled(gConfigGeneral.MultiThreading) + , _enabled(Config::Get().general.MultiThreading) { if (_enabled) _mutex.lock(); @@ -39,7 +41,7 @@ template class DrawingSharedLock public: DrawingSharedLock(T& mutex) : _mutex(mutex) - , _enabled(gConfigGeneral.MultiThreading) + , _enabled(Config::Get().general.MultiThreading) { if (_enabled) _mutex.lock_shared(); diff --git a/src/openrct2/drawing/LightFX.cpp b/src/openrct2/drawing/LightFX.cpp index f68407b33b..66891a2817 100644 --- a/src/openrct2/drawing/LightFX.cpp +++ b/src/openrct2/drawing/LightFX.cpp @@ -28,6 +28,8 @@ #include #include +using namespace OpenRCT2; + static uint8_t _bakedLightTexture_lantern_0[32 * 32]; static uint8_t _bakedLightTexture_lantern_1[64 * 64]; static uint8_t _bakedLightTexture_lantern_2[128 * 128]; @@ -130,12 +132,12 @@ void LightFXSetAvailable(bool available) bool LightFXIsAvailable() { - return _lightfxAvailable && gConfigGeneral.EnableLightFx != 0; + return _lightfxAvailable && Config::Get().general.EnableLightFx != 0; } bool LightFXForVehiclesIsAvailable() { - return LightFXIsAvailable() && gConfigGeneral.EnableLightFxForVehicles != 0; + return LightFXIsAvailable() && Config::Get().general.EnableLightFxForVehicles != 0; } void LightFXInit() diff --git a/src/openrct2/drawing/ScrollingText.cpp b/src/openrct2/drawing/ScrollingText.cpp index be176b72ef..b66aa49450 100644 --- a/src/openrct2/drawing/ScrollingText.cpp +++ b/src/openrct2/drawing/ScrollingText.cpp @@ -147,7 +147,7 @@ static int32_t ScrollingTextGetMatchingOrOldest( static void ScrollingTextFormat(utf8* dst, size_t size, DrawScrollText* scrollText) { - if (gConfigGeneral.UpperCaseBanners) + if (Config::Get().general.UpperCaseBanners) { FormatStringToUpper(dst, size, scrollText->string_id, scrollText->string_args); } @@ -1586,7 +1586,7 @@ static void ScrollingTextSetBitmapForTTF( int32_t min_vpos = -fontDesc->offset_y; int32_t max_vpos = std::min(surface->h - 2, min_vpos + 7); - bool use_hinting = gConfigFonts.EnableHinting && fontDesc->hinting_threshold > 0; + bool use_hinting = Config::Get().fonts.EnableHinting && fontDesc->hinting_threshold > 0; for (int32_t x = 0;; x++) { diff --git a/src/openrct2/drawing/TTF.cpp b/src/openrct2/drawing/TTF.cpp index 07a17a580b..da19b3c52a 100644 --- a/src/openrct2/drawing/TTF.cpp +++ b/src/openrct2/drawing/TTF.cpp @@ -26,6 +26,8 @@ # include "DrawingLock.hpp" # include "TTF.h" +using namespace OpenRCT2; + static bool _ttfInitialised = false; constexpr int32_t kTTFSurfaceCacheSize = 256; @@ -78,7 +80,7 @@ static void TTFToggleHinting(bool) for (int32_t i = 0; i < FontStyleCount; i++) { TTFFontDescriptor* fontDesc = &(gCurrentTTFFontSet->size[i]); - bool use_hinting = gConfigFonts.EnableHinting && fontDesc->hinting_threshold; + bool use_hinting = Config::Get().fonts.EnableHinting && fontDesc->hinting_threshold; TTF_SetFontHinting(fontDesc->font, use_hinting ? 1 : 0); } diff --git a/src/openrct2/drawing/Weather.cpp b/src/openrct2/drawing/Weather.cpp index ef5112e074..025b9b32de 100644 --- a/src/openrct2/drawing/Weather.cpp +++ b/src/openrct2/drawing/Weather.cpp @@ -55,7 +55,7 @@ const DrawWeatherFunc DrawSnowFunctions[] = { */ void DrawWeather(DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer) { - if (gConfigGeneral.RenderWeatherEffects) + if (Config::Get().general.RenderWeatherEffects) { uint32_t viewFlags = 0; diff --git a/src/openrct2/drawing/X8DrawingEngine.cpp b/src/openrct2/drawing/X8DrawingEngine.cpp index 667445e001..57c368237e 100644 --- a/src/openrct2/drawing/X8DrawingEngine.cpp +++ b/src/openrct2/drawing/X8DrawingEngine.cpp @@ -120,7 +120,7 @@ X8DrawingEngine::X8DrawingEngine([[maybe_unused]] const std::shared_ptr(shopItemDescriptor.Naming.Indefinite); - if (gConfigNotifications.GuestBoughtItem) + if (Config::Get().notifications.GuestBoughtItem) { News::AddItemToQueue(News::ItemType::PeepOnRide, STR_PEEP_TRACKING_NOTIFICATION_BOUGHT_X, Id, ft); } @@ -3577,7 +3577,7 @@ void PeepUpdateRideLeaveEntranceDefault(Guest* peep, Ride& ride, CoordsXYZD& ent auto ft = Formatter(); ride.FormatNameTo(ft); - if (gConfigNotifications.RideWarnings) + if (Config::Get().notifications.RideWarnings) { News::AddItemToQueue(News::ItemType::Ride, STR_GUESTS_GETTING_STUCK_ON_RIDE, peep->CurrentRide.ToUnderlying(), ft); } @@ -3881,7 +3881,7 @@ void Guest::UpdateRideFreeVehicleEnterRide(Ride& ride) else msg_string = STR_PEEP_TRACKING_PEEP_IS_ON_X; - if (gConfigNotifications.GuestOnRide) + if (Config::Get().notifications.GuestOnRide) { News::AddItemToQueue(News::ItemType::PeepOnRide, msg_string, Id, ft); } @@ -5035,7 +5035,7 @@ void Guest::UpdateRideLeaveExit() FormatNameTo(ft); ride->FormatNameTo(ft); - if (gConfigNotifications.GuestLeftRide) + if (Config::Get().notifications.GuestLeftRide) { News::AddItemToQueue(News::ItemType::PeepOnRide, STR_PEEP_TRACKING_LEFT_RIDE_X, Id, ft); } diff --git a/src/openrct2/entity/MoneyEffect.cpp b/src/openrct2/entity/MoneyEffect.cpp index 151866762b..c216b791ab 100644 --- a/src/openrct2/entity/MoneyEffect.cpp +++ b/src/openrct2/entity/MoneyEffect.cpp @@ -22,6 +22,8 @@ #include "../world/Map.h" #include "EntityRegistry.h" +using namespace OpenRCT2; + static constexpr CoordsXY _moneyEffectMoveOffset[] = { { 1, -1 }, { 1, 1 }, @@ -179,7 +181,7 @@ void MoneyEffect::Paint(PaintSession& session, int32_t imageDirection) const return; } - if (GuestPurchase && !gConfigGeneral.ShowGuestPurchases) + if (GuestPurchase && !Config::Get().general.ShowGuestPurchases) { // Don't show the money effect for guest purchases when the option is disabled. return; diff --git a/src/openrct2/entity/Peep.cpp b/src/openrct2/entity/Peep.cpp index d8c102f8c5..b00596ff23 100644 --- a/src/openrct2/entity/Peep.cpp +++ b/src/openrct2/entity/Peep.cpp @@ -740,7 +740,7 @@ void Peep::UpdateFalling() if (Action == PeepActionType::Drowning) return; - if (gConfigNotifications.GuestDied) + if (Config::Get().notifications.GuestDied) { auto ft = Formatter(); FormatNameTo(ft); @@ -1126,7 +1126,7 @@ void PeepProblemWarningsUpdate() else if (hungerCounter >= kPeepHungerWarningThreshold && hungerCounter >= gameState.NumGuestsInPark / 16) { warningThrottle[0] = 4; - if (gConfigNotifications.GuestWarnings) + if (Config::Get().notifications.GuestWarnings) { constexpr auto thoughtId = static_cast(PeepThoughtType::Hungry); News::AddItemToQueue(News::ItemType::Peeps, STR_PEEPS_ARE_HUNGRY, thoughtId, {}); @@ -1138,7 +1138,7 @@ void PeepProblemWarningsUpdate() else if (thirstCounter >= kPeepThirstWarningThreshold && thirstCounter >= gameState.NumGuestsInPark / 16) { warningThrottle[1] = 4; - if (gConfigNotifications.GuestWarnings) + if (Config::Get().notifications.GuestWarnings) { constexpr auto thoughtId = static_cast(PeepThoughtType::Thirsty); News::AddItemToQueue(News::ItemType::Peeps, STR_PEEPS_ARE_THIRSTY, thoughtId, {}); @@ -1150,7 +1150,7 @@ void PeepProblemWarningsUpdate() else if (toiletCounter >= kPeepToiletWarningThreshold && toiletCounter >= gameState.NumGuestsInPark / 16) { warningThrottle[2] = 4; - if (gConfigNotifications.GuestWarnings) + if (Config::Get().notifications.GuestWarnings) { constexpr auto thoughtId = static_cast(PeepThoughtType::Toilet); News::AddItemToQueue(News::ItemType::Peeps, STR_PEEPS_CANT_FIND_TOILET, thoughtId, {}); @@ -1162,7 +1162,7 @@ void PeepProblemWarningsUpdate() else if (litterCounter >= kPeepLitterWarningThreshold && litterCounter >= gameState.NumGuestsInPark / 32) { warningThrottle[3] = 4; - if (gConfigNotifications.GuestWarnings) + if (Config::Get().notifications.GuestWarnings) { constexpr auto thoughtId = static_cast(PeepThoughtType::BadLitter); News::AddItemToQueue(News::ItemType::Peeps, STR_PEEPS_DISLIKE_LITTER, thoughtId, {}); @@ -1174,7 +1174,7 @@ void PeepProblemWarningsUpdate() else if (disgustCounter >= kPeepDisgustWarningThreshold && disgustCounter >= gameState.NumGuestsInPark / 32) { warningThrottle[4] = 4; - if (gConfigNotifications.GuestWarnings) + if (Config::Get().notifications.GuestWarnings) { constexpr auto thoughtId = static_cast(PeepThoughtType::PathDisgusting); News::AddItemToQueue(News::ItemType::Peeps, STR_PEEPS_DISGUSTED_BY_PATHS, thoughtId, {}); @@ -1186,7 +1186,7 @@ void PeepProblemWarningsUpdate() else if (vandalismCounter >= kPeepVandalismWarningThreshold && vandalismCounter >= gameState.NumGuestsInPark / 32) { warningThrottle[5] = 4; - if (gConfigNotifications.GuestWarnings) + if (Config::Get().notifications.GuestWarnings) { constexpr auto thoughtId = static_cast(PeepThoughtType::Vandalism); News::AddItemToQueue(News::ItemType::Peeps, STR_PEEPS_DISLIKE_VANDALISM, thoughtId, {}); @@ -1198,7 +1198,7 @@ void PeepProblemWarningsUpdate() else if (noexitCounter >= kPeepNoExitWarningThreshold) { warningThrottle[6] = 4; - if (gConfigNotifications.GuestWarnings) + if (Config::Get().notifications.GuestWarnings) { constexpr auto thoughtId = static_cast(PeepThoughtType::CantFindExit); News::AddItemToQueue(News::ItemType::Peeps, STR_PEEPS_GETTING_LOST_OR_STUCK, thoughtId, {}); @@ -1207,7 +1207,7 @@ void PeepProblemWarningsUpdate() else if (lostCounter >= kPeepLostWarningThreshold) { warningThrottle[6] = 4; - if (gConfigNotifications.GuestWarnings) + if (Config::Get().notifications.GuestWarnings) { constexpr auto thoughtId = static_cast(PeepThoughtType::Lost); News::AddItemToQueue(News::ItemType::Peeps, STR_PEEPS_GETTING_LOST_OR_STUCK, thoughtId, {}); @@ -1220,7 +1220,7 @@ void PeepProblemWarningsUpdate() { // The amount of guests complaining about queue duration is at least 5% of the amount of queuing guests. // This includes guests who are no longer queuing. warningThrottle[7] = 4; - if (gConfigNotifications.GuestWarnings) + if (Config::Get().notifications.GuestWarnings) { auto rideWithMostQueueComplaints = std::max_element( queueComplainingGuestsMap.begin(), queueComplainingGuestsMap.end(), @@ -1251,7 +1251,7 @@ void PeepUpdateCrowdNoise() if (OpenRCT2::Audio::gGameSoundsOff) return; - if (!gConfigSound.SoundEnabled) + if (!Config::Get().sound.SoundEnabled) return; if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) @@ -1791,7 +1791,7 @@ static bool PeepInteractWithEntrance(Peep* peep, const CoordsXYE& coords, uint8_ auto ft = Formatter(); guest->FormatNameTo(ft); ride->FormatNameTo(ft); - if (gConfigNotifications.GuestQueuingForRide) + if (Config::Get().notifications.GuestQueuingForRide) { News::AddItemToQueue(News::ItemType::PeepOnRide, STR_PEEP_TRACKING_PEEP_JOINED_QUEUE_FOR_X, guest->Id, ft); } @@ -1852,7 +1852,7 @@ static bool PeepInteractWithEntrance(Peep* peep, const CoordsXYE& coords, uint8_ { auto ft = Formatter(); guest->FormatNameTo(ft); - if (gConfigNotifications.GuestLeftPark) + if (Config::Get().notifications.GuestLeftPark) { News::AddItemToQueue(News::ItemType::PeepOnRide, STR_PEEP_TRACKING_LEFT_PARK, guest->Id, ft); } @@ -2222,7 +2222,7 @@ static void PeepInteractWithPath(Peep* peep, const CoordsXYE& coords) auto ft = Formatter(); guest->FormatNameTo(ft); ride->FormatNameTo(ft); - if (gConfigNotifications.GuestQueuingForRide) + if (Config::Get().notifications.GuestQueuingForRide) { News::AddItemToQueue( News::ItemType::PeepOnRide, STR_PEEP_TRACKING_PEEP_JOINED_QUEUE_FOR_X, guest->Id, ft); @@ -2339,7 +2339,7 @@ static bool PeepInteractWithShop(Peep* peep, const CoordsXYE& coords) ride->FormatNameTo(ft); StringId string_id = ride->GetRideTypeDescriptor().HasFlag(RIDE_TYPE_FLAG_IN_RIDE) ? STR_PEEP_TRACKING_PEEP_IS_IN_X : STR_PEEP_TRACKING_PEEP_IS_ON_X; - if (gConfigNotifications.GuestUsedFacility) + if (Config::Get().notifications.GuestUsedFacility) { News::AddItemToQueue(News::ItemType::PeepOnRide, string_id, guest->Id, ft); } diff --git a/src/openrct2/interface/Fonts.cpp b/src/openrct2/interface/Fonts.cpp index d32fdff674..75d28c21f1 100644 --- a/src/openrct2/interface/Fonts.cpp +++ b/src/openrct2/interface/Fonts.cpp @@ -17,6 +17,7 @@ #include "../util/Util.h" #include "FontFamilies.h" +using namespace OpenRCT2; using namespace OpenRCT2::Localisation; #ifndef NO_TTF @@ -129,12 +130,15 @@ static bool LoadFont(LocalisationService& localisationService, TTFFontSetDescrip static bool LoadCustomConfigFont(LocalisationService& localisationService) { static TTFFontSetDescriptor TTFFontCustom = { { - { gConfigFonts.FileName.c_str(), gConfigFonts.FontName.c_str(), gConfigFonts.SizeTiny, gConfigFonts.OffsetX, - gConfigFonts.OffsetY, gConfigFonts.HeightTiny, gConfigFonts.HintingThreshold, nullptr }, - { gConfigFonts.FileName.c_str(), gConfigFonts.FontName.c_str(), gConfigFonts.SizeSmall, gConfigFonts.OffsetX, - gConfigFonts.OffsetY, gConfigFonts.HeightSmall, gConfigFonts.HintingThreshold, nullptr }, - { gConfigFonts.FileName.c_str(), gConfigFonts.FontName.c_str(), gConfigFonts.SizeMedium, gConfigFonts.OffsetX, - gConfigFonts.OffsetY, gConfigFonts.HeightMedium, gConfigFonts.HintingThreshold, nullptr }, + { Config::Get().fonts.FileName.c_str(), Config::Get().fonts.FontName.c_str(), Config::Get().fonts.SizeTiny, + Config::Get().fonts.OffsetX, Config::Get().fonts.OffsetY, Config::Get().fonts.HeightTiny, + Config::Get().fonts.HintingThreshold, nullptr }, + { Config::Get().fonts.FileName.c_str(), Config::Get().fonts.FontName.c_str(), Config::Get().fonts.SizeSmall, + Config::Get().fonts.OffsetX, Config::Get().fonts.OffsetY, Config::Get().fonts.HeightSmall, + Config::Get().fonts.HintingThreshold, nullptr }, + { Config::Get().fonts.FileName.c_str(), Config::Get().fonts.FontName.c_str(), Config::Get().fonts.SizeMedium, + Config::Get().fonts.OffsetX, Config::Get().fonts.OffsetY, Config::Get().fonts.HeightMedium, + Config::Get().fonts.HintingThreshold, nullptr }, } }; TTFDispose(); @@ -154,7 +158,7 @@ void TryLoadFonts(LocalisationService& localisationService) if (fontFamily != FAMILY_OPENRCT2_SPRITE) { - if (!gConfigFonts.FileName.empty()) + if (!Config::Get().fonts.FileName.empty()) { if (LoadCustomConfigFont(localisationService)) { diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index 8783cc5e78..6021be084c 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -686,7 +686,7 @@ static int32_t ConsoleCommandGet(InteractiveConsole& console, const arguments_t& } else if (argv[0] == "console_small_font") { - console.WriteFormatLine("console_small_font %d", gConfigInterface.ConsoleSmallFont); + console.WriteFormatLine("console_small_font %d", Config::Get().interface.ConsoleSmallFont); } else if (argv[0] == "location") { @@ -703,19 +703,19 @@ static int32_t ConsoleCommandGet(InteractiveConsole& console, const arguments_t& } else if (argv[0] == "window_scale") { - console.WriteFormatLine("window_scale %.3f", gConfigGeneral.WindowScale); + console.WriteFormatLine("window_scale %.3f", Config::Get().general.WindowScale); } else if (argv[0] == "window_limit") { - console.WriteFormatLine("window_limit %d", gConfigGeneral.WindowLimit); + console.WriteFormatLine("window_limit %d", Config::Get().general.WindowLimit); } else if (argv[0] == "render_weather_effects") { - console.WriteFormatLine("render_weather_effects %d", gConfigGeneral.RenderWeatherEffects); + console.WriteFormatLine("render_weather_effects %d", Config::Get().general.RenderWeatherEffects); } else if (argv[0] == "render_weather_gloom") { - console.WriteFormatLine("render_weather_gloom %d", gConfigGeneral.RenderWeatherGloom); + console.WriteFormatLine("render_weather_gloom %d", Config::Get().general.RenderWeatherGloom); } else if (argv[0] == "cheat_sandbox_mode") { @@ -740,7 +740,7 @@ static int32_t ConsoleCommandGet(InteractiveConsole& console, const arguments_t& #ifndef NO_TTF else if (argv[0] == "enable_hinting") { - console.WriteFormatLine("enable_hinting %d", gConfigFonts.EnableHinting); + console.WriteFormatLine("enable_hinting %d", Config::Get().fonts.EnableHinting); } #endif else @@ -1065,8 +1065,8 @@ static int32_t ConsoleCommandSet(InteractiveConsole& console, const arguments_t& } else if (argv[0] == "console_small_font" && InvalidArguments(&invalidArgs, int_valid[0])) { - gConfigInterface.ConsoleSmallFont = (int_val[0] != 0); - ConfigSaveDefault(); + Config::Get().interface.ConsoleSmallFont = (int_val[0] != 0); + Config::Save(); console.Execute("get console_small_font"); } else if (argv[0] == "location" && InvalidArguments(&invalidArgs, int_valid[0] && int_valid[1])) @@ -1084,8 +1084,8 @@ static int32_t ConsoleCommandSet(InteractiveConsole& console, const arguments_t& else if (argv[0] == "window_scale" && InvalidArguments(&invalidArgs, double_valid[0])) { float newScale = static_cast(0.001 * std::trunc(1000 * double_val[0])); - gConfigGeneral.WindowScale = std::clamp(newScale, 0.5f, 5.0f); - ConfigSaveDefault(); + Config::Get().general.WindowScale = std::clamp(newScale, 0.5f, 5.0f); + Config::Save(); GfxInvalidateScreen(); ContextTriggerResize(); ContextUpdateCursorScale(); @@ -1098,14 +1098,14 @@ static int32_t ConsoleCommandSet(InteractiveConsole& console, const arguments_t& } else if (argv[0] == "render_weather_effects" && InvalidArguments(&invalidArgs, int_valid[0])) { - gConfigGeneral.RenderWeatherEffects = (int_val[0] != 0); - ConfigSaveDefault(); + Config::Get().general.RenderWeatherEffects = (int_val[0] != 0); + Config::Save(); console.Execute("get render_weather_effects"); } else if (argv[0] == "render_weather_gloom" && InvalidArguments(&invalidArgs, int_valid[0])) { - gConfigGeneral.RenderWeatherGloom = (int_val[0] != 0); - ConfigSaveDefault(); + Config::Get().general.RenderWeatherGloom = (int_val[0] != 0); + Config::Save(); console.Execute("get render_weather_gloom"); } else if (argv[0] == "cheat_sandbox_mode" && InvalidArguments(&invalidArgs, int_valid[0])) @@ -1187,8 +1187,8 @@ static int32_t ConsoleCommandSet(InteractiveConsole& console, const arguments_t& #ifndef NO_TTF else if (argv[0] == "enable_hinting" && InvalidArguments(&invalidArgs, int_valid[0])) { - gConfigFonts.EnableHinting = (int_val[0] != 0); - ConfigSaveDefault(); + Config::Get().fonts.EnableHinting = (int_val[0] != 0); + Config::Save(); console.Execute("get enable_hinting"); TTFToggleHinting(); } diff --git a/src/openrct2/interface/Screenshot.cpp b/src/openrct2/interface/Screenshot.cpp index 51f8bcd272..ab00e2df2d 100644 --- a/src/openrct2/interface/Screenshot.cpp +++ b/src/openrct2/interface/Screenshot.cpp @@ -377,7 +377,7 @@ void ScreenshotGiant() { viewport.flags = vp->flags; } - if (gConfigGeneral.TransparentScreenshot) + if (Config::Get().general.TransparentScreenshot) { viewport.flags |= VIEWPORT_FLAG_TRANSPARENT_BACKGROUND; } @@ -445,7 +445,7 @@ static void ApplyOptions(const ScreenshotOptions* options, Viewport& viewport) CheatsSet(CheatType::RemoveLitter); } - if (options->transparent || gConfigGeneral.TransparentScreenshot) + if (options->transparent || Config::Get().general.TransparentScreenshot) { viewport.flags |= VIEWPORT_FLAG_TRANSPARENT_BACKGROUND; } diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index 55026bd566..0555af54a0 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -196,7 +196,7 @@ void ViewportCreate(WindowBase* w, const ScreenCoordsXY& screenCoords, int32_t w viewport->flags = 0; viewport->rotation = GetCurrentRotation(); - if (gConfigGeneral.AlwaysShowGridlines) + if (Config::Get().general.AlwaysShowGridlines) viewport->flags |= VIEWPORT_FLAG_GRIDLINES; w->viewport = viewport; @@ -991,7 +991,7 @@ static void ViewportPaintColumn(PaintSession& session) PaintDrawStructs(session); - if (gConfigGeneral.RenderWeatherGloom && !gTrackDesignSaveMode && !(session.ViewFlags & VIEWPORT_FLAG_HIDE_ENTITIES) + if (Config::Get().general.RenderWeatherGloom && !gTrackDesignSaveMode && !(session.ViewFlags & VIEWPORT_FLAG_HIDE_ENTITIES) && !(session.ViewFlags & VIEWPORT_FLAG_HIGHLIGHT_PATH_ISSUES)) { ViewportPaintWeatherGloom(session.DPI); @@ -1055,7 +1055,7 @@ static void ViewportPaint(const Viewport* viewport, DrawPixelInfo& dpi, const Sc _paintColumns.clear(); - bool useMultithreading = gConfigGeneral.MultiThreading; + bool useMultithreading = Config::Get().general.MultiThreading; if (useMultithreading && _paintJobs == nullptr) { _paintJobs = std::make_unique(); @@ -1256,7 +1256,7 @@ void HideGridlines() WindowBase* mainWindow = WindowGetMain(); if (mainWindow != nullptr) { - if (!gConfigGeneral.AlwaysShowGridlines) + if (!Config::Get().general.AlwaysShowGridlines) { mainWindow->viewport->flags &= ~VIEWPORT_FLAG_GRIDLINES; mainWindow->Invalidate(); @@ -2194,11 +2194,11 @@ uint8_t GetCurrentRotation() int32_t GetHeightMarkerOffset() { // Height labels in units - if (gConfigGeneral.ShowHeightAsUnits) + if (Config::Get().general.ShowHeightAsUnits) return 0; // Height labels in feet - if (gConfigGeneral.MeasurementFormat == MeasurementFormat::Imperial) + if (Config::Get().general.MeasurementFormat == MeasurementFormat::Imperial) return 1 * 256; // Height labels in metres diff --git a/src/openrct2/interface/Window.cpp b/src/openrct2/interface/Window.cpp index 45a7263ad8..cb8dcc9397 100644 --- a/src/openrct2/interface/Window.cpp +++ b/src/openrct2/interface/Window.cpp @@ -191,10 +191,10 @@ static void WindowCloseSurplus(int32_t cap, WindowClass avoid_classification) */ void WindowSetWindowLimit(int32_t value) { - int32_t prev = gConfigGeneral.WindowLimit; + int32_t prev = Config::Get().general.WindowLimit; int32_t val = std::clamp(value, kWindowLimitMin, kWindowLimitMax); - gConfigGeneral.WindowLimit = val; - ConfigSaveDefault(); + Config::Get().general.WindowLimit = val; + Config::Save(); // Checks if value decreases and then closes surplus // windows if one sets a limit lower than the number of windows open if (val < prev) @@ -966,7 +966,7 @@ void WindowZoomSet(WindowBase& w, ZoomLevel zoomLevel, bool atCursor) int32_t saved_map_y = 0; int32_t offset_x = 0; int32_t offset_y = 0; - if (gConfigGeneral.ZoomToCursor && atCursor) + if (Config::Get().general.ZoomToCursor && atCursor) { WindowViewportGetMapCoordsByCursor(w, &saved_map_x, &saved_map_y, &offset_x, &offset_y); } @@ -992,7 +992,7 @@ void WindowZoomSet(WindowBase& w, ZoomLevel zoomLevel, bool atCursor) } // Zooming to cursor? Centre around the tile we were hovering over just now. - if (gConfigGeneral.ZoomToCursor && atCursor) + if (Config::Get().general.ZoomToCursor && atCursor) { WindowViewportCentreTileAroundCursor(w, saved_map_x, saved_map_y, offset_x, offset_y); } @@ -1846,7 +1846,7 @@ void WindowBase::ResizeFrame() // Title widgets[1].right = width - 2; // Close button - if (gConfigInterface.WindowButtonsOnTheLeft) + if (Config::Get().interface.WindowButtonsOnTheLeft) { widgets[2].left = 2; widgets[2].right = 2 + CloseButtonWidth; diff --git a/src/openrct2/localisation/Currency.cpp b/src/openrct2/localisation/Currency.cpp index 9a523a2a2a..9c0917ee3e 100644 --- a/src/openrct2/localisation/Currency.cpp +++ b/src/openrct2/localisation/Currency.cpp @@ -13,6 +13,8 @@ #include "../util/Util.h" #include "StringIds.h" +using namespace OpenRCT2; + // clang-format off CurrencyDescriptor CurrencyDescriptors[EnumValue(CurrencyType::Count)] = { { "GBP", 10, CurrencyAffix::Prefix, u8"£", CurrencyAffix::Suffix, "GBP", STR_POUNDS }, // British Pound @@ -38,12 +40,12 @@ CurrencyDescriptor CurrencyDescriptors[EnumValue(CurrencyType::Count)] = { void CurrencyLoadCustomCurrencyConfig() { - CurrencyDescriptors[EnumValue(CurrencyType::Custom)].rate = gConfigGeneral.CustomCurrencyRate; - CurrencyDescriptors[EnumValue(CurrencyType::Custom)].affix_unicode = gConfigGeneral.CustomCurrencyAffix; - if (!gConfigGeneral.CustomCurrencySymbol.empty()) + CurrencyDescriptors[EnumValue(CurrencyType::Custom)].rate = Config::Get().general.CustomCurrencyRate; + CurrencyDescriptors[EnumValue(CurrencyType::Custom)].affix_unicode = Config::Get().general.CustomCurrencyAffix; + if (!Config::Get().general.CustomCurrencySymbol.empty()) { SafeStrCpy( - CurrencyDescriptors[EnumValue(CurrencyType::Custom)].symbol_unicode, gConfigGeneral.CustomCurrencySymbol.c_str(), - kCurrencySymbolMaxSize); + CurrencyDescriptors[EnumValue(CurrencyType::Custom)].symbol_unicode, + Config::Get().general.CustomCurrencySymbol.c_str(), kCurrencySymbolMaxSize); } } diff --git a/src/openrct2/localisation/Formatting.cpp b/src/openrct2/localisation/Formatting.cpp index 1209b27a11..00e490354c 100644 --- a/src/openrct2/localisation/Formatting.cpp +++ b/src/openrct2/localisation/Formatting.cpp @@ -386,7 +386,7 @@ namespace OpenRCT2 template void FormatCurrency(FormatBuffer& ss, T rawValue) { - auto currencyDesc = &CurrencyDescriptors[EnumValue(gConfigGeneral.CurrencyFormat)]; + auto currencyDesc = &CurrencyDescriptors[EnumValue(Config::Get().general.CurrencyFormat)]; auto value = static_cast(rawValue) * currencyDesc->rate; // Negative sign @@ -536,7 +536,7 @@ namespace OpenRCT2 case FormatToken::Velocity: if constexpr (std::is_integral()) { - switch (gConfigGeneral.MeasurementFormat) + switch (Config::Get().general.MeasurementFormat) { default: case MeasurementFormat::Imperial: @@ -566,7 +566,7 @@ namespace OpenRCT2 case FormatToken::Length: if constexpr (std::is_integral()) { - switch (gConfigGeneral.MeasurementFormat) + switch (Config::Get().general.MeasurementFormat) { default: case MeasurementFormat::Imperial: diff --git a/src/openrct2/localisation/Localisation.cpp b/src/openrct2/localisation/Localisation.cpp index 24fa2a2b7a..a1e0052ea4 100644 --- a/src/openrct2/localisation/Localisation.cpp +++ b/src/openrct2/localisation/Localisation.cpp @@ -38,6 +38,8 @@ #include #include +using namespace OpenRCT2; + thread_local char gCommonStringFormatBuffer[CommonTextBufferSize]; #ifdef DEBUG @@ -362,7 +364,7 @@ void FormatReadableSpeed(char* buf, size_t bufSize, uint64_t sizeBytes) money64 StringToMoney(const char* string_to_monetise) { const char* decimal_char = LanguageGetString(STR_LOCALE_DECIMAL_POINT); - const CurrencyDescriptor* currencyDesc = &CurrencyDescriptors[EnumValue(gConfigGeneral.CurrencyFormat)]; + const CurrencyDescriptor* currencyDesc = &CurrencyDescriptors[EnumValue(Config::Get().general.CurrencyFormat)]; char processedString[128] = {}; Guard::Assert(strlen(string_to_monetise) < sizeof(processedString)); @@ -452,7 +454,7 @@ void MoneyToString(money64 amount, char* buffer_to_put_value_to, size_t buffer_l return; } - const CurrencyDescriptor& currencyDesc = CurrencyDescriptors[EnumValue(gConfigGeneral.CurrencyFormat)]; + const CurrencyDescriptor& currencyDesc = CurrencyDescriptors[EnumValue(Config::Get().general.CurrencyFormat)]; const char* sign = amount >= 0 ? "" : "-"; const uint64_t a = std::abs(amount) * currencyDesc.rate; diff --git a/src/openrct2/management/Award.cpp b/src/openrct2/management/Award.cpp index 7eb6facaf2..876cf2fbed 100644 --- a/src/openrct2/management/Award.cpp +++ b/src/openrct2/management/Award.cpp @@ -644,7 +644,7 @@ void AwardUpdateAll() { // Add award currentAwards.push_back(Award{ 5u, awardType }); - if (gConfigNotifications.ParkAward) + if (Config::Get().notifications.ParkAward) { News::AddItemToQueue(News::ItemType::Award, AwardNewsStrings[EnumValue(awardType)], 0, {}); } diff --git a/src/openrct2/management/Marketing.cpp b/src/openrct2/management/Marketing.cpp index 718ff9e9e7..e33289e09b 100644 --- a/src/openrct2/management/Marketing.cpp +++ b/src/openrct2/management/Marketing.cpp @@ -74,7 +74,7 @@ uint16_t MarketingGetCampaignGuestGenerationProbability(int32_t campaignType) static void MarketingRaiseFinishedNotification(const MarketingCampaign& campaign) { - if (gConfigNotifications.ParkMarketingCampaignFinished) + if (Config::Get().notifications.ParkMarketingCampaignFinished) { Formatter ft; // This sets the string parameters for the marketing types that have an argument. diff --git a/src/openrct2/management/Research.cpp b/src/openrct2/management/Research.cpp index ac79b73dff..6c75a5c863 100644 --- a/src/openrct2/management/Research.cpp +++ b/src/openrct2/management/Research.cpp @@ -257,7 +257,7 @@ void ResearchFinishItem(const ResearchItem& researchItem) if (!gSilentResearch) { - if (gConfigNotifications.RideResearched) + if (Config::Get().notifications.RideResearched) { News::AddItemToQueue(News::ItemType::Research, availabilityString, researchItem.rawValue, ft); } @@ -279,7 +279,7 @@ void ResearchFinishItem(const ResearchItem& researchItem) if (!gSilentResearch) { - if (gConfigNotifications.RideResearched) + if (Config::Get().notifications.RideResearched) { News::AddItemToQueue( News::ItemType::Research, STR_NEWS_ITEM_RESEARCH_NEW_SCENERY_SET_AVAILABLE, researchItem.rawValue, ft); diff --git a/src/openrct2/network/NetworkBase.cpp b/src/openrct2/network/NetworkBase.cpp index 369b4630ae..32fe00ee79 100644 --- a/src/openrct2/network/NetworkBase.cpp +++ b/src/openrct2/network/NetworkBase.cpp @@ -285,7 +285,7 @@ bool NetworkBase::BeginClient(const std::string& host, uint16_t port) // risk of tick collision with the server map and title screen map. GameActions::SuspendQueue(); - auto keyPath = NetworkGetPrivateKeyPath(gConfigNetwork.PlayerName); + auto keyPath = NetworkGetPrivateKeyPath(Config::Get().network.PlayerName); if (!File::Exists(keyPath)) { Console::WriteLine("Generating key... This may take a while"); @@ -313,7 +313,7 @@ bool NetworkBase::BeginClient(const std::string& host, uint16_t port) const std::string hash = _key.PublicKeyHash(); const utf8* publicKeyHash = hash.c_str(); - keyPath = NetworkGetPublicKeyPath(gConfigNetwork.PlayerName, publicKeyHash); + keyPath = NetworkGetPublicKeyPath(Config::Get().network.PlayerName, publicKeyHash); Console::WriteLine("Key generated, saving public bits as %s", keyPath.c_str()); try @@ -375,12 +375,12 @@ bool NetworkBase::BeginServer(uint16_t port, const std::string& address) return false; } - ServerName = gConfigNetwork.ServerName; - ServerDescription = gConfigNetwork.ServerDescription; - ServerGreeting = gConfigNetwork.ServerGreeting; - ServerProviderName = gConfigNetwork.ProviderName; - ServerProviderEmail = gConfigNetwork.ProviderEmail; - ServerProviderWebsite = gConfigNetwork.ProviderWebsite; + ServerName = Config::Get().network.ServerName; + ServerDescription = Config::Get().network.ServerDescription; + ServerGreeting = Config::Get().network.ServerGreeting; + ServerProviderName = Config::Get().network.ProviderName; + ServerProviderEmail = Config::Get().network.ProviderEmail; + ServerProviderWebsite = Config::Get().network.ProviderWebsite; IsServerPlayerInvisible = gOpenRCT2Headless; @@ -389,7 +389,7 @@ bool NetworkBase::BeginServer(uint16_t port, const std::string& address) BeginChatLog(); BeginServerLog(); - NetworkPlayer* player = AddPlayer(gConfigNetwork.PlayerName, ""); + NetworkPlayer* player = AddPlayer(Config::Get().network.PlayerName, ""); player->Flags |= NETWORK_PLAYER_FLAG_ISSERVER; player->Group = 0; player_id = player->Id; @@ -410,7 +410,7 @@ bool NetworkBase::BeginServer(uint16_t port, const std::string& address) status = NETWORK_STATUS_CONNECTED; listening_port = port; - _serverState.gamestateSnapshotsEnabled = gConfigNetwork.DesyncDebugging; + _serverState.gamestateSnapshotsEnabled = Config::Get().network.DesyncDebugging; _advertiser = CreateServerAdvertiser(listening_port); GameLoadScripts(); @@ -856,7 +856,7 @@ bool NetworkBase::CheckDesynchronizaton() intent.PutExtra(INTENT_EXTRA_MESSAGE, std::string{ str_desync }); ContextOpenIntent(&intent); - if (!gConfigNetwork.StayConnected) + if (!Config::Get().network.StayConnected) { Close(); } @@ -928,12 +928,12 @@ std::string NetworkBase::GenerateAdvertiseKey() std::string NetworkBase::GetMasterServerUrl() { - if (gConfigNetwork.MasterServerUrl.empty()) + if (Config::Get().network.MasterServerUrl.empty()) { return OPENRCT2_MASTER_SERVER_URL; } - return gConfigNetwork.MasterServerUrl; + return Config::Get().network.MasterServerUrl; } NetworkGroup* NetworkBase::AddGroup() @@ -1172,7 +1172,7 @@ void NetworkBase::BeginChatLog() void NetworkBase::AppendChatLog(std::string_view s) { - if (gConfigNetwork.LogChat && _chat_log_fs.is_open()) + if (Config::Get().network.LogChat && _chat_log_fs.is_open()) { AppendLog(_chat_log_fs, s); } @@ -1210,7 +1210,7 @@ void NetworkBase::BeginServerLog() void NetworkBase::AppendServerLog(const std::string& s) { - if (gConfigNetwork.LogServerActions && _server_log_fs.is_open()) + if (Config::Get().network.LogServerActions && _server_log_fs.is_open()) { AppendLog(_server_log_fs, s); } @@ -1660,13 +1660,13 @@ void NetworkBase::ServerSendSetDisconnectMsg(NetworkConnection& connection, cons json_t NetworkBase::GetServerInfoAsJson() const { json_t jsonObj = { - { "name", gConfigNetwork.ServerName }, + { "name", Config::Get().network.ServerName }, { "requiresPassword", _password.size() > 0 }, { "version", NetworkGetVersion() }, { "players", GetNumVisiblePlayers() }, - { "maxPlayers", gConfigNetwork.Maxplayers }, - { "description", gConfigNetwork.ServerDescription }, - { "greeting", gConfigNetwork.ServerGreeting }, + { "maxPlayers", Config::Get().network.Maxplayers }, + { "description", Config::Get().network.ServerDescription }, + { "greeting", Config::Get().network.ServerGreeting }, { "dedicated", gOpenRCT2Headless }, }; return jsonObj; @@ -1680,9 +1680,9 @@ void NetworkBase::ServerSendGameInfo(NetworkConnection& connection) // Provider details json_t jsonProvider = { - { "name", gConfigNetwork.ProviderName }, - { "email", gConfigNetwork.ProviderEmail }, - { "website", gConfigNetwork.ProviderWebsite }, + { "name", Config::Get().network.ProviderName }, + { "email", Config::Get().network.ProviderEmail }, + { "website", Config::Get().network.ProviderWebsite }, }; jsonObj["provider"] = jsonProvider; @@ -2202,7 +2202,7 @@ std::string NetworkBase::MakePlayerNameUnique(const std::string& name) void NetworkBase::Client_Handle_TOKEN(NetworkConnection& connection, NetworkPacket& packet) { - auto keyPath = NetworkGetPrivateKeyPath(gConfigNetwork.PlayerName); + auto keyPath = NetworkGetPrivateKeyPath(Config::Get().network.PlayerName); if (!File::Exists(keyPath)) { LOG_ERROR("Key file (%s) was not found. Restart client to re-generate it.", keyPath.c_str()); @@ -2245,7 +2245,7 @@ void NetworkBase::Client_Handle_TOKEN(NetworkConnection& connection, NetworkPack // when process dump gets collected at some point in future. _key.Unload(); - Client_Send_AUTH(gConfigNetwork.PlayerName, gCustomPassword, pubkey, signature); + Client_Send_AUTH(Config::Get().network.PlayerName, gCustomPassword, pubkey, signature); } void NetworkBase::ServerHandleRequestGamestate(NetworkConnection& connection, NetworkPacket& packet) @@ -2677,7 +2677,7 @@ void NetworkBase::ServerHandleAuth(NetworkConnection& connection, NetworkPacket& if (verified) { LOG_VERBOSE("Connection %s: Signature verification ok. Hash %s", hostName, hash.c_str()); - if (gConfigNetwork.KnownKeysOnly && _userManager.GetUserByHash(hash) == nullptr) + if (Config::Get().network.KnownKeysOnly && _userManager.GetUserByHash(hash) == nullptr) { LOG_VERBOSE("Connection %s: Hash %s, not known", hostName, hash.c_str()); connection.AuthStatus = NetworkAuth::UnknownKeyDisallowed; @@ -2733,7 +2733,7 @@ void NetworkBase::ServerHandleAuth(NetworkConnection& connection, NetworkPacket& } } - if (GetNumVisiblePlayers() >= gConfigNetwork.Maxplayers) + if (GetNumVisiblePlayers() >= Config::Get().network.Maxplayers) { connection.AuthStatus = NetworkAuth::Full; LOG_INFO("Connection %s: Server is full.", hostName); @@ -3963,7 +3963,7 @@ void NetworkSendGameAction(const GameAction* action) void NetworkSendPassword(const std::string& password) { auto& network = OpenRCT2::GetContext()->GetNetwork(); - const auto keyPath = NetworkGetPrivateKeyPath(gConfigNetwork.PlayerName); + const auto keyPath = NetworkGetPrivateKeyPath(Config::Get().network.PlayerName); if (!File::Exists(keyPath)) { LOG_ERROR("Private key %s missing! Restart the game to generate it.", keyPath.c_str()); @@ -3986,7 +3986,7 @@ void NetworkSendPassword(const std::string& password) // Don't keep private key in memory. There's no need and it may get leaked // when process dump gets collected at some point in future. network._key.Unload(); - network.Client_Send_AUTH(gConfigNetwork.PlayerName, password, pubkey, signature); + network.Client_Send_AUTH(Config::Get().network.PlayerName, password, pubkey, signature); } void NetworkSetPassword(const char* password) diff --git a/src/openrct2/network/NetworkServerAdvertiser.cpp b/src/openrct2/network/NetworkServerAdvertiser.cpp index fed1d405f5..900b80e3d7 100644 --- a/src/openrct2/network/NetworkServerAdvertiser.cpp +++ b/src/openrct2/network/NetworkServerAdvertiser.cpp @@ -92,7 +92,7 @@ public: { UpdateLAN(); # ifndef DISABLE_HTTP - if (gConfigNetwork.Advertise) + if (Config::Get().network.Advertise) { UpdateWAN(); } @@ -182,9 +182,9 @@ private: { "port", _port }, }; - if (!gConfigNetwork.AdvertiseAddress.empty()) + if (!Config::Get().network.AdvertiseAddress.empty()) { - body["address"] = gConfigNetwork.AdvertiseAddress; + body["address"] = Config::Get().network.AdvertiseAddress; } request.body = body.dump(); @@ -345,9 +345,9 @@ private: static std::string GetMasterServerUrl() { std::string result = OPENRCT2_MASTER_SERVER_URL; - if (!gConfigNetwork.MasterServerUrl.empty()) + if (!Config::Get().network.MasterServerUrl.empty()) { - result = gConfigNetwork.MasterServerUrl; + result = Config::Get().network.MasterServerUrl; } return result; } diff --git a/src/openrct2/network/ServerList.cpp b/src/openrct2/network/ServerList.cpp index b803fb77da..e3dd821c0d 100644 --- a/src/openrct2/network/ServerList.cpp +++ b/src/openrct2/network/ServerList.cpp @@ -360,9 +360,9 @@ std::future> ServerList::FetchOnlineServerListAsync auto f = p->get_future(); std::string masterServerUrl = OPENRCT2_MASTER_SERVER_URL; - if (!gConfigNetwork.MasterServerUrl.empty()) + if (!Config::Get().network.MasterServerUrl.empty()) { - masterServerUrl = gConfigNetwork.MasterServerUrl; + masterServerUrl = Config::Get().network.MasterServerUrl; } Http::Request request; diff --git a/src/openrct2/paint/Paint.cpp b/src/openrct2/paint/Paint.cpp index 2229a88f7f..96f36f517d 100644 --- a/src/openrct2/paint/Paint.cpp +++ b/src/openrct2/paint/Paint.cpp @@ -914,7 +914,7 @@ void PaintDrawMoneyStructs(DrawPixelInfo& dpi, PaintStringStruct* ps) // Use sprite font unless the currency contains characters unsupported by the sprite font auto forceSpriteFont = false; - const auto& currencyDesc = CurrencyDescriptors[EnumValue(gConfigGeneral.CurrencyFormat)]; + const auto& currencyDesc = CurrencyDescriptors[EnumValue(Config::Get().general.CurrencyFormat)]; if (LocalisationService_UseTrueTypeFont() && FontSupportsStringSprite(currencyDesc.symbol_unicode)) { forceSpriteFont = true; diff --git a/src/openrct2/paint/Painter.cpp b/src/openrct2/paint/Painter.cpp index ac85282daf..bab73fd697 100644 --- a/src/openrct2/paint/Painter.cpp +++ b/src/openrct2/paint/Painter.cpp @@ -79,7 +79,7 @@ void Painter::Paint(IDrawingEngine& de) if (text != nullptr) PaintReplayNotice(*dpi, text); - if (gConfigGeneral.ShowFPS) + if (Config::Get().general.ShowFPS) { PaintFPS(*dpi); } diff --git a/src/openrct2/paint/VirtualFloor.cpp b/src/openrct2/paint/VirtualFloor.cpp index 416fa59aff..d8b02bd217 100644 --- a/src/openrct2/paint/VirtualFloor.cpp +++ b/src/openrct2/paint/VirtualFloor.cpp @@ -405,7 +405,7 @@ void VirtualFloorPaint(PaintSession& session) { { 5, 5, _virtualFloorHeight + ((dullEdges & EDGE_NW) ? -2 : 0) }, { 0, 0, 1 } }); } - if (gConfigGeneral.VirtualFloorStyle != VirtualFloorStyles::Glassy) + if (Config::Get().general.VirtualFloorStyle != VirtualFloorStyles::Glassy) return; if (!weAreOccupied && !weAreLit && weAreAboveGround && weAreOwned) diff --git a/src/openrct2/paint/tile_element/Paint.Banner.cpp b/src/openrct2/paint/tile_element/Paint.Banner.cpp index 06becae32e..5d0e2de1be 100644 --- a/src/openrct2/paint/tile_element/Paint.Banner.cpp +++ b/src/openrct2/paint/tile_element/Paint.Banner.cpp @@ -58,7 +58,7 @@ static void PaintBannerScrollingText( banner.FormatTextTo(ft, true); char text[256]; - if (gConfigGeneral.UpperCaseBanners) + if (Config::Get().general.UpperCaseBanners) { FormatStringToUpper(text, sizeof(text), STR_BANNER_TEXT_FORMAT, ft.Data()); } diff --git a/src/openrct2/paint/tile_element/Paint.Entrance.cpp b/src/openrct2/paint/tile_element/Paint.Entrance.cpp index 555eb6a14b..1f447e63c2 100644 --- a/src/openrct2/paint/tile_element/Paint.Entrance.cpp +++ b/src/openrct2/paint/tile_element/Paint.Entrance.cpp @@ -63,7 +63,7 @@ static void PaintRideEntranceExitScrollingText( } char text[256]; - if (gConfigGeneral.UpperCaseBanners) + if (Config::Get().general.UpperCaseBanners) { FormatStringToUpper(text, sizeof(text), STR_BANNER_TEXT_FORMAT, ft.Data()); } @@ -235,7 +235,7 @@ static void PaintParkEntranceScrollingText( } char text[256]; - if (gConfigGeneral.UpperCaseBanners) + if (Config::Get().general.UpperCaseBanners) { FormatStringToUpper(text, sizeof(text), STR_BANNER_TEXT_FORMAT, ft.Data()); } diff --git a/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp b/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp index 52f306ceae..f84992f69b 100644 --- a/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp +++ b/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp @@ -316,7 +316,7 @@ static void PaintLargeSceneryScrollingText( banner->FormatTextTo(ft); char text[256]; - if (gConfigGeneral.UpperCaseBanners) + if (Config::Get().general.UpperCaseBanners) { FormatStringToUpper(text, sizeof(text), STR_SCROLLING_SIGN_TEXT, ft.Data()); } diff --git a/src/openrct2/paint/tile_element/Paint.Path.cpp b/src/openrct2/paint/tile_element/Paint.Path.cpp index b58b438d0e..f29eabe920 100644 --- a/src/openrct2/paint/tile_element/Paint.Path.cpp +++ b/src/openrct2/paint/tile_element/Paint.Path.cpp @@ -161,7 +161,7 @@ static void PathPaintQueueBanner( { ft.Add(STR_RIDE_ENTRANCE_CLOSED); } - if (gConfigGeneral.UpperCaseBanners) + if (Config::Get().general.UpperCaseBanners) { FormatStringToUpper( gCommonStringFormatBuffer, sizeof(gCommonStringFormatBuffer), STR_BANNER_TEXT_FORMAT, ft.Data()); diff --git a/src/openrct2/paint/tile_element/Paint.Surface.cpp b/src/openrct2/paint/tile_element/Paint.Surface.cpp index 2e6d9706c7..b10b01eb47 100644 --- a/src/openrct2/paint/tile_element/Paint.Surface.cpp +++ b/src/openrct2/paint/tile_element/Paint.Surface.cpp @@ -1270,7 +1270,7 @@ void PaintSurface(PaintSession& session, uint8_t direction, uint16_t height, con } if (zoomLevel <= ZoomLevel{ 0 } && has_surface && !(session.ViewFlags & VIEWPORT_FLAG_UNDERGROUND_INSIDE) - && !(session.ViewFlags & VIEWPORT_FLAG_HIDE_BASE) && gConfigGeneral.LandscapeSmoothing) + && !(session.ViewFlags & VIEWPORT_FLAG_HIDE_BASE) && Config::Get().general.LandscapeSmoothing) { ViewportSurfaceSmoothenEdge(session, EDGE_TOPLEFT, selfDescriptor, tileDescriptors[2]); ViewportSurfaceSmoothenEdge(session, EDGE_TOPRIGHT, selfDescriptor, tileDescriptors[3]); @@ -1319,7 +1319,8 @@ void PaintSurface(PaintSession& session, uint8_t direction, uint16_t height, con const auto image_id = ImageId(SPR_WATER_MASK + image_offset, FilterPaletteID::PaletteWater).WithBlended(true); PaintAddImageAsParent(session, image_id, { 0, 0, waterHeight }, { 32, 32, -1 }); - const bool transparent = gConfigGeneral.TransparentWater || (session.ViewFlags & VIEWPORT_FLAG_UNDERGROUND_INSIDE); + const bool transparent = Config::Get().general.TransparentWater + || (session.ViewFlags & VIEWPORT_FLAG_UNDERGROUND_INSIDE); const uint32_t overlayStart = transparent ? SPR_WATER_OVERLAY : SPR_RCT1_WATER_OVERLAY; PaintAttachToPreviousPS(session, ImageId(overlayStart + image_offset), 0, 0); diff --git a/src/openrct2/paint/tile_element/Paint.TileElement.cpp b/src/openrct2/paint/tile_element/Paint.TileElement.cpp index d9ffb53086..8ba863509a 100644 --- a/src/openrct2/paint/tile_element/Paint.TileElement.cpp +++ b/src/openrct2/paint/tile_element/Paint.TileElement.cpp @@ -34,6 +34,8 @@ #include "Paint.Surface.h" #include "Segment.h" +using namespace OpenRCT2; + static void BlankTilesPaint(PaintSession& session, int32_t x, int32_t y); static void PaintTileElementBase(PaintSession& session, const CoordsXY& origCoords); @@ -138,7 +140,7 @@ static void PaintTileElementBase(PaintSession& session, const CoordsXY& origCoor bool partOfVirtualFloor = false; - if (gConfigGeneral.VirtualFloorStyle != VirtualFloorStyles::Off) + if (Config::Get().general.VirtualFloorStyle != VirtualFloorStyles::Off) { partOfVirtualFloor = VirtualFloorTileIsFloor(session.MapPosition); } @@ -284,7 +286,7 @@ static void PaintTileElementBase(PaintSession& session, const CoordsXY& origCoor session.MapPosition = mapPosition; } while (!(tile_element++)->IsLastForTile()); - if (gConfigGeneral.VirtualFloorStyle != VirtualFloorStyles::Off && partOfVirtualFloor) + if (Config::Get().general.VirtualFloorStyle != VirtualFloorStyles::Off && partOfVirtualFloor) { VirtualFloorPaint(session); } diff --git a/src/openrct2/paint/tile_element/Paint.Wall.cpp b/src/openrct2/paint/tile_element/Paint.Wall.cpp index d96b386ce9..25b7445fb3 100644 --- a/src/openrct2/paint/tile_element/Paint.Wall.cpp +++ b/src/openrct2/paint/tile_element/Paint.Wall.cpp @@ -177,7 +177,7 @@ static void PaintWallScrollingText( auto ft = Formatter(); banner->FormatTextTo(ft); char signString[256]; - if (gConfigGeneral.UpperCaseBanners) + if (Config::Get().general.UpperCaseBanners) { FormatStringToUpper(signString, sizeof(signString), STR_SCROLLING_SIGN_TEXT, ft.Data()); } diff --git a/src/openrct2/platform/Crash.cpp b/src/openrct2/platform/Crash.cpp index badd8b0c44..f738a4ae69 100644 --- a/src/openrct2/platform/Crash.cpp +++ b/src/openrct2/platform/Crash.cpp @@ -200,7 +200,7 @@ static bool OnCrash( } auto configFilePathUTF8 = String::ToUtf8(configFilePath); - if (ConfigSave(configFilePathUTF8)) + if (Config::SaveToPath(configFilePathUTF8)) { _uploadFiles[L"attachment_config.ini"] = configFilePath; } diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 72bb089536..e4bc7646cd 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -1618,7 +1618,7 @@ void RidePrepareBreakdown(Ride& ride, int32_t breakdownReason) */ void RideBreakdownAddNewsItem(const Ride& ride) { - if (gConfigNotifications.RideBrokenDown) + if (Config::Get().notifications.RideBrokenDown) { Formatter ft; ride.FormatNameTo(ft); @@ -1645,7 +1645,7 @@ static void RideBreakdownStatusUpdate(Ride& ride) if (!(ride.not_fixed_timeout & 15) && ride.mechanic_status != RIDE_MECHANIC_STATUS_FIXING && ride.mechanic_status != RIDE_MECHANIC_STATUS_HAS_FIXED_STATION_BRAKES) { - if (gConfigNotifications.RideWarnings) + if (Config::Get().notifications.RideWarnings) { Formatter ft; ride.FormatNameTo(ft); @@ -2326,7 +2326,7 @@ static void RideEntranceExitConnected(Ride& ride) // name of ride is parameter of the format string Formatter ft; ride.FormatNameTo(ft); - if (gConfigNotifications.RideWarnings) + if (Config::Get().notifications.RideWarnings) { News::AddItemToQueue(News::ItemType::Ride, STR_ENTRANCE_NOT_CONNECTED, ride.id.ToUnderlying(), ft); } @@ -2338,7 +2338,7 @@ static void RideEntranceExitConnected(Ride& ride) // name of ride is parameter of the format string Formatter ft; ride.FormatNameTo(ft); - if (gConfigNotifications.RideWarnings) + if (Config::Get().notifications.RideWarnings) { News::AddItemToQueue(News::ItemType::Ride, STR_EXIT_NOT_CONNECTED, ride.id.ToUnderlying(), ft); } @@ -2403,7 +2403,7 @@ static void RideShopConnected(const Ride& ride) } // Name of ride is parameter of the format string - if (gConfigNotifications.RideWarnings) + if (Config::Get().notifications.RideWarnings) { Formatter ft; ride2->FormatNameTo(ft); @@ -5221,7 +5221,7 @@ void Ride::SetReversedTrains(bool reverseTrains) void Ride::SetToDefaultInspectionInterval() { - uint8_t defaultInspectionInterval = gConfigGeneral.DefaultInspectionInterval; + uint8_t defaultInspectionInterval = Config::Get().general.DefaultInspectionInterval; if (inspection_interval != defaultInspectionInterval) { if (defaultInspectionInterval <= RIDE_INSPECTION_NEVER) @@ -5253,7 +5253,7 @@ void Ride::Crash(uint8_t vehicleIndex) } } - if (gConfigNotifications.RideCrashed) + if (Config::Get().notifications.RideCrashed) { Formatter ft; FormatNameTo(ft); diff --git a/src/openrct2/ride/RideAudio.cpp b/src/openrct2/ride/RideAudio.cpp index 62c48faad3..5964872087 100644 --- a/src/openrct2/ride/RideAudio.cpp +++ b/src/openrct2/ride/RideAudio.cpp @@ -258,7 +258,7 @@ namespace OpenRCT2::RideAudio return; // TODO Allow circus music (CSS24) to play if ride music is disabled (that should be sound) - if (gGameSoundsOff || !gConfigSound.RideMusicEnabled) + if (gGameSoundsOff || !Config::Get().sound.RideMusicEnabled) return; StopInactiveRideMusicChannels(); diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 4c2af58629..e8bd5939de 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -2762,7 +2762,7 @@ void Vehicle::CheckIfMissing() curRide->lifecycle_flags |= RIDE_LIFECYCLE_HAS_STALLED_VEHICLE; - if (gConfigNotifications.RideStalledVehicles) + if (Config::Get().notifications.RideStalledVehicles) { Formatter ft; ft.Add(GetRideComponentName(GetRideTypeDescriptor(curRide->type).NameConvention.vehicle).number); @@ -4520,7 +4520,7 @@ static void ride_train_crash(Ride& ride, uint16_t numFatalities) if (numFatalities != 0) { - if (gConfigNotifications.RideCasualties) + if (Config::Get().notifications.RideCasualties) { ride.FormatNameTo(ft); News::AddItemToQueue( diff --git a/src/openrct2/ride/coaster/WoodenRollerCoaster.cpp b/src/openrct2/ride/coaster/WoodenRollerCoaster.cpp index 8d788339b6..39d50c643e 100644 --- a/src/openrct2/ride/coaster/WoodenRollerCoaster.cpp +++ b/src/openrct2/ride/coaster/WoodenRollerCoaster.cpp @@ -25,6 +25,8 @@ #include "../TrackData.h" #include "../TrackPaint.h" +using namespace OpenRCT2; + enum { SPR_WOODEN_RC_FLAT_TO_LEFT_BANK_SW_NE = 23497, @@ -8001,7 +8003,7 @@ static void WoodenRCTrackWaterSplash( PaintSession& session, const Ride& ride, uint8_t trackSequence, uint8_t direction, int32_t height, const TrackElement& trackElement) { - const bool transparent = gConfigGeneral.TransparentWater || (session.ViewFlags & VIEWPORT_FLAG_UNDERGROUND_INSIDE); + const bool transparent = Config::Get().general.TransparentWater || (session.ViewFlags & VIEWPORT_FLAG_UNDERGROUND_INSIDE); const auto waterMask = ImageId(SPR_WATER_MASK).WithRemap(FilterPaletteID::PaletteWater).WithBlended(true); const auto waterOverlay = ImageId(transparent ? SPR_WATER_OVERLAY : SPR_RCT1_WATER_OVERLAY); diff --git a/src/openrct2/scenario/Scenario.cpp b/src/openrct2/scenario/Scenario.cpp index ef9ce9876b..7f91d2496e 100644 --- a/src/openrct2/scenario/Scenario.cpp +++ b/src/openrct2/scenario/Scenario.cpp @@ -243,7 +243,7 @@ static void ScenarioCheckEntranceFeeTooHigh() auto y = entrance.y + 16; uint32_t packed_xy = (y << 16) | x; - if (gConfigNotifications.ParkWarnings) + if (Config::Get().notifications.ParkWarnings) { News::AddItemToQueue(News::ItemType::Blank, STR_ENTRANCE_FEE_TOO_HI, packed_xy, {}); } @@ -260,7 +260,7 @@ void ScenarioAutosaveCheck() uint32_t timeSinceSave = Platform::GetTicks() - gLastAutoSaveUpdate; bool shouldSave = false; - switch (gConfigGeneral.AutosaveFrequency) + switch (Config::Get().general.AutosaveFrequency) { case AUTOSAVE_EVERY_MINUTE: shouldSave = timeSinceSave >= 1 * 60 * 1000; @@ -356,7 +356,7 @@ static void ScenarioUpdateDayNightCycle() float currentDayNightCycle = gDayNightCycle; gDayNightCycle = 0; - if (gScreenFlags == SCREEN_FLAGS_PLAYING && gConfigGeneral.DayNightCycle) + if (gScreenFlags == SCREEN_FLAGS_PLAYING && Config::Get().general.DayNightCycle) { float monthFraction = GetDate().GetMonthTicks() / static_cast(kTicksPerMonth); if (monthFraction < (1 / 8.0f)) @@ -692,28 +692,28 @@ ObjectiveStatus Objective::CheckGuestsAndRating() const gameState.ScenarioParkRatingWarningDays++; if (gameState.ScenarioParkRatingWarningDays == 1) { - if (gConfigNotifications.ParkRatingWarnings) + if (Config::Get().notifications.ParkRatingWarnings) { News::AddItemToQueue(News::ItemType::Graph, STR_PARK_RATING_WARNING_4_WEEKS_REMAINING, 0, {}); } } else if (gameState.ScenarioParkRatingWarningDays == 8) { - if (gConfigNotifications.ParkRatingWarnings) + if (Config::Get().notifications.ParkRatingWarnings) { News::AddItemToQueue(News::ItemType::Graph, STR_PARK_RATING_WARNING_3_WEEKS_REMAINING, 0, {}); } } else if (gameState.ScenarioParkRatingWarningDays == 15) { - if (gConfigNotifications.ParkRatingWarnings) + if (Config::Get().notifications.ParkRatingWarnings) { News::AddItemToQueue(News::ItemType::Graph, STR_PARK_RATING_WARNING_2_WEEKS_REMAINING, 0, {}); } } else if (gameState.ScenarioParkRatingWarningDays == 22) { - if (gConfigNotifications.ParkRatingWarnings) + if (Config::Get().notifications.ParkRatingWarnings) { News::AddItemToQueue(News::ItemType::Graph, STR_PARK_RATING_WARNING_1_WEEK_REMAINING, 0, {}); } @@ -855,7 +855,7 @@ bool AllowEarlyCompletion() case NETWORK_MODE_NONE: case NETWORK_MODE_SERVER: default: - return gConfigGeneral.AllowEarlyCompletion; + return Config::Get().general.AllowEarlyCompletion; } } diff --git a/src/openrct2/scenario/ScenarioRepository.cpp b/src/openrct2/scenario/ScenarioRepository.cpp index a7e3d5af2b..573fd5f0aa 100644 --- a/src/openrct2/scenario/ScenarioRepository.cpp +++ b/src/openrct2/scenario/ScenarioRepository.cpp @@ -596,7 +596,7 @@ private: void Sort() { - if (gConfigGeneral.ScenarioSelectMode == SCENARIO_SELECT_MODE_ORIGIN) + if (Config::Get().general.ScenarioSelectMode == SCENARIO_SELECT_MODE_ORIGIN) { std::sort( _scenarios.begin(), _scenarios.end(), [](const ScenarioIndexEntry& a, const ScenarioIndexEntry& b) -> bool { diff --git a/src/openrct2/scenes/title/TitleScene.cpp b/src/openrct2/scenes/title/TitleScene.cpp index eb3b58e658..5fafb6819d 100644 --- a/src/openrct2/scenes/title/TitleScene.cpp +++ b/src/openrct2/scenes/title/TitleScene.cpp @@ -187,7 +187,7 @@ void TitleScene::ChangePresetSequence(size_t preset) } const utf8* configId = TitleSequenceManagerGetConfigID(preset); - gConfigInterface.CurrentTitleSequencePreset = configId; + Config::Get().interface.CurrentTitleSequencePreset = configId; if (!_previewingSequence) _currentSequence = preset; @@ -214,7 +214,7 @@ void TitleScene::TitleInitialise() { _sequencePlayer = GetContext().GetUiContext()->GetTitleSequencePlayer(); } - if (gConfigInterface.RandomTitleSequence) + if (Config::Get().interface.RandomTitleSequence) { const size_t total = TitleSequenceManager::GetCount(); if (total > 0) @@ -310,7 +310,7 @@ bool TitleScene::TryLoadSequence(bool loadPreview) { // Forcefully change the preset to a preset that works. const utf8* configId = TitleSequenceManagerGetConfigID(targetSequence); - gConfigInterface.CurrentTitleSequencePreset = configId; + Config::Get().interface.CurrentTitleSequencePreset = configId; } _currentSequence = targetSequence; GfxInvalidateScreen(); @@ -387,7 +387,7 @@ void TitleSetHideVersionInfo(bool value) size_t TitleGetConfigSequence() { - return TitleSequenceManagerGetIndexForConfigID(gConfigInterface.CurrentTitleSequencePreset.c_str()); + return TitleSequenceManagerGetIndexForConfigID(Config::Get().interface.CurrentTitleSequencePreset.c_str()); } size_t TitleGetCurrentSequence() diff --git a/src/openrct2/scripting/ScriptEngine.cpp b/src/openrct2/scripting/ScriptEngine.cpp index 42fec5d6e3..d7b1800e46 100644 --- a/src/openrct2/scripting/ScriptEngine.cpp +++ b/src/openrct2/scripting/ScriptEngine.cpp @@ -572,7 +572,7 @@ void ScriptEngine::RefreshPlugins() } // Turn on hot reload if not already enabled - if (!_hotReloadingInitialised && gConfigPlugin.EnableHotReloading && NetworkGetMode() == NETWORK_MODE_NONE) + if (!_hotReloadingInitialised && Config::Get().plugin.EnableHotReloading && NetworkGetMode() == NETWORK_MODE_NONE) { SetupHotReloading(); } diff --git a/src/openrct2/scripting/bindings/game/ScConfiguration.hpp b/src/openrct2/scripting/bindings/game/ScConfiguration.hpp index 1874a9bc64..452aa69094 100644 --- a/src/openrct2/scripting/bindings/game/ScConfiguration.hpp +++ b/src/openrct2/scripting/bindings/game/ScConfiguration.hpp @@ -173,8 +173,8 @@ namespace OpenRCT2::Scripting DukObject obj(ctx); if (ns == "general") { - obj.Set("general.language", gConfigGeneral.Language); - obj.Set("general.showFps", gConfigGeneral.ShowFPS); + obj.Set("general.language", Config::Get().general.Language); + obj.Set("general.showFps", Config::Get().general.ShowFPS); } result = obj.Take(); } @@ -205,7 +205,7 @@ namespace OpenRCT2::Scripting } if (key == "general.showFps") { - duk_push_boolean(ctx, gConfigGeneral.ShowFPS); + duk_push_boolean(ctx, Config::Get().general.ShowFPS); return DukValue::take_from_stack(ctx); } } @@ -246,7 +246,7 @@ namespace OpenRCT2::Scripting { if (key == "general.showFps") { - gConfigGeneral.ShowFPS = value.as_bool(); + Config::Get().general.ShowFPS = value.as_bool(); } else { diff --git a/src/openrct2/scripting/bindings/network/ScSocket.hpp b/src/openrct2/scripting/bindings/network/ScSocket.hpp index ca570629ec..71b656875a 100644 --- a/src/openrct2/scripting/bindings/network/ScSocket.hpp +++ b/src/openrct2/scripting/bindings/network/ScSocket.hpp @@ -89,15 +89,16 @@ namespace OpenRCT2::Scripting constexpr char delimiter = ','; size_t start_pos = 0; size_t end_pos = 0; - while ((end_pos = gConfigPlugin.AllowedHosts.find(delimiter, start_pos)) != std::string::npos) + while ((end_pos = Config::Get().plugin.AllowedHosts.find(delimiter, start_pos)) != std::string::npos) { - if (host == gConfigPlugin.AllowedHosts.substr(start_pos, end_pos - start_pos)) + if (host == Config::Get().plugin.AllowedHosts.substr(start_pos, end_pos - start_pos)) { return true; } start_pos = end_pos + 1; } - return host == gConfigPlugin.AllowedHosts.substr(start_pos, gConfigPlugin.AllowedHosts.length() - start_pos); + return host + == Config::Get().plugin.AllowedHosts.substr(start_pos, Config::Get().plugin.AllowedHosts.length() - start_pos); } public: diff --git a/src/openrct2/world/Climate.cpp b/src/openrct2/world/Climate.cpp index 262830c05a..fdbb93134c 100644 --- a/src/openrct2/world/Climate.cpp +++ b/src/openrct2/world/Climate.cpp @@ -398,9 +398,9 @@ static void ClimateUpdateLightning() { if (_lightningTimer == 0) return; - if (gConfigGeneral.DisableLightningEffect) + if (Config::Get().general.DisableLightningEffect) return; - if (!gConfigGeneral.RenderWeatherEffects && !gConfigGeneral.RenderWeatherGloom) + if (!Config::Get().general.RenderWeatherEffects && !Config::Get().general.RenderWeatherGloom) return; _lightningTimer--; diff --git a/test/tests/FormattingTests.cpp b/test/tests/FormattingTests.cpp index 474700bdc0..899adfb126 100644 --- a/test/tests/FormattingTests.cpp +++ b/test/tests/FormattingTests.cpp @@ -140,7 +140,7 @@ TEST_F(FormattingTests, comma_large) TEST_F(FormattingTests, currency) { - gConfigGeneral.CurrencyFormat = CurrencyType::Pounds; + Config::Get().general.CurrencyFormat = CurrencyType::Pounds; ASSERT_EQ(u8"-£251", FormatString("{CURRENCY}", -2510)); ASSERT_EQ(u8"£1", FormatString("{CURRENCY}", 4)); ASSERT_EQ(u8"£1", FormatString("{CURRENCY}", 5)); @@ -151,7 +151,7 @@ TEST_F(FormattingTests, currency) TEST_F(FormattingTests, currency2dp) { - gConfigGeneral.CurrencyFormat = CurrencyType::Pounds; + Config::Get().general.CurrencyFormat = CurrencyType::Pounds; ASSERT_EQ(u8"-£251.00", FormatString("{CURRENCY2DP}", -2510)); ASSERT_EQ(u8"£0.40", FormatString("{CURRENCY2DP}", 4)); ASSERT_EQ(u8"£0.50", FormatString("{CURRENCY2DP}", 5)); @@ -162,7 +162,7 @@ TEST_F(FormattingTests, currency2dp) TEST_F(FormattingTests, currency_yen) { - gConfigGeneral.CurrencyFormat = CurrencyType::Yen; + Config::Get().general.CurrencyFormat = CurrencyType::Yen; ASSERT_EQ(u8"-¥25,100", FormatString("{CURRENCY}", -2510)); ASSERT_EQ(u8"¥40", FormatString("{CURRENCY2DP}", 4)); ASSERT_EQ(u8"¥50", FormatString("{CURRENCY2DP}", 5)); @@ -173,7 +173,7 @@ TEST_F(FormattingTests, currency_yen) TEST_F(FormattingTests, currency2dp_yen) { - gConfigGeneral.CurrencyFormat = CurrencyType::Yen; + Config::Get().general.CurrencyFormat = CurrencyType::Yen; ASSERT_EQ(u8"-¥25,100", FormatString("{CURRENCY2DP}", -2510)); ASSERT_EQ(u8"¥40", FormatString("{CURRENCY2DP}", 4)); ASSERT_EQ(u8"¥50", FormatString("{CURRENCY2DP}", 5)); @@ -184,14 +184,14 @@ TEST_F(FormattingTests, currency2dp_yen) TEST_F(FormattingTests, currency_pts) { - gConfigGeneral.CurrencyFormat = CurrencyType::Peseta; + Config::Get().general.CurrencyFormat = CurrencyType::Peseta; ASSERT_EQ("-251Pts", FormatString("{CURRENCY}", -2510)); ASSERT_EQ("112Pts", FormatString("{CURRENCY}", 1111)); } TEST_F(FormattingTests, currency2dp_pts) { - gConfigGeneral.CurrencyFormat = CurrencyType::Peseta; + Config::Get().general.CurrencyFormat = CurrencyType::Peseta; ASSERT_EQ("-251.00Pts", FormatString("{CURRENCY2DP}", -2510)); ASSERT_EQ("0.40Pts", FormatString("{CURRENCY2DP}", 4)); ASSERT_EQ("111.10Pts", FormatString("{CURRENCY2DP}", 1111)); @@ -211,42 +211,42 @@ TEST_F(FormattingTests, escaped_braces) TEST_F(FormattingTests, velocity_mph) { - gConfigGeneral.MeasurementFormat = MeasurementFormat::Imperial; + Config::Get().general.MeasurementFormat = MeasurementFormat::Imperial; auto actual = FormatString("Train is going at {VELOCITY}.", 1024); ASSERT_EQ("Train is going at 1,024 mph.", actual); } TEST_F(FormattingTests, velocity_kph) { - gConfigGeneral.MeasurementFormat = MeasurementFormat::Metric; + Config::Get().general.MeasurementFormat = MeasurementFormat::Metric; auto actual = FormatString("Train is going at {VELOCITY}.", 1024); ASSERT_EQ("Train is going at 1,648 km/h.", actual); } TEST_F(FormattingTests, velocity_mps) { - gConfigGeneral.MeasurementFormat = MeasurementFormat::SI; + Config::Get().general.MeasurementFormat = MeasurementFormat::SI; auto actual = FormatString("Train is going at {VELOCITY}.", 1024); ASSERT_EQ("Train is going at 457.7 m/s.", actual); } TEST_F(FormattingTests, length_imperial) { - gConfigGeneral.MeasurementFormat = MeasurementFormat::Imperial; + Config::Get().general.MeasurementFormat = MeasurementFormat::Imperial; auto actual = FormatString("Height: {LENGTH}", 1024); ASSERT_EQ("Height: 3,360 ft", actual); } TEST_F(FormattingTests, length_metric) { - gConfigGeneral.MeasurementFormat = MeasurementFormat::Metric; + Config::Get().general.MeasurementFormat = MeasurementFormat::Metric; auto actual = FormatString("Height: {LENGTH}", 1024); ASSERT_EQ("Height: 1,024 m", actual); } TEST_F(FormattingTests, length_si) { - gConfigGeneral.MeasurementFormat = MeasurementFormat::SI; + Config::Get().general.MeasurementFormat = MeasurementFormat::SI; auto actual = FormatString("Height: {LENGTH}", 2048); ASSERT_EQ("Height: 2,048 m", actual); }