Code: Select all
local gui = {}
local gui.__index = gui
local buttontypes = {
"button", "text", "frame"
}
local lg = love.graphics
local lm = love.math
-- Private functions
local function checkType(b)
if type(buttontype) ~= "string" then
error("[GUI]button type must be a string", 2)
end
for k, v in pairs(buttontypes) do
if b == buttontypes then
return true
end
end
error("[GUI]"..b.." is an invalid button type")
end
local function checkExist(name)
for k, v in pairs(guihandler) do
if name == v.name then
return true
else
error("[GUI]"..name.." doesn't exist")
return false
end
end
end
local function checkstring(s)
if type(s) ~= "string" then
error("[GUI]Must be a string", 2)
end
return true
end
local function checknumber(n)
if type(n) ~= "number" or n < 0 then
error("[GUI]Must be a positive number", 2)
end
return true
end
-- Public functions, methods
function gui.New(_type_, x, y, text)
checkType(_type_)
local newgui = {}
setmetatable(newgui, gui)
newgui.x = x or 0
newgui.y = y or 0
newgui.width = 50
newgui.height = 50
newgui.text = text or ""
newgui.onclick = function() end
newgui.onmousein = function() end
newgui.onmouseout = function() end
return newgui
end
function gui:SetPos(x, y)
checknumber(x)
checknumber(y)
self.x = x
self.y = y
end
function gui:SetX(x)
checknumber(x)
self.x = x
end
function gui:SetY(y)
checknumber(y)
self.y = y
end
function gui:SetText(text)
self.text = text or ""
end
Code: Select all
a = gui.New("button", 50, 50, "Iam a button!")
b = gui.New("button", 50, 100, "Iam also button!")
c = gui.New("button", 75, 150, "Iam not a button")
Code: Select all
function gui:updateAll(dt)
--code--
end