mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-18 20:43:04 +01:00
Add progress bars to loading saved games and scenarios
This commit is contained in:
@@ -656,13 +656,20 @@ namespace OpenRCT2
|
||||
ContextOpenIntent(&intent);
|
||||
}
|
||||
|
||||
void SetProgress(uint32_t currentProgress, uint32_t totalCount, StringId format = STR_NONE) override
|
||||
void SetProgress(
|
||||
uint32_t currentProgress, uint32_t totalCount, StringId format = STR_NONE, bool forceDraw = false) override
|
||||
{
|
||||
auto intent = Intent(INTENT_ACTION_PROGRESS_SET);
|
||||
intent.PutExtra(INTENT_EXTRA_PROGRESS_OFFSET, currentProgress);
|
||||
intent.PutExtra(INTENT_EXTRA_PROGRESS_TOTAL, totalCount);
|
||||
intent.PutExtra(INTENT_EXTRA_STRING_ID, format);
|
||||
ContextOpenIntent(&intent);
|
||||
|
||||
// Ideally, we'd force a redraw at all times at this point. OpenGL has to be directed
|
||||
// from the main thread, though, so this cannot be invoked when off main thread.
|
||||
// It's fine (and indeed useful!) for synchronous calls, so we keep it as an option.
|
||||
if (!gOpenRCT2Headless && forceDraw)
|
||||
Draw();
|
||||
}
|
||||
|
||||
void CloseProgress() override
|
||||
@@ -755,7 +762,11 @@ namespace OpenRCT2
|
||||
parkImporter = ParkImporter::CreateS6(*_objectRepository);
|
||||
}
|
||||
|
||||
OpenProgress(asScenario ? STR_LOADING_SCENARIO : STR_LOADING_SAVED_GAME);
|
||||
SetProgress(0, 100, STR_STRING_M_PERCENT, true);
|
||||
|
||||
auto result = parkImporter->LoadFromStream(stream, info.Type == FILE_TYPE::SCENARIO, false, path.c_str());
|
||||
SetProgress(30, 100, STR_STRING_M_PERCENT, true);
|
||||
|
||||
// From this point onwards the currently loaded park will be corrupted if loading fails
|
||||
// so reload the title screen if that happens.
|
||||
@@ -763,10 +774,12 @@ namespace OpenRCT2
|
||||
|
||||
GameUnloadScripts();
|
||||
_objectManager->LoadObjects(result.RequiredObjects);
|
||||
SetProgress(70, 100, STR_STRING_M_PERCENT, true);
|
||||
|
||||
// TODO: Have a separate GameState and exchange once loaded.
|
||||
auto& gameState = ::GetGameState();
|
||||
parkImporter->Import(gameState);
|
||||
SetProgress(100, 100, STR_STRING_M_PERCENT, true);
|
||||
|
||||
gScenarioSavePath = path;
|
||||
gCurrentLoadedPath = path;
|
||||
@@ -841,6 +854,7 @@ namespace OpenRCT2
|
||||
windowManager->ShowError(STR_PARK_USES_FALLBACK_IMAGES_WARNING, STR_EMPTY, Formatter());
|
||||
}
|
||||
|
||||
CloseProgress();
|
||||
return true;
|
||||
}
|
||||
catch (const ObjectLoadException& e)
|
||||
@@ -916,6 +930,7 @@ namespace OpenRCT2
|
||||
Console::Error::WriteLine(e.what());
|
||||
}
|
||||
|
||||
CloseProgress();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user