Don't clear menu UI on game load

ini_importer_tests
uramer 12 months ago
parent d1268acf95
commit a6e2ceebb8

@ -546,7 +546,8 @@ namespace MWGui
{
try
{
LuaUi::clearUserInterface();
LuaUi::clearGameInterface();
LuaUi::clearMenuInterface();
mStatsWatcher.reset();

@ -15,6 +15,7 @@ namespace MWLua
struct Context
{
bool mIsMenu;
bool mIsGlobal;
LuaManager* mLuaManager;
LuaUtil::LuaState* mLua;

@ -75,6 +75,7 @@ namespace MWLua
void LuaManager::init()
{
Context context;
context.mIsMenu = false;
context.mIsGlobal = true;
context.mLuaManager = this;
context.mLua = &mLua;
@ -86,11 +87,14 @@ namespace MWLua
localContext.mIsGlobal = false;
localContext.mSerializer = mLocalSerializer.get();
Context menuContext = context;
menuContext.mIsMenu = true;
for (const auto& [name, package] : initCommonPackages(context))
mLua.addCommonPackage(name, package);
for (const auto& [name, package] : initGlobalPackages(context))
mGlobalScripts.addPackage(name, package);
for (const auto& [name, package] : initMenuPackages(context))
for (const auto& [name, package] : initMenuPackages(menuContext))
mMenuScripts.addPackage(name, package);
mLocalPackages = initLocalPackages(localContext);
@ -278,7 +282,7 @@ namespace MWLua
void LuaManager::clear()
{
LuaUi::clearUserInterface();
LuaUi::clearGameInterface();
mUiResourceManager.clear();
MWBase::Environment::get().getWorld()->getPostProcessor()->disableDynamicShaders();
mActiveLocalScripts.clear();
@ -526,7 +530,8 @@ namespace MWLua
{
Log(Debug::Info) << "Reload Lua";
LuaUi::clearUserInterface();
LuaUi::clearGameInterface();
LuaUi::clearMenuInterface();
MWBase::Environment::get().getWindowManager()->setConsoleMode("");
MWBase::Environment::get().getL10nManager()->dropCache();
mUiResourceManager.clear();

@ -155,15 +155,27 @@ namespace MWLua
}
};
api["content"] = LuaUi::loadContentConstructor(context.mLua);
api["create"] = [luaManager = context.mLuaManager](const sol::table& layout) {
auto element = LuaUi::Element::make(layout);
luaManager->addAction([element] { wrapAction(element, [&] { element->create(); }); }, "Create UI");
api["create"] = [context](const sol::table& layout) {
auto element
= context.mIsMenu ? LuaUi::Element::makeMenuElement(layout) : LuaUi::Element::makeGameElement(layout);
context.mLuaManager->addAction([element] { wrapAction(element, [&] { element->create(); }); }, "Create UI");
return element;
};
api["updateAll"] = [context]() {
LuaUi::Element::forEach([](LuaUi::Element* e) { e->mUpdate = true; });
context.mLuaManager->addAction(
[]() { LuaUi::Element::forEach([](LuaUi::Element* e) { e->update(); }); }, "Update all UI elements");
if (context.mIsMenu)
{
LuaUi::Element::forEachMenuElement([](LuaUi::Element* e) { e->mUpdate = true; });
context.mLuaManager->addAction(
[]() { LuaUi::Element::forEachMenuElement([](LuaUi::Element* e) { e->update(); }); },
"Update all menu UI elements");
}
else
{
LuaUi::Element::forEachGameElement([](LuaUi::Element* e) { e->mUpdate = true; });
context.mLuaManager->addAction(
[]() { LuaUi::Element::forEachGameElement([](LuaUi::Element* e) { e->update(); }); },
"Update all game UI elements");
}
};
api["_getMenuTransparency"] = []() -> float { return Settings::gui().mMenuTransparency; };

@ -240,7 +240,8 @@ namespace LuaUi
}
}
std::map<Element*, std::shared_ptr<Element>> Element::sAllElements;
std::map<Element*, std::shared_ptr<Element>> Element::sGameElements;
std::map<Element*, std::shared_ptr<Element>> Element::sMenuElements;
Element::Element(sol::table layout)
: mRoot(nullptr)
@ -251,10 +252,17 @@ namespace LuaUi
{
}
std::shared_ptr<Element> Element::make(sol::table layout)
std::shared_ptr<Element> Element::makeGameElement(sol::table layout)
{
std::shared_ptr<Element> ptr(new Element(std::move(layout)));
sAllElements[ptr.get()] = ptr;
sGameElements[ptr.get()] = ptr;
return ptr;
}
std::shared_ptr<Element> Element::makeMenuElement(sol::table layout)
{
std::shared_ptr<Element> ptr(new Element(std::move(layout)));
sMenuElements[ptr.get()] = ptr;
return ptr;
}
@ -302,6 +310,7 @@ namespace LuaUi
mRoot = nullptr;
mLayout = sol::make_object(mLayout.lua_state(), sol::nil);
}
sAllElements.erase(this);
sGameElements.erase(this);
sMenuElements.erase(this);
}
}

@ -7,12 +7,20 @@ namespace LuaUi
{
struct Element
{
static std::shared_ptr<Element> make(sol::table layout);
static std::shared_ptr<Element> makeGameElement(sol::table layout);
static std::shared_ptr<Element> makeMenuElement(sol::table layout);
template <class Callback>
static void forEach(Callback callback)
static void forEachGameElement(Callback callback)
{
for (auto& [e, _] : sAllElements)
for (auto& [e, _] : sGameElements)
callback(e);
}
template <class Callback>
static void forEachMenuElement(Callback callback)
{
for (auto& [e, _] : sMenuElements)
callback(e);
}
@ -28,12 +36,14 @@ namespace LuaUi
void destroy();
friend void clearUserInterface();
friend void clearGameInterface();
friend void clearMenuInterface();
private:
Element(sol::table layout);
sol::table layout() { return LuaUtil::cast<sol::table>(mLayout); }
static std::map<Element*, std::shared_ptr<Element>> sAllElements;
static std::map<Element*, std::shared_ptr<Element>> sGameElements;
static std::map<Element*, std::shared_ptr<Element>> sMenuElements;
};
}

@ -44,10 +44,17 @@ namespace LuaUi
return types;
}
void clearUserInterface()
void clearGameInterface()
{
// TODO: move settings clearing logic to Lua?
clearSettings();
while (!Element::sAllElements.empty())
Element::sAllElements.begin()->second->destroy();
while (!Element::sGameElements.empty())
Element::sGameElements.begin()->second->destroy();
}
void clearMenuInterface()
{
while (!Element::sMenuElements.empty())
Element::sMenuElements.begin()->second->destroy();
}
}

@ -10,7 +10,8 @@ namespace LuaUi
const std::unordered_map<std::string, std::string>& widgetTypeToName();
void clearUserInterface();
void clearGameInterface();
void clearMenuInterface();
}
#endif // OPENMW_LUAUI_WIDGETLIST

Loading…
Cancel
Save