examples/options: Add a double text widget
This commit is contained in:
parent
fb1871e0d9
commit
a1f59a60d6
1 changed files with 22 additions and 4 deletions
|
@ -27,7 +27,9 @@ local OptionsMenu = Scene:extend()
|
|||
local ListBox = require "gamecore.modules.menusystem.listbox"
|
||||
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 ExitWidget = Widget.Text:extend()
|
||||
|
||||
|
@ -62,7 +64,7 @@ end
|
|||
function OptionsMenu:addSubMenu(name, fullname)
|
||||
self:addMenu(name)
|
||||
SubMenuWidget(self, "main", name, fullname)
|
||||
SubMenuWidget(self, name, "main", "< Back", 1)
|
||||
SubMenuWidget(self, name, "main", "Back", 1, "<")
|
||||
end
|
||||
|
||||
function OptionsMenu:addScene(submenu, scene, fullname)
|
||||
|
@ -77,14 +79,30 @@ end
|
|||
-- WIDGETS
|
||||
-- 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
|
||||
|
||||
function SubMenuWidget:new(scene, menu, newmenu, fullname, order)
|
||||
function SubMenuWidget:new(scene, menu, newmenu, fullname, order, label2)
|
||||
self.scene = scene
|
||||
local widgetmenu = self.scene.menusystem.menus[menu]
|
||||
local font = self.scene.assets.fonts["medium"]
|
||||
local label2 = label2 or ">"
|
||||
self.newmenu = newmenu
|
||||
SubMenuWidget.super.new(self, widgetmenu, font, fullname)
|
||||
SubMenuWidget.super.new(self, widgetmenu, font, fullname, label2)
|
||||
self.order = order or 0
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue