-- Sharpiepoops' tfm.* namespace browser v0.01 -- Based on crude early version of UI controls library gui = {} gui.rgb = function(r,g,b) return r * 256 * 256 + g * 256 + b end gui.null = {} gui.null.isVisibleForPlayer = function(p) return false end gui.controls = {} gui.baseid = 0 gui.defaultbg = gui.rgb(0,0,128) gui.defaultbc = gui.rgb(255,255,255) gui.defaultba = 0.8 gui.autoCloseEqual = 1 gui.autoCloseGreaterThanOrEqual = 2 gui.control = {} gui.control.show = function(c,p) --print('gui.show:'..tostring(c)..':'..tostring(c.x)..','..tostring(c.y)) -- auto close members of same autoCloseGroup if c.autoCloseGroup then --print('autoCloseGroup:'..c.autoCloseGroup) for i,c2 in ipairs(gui.controls) do if c2.autoCloseGroup and c.id ~= c2.id then --print('- autoCloseGroup:'..c2.autoCloseGroup .. ' header:'..c2.header.. ' behaviour:'..c.autoCloseGroupBehaviour) if c.autoCloseGroupBehaviour == gui.autoCloseEqual and c.autoCloseGroup == c2.autoCloseGroup then c2:hide(p) elseif c.autoCloseGroupBehaviour == gui.autoCloseGreaterThanOrEqual and c2.autoCloseGroup >= c.autoCloseGroup then c2:hide(p) end end end end -- call onShow if c.onShow then c:onShow() end -- show ui.addTextArea(gui.baseid + c.id, c.html, p, c.x, c.y, c.w, c.h, c.bg, c.bc, c.ba) if p then c.isVisible[p] = true else c.isVisible = {} c.isVisible['*'] = true end end gui.control.hide = function(c,p) -- call onHide if c.onHide then c:onHide() end -- hide ui.removeTextArea(gui.baseid + c.id, p) if p then c.isVisible[p] = false else c.isVisible = {} end -- destroy if needed if c.destroyOnClose == true then gui.controls[c.id] = gui.null end end gui.control.toggle = function(c,p) if c:isVisibleForPlayer(p) then c:hide(p) else c:show(p) end end gui.control.isVisibleForPlayer = function(c,p) if c.isVisible[p] == true then return true end if c.isVisible['*'] == true then return true end return false end gui.newControl = function(x,y,w,h) local c = {} c.x = x c.y = y c.w = w c.h = h c.id = table.getn(gui.controls)+1 c.text = "" c.html = "" c.isVisible = {} c.isVisibleForPlayer = gui.control.isVisibleForPlayer c.autoCloseGroupBehaviour = gui.autoCloseEqual c.destroyOnClose = false c.bg = gui.defaultbg c.bc = gui.defaultbc c.ba = gui.defaultba --print("id:" .. c.id) table.insert(gui.controls,c) -- set up methods c.show = gui.control.show c.hide = gui.control.hide c.toggle = gui.control.toggle return c end -- Label ---------------------------------------------------------------------- gui.label = {} gui.label.setText = function(c,text) c.text = text c.html = text end gui.newLabel = function(x,y,w,h,text) c = gui.newControl(x,y,w,h) c.type = "gui.label" c.setText = gui.label.setText c:setText(text) return c end -- Button --------------------------------------------------------------------- gui.button = {} gui.button.setText = function(c,text) c.text = text c.html = '' .. text .. '' end gui.newButton = function(x,y,w,h,text) c = gui.newControl(x,y,w,h) c.type = "gui.button" c.setText = gui.button.setText c:setText(text) return c end -- List ----------------------------------------------------------------------- gui.list = {} gui.list.resetItems = function(c) c.children = {} end gui.list.addItem = function(c,child) -- update the id to reflect it's position in the table child.parent = c child.id = table.getn(c.children) + 1 child:setText(child.text) table.insert(c.children, child) c.html = '