Hi. I'd like to know how to fill up a derma panel with other derma panels. What I mean:
https://files.facepunch.com/forum/upload/133929/45538a82-5f17-411e-8e22-6178d7ae05b5/smthlikedat.png
I'd like to know a good way to fill up the grey panel with the squares. I could just make every single one by hand but I'd like to learn a more effective way. I was thinking about a for loop but I don't know how to create a panel that has a different name for every iteration of the loop (because I'd like to adress them as seperate panels later)
Tried something like this but it didn't work:
for i=0, 10 do
test.i = vgui.Create( "DPanel")
end
Also these squares will count as "slots" - I want to make them functional
(I want to put dragabble icons in these slots)
Here's my code if it helps:
local ply = LocalPlayer()
local selectedBox = 1
local singlePopup = true
function mapping(xmin,xmax,xminout,xmaxout,xmap)
return (xmap - xmin) * (xmaxout - xminout) / (xmax - xmin) + xminout
end
function xmapping(xyz)
return mapping(1,2000,1,ScrW(),xyz)
end
function ymapping(xyz)
return mapping(1,2000,1,ScrH(),xyz)
end
function WcisnieciePrzycisku(ply,key)
if key == KEY_F1 and singlePopup == true then
singlePopup = false
NiechSieStanaPanele(ply)
end
end
function NiechSieStanaPanele(ply)
FirstPanel = vgui.Create( "DPanel")
FirstPanel:SetPos(xmapping(98),ymapping(170))
FirstPanel:SetSize(xmapping(1790),ymapping(1680))
FirstPanel:SetBackgroundColor( Color(200,200,200,240))
SecondPanel = vgui.Create( "DPanel")
SecondPanel:SetPos(xmapping(110),ymapping(190))
SecondPanel:SetSize(xmapping(1765),ymapping(1640))
SecondPanel:SetBackgroundColor( Color(230,230,230,240))
ThirdPanel = vgui.Create( "DPanel")
ThirdPanel:SetPos(xmapping(124),ymapping(215))
ThirdPanel:SetSize(xmapping(500),ymapping(1583))
ThirdPanel:SetBackgroundColor( Color(100,100,100,255))
timer.Simple(1, function()
FirstPanel:Remove()
SecondPanel:Remove()
ThirdPanel:Remove()
singlePopup = true
end)
end
hook.Add( "PlayerButtonUp", "CiskPrzycisk", WcisnieciePrzycisku )
Any help appreciated.
There are a few ways to go about handling something like this, depending on how dynamic this panel is.
this is a quick thing i wrote that should do something similar to what you want. it should create 30 panels size 32x32 in a 3x10 grid spaced 8 units way from each other.
local pos_x, pos_y = 0, 0
local subpanels = {}
local col = Color( 200, 200, 200, 240 )
local space = 8
for i = 0, 30 do
local p = vgui.Create( "DPanel" )
p:SetSize( 32, 32 )
p:SetPos( pos_x, pos_y )
p:SetBackgroundColor( col )
pos_x = pos_x + space
if pos_x > 3 * space then
pos_x = 0
pos_y = pos_y + space
end
table.insert( subpanels, p )
end
Exactly what I needed, thanks.
I've ran into another problem. I tried removing all panels after creating them with for k,v loop:
for k,v in pairs(subpanels) do
v:Remove()
end
I printed out all the subpanels after their first creation:
1 = Panel: [name:DPanel][class:Panel][87,113,70,70]
2 = Panel: [name:DPanel][class:Panel][157,113,70,70]
3 = Panel: [name:DPanel][class:Panel][227,113,70,70]
4 = Panel: [name:DPanel][class:Panel][297,113,70,70]
5 = Panel: [name:DPanel][class:Panel][367,113,70,70]
6 = Panel: [name:DPanel][class:Panel][87,183,70,70]
7 = Panel: [name:DPanel][class:Panel][157,183,70,70]
8 = Panel: [name:DPanel][class:Panel][227,183,70,70]
9 = Panel: [name:DPanel][class:Panel][297,183,70,70]
10 = Panel: [name:DPanel][class:Panel][367,183,70,70]
11 = Panel: [name:DPanel][class:Panel][87,253,70,70]
12 = Panel: [name:DPanel][class:Panel][157,253,70,70]
13 = Panel: [name:DPanel][class:Panel][227,253,70,70]
14 = Panel: [name:DPanel][class:Panel][297,253,70,70]
15 = Panel: [name:DPanel][class:Panel][367,253,70,70]
16 = Panel: [name:DPanel][class:Panel][87,323,70,70]
17 = Panel: [name:DPanel][class:Panel][157,323,70,70]
18 = Panel: [name:DPanel][class:Panel][227,323,70,70]
19 = Panel: [name:DPanel][class:Panel][297,323,70,70]
20 = Panel: [name:DPanel][class:Panel][367,323,70,70]
21 = Panel: [name:DPanel][class:Panel][87,393,70,70]
22 = Panel: [name:DPanel][class:Panel][157,393,70,70]
23 = Panel: [name:DPanel][class:Panel][227,393,70,70]
24 = Panel: [name:DPanel][class:Panel][297,393,70,70]
25 = Panel: [name:DPanel][class:Panel][367,393,70,70]
Everything went well, but after creating it again I noticed this:
1 = [NULL Panel]
2 = [NULL Panel]
3 = [NULL Panel]
4 = [NULL Panel]
5 = [NULL Panel]
6 = [NULL Panel]
7 = [NULL Panel]
8 = [NULL Panel]
9 = [NULL Panel]
10 = [NULL Panel]
11 = [NULL Panel]
12 = [NULL Panel]
13 = [NULL Panel]
14 = [NULL Panel]
15 = [NULL Panel]
16 = [NULL Panel]
17 = [NULL Panel]
18 = [NULL Panel]
19 = [NULL Panel]
20 = [NULL Panel]
21 = [NULL Panel]
22 = [NULL Panel]
23 = [NULL Panel]
24 = [NULL Panel]
25 = [NULL Panel]
26 = Panel: [name:DPanel][class:Panel][87,113,70,70]
27 = Panel: [name:DPanel][class:Panel][157,113,70,70]
28 = Panel: [name:DPanel][class:Panel][227,113,70,70]
29 = Panel: [name:DPanel][class:Panel][297,113,70,70]
30 = Panel: [name:DPanel][class:Panel][367,113,70,70]
31 = Panel: [name:DPanel][class:Panel][87,183,70,70]
32 = Panel: [name:DPanel][class:Panel][157,183,70,70]
33 = Panel: [name:DPanel][class:Panel][227,183,70,70]
34 = Panel: [name:DPanel][class:Panel][297,183,70,70]
35 = Panel: [name:DPanel][class:Panel][367,183,70,70]
36 = Panel: [name:DPanel][class:Panel][87,253,70,70]
37 = Panel: [name:DPanel][class:Panel][157,253,70,70]
38 = Panel: [name:DPanel][class:Panel][227,253,70,70]
39 = Panel: [name:DPanel][class:Panel][297,253,70,70]
40 = Panel: [name:DPanel][class:Panel][367,253,70,70]
41 = Panel: [name:DPanel][class:Panel][87,323,70,70]
42 = Panel: [name:DPanel][class:Panel][157,323,70,70]
43 = Panel: [name:DPanel][class:Panel][227,323,70,70]
44 = Panel: [name:DPanel][class:Panel][297,323,70,70]
45 = Panel: [name:DPanel][class:Panel][367,323,70,70]
46 = Panel: [name:DPanel][class:Panel][87,393,70,70]
47 = Panel: [name:DPanel][class:Panel][157,393,70,70]
48 = Panel: [name:DPanel][class:Panel][227,393,70,70]
49 = Panel: [name:DPanel][class:Panel][297,393,70,70]
50 = Panel: [name:DPanel][class:Panel][367,393,70,70]
Now there are null panels there.
1.Can this lead to server lag?
2.How can I fix it? - As I said, I want to address each panel separately, but now they change their id each
call so it makes it difficult.
Whatever table you use to store the panels in, recreate it before you start adding new panels into it ( self.panels = {} or smth ), assuming that you only ever fully empty the list, not remove 1-2 (for example) panels.
If you empty the list only partially in at least one case, you will need to manually remove the elements from the list, and there are a few approaches to doing so.
Sorry, you need to Log In to post a reply to this thread.