mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-28 17:56:37 +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
 | ||||
|     sol::table initUserInterfacePackage(const Context&); | ||||
|     void clearUserInterface(); | ||||
| 
 | ||||
|     // Implemented in inputbindings.cpp
 | ||||
|     sol::table initInputPackage(const Context&); | ||||
|  |  | |||
|  | @ -220,6 +220,7 @@ namespace MWLua | |||
|             mPlayer.getRefData().setLuaScripts(nullptr); | ||||
|             mPlayer = MWWorld::Ptr(); | ||||
|         } | ||||
|         clearUserInterface(); | ||||
|     } | ||||
| 
 | ||||
|     void LuaManager::setupPlayer(const MWWorld::Ptr& ptr) | ||||
|  | @ -425,6 +426,7 @@ namespace MWLua | |||
|                 continue; | ||||
|             ESM::LuaScripts data; | ||||
|             scripts->save(data); | ||||
|             clearUserInterface(); | ||||
|             scripts->load(data); | ||||
|         } | ||||
|         for (LocalScripts* scripts : mActiveLocalScripts) | ||||
|  |  | |||
|  | @ -10,6 +10,7 @@ namespace MWLua | |||
| { | ||||
|     namespace | ||||
|     { | ||||
|         std::set<LuaUi::Element*> allElements; | ||||
| 
 | ||||
|         class UiAction final : public Action | ||||
|         { | ||||
|  | @ -152,6 +153,7 @@ namespace MWLua | |||
|         { | ||||
|             if (element->mDestroy) | ||||
|                 return; | ||||
|             allElements.erase(element.get()); | ||||
|             element->mDestroy = true; | ||||
|             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) | ||||
|         { | ||||
|             auto element = std::make_shared<LuaUi::Element>(layout); | ||||
|             allElements.emplace(element.get()); | ||||
|             context.mLuaManager->addAction(std::make_unique<UiAction>(UiAction::CREATE, element, context.mLua)); | ||||
|             return element; | ||||
|         }; | ||||
|  | @ -180,4 +183,10 @@ namespace MWLua | |||
|         return LuaUtil::makeReadOnly(api); | ||||
|     } | ||||
|      | ||||
|     void clearUserInterface() | ||||
|     { | ||||
|         for (auto element : allElements) | ||||
|             element->destroy(); | ||||
|         allElements.clear(); | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue