Hello again facepunch! I need help with the PANEL:init thing. How would I add a DTextEntry element to a PANEL.
CODE:
[CODE]PANEL = {}
function PANEL:Init()
self:SetSize( 500, 320 )
self:Center()
end
function PANEL:Paint(w,h)
draw.RoundedBox( 0, 0, 0, w, h, Color( 74, 74, 74 ) )
draw.RoundedBox( 0, 0, 300, w, h, Color( 140, 140, 140 ) )
draw.RoundedBox( 0, 0, -300, w, h, Color( 140, 140, 140 ) )
end
vgui.Register("PlayerPanel", PANEL, "Panel")
local panel = vgui.Create( "MyPanel" )[/CODE]
Add any child vgui elements in Init i think
[QUOTE=rtm516;50487083]Add any child vgui elements in Init i think[/QUOTE]
Already tried that. It didn't work at all.
[QUOTE=Chal-k;50487113]Already tried that. It didn't work at all.[/QUOTE]
What went wrong exactly? Putting new elements in the init method should work.
You can add child elements in at any time, same way you'd create normal panels except you'd use self as the second argument.
One note about your code is your custom panel's name is `PlayerPanel` but you're using the name `MyPanel` to create it
[CODE]
function PANEL:Init()
self:SetSize( 500, 320 )
self:Center()
self.TextEntry = vgui.Create( 'DTextEntry', self ) -- I made it a variable of the panel because that makes it easier to access
-- more textentry code here
end
[/CODE]
PROBLEM:
The TextEntry in the panel overlays my main derma panel. As seen in the pictures below:
MAIN DERMA:
[IMG]http://images.akamai.steamusercontent.com/ugc/271720179210552715/5F9E5F441F584334B12A6DC23BAE61D458BE9287/[/IMG]
PANEL TEXT ENTRY OVERLAYING MAIN DERMA:
[IMG]http://images.akamai.steamusercontent.com/ugc/271720179210550844/D968945340BC01B981173BAB01E5A0CCE5341205/[/IMG]
CODE:
[CODE]PANEL = {}
function PANEL:Init()
self:SetSize( 500, 320 )
self:Center()
self.TextEntry = vgui.Create( 'DTextEntry', self )
self:SetSize( 70, 20 )
self:SetPos( 8, 150 )
end
function PANEL:Paint(w,h)
draw.RoundedBox( 0, 0, 0, w, h, Color( 74, 74, 74 ) )
draw.RoundedBox( 0, 0, 300, w, h, Color( 140, 140, 140 ) )
draw.RoundedBox( 0, 0, -300, w, h, Color( 140, 140, 140 ) )
end
vgui.Register("PlayerPanel", PANEL, "Panel")
local panel = vgui.Create( "MyPanel" )[/CODE]
Wait, so what do you want it to do?
I'm just saying, a common beginner's mistake is to put their name on every visible thing they make, maybe you shouldn't..
[QUOTE=MPan1;50494542]Wait, so what do you want it to do?[/QUOTE]
I want it so when you press the button on the Derma Frame, it opens a blank new panel with the DTextEntry. I don't want it overlapping the Derma Frame with the rules.
[editline]11th June 2016[/editline]
[QUOTE=The Noodler;50495101]I'm just saying, a common beginner's mistake is to put their name on every visible thing they make, maybe you shouldn't..[/QUOTE]
Why?
[QUOTE=Chal-k;50499841]I want it so when you press the button on the Derma Frame, it opens a blank new panel with the DTextEntry. I don't want it overlapping the Derma Frame with the rules.[/QUOTE]
Well, just create a new blank panel and then parent the DTextEntry to it.
[QUOTE=Chal-k;50492721]PROBLEM:
The TextEntry in the panel overlays my main derma panel. As seen in the pictures below:
MAIN DERMA:
[IMG]http://images.akamai.steamusercontent.com/ugc/271720179210552715/5F9E5F441F584334B12A6DC23BAE61D458BE9287/[/IMG]
PANEL TEXT ENTRY OVERLAYING MAIN DERMA:
[IMG]http://images.akamai.steamusercontent.com/ugc/271720179210550844/D968945340BC01B981173BAB01E5A0CCE5341205/[/IMG]
CODE:
[CODE]
function PANEL:Init()
self:SetSize( 500, 320 )
self:Center()
self.TextEntry = vgui.Create( 'DTextEntry', self )
self:SetSize( 70, 20 )
self:SetPos( 8, 150 )
end
[/CODE][/QUOTE]
Now, imo I'd change it to:
[CODE]
function PANEL:Init()
self:SetSize( 500, 320 )
self:Center()
local sTextEntry = vgui.Create( 'DTextEntry', self )
sTextEntry:SetSize( 70, 20 )
sTextEntry:SetPos( 8, 150 )
end
[/CODE]
That may help some, because the self: is going off of the panel, not that element.
[QUOTE=Appledevdude;50500647]That may help some, because the self: is going off of the panel, not that element.[/QUOTE]
That just makes it harder for anyone wanting to retrieve the text entry parented to the panel to do so
Doing the thing above means in any other PANEL function you can just do self.TextEntry to retrieve the textentry
I wasn't focusing on the name, but everything you've mentioned is very true. I wasn't thinking about that :P
I thought putting your name on stuff was so the names if functions and stuff wouldn't conflict, for example basically everything Falco makes.
[QUOTE=SirFrancisB;50503408]I thought putting your name on stuff was so the names if functions and stuff wouldn't conflict, for example basically everything Falco makes.[/QUOTE]
What would a derma panel conflict with? And unless you're making global functions, or tables then you shouldn't put your name in it.
E.g.
ULX could make a global table named ulx, though every function in it shouldn't have ulx_ in the name of it.
[QUOTE=Appledevdude;50500647]Now, imo I'd change it to:
[CODE]
function PANEL:Init()
self:SetSize( 500, 320 )
self:Center()
local sTextEntry = vgui.Create( 'DTextEntry', self )
sTextEntry:SetSize( 70, 20 )
sTextEntry:SetPos( 8, 150 )
end
[/CODE]
That may help some, because the self: is going off of the panel, not that element.[/QUOTE]
IT WORKED! Thanks so much!
Sorry, you need to Log In to post a reply to this thread.