mirror of
https://github.com/OpenMW/openmw.git
synced 2025-04-01 08:06:41 +00:00
Let menu scripts clean up before loading a game
This commit is contained in:
parent
0a2adfee16
commit
ad5d594c28
4 changed files with 12 additions and 7 deletions
|
@ -421,6 +421,10 @@ void MWState::StateManager::loadGame(const Character* character, const std::file
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// let menu scripts do cleanup
|
||||||
|
mState = State_Ended;
|
||||||
|
MWBase::Environment::get().getLuaManager()->gameEnded();
|
||||||
|
|
||||||
cleanup();
|
cleanup();
|
||||||
|
|
||||||
Log(Debug::Info) << "Reading save file " << filepath.filename();
|
Log(Debug::Info) << "Reading save file " << filepath.filename();
|
||||||
|
|
|
@ -47,6 +47,7 @@ local recording = nil
|
||||||
|
|
||||||
I.Settings.registerRenderer('inputBinding', function(id, set, arg)
|
I.Settings.registerRenderer('inputBinding', function(id, set, arg)
|
||||||
if type(id) ~= 'string' then error('inputBinding: must have a string default value') end
|
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.type then error('inputBinding: type argument is required') end
|
||||||
if not arg.key then error('inputBinding: key 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]
|
local info = input.actions[arg.key] or input.triggers[arg.key]
|
||||||
|
|
|
@ -90,7 +90,6 @@ local function registerGroup(options)
|
||||||
}
|
}
|
||||||
local valueSection = contextSection(options.key)
|
local valueSection = contextSection(options.key)
|
||||||
local argumentSection = contextSection(options.key .. argumentSectionPostfix)
|
local argumentSection = contextSection(options.key .. argumentSectionPostfix)
|
||||||
argumentSection:removeOnExit()
|
|
||||||
for i, opt in ipairs(options.settings) do
|
for i, opt in ipairs(options.settings) do
|
||||||
local setting = registerSetting(opt)
|
local setting = registerSetting(opt)
|
||||||
setting.order = i
|
setting.order = i
|
||||||
|
|
|
@ -354,6 +354,8 @@ end
|
||||||
|
|
||||||
local function onGroupRegistered(global, key)
|
local function onGroupRegistered(global, key)
|
||||||
local group = common.getSection(global, common.groupSectionKey):get(key)
|
local group = common.getSection(global, common.groupSectionKey):get(key)
|
||||||
|
if not group then return end
|
||||||
|
|
||||||
groups[group.page] = groups[group.page] or {}
|
groups[group.page] = groups[group.page] or {}
|
||||||
local pageGroup = {
|
local pageGroup = {
|
||||||
key = group.key,
|
key = group.key,
|
||||||
|
@ -364,6 +366,8 @@ local function onGroupRegistered(global, key)
|
||||||
if not groups[group.page][pageGroup.key] then
|
if not groups[group.page][pageGroup.key] then
|
||||||
common.getSection(global, group.key):subscribe(onSettingChanged(global))
|
common.getSection(global, group.key):subscribe(onSettingChanged(global))
|
||||||
common.getArgumentSection(global, group.key):subscribe(async:callback(function(_, settingKey)
|
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)
|
local group = common.getSection(global, common.groupSectionKey):get(group.key)
|
||||||
if not group or not pageOptions[group.page] then return end
|
if not group or not pageOptions[group.page] then return end
|
||||||
|
|
||||||
|
@ -431,10 +435,12 @@ local menuGroups = {}
|
||||||
local menuPages = {}
|
local menuPages = {}
|
||||||
|
|
||||||
local function resetPlayerGroups()
|
local function resetPlayerGroups()
|
||||||
|
local settingGroupsSection = storage.playerSection(common.groupSectionKey)
|
||||||
for pageKey, page in pairs(groups) do
|
for pageKey, page in pairs(groups) do
|
||||||
for groupKey, group in pairs(page) do
|
for groupKey, group in pairs(page) do
|
||||||
if not menuGroups[groupKey] and not group.global then
|
if not menuGroups[groupKey] and not group.global then
|
||||||
page[groupKey] = nil
|
page[groupKey] = nil
|
||||||
|
settingGroupsSection:set(groupKey, nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if pageOptions[pageKey] then
|
if pageOptions[pageKey] then
|
||||||
|
@ -487,8 +493,6 @@ local function registerPage(options)
|
||||||
ui.registerSettingsPage(pageOptions[page.key])
|
ui.registerSettingsPage(pageOptions[page.key])
|
||||||
end
|
end
|
||||||
|
|
||||||
local lastState
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
interfaceName = 'Settings',
|
interfaceName = 'Settings',
|
||||||
interface = {
|
interface = {
|
||||||
|
@ -509,14 +513,11 @@ return {
|
||||||
},
|
},
|
||||||
engineHandlers = {
|
engineHandlers = {
|
||||||
onStateChanged = function()
|
onStateChanged = function()
|
||||||
if lastState == menu.STATE.Running then
|
resetPlayerGroups()
|
||||||
resetPlayerGroups()
|
|
||||||
end
|
|
||||||
updatePlayerGroups()
|
updatePlayerGroups()
|
||||||
if menu.getState() == menu.STATE.Running then
|
if menu.getState() == menu.STATE.Running then
|
||||||
updateGlobalGroups()
|
updateGlobalGroups()
|
||||||
end
|
end
|
||||||
lastState = menu.getState()
|
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
eventHandlers = {
|
eventHandlers = {
|
||||||
|
|
Loading…
Reference in a new issue