scenes/boost: basic update of the pause menu to the new menusystem

This commit is contained in:
Kazhnuz 2019-02-11 20:34:25 +01:00
parent 44bf09aa88
commit c8c0304849
2 changed files with 37 additions and 39 deletions

View file

@ -1,4 +1,5 @@
local PauseMenu = Object:extend()
local ListBox = require "core.modules.menusystem.listbox"
local PauseMenu = ListBox:extend()
local Widget = require "core.modules.menusystem.widgets"
@ -7,23 +8,23 @@ local RestartWidget = Widget.Base:extend()
local ExitWidget = Widget.Base:extend()
function PauseMenu:new(controller)
local height, width, x, y
height = 72
width = 64
x = 424/2 - width/2
y = 240/2 - height/2
PauseMenu.super.new(self, controller.menusystem, "pauseMenu", x, y, width, height, 3)
self.controller = controller
self.active = false
self.height = 56+16
self:setSound(self.controller.assets.sfx["select"])
self.haveFocus = false
self.isActive = false
self.isVisible = false
self.assets = self.controller.assets
self.menu = self.controller.menusystem.TextMenu(424/2, self.height+8, self.assets.fonts["menu"], 6)
self.controller.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))
ResumeWidget(self)
RestartWidget(self)
ExitWidget(self)
self.canvas = nil
self.activeCanvas = false
@ -32,12 +33,13 @@ end
function PauseMenu:draw()
if (self.activeCanvas == false) then
local width = self.menu:getWidth() or 10
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)
self.controller.menusystem:draw()
PauseMenu.super.draw(self)
end
function PauseMenu:drawCanvas(width, height)
@ -61,33 +63,27 @@ end
--- MENU WIDGETS
function ResumeWidget:new(menusystem)
ResumeWidget.super.new(self)
function ResumeWidget:new(menu)
ResumeWidget.super.new(self, menu)
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)
function RestartWidget:new(menu)
RestartWidget.super.new(self, menu)
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)
function ExitWidget:new(menu)
ExitWidget.super.new(self, menu)
self.label = "exit"
self.menusystem = menusystem
self.controller = menusystem.controller
end
function ExitWidget:action()

View file

@ -35,7 +35,6 @@ function BoostLevel:new()
self.assets:playMusic()
end
self.pause = false
self.initiated = false
self.world:loadWorld()
@ -56,7 +55,8 @@ function BoostLevel:initManagers()
self.camera = Camera(self, 0, 0)
self.background = Background(self)
self.characters = CharacterManager(self)
self.pausemenu = PauseMenu(self)
PauseMenu(self)
end
function BoostLevel:initMission(levelid)
@ -101,17 +101,23 @@ function BoostLevel:getLevelData(file)
end
function BoostLevel:update(dt)
if self.pause == false then
if self.menusystem.menus["pauseMenu"].isActive == false then
self.assets:update(dt)
self.mission.timer = self.mission.timer + dt
self.world:update(dt)
self.camera:update(dt)
else
self.pausemenu:update(dt)
end
if self.keys["start"].isPressed then
self.pause = (self.pause == false)
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
else
self.menusystem.menus["pauseMenu"].isActive = false
self.menusystem.menus["pauseMenu"].isFocus = false
self.menusystem.menus["pauseMenu"].isVisible = false
end
end
end
@ -124,10 +130,6 @@ function BoostLevel:draw()
utils.graphics.resetColor()
self.hud:draw()
if self.pause == true then
self.pausemenu:draw(dt)
end
end
function BoostLevel:resetFont()