· 8 years ago · May 22, 2018, 01:42 AM
1--[[
2 © 2013 CloudSixteen.com do not share, re-distribute or modify
3 without permission of its author (kurozael@gmail.com).
4--]]
5--[[
6 © Songbird aka Alko - do not re-distribute without permission of its author (ael9000 gmail.com).
7--]]
8
9local Clockwork = Clockwork;
10local pairs = pairs;
11local RunConsoleCommand = RunConsoleCommand;
12local SysTime = SysTime;
13local ScrH = ScrH;
14local ScrW = ScrW;
15local table = table;
16local string = string;
17local vgui = vgui;
18local math = math;
19
20local PANEL = {};
21
22-- Called when the panel is initialized.
23function PANEL:Init()
24 if (!Clockwork.theme:Call("PreCharacterMenuInit", self)) then
25 local smallTextFont = Clockwork.option:GetFont("menu_text_small");
26 local tinyTextFont = Clockwork.option:GetFont("menu_text_tiny");
27 local hugeTextFont = Clockwork.option:GetFont("menu_text_huge");
28 local scrH = ScrH();
29 local scrW = ScrW();
30
31 self:SetPos(0, 0);
32 self:SetSize(scrW, scrH);
33 self:SetDrawOnTop(false);
34 self:SetPaintBackground(false);
35 self:SetMouseInputEnabled(true);
36
37 self.titleLabel = vgui.Create("cwLabelButton", self);
38 self.titleLabel:SetDisabled(true);
39 self.titleLabel:SetFont(hugeTextFont);
40 self.titleLabel:SetText(string.upper(Schema:GetName()));
41
42 local schemaLogo = Clockwork.option:GetKey("schema_logo");
43
44 self.subLabel = vgui.Create("cwLabelButton", self);
45 self.subLabel:SetDisabled(true);
46 self.subLabel:SetFont(smallTextFont);
47 self.subLabel:SetText(string.upper(Schema:GetDescription()));
48 self.subLabel:SizeToContents();
49
50 if (schemaLogo == "") then
51 self.titleLabel:SetVisible(true);
52 self.titleLabel:SizeToContents();
53 self.titleLabel:SetPos((scrW / 2) - (self.titleLabel:GetWide() / 2), scrH * 0.3);
54 self.subLabel:SetPos((scrW / 2) - (self.subLabel:GetWide() / 2), self.titleLabel.y + self.titleLabel:GetTall() + 8);
55 else
56 self.titleLabel:SetVisible(false);
57 self.titleLabel:SetSize(512, 256);
58 self.titleLabel:SetPos((scrW / 2) - (self.titleLabel:GetWide() / 2), scrH * 0.3 - 128);
59 self.subLabel:SetPos(self.titleLabel.x + (self.titleLabel:GetWide() / 2) - (self.subLabel:GetWide() / 2), self.titleLabel.y + self.titleLabel:GetTall() + 8);
60 end;
61
62 self.authorLabel = vgui.Create("cwLabelButton", self);
63 self.authorLabel:SetDisabled(true);
64 self.authorLabel:SetFont(tinyTextFont);
65 self.authorLabel:SetText("DEVELOPED BY "..string.upper(Schema:GetAuthor()));
66 self.authorLabel:SizeToContents();
67 self.authorLabel:SetPos(self.subLabel.x + (self.subLabel:GetWide() - self.authorLabel:GetWide()), self.subLabel.y + self.subLabel:GetTall() + 4);
68
69 self.createButton = vgui.Create("cwLabelButton", self);
70 self.createButton:SetFont(smallTextFont);
71 self.createButton:SetText("NEW CHARACTER");
72 self.createButton:FadeIn(0.5);
73 self.createButton:SetCallback(function(panel)
74 if (table.Count(Clockwork.character:GetAll()) >= Clockwork.player:GetMaximumCharacters()) then
75 return Clockwork.character:SetFault("You cannot create any more characters!");
76 end;
77
78 Clockwork.character:ResetCreationInfo();
79 Clockwork.character:OpenNextCreationPanel();
80 end);
81 self.createButton:SizeToContents();
82 self.createButton:SetMouseInputEnabled(true);
83 self.createButton:SetPos(ScrW() * 0.1, ScrH() * 0.6);
84
85 self.loadButton = vgui.Create("cwLabelButton", self);
86 self.loadButton:SetFont(smallTextFont);
87 self.loadButton:SetText("LOAD CHARACTER");
88 self.loadButton:FadeIn(0.5);
89 self.loadButton:SetCallback(function(panel)
90 self:OpenPanel("cwCharacterList", nil, function(panel)
91 Clockwork.character:RefreshPanelList();
92 end);
93 end);
94 self.loadButton:SizeToContents();
95 self.loadButton:SetMouseInputEnabled(true);
96 self.loadButton:SetPos(ScrW() * 0.1, ScrH() * 0.65);
97
98 self.aboutButton = vgui.Create("cwLabelButton", self);
99 self.aboutButton:SetFont(smallTextFont);
100 self.aboutButton:SetText("CLOUDSIXTEEN.COM");
101 self.aboutButton:SetAlpha(0);
102 self.aboutButton:FadeIn(1);
103 self.aboutButton:SetCallback(function(panel)
104 gui.OpenURL("http://cloudsixteen.com")
105 end);
106 self.aboutButton:SizeToContents();
107 self.aboutButton:SetMouseInputEnabled(true);
108 self.aboutButton:SetPos((ScrW() * 0.1), ScrH() * 0.7);
109
110 self.disconnectButton = vgui.Create("cwLabelButton", self);
111 self.disconnectButton:SetFont(smallTextFont);
112 self.disconnectButton:SetText("DISCONNECT");
113 self.disconnectButton:FadeIn(0.5);
114 self.disconnectButton:SetCallback(function(panel)
115 if (Clockwork.Client:HasInitialized() and !Clockwork.character:IsMenuReset()) then
116 Clockwork.character:SetPanelMainMenu();
117 Clockwork.character:SetPanelOpen(false);
118 else
119 RunConsoleCommand("disconnect");
120 end;
121 end);
122 self.disconnectButton:SizeToContents();
123 self.disconnectButton:SetPos(ScrW() * 0.1, ScrH() * 0.75);
124 self.disconnectButton:SetMouseInputEnabled(true);
125
126 self.previousButton = vgui.Create("cwLabelButton", self);
127 self.previousButton:SetFont(tinyTextFont);
128 self.previousButton:SetText("PREVIOUS");
129 self.previousButton:SetCallback(function(panel)
130 if (!Clockwork.character:IsCreationProcessActive()) then
131 local activePanel = Clockwork.character:GetActivePanel();
132
133 if (activePanel and activePanel.OnPrevious) then
134 activePanel:OnPrevious();
135 end;
136 else
137 Clockwork.character:OpenPreviousCreationPanel()
138 end;
139 end);
140 self.previousButton:SizeToContents();
141 self.previousButton:SetMouseInputEnabled(true);
142 self.previousButton:SetPos((scrW * 0.2) - (self.previousButton:GetWide() / 2), scrH * 0.9);
143
144 self.nextButton = vgui.Create("cwLabelButton", self);
145 self.nextButton:SetFont(tinyTextFont);
146 self.nextButton:SetText("NEXT");
147 self.nextButton:SetCallback(function(panel)
148 if (!Clockwork.character:IsCreationProcessActive()) then
149 local activePanel = Clockwork.character:GetActivePanel();
150
151 if (activePanel and activePanel.OnNext) then
152 activePanel:OnNext();
153 end;
154 else
155 Clockwork.character:OpenNextCreationPanel()
156 end;
157 end);
158 self.nextButton:SizeToContents();
159 self.nextButton:SetMouseInputEnabled(true);
160 self.nextButton:SetPos((scrW * 0.8) - (self.nextButton:GetWide() / 2), scrH * 0.9);
161
162 self.cancelButton = vgui.Create("cwLabelButton", self);
163 self.cancelButton:SetFont(tinyTextFont);
164 self.cancelButton:SetText("CANCEL");
165 self.cancelButton:SetCallback(function(panel)
166 self:ReturnToMainMenu();
167 end);
168 self.cancelButton:SizeToContents();
169 self.cancelButton:SetMouseInputEnabled(true);
170 self.cancelButton:SetPos((scrW * 0.5) - (self.cancelButton:GetWide() / 2), scrH * 0.9);
171
172 self.characterModel = vgui.Create("cwCharacterModel", self);
173 self.characterModel:SetSize(512, 512);
174 self.characterModel:SetAlpha(0);
175 self.characterModel:SetModel("models/error.mdl");
176 self.createTime = SysTime();
177
178 Clockwork.theme:Call("PostCharacterMenuInit", self)
179 end;
180end;
181
182-- A function to fade in the model panel.
183function PANEL:FadeInModelPanel(model)
184 if (ScrH() < 768) then
185 return true;
186 end;
187
188 local panel = Clockwork.character:GetActivePanel();
189 local x, y = ScrW() - self.characterModel:GetWide() - 8, 16;
190
191 if (panel) then
192 x, y = panel.x + panel:GetWide() - 16, panel.y - 80;
193 end;
194
195 self.characterModel:SetPos(x, y);
196
197 if (self.characterModel:FadeIn(0.5)) then
198 self:SetModelPanelModel(model);
199 return true;
200 else
201 return false;
202 end;
203end;
204
205-- A function to fade out the model panel.
206function PANEL:FadeOutModelPanel()
207 self.characterModel:FadeOut(0.5);
208end;
209
210-- A function to set the model panel's model.
211function PANEL:SetModelPanelModel(model)
212 if (self.characterModel.currentModel != model) then
213 self.characterModel.currentModel = model;
214 self.characterModel:SetModel(model);
215 end;
216
217 local modelPanel = self.characterModel:GetModelPanel();
218 local weaponModel = Clockwork.plugin:Call(
219 "GetModelSelectWeaponModel", model
220 );
221 local sequence = Clockwork.plugin:Call(
222 "GetModelSelectSequence", modelPanel.Entity, model
223 );
224
225 if (weaponModel) then
226 self.characterModel:SetWeaponModel(weaponModel);
227 else
228 self.characterModel:SetWeaponModel(false);
229 end;
230
231 if (sequence) then
232 modelPanel.Entity:ResetSequence(sequence);
233 end;
234end;
235
236-- A function to return to the main menu.
237function PANEL:ReturnToMainMenu()
238 local panel = Clockwork.character:GetActivePanel();
239
240 if (panel) then
241 panel:FadeOut(0.5, function()
242 Clockwork.character.activePanel = nil;
243 panel:Remove();
244 self:FadeInTitle();
245 end);
246 else
247 self:FadeInTitle();
248 end;
249
250 self:FadeOutModelPanel();
251 self:FadeOutNavigation();
252end;
253
254-- A function to fade out the navigation.
255function PANEL:FadeOutNavigation()
256 self.previousButton:FadeOut(0.5);
257 self.cancelButton:FadeOut(0.5);
258 self.nextButton:FadeOut(0.5);
259end;
260
261-- A function to fade in the navigation.
262function PANEL:FadeInNavigation()
263 self.previousButton:FadeIn(0.5);
264 self.cancelButton:FadeIn(0.5);
265 self.nextButton:FadeIn(0.5);
266end;
267
268-- A function to fade out the title.
269function PANEL:FadeOutTitle()
270 self.subLabel:FadeOut(0.5);
271 self.titleLabel:FadeOut(0.5);
272 self.createButton:FadeOut(0.5)
273 self.loadButton:FadeOut(0.5)
274 self.aboutButton:FadeOut(0.5)
275 self.disconnectButton:FadeOut(0.5)
276 self.authorLabel:FadeOut(0.5);
277end;
278
279-- A function to fade in the title.
280function PANEL:FadeInTitle()
281 self.subLabel:FadeIn(0.5);
282 self.createButton:FadeIn(0.5)
283 self.loadButton:FadeIn(0.5)
284 self.aboutButton:FadeIn(0.5)
285 self.disconnectButton:FadeIn(0.5)
286 self.titleLabel:FadeIn(0.5);
287 self.authorLabel:FadeIn(0.5);
288end;
289
290-- A function to open a panel.
291function PANEL:OpenPanel(vguiName, childData, Callback)
292 if (!Clockwork.theme:Call("PreCharacterMenuOpenPanel", self, vguiName, childData, Callback)) then
293 local panel = Clockwork.character:GetActivePanel();
294
295 if (panel) then
296 panel:FadeOut(0.5, function()
297 panel:Remove(); self.childData = childData;
298
299 Clockwork.character.activePanel = vgui.Create(vguiName, self);
300 Clockwork.character.activePanel:SetAlpha(0);
301 Clockwork.character.activePanel:FadeIn(0.5);
302 Clockwork.character.activePanel:MakePopup();
303 Clockwork.character.activePanel:SetPos(ScrW() * 0.2, ScrH() * 0.275);
304
305 if (Callback) then
306 Callback(Clockwork.character.activePanel);
307 end;
308
309 if (childData) then
310 Clockwork.character.activePanel.bIsCreationProcess = true;
311 Clockwork.character:FadeInNavigation();
312 end;
313 end);
314 else
315 self.childData = childData;
316 self:FadeOutTitle();
317
318 Clockwork.character.activePanel = vgui.Create(vguiName, self);
319 Clockwork.character.activePanel:SetAlpha(0);
320 Clockwork.character.activePanel:FadeIn(0.5);
321 Clockwork.character.activePanel:MakePopup();
322 Clockwork.character.activePanel:SetPos(ScrW() * 0.2, ScrH() * 0.275);
323
324 if (Callback) then
325 Callback(Clockwork.character.activePanel);
326 end;
327
328 if (childData) then
329 Clockwork.character.activePanel.bIsCreationProcess = true;
330 Clockwork.character:FadeInNavigation();
331 end;
332 end;
333
334 --[[ Fade out the model panel, we probably don't need it now! --]]
335 self:FadeOutModelPanel();
336
337 Clockwork.theme:Call("PostCharacterMenuOpenPanel", self);
338 end;
339end;
340
341-- Called when the panel is painted.
342function PANEL:Paint(w, h)
343
344 if (!Clockwork.theme:Call("PreCharacterMenuPaint", self)) then
345 local schemaLogo = Clockwork.option:GetKey("schema_logo");
346 local subLabelAlpha = self.subLabel:GetAlpha();
347
348 if (schemaLogo != "" and subLabelAlpha > 0) then
349 if (!self.logoTextureID) then
350 self.logoTextureID = Material(schemaLogo..".png");
351 end;
352
353 self.logoTextureID:SetFloat("$alpha", subLabelAlpha);
354
355 surface.SetDrawColor(255, 255, 255, subLabelAlpha);
356 surface.SetMaterial(self.logoTextureID);
357 surface.DrawTexturedRect(self.titleLabel.x, self.titleLabel.y - 64, 512, 256);
358 end;
359
360 Clockwork.theme:Call("PostCharacterMenuPaint", self)
361 end;
362end;
363
364
365-- Called each frame.
366function PANEL:Think()
367 if (!Clockwork.theme:Call("PreCharacterMenuThink", self)) then
368 local characters = table.Count(Clockwork.character:GetAll());
369 local bIsLoading = Clockwork.character:IsPanelLoading();
370 local schemaLogo = Clockwork.option:GetKey("schema_logo");
371 local activePanel = Clockwork.character:GetActivePanel();
372 local fault = Clockwork.character:GetFault();
373
374 if (Clockwork.plugin:Call("ShouldDrawCharacterBackgroundBlur")) then
375 Clockwork.kernel:RegisterBackgroundBlur(self, self.createTime);
376 else
377 Clockwork.kernel:RemoveBackgroundBlur(self);
378 end;
379
380 if (self.characterModel) then
381 if (!self.characterModel.currentModel
382 or self.characterModel.currentModel == "models/error.mdl") then
383 self.characterModel:SetAlpha(0);
384 end;
385 end;
386
387 if (!Clockwork.character:IsCreationProcessActive()) then
388 if (activePanel) then
389 if (activePanel.GetNextDisabled
390 and activePanel:GetNextDisabled()) then
391 self.nextButton:SetDisabled(true);
392 else
393 self.nextButton:SetDisabled(false);
394 end;
395
396 if (activePanel.GetPreviousDisabled
397 and activePanel:GetPreviousDisabled()) then
398 self.previousButton:SetDisabled(true);
399 else
400 self.previousButton:SetDisabled(false);
401 end;
402 end;
403 else
404 local previousPanelInfo = Clockwork.character:GetPreviousCreationPanel();
405
406 if (previousPanelInfo) then
407 self.previousButton:SetDisabled(false);
408 else
409 self.previousButton:SetDisabled(true);
410 end;
411
412 self.nextButton:SetDisabled(false);
413 end;
414
415 if (schemaLogo == "") then
416 self.titleLabel:SetVisible(true);
417 else
418 self.titleLabel:SetVisible(false);
419 end;
420
421 if (characters == 0 or bIsLoading) then
422 self.loadButton:SetDisabled(true);
423 else
424 self.loadButton:SetDisabled(false);
425 end;
426
427 if (characters >= Clockwork.player:GetMaximumCharacters()
428 or Clockwork.character:IsPanelLoading()) then
429 self.createButton:SetDisabled(true);
430 else
431 self.createButton:SetDisabled(false);
432 end;
433
434 if (Clockwork.Client:HasInitialized() and !Clockwork.character:IsMenuReset()) then
435 self.disconnectButton:SetText("CANCEL");
436 self.disconnectButton:SizeToContents();
437 else
438 self.disconnectButton:SetText("DISCONNECT");
439 self.disconnectButton:SizeToContents();
440 self.disconnectButton:SetPos(ScrW() * 0.1, ScrH() * 0.75);
441 end;
442
443 if (self.animation) then
444 self.animation:Run();
445 end;
446
447 self:SetSize(ScrW(), ScrH());
448
449 Clockwork.theme:Call("PostCharacterMenuThink", self)
450 end;
451end;
452
453vgui.Register("cwCharacterMenu", PANEL, "DPanel");