1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-22 05:09:41 +00:00

Queue Lua handler uiModeChanged

This commit is contained in:
Petr Mikheev 2023-10-21 13:04:02 +02:00
parent b9c986b0b8
commit 4d66679204
3 changed files with 18 additions and 3 deletions

View file

@ -246,6 +246,13 @@ namespace MWLua
reloadAllScriptsImpl(); reloadAllScriptsImpl();
mReloadAllScriptsRequested = false; mReloadAllScriptsRequested = false;
} }
if (mDelayedUiModeChangedArg)
{
if (playerScripts)
playerScripts->uiModeChanged(*mDelayedUiModeChangedArg, true);
mDelayedUiModeChangedArg = std::nullopt;
}
} }
void LuaManager::applyDelayedActions() void LuaManager::applyDelayedActions()
@ -275,6 +282,7 @@ namespace MWLua
mGlobalScripts.removeAllScripts(); mGlobalScripts.removeAllScripts();
mGlobalScriptsStarted = false; mGlobalScriptsStarted = false;
mNewGameStarted = false; mNewGameStarted = false;
mDelayedUiModeChangedArg = std::nullopt;
if (!mPlayer.isEmpty()) if (!mPlayer.isEmpty())
{ {
mPlayer.getCellRef().unsetRefNum(); mPlayer.getCellRef().unsetRefNum();
@ -325,9 +333,15 @@ namespace MWLua
{ {
if (mPlayer.isEmpty()) if (mPlayer.isEmpty())
return; return;
ObjectId argId = arg.isEmpty() ? ObjectId() : getId(arg);
if (mApplyingDelayedActions)
{
mDelayedUiModeChangedArg = argId;
return;
}
PlayerScripts* playerScripts = dynamic_cast<PlayerScripts*>(mPlayer.getRefData().getLuaScripts()); PlayerScripts* playerScripts = dynamic_cast<PlayerScripts*>(mPlayer.getRefData().getLuaScripts());
if (playerScripts) if (playerScripts)
playerScripts->uiModeChanged(arg, mApplyingDelayedActions); playerScripts->uiModeChanged(argId, false);
} }
void LuaManager::objectAddedToScene(const MWWorld::Ptr& ptr) void LuaManager::objectAddedToScene(const MWWorld::Ptr& ptr)

View file

@ -204,6 +204,7 @@ namespace MWLua
std::optional<DelayedAction> mTeleportPlayerAction; std::optional<DelayedAction> mTeleportPlayerAction;
std::vector<std::string> mUIMessages; std::vector<std::string> mUIMessages;
std::vector<std::pair<std::string, Misc::Color>> mInGameConsoleMessages; std::vector<std::pair<std::string, Misc::Color>> mInGameConsoleMessages;
std::optional<ObjectId> mDelayedUiModeChangedArg;
LuaUtil::LuaStorage mGlobalStorage{ mLua.sol() }; LuaUtil::LuaStorage mGlobalStorage{ mLua.sol() };
LuaUtil::LuaStorage mPlayerStorage{ mLua.sol() }; LuaUtil::LuaStorage mPlayerStorage{ mLua.sol() };

View file

@ -66,9 +66,9 @@ namespace MWLua
} }
// `arg` is either forwarded from MWGui::pushGuiMode or empty // `arg` is either forwarded from MWGui::pushGuiMode or empty
void uiModeChanged(const MWWorld::Ptr& arg, bool byLuaAction) void uiModeChanged(ObjectId arg, bool byLuaAction)
{ {
if (arg.isEmpty()) if (arg.isZeroOrUnset())
callEngineHandlers(mUiModeChanged, byLuaAction); callEngineHandlers(mUiModeChanged, byLuaAction);
else else
callEngineHandlers(mUiModeChanged, byLuaAction, LObject(arg)); callEngineHandlers(mUiModeChanged, byLuaAction, LObject(arg));