diff --git a/src/openrct2-ui/WindowManager.cpp b/src/openrct2-ui/WindowManager.cpp index 4b6aece012..5ae9cf4996 100644 --- a/src/openrct2-ui/WindowManager.cpp +++ b/src/openrct2-ui/WindowManager.cpp @@ -269,11 +269,6 @@ public: return nullptr; } - case WindowClass::ProgressWindow: - { - std::string message = intent->GetStringExtra(INTENT_EXTRA_MESSAGE); - return ProgressWindowOpen(message); - } case WindowClass::Ride: { const auto rideId = RideId::FromUnderlying(intent->GetSIntExtra(INTENT_EXTRA_RIDE_ID)); @@ -340,6 +335,26 @@ public: return window; } + case INTENT_ACTION_PROGRESS_OPEN: + { + std::string message = intent->GetStringExtra(INTENT_EXTRA_MESSAGE); + return ProgressWindowOpen(message); + } + + case INTENT_ACTION_PROGRESS_SET: + { + uint32_t currentProgress = intent->GetUIntExtra(INTENT_EXTRA_PROGRESS_OFFSET); + uint32_t totalCount = intent->GetUIntExtra(INTENT_EXTRA_PROGRESS_TOTAL); + ProgressWindowSet(currentProgress, totalCount); + return nullptr; + } + + case INTENT_ACTION_PROGRESS_CLOSE: + { + ProgressWindowClose(); + return nullptr; + } + case INTENT_ACTION_NULL: // Intent does not hold an intent action break; diff --git a/src/openrct2-ui/windows/ProgressWindow.cpp b/src/openrct2-ui/windows/ProgressWindow.cpp index c803f193a0..96de0ae963 100644 --- a/src/openrct2-ui/windows/ProgressWindow.cpp +++ b/src/openrct2-ui/windows/ProgressWindow.cpp @@ -69,6 +69,8 @@ namespace OpenRCT2::Ui::Windows private: std::string _captionTemplate; std::string _currentCaption; + uint32_t _currentProgress; + uint32_t _totalCount; uint8_t style; public: @@ -85,35 +87,37 @@ namespace OpenRCT2::Ui::Windows max_width = min_width; max_height = min_height; - style = nextStyle++ % std::size(kVehicleStyles); + ApplyStyle(); } void OnUpdate() override { - frame_no += 3; - if (frame_no > width) - { - frame_no = 0; - style++; - if (style >= 3) - style = 0; - } - - InvalidateWidget(WIDX_BACKGROUND); + Invalidate(); } void OnPrepareDraw() override { ResizeFrame(); + PrepareCaption(); + } + + void ApplyStyle() + { + style = nextStyle++; + nextStyle %= std::size(kVehicleStyles); } void PrepareCaption() { - std::stringstream caption; - caption << _captionTemplate; - caption << " (" << frame_no << " / " << width << ")"; - - _currentCaption = caption.str(); + if (_totalCount > 0) + { + std::stringstream caption; + caption << _captionTemplate; + caption << " (" << _currentProgress << " / " << _totalCount << ")"; + _currentCaption = caption.str(); + } + else + _currentCaption = _captionTemplate; // Set window title auto ft = Formatter::Common(); @@ -123,7 +127,6 @@ namespace OpenRCT2::Ui::Windows void OnDraw(DrawPixelInfo& dpi) override { - PrepareCaption(); WindowDrawWidgets(*this, dpi); auto& widget = widgets[WIDX_TITLE]; @@ -156,6 +159,17 @@ namespace OpenRCT2::Ui::Windows void SetCaptionTemplate(const std::string& text) { _captionTemplate = text; + _currentProgress = 0; + _totalCount = 0; + + ApplyStyle(); + Invalidate(); + } + + void SetProgress(uint32_t currentProgress, uint32_t totalCount) + { + _currentProgress = currentProgress; + _totalCount = totalCount; Invalidate(); } }; @@ -178,7 +192,17 @@ namespace OpenRCT2::Ui::Windows return window; } - // force close + void ProgressWindowSet(uint32_t currentProgress, uint32_t totalCount) + { + auto window = WindowFindByClass(WindowClass::ProgressWindow); + if (window == nullptr) + { + return; + } + auto progressWindow = static_cast(window); + progressWindow->SetProgress(currentProgress, totalCount); + } + void ProgressWindowClose() { auto window = WindowFindByClass(WindowClass::ProgressWindow); diff --git a/src/openrct2-ui/windows/Window.h b/src/openrct2-ui/windows/Window.h index 624f34cbc4..258dc22afc 100644 --- a/src/openrct2-ui/windows/Window.h +++ b/src/openrct2-ui/windows/Window.h @@ -168,6 +168,7 @@ namespace OpenRCT2::Ui::Windows void WindowNetworkStatusClose(); WindowBase* ProgressWindowOpen(const std::string& text); + void ProgressWindowSet(uint32_t currentProgress, uint32_t totalCount); void ProgressWindowClose(); void WindowTextInputKey(WindowBase* w, uint32_t keycode); diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index 99680f7863..c2fa8518ca 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -521,10 +521,10 @@ namespace OpenRCT2 if (!gOpenRCT2Headless) { auto* preloaderScene = GetPreloaderScene(); - preloaderScene->AddJob([this]() { InitialiseRepositories(); }); + SetActiveScene(preloaderScene); // TODO: preload the title scene in another (parallel) job. - SetActiveScene(preloaderScene); + preloaderScene->AddJob([this]() { InitialiseRepositories(); }); } else { @@ -549,35 +549,34 @@ namespace OpenRCT2 } auto currentLanguage = _localisationService->GetCurrentLanguage(); - auto* preloaderScene = GetPreloaderScene(); - preloaderScene->UpdateCaption(STR_CHECKING_OBJECT_FILES); + OpenProgress(STR_CHECKING_OBJECT_FILES); _objectRepository->LoadOrConstruct(currentLanguage); - preloaderScene->UpdateCaption(STR_LOADING_GENERIC); + OpenProgress(STR_LOADING_GENERIC); Audio::LoadAudioObjects(); if (!gOpenRCT2Headless) { - preloaderScene->UpdateCaption(STR_CHECKING_ASSET_PACKS); + OpenProgress(STR_CHECKING_ASSET_PACKS); _assetPackManager->Scan(); _assetPackManager->LoadEnabledAssetPacks(); _assetPackManager->Reload(); } - preloaderScene->UpdateCaption(STR_CHECKING_TRACK_DESIGN_FILES); + OpenProgress(STR_CHECKING_TRACK_DESIGN_FILES); _trackDesignRepository->Scan(currentLanguage); - preloaderScene->UpdateCaption(STR_CHECKING_SCENARIO_FILES); + OpenProgress(STR_CHECKING_SCENARIO_FILES); _scenarioRepository->Scan(currentLanguage); - preloaderScene->UpdateCaption(STR_CHECKING_TITLE_SEQUENCES); + OpenProgress(STR_CHECKING_TITLE_SEQUENCES); TitleSequenceManager::Scan(); - if (preloaderScene->GetCompletionScene() == GetTitleScene()) - preloaderScene->UpdateCaption(STR_LOADING_TITLE_SEQUENCE); + if (GetPreloaderScene()->GetCompletionScene() == GetTitleScene()) + OpenProgress(STR_LOADING_TITLE_SEQUENCE); else - preloaderScene->UpdateCaption(STR_LOADING_GENERIC); + OpenProgress(STR_LOADING_GENERIC); } public: @@ -646,12 +645,26 @@ namespace OpenRCT2 _drawingEngine = nullptr; } - void SetProgress(size_t currentProgress, size_t totalCount) override + void OpenProgress(StringId captionStringId) override { - if (GetActiveScene() != GetPreloaderScene()) - return; + auto captionString = _localisationService->GetString(captionStringId); + auto intent = Intent(INTENT_ACTION_PROGRESS_OPEN); + intent.PutExtra(INTENT_EXTRA_MESSAGE, captionString); + ContextOpenIntent(&intent); + } - GetPreloaderScene()->SetProgress(currentProgress, totalCount); + void SetProgress(uint32_t currentProgress, uint32_t totalCount) override + { + auto intent = Intent(INTENT_ACTION_PROGRESS_SET); + intent.PutExtra(INTENT_EXTRA_PROGRESS_OFFSET, currentProgress); + intent.PutExtra(INTENT_EXTRA_PROGRESS_TOTAL, totalCount); + ContextOpenIntent(&intent); + } + + void CloseProgress() override + { + auto intent = Intent(INTENT_ACTION_PROGRESS_CLOSE); + ContextOpenIntent(&intent); } bool LoadParkFromFile(const u8string& path, bool loadTitleScreenOnFail = false, bool asScenario = false) final override diff --git a/src/openrct2/Context.h b/src/openrct2/Context.h index 4fa8e38c66..88ea5b391c 100644 --- a/src/openrct2/Context.h +++ b/src/openrct2/Context.h @@ -158,7 +158,10 @@ namespace OpenRCT2 virtual bool Initialise() abstract; virtual void InitialiseDrawingEngine() abstract; virtual void DisposeDrawingEngine() abstract; - virtual void SetProgress(size_t currentProgress, size_t totalCount) abstract; + + virtual void OpenProgress(StringId captionStringId) abstract; + virtual void SetProgress(uint32_t currentProgress, uint32_t totalCount) abstract; + virtual void CloseProgress() abstract; virtual bool LoadParkFromFile( const u8string& path, bool loadTitleScreenOnFail = false, bool asScenario = false) abstract; diff --git a/src/openrct2/core/FileIndex.hpp b/src/openrct2/core/FileIndex.hpp index 442bb92f38..0a9b9b31a3 100644 --- a/src/openrct2/core/FileIndex.hpp +++ b/src/openrct2/core/FileIndex.hpp @@ -212,7 +212,7 @@ private: auto reportProgress = [&]() { const size_t completed = processed; Console::WriteFormat("File %5zu of %zu, done %3d%%\r", completed, totalCount, completed * 100 / totalCount); - OpenRCT2::GetContext()->SetProgress(completed, totalCount); + OpenRCT2::GetContext()->SetProgress(static_cast(completed), static_cast(totalCount)); }; for (size_t rangeStart = 0; rangeStart < totalCount; rangeStart += stepSize) diff --git a/src/openrct2/scenes/preloader/PreloaderScene.cpp b/src/openrct2/scenes/preloader/PreloaderScene.cpp index b4505f0fbb..ad520cc16c 100644 --- a/src/openrct2/scenes/preloader/PreloaderScene.cpp +++ b/src/openrct2/scenes/preloader/PreloaderScene.cpp @@ -29,7 +29,6 @@ using namespace OpenRCT2; PreloaderScene::PreloaderScene(IContext& context) : Scene(context) , _jobs(1) - , _captionId(STR_LOADING_GENERIC) { } @@ -48,8 +47,6 @@ void PreloaderScene::Load() auto* drawingContext = engine->GetDrawingContext(); drawingContext->Clear(*engine->GetDrawingPixelInfo(), PALETTE_INDEX_10); - UpdateCaption(_captionId); - LOG_VERBOSE("PreloaderScene::Load() finished"); } @@ -71,26 +68,6 @@ void PreloaderScene::Tick() } } -void PreloaderScene::UpdateCaption(StringId stringId) -{ - _captionId = stringId; - - auto intent = Intent(WindowClass::NetworkStatus); - intent.PutExtra(INTENT_EXTRA_MESSAGE, GetContext().GetLocalisationService().GetString(stringId)); - ContextOpenIntent(&intent); -}; - -void PreloaderScene::SetProgress(size_t currentProgress, size_t totalCount) -{ - std::stringstream caption; - caption << GetContext().GetLocalisationService().GetString(_captionId); - caption << " (" << currentProgress << " / " << totalCount << ")"; - - auto intent = Intent(WindowClass::NetworkStatus); - intent.PutExtra(INTENT_EXTRA_MESSAGE, caption.str()); - ContextOpenIntent(&intent); -} - void PreloaderScene::Stop() { Audio::StopAll(); diff --git a/src/openrct2/scenes/preloader/PreloaderScene.h b/src/openrct2/scenes/preloader/PreloaderScene.h index eaf7eafcd7..09324df707 100644 --- a/src/openrct2/scenes/preloader/PreloaderScene.h +++ b/src/openrct2/scenes/preloader/PreloaderScene.h @@ -23,8 +23,6 @@ namespace OpenRCT2 void Load() override; void Tick() override; void Stop() override; - void UpdateCaption(StringId stringId); - void SetProgress(size_t currentProgress, size_t totalCount); void AddJob(const std::function& fn) { _jobs.AddTask(fn); @@ -32,6 +30,5 @@ namespace OpenRCT2 private: JobPool _jobs; - StringId _captionId; }; } // namespace OpenRCT2 diff --git a/src/openrct2/scenes/title/TitleScene.cpp b/src/openrct2/scenes/title/TitleScene.cpp index c9dc43f685..07e38464b4 100644 --- a/src/openrct2/scenes/title/TitleScene.cpp +++ b/src/openrct2/scenes/title/TitleScene.cpp @@ -206,11 +206,6 @@ void TitleScene::CreateWindows() ContextOpenWindow(WindowClass::TitleOptions); ContextOpenWindow(WindowClass::TitleLogo); WindowResizeGui(ContextGetWidth(), ContextGetHeight()); - - auto intent = Intent(WindowClass::ProgressWindow); - intent.PutExtra(INTENT_EXTRA_MESSAGE, "Important stuff is loading"); - ContextOpenIntent(&intent); - _hideVersionInfo = false; } diff --git a/src/openrct2/windows/Intent.h b/src/openrct2/windows/Intent.h index 96e635c82e..a9365b7341 100644 --- a/src/openrct2/windows/Intent.h +++ b/src/openrct2/windows/Intent.h @@ -49,6 +49,9 @@ enum IntentAction INTENT_ACTION_SET_MAP_TOOLTIP, INTENT_ACTION_NEW_SCENERY, INTENT_ACTION_TILE_MODIFY, + INTENT_ACTION_PROGRESS_OPEN, + INTENT_ACTION_PROGRESS_SET, + INTENT_ACTION_PROGRESS_CLOSE, INTENT_ACTION_NULL = 255, }; @@ -126,4 +129,6 @@ enum INTENT_EXTRA_BANNER_INDEX, INTENT_EXTRA_FORMATTER, INTENT_EXTRA_SCENERY_GROUP_ENTRY_INDEX, + INTENT_EXTRA_PROGRESS_OFFSET, + INTENT_EXTRA_PROGRESS_TOTAL, };