1
0
Fork 0
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:
Alexei Kotov 2024-02-05 00:41:11 +00:00
commit a5d88d489b
7 changed files with 26 additions and 8 deletions

View file

@ -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;

View file

@ -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);

View file

@ -379,6 +379,12 @@ namespace MWLua
mMenuScripts.stateChanged();
}
void LuaManager::noGame()
{
clear();
mMenuScripts.stateChanged();
}
void LuaManager::uiModeChanged(const MWWorld::Ptr& arg)
{
if (mPlayer.isEmpty())

View file

@ -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;

View file

@ -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

View file

@ -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,

View file

@ -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