• 2nd-level (and deeper) child elements losing their functionality on vgui.Register()?
    7 replies, posted
I have this code: [CODE]local PANEL = {} function PANEL:Init() local ply = LocalPlayer() local strup = string.upper local teamname = ply:getDarkRPVar("job") or team.GetName(ply:Team()) surface.SetFont( "f4_PlayerJob" ) local tnw, tnh = surface.GetTextSize( teamname ) local nick, plyTeam = ply:Nick(), ply:Team() self:ShowCloseButton(false) self:SetDraggable(false) self:SetTitle("") self:MakePopup() self:SetMouseInputEnabled(true) self.children = {} local closeButton = vgui.Create("DLabel", self) closeButton:SetDrawOnTop( true ) closeButton:SetText("") closeButton:SetSize(50, 18) closeButton:SetMouseInputEnabled(true) closeButton.Paint = function(s, w, h) draw.RoundedBox( 0, 0, 0, w, 2, Color( 200, 100, 100 )) draw.RoundedBox( 4, 0, 0, w, h, Color( 200, 100, 100 )) if s:IsHovered() then draw.RoundedBox( 0, 0, 0, w, 2, Color( 220, 100, 100 )) draw.RoundedBox( 4, 0, 0, w, h, Color( 220, 100, 100 )) end draw.SimpleText( "r", "Marlett", w/2, h/2, Color(255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) end closeButton.DoClick = function() self:Remove() end closeButton:SetZPos( 10000 ) self.children.closeButton = closeButton local tabs = vgui.Create( "DPanel", self ) tabs:SetMouseInputEnabled(true) tabs.Paint = function(s,w,h) draw.RoundedBox( 4, 0, 0, w, h, self.color or Color(200,200,200) ) draw.RoundedBoxEx( 4, 1, 1, w-2, h-2, self.color or Color(71,106,127), true, false, true, false ) end self.children.tabs = tabs local btn = vgui.Create("DLabel", tabs) btn:SetDrawOnTop( true ) btn:SetText("") btn:SetSize(50, 18) btn:SetMouseInputEnabled(true) btn.Paint = function(s, w, h) draw.RoundedBox( 0, 0, 0, w, 2, Color( 200, 100, 100 )) draw.RoundedBox( 4, 0, 0, w, h, Color( 200, 100, 100 )) if s:IsHovered() then draw.RoundedBox( 0, 0, 0, w, 2, Color( 220, 100, 100 )) draw.RoundedBox( 4, 0, 0, w, h, Color( 220, 100, 100 )) end draw.SimpleText( "r", "Marlett", w/2, h/2, Color(255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) end btn.DoClick = function() self:Remove() end btn:SetZPos( 10000 ) end vgui.Register("m_F4Frame", PANEL, "DFrame")[/CODE] There are two buttons in [I]vgui.Register'ed[/I] element: closeButton and btn. There's literally no difference between them [U]but:[/U] [B]closeButton[/B] is parented to [B]self[/B] (directly to the element which is going to be [I]vgui.Register'ed[/I]) [B]btn[/B] is parented to [B]tabs[/B] which is child element of the element which is going to be [I]vgui.Register'ed[/I] The issue is that [B]closeButton[/B] is working as it should, when [B]btn[/B] is only being drawn, but has no real functionality. When I change parent element of [B]btn[/B] from [B]tabs[/B] to [B]self[/B] it starts working, but I need parent of [B]btn[/B] to be [B]tabs[/B] because I need it to be inside of [B]tabs[/B] and set it's position relative to [B]tabs[/B], not [B]self[/B]. What's the issue with this code? I'm kinda new to VGUI of GMod, I might have missed something important. Thanks :3
btn:SetDrawOnTop( true ) probably makes it appear on top of everything while in reality it isn't.
[QUOTE=Robotboy655;52185967]btn:SetDrawOnTop( true ) probably makes it appear on top of everything while in reality it isn't.[/QUOTE] SetZPos to 9999999 does not force it to be drawn on top of everything else? I'll try removing it and see if it still has similar behaviour but I'm not sure if this gonna work. Also, how to force it to draw over [I]any[/I] element, if you are not sure that setzpos and drawontop are enough? I'm not sure, but I think this code should work without mess with elements Z layer.
[QUOTE=Robotboy655;52185967]btn:SetDrawOnTop( true ) probably makes it appear on top of everything while in reality it isn't.[/QUOTE] I've removed all functions related to Z pos of element, it looks like this now: [code] local btn = vgui.Create("DLabel", tabs) btn:SetText("") btn:SetSize(50, 18) btn:SetMouseInputEnabled(true) btn.Paint = function(s, w, h) draw.RoundedBox( 0, 0, 0, w, 2, Color( 200, 100, 100 )) draw.RoundedBox( 4, 0, 0, w, h, Color( 200, 100, 100 )) if s:IsHovered() then draw.RoundedBox( 0, 0, 0, w, 2, Color( 220, 100, 100 )) draw.RoundedBox( 4, 0, 0, w, h, Color( 220, 100, 100 )) end draw.SimpleText( "r", "Marlett", w/2, h/2, Color(255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) end btn.DoClick = function() self:Remove() end [/code] It has not changed its behaviour, so I'm still wondering what's wrong :( [editline]5th May 2017[/editline] Just lame stuff I found out - when I call nil method on created panel THE PROBLEM BUTTON STARTS WORKING despite the fact it's throwing LUA error into console FOR FUCK SAKE WHAT IS WRONG WITH THIS SHIT!11!111
I don't know what you are on about, but you have 2 exactly the same looking buttonsю [code] local PANEL = {} function PANEL:Init() local ply = LocalPlayer() local strup = string.upper local teamname = team.GetName(ply:Team()) surface.SetFont( "Default" ) local tnw, tnh = surface.GetTextSize( teamname ) local nick, plyTeam = ply:Nick(), ply:Team() self:ShowCloseButton(false) self:SetDraggable(false) self:SetTitle("") self:MakePopup() self:SetMouseInputEnabled(true) self.children = {} local closeButton = vgui.Create("DLabel", self) closeButton:SetDrawOnTop( true ) closeButton:SetText("") closeButton:SetSize(50, 18) closeButton:SetMouseInputEnabled(true) closeButton.Paint = function(s, w, h) draw.RoundedBox( 0, 0, 0, w, 2, Color( 200, 100, 100 )) draw.RoundedBox( 4, 0, 0, w, h, Color( 200, 100, 100 )) if s:IsHovered() then draw.RoundedBox( 0, 0, 0, w, 2, Color( 220, 100, 100 )) draw.RoundedBox( 4, 0, 0, w, h, Color( 220, 100, 100 )) end draw.SimpleText( "r", "Marlett", w/2, h/2, Color(255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) end closeButton.DoClick = function() self:Remove() end closeButton:SetZPos( 10000 ) self.children.closeButton = closeButton local tabs = vgui.Create( "DPanel", self ) tabs:SetMouseInputEnabled(true) tabs:Dock(FILL) tabs.Paint = function(s,w,h) draw.RoundedBox( 4, 0, 0, w, h, self.color or Color(200,200,200) ) draw.RoundedBoxEx( 4, 1, 1, w-2, h-2, self.color or Color(71,106,127), true, false, true, false ) end self.children.tabs = tabs local btn = vgui.Create("DLabel", tabs) btn:SetSize(50, 18) btn:SetMouseInputEnabled(true) btn.Paint = function(s, w, h) draw.RoundedBox( 0, 0, 0, w, 2, Color( 200, 100, 100 )) draw.RoundedBox( 4, 0, 0, w, h, Color( 200, 100, 100 )) if s:IsHovered() then draw.RoundedBox( 0, 0, 0, w, 2, Color( 220, 100, 100 )) draw.RoundedBox( 4, 0, 0, w, h, Color( 220, 100, 100 )) end draw.SimpleText( "r", "Marlett", w/2, h/2, Color(255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) end btn.DoClick = function() print("I work") self:Remove() end end vgui.Register("m_F4Frame", PANEL, "DFrame") concommand.Add("testtest", function() local a=vgui.Create("m_F4Frame") a:SetSize(400, 400) a:SetPos(100,200) a:MakePopup() end)[/code] This code works. Note the Dock( FILL )
[QUOTE=Robotboy655;52189214]I don't know what you are on about, but you have 2 exactly the same looking buttonsю [code] local PANEL = {} function PANEL:Init() local ply = LocalPlayer() local strup = string.upper local teamname = team.GetName(ply:Team()) surface.SetFont( "Default" ) local tnw, tnh = surface.GetTextSize( teamname ) local nick, plyTeam = ply:Nick(), ply:Team() self:ShowCloseButton(false) self:SetDraggable(false) self:SetTitle("") self:MakePopup() self:SetMouseInputEnabled(true) self.children = {} local closeButton = vgui.Create("DLabel", self) closeButton:SetDrawOnTop( true ) closeButton:SetText("") closeButton:SetSize(50, 18) closeButton:SetMouseInputEnabled(true) closeButton.Paint = function(s, w, h) draw.RoundedBox( 0, 0, 0, w, 2, Color( 200, 100, 100 )) draw.RoundedBox( 4, 0, 0, w, h, Color( 200, 100, 100 )) if s:IsHovered() then draw.RoundedBox( 0, 0, 0, w, 2, Color( 220, 100, 100 )) draw.RoundedBox( 4, 0, 0, w, h, Color( 220, 100, 100 )) end draw.SimpleText( "r", "Marlett", w/2, h/2, Color(255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) end closeButton.DoClick = function() self:Remove() end closeButton:SetZPos( 10000 ) self.children.closeButton = closeButton local tabs = vgui.Create( "DPanel", self ) tabs:SetMouseInputEnabled(true) tabs:Dock(FILL) tabs.Paint = function(s,w,h) draw.RoundedBox( 4, 0, 0, w, h, self.color or Color(200,200,200) ) draw.RoundedBoxEx( 4, 1, 1, w-2, h-2, self.color or Color(71,106,127), true, false, true, false ) end self.children.tabs = tabs local btn = vgui.Create("DLabel", tabs) btn:SetSize(50, 18) btn:SetMouseInputEnabled(true) btn.Paint = function(s, w, h) draw.RoundedBox( 0, 0, 0, w, 2, Color( 200, 100, 100 )) draw.RoundedBox( 4, 0, 0, w, h, Color( 200, 100, 100 )) if s:IsHovered() then draw.RoundedBox( 0, 0, 0, w, 2, Color( 220, 100, 100 )) draw.RoundedBox( 4, 0, 0, w, h, Color( 220, 100, 100 )) end draw.SimpleText( "r", "Marlett", w/2, h/2, Color(255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) end btn.DoClick = function() print("I work") self:Remove() end end vgui.Register("m_F4Frame", PANEL, "DFrame") concommand.Add("testtest", function() local a=vgui.Create("m_F4Frame") a:SetSize(400, 400) a:SetPos(100,200) a:MakePopup() end)[/code] This code works. Note the Dock( FILL )[/QUOTE] Good. When I type testtest into console, the button works. When I trigger it with function below it does not ¯ \ _ (ツ) _ / ¯ [code] local function createWindow() --unrelated stuff up here nf4_BG = vgui.Create( "m_F4Frame" ) nf4_BG:SetSize(1100,720) nf4_BG:Center() nf4_BG:MakePopup() --unrelated stuff down here end [/code]
There must be some other invisible panel over your panel.
[QUOTE=Robotboy655;52189520]There must be some other invisible panel over your panel.[/QUOTE] Dayum, man, I've ran clear script and it still does not work.
Sorry, you need to Log In to post a reply to this thread.