scenes/boost: fix pause menu crashes
This commit is contained in:
parent
592e92ea6d
commit
7b2a5298ba
2 changed files with 18 additions and 50 deletions
|
@ -3,14 +3,14 @@ local PauseMenu = ListBox:extend()
|
|||
|
||||
local Widget = require "core.modules.menusystem.widgets"
|
||||
|
||||
local ResumeWidget = Widget.Base:extend()
|
||||
local RestartWidget = Widget.Base:extend()
|
||||
local ExitWidget = Widget.Base:extend()
|
||||
local ResumeWidget = Widget.Text:extend()
|
||||
local RestartWidget = Widget.Text:extend()
|
||||
local ExitWidget = Widget.Text:extend()
|
||||
|
||||
function PauseMenu:new(controller)
|
||||
local height, width, x, y
|
||||
height = 72
|
||||
width = 64
|
||||
width = 72
|
||||
x = 424/2 - width/2
|
||||
y = 240/2 - height/2
|
||||
|
||||
|
@ -18,76 +18,45 @@ function PauseMenu:new(controller)
|
|||
self.controller = controller
|
||||
|
||||
self:setSound(self.controller.assets.sfx["select"])
|
||||
self.haveFocus = false
|
||||
self.isActive = false
|
||||
self.isVisible = false
|
||||
|
||||
ResumeWidget(self)
|
||||
RestartWidget(self)
|
||||
ExitWidget(self)
|
||||
local font = self.controller.assets.fonts["menu"]
|
||||
|
||||
self.canvas = nil
|
||||
self.activeCanvas = false
|
||||
self.width = 0
|
||||
ResumeWidget(self, font)
|
||||
RestartWidget(self, font)
|
||||
ExitWidget(self, font)
|
||||
end
|
||||
|
||||
function PauseMenu:draw()
|
||||
if (self.activeCanvas == false) then
|
||||
local width = self:getWidth() or 10
|
||||
self.width = self:drawCanvas(width, 64)
|
||||
end
|
||||
|
||||
love.graphics.draw(self.canvas, (424 - self.width)/2, self.height - 28)
|
||||
PauseMenu.super.draw(self)
|
||||
|
||||
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)
|
||||
|
||||
core.screen: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( )
|
||||
core.screen:cease()
|
||||
|
||||
self.activeCanvas = true
|
||||
|
||||
return width + 64
|
||||
end
|
||||
|
||||
--- MENU WIDGETS
|
||||
|
||||
function ResumeWidget:new(menu)
|
||||
ResumeWidget.super.new(self, menu)
|
||||
self.label = "resume"
|
||||
function ResumeWidget:new(menu, font)
|
||||
ResumeWidget.super.new(self, menu, font, "resume")
|
||||
end
|
||||
|
||||
function ResumeWidget:action()
|
||||
self.controller.pause = false
|
||||
self.menu.isActive = false
|
||||
self.menu.isVisible = false
|
||||
end
|
||||
|
||||
function RestartWidget:new(menu)
|
||||
RestartWidget.super.new(self, menu)
|
||||
self.label = "restart"
|
||||
function RestartWidget:new(menu, font)
|
||||
ResumeWidget.super.new(self, menu, font, "restart")
|
||||
end
|
||||
|
||||
function RestartWidget:action()
|
||||
self.controller:restartLevel()
|
||||
end
|
||||
|
||||
function ExitWidget:new(menu)
|
||||
ExitWidget.super.new(self, menu)
|
||||
self.label = "exit"
|
||||
function ExitWidget:new(menu, font)
|
||||
ExitWidget.super.new(self, menu, font, "exit")
|
||||
end
|
||||
|
||||
function ExitWidget:action()
|
||||
self.controller:exitLevel()
|
||||
self.menu.controller:exitLevel()
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -111,11 +111,10 @@ function BoostLevel:update(dt)
|
|||
if self.keys["start"].isPressed then
|
||||
if not (self.menusystem.menus["pauseMenu"].isActive) then
|
||||
self.menusystem.menus["pauseMenu"].isActive = true
|
||||
self.menusystem.menus["pauseMenu"].isFocus = true
|
||||
self.menusystem.menus["pauseMenu"].isVisible = true
|
||||
self.menusystem.menus["pauseMenu"]:getFocus()
|
||||
else
|
||||
self.menusystem.menus["pauseMenu"].isActive = false
|
||||
self.menusystem.menus["pauseMenu"].isFocus = false
|
||||
self.menusystem.menus["pauseMenu"].isVisible = false
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue