1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Add progress bars to loading saved games and scenarios

This commit is contained in:
Aaron van Geffen
2024-07-14 22:18:31 +02:00
parent 4a981be643
commit 5f0c3d2ffd
4 changed files with 25 additions and 2 deletions

View File

@@ -3720,6 +3720,9 @@ STR_6645 :Makes some UI elements bigger so they are easier to click or tap.
STR_6646 :Author: {STRING}
STR_6647 :Authors: {STRING}
STR_6648 :Loading plugin engine…
STR_6649 :Loading scenario…
STR_6650 :Loading saved game…
STR_6651 :{STRING} ({COMMA32}%)
#############
# Scenarios #

View File

@@ -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;
}

View File

@@ -160,7 +160,9 @@ namespace OpenRCT2
virtual void DisposeDrawingEngine() = 0;
virtual void OpenProgress(StringId captionStringId) = 0;
virtual void SetProgress(uint32_t currentProgress, uint32_t totalCount, StringId format = STR_NONE) = 0;
virtual void SetProgress(
uint32_t currentProgress, uint32_t totalCount, StringId format = STR_NONE, bool forceDraw = false)
= 0;
virtual void CloseProgress() = 0;
virtual bool LoadParkFromFile(const u8string& path, bool loadTitleScreenOnFail = false, bool asScenario = false) = 0;

View File

@@ -1685,6 +1685,9 @@ enum : StringId
STR_STRING_M_OF_N_KIB = 6643,
STR_LOADING_PLUGIN_ENGINE = 6648,
STR_LOADING_SCENARIO = 6649,
STR_LOADING_SAVED_GAME = 6650,
STR_STRING_M_PERCENT = 6651,
// Have to include resource strings (from scenarios and objects) for the time being now that language is partially working
/* MAX_STR_COUNT = 32768 */ // MAX_STR_COUNT - upper limit for number of strings, not the current count strings