1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-04-01 08:36:40 +00:00

Let menu scripts clean up before loading a game

This commit is contained in:
uramer 2024-01-27 14:47:22 +01:00
parent 0a2adfee16
commit ad5d594c28
4 changed files with 12 additions and 7 deletions

View file

@ -421,6 +421,10 @@ void MWState::StateManager::loadGame(const Character* character, const std::file
{
try
{
// let menu scripts do cleanup
mState = State_Ended;
MWBase::Environment::get().getLuaManager()->gameEnded();
cleanup();
Log(Debug::Info) << "Reading save file " << filepath.filename();

View file

@ -47,6 +47,7 @@ local recording = nil
I.Settings.registerRenderer('inputBinding', function(id, set, arg)
if type(id) ~= 'string' then error('inputBinding: must have a string default value') end
if not arg then error('inputBinding: argument with "key" and "type" is required') end
if not arg.type then error('inputBinding: type argument is required') end
if not arg.key then error('inputBinding: key argument is required') end
local info = input.actions[arg.key] or input.triggers[arg.key]

View file

@ -90,7 +90,6 @@ local function registerGroup(options)
}
local valueSection = contextSection(options.key)
local argumentSection = contextSection(options.key .. argumentSectionPostfix)
argumentSection:removeOnExit()
for i, opt in ipairs(options.settings) do
local setting = registerSetting(opt)
setting.order = i

View file

@ -354,6 +354,8 @@ end
local function onGroupRegistered(global, key)
local group = common.getSection(global, common.groupSectionKey):get(key)
if not group then return end
groups[group.page] = groups[group.page] or {}
local pageGroup = {
key = group.key,
@ -364,6 +366,8 @@ local function onGroupRegistered(global, key)
if not groups[group.page][pageGroup.key] then
common.getSection(global, group.key):subscribe(onSettingChanged(global))
common.getArgumentSection(global, group.key):subscribe(async:callback(function(_, settingKey)
if settingKey == nil then return end
local group = common.getSection(global, common.groupSectionKey):get(group.key)
if not group or not pageOptions[group.page] then return end
@ -431,10 +435,12 @@ local menuGroups = {}
local menuPages = {}
local function resetPlayerGroups()
local settingGroupsSection = storage.playerSection(common.groupSectionKey)
for pageKey, page in pairs(groups) do
for groupKey, group in pairs(page) do
if not menuGroups[groupKey] and not group.global then
page[groupKey] = nil
settingGroupsSection:set(groupKey, nil)
end
end
if pageOptions[pageKey] then
@ -487,8 +493,6 @@ local function registerPage(options)
ui.registerSettingsPage(pageOptions[page.key])
end
local lastState
return {
interfaceName = 'Settings',
interface = {
@ -509,14 +513,11 @@ return {
},
engineHandlers = {
onStateChanged = function()
if lastState == menu.STATE.Running then
resetPlayerGroups()
end
resetPlayerGroups()
updatePlayerGroups()
if menu.getState() == menu.STATE.Running then
updateGlobalGroups()
end
lastState = menu.getState()
end,
},
eventHandlers = {