From c8c030484908cf9d7837bc67c9c738df259d300e Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 11 Feb 2019 20:34:25 +0100 Subject: [PATCH] scenes/boost: basic update of the pause menu to the new menusystem --- .../subgame/sonic-boost/controller/pause.lua | 54 +++++++++---------- .../scenes/subgame/sonic-boost/init.lua | 22 ++++---- 2 files changed, 37 insertions(+), 39 deletions(-) diff --git a/sonic-boost.love/scenes/subgame/sonic-boost/controller/pause.lua b/sonic-boost.love/scenes/subgame/sonic-boost/controller/pause.lua index 7f248ff..9b720f9 100644 --- a/sonic-boost.love/scenes/subgame/sonic-boost/controller/pause.lua +++ b/sonic-boost.love/scenes/subgame/sonic-boost/controller/pause.lua @@ -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() diff --git a/sonic-boost.love/scenes/subgame/sonic-boost/init.lua b/sonic-boost.love/scenes/subgame/sonic-boost/init.lua index 684a01f..e6899f3 100644 --- a/sonic-boost.love/scenes/subgame/sonic-boost/init.lua +++ b/sonic-boost.love/scenes/subgame/sonic-boost/init.lua @@ -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()