2019-02-11 20:34:25 +01:00
|
|
|
local ListBox = require "core.modules.menusystem.listbox"
|
|
|
|
local PauseMenu = ListBox:extend()
|
2019-02-03 19:54:02 +01:00
|
|
|
|
2019-02-10 20:00:37 +01:00
|
|
|
local Widget = require "core.modules.menusystem.widgets"
|
|
|
|
|
|
|
|
local ResumeWidget = Widget.Base:extend()
|
|
|
|
local RestartWidget = Widget.Base:extend()
|
|
|
|
local ExitWidget = Widget.Base:extend()
|
2019-02-03 19:54:02 +01:00
|
|
|
|
|
|
|
function PauseMenu:new(controller)
|
2019-02-11 20:34:25 +01:00
|
|
|
local height, width, x, y
|
|
|
|
height = 72
|
|
|
|
width = 64
|
|
|
|
x = 424/2 - width/2
|
|
|
|
y = 240/2 - height/2
|
2019-02-03 19:54:02 +01:00
|
|
|
|
2019-02-11 20:34:25 +01:00
|
|
|
PauseMenu.super.new(self, controller.menusystem, "pauseMenu", x, y, width, height, 3)
|
|
|
|
self.controller = controller
|
2019-02-03 19:54:02 +01:00
|
|
|
|
2019-02-11 20:34:25 +01:00
|
|
|
self:setSound(self.controller.assets.sfx["select"])
|
|
|
|
self.haveFocus = false
|
|
|
|
self.isActive = false
|
|
|
|
self.isVisible = false
|
2019-02-03 19:54:02 +01:00
|
|
|
|
2019-02-11 20:34:25 +01:00
|
|
|
ResumeWidget(self)
|
|
|
|
RestartWidget(self)
|
|
|
|
ExitWidget(self)
|
2019-02-03 19:54:02 +01:00
|
|
|
|
|
|
|
self.canvas = nil
|
|
|
|
self.activeCanvas = false
|
|
|
|
self.width = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
function PauseMenu:draw()
|
|
|
|
if (self.activeCanvas == false) then
|
2019-02-11 20:34:25 +01:00
|
|
|
local width = self:getWidth() or 10
|
2019-02-03 19:54:02 +01:00
|
|
|
self.width = self:drawCanvas(width, 64)
|
|
|
|
end
|
|
|
|
|
|
|
|
love.graphics.draw(self.canvas, (424 - self.width)/2, self.height - 28)
|
2019-02-11 20:34:25 +01:00
|
|
|
PauseMenu.super.draw(self)
|
|
|
|
|
2019-02-03 19:54:02 +01:00
|
|
|
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)
|
|
|
|
|
2019-02-10 20:00:37 +01:00
|
|
|
core.screen:cease()
|
2019-02-03 19:54:02 +01:00
|
|
|
love.graphics.setCanvas( self.canvas )
|
|
|
|
|
2019-02-03 20:17:49 +01:00
|
|
|
--self.controller.gui.textbox["solid"]:draw(32, 32, width, height)
|
2019-02-03 19:54:02 +01:00
|
|
|
self.controller.assets.fonts["title"]:draw("PAUSE", (width + 64)/2, 12, -1)
|
|
|
|
|
|
|
|
love.graphics.setCanvas( )
|
2019-02-10 20:00:37 +01:00
|
|
|
core.screen:cease()
|
2019-02-03 19:54:02 +01:00
|
|
|
|
|
|
|
self.activeCanvas = true
|
|
|
|
|
|
|
|
return width + 64
|
|
|
|
end
|
|
|
|
|
|
|
|
--- MENU WIDGETS
|
|
|
|
|
2019-02-11 20:34:25 +01:00
|
|
|
function ResumeWidget:new(menu)
|
|
|
|
ResumeWidget.super.new(self, menu)
|
2019-02-03 19:54:02 +01:00
|
|
|
self.label = "resume"
|
|
|
|
end
|
|
|
|
|
|
|
|
function ResumeWidget:action()
|
|
|
|
self.controller.pause = false
|
|
|
|
end
|
|
|
|
|
2019-02-11 20:34:25 +01:00
|
|
|
function RestartWidget:new(menu)
|
|
|
|
RestartWidget.super.new(self, menu)
|
2019-02-03 19:54:02 +01:00
|
|
|
self.label = "restart"
|
|
|
|
end
|
|
|
|
|
|
|
|
function RestartWidget:action()
|
|
|
|
self.controller:restartLevel()
|
|
|
|
end
|
|
|
|
|
2019-02-11 20:34:25 +01:00
|
|
|
function ExitWidget:new(menu)
|
|
|
|
ExitWidget.super.new(self, menu)
|
2019-02-03 19:54:02 +01:00
|
|
|
self.label = "exit"
|
|
|
|
end
|
|
|
|
|
|
|
|
function ExitWidget:action()
|
|
|
|
self.controller:exitLevel()
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
return PauseMenu
|