From 8dbd8b45a8b2ded15077af0b98bec40cade088e1 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 27 Aug 2020 08:44:21 +0200 Subject: [PATCH] feat: add save/exit and resume Fix #54 --- .../overworld/screens/mainmenu/pause.lua | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua index a02f9d7..6de0fbc 100644 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua +++ b/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua @@ -15,6 +15,7 @@ local CharacterWidget = baseWidget:extend() local TeamWidget = menu.BaseWidget:extend() local ViewWidget = menu.BaseWidget:extend() +local SaveExitWidget = menu.BaseWidget:extend() function PauseScreen:new(scene, menu, widget) self.menuSelected = menu or "main" @@ -31,15 +32,22 @@ function PauseScreen:setMenu() menu.BaseWidget(self.scene, "main", "Chao", ">") menu.BaseWidget(self.scene, "main", "Encylopedia", ">") menu.BaseWidget(self.scene, "main", "Options", ">") - menu.BaseWidget(self.scene, "main", "Save / Exit", ">") - menu.BaseWidget(self.scene, "main", "Resume", ">") + self.scene.menusystem.menus["main"]:addSubMenu("save", "Save / Exit") + 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) for i, name in ipairs(game.characters.team) do CharacterWidget(self.scene, name) 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 self.scene.menusystem.menus[self.menuSelected].widget.selected = self.widgetSelected end @@ -55,7 +63,7 @@ function CharacterMenu:new(scene) end function CharacterMenu:cancelAction() - self.scene.menusystem.menus["main"]:getFocus() + self.scene.menusystem:switchMenu("main") end -- Hero custom widget @@ -115,4 +123,23 @@ function ViewWidget:action() self.scene.screens.mainmenu[self.nextView](self.scene) 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