Refonte pour utiliser le systeme de GUI #112

Merged
kazhnuz merged 102 commits from feat/gui into master 2022-01-06 19:15:16 +01:00
4 changed files with 61 additions and 21 deletions
Showing only changes of commit 8914dc2d09 - Show all commits

View 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

View 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

View file

@ -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

View 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