mirror of
https://github.com/OpenMW/openmw.git
synced 2025-04-14 04:06:44 +00:00
Merge branch 'clean_lua_ui' into 'master'
Clear Lua-created UI on game load and reloadlua command See merge request OpenMW/openmw!1418
This commit is contained in:
commit
a39305b108
3 changed files with 12 additions and 0 deletions
|
@ -58,6 +58,7 @@ namespace MWLua
|
||||||
|
|
||||||
// Implemented in uibindings.cpp
|
// Implemented in uibindings.cpp
|
||||||
sol::table initUserInterfacePackage(const Context&);
|
sol::table initUserInterfacePackage(const Context&);
|
||||||
|
void clearUserInterface();
|
||||||
|
|
||||||
// Implemented in inputbindings.cpp
|
// Implemented in inputbindings.cpp
|
||||||
sol::table initInputPackage(const Context&);
|
sol::table initInputPackage(const Context&);
|
||||||
|
|
|
@ -220,6 +220,7 @@ namespace MWLua
|
||||||
mPlayer.getRefData().setLuaScripts(nullptr);
|
mPlayer.getRefData().setLuaScripts(nullptr);
|
||||||
mPlayer = MWWorld::Ptr();
|
mPlayer = MWWorld::Ptr();
|
||||||
}
|
}
|
||||||
|
clearUserInterface();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaManager::setupPlayer(const MWWorld::Ptr& ptr)
|
void LuaManager::setupPlayer(const MWWorld::Ptr& ptr)
|
||||||
|
@ -425,6 +426,7 @@ namespace MWLua
|
||||||
continue;
|
continue;
|
||||||
ESM::LuaScripts data;
|
ESM::LuaScripts data;
|
||||||
scripts->save(data);
|
scripts->save(data);
|
||||||
|
clearUserInterface();
|
||||||
scripts->load(data);
|
scripts->load(data);
|
||||||
}
|
}
|
||||||
for (LocalScripts* scripts : mActiveLocalScripts)
|
for (LocalScripts* scripts : mActiveLocalScripts)
|
||||||
|
|
|
@ -10,6 +10,7 @@ namespace MWLua
|
||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
std::set<LuaUi::Element*> allElements;
|
||||||
|
|
||||||
class UiAction final : public Action
|
class UiAction final : public Action
|
||||||
{
|
{
|
||||||
|
@ -152,6 +153,7 @@ namespace MWLua
|
||||||
{
|
{
|
||||||
if (element->mDestroy)
|
if (element->mDestroy)
|
||||||
return;
|
return;
|
||||||
|
allElements.erase(element.get());
|
||||||
element->mDestroy = true;
|
element->mDestroy = true;
|
||||||
context.mLuaManager->addAction(std::make_unique<UiAction>(UiAction::DESTROY, element, context.mLua));
|
context.mLuaManager->addAction(std::make_unique<UiAction>(UiAction::DESTROY, element, context.mLua));
|
||||||
};
|
};
|
||||||
|
@ -168,6 +170,7 @@ namespace MWLua
|
||||||
api["create"] = [context](const sol::table& layout)
|
api["create"] = [context](const sol::table& layout)
|
||||||
{
|
{
|
||||||
auto element = std::make_shared<LuaUi::Element>(layout);
|
auto element = std::make_shared<LuaUi::Element>(layout);
|
||||||
|
allElements.emplace(element.get());
|
||||||
context.mLuaManager->addAction(std::make_unique<UiAction>(UiAction::CREATE, element, context.mLua));
|
context.mLuaManager->addAction(std::make_unique<UiAction>(UiAction::CREATE, element, context.mLua));
|
||||||
return element;
|
return element;
|
||||||
};
|
};
|
||||||
|
@ -180,4 +183,10 @@ namespace MWLua
|
||||||
return LuaUtil::makeReadOnly(api);
|
return LuaUtil::makeReadOnly(api);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clearUserInterface()
|
||||||
|
{
|
||||||
|
for (auto element : allElements)
|
||||||
|
element->destroy();
|
||||||
|
allElements.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue