sonic-radiance/sonic-radiance.love/scenes/debug/commons/menu.lua

84 lines
2.2 KiB
Lua
Raw Normal View History

2020-08-01 10:31:09 +02:00
local menu = {}
local ListBox = require "core.modules.menusystem.listbox"
local Widget = require "core.modules.menusystem.widgets"
menu.DebugMenu = ListBox:extend()
menu.DebugWidget = Widget.Text:extend()
menu.SubMenuWidget = menu.DebugWidget:extend()
menu.SceneWidget = menu.DebugWidget:extend()
2020-08-01 10:31:09 +02:00
local CONST = {}
CONST.MENU = {}
CONST.MENU.X = 16
CONST.MENU.Y = 48
CONST.MENU.W = 424/2
2020-08-01 14:01:08 +02:00
CONST.MENU.ITEM_NUMBER = 8
2020-08-01 10:31:09 +02:00
CONST.MENU.ITEM_HEIGHT = 18
-- Basic menu structure
function menu.DebugMenu:new(scene, name)
self.scene = scene
local x, y = CONST.MENU.X, CONST.MENU.Y
local w, h = CONST.MENU.W, CONST.MENU.ITEM_NUMBER * CONST.MENU.ITEM_HEIGHT
menu.DebugMenu.super.new(self, scene.menusystem, name, x, y, w, h, CONST.MENU.ITEM_NUMBER)
end
function menu.DebugMenu:drawCursor()
end
2020-08-01 14:01:08 +02:00
function menu.DebugMenu:draw()
love.graphics.setColor(0, 0, 0, 0.5)
love.graphics.rectangle("fill", self.x, self.y, self.w, self.h)
utils.graphics.resetColor()
menu.DebugMenu.super.draw(self)
end
2020-08-01 10:31:09 +02:00
-- Widget
function menu.DebugWidget:new(scene, menu_name, label)
local font = scene.assets.fonts["small"]
self.scene = scene
local widgetMenu = scene.menusystem.menus[menu_name]
menu.DebugWidget.super.new(self, widgetMenu, font, label)
end
function menu.DebugWidget:drawCanvas()
local h = math.floor(self.height / 2) - (self.font:getHeight() / 2)
self.font:draw(self.label, 8, h, -1, "left")
end
function menu.DebugWidget:drawSelected(x, y, w, h)
love.graphics.setColor(1, 1, 0, 1)
self:draw(x, y, w, h)
utils.graphics.resetColor()
end
-- SubMenuWidget
function menu.SubMenuWidget:new(scene, menu_name, newmenu, name)
menu.SubMenuWidget.super.new(self, scene, menu_name, name)
self.newmenu = newmenu or "BaseMenu"
end
function menu.SubMenuWidget:action()
self.scene.menusystem:switchMenu(self.newmenu)
end
-- SceneWidget
function menu.SceneWidget:new(scene, menuName, newScene, newSceneName, sceneArgument)
menu.SceneWidget.super.new(self, scene, menuName, newSceneName)
self.newScene = newScene
self.sceneArgument = sceneArgument
end
function menu.SceneWidget:action()
if (self.sceneArgument ~= nil) then
self.newScene(self.sceneArgument)
else
self.newScene()
end
end
2020-08-01 10:31:09 +02:00
return menu