Hello. I want to update a Derma panel once a certain variable gets changed within the Panel, but when I recall Panel:Init() it will redraw some of the same objects. Is there a way to re initialize the Derma w/o creating a new object or recreating existing objects?
If you don't understand what I mean, I can upload a video of the current problem I have.
This should do you just fine :)
[lua]
Panel.Think = function()
-- body
end
[/lua]
So let's say you want to update the color of the panel when a variable is changed.
[lua]
var = 0
panel = vgui.Create("DPanel")
panel:SetSize(200,200)
panel:Center()
panel.Think = function()
if var > 0 then
panel:SetBackgroundColor(Color(50,50,255))
else
panel:SetBackgroundColor(Color(50,50,50))
end
end
[/lua]
EDIT: Fuck [lua] tags. Took me 10 edits to get the spacing right...
[QUOTE=Richtofen;52302010]This should do you just fine :)
[lua]
Panel.Think = function()
-- body
end
[/lua]
So let's say you want to update the color of the panel when a variable is changed.
[lua]
var = 0
panel = vgui.Create("DPanel")
panel:SetSize(200,200)
panel:Center()
panel.Think = function()
if var > 0 then
panel:SetBackgroundColor(Color(50,50,255))
else
panel:SetBackgroundColor(Color(50,50,50))
end
end
[/lua]
EDIT: Fuck [lua] tags. Took me 10 edits to get the spacing right...[/QUOTE]
In my PANEL:Init() I create a bunch of sub-elements, like list and stuff. I want to update the sub-elements created within Init(), and possibly replace them with others based on the variables. I want to completely re-initialize the PANEL, but that just recreates the elements and leaves the old ones.
Without more detail i'm afraid I can't help. Can you give me like a specific thing you're trying to accomplish rather than broad "possibly replace them with others based on variables"?
[QUOTE=Richtofen;52302335]Without more detail i'm afraid I can't help. Can you give me like a specific thing you're trying to accomplish rather than broad "possibly replace them with others based on variables"?[/QUOTE]
on init an if statement checks the value of a variable. depending on the value, it creates one of two objects.
Okay, So is this what you're talking about?
[lua]
local g = 0
function PANEL:Init()
self:SetSize(200,200)
self:Center()
self:MakePopup()
self:SetTitle("Example for overki11")
end
function PANEL:Think()
if g > 0 then
self[1] = vgui.Create("DLabel")
self[1]:SetFont("Default")
self[1]:SetText("Hi")
self[1]:SetSize(self:GetWide(),self:GetTall())
self[1]:SetPos(0,0)
self[1]:SetTextColor(Color(0,0,255))
else
self[2] = vgui.Create("DLabel")
self[2]:SetFont("Default")
self[2]:SetText("Bye")
self[2]:SetSize(self:GetWide(),self:GetTall())
self[2]:SetPos(0,0)
self[2]:SetTextColor(Color(255,0,0))
end
end
derma.DefineControl('HnaknawFrame','',PANEL,'Example Frame for overki11 on Facepunch')
[/lua]
You can put your if statement in [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/PANEL/PerformLayout]PANEL:PerformLayout[/url] and then use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Panel/InvalidateLayout]Panel:InvalidateLayout[/url] after you changed the variable to update the panel.
[editline]2nd June 2017[/editline]
After reading your problem again I realized that my solution may not work since it only works on custom GUI afaik.
Sorry, you need to Log In to post a reply to this thread.