feat: new element types
This commit is contained in:
parent
08674dbf7e
commit
8914dc2d09
4 changed files with 61 additions and 21 deletions
34
sonic-radiance.love/birb/modules/gui/elements/composite.lua
Normal file
34
sonic-radiance.love/birb/modules/gui/elements/composite.lua
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
local Parent = require "birb.modules.gui.elements.parent"
|
||||||
|
local CompositeElement = Parent:extend()
|
||||||
|
|
||||||
|
function CompositeElement:new(name, x, y, childrenList)
|
||||||
|
self.children = {}
|
||||||
|
self:addChildren(childrenList)
|
||||||
|
CompositeElement.super.new(self, name, x, y, 1, 1)
|
||||||
|
self.isVisible = true
|
||||||
|
end
|
||||||
|
|
||||||
|
function CompositeElement:addChildren(list)
|
||||||
|
for _, childData in ipairs(list) do
|
||||||
|
self:addChild(childData[1], childData[2], childData[3])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function CompositeElement:addChild(children, relx, rely)
|
||||||
|
local child = {}
|
||||||
|
child.name = children.name
|
||||||
|
child.relx = relx
|
||||||
|
child.rely = rely
|
||||||
|
table.insert(self.children, child)
|
||||||
|
end
|
||||||
|
|
||||||
|
function CompositeElement:update(dt)
|
||||||
|
for _, child in ipairs(self.children) do
|
||||||
|
local childElement = self.getGui().elements[child.name]
|
||||||
|
childElement.x = self.x + child.relx
|
||||||
|
childElement.y = self.y + child.rely
|
||||||
|
childElement.isVisible = self.isVisible
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return CompositeElement
|
13
sonic-radiance.love/birb/modules/gui/elements/counter.lua
Normal file
13
sonic-radiance.love/birb/modules/gui/elements/counter.lua
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
local Parent = require "birb.modules.gui.elements.variable"
|
||||||
|
local CounterElement = Parent:extend()
|
||||||
|
|
||||||
|
function CounterElement:new(name, fontName, object, varName, nbrs, x, y, align, depth)
|
||||||
|
CounterElement.super.new(self, name, fontName, object, varName, x, y, align, depth)
|
||||||
|
self.nbrs = nbrs or 0
|
||||||
|
end
|
||||||
|
|
||||||
|
function CounterElement:getText()
|
||||||
|
return utils.math.numberToString(CounterElement.super.getText(self), self.nbrs)
|
||||||
|
end
|
||||||
|
|
||||||
|
return CounterElement
|
|
@ -1,21 +0,0 @@
|
||||||
local Parent = require "birb.modules.gui.elements.parent"
|
|
||||||
local LinkedElement = Parent:extend()
|
|
||||||
|
|
||||||
function LinkedElement:new(name, x, y, w, h, object, varName)
|
|
||||||
LinkedElement.super.new(self, name, x, y, w, h)
|
|
||||||
self.object = object
|
|
||||||
self.variables = {}
|
|
||||||
self:addVariable(varName, "main")
|
|
||||||
end
|
|
||||||
|
|
||||||
function LinkedElement:addVariable(varName, internalName)
|
|
||||||
internalName = internalName or varName
|
|
||||||
self.variables[internalName] = varName
|
|
||||||
end
|
|
||||||
|
|
||||||
function LinkedElement:getVariableContent(varName)
|
|
||||||
varName = varName or "main"
|
|
||||||
return self.object[self.variables[varName]]
|
|
||||||
end
|
|
||||||
|
|
||||||
return LinkedElement
|
|
14
sonic-radiance.love/birb/modules/gui/elements/variable.lua
Normal file
14
sonic-radiance.love/birb/modules/gui/elements/variable.lua
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
local Parent = require "birb.modules.gui.elements.text"
|
||||||
|
local VariableElement = Parent:extend()
|
||||||
|
|
||||||
|
function VariableElement:new(name, fontName, object, varName, x, y, align, depth)
|
||||||
|
VariableElement.super.new(self, name, fontName, "", x, y, align, depth)
|
||||||
|
self.object = object
|
||||||
|
self.variable = varName
|
||||||
|
end
|
||||||
|
|
||||||
|
function VariableElement:getText()
|
||||||
|
return self.object[self.variable]
|
||||||
|
end
|
||||||
|
|
||||||
|
return VariableElement
|
Loading…
Reference in a new issue