• The Best Way to Refresh Some Code Frequently
    6 replies, posted
First I would like the list to dislpay the name, playermodel and money of every player on the server which it does just fine. Second I would like the player to be able to click on the playermodel whereupon a notification containing all information pops up. That also works fine. But if the player clicks on multiple playermodels the notifications that are popping up are overlapping eachother and that looks ugly. So I want the player to just be able to click at one playermodel one time and after the notification disappeared it should be possible to click any playermodel again. And that's the problem. It just works for the last player-panel but I have no clue why. [CODE] -- The panel for the first tab local panel1 = vgui.Create( "DScrollPanel", sheet ) panel1:SetWide(600) panel1:SetTall(465) panel1:Dock(RIGHT) panel1:DockMargin(-15,-28,-174,0) panel1.Paint = function( self, w, h ) draw.RoundedBox( 4, 0, 0, 600, h, Color( 190, 190, 190, 255 ) ) end --The panels on which the player information are displayed (With a white frame around each panel) for k,v in ipairs(player.GetAll()) do panelP = vgui.Create( "DPanel", panel1) panelP:SetWide(350) panelP:SetTall(50) panelP:SetPos(0,-50+k*50) panelP:SetParent(panel1) function panelP:Paint() surface.SetDrawColor(255,255,255) surface.DrawOutlinedRect(0,0,350,50) draw.RoundedBox(5,335,5,10,40,team.GetColor(v:Team ())) surface.SetTextPos( 55, 5 ) surface.SetFont("MyFont1") surface.SetTextColor(255,255,255,255) if(string.len(v:Nick())) > 13 then surface.DrawText("Name:"..string.sub(v:Nick(),1,13).."...") else surface.DrawText("Name:"..(v:Nick())) end surface.SetTextPos( 55, 25 ) surface.DrawText("Money:"..v:getDarkRPVar( "money")) end end -- The background panels for the playermodel-panels for k,v in pairs(player.GetAll()) do pmPanel = vgui.Create( "DPanel",panel1 ) pmPanel:SetPos( 0,-50+k*50 ) pmPanel:SetSize( 50, 50 ) function pmPanel:Paint() surface.SetDrawColor(90,90,90,100) surface.DrawRect(1,1,49,48) end -- The playermodel-panels picon = vgui.Create( "DModelPanel", pmPanel ) picon:SetSize( 50, 50 ) picon:SetPos( 0,-1 ) picon:SetModel( v:GetModel() ) picon:SetAnimated( false ) picon:SetCamPos( Vector( 18, 0, 65)) picon:SetLookAt( Vector( 0, 0, 65 ) ) function picon:LayoutEntity( ent ) -- Stops the rotation of the playermodels end picon.DoClick = function() -- The notification panel NotifyPanel = vgui.Create( "DNotify" ) NotifyPanel:SetPos( 15, 55 ) NotifyPanel:SetSize( 350, 100 ) NotifyPanel:SetLife(3) -- The gray background panel bg = vgui.Create( "DPanel", NotifyPanel ) bg:Dock( FILL ) bg:SetBackgroundColor( Color( 64, 64, 64 ) ) -- The background panel for the playermodel in the notification local imgP = vgui.Create( "DPanel", bg ) imgP:SetSize( 80, 80 ) imgP:SetPos( 11,11 ) imgP:SetParent(bg) function imgP:Paint() surface.SetDrawColor(100,100,100) surface.DrawRect(0,0,230,110) end -- The playermodel-panel on the notification local img = vgui.Create( "DModelPanel", imgP ) img:SetSize( 80, 80 ) img:SetPos( 0,0 ) img:SetModel( v:GetModel() ) img:SetAnimated( false ) img:SetCamPos( Vector( 15, 0, 64)) img:SetLookAt( Vector( 0, 0, 64 )) function img:LayoutEntity( ent ) -- Stops the rotation of the playermodels end -- The text on the notification local Plabel = vgui.Create( "DPanel", bg) Plabel:SetPos(105,10) Plabel:SetSize(340,80) function Plabel:Paint() surface.SetDrawColor(100,100,100) surface.DrawRect(0,0,230,110) surface.SetTextPos( 10, 5 ) surface.SetFont("MyFont1") surface.SetTextColor(255,255,255,255) if(string.len(v:Nick())) > 13 then surface.DrawText("Name:"..string.sub(v:Nick(),1,13).."...") else surface.DrawText("Name:"..(v:Nick())) end surface.SetTextPos( 10, 25 ) surface.DrawText("Money:"..v:getDarkRPVar( "money")) end -- Adds the gray background panel to the notification NotifyPanel:AddItem( bg ) end -- That should disable all panels if the notification is visible so that the player can't open more than one notification -- at the same time if IsValid(bg) and IsValid(pmPanel) then if bg:IsVisible() then pmPanel:SetDisabled(true) elseif not IsVisible(bg) then pmPanel:SetDisabled(false) end end end -- The piece of code below is there to refresh the player-model panels so that they can be disabled immediatly if clicked on for k,v in pairs(player.GetAll()) do timer.Create("RefreshPlayerModels", 1, 0, function() -- That removes the existing playermodel-panels and their backgrounds pmPanel:Remove() picon:Remove() -- The background panels for the playermodel-panels pmPanel = vgui.Create( "DPanel",panel1 ) pmPanel:SetPos( 0,-50+k*50 ) pmPanel:SetSize( 50, 50 ) function pmPanel:Paint() surface.SetDrawColor(90,90,90,100) surface.DrawRect(1,1,49,48) end -- The playermodel-panels picon = vgui.Create( "DModelPanel", pmPanel ) picon:SetSize( 50, 50 ) picon:SetPos( 0,-1 ) picon:SetModel( v:GetModel() ) picon:SetAnimated( false ) picon:SetCamPos( Vector( 18, 0, 65)) picon:SetLookAt( Vector( 0, 0, 65 ) ) function picon:LayoutEntity( ent ) end picon.DoClick = function() -- The notification panel NotifyPanel = vgui.Create( "DNotify" ) NotifyPanel:SetPos( 15, 55 ) NotifyPanel:SetSize( 350, 100 ) NotifyPanel:SetLife(3) -- The gray background panel bg = vgui.Create( "DPanel", NotifyPanel ) bg:Dock( FILL ) bg:SetBackgroundColor( Color( 64, 64, 64 ) ) -- The background panel for the playermodel in the notification local imgP = vgui.Create( "DPanel", bg ) imgP:SetSize( 80, 80 ) imgP:SetPos( 11,11 ) imgP:SetParent(bg) function imgP:Paint() surface.SetDrawColor(100,100,100) surface.DrawRect(0,0,230,110) end -- The playermodel-panel on the notification local img = vgui.Create( "DModelPanel", imgP ) img:SetSize( 80, 80 ) img:SetPos( 0,0 ) img:SetModel( v:GetModel() ) img:SetAnimated( false ) img:SetCamPos( Vector( 15, 0, 64)) img:SetLookAt( Vector( 0, 0, 64 )) function img:LayoutEntity( ent ) end -- The text on the notification local Plabel = vgui.Create( "DPanel", bg) Plabel:SetPos(105,10) Plabel:SetSize(340,80) function Plabel:Paint() surface.SetDrawColor(100,100,100) surface.DrawRect(0,0,230,110) surface.SetTextPos( 10, 5 ) surface.SetFont("MyFont1") surface.SetTextColor(255,255,255,255) if(string.len(v:Nick())) > 13 then surface.DrawText("Name:"..string.sub(v:Nick(),1,13).."...") else surface.DrawText("Name:"..(v:Nick())) end surface.SetTextPos( 10, 25 ) surface.DrawText("Money:"..v:getDarkRPVar( "money")) end -- Adds the gray background panel to the notification NotifyPanel:AddItem( bg ) end -- That should disable all panels if the notification is visible so that the player can't open more than one notification -- at the same time if IsValid(bg) then if bg:IsVisible() then pmPanel:SetDisabled(true) elseif not IsVisible(bg) then pmPanel:SetDisabled(false) end end end) end [/CODE] [video]https://youtu.be/NvxY8OXNrh0[/video]
*bump* Edit: -Changed the title to clearify the question and because it was misleading (I suppose it needs some time to be displayed correctly. The title should be "I need help with derma".) -Changed some code
I'll be friendly... No one is going to read that messy code you posted. No indentation, no comments besides weird separator lines, it's practically unreadable. At the absolute very least, give it proper indentation - many text editors can even do it for you. As for your problem, you should demonstrate it - if pictures don't convey the problem (which I think they don't), then make a video. In general, the best way to describe a problem is: I want to get [xxx] What I actually get is [xxx]
[QUOTE=Neat-Nit;50016438]I'll be friendly... No one is going to read that messy code you posted. No indentation, no comments besides weird separator lines, it's practically unreadable. At the absolute very least, give it proper indentation - many text editors can even do it for you. As for your problem, you should demonstrate it - if pictures don't convey the problem (which I think they don't), then make a video. In general, the best way to describe a problem is: I want to get [xxx] What I actually get is [xxx][/QUOTE] Thanks for being friendly :) I added comments to everything in my code and a video that is showing the issue.
*bump* Can no one helpe me? :saddowns:
I'm kind of in a hurry so I don't have time to read the code but I did see the video. Why don't you make it so when you click on a player, first it would remove the old panel and only then create the new one? By the way the code is still horrible... search on Google for "code indentation".
[QUOTE=Neat-Nit;50020498]I'm kind of in a hurry so I don't have time to read the code but I did see the video. Why don't you make it so when you click on a player, first it would remove the old panel and only then create the new one? By the way the code is still horrible... search on Google for "code indentation".[/QUOTE] I just discovered that sublime can reindent code automatically :smile: I think the code looks a little bit better now.
Sorry, you need to Log In to post a reply to this thread.