mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-21 05:39:42 +00:00
Merge branch 'menu_fixes' into 'master'
Follow up fixes for Lua Menu MR !3464 See merge request OpenMW/openmw!3834
This commit is contained in:
commit
a5d88d489b
7 changed files with 26 additions and 8 deletions
|
@ -56,6 +56,7 @@ namespace MWBase
|
|||
virtual void newGameStarted() = 0;
|
||||
virtual void gameLoaded() = 0;
|
||||
virtual void gameEnded() = 0;
|
||||
virtual void noGame() = 0;
|
||||
virtual void objectAddedToScene(const MWWorld::Ptr& ptr) = 0;
|
||||
virtual void objectRemovedFromScene(const MWWorld::Ptr& ptr) = 0;
|
||||
virtual void objectTeleported(const MWWorld::Ptr& ptr) = 0;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "corebindings.hpp"
|
||||
|
||||
#include <chrono>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <components/debug/debuglog.hpp>
|
||||
#include <components/esm3/loadfact.hpp>
|
||||
|
@ -133,7 +134,14 @@ namespace MWLua
|
|||
sol::table api(context.mLua->sol(), sol::create);
|
||||
for (auto& [k, v] : LuaUtil::getMutableFromReadOnly(initCorePackage(context)))
|
||||
api[k] = v;
|
||||
api["sendGlobalEvent"] = sol::nil;
|
||||
api["sendGlobalEvent"] = [context](std::string eventName, const sol::object& eventData) {
|
||||
if (MWBase::Environment::get().getStateManager()->getState() == MWBase::StateManager::State_NoGame)
|
||||
{
|
||||
throw std::logic_error("Can't send global events when no game is loaded");
|
||||
}
|
||||
context.mLuaEvents->addGlobalEvent(
|
||||
{ std::move(eventName), LuaUtil::serialize(eventData, context.mSerializer) });
|
||||
};
|
||||
api["sound"] = sol::nil;
|
||||
api["vfx"] = sol::nil;
|
||||
return LuaUtil::makeReadOnly(api);
|
||||
|
|
|
@ -379,6 +379,12 @@ namespace MWLua
|
|||
mMenuScripts.stateChanged();
|
||||
}
|
||||
|
||||
void LuaManager::noGame()
|
||||
{
|
||||
clear();
|
||||
mMenuScripts.stateChanged();
|
||||
}
|
||||
|
||||
void LuaManager::uiModeChanged(const MWWorld::Ptr& arg)
|
||||
{
|
||||
if (mPlayer.isEmpty())
|
||||
|
|
|
@ -70,6 +70,7 @@ namespace MWLua
|
|||
void newGameStarted() override;
|
||||
void gameLoaded() override;
|
||||
void gameEnded() override;
|
||||
void noGame() override;
|
||||
void objectAddedToScene(const MWWorld::Ptr& ptr) override;
|
||||
void objectRemovedFromScene(const MWWorld::Ptr& ptr) override;
|
||||
void inputEvent(const InputEvent& event) override;
|
||||
|
|
|
@ -62,16 +62,19 @@ void MWState::StateManager::cleanup(bool force)
|
|||
MWBase::Environment::get().getInputManager()->clear();
|
||||
MWBase::Environment::get().getMechanicsManager()->clear();
|
||||
|
||||
mState = State_NoGame;
|
||||
mCharacterManager.setCurrentCharacter(nullptr);
|
||||
mTimePlayed = 0;
|
||||
mLastSavegame.clear();
|
||||
|
||||
MWMechanics::CreatureStats::cleanup();
|
||||
|
||||
endGame();
|
||||
mState = State_NoGame;
|
||||
MWBase::Environment::get().getLuaManager()->noGame();
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: do we need this cleanup?
|
||||
MWBase::Environment::get().getLuaManager()->clear();
|
||||
}
|
||||
MWBase::Environment::get().getLuaManager()->clear();
|
||||
}
|
||||
|
||||
std::map<int, int> MWState::StateManager::buildContentFileIndexMap(const ESM::ESMReader& reader) const
|
||||
|
|
|
@ -421,7 +421,6 @@ local menuGroups = {}
|
|||
local menuPages = {}
|
||||
|
||||
local function resetPlayerGroups()
|
||||
print('MENU reset player groups')
|
||||
local playerGroupsSection = storage.playerSection(common.groupSectionKey)
|
||||
for pageKey, page in pairs(groups) do
|
||||
for groupKey, group in pairs(page) do
|
||||
|
@ -503,7 +502,7 @@ return {
|
|||
if menu.getState() == menu.STATE.Running then
|
||||
updatePlayerGroups()
|
||||
updateGlobalGroups()
|
||||
else
|
||||
elseif menu.getState() == menu.STATE.NoGame then
|
||||
resetPlayerGroups()
|
||||
end
|
||||
end,
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
-- @function [parent=#core] quit
|
||||
|
||||
---
|
||||
-- Send an event to global scripts.
|
||||
-- Send an event to global scripts. Note: in menu scripts, errors if the game is not running (check @{openmw.menu#menu.getState})
|
||||
-- @function [parent=#core] sendGlobalEvent
|
||||
-- @param #string eventName
|
||||
-- @param eventData
|
||||
|
|
Loading…
Reference in a new issue