sonic-bluestreak/sonic-boost.love/scenes/subgame/sonic-boost/controller/pause.lua

103 lines
2.4 KiB
Lua
Raw Normal View History

local PauseMenu = Object:extend()
local Menu = require "modules.menus"
local ResumeWidget = Menu.Widget.Base:extend()
local RestartWidget = Menu.Widget.Base:extend()
local ExitWidget = Menu.Widget.Base:extend()
function PauseMenu:new(controller)
self.controller = controller
self.active = false
self.height = 56+16
self.assets = self.controller.assets
self.menusystem = Menu.Controller()
self.menu = Menu.TextMenu(424/2, self.height+8, self.assets.fonts["menu"], 6)
self.menusystem:addMenu(self.menu)
self.menu:centerText(180)
self.menu:setSound(self.assets.sfx["select"])
self.menu.focus = true
self.menu:addWidget(ResumeWidget(self))
self.menu:addWidget(RestartWidget(self))
self.menu:addWidget(ExitWidget(self))
self.canvas = nil
self.activeCanvas = false
self.width = 0
end
function PauseMenu:update(dt)
self.menusystem:update(dt)
end
function PauseMenu:draw()
if (self.activeCanvas == false) then
local width = self.menu:getWidth() or 10
self.width = self:drawCanvas(width, 64)
end
love.graphics.draw(self.canvas, (424 - self.width)/2, self.height - 28)
self.menusystem:draw()
end
function PauseMenu:drawCanvas(width, height)
local width = (math.floor( width / 16 ) + 1) * 16
local height = height or 80
self.canvas = love.graphics.newCanvas(width + 64, height + 64)
CScreen:cease()
love.graphics.setCanvas( self.canvas )
--self.controller.gui.textbox["solid"]:draw(32, 32, width, height)
self.controller.assets.fonts["title"]:draw("PAUSE", (width + 64)/2, 12, -1)
love.graphics.setCanvas( )
CScreen:cease()
self.activeCanvas = true
return width + 64
end
--- MENU WIDGETS
function ResumeWidget:new(menusystem)
ResumeWidget.super.new(self)
self.label = "resume"
self.menusystem = menusystem
self.controller = menusystem.controller
end
function ResumeWidget:action()
self.controller.pause = false
end
function RestartWidget:new(menusystem)
RestartWidget.super.new(self)
self.label = "restart"
self.menusystem = menusystem
self.controller = menusystem.controller
end
function RestartWidget:action()
self.controller:restartLevel()
end
function ExitWidget:new(menusystem)
ExitWidget.super.new(self)
self.label = "exit"
self.menusystem = menusystem
self.controller = menusystem.controller
end
function ExitWidget:action()
self.controller:exitLevel()
end
return PauseMenu