• Print

Author Topic: Derma Question  (Read 10352 times)

0 Members and 1 Guest are viewing this topic.

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Derma Question
« on: December 06, 2013, 03:42:48 pm »
I'm not too familiar with Derma and whatever xgui uses (draw boxes?). I'm trying to make a derma frrame that I can make up and close with the F2 key. I got it to open up with the key, but I want to be able to press it again and it closes.. anyone thing they can assist me on this?

Server Side:
Code: [Select]
function MyMenu( ply )
    umsg.Start( "MyMenu", ply )
    umsg.End()
end --End the function
hook.Add("ShowTeam", "MyHook", MyMenu)

Dumb Client Side:
Code: [Select]

function menu(ply)


// Start of Main Frame
local MainMenuFrame = vgui.Create( "DFrame" )
MainMenuFrame:SetSize( 600, 250 )
MainMenuFrame:SetTitle("Menu" )
MainMenuFrame:Center()
MainMenuFrame:SetVisible( true )
MainMenuFrame:SetDraggable( false )
MainMenuFrame:MakePopup()
// End of Main Frame

end

usermessage.Hook( "MyMenu", menu )


If anyone can assist me here, or direct me to where I can get help that would be really great, thanks.
(Also if anyone knows what xgui is coded in that would also be helpful. {Ex. Derma(vgui.Create) or this draw(draw.RoundedBox) stuff})
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Derma Question
« Reply #1 on: December 06, 2013, 04:18:43 pm »
If anyone can assist me here, or direct me to where I can get help that would be really great, thanks.
(Also if anyone knows what xgui is coded in that would also be helpful. {Ex. Derma(vgui.Create) or this draw(draw.RoundedBox) stuff})

Have a toggle function, and a show and a hide function.
F2 runs toggle.
The toggle function checks a variable and or IsVisible to see if the panel is visible, and runs hide if showing.
If not visible, the toggle function runs show.
Sorry, don't know command for closing, SetVisible or Close or something.
In a much more robust way, that's how XGUI does it.

Xgui is mostly written in the derma vgui. model, but has one or two drawroundedboxes too, which I thought was derma.

Sorry, I don't know Derma, etc.
The above is just my basic knowledge of lua/xgui and the little I picked up while looking through XGUI for what you were asking to do.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Re: Derma Question
« Reply #2 on: December 06, 2013, 04:27:06 pm »
I'll see what I can do. Hopefully that will work, and I'm glad we're somewhat on the same boat here. I'll edit this post if it ended up not working.

Edit:
As I have just remembered, I tried this before in the past, but for whatever reason it did not work. It never gave an error, it just didn't work.. Not sure what I want to do now.
« Last Edit: December 06, 2013, 04:38:24 pm by chaos13125 »
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Derma Question
« Reply #3 on: December 06, 2013, 04:41:56 pm »
You have tried what, exactly, in the past?
Experiencing God's grace one day at a time.

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Re: Derma Question
« Reply #4 on: December 06, 2013, 04:49:40 pm »
You have tried what, exactly, in the past?

Basically what Jam said. I did try it again though, and it still didn't work.

Client Side: (I have it commented because it's not working, and I testing a whole punch of things atm, so I need this menu to work no matter what.. I just wanted to be able to press the same button so it would go away :()
Code: [Select]
function tdm_menu(ply)
--if TestingPanel != nil then
--if TestingPanel:IsVisible( ) then
--MsgN('IsVisible')
--else
--MsgN('IsNotVisible')
--end

--else
local GAMEMODE_VERSION = "0.9b"

// Start of Main Frame
local MainMenuFrame = vgui.Create( "DFrame" )
MainMenuFrame:SetSize( 600, 250 )
MainMenuFrame:SetTitle("Team Deathmatch Menu: Version "..GAMEMODE_VERSION )
MainMenuFrame:Center()
MainMenuFrame:SetVisible( true )
MainMenuFrame:SetDraggable( false )
MainMenuFrame:MakePopup()
function MainMenuFrame:Paint( w, h )
draw.RoundedBox( 0, 0, 0, w, h, Color(team.GetColor(LocalPlayer():Team()).r,team.GetColor(LocalPlayer():Team()).g,team.GetColor(LocalPlayer():Team()).b,50))
surface.SetDrawColor(0,0,0)
surface.DrawOutlinedRect(1,1,w-1,h-1)
end
local TestingPanel = vgui.Create( "DPanel", MainMenuFrame )
TestingPanel:SetPos( 25, 50 )
TestingPanel:SetSize( 250, 250 )
TestingPanel.Paint = function() -- Paint function
    --Set our rect color below us; we do this so you can see items added to this panel
    surface.SetDrawColor( 50, 50, 50, 255 )
    surface.DrawRect( 0, 0, TestingPanel:GetWide(), TestingPanel:GetTall() ) -- Draw the rect
end

end
--end

concommand.Add( "tdm_menu", tdm_menu )
usermessage.Hook( "MyMenu", tdm_menu )
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Derma Question
« Reply #5 on: December 06, 2013, 06:30:17 pm »
And what piece doesn't work?
Experiencing God's grace one day at a time.

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Re: Derma Question
« Reply #6 on: December 06, 2013, 11:05:26 pm »
And what piece doesn't work?

The menu doesn't go away if it is already opened when I press F2 .
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Derma Question
« Reply #7 on: December 07, 2013, 10:18:50 am »
Try basing it off your main frame instead of the panel frame.
Experiencing God's grace one day at a time.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Derma Question
« Reply #8 on: December 07, 2013, 10:35:45 am »
Here's how I did it in my gamemode:

SERVERSIDE:
Code: Lua
  1. function GM:ShowTeam( ply )
  2.  
  3.         ply:SendLua("SGS_OpenHotBar()")
  4.  
  5. end
  6.  
All that does is send the SGS_OpenHotBar() function to the client when F2 is pressed.

CLIENTSIDE:
Code: Lua
  1. function SGS_OpenHotBar()
  2.  
  3.         if SGS.HotBar then
  4.                 SGS.HotBar:Remove()
  5.                 SGS.HotBar = nil
  6.         else
  7.                 SGS.HotBar = vgui.Create( "sgs_HotBar" )
  8.                 SGS.HotBar:SetVisible(true)
  9.         end
  10.        
  11. end
  12.  
How I did it, was when I open the panel I set it to a global instead of a local. So instead of doing:
local whatever = vgui.Create("DPanel")
I did:
SGS.whatever = vgui.Create("DPanel")

This allows me to check on the status and manipulate the panel from other code later on.
All you need to do is check to see if it exists. If so, remove it. If not, create it.
There you are! Toggle!


edit: I create my own custom vgui element, that's why my else block is so small. For you, you'd just paste your entire vgui creation code inside of the else, or calling it through a function might be cleaner.
« Last Edit: December 07, 2013, 10:37:32 am by MrPresident »

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: Derma Question
« Reply #9 on: December 07, 2013, 10:36:32 am »
As it currently stands, every time you run the tdm_menu function, you're creating a new derma menu. These can start to add up if you don't take care of them. So there's two ways to go about doing what you want:


A) Use :Remove() to hide the menu, recreate the menu to show it.
You can use nil to see if the window exists or not. The code would look a little something like this:
Code: Lua
  1. local MainMenuFrame      --*Important!*
  2.  
  3. function tdm_menu(ply)
  4.   if MainMenuFrame then
  5.     MainMenuFrame:Remove()
  6.     MainMenuFrame = nil
  7.     return
  8.   end
  9.  
  10.   --Code to create Frame here.
  11.  
  12. end
  13.  

Note: Another reason why I think this may not have worked for you is because you need to declare your MainMenuFrame to be local to the script, rather than the function. This will ensure that future function calls are accessing the same variable, rather than creating new ones.



B) Create the menu once, then just set the visibility of it.
This is how XUGI works- If I were to have XGUI create all of the derma elements every time you opened it.. there would be huge lag spikes. However, this method isn't designed for DFrame popups, so you may have to do a bit of extra work to get this to work right (with regards to enabling/disabling mouse and keyboard focus). To do this, you would restructure you code like so:

Code: Lua
  1. -- Create Frame here outside the function, but set MainMenuFrame:SetVisible(false). Preferably don't call :MakePopup() here.
  2.  
  3. function tdm_menu(ply)
  4.   if MainMenuFrame:IsVisible()
  5.     MainMenuFrame:setVisible(false)
  6.   else
  7.     MainMenuFrame:setVisible(true)
  8. end
  9.  

You will also have to determine when the best method to call :MakePopup() is, ideally you would want it only to happen the first time the menu is opened. But, I digress- it's been a while since I've worked with this, and since your menu is so simple, the first option should be fine.
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Derma Question
« Reply #10 on: December 07, 2013, 10:39:55 am »
Stickly's previous post is pretty much exactly what I was trying to show, except he explained it much better than I did.

I hope this helps.

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Re: Derma Question
« Reply #11 on: December 07, 2013, 01:41:48 pm »
Thank you all for assisting me, though it did not appear to work for me. It was also apparent to me that I did not send my entire code, so some of it was lacking information.

This is my NEW CLIENTSIDE that I got from Mr. President.
Code: [Select]
function GM:ShowTeam( ply )
ply:SendLua("TeamDeathMatchMenu()")   
end

This is my entire SERVERSIDE that I attempted to modify using what first Mr. President said, and it didn't really work. So then I tried to use Sticky Man's, but this wouldn't work at all, like not an error, no nothing, just nothing worked.
Code: [Select]
function TeamDeathMatchMenu(ply)

MainMenuFrame = vgui.Create( "DFrame" )
MainMenuFrame:SetSize( 600, 250 )
MainMenuFrame:SetTitle("Team Deathmatch Menu: Version" )
MainMenuFrame:Center()
MainMenuFrame:ShowCloseButton( true )
MainMenuFrame:SetDraggable( false )
if MainMenuFrame:IsVisible() then
   MainMenuFrame:SetVisible(false)
else
   MainMenuFrame:SetVisible(true)
end
function MainMenuFrame:Paint( w, h )
draw.RoundedBox( 0, 0, 0, w, h, Color(team.GetColor(LocalPlayer():Team()).r,team.GetColor(LocalPlayer():Team()).g,team.GetColor(LocalPlayer():Team()).b,50))
surface.SetDrawColor(0,0,0)
surface.DrawOutlinedRect(1,1,w-1,h-1)
end

end

concommand.Add( "TeamDeathMatchMenu", TeamDeathMatchMenu )
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: Derma Question
« Reply #12 on: December 09, 2013, 09:23:25 am »
I don't think you're quite grasping the concept, but the following commented code should work, and hopefully explain how it's working:

Code: Lua
  1. local MainMenuFrame                     -- IMPORTANT!
  2.  
  3. function TeamDeathMatchMenu(ply)        -- This is obviously called when the command is run.
  4.        
  5.         -- This checks to see if the menu is already open
  6.         if MainMenuFrame then
  7.                 MainMenuFrame:Remove()  -- Remove the menu and set the value to nil
  8.                 MainMenuFrame = nil
  9.                 return                                  -- Exit the function to prevent the menu from geting created again.
  10.         end
  11.        
  12.         -- Create the frame, since it doesn't exist
  13.         MainMenuFrame = vgui.Create( "DFrame" )
  14.         MainMenuFrame:SetSize( 600, 250 )
  15.         MainMenuFrame:SetTitle("Team Deathmatch Menu: Version" )
  16.         MainMenuFrame:Center()
  17.         MainMenuFrame:ShowCloseButton( true )
  18.         MainMenuFrame:SetDraggable( false )
  19.        
  20.        
  21.         function MainMenuFrame:Paint( w, h )
  22.                 draw.RoundedBox( 0, 0, 0, w, h, Color(team.GetColor(LocalPlayer():Team()).r,team.GetColor(LocalPlayer():Team()).g,team.GetColor(LocalPlayer():Team()).b,50))
  23.                 surface.SetDrawColor(0,0,0)
  24.                 surface.DrawOutlinedRect(1,1,w-1,h-1)
  25.         end
  26.        
  27.         MainMenuFrame:SetVisible( true )                -- You forgot to add these two lines in your second example, which is probably why nothing happened.
  28.         MainMenuFrame:MakePopup( true )
  29.  
  30. end
  31.  
  32. concommand.Add( "TeamDeathMatchMenu", TeamDeathMatchMenu )

(Also, you can use the BBCode [ code=lua ] for lua code on these forums.)
« Last Edit: December 09, 2013, 09:26:22 am by Stickly Man! »
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

  • Print