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

72 lines
1.8 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
CONST.MENU.ITEM_NUMBER = 10
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
-- 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)
menu.SceneWidget.super.new(self, scene, menuName, newSceneName)
self.newScene = newScene
end
function menu.SceneWidget:action()
self.newScene()
end
2020-08-01 10:31:09 +02:00
return menu