-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrintFrame.lua
More file actions
252 lines (229 loc) · 8.49 KB
/
PrintFrame.lua
File metadata and controls
252 lines (229 loc) · 8.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
function PrintFrame(IN,depth,maxdepth,StartPathName)
local SK = ""
local CPath = StartPathName .. "."
local Contents = vgui.Create("DFrame")
local Tabs = vgui.Create("DPropertySheet",Contents)
Tabs:Dock(FILL)
local Tab1 = vgui.Create("DPanel")
Tabs:AddSheet("Print",Tab1,"icon16/application_view_list.png",false,false,"Your query.")
Tab1:Dock(FILL)
Contents:Center()
Contents:SetSize(1000,500)
Contents:SetTitle("Contents")
Contents:MakePopup()
Contents:SetSkin(SK)
local Tree = vgui.Create("DTree",Tab1)
Tree:Dock(FILL)
Tree:SetLineHeight(16)
Tree:SetDrawBackground(false)
local Lenmax = maxdepth or 1
local function DoNodePopulate(From,IN,depth,maxdepth,StartPathName)
for k,v in pairs(IN) do
if Lenmax > 0 then
local Bulletin = From:AddNode(k ..":" .. tostring(v))
Bulletin.BType = type(v)
Bulletin.PathN = StartPathName .. "." .. k
Bulletin.PureN = k
Bulletin.PureV = v
Bulletin:SetSkin(SK)
if istable(v) then Bulletin:SetIcon("icon16/application_view_list.png") end
if type(v)=="string" then Bulletin:SetIcon("icon16/font.png") end
if IsColor(v) then Bulletin:SetIcon("icon16/color_wheel.png")
Bulletin.BType = "color"
end
if type(v)=="function" then Bulletin:SetIcon("icon16/cog_go.png") end
if type(v)=="number" then Bulletin:SetIcon("icon16/calendar_view_day.png") end
if type(v)=="userdata" then Bulletin:SetIcon("icon16/database_gear.png") end
if type(v)=="boolean" then Bulletin:SetIcon("icon16/contrast_high.png") end
if type(v)=="nil" then Bulletin:SetIcon("icon16/cross.png") end -- should not happen
if type(v)=="Vector" then Bulletin:SetIcon("icon16/arrow_out.png") end
if type(v)=="Angle" then Bulletin:SetIcon("icon16/arrow_rotate_anticlockwise.png") end
if type(v)=="IMaterial" then Bulletin:SetIcon("icon16/image.png") end
if type(v) == "table" then
depth=depth+1
Lenmax=Lenmax-1
DoNodePopulate(Bulletin,v,depth,maxdepth,Bulletin.PathN)
end
function Bulletin:Paint(w,h)
end
end
end
end
local Interaction = vgui.Create("DPanel",Tab1)
Interaction:Dock(BOTTOM)
Interaction:SetSize(1000,100)
Interaction:SetSkin(SK)
local MaterialPreview = vgui.Create("DPanel",Interaction)
MaterialPreview:SetSize(75,75)
MaterialPreview:SetPos(400,12)
MaterialPreview.Color=Color(0,0,0,0)
MaterialPreview.DispType="Color"
MaterialPreview.Mat = Material( "gui/alpha_grid.png", "noclamp smooth" )
function MaterialPreview:Paint(w,h)
local r,g,b,a = self.Color:Unpack()
if self.DispType=="Color" then
local MT = Material( "gui/alpha_grid.png", "noclamp smooth" )
surface.SetDrawColor(255,255,255,255)
surface.SetMaterial(MT)
surface.DrawTexturedRectUV(0,0,w,h,-0.125,-0.125,0.125,0.125)
end
if self.DispType=="Mat" then
local MT = self.Mat or Material( "gui/alpha_grid.png", "noclamp smooth" )
surface.SetDrawColor(255,255,255,255)
surface.SetMaterial(MT)
surface.DrawTexturedRectUV(0,0,w,h,0,0,1,1)
end
if self.DispType=="Color" then
surface.SetDrawColor(r or 0,g or 0,b or 0,a or 0)
surface.DrawRect(0,0,w,h)
end
end
local InfoI=vgui.Create("DLabel",Interaction)
InfoI:SetPos(5,5)
InfoI:SetSize(490,90)
InfoI:SetText("Welcome to the contents manager. Select a node to start.")
InfoI:SetContentAlignment(7)
InfoI:SetSkin(SK)
local ChangeValue = vgui.Create("DButton",Interaction)
ChangeValue:SetPos(1000-200,5)
ChangeValue:SetSize(190,40)
ChangeValue:SetSkin(SK)
ChangeValue:SetText("<unsupported>")
function ChangeValue:DoClick() end
local ChangeSkin = vgui.Create("DComboBox",Interaction)
ChangeSkin:SetSkin(SK)
ChangeSkin:SetPos(5,100-20)
ChangeSkin:SetSize(95,20)
ChangeSkin:SetValue("Set Skin:")
for k,v in pairs(derma.SkinList) do
ChangeSkin:AddChoice(k)
end
function ChangeSkin:OnSelect(ID,Val)
SK = Val
Contents:SetSkin(SK)
Tree:SetSkin(SK)
ChangeSkin:SetSkin(SK)
ChangeValue:SetSkin(SK)
Tab1:SetSkin(SK)
end
function Tree:OnNodeSelected(pnl)
local TXT = Tree:GetSelectedItem():GetText()
local NM = Tree:GetSelectedItem().PathN
local VL = string.split(TXT,":")[2]
if Tree:GetSelectedItem().BType == "color" or Tree:GetSelectedItem().BType == "IMaterial" then
MaterialPreview:Show()
else
MaterialPreview:Hide()
end
if Tree:GetSelectedItem().BType == "boolean" or Tree:GetSelectedItem().BType == "number" or Tree:GetSelectedItem().BType == "string" or Tree:GetSelectedItem().BType == "color" then
ChangeValue:SetText("Change Value:")
function ChangeValue:DoClick()
local ChangValPopup = vgui.Create("DFrame")
ChangValPopup:SetSize(200,100)
ChangValPopup:Center()
ChangValPopup:MakePopup()
ChangValPopup:SetTitle("Change Value")
ChangValPopup:SetSkin(SK)
if Tree:GetSelectedItem().BType == "boolean" then
ChangValPopup:SetSize(200,100)
local CVPnl = vgui.Create("DCheckBoxLabel",ChangValPopup)
CVPnl:Center()
CVPnl:SetText(string.split(TXT,":")[1])
CVPnl:SetChecked(tobool(VL))
CVPnl:SetSkin(SK)
function CVPnl:OnChange(bool)
end -- actually make it do stuff when i can guarantee it does so reliably
end
if Tree:GetSelectedItem().BType == "number" then
ChangValPopup:SetSize(200,100)
local CVPnl = vgui.Create("DNumberWang",ChangValPopup)
CVPnl:Center()
CVPnl:SetValue(VL)
CVPnl:SetSkin(SK)
local OK = vgui.Create("DButton",ChangValPopup)
OK:Dock(BOTTOM)
OK:SetText("Ok")
function OK:DoClick()
ChangValPopup:Close()
end
end
if Tree:GetSelectedItem().BType == "string" then
ChangValPopup:SetSize(200,100)
local CVPnl = vgui.Create("DTextEntry",ChangValPopup)
CVPnl:SetSkin(SK)
CVPnl:SetWide(ChangValPopup:GetWide()-5)
CVPnl:Center()
CVPnl:SetText(VL)
local OK = vgui.Create("DButton",ChangValPopup)
OK:Dock(BOTTOM)
OK:SetText("Ok")
function OK:DoClick()
ChangValPopup:Close()
end
end
if Tree:GetSelectedItem().BType == "color" then
ChangValPopup:SetSize(300,300)
local CVPnl = vgui.Create("DColorMixer",ChangValPopup)
CVPnl:Dock(FILL)
CVPnl:SetColor(string.ToColor(VL))
CVPnl:SetSkin(SK)
local OK = vgui.Create("DButton",ChangValPopup)
OK:Dock(BOTTOM)
OK:SetText("Ok")
function OK:DoClick()
ChangValPopup:Close()
end
end
end
else
ChangeValue:SetText("<unsupported>")
function ChangeValue:DoClick() end
end
if Tree:GetSelectedItem().BType == "table" then
InfoI:SetText(NM.."\nType:".. Tree:GetSelectedItem().BType or "No item selected.")
else
InfoI:SetText(NM.."\nType:".. Tree:GetSelectedItem().BType .."(".. VL ..")" or "No item selected.")
if Tree:GetSelectedItem().BType == "color" then
MaterialPreview.DispType = "Color"
MaterialPreview.Color = string.ToColor(VL)
end
if Tree:GetSelectedItem().BType == "IMaterial" then
MaterialPreview.DispType = "Mat"
MaterialPreview.Mat = Tree:GetSelectedItem().PureV
end
end
function pnl:DoRightClick()
local RCMenu=DermaMenu(false,Contents)
RCMenu:SetPos(500,500-100)
RCMenu:SetMaxHeight(90)
RCMenu:AddOption("Copy Name (".. pnl.PureN ..")" ,function() SetClipboardText(pnl.PureN) end)
RCMenu:AddOption("Copy Path (".. NM ..")" ,function() SetClipboardText(NM) end)
RCMenu:AddOption("Copy Value (".. VL ..")" ,function() SetClipboardText(VL) end)
if Tree:GetSelectedItem().BType == "function" then
RCMenu:AddSpacer()
RCMenu:AddOption("copy function call as print",function() SetClipboardText("print(".. NM .."())") end)
RCMenu:AddOption("copy function call as printtable",function() SetClipboardText("PrintTable(".. NM .."())") end)
end
end
end
DoNodePopulate(Tree,IN,depth,maxdepth,StartPathName)
end
function TestPrintFrame()
local TestTable = {}
TestTable["Test Values"]={
number=0,
string="string",
vec=Vector(0,0,0),
col1=Color(0,255,0,127),
ang=Angle(0,0,0),
quat=Quaternion(0,0,0,0),
func=function()end,
bool=false,
table={string2="The Fitnessgram pacer test is a multistage aerobic capacity test that progressively",
string3="gets more difficult as it continues."
},
MaterialPreviewBaseTexture=Material( "gui/alpha_grid.png", "noclamp smooth" ),
E=Material("gui/e.png","noclamp nosmooth")
}
PrintFrame(TestTable,0,250,"TestTable")
end