-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmainmenu.lua
More file actions
396 lines (313 loc) · 10.3 KB
/
Copy pathmainmenu.lua
File metadata and controls
396 lines (313 loc) · 10.3 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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
local R=function(a,b,c,d,e) return function() return RunConsoleCommand(a,b,c,d,e) end end
local M=function(x) return function() return RunGameUICommand(x) end end
local NOT=function(f) return function(...) return not f(...) end end
local mainmenu = {
{""},
{"resume_game", gui.HideGameUI, "icon16/joystick.png" ,show=IsInGame},
{"disconnect", M"disconnect", "icon16/disconnect.png" ,show=IsInGame},
{"reconnect", R"retry", "icon16/connect.png" ,show=WasInGame},
{"server_players", M"openplayerlistdialog", "icon16/group_delete.png" ,show=IsInGame},
{"",show=WasInGame},
--{"new_game", M"opencreatemultiplayergamedialog", "icon16/server.png" },
{"legacy_browser", M"openserverbrowser", "icon16/world.png" },
{"server_list", R"lua_openserverbrowser", "icon16/world.png" },
{""},
{"options", M"openoptionsdialog", "icon16/wrench.png" },
{"GameUI_Console", R"showconsole", "icon16/application_xp_terminal.png",
show=function() return IsDeveloper() and not gui.IsConsoleVisible() end},
{""},
{"GameUI_Quit", M"quitnoconfirm", "icon16/door.png" },
{""},
}
-- addons
-- games
-- language
-- settings
-- lua cache?
-- workshop search
-- con filter out
-- console open
-- devmode quicktoggle
-- favorites and their status on main menu?
-- browser? / overlay?
-- client.vdf browser/editor
--
local menulist_wrapper = vgui.Create('DPanelList',nil,'menulist_wrapper')
local isours
if pnlMainMenu and pnlMainMenu:IsValid() then pnlMainMenu:Remove() end
_G.pnlMainMenu = menulist_wrapper
menulist_wrapper:EnableVerticalScrollbar(true)
menulist_wrapper:SetWide(350)
menulist_wrapper:Dock(LEFT)
menulist_wrapper:DockMargin(32,32,32,32)
local div_hack = vgui.Create'EditablePanel'
div_hack:SetTall(52)
div_hack:SetZPos(-20000)
menulist_wrapper:AddItem(div_hack)
local lastscroll = menulist_wrapper.VBar:GetScroll()
local addonslist
function CreateAddons()
if addonslist and addonslist:IsValid() then addonslist:Remove() addonslist=nil end
addonslist = vgui.Create('DForm',menulist_wrapper,'addonslist')
addonslist:Dock(TOP)
addonslist:SetName"#manage_addons"
addonslist:SetExpanded(false)
addonslist:SetCookieName"addonslist"
addonslist:LoadCookies()
menulist_wrapper:AddItem(addonslist)
menulist_wrapper:InvalidateLayout(true)
addonslist:InvalidateLayout(true)
addonslist.Header:SetIcon 'icon16/plugin.png'
local btn = vgui.Create("DButton",addonslist,'addonslist_button')
addonslist:AddItem(btn)
btn:SetText("#addons.enableall")
btn:SetIcon 'icon16/add.png'
function btn.DoClick(btn)
for k,v in next,engine.GetAddons() do
steamworks.SetShouldMountAddon(v.wsid or v.file,true)
end
isours = true
steamworks.ApplyAddons()
isours = true
CreateMenu()
end
local btn = vgui.Create("DButton",addonslist,'addonslist_button')
addonslist:AddItem(btn)
btn:SetText("#addons.disableall")
btn:SetIcon 'icon16/delete.png'
function btn.DoClick(btn)
for k,v in next,engine.GetAddons() do
steamworks.SetShouldMountAddon(v.wsid or v.file,false)
end
isours = true
steamworks.ApplyAddons()
isours = true
CreateMenu()
end
local btn = vgui.Create("DButton",addonslist,'addonslist_button')
addonslist:AddItem(btn)
btn:SetText("#addons.uninstallall")
btn:SetIcon 'icon16/stop.png'
function btn.DoClick(btn)
for k,v in next,engine.GetAddons() do
if v.wsid then
print("Unsubscribe",v.wsid)
steamworks.Unsubscribe(v.wsid)
end
end
isours = true steamworks.ApplyAddons() isours = true
CreateMenu()
end
local function AddButton(data,title,mounted,downloaded,wsid,filepath)
local btn = vgui.Create("DCheckBoxLabel",addonslist,'addonslist_button')
addonslist:AddItem(btn)
btn:SetText(title or filepath)
btn:SetChecked(mounted)
btn:SetBright(true)
btn:SetDisabled(not downloaded)
btn:SizeToContents()
function btn:OnChange(val)
print("mount",filepath,val)
local old = steamworks.ShouldMountAddon(wsid)
steamworks.SetShouldMountAddon(wsid,val)
isours = true steamworks.ApplyAddons() isours = true
local new = steamworks.ShouldMountAddon(wsid)
btn:SetChecked(new)
if old==new then
print("Warning: ","could not toggle",filepath)
end
end
btn.Label.DoRightClick=function()
local m =DermaMenu()
m:AddOption("#addon.unsubscribe",function()
print("Unsubscribe",wsid)
steamworks.Unsubscribe(wsid)
end)
m:AddOption("#copy",function()
SetClipboardText('http://steamcommunity.com/sharedfiles/filedetails/?id='..wsid)
end)
m:Open()
end
btn:InvalidateLayout(true)
--btn:Dock(TOP)
end
local t=engine.GetAddons()
table.sort(t,function(a,b)
if a.mounted==b.mounted then
if a.wsid and b.wsid then
return a.wsid<b.wsid
elseif a.title and b.title then
return a.title<b.title
else
return a.file<b.file
end
else
return (a.mounted and 0 or 1)<(b.mounted and 0 or 1)
end
end)
for _,data in next,t do
AddButton(data,data.title,data.mounted,data.downloaded,data.wsid,data.file)
end
menulist_wrapper.VBar:SetScroll(lastscroll)
end
local settingslist
function CreateExtraSettings()
if settingslist and settingslist:IsValid() then settingslist:Remove() settingslist=nil end
settingslist = vgui.Create('DForm',menulist_wrapper,'settingslist')
settingslist:Dock(TOP)
settingslist:SetName"Extra Settings"
settingslist:SetExpanded(false)
settingslist.Header:SetIcon 'icon16/cog.png'
settingslist:SetCookieName"settingslist"
settingslist:LoadCookies()
menulist_wrapper:AddItem(settingslist)
menulist_wrapper:InvalidateLayout(true)
settingslist:InvalidateLayout(true)
local function AddCheck(txt,cvar)
local
c = vgui.Create( 'DCheckBoxLabel',settingslist,'settingslist_check')
settingslist:AddItem(c)
c:SetText( txt )
c:SetConVar(cvar)
c:SetBright(true)
c:SizeToContents()
c:InvalidateLayout(true)
return c
end
local x = vgui.Create( 'DLabel',settingslist)
x:SetText"Loading Screen"
settingslist:AddItem(x)
AddCheck( "Enable","lua_loading_screen")
AddCheck( "Transparency","lua_loading_screen_transp")
AddCheck( "Try hiding","lua_loading_screen_hide")
local x = vgui.Create( 'DLabel',settingslist)
x:SetText"Download / Upload"
settingslist:AddItem(x)
AddCheck( "Allow DL","cl_allowdownload")
AddCheck( "Allow UL","cl_allowupload")
AddCheck( "FastDL debug","download_debug")
local x = vgui.Create( 'DLabel',settingslist)
x:SetText" "
settingslist:AddItem(x)
end
local gameslist
function CreateGames()
if gameslist and gameslist:IsValid() then gameslist:Remove() gameslist=nil end
gameslist = vgui.Create('DForm',menulist_wrapper,'gameslist')
gameslist:Dock(TOP)
gameslist:SetName"#mounted_games"
gameslist:SetExpanded(false)
gameslist.Header:SetIcon 'icon16/joystick.png'
gameslist:SetCookieName"gameslist"
gameslist:LoadCookies()
menulist_wrapper:AddItem(gameslist)
menulist_wrapper:InvalidateLayout(true)
gameslist:InvalidateLayout(true)
local function AddButton(data,title,mounted,owned,installed,depot)
local btn = vgui.Create("DCheckBoxLabel",gameslist,'gameslist_button')
gameslist:AddItem(btn)
btn:SetText(title)
btn:SetChecked(mounted)
btn:SetBright(true)
btn:SetDisabled(not owned or not installed)
btn:SizeToContents()
function btn:OnChange(val)
engine.SetMounted(depot,val)
btn:SetChecked(IsMounted(depot))
end
btn:InvalidateLayout(true)
--btn:Dock(TOP)
end
local t=engine.GetGames()
table.sort(t,function(a,b)
if a.mounted==b.mounted then
if a.mounted then
return a.depot<b.depot
else
return ((a.installed and a.owned) and 0 or 1)<((b.installed and b.owned) and 0 or 1)
end
else
return (a.mounted and 0 or 1)<(b.mounted and 0 or 1)
end
end)
for _,data in next,t do
AddButton(data,data.title,data.mounted,data.owned,data.installed,data.depot)
end
CreateAddons()
end
local menulist
local creating
local function _CreateMenu()
creating = false
lastscroll = menulist_wrapper.VBar:GetScroll()
if menulist and menulist:IsValid() then menulist:Remove() menulist=nil end
menulist = vgui.Create('DForm',menulist_wrapper,'menulist')
menulist:Dock(TOP)
menulist:SetName""
menulist.Header:SetIcon 'icon16/house.png'
menulist:SetCookieName"menulist"
menulist:LoadCookies()
menulist_wrapper:AddItem(menulist)
menulist_wrapper:InvalidateLayout(true)
menulist:InvalidateLayout(true)
local function AddButton(data,text,menucmd,icon)
if data.show and not data:show() then return end
if text=="" and not menucmd then
local div = vgui.Create'EditablePanel'
div:SetTall(1)
menulist:AddItem(div)
return
end
local btn = vgui.Create("DButton",menulist,'menulist_button')
menulist:AddItem(btn)
btn:SetText("#"..text)
btn:SetFont"closecaption_normal"
btn:SizeToContents()
btn.DoClick=function()
menucmd()
btn:SetSelected(false)
end
if icon and #icon>0 then
btn:SetImage(icon)
end
btn:InvalidateLayout(true)
btn:SetTextInset( 16+ 16, 0 )
btn:SetContentAlignment(4)
local tall = btn:GetTall()+4
tall=tall<32 and 32 or tall
btn:SetTall(tall)
--btn:Dock(TOP)
end
for _,data in next,mainmenu do
AddButton(data,data[1],data[2],data[3])
end
CreateExtraSettings()
CreateGames()
menulist:InvalidateLayout(true)
end
function CreateMenu()
if creating then return end
creating = true
timer.Simple(0.2,function()
_CreateMenu()
end)
end
--CreateMenu()
hook.Add( "GameContentsChanged", "CreateMenu", function(mount,addon)
if mount then return end
-- EEK
if not mount and not addon then return end
if isours then isours = false return end
CreateMenu()
end )
hook.Add( "InGame", "CreateMenu", function(is)
CreateMenu()
end )
hook.Add( "ConsoleVisible", "CreateMenu", function(is)
if IsDeveloper() then
CreateMenu()
end
end )
hook.Add( "LoadingStatus", "CreateMenu", function(status)
--CreateMenu()
end )