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 Widget = require "core.modules.menusystem.widgets"
|
||||||
|
|
||||||
local ResumeWidget = Widget.Base:extend()
|
local ResumeWidget = Widget.Text:extend()
|
||||||
local RestartWidget = Widget.Base:extend()
|
local RestartWidget = Widget.Text:extend()
|
||||||
local ExitWidget = Widget.Base:extend()
|
local ExitWidget = Widget.Text:extend()
|
||||||
|
|
||||||
function PauseMenu:new(controller)
|
function PauseMenu:new(controller)
|
||||||
local height, width, x, y
|
local height, width, x, y
|
||||||
height = 72
|
height = 72
|
||||||
width = 64
|
width = 72
|
||||||
x = 424/2 - width/2
|
x = 424/2 - width/2
|
||||||
y = 240/2 - height/2
|
y = 240/2 - height/2
|
||||||
|
|
||||||
|
@ -18,76 +18,45 @@ function PauseMenu:new(controller)
|
||||||
self.controller = controller
|
self.controller = controller
|
||||||
|
|
||||||
self:setSound(self.controller.assets.sfx["select"])
|
self:setSound(self.controller.assets.sfx["select"])
|
||||||
self.haveFocus = false
|
|
||||||
self.isActive = false
|
self.isActive = false
|
||||||
self.isVisible = false
|
self.isVisible = false
|
||||||
|
|
||||||
ResumeWidget(self)
|
local font = self.controller.assets.fonts["menu"]
|
||||||
RestartWidget(self)
|
|
||||||
ExitWidget(self)
|
|
||||||
|
|
||||||
self.canvas = nil
|
ResumeWidget(self, font)
|
||||||
self.activeCanvas = false
|
RestartWidget(self, font)
|
||||||
self.width = 0
|
ExitWidget(self, font)
|
||||||
end
|
end
|
||||||
|
|
||||||
function PauseMenu:draw()
|
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)
|
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
|
end
|
||||||
|
|
||||||
--- MENU WIDGETS
|
--- MENU WIDGETS
|
||||||
|
|
||||||
function ResumeWidget:new(menu)
|
function ResumeWidget:new(menu, font)
|
||||||
ResumeWidget.super.new(self, menu)
|
ResumeWidget.super.new(self, menu, font, "resume")
|
||||||
self.label = "resume"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function ResumeWidget:action()
|
function ResumeWidget:action()
|
||||||
self.controller.pause = false
|
self.menu.isActive = false
|
||||||
|
self.menu.isVisible = false
|
||||||
end
|
end
|
||||||
|
|
||||||
function RestartWidget:new(menu)
|
function RestartWidget:new(menu, font)
|
||||||
RestartWidget.super.new(self, menu)
|
ResumeWidget.super.new(self, menu, font, "restart")
|
||||||
self.label = "restart"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function RestartWidget:action()
|
function RestartWidget:action()
|
||||||
self.controller:restartLevel()
|
self.controller:restartLevel()
|
||||||
end
|
end
|
||||||
|
|
||||||
function ExitWidget:new(menu)
|
function ExitWidget:new(menu, font)
|
||||||
ExitWidget.super.new(self, menu)
|
ExitWidget.super.new(self, menu, font, "exit")
|
||||||
self.label = "exit"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function ExitWidget:action()
|
function ExitWidget:action()
|
||||||
self.controller:exitLevel()
|
self.menu.controller:exitLevel()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -111,11 +111,10 @@ function BoostLevel:update(dt)
|
||||||
if self.keys["start"].isPressed then
|
if self.keys["start"].isPressed then
|
||||||
if not (self.menusystem.menus["pauseMenu"].isActive) then
|
if not (self.menusystem.menus["pauseMenu"].isActive) then
|
||||||
self.menusystem.menus["pauseMenu"].isActive = true
|
self.menusystem.menus["pauseMenu"].isActive = true
|
||||||
self.menusystem.menus["pauseMenu"].isFocus = true
|
|
||||||
self.menusystem.menus["pauseMenu"].isVisible = true
|
self.menusystem.menus["pauseMenu"].isVisible = true
|
||||||
|
self.menusystem.menus["pauseMenu"]:getFocus()
|
||||||
else
|
else
|
||||||
self.menusystem.menus["pauseMenu"].isActive = false
|
self.menusystem.menus["pauseMenu"].isActive = false
|
||||||
self.menusystem.menus["pauseMenu"].isFocus = false
|
|
||||||
self.menusystem.menus["pauseMenu"].isVisible = false
|
self.menusystem.menus["pauseMenu"].isVisible = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue