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" local Widget = require "core.modules.menusystem.widgets"
@ -7,23 +8,23 @@ local RestartWidget = Widget.Base:extend()
local ExitWidget = Widget.Base:extend() local ExitWidget = Widget.Base:extend()
function PauseMenu:new(controller) 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.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 ResumeWidget(self)
RestartWidget(self)
self.menu = self.controller.menusystem.TextMenu(424/2, self.height+8, self.assets.fonts["menu"], 6) ExitWidget(self)
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))
self.canvas = nil self.canvas = nil
self.activeCanvas = false self.activeCanvas = false
@ -32,12 +33,13 @@ end
function PauseMenu:draw() function PauseMenu:draw()
if (self.activeCanvas == false) then if (self.activeCanvas == false) then
local width = self.menu:getWidth() or 10 local width = self:getWidth() or 10
self.width = self:drawCanvas(width, 64) self.width = self:drawCanvas(width, 64)
end end
love.graphics.draw(self.canvas, (424 - self.width)/2, self.height - 28) love.graphics.draw(self.canvas, (424 - self.width)/2, self.height - 28)
self.controller.menusystem:draw() PauseMenu.super.draw(self)
end end
function PauseMenu:drawCanvas(width, height) function PauseMenu:drawCanvas(width, height)
@ -61,33 +63,27 @@ end
--- MENU WIDGETS --- MENU WIDGETS
function ResumeWidget:new(menusystem) function ResumeWidget:new(menu)
ResumeWidget.super.new(self) ResumeWidget.super.new(self, menu)
self.label = "resume" self.label = "resume"
self.menusystem = menusystem
self.controller = menusystem.controller
end end
function ResumeWidget:action() function ResumeWidget:action()
self.controller.pause = false self.controller.pause = false
end end
function RestartWidget:new(menusystem) function RestartWidget:new(menu)
RestartWidget.super.new(self) RestartWidget.super.new(self, menu)
self.label = "restart" self.label = "restart"
self.menusystem = menusystem
self.controller = menusystem.controller
end end
function RestartWidget:action() function RestartWidget:action()
self.controller:restartLevel() self.controller:restartLevel()
end end
function ExitWidget:new(menusystem) function ExitWidget:new(menu)
ExitWidget.super.new(self) ExitWidget.super.new(self, menu)
self.label = "exit" self.label = "exit"
self.menusystem = menusystem
self.controller = menusystem.controller
end end
function ExitWidget:action() function ExitWidget:action()

View file

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