improvement: port the pause menus to the new menu system

This commit is contained in:
Kazhnuz 2020-08-20 10:17:46 +02:00
parent cb626bfa4a
commit e962396ee1

View file

@ -1,75 +1,68 @@
local ListBox = require "core.modules.menusystem.listbox" local ListBox = require "core.modules.menusystem.listbox"
local PauseMenu = ListBox:extend() local RadianceListMenu = require "game.modules.menus.list"
local PauseMenu = RadianceListMenu.ListMenu:extend()
local Widget = require "core.modules.menusystem.widgets" local Widget = require "core.modules.menusystem.widgets"
local ResumeWidget = Widget.Text:extend() local ResumeWidget = RadianceListMenu.DualTextWidget:extend()
local RestartWidget = Widget.Text:extend() local RestartWidget = RadianceListMenu.DualTextWidget:extend()
local ExitWidget = Widget.Text:extend() local ExitWidget = RadianceListMenu.DualTextWidget:extend()
local gui = require "game.modules.gui" local gui = require "game.modules.gui"
local WIDTH = 80
local HEIGHT = 72
function PauseMenu:new(subgame) function PauseMenu:new(subgame)
local height, width, x, y local x, y
height = 72 x = 424/2 - WIDTH/2
width = 128 y = 240/2 - (3*17)/2
x = 424/2 - width/2
y = 240/2 - height/2
PauseMenu.super.new(self, subgame.menusystem, "pauseMenu", x, y, width, height, 3) PauseMenu.super.new(self, subgame, "pauseMenu", x, y, WIDTH, 3, true)
self.subgame = subgame
self:setSound(self.subgame.assets.sfx["navigate"]) self:setSound(self.scene.assets.sfx["navigate"])
self.isActive = false self.isActive = false
self.isVisible = false self.isVisible = false
local font = self.subgame.assets.fonts["menu"] ResumeWidget(subgame)
self:setCancelWidget()
self.textbox = gui.newTextBox("assets/gui/dialogbox.png", width+16, height+16) RestartWidget(subgame)
ExitWidget(subgame)
ResumeWidget(self, font)
RestartWidget(self, font)
ExitWidget(self, font)
end
function PauseMenu:draw()
love.graphics.draw(self.textbox, self.x-8, self.y-8)
PauseMenu.super.draw(self)
end end
--- MENU WIDGETS --- MENU WIDGETS
function ResumeWidget:new(menu, font) function ResumeWidget:new(scene)
ResumeWidget.super.new(self, menu, font, "resume") ResumeWidget.super.new(self, scene, "pauseMenu", "Resume", "")
end end
function ResumeWidget:action() function ResumeWidget:action()
self.menu.isActive = false self.menu.isActive = false
self.menu.isVisible = false self.menu.isVisible = false
self.menu.subgame.world.isActive = true self.scene.world.isActive = true
self.menu.subgame.assets.isActive = true self.scene.assets.isActive = true
self.menu.subgame:flushKeys() self.scene:flushKeys()
end end
function RestartWidget:new(menu, font) function RestartWidget:new(scene)
ResumeWidget.super.new(self, menu, font, "restart") ResumeWidget.super.new(self, scene, "pauseMenu", "Restart", "")
end end
function RestartWidget:action() function RestartWidget:action()
self.menu.subgame:restartLevel() self.scene:restartLevel()
self.menu.isActive = false self.menu.isActive = false
self.menu.isVisible = false self.menu.isVisible = false
self.menu.subgame.world.isActive = true self.scene.world.isActive = true
self.menu.subgame.assets.isActive = true self.scene.assets.isActive = true
self.menu.subgame:flushKeys() self.scene:flushKeys()
end end
function ExitWidget:new(menu, font) function ExitWidget:new(scene)
ExitWidget.super.new(self, menu, font, "exit") ExitWidget.super.new(self, scene, "pauseMenu", "Exit", "")
end end
function ExitWidget:action() function ExitWidget:action()
self.menu.subgame:exitLevel() self.scene:exitLevel()
end end