I have been working on my own application system type addon for my server, and the main problem I am having is recreating the windows every time like this:
[CODE]local dermabutton = vgui.Create("DButton", panel)
dermabutton:SetPos()
dermabutton:SetSize()
dermabutton:SetText()
dermabutton.Paint = function()
end
dermabutton.DoClick = function()
end[/CODE]
I just have THAT for every element I create, and I have seen other people make way cleaner code accomplishing the same thing, I just couldn't grasp it. I remember seeing something about saving a vgui element with vgui.Register() there is just not much documentation that I have seen on it besides what is on maurits.tv and that doesn't really explain it all very well. Just looking for a bit more information on the use of that considering I have 1 file called cl_gui.lua that is 1500 lines long, with a lot of repetition when creating the derma elements.
EDIT: I somewhat understand what is on maurits.tv in the example, would it just be as simple as following that template and doing a vgui.Create("buttonname", parent) then setting the position if I use the same button multiple times?
yes, you can make a skin like
[CODE]
PANEL = {};
function PANEL:Init()
end
function PANEL:Paint( w, h )
draw.RoundedBox( 4, 0, 0, w, h, Color( 0, 0, 0, 255 ) );
end
vgui.Register( "MySkin", PANEL, "DPanel" );
[/CODE]
then vgui.Create( "MySkin" )
The example says to make PANEL local, I am assuming you would want it local since you are saving it's values into the vgui system anyway?
Yeah you'd want it as a local.
Also, say I wanted to make the framework of a panel with the vgui.Register. It seems like with my testing that if you want to set the size outside of the vgui.Register functions, it doesn't work quite normal. Like centering it with the PANEL:Init() then setting the size with derma:SetSize() after creating it.
Another question, if I am looping and setting the position based on an incrementing variable, how can I apply that increment to the vgui.Register? Or do I need to set the position in the actual file I am creating the derma panels in?
EDIT: Another question, is there any way to send variables such as an image to use with SetImage() when creating the panel? Or do I need to use SetImage after doing the vgui.Create. Pretty much asking if the panel can use variables defined outside of the vgui.Register functions.
[editline]13th January 2016[/editline]
Nevermind, after a bit of tinkering around with it I found something that works, thanks for the help guys.
Note for anyone else interested: I made a function with the PANEL variable and called that function to pass the variable (test:SetTarget(v.player)) which sent that steamid for the rest of the functions to use.
Sorry, you need to Log In to post a reply to this thread.