I've been trying to develop a semi-fluid widget-based framework for my GUI, and I have run into more than a few snags. It seems even if the widgets successfully loads, it will not display on screen. I can't seem to find where I screwed up. Any help would be appreciated. Oh, just as a note, it uses Geyser.
main gui script
gui = gui or {}
gui.const = gui.const or {}
gui.const.maxwidth, gui.const.maxheight = getMainWindowSize()
gui.locations = gui.locations or {
leftSidebar = {
width = 0,
height = gui.const.maxheight,
x = 0,
y = "0px",
enabled = false,
widgets = {}
};
rightSidebar = {
width = 0,
height = gui.const.maxheight,
x = 0,
y = "0px",
enabled = false,
widgets = {}
};
overhead = {
width = 0,
height = 0,
x = 0,
y = "0px",
enabled = false,
widgets = {}
}
}
function gui:calculatePos()
if gui.locations.rightSidebar.enabled == true then
gui.locations.rightSidebar.width = widgets[gui:getWidest(gui.locations.rightSidebar.widgets)].width
gui.locations.rightSidebar.x = 0 - gui.locations.rightSidebar.width - 9
end
if gui.locations.leftSidebar.enabled == true then
gui.locations.leftSidebar.x = 0
gui.locations.leftSidebar.width = widgets[gui:getWidest(gui.locations.leftSidebar.widgets)].width
end
if gui.locations.overhead.enabled == true then
gui.locations.overhead.x = 0
gui.locations.overhead.width = gui.const.maxwidth - 9 --neg 9 due to scrollbar
gui.locations.overhead.height = gui:getTotalOverheadHeight()
end
if gui.locations.leftSidebar.enabled == true and gui.locations.overhead.enabled == true then
gui.locations.overhead.x = gui.locations.leftSidebar.width
gui.locations.overhead.width = gui.locations.overhead.width - gui.locations.leftSidebar.width
if gui.locations.rightSidebar.enabled == true then
gui.locations.overhead.width = gui.locations.overhead.width - gui.locations.rightSidebar.width + 9
end
end
if gui.locations.rightSidebar.enabled == true and gui.locations.overhead.enabled == true and gui.locations.leftSidebar.enabled == false then
gui.locations.overhead.width = gui.locations.overhead.width - gui.locations.rightSidebar.width
end
gui.locations.rightSidebar.width = tostring(gui.locations.rightSidebar.width) .. "px"
gui.locations.rightSidebar.x = tostring(gui.locations.rightSidebar.x) .. "px"
gui.locations.leftSidebar.width = tostring(gui.locations.leftSidebar.width) .. "px"
gui.locations.leftSidebar.x = tostring(gui.locations.leftSidebar.x) .. "px"
gui.locations.overhead.width = tostring(gui.locations.overhead.width) .. "px"
gui.locations.overhead.x = tostring(gui.locations.overhead.x) .. "px"
end
function gui:getWidest(widtable)
local widest = nil
local widewidth = nil
for _,v in pairs(widtable) do
if widgets[v].width ~= nil then
if widest == nil or widgets[v].width > widewidth then
widest = v
widewidth = widgets[v].width
end
end
end
return widest
end
function gui:getTotalOverheadHeight()
local wid = 0
for _,v in pairs(gui.locations.overhead.widgets) do
wid = wid + widgets[v].height
end
return wid
end
function gui:resetLocation()
gui.locations.leftSidebar = {
width = 0,
height = "100%",
x = 0,
y = "0px",
enabled = false,
widgets = {}
}
gui.locations.rightSidebar = {
width = 0,
height = "100%",
x = 0,
y = "0px",
enabled = false,
widgets = {}
}
gui.locations.overhead = {
width = 0,
height = 0,
x = 0,
y = "0px",
enabled = false,
widgets = {}
}
end
function gui:update()
if gui.locations.leftSidebar.enabled == true then
for _, v in pairs(gui.locations.leftSidebar.widgets) do
widgets[v]:update()
end
tempx = 0
tempy = 0
end
if gui.locations.rightSidebar.enabled == true then
for _, v in pairs(gui.locations.rightSidebar.widgets) do
widgets[v]:update()
end
tempx = 0
tempy = 0
end
if gui.locations.overhead.enabled == true then
for _, v in pairs(gui.locations.overhead.widgets) do
widgets[v]:update()
end
tempx = 0
tempy = 0
end
end
function gui:deploy()
local tempx = 0 --for overhead
local tempy = 0 --for sidebar
if gui.locations.leftSidebar.enabled == true then
gui.leftSidebar = Geyser.Container:new(
{x = gui.locations.leftSidebar.x, y = gui.locations.leftSidebar.y,
width = gui.locations.leftSidebar.width, height = gui.locations.leftSidebar.height,
name = "leftSidebar"})
for _, v in pairs(gui.locations.leftSidebar.widgets) do
tempx, tempy = widgets[v]:initiate("leftSidebar", tempx, tempy)
end
echo("t")
gui.leftSidebar:show()
echo("t")
tempx = 0
tempy = 0
end
if gui.locations.rightSidebar.enabled == true then
gui.rightSidebar = Geyser.Container:new(
{x = gui.locations.rightSidebar.x, y = gui.locations.rightSidebar.y,
width = gui.locations.rightSidebar.width, height = gui.locations.rightSidebar.height,
name = "rightSidebar"})
for _, v in pairs(gui.locations.rightSidebar.widgets) do
tempx, tempy = widgets[v]:initiate("rightSidebar", tempx, tempy)
echo(tempx .. "/" .. tempy .. "/")
end
gui.rightSidebar:show()
tempx = 0
tempy = 0
end
if gui.locations.overhead.enabled == true then
gui.overhead = Geyser.Container:new(
{x = gui.locations.overhead.x, y = gui.locations.overhead.y,
width = gui.locations.overhead.width, height = gui.locations.overhead.height,
name = "overhead"})
for _, v in pairs(gui.locations.overhead.widgets) do
tempx, tempy = widgets[v]:initiate("overhead", tempx, tempy)
end
gui.overhead:show()
tempx = 0
tempy = 0
end
end
function gui:destroy()
if gui.locations.leftSidebar.enabled == true then
for _, v in pairs(gui.locations.leftSidebar.widgets) do
widgets[v]:destroy()
end
tempx = 0
tempy = 0
end
if gui.locations.rightSidebar.enabled == true then
for _, v in pairs(gui.locations.rightSidebar.widgets) do
widgets[v]:destroy()
end
tempx = 0
tempy = 0
end
if gui.locations.overhead.enabled == true then
for _, v in pairs(gui.locations.overhead.widgets) do
widgets[v]:destroy()
end
tempx = 0
tempy = 0
end
Geyser.hideAll()
end
function gui:loadProfile(profile)
gui:destroy()
gui:resetLocation()
gui:calculatePos()
if profiles[profile].leftSidebar.enabled == true then
gui.locations.leftSidebar.enabled = true
gui.locations.leftSidebar.widgets = profiles[profile].leftSidebar.widgets
end
if profiles[profile].rightSidebar.enabled == true then
gui.locations.rightSidebar.enabled = true
gui.locations.rightSidebar.widgets = profiles[profile].rightSidebar.widgets
end
if profiles[profile].overhead.enabled == true then
gui.locations.overhead.enabled = true
gui.locations.overhead.widgets = profiles[profile].overhead.widgets
end
gui:deploy()
end
widget init
widgets = widgets or {}
profiles = profiles or {}
--Set profile information
profiles.sideprofile = { --initialize profile, set name to testprofile
leftSidebar = { --set information for left sidebar location
enabled = true, --show left sidebar
widgets = { --set left sidebar widgets
"sidegauges"
}
}; --end left sidebar information
rightSidebar = { -- set right sidebar information
enabled = false --disable right sidebar
}; --end right sidebar information
overhead = { --You know the drill
enabled = false --yada yada
}
} --end profile
widgets.sidegauges = widgets.sidegauges or { --required in every widget
intendedLocation = "overhead", --Really, ignore this. It has no purpose other than
--telling people where to place this
width = 200 -- You need at least one widget with a specified width in a sidebar plugin.
}
function widgets.sidegauges:initiate(location, tempx, tempy) --required in every widget
widgets.sidegauges.sidegauges = Geyser.Container:new(
{ x = tempx .. "px", y = tempy .. "px",
width = "100%", height = "62px",
name = "sidegauges"}) --create console
widgets.sidegauges.hgauge = Geyser.Gauge:new(
{ x = "0px", y = "0px",
width = "100%", height = "12px",
orientation = "horizontal", color = "red",
name = "hGauge"}, widgets.sidegauges.sidegauges)
widgets.sidegauges.mgauge = Geyser.Gauge:new(
{ x = "0px", y = "0px",
width = "100%", height = "12px",
orientation = "horizontal", color = "blue",
name = "mGauge"}, widgets.sidegauges.sidegauges)
widgets.sidegauges.egauge = Geyser.Gauge:new(
{ x = "0px", y = "0px",
width = "100%", height = "12px",
orientation = "horizontal", color = "yellow",
name = "eGauge"}, widgets.sidegauges.sidegauges)
widgets.sidegauges.pgauge = Geyser.Gauge:new(
{ x = "0px", y = "0px",
width = "100%", height = "12px",
orientation = "horizontal", color = "violet",
name = "pGauge"}, widgets.sidegauges.sidegauges)
widgets.sidegauges.xpgauge = Geyser.Gauge:new(
{ x = "0px", y = "0px",
width = "100%", height = "12px",
orientation = "horizontal", color = "NavyBlue",
name = "xpGauge"}, widgets.sidegauges.sidegauges)
if location == "leftSidebar" then
gui.leftSidebar:add(widgets.sidegauges.sidegauges)
elseif location == "rightSidebar" then
gui.rightSidebar:add(widgets.sidegauges.sidegauges)
elseif location == "overhead" then
gui.overhead:add(widgets.sidegauges.sidegauges)
end
local r = tempx
local s = tempy + 62
return r, s --height is used for sidebars. Both for overhead
end
function widgets.sidegauges:destroy()
end
function widgets.sidegauges:update()
if tonumber(stats.health) > tonumber(stats.maxhealth) then
widgets.sidegauges.hgauge:setValue(tonumber(stats.maxhealth), tonumber(stats.maxhealth))
else
widgets.sidegauges.hgauge:setValue(tonumber(stats.health), tonumber(stats.maxhealth))
end
widgets.sidegauges.hgauge:setText(tostring(stats.health) .. "/" .. tostring(stats.maxhealth))
if tonumber(stats.mana) > tonumber(stats.maxmana) then
widgets.sidegauges.mgauge:setValue(tonumber(stats.maxmana), tonumber(stats.maxmana))
else
widgets.sidegauges.mgauge:setValue(tonumber(stats.mana), tonumber(stats.maxmana))
end
widgets.sidegauges.mgauge:setText(tostring(stats.mana) .. "/" .. tostring(stats.maxmana))
if tonumber(stats.ego) > tonumber(tonumber(stats.maxego)) then
widgets.sidegauges.egauge:setValue(tonumber(stats.maxego), tonumber(stats.maxego))
else
widgets.sidegauges.egauge:setValue(tonumber(stats.ego), tonumber(stats.maxego))
end
widgets.sidegauges.egauge:setText(tostring(stats.ego) .. "/" .. tostring(stats.maxego))
widgets.sidegauges.pgauge:setValue(tonumber(stats.power), 10, tostring(stats.power) .. "/10")
widgets.sidegauges.xpgauge:setValue(tonumber(stats.newlevel), 100,tostring(stats.newlevel) .. "/100")
end