examples/options: Add a double text widget

This commit is contained in:
Kazhnuz 2019-04-13 09:59:23 +02:00
parent fb1871e0d9
commit a1f59a60d6

View file

@ -27,7 +27,9 @@ local OptionsMenu = Scene:extend()
local ListBox = require "gamecore.modules.menusystem.listbox" local ListBox = require "gamecore.modules.menusystem.listbox"
local Widget = require "gamecore.modules.menusystem.widgets" local Widget = require "gamecore.modules.menusystem.widgets"
local SubMenuWidget = Widget.Text:extend() local DoubleTextWidget = Widget.Text:extend()
local SubMenuWidget = DoubleTextWidget:extend()
local SceneWidget = Widget.Text:extend() local SceneWidget = Widget.Text:extend()
local ExitWidget = Widget.Text:extend() local ExitWidget = Widget.Text:extend()
@ -62,7 +64,7 @@ end
function OptionsMenu:addSubMenu(name, fullname) function OptionsMenu:addSubMenu(name, fullname)
self:addMenu(name) self:addMenu(name)
SubMenuWidget(self, "main", name, fullname) SubMenuWidget(self, "main", name, fullname)
SubMenuWidget(self, name, "main", "< Back", 1) SubMenuWidget(self, name, "main", "Back", 1, "<")
end end
function OptionsMenu:addScene(submenu, scene, fullname) function OptionsMenu:addScene(submenu, scene, fullname)
@ -77,14 +79,30 @@ end
-- WIDGETS -- WIDGETS
-- Widgets used by menus -- Widgets used by menus
-- DoubleText widget : a two-side text widget
function DoubleTextWidget:new(menu, font, label1, label2)
DoubleTextWidget.super.new(self, menu, font, label1)
self.label2 = label2 or ""
end
function DoubleTextWidget:drawCanvas()
local w, h
w = math.floor(self.width)
h = math.floor(self.height / 2) - (self.font:getHeight() / 2)
self.font:draw(self.label, 4, h, -1, "left")
self.font:draw(self.label2, w-4, h, -1, "right")
end
-- Submenu widget :: go to a submenu -- Submenu widget :: go to a submenu
function SubMenuWidget:new(scene, menu, newmenu, fullname, order) function SubMenuWidget:new(scene, menu, newmenu, fullname, order, label2)
self.scene = scene self.scene = scene
local widgetmenu = self.scene.menusystem.menus[menu] local widgetmenu = self.scene.menusystem.menus[menu]
local font = self.scene.assets.fonts["medium"] local font = self.scene.assets.fonts["medium"]
local label2 = label2 or ">"
self.newmenu = newmenu self.newmenu = newmenu
SubMenuWidget.super.new(self, widgetmenu, font, fullname) SubMenuWidget.super.new(self, widgetmenu, font, fullname, label2)
self.order = order or 0 self.order = order or 0
end end