improvement: better textmenus
This commit is contained in:
parent
8914dc2d09
commit
c95ff30d6e
2 changed files with 29 additions and 3 deletions
|
@ -38,10 +38,30 @@ function TextMenu:new(name, font, x, y, w, slotNumber, padding, lineSize)
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
self.padding = padding or BASE_PADDING
|
self.padding = padding or BASE_PADDING
|
||||||
self:setSelectedColor(1,1,1)
|
|
||||||
TextMenu.super.new(self, name, x, y, w, (self.lineHeight * slotNumber), slotNumber)
|
TextMenu.super.new(self, name, x, y, w, (self.lineHeight * slotNumber), slotNumber)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function TextMenu:addItem(text, position, func, type, additionnalItems, color)
|
||||||
|
local widget = TextMenu.baseWidgets.Base(self.name, text, position)
|
||||||
|
widget:setFunc(func)
|
||||||
|
widget.type = type or "select"
|
||||||
|
if (additionnalItems ~= nil) then
|
||||||
|
for _, item in ipairs(additionnalItems) do
|
||||||
|
widget:addLabel(item[1], item[2])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if (color ~= nil) then
|
||||||
|
widget:setColor(color[1], color[2], color[3])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function TextMenu:generateSubmenu(pageName, label, parent, list, func, backWidget)
|
||||||
|
self:addSubmenu(pageName, label, parent, backWidget)
|
||||||
|
for _, data in ipairs(list) do
|
||||||
|
self:addItem(func(data))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function TextMenu:setFont(fontName)
|
function TextMenu:setFont(fontName)
|
||||||
local scene = core.scenemanager.currentScene
|
local scene = core.scenemanager.currentScene
|
||||||
self.font = scene.assets:getFont(fontName)
|
self.font = scene.assets:getFont(fontName)
|
||||||
|
@ -59,7 +79,7 @@ function TextMenu:setSelectedColor(r, g, b)
|
||||||
end
|
end
|
||||||
|
|
||||||
function TextMenu:getSelectedColor()
|
function TextMenu:getSelectedColor()
|
||||||
return self.selectedColor.r, self.selectedColor.g, self.selectedColor.b
|
return self.selectedColor
|
||||||
end
|
end
|
||||||
|
|
||||||
function TextMenu:getPadding()
|
function TextMenu:getPadding()
|
||||||
|
@ -74,6 +94,7 @@ function TextMenu:addSubmenu(pageName, label, parent, backWidget)
|
||||||
TextMenu.super.addSubmenu(self, pageName, parent)
|
TextMenu.super.addSubmenu(self, pageName, parent)
|
||||||
if (backWidget ~= false) then
|
if (backWidget ~= false) then
|
||||||
TextMenu.baseWidgets.Back(self.name)
|
TextMenu.baseWidgets.Back(self.name)
|
||||||
|
self:setCancelWidget("last")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,12 @@ function TextMenuWidget:getFont()
|
||||||
end
|
end
|
||||||
|
|
||||||
function TextMenuWidget:getSelectedColor()
|
function TextMenuWidget:getSelectedColor()
|
||||||
return self.menu:getSelectedColor()
|
local selectedColor = self.menu:getSelectedColor()
|
||||||
|
if (selectedColor ~= nil) then
|
||||||
|
return selectedColor.r, selectedColor.g, selectedColor.b
|
||||||
|
else
|
||||||
|
return self:getColor()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function TextMenuWidget:getPadding()
|
function TextMenuWidget:getPadding()
|
||||||
|
|
Loading…
Reference in a new issue