sonic-bluestreak/sonic-bluestreak.love/scenes/overworld/screens/mainmenu/pause.lua

138 lines
4.2 KiB
Lua
Raw Permalink Normal View History

2021-11-25 10:57:13 +01:00
local ParentScreen = require "scenes.overworld.screens.parent"
local PauseScreen = ParentScreen:extend()
local menu = require "game.modules.menus.fancy"
local baseCharacterMenu = require "scenes.overworld.screens.mainmenu.common.charmenu"
local baseCharacterWidget = require "scenes.overworld.screens.mainmenu.common.charwidget"
local CharacterMenu = baseCharacterMenu:extend()
local CharacterWidget = baseCharacterWidget:extend()
local TeamWidget = menu.BaseWidget:extend()
local ViewWidget = menu.BaseWidget:extend()
local SaveExitWidget = menu.BaseWidget:extend()
local defTransitions = require "birb.modules.transitions"
local radTransitions = require "game.modules.transitions"
local ConfirmDialog = require "game.modules.confirmdialog"
local const = require "scenes.overworld.screens.mainmenu.const"
function PauseScreen:new(scene, menu, widget)
self.menuSelected = menu or "main"
self.widgetSelected = widget
self.widget = widget
PauseScreen.super.new(self, scene, "Menu")
end
function PauseScreen:setMenu()
menu.FancyMenu(self.scene, "main", const.X, const.Y, 108, 10, false)
TeamWidget(self.scene)
menu.BaseWidget(self.scene, "main", "Quest", ">")
ViewWidget(self.scene, "Items", "items")
menu.BaseWidget(self.scene, "main", "Chao", ">")
menu.BaseWidget(self.scene, "main", "Encylopedia", ">")
--menu.BaseWidget(self.scene, "main", "Options", ">")
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()
self.scene.menusystem.menus["main"]:setCancelWidget()
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:switchMenu(self.menuSelected)
self.scene.menusystem.menus["main"].isVisible = true
if (self.widgetSelected ~= nil) then
self.scene.menusystem.menus[self.menuSelected].widget.selected = self.widgetSelected
self.scene.menusystem.menus[self.menuSelected].cursorTransition = self.widgetSelected - 1
end
self.scene.menusystem:setSoundFromSceneAssets("mBeep")
end
function PauseScreen:draw()
end
-- Character menu
function CharacterMenu:cancelAction()
self.scene.assets:playSFX("mBeep")
self.scene.menusystem:switchMenu("main")
end
-- Hero custom widget
--
function CharacterWidget:action()
self.scene.assets:playSFX("mSelect")
self.scene.screens.mainmenu.character(self.scene, self.charName)
end
-- Team Widget
--
function TeamWidget:new(scene)
TeamWidget.super.new(self, scene, "main", "Team", ">")
end
function TeamWidget:action()
self.scene.assets:playSFX("mBeep")
self.scene.menusystem.menus["character"]:getFocus()
end
-- View Widget
function ViewWidget:new(scene, name, view)
TeamWidget.super.new(self, scene, "main", name, ">")
self.nextView = view
end
function ViewWidget:action()
self.scene.assets:playSFX("mSelect")
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 or self.exit) then
self.scene.assets:playSFX("mSelect")
else
self.scene.assets:playSFX("mBack")
end
if (self.save) then
self.scene.world:savePosition()
game:write()
end
if (self.exit) then
if (self.save) then
self:exitToMenu()
else
local confirm = ConfirmDialog(self.scene, "Do you to exit the game ? \nAll unsaved data will be lost.",
function() self:exitToMenu() end)
confirm:setCancelChoice(2)
end
else
self.scene:unpause()
end
end
function SaveExitWidget:exitToMenu()
core.screen:startTransition(defTransitions.default, defTransitions.circle, function() game:reload() scenes.menus.main() end, 424/2, 240/2)
self.scene.tweens:newTween(0, 0.3, {ringBorder=-16}, "inOutQuad")
self.scene.tweens:newTween(0, 0.3, {timeBorder=-20}, "inOutQuad")
end
return PauseScreen