Problem with closing derma.

Hello,here is my code,this VGUI is binded on F2 and it have to close if player press F2 and VGUI is open.



local frame -- make a frame variable to use
-- then later
    net.Receive( "showadmin", function()
    if !IsValid( frame ) then -- if the frame variable isn't defined then
    frame = vgui.Create( 'DFrame' ) -- set it as your frame
    frame = vgui.Create( 'DFrame' ) -- set it as your frame
    frame:SetSize(900, 400) 
    local w = ScrW() / 2
    local h = ScrH() / 2
    frame:SetVisible( true )
    frame:SetPos(w-450, h-200)
    frame:SetTitle("La Merguez - Panneau de Modération")
    frame:SetDraggable(false)             
    frame:ShowCloseButton(true)
    frame:MakePopup()
    frame:SizeToContents()
    frame.Paint = function()
    draw.RoundedBox( 8, 0, 0, frame:GetWide(), frame:GetTall(), Color( 50, 50, 50))
    end
    frame:Center()
    else -- otherwise
    frame:Close() -- close the existing frame
    frame = nil -- set the variable as nil just to make sure
    end
end ) 

This code doesn’t work except if i remove the MakePopup function.
If i remove the MakePopup function all work fine,but i need the MakePopup function.

How i can solve this problem ?

If you want anyone to help, tab your code so it’s followable. Your tabbing makes 0 sense and is illogical…

I’ve cleaned up your code for you. First off, you’ve defined ‘frame’ as a new vgui instance twice. You’ve also defined ‘w’ and ‘h’ (I assume you wanted the width and height) but used them in setting the position, only to be obsolete because of you using the frame:Center() function. I fixed your problem by making the ‘frame’ variable global, instead of local. Because ‘frame’ is very generic I’ve changed it to ‘modpanel’. In your paint function you used the GetWide and GetTall functions, but instead you can give the paint function the arguments self, w, h, ‘self’ being the panel itself, so you could use self:GetWide() and it would get that panel, and w being the width, and h being the height.

I’ve cleaned up the tabbing and stuff; here you go:



local function drawModPanel()
  local w = ScrW() / 2
  local h = ScrH() / 2

  modpanel = vgui.Create( 'DFrame' )
  modpanel:SetSize(w, h)
  modpanel:SetVisible( true )
  modpanel:SetTitle("La Merguez - Panneau de Modération")
  modpanel:SetDraggable(false)
  modpanel:ShowCloseButton(true)
  modpanel:SizeToContents()
  modpanel.Paint = function( self, w, h )
    draw.RoundedBox( 8, 0, 0, w, h, Color(50, 50, 50) )
  end
  modpanel:Center()
  modpanel:MakePopup()
end

net.Receive( "showadmin", function()
  if IsValid(modpanel) then
    modpanel:Close()
    modpanel = nil
  else
    drawModPanel()
  end
end )


Thanks you for the explainations and the help but the problem is still the same with your code F2 don’t close the panel.

But if i remove the MakePopup it actually close it.

May I see the server side part of the code that handles when the player presses F2, if you use the GM:ShowTeam() function/hook?

I already tryed to make an check serverside,but it still the same,if i’ve got this stupid MakePopup it won’t close the DFrame.

[editline]4th April 2016[/editline]

I think it’s because if you do MakePopup,it disable the possibility to make F2 again.

Yeah.
Try doing this:



local function drawModPanel()
  local w = ScrW() / 2
  local h = ScrH() / 2

  modpanel = vgui.Create( 'DFrame' )
  modpanel:SetSize(w, h)
  modpanel:SetVisible( true )
  modpanel:SetTitle("La Merguez - Panneau de Modération")
  modpanel:SetDraggable(false)
  modpanel:ShowCloseButton(true)
  modpanel:SizeToContents()
  modpanel.Paint = function( self, w, h )
    draw.RoundedBox( 8, 0, 0, w, h, Color(50, 50, 50) )
  end
  modpanel:Center()
  gui.EnableScreenClicker( true )
end

net.Receive( "showadmin", function()
  if IsValid(modpanel) then
    modpanel:Close()
    modpanel = nil
    gui.EnableScreenClicker( false )
  else
    drawModPanel()
  end
end )


I already done that but the problem is player can actually open other menus.

Next time don’t open a brand new thread for the same exact question. You had people answering you in your other one.

http://forum.facepunch.com/showthread.php?t=1513065

I say this in the nicest, most unhostile way I can - Learn English

Yeah sorry english isn’t my primary language.

bump

bump


(User was banned for this post ("Your thread is marked as solved - why bump?" - Bradyns))