feat: add save/exit and resume

Fix #54
This commit is contained in:
Kazhnuz 2020-08-27 08:44:21 +02:00
parent 717d7c57c0
commit 8dbd8b45a8

View file

@ -15,6 +15,7 @@ local CharacterWidget = baseWidget:extend()
local TeamWidget = menu.BaseWidget:extend() local TeamWidget = menu.BaseWidget:extend()
local ViewWidget = menu.BaseWidget:extend() local ViewWidget = menu.BaseWidget:extend()
local SaveExitWidget = menu.BaseWidget:extend()
function PauseScreen:new(scene, menu, widget) function PauseScreen:new(scene, menu, widget)
self.menuSelected = menu or "main" self.menuSelected = menu or "main"
@ -31,15 +32,22 @@ function PauseScreen:setMenu()
menu.BaseWidget(self.scene, "main", "Chao", ">") menu.BaseWidget(self.scene, "main", "Chao", ">")
menu.BaseWidget(self.scene, "main", "Encylopedia", ">") menu.BaseWidget(self.scene, "main", "Encylopedia", ">")
menu.BaseWidget(self.scene, "main", "Options", ">") menu.BaseWidget(self.scene, "main", "Options", ">")
menu.BaseWidget(self.scene, "main", "Save / Exit", ">") self.scene.menusystem.menus["main"]:addSubMenu("save", "Save / Exit")
menu.BaseWidget(self.scene, "main", "Resume", ">") SaveExitWidget(self.scene, "main", "Resume", false, false)
SaveExitWidget(self.scene, "save", "Save game", true, false)
SaveExitWidget(self.scene, "save", "Save and exit", true, true)
SaveExitWidget(self.scene, "save", "Exit game", false, true)
self.scene.menusystem.menus["main"]:finalize()
CharacterMenu(self.scene) CharacterMenu(self.scene)
for i, name in ipairs(game.characters.team) do for i, name in ipairs(game.characters.team) do
CharacterWidget(self.scene, name) CharacterWidget(self.scene, name)
end end
self.scene.menusystem.menus["character"].isLocked = true
self.scene.menusystem.menus[self.menuSelected]:getFocus() self.scene.menusystem:switchMenu(self.menuSelected)
if (self.widgetSelected ~= nil) then if (self.widgetSelected ~= nil) then
self.scene.menusystem.menus[self.menuSelected].widget.selected = self.widgetSelected self.scene.menusystem.menus[self.menuSelected].widget.selected = self.widgetSelected
end end
@ -55,7 +63,7 @@ function CharacterMenu:new(scene)
end end
function CharacterMenu:cancelAction() function CharacterMenu:cancelAction()
self.scene.menusystem.menus["main"]:getFocus() self.scene.menusystem:switchMenu("main")
end end
-- Hero custom widget -- Hero custom widget
@ -115,4 +123,23 @@ function ViewWidget:action()
self.scene.screens.mainmenu[self.nextView](self.scene) self.scene.screens.mainmenu[self.nextView](self.scene)
end end
-- Save & Exit Widget
function SaveExitWidget:new(scene, menu, name, save, exit)
SaveExitWidget.super.new(self, scene, menu, name, "")
self.exit = exit
self.save = save
end
function SaveExitWidget:action()
if (self.save) then
game:write()
end
if (self.exit) then
scenes.debug.menu()
else
self.scene:unpause()
end
end
return PauseScreen return PauseScreen