• The Ultimate Guide to Derma - Everything there is to know about Derma
    217 replies, posted
I understand what your all saying about the looping stuff, but for now I just want to fill out all the libraries. My original plan was just to paste exactly how each part of Derma works. Like how I did above. Later on I will then go in depth about VGUI and coding more efficiently. I will also include other examples other than concommands. [b]Edit:[/b] [QUOTE=garry]FYI, DCollapsibleCategory is really designed to be used in a DPanelList (as seen in the map selection/toolbar/etc).[/QUOTE] I noticed that while going through the spawnmenu to find out how it worked. But it seems like there are other was to use it.
For some reason when I open a derma panel I made the mouse doesn't appear, and instead I can look around like normal, which means the only way I can press something is if I open the console first so I can see my mouse. Is there a reason why that happens?
I'm not to sure why that happens. Post your code then I'll be able to tell.
[lua] function testpanel() // Create the function test = vgui.Create("DFrame") // Create the frame menu1 = vgui.Create("DButton") // Create the button menu2 = vgui.Create("DButton") menu3 = vgui.Create("DButton") menu4 = vgui.Create("DButton") test:SetPos(50,50) // set the frame's position on the screen test:SetSize(500, 500) // set the frame size test:SetTitle( "Madness Evolved" ) // set the frame title test:SetVisible( true ) // Make the frame visible test:MouseCapture(true) menu1:SetParent( test ) // parent the button to the frame menu1:SetText( "Weapons >" ) // set the button text menu1:SetPos(51, 150) // set the button position in the frame menu1:SetSize( 100, 20 ) // set the button size menu1.DoClick = function () // this will be called when the button is clicked local menu123 = DermaMenu() // create a derma menu menu123:AddOption("hello", function() Msg("Hello") end ) // adding options menu123:AddOption("how", function() Msg("How") end ) menu123:AddOption("are", function() Msg("Are") end ) menu123:AddOption("you", function() Msg("You") end ) menu123:AddOption("?", function() Msg("?") end ) menu123:Open() end // ending the doclick function menu2:SetParent( test ) menu2:SetText( "Kill >" ) menu2:SetPos(150, 150) menu2:SetSize( 100, 20 ) menu2.DoClick = function () // this will be called when the button is clicked local menu223 = DermaMenu() // create a derma menu menu223:AddOption("Ignite", RunConsoleCommand("igniteplayer", "LocalPlayer()")) // adding options menu223:AddOption("Normal Kill", function() LocalPlayer():ConCommand("kill") end) menu223:AddOption("Time Bomb", RunConsoleCommand("timebomb", "LocalPlayer()")) menu223:AddOption("Gravity Kill", RunConsoleCommand("gravitykill")) menu223:AddOption("Force Kill", function() Msg("?") end ) menu223:Open() end // ending the doclick function menu3:SetParent( test ) menu3:SetText( "Powerups >" ) menu3:SetPos(250, 150) menu3:SetSize( 100, 20 ) menu3.DoClick = function () // this will be called when the button is clicked local menu323 = DermaMenu() // create a derma menu menu323:AddOption("hello", function() Msg("Hello") end ) // adding options menu323:AddOption("how", function() Msg("How") end ) menu323:AddOption("are", function() Msg("Are") end ) menu323:AddOption("you", function() Msg("You") end ) menu323:AddOption("?", function() Msg("?") end ) menu323:Open() end // ending the doclick function menu4:SetParent( test ) menu4:SetText( "Options >" ) menu4:SetPos(350, 150) menu4:SetSize( 100, 20 ) menu4.DoClick = function () // this will be called when the button is clicked local menu423 = DermaMenu() // create a derma menu menu423:AddOption("hello", function() Msg("Hello") end ) // adding options menu423:AddOption("how", function() Msg("How") end ) menu423:AddOption("are", function() Msg("Are") end ) menu423:AddOption("you", function() Msg("You") end ) menu423:AddOption("?", function() Msg("?") end ) menu423:Open() end // ending the doclick function // function KeyPressed () // if input.IsKeyDown(27) = true then // test:MakePopup() // make the frame popup // else end // ending the function Msg("FUCK OFF") concommand.Add("menutest", testpanel) [/lua]
I have a feeling it has to do with [lua]test:MouseCapture(true)[/lua] Also try Creating your Derma items before you code them. I wouldn't just create them at the top then work your way down like that. [b]Edit:[/b] Try taking that line out. Then what happens?
With or without mousecapture, it still doesn't work. I added that in a couple minutes ago to see if it would fix it.
Alright I know what's wrong. Replace [lua]test:MakePopup()[/lua] With [lua]test:MouseCapture(true)[/lua] You need to make the frame appear.
I have added your images from this thread to the wiki. I hope your fine with it. Good tutorial of showing an easy way of how to use Derma.
[QUOTE=aVoN]I have added your images from this thread to the wiki. I hope your fine with it. Good tutorial of showing an easy way of how to use Derma.[/QUOTE] Alright thank you! I've been wanting to know how to add images to it. May you care to send a PM on how? [b]Edit:[/b] [QUOTE=superadamwo]With or without mousecapture, it still doesn't work. I added that in a couple minutes ago to see if it would fix it.[/QUOTE] Here's your frame the way I'd do it. Should work, not tested. [lua] function testpanel() // Create the function test = vgui.Create("DFrame") // Create the frame test:SetPos(50,50) // set the frame's position on the screen test:SetSize(500, 500) // set the frame size test:SetTitle( "Madness Evolved" ) // set the frame title test:SetVisible( true ) // Make the frame visible test:SetDraggable( true ) -- Draggable by mouse? test:ShowCloseButton( true ) -- Show the close button? test:MakePopup() -- Show the frame. THIS IS WHAT YOU MISSED menu1 = vgui.Create("DButton") menu1:SetParent( test ) // parent the button to the frame menu1:SetText( "Weapons >" ) // set the button text menu1:SetPos(51, 150) // set the button position in the frame menu1:SetSize( 100, 20 ) // set the button size menu1.DoClick = function () // this will be called when the button is clicked local menu123 = DermaMenu() // create a derma menu menu123:AddOption("hello", function() Msg("Hello") end ) // adding options menu123:AddOption("how", function() Msg("How") end ) menu123:AddOption("are", function() Msg("Are") end ) menu123:AddOption("you", function() Msg("You") end ) menu123:AddOption("?", function() Msg("?") end ) menu123:Open() end // ending the doclick function menu2 = vgui.Create("DButton") menu2:SetParent( test ) menu2:SetText( "Kill >" ) menu2:SetPos(150, 150) menu2:SetSize( 100, 20 ) menu2.DoClick = function () // this will be called when the button is clicked local menu223 = DermaMenu() // create a derma menu menu223:AddOption("Ignite", RunConsoleCommand("igniteplayer", "LocalPlayer()")) // adding options menu223:AddOption("Normal Kill", function() LocalPlayer():ConCommand("kill") end) menu223:AddOption("Time Bomb", RunConsoleCommand("timebomb", "LocalPlayer()")) menu223:AddOption("Gravity Kill", RunConsoleCommand("gravitykill")) menu223:AddOption("Force Kill", function() Msg("?") end ) menu223:Open() end // ending the doclick function menu3 = vgui.Create("DButton") menu3:SetParent( test ) menu3:SetText( "Powerups >" ) menu3:SetPos(250, 150) menu3:SetSize( 100, 20 ) menu3.DoClick = function () // this will be called when the button is clicked local menu323 = DermaMenu() // create a derma menu menu323:AddOption("hello", function() Msg("Hello") end ) // adding options menu323:AddOption("how", function() Msg("How") end ) menu323:AddOption("are", function() Msg("Are") end ) menu323:AddOption("you", function() Msg("You") end ) menu323:AddOption("?", function() Msg("?") end ) menu323:Open() end // ending the doclick function menu4 = vgui.Create("DButton") menu4:SetParent( test ) menu4:SetText( "Options >" ) menu4:SetPos(350, 150) menu4:SetSize( 100, 20 ) menu4.DoClick = function () // this will be called when the button is clicked local menu423 = DermaMenu() // create a derma menu menu423:AddOption("hello", function() Msg("Hello") end ) // adding options menu423:AddOption("how", function() Msg("How") end ) menu423:AddOption("are", function() Msg("Are") end ) menu423:AddOption("you", function() Msg("You") end ) menu423:AddOption("?", function() Msg("?") end ) menu423:Open() end // ending the doclick function end concommand.Add("menutest", testpanel) [/lua] Good luck man.
[QUOTE=PC Camp] [lua] menu1 = vgui.Create("DButton") menu1:SetParent( test ) // parent the button to the frame [/lua][/QUOTE] [lua] menu1 = vgui.Create( "DButton", test ) [/lua]
You could do that also. I think it's easier for new learners to understand it directly. Thanks though. :)
Worked, thanks. Was it not working because I did MakePopup after defining the buttons or something?
I think so. For some reason you must define everything in chronological order. For example, look at how I did the DPanelList.
Well that's annoying.
Two things: 1. How can I make F1 toggle a window? I have it open it but haven't been able to make it close it if it's open. 2. No one gave me a good working answer on how to change a DLabel's text size. Can you answer these?
What if you wanna make it so you can open it by a command? :)
[QUOTE=ChewGum]What if you wanna make it so you can open it by a command? :)[/QUOTE] concommand.Add("showMenu",ShowMenu) ShowMenu() is a function to create the menu something similar to this [lua] vgui.Register( "Menu",PANEL, "DFrame" ) DermaMenu = nil function ShowMenu() DermaMenu = vgui.Create("Menu") DermaMenu:MakePopup() DermaMenu:Center() end[/lua]
[QUOTE=superadamwo]With or without mousecapture, it still doesn't work. I added that in a couple minutes ago to see if it would fix it.[/QUOTE] [lua]gui.EnableScreenClicker( true )[/lua] [QUOTE=Bang Train]concommand.Add("showMenu",ShowMenu) ShowMenu() is a function to create the menu something similar to this [lua] vgui.Register( "Menu",PANEL, "DFrame" ) DermaMenu = nil function ShowMenu() DermaMenu = vgui.Create("Menu") DermaMenu:MakePopup() DermaMenu:Center() end[/lua][/QUOTE] Why would you register "Menu" when there is nothing there? PANEL isn't defined, and the whole thing is just broken. [lua] function ShowMenu() DermaMenu = vgui.Create("DFrame") // Remember to set the size and position. DermaMenu:MakePopup() DermaMenu:Center() end concommand.Add( "ShowMahMenu", ShowMenu ) [/lua]
Kiporsnikov: sorry 4got to show what PANEL was. [lua] local PANEL = {} function PANEL:Init() --create the buttons and stuff end function PANEL:PerformLayout() --perform any layout stuff like panel's size end vgui.Register( "Menu",PANEL, "DFrame" ) DermaMenu = nil function ShowMenu() DermaMenu = vgui.Create("Menu") DermaMenu:MakePopup() DermaMenu:Center() end[/lua]
[QUOTE=Bang Train]Kiporsnikov: sorry 4got to show what PANEL was. [lua] local PANEL = {} function PANEL:Init() --create the buttons and stuff end function PANEL:PerformLayout() --show panel end vgui.Register( "Menu",PANEL, "DFrame" ) DermaMenu = nil function ShowMenu() DermaMenu = vgui.Create("Menu") DermaMenu:MakePopup() DermaMenu:Center() end[/lua][/QUOTE] Still completely useless and unnecessary. You're creating a custom blank VGUI element derived from DFrame. When there's one exactly like it already... Called DFrame! [lua] Value_One = "Pies" -- This one isn't good enough for us. Value_Two = Value_One print( "I'd like some " .. Value_Two .. "." ) -- That's better. [/lua]
I've been trying to figure out the same thing as Bang Train, sort of. I've been looking for a function that will cause my menu to open when a player holds down Q, and close when they let go.
[lua]function QMenuOn( pl, Key ) if ( Key == KEY_Q ) then // Open the menu end end hook.Add( "KeyPress", "Lolque", QMenuOn ) function QMenuOff( pl, Key ) if ( Key == KEY_Q ) then // Close the menu end end hook.Add( "KeyRelease", "Lolwut", QMenuOff ) [/lua] See: [url]http://www.garrysmod.com/wiki/?title=Gamemode.KeyRelease[/url] [url]http://www.garrysmod.com/wiki/?title=Gamemode.KeyPress[/url] [url]http://www.garrysmod.com/wiki/?title=IN_KEYS[/url] [url]http://www.garrysmod.com/wiki/?title=Hook.Add[/url]
I thought I looked at every hook with the word "key" in it. I guess not. Fuck... Now one more thing I never understood when I looked at scripts is why people put two functions in if they only use one. You put in pl and key, but you only used key. Why is that? Also I tried it that way and it didn't work. So then I just tried: [lua] function QMenuOn( pl, Key ) if ( Key == KEY_Q ) then Msg("LGBBBVHKHBVLHK") end end hook.Add( "KeyPress", "QMenuOn", QMenuOn ) [/lua] But that didn't work either :(
Do a think hook and use [url=http://garrysmod.com/wiki/?title=Player.KeyDown]KeyDown()[/url]. I'd help and provide an example but I have a term paper to get done. Sorry. :(
I tried something else, but it appears that the whole system is bugged. [lua] if pl:KeyDown( KEY_Q ) then print( "IT'S ON!" ) end [/lua] That returns true at random. If I were you, I'd hook into SpawnMenuOpen or something like that. Either that, or one of the F* functions.
If you do this [lua] function SeeIfTheirKeyIsDown() for k, v in pairs(player.GetAll()) do if v:KeyDown( KEY_Q ) then Msg("Holding Q down\n") -- Create panel here end end end hook.Add("Think", "Your Think Hook", SeeIfTheirKeyIsDown) [/lua] it will work. Tested, works fine. :)
Doesn't a "think" hook lag a lot? Also why did you need to put the loop there, couldn't you have just done: [lua] function SeeIfTheirKeyIsDown() if LocalPlayer():KeyDown( KEY_Q ) then Msg("Holding Q down\n") -- Create panel here end end end hook.Add("Think", "Your Think Hook", SeeIfTheirKeyIsDown) [/lua] Since the think hook is running the function every frame anyway. Also the other problem is that the derma panel will repeatedly open while you hold down Q so you'll end up with hundreds of them, and I just want it to create one and then keep that one open until I let go of Q. And Kiporsnikov, I can't use SpawnMenuOpen because the spawn menu is disabled in my gamemode, and holding down Q with it disabled makes the function return false.
wouldn't hook.Add("OnSpawnMenuOpen", "OpenMyPanel", CreatePanel()) and hook.Add("OnSpawnMenuClose", "CloseMyPanel", OnSpawnMenuClose()) be better? don't forget to create your panel with a variable eg myqpanel = vgui.Create("dpanel") so on close you can do myqpanel:Remove() if that hook fails you can always check the concommand +menu and -menu I think that hook i used is in the base so you shouldn't have to use the concommand also if you don't want the spawnmenu to come up either don't derive from sandbox or return false at the end of the CreatePanel() function.
Well [lua]LocalPlayer()[/lua] should always be used on client scripts. [b]Very[/b] rarely will LocalPlayer() not come up nil. When using [lua]for k, v in pairs(player.GetAll()) do[/lua] your cycling through all the players to see if they have that key down. For your request, I'll look into that. I've never made a toggling frame by holding down a key. If anything I'd do two concommands like "+panel" and "-panel". I'll write something up that will work like how you want it.
[QUOTE=Ben Build]wouldn't hook.Add("OnSpawnMenuOpen", "OpenMyPanel", CreatePanel()) and hook.Add("OnSpawnMenuClose", "CloseMyPanel", OnSpawnMenuClose()) be better? don't forget to create your panel with a variable eg myqpanel = vgui.Create("dpanel") so on close you can do myqpanel:Remove() if that hook fails you can always check the concommand +menu and -menu[/QUOTE] This is the best approach.
Sorry, you need to Log In to post a reply to this thread.