2019-02-03 19:54:02 +01:00
|
|
|
local PauseMenu = Object:extend()
|
|
|
|
|
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)
|
|
|
|
self.controller = controller
|
|
|
|
self.active = false
|
|
|
|
|
|
|
|
self.height = 56+16
|
|
|
|
|
|
|
|
self.assets = self.controller.assets
|
|
|
|
|
2019-02-10 20:00:37 +01:00
|
|
|
self.menu = self.controller.menusystem.TextMenu(424/2, self.height+8, self.assets.fonts["menu"], 6)
|
2019-02-03 19:54:02 +01:00
|
|
|
|
2019-02-10 20:00:37 +01:00
|
|
|
self.controller.menusystem:addMenu(self.menu)
|
2019-02-03 19:54:02 +01:00
|
|
|
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: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)
|
2019-02-10 20:00:37 +01:00
|
|
|
self.controller.menusystem:draw()
|
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
|
|
|
|
|
|
|
|
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
|