Working on loading screen
This commit is contained in:
1 parent
1c2c80f0ea
commit
44f5136f1d
8 files changed
+272
-187
No files matched your search
+32
-10
@@ -8,6 +8,7 @@
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <SDL.h>
|
||||
|
||||
namespace ZL {
|
||||
|
||||
@@ -119,6 +120,9 @@ namespace ZL {
|
||||
}
|
||||
|
||||
std::shared_ptr<UiNode> MenuManager::loadLocalizedUi(const std::string& basePath, const std::string& zipFile) {
|
||||
// Service the OS message queue between UI screens so the window doesn't
|
||||
// get flagged as "not responding" while loading the ~50 UI layout files.
|
||||
SDL_PumpEvents();
|
||||
static const std::string marker = "resources/w/ui/";
|
||||
if (basePath.rfind(marker, 0) == 0) {
|
||||
const std::string localizedPath = "resources/w/ui_" + languageToCode(g_currentLanguage) + "/" + basePath.substr(marker.size());
|
||||
@@ -507,9 +511,6 @@ namespace ZL {
|
||||
}
|
||||
|
||||
void MenuManager::reloadLocalizedGameContent() {
|
||||
ItemRegistry::instance().loadFromJson("resources/config/items.json", CONST_ZIP_FILE);
|
||||
gameState_.questJournal.reloadDefinitionsPreservingState("resources/config/quests.json", CONST_ZIP_FILE);
|
||||
|
||||
// Screens below the Language screen on the menu stack hold onto their old
|
||||
// (pre-reload) UiNode instances, so simply reopening Language on top of
|
||||
// them would leave Main Menu / Settings / the pause menu showing stale
|
||||
@@ -525,16 +526,37 @@ namespace ZL {
|
||||
for (int i = 0; i < depth; ++i) uiManager.popMenu();
|
||||
}
|
||||
|
||||
loadUiRoots(CONST_ZIP_FILE);
|
||||
// Unloading/reloading ~50 UI screens and their textures is heavy enough to
|
||||
// freeze the window for a noticeable moment, so run it the same way the
|
||||
// initial resource load runs: a queue of closures drained one per frame
|
||||
// with the loading screen shown, instead of one big blocking call here.
|
||||
std::vector<std::function<void()>> steps;
|
||||
|
||||
toastTextureQuestNew = loadLocalizedTexture("resources/w/ui/img/toast/quest_new001.png", CONST_ZIP_FILE);
|
||||
toastTextureQuestCompleted = loadLocalizedTexture("resources/w/ui/img/toast/quest_completed001.png", CONST_ZIP_FILE);
|
||||
toastTextureQuestFailed = loadLocalizedTexture("resources/w/ui/img/toast/quest_failed001.png", CONST_ZIP_FILE);
|
||||
toastTextureItemAdded = loadLocalizedTexture("resources/w/ui/img/toast/item_received001.png", CONST_ZIP_FILE);
|
||||
toastTextureItemRemoved = loadLocalizedTexture("resources/w/ui/img/toast/item_removed001.png", CONST_ZIP_FILE);
|
||||
steps.push_back([this]() {
|
||||
ItemRegistry::instance().loadFromJson("resources/config/items.json", CONST_ZIP_FILE);
|
||||
gameState_.questJournal.reloadDefinitionsPreservingState("resources/config/quests.json", CONST_ZIP_FILE);
|
||||
});
|
||||
|
||||
steps.push_back([this]() {
|
||||
renderer.textureManager.UnloadByPrefix("resources/w/ui");
|
||||
loadUiRoots(CONST_ZIP_FILE);
|
||||
|
||||
showMainMenu();
|
||||
toastTextureQuestNew = loadLocalizedTexture("resources/w/ui/img/toast/quest_new001.png", CONST_ZIP_FILE);
|
||||
toastTextureQuestCompleted = loadLocalizedTexture("resources/w/ui/img/toast/quest_completed001.png", CONST_ZIP_FILE);
|
||||
toastTextureQuestFailed = loadLocalizedTexture("resources/w/ui/img/toast/quest_failed001.png", CONST_ZIP_FILE);
|
||||
toastTextureItemAdded = loadLocalizedTexture("resources/w/ui/img/toast/item_received001.png", CONST_ZIP_FILE);
|
||||
toastTextureItemRemoved = loadLocalizedTexture("resources/w/ui/img/toast/item_removed001.png", CONST_ZIP_FILE);
|
||||
});
|
||||
|
||||
steps.push_back([this]() {
|
||||
showMainMenu();
|
||||
});
|
||||
|
||||
if (runAsLoadingSequence) {
|
||||
runAsLoadingSequence(std::move(steps));
|
||||
} else {
|
||||
for (auto& step : steps) step();
|
||||
}
|
||||
}
|
||||
|
||||
void MenuManager::showLoadGameScreen()
|
||||
|
||||
Reference in new issue
Block a user