Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 61.21 KB | None | 0 0
  1. --[[
  2. © 2014 CloudSixteen.com do not share, re-distribute or modify
  3. without permission of its author (kurozael@gmail.com).
  4.  
  5. Clockwork was created by Conna Wiles (also known as kurozael.)
  6. http://cloudsixteen.com/license/clockwork.html
  7. --]]
  8.  
  9. local Clockwork = Clockwork;
  10. local pairs = pairs;
  11. local RunConsoleCommand = RunConsoleCommand;
  12. local SysTime = SysTime;
  13. local ScrH = ScrH;
  14. local ScrW = ScrW;
  15. local table = table;
  16. local string = string;
  17. local vgui = vgui;
  18. local math = math;
  19.  
  20. local PANEL = {};
  21.  
  22. -- Called when the panel is initialized.
  23. function 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.  
  41. local schemaLogo = Clockwork.option:GetKey("schema_logo");
  42.  
  43. self.subLabel = vgui.Create("cwLabelButton", self);
  44. self.subLabel:SetDisabled(true);
  45. self.subLabel:SetFont(smallTextFont);
  46. self.subLabel:SizeToContents();
  47.  
  48. if (schemaLogo == "") then
  49. self.titleLabel:SetVisible(true);
  50. self.titleLabel:SizeToContents();
  51. self.titleLabel:SetPos((scrW / 2) - (self.titleLabel:GetWide() / 2), scrH * 0.4);
  52. self.subLabel:SetPos((scrW / 2) - (self.subLabel:GetWide() / 2), self.titleLabel.y + self.titleLabel:GetTall() + 8);
  53. else
  54. self.titleLabel:SetVisible(false);
  55. self.titleLabel:SetSize(512, 256);
  56. self.titleLabel:SetPos((scrW / 2) - (self.titleLabel:GetWide() / 2), scrH * 0.4 - 128);
  57. self.subLabel:SetPos(self.titleLabel.x + (self.titleLabel:GetWide() / 2) - (self.subLabel:GetWide() / 2), self.titleLabel.y + self.titleLabel:GetTall() + 8);
  58. end;
  59.  
  60. self.authorLabel = vgui.Create("cwLabelButton", self);
  61. self.authorLabel:SetDisabled(true);
  62. self.authorLabel:SetFont(tinyTextFont);
  63. self.authorLabel:SizeToContents();
  64. self.authorLabel:SetPos(self.subLabel.x + (self.subLabel:GetWide() - self.authorLabel:GetWide()), self.subLabel.y + self.subLabel:GetTall() + 4);
  65.  
  66. self.createButton = vgui.Create("cwLabelButton", self);
  67. self.createButton:SetFont(smallTextFont);
  68. self.createButton:SetText("NEW");
  69. self.createButton:FadeIn(0.5);
  70. self.createButton:SetCallback(function(panel)
  71. if (table.Count(Clockwork.character:GetAll()) >= Clockwork.player:GetMaximumCharacters()) then
  72. return Clockwork.character:SetFault("You cannot create any more characters!");
  73. end;
  74.  
  75. Clockwork.character:ResetCreationInfo();
  76. Clockwork.character:OpenNextCreationPanel();
  77. end);
  78. self.createButton:SizeToContents();
  79. self.createButton:SetMouseInputEnabled(true);
  80. self.createButton:SetPos(scrW * 0.25, 16);
  81.  
  82. self.loadButton = vgui.Create("cwLabelButton", self);
  83. self.loadButton:SetFont(smallTextFont);
  84. self.loadButton:SetText("LOAD");
  85. self.loadButton:FadeIn(0.5);
  86. self.loadButton:SetCallback(function(panel)
  87. self:OpenPanel("cwCharacterList", nil, function(panel)
  88. Clockwork.character:RefreshPanelList();
  89. end);
  90. end);
  91. self.loadButton:SizeToContents();
  92. self.loadButton:SetMouseInputEnabled(true);
  93. self.loadButton:SetPos(scrW * 0.75, 16);
  94.  
  95. self.disconnectButton = vgui.Create("cwLabelButton", self);
  96. self.disconnectButton:SetFont(smallTextFont);
  97. self.disconnectButton:SetText("LEAVE");
  98. self.disconnectButton:FadeIn(0.5);
  99. self.disconnectButton:SetCallback(function(panel)
  100. if (Clockwork.Client:HasInitialized() and !Clockwork.character:IsMenuReset()) then
  101. Clockwork.character:SetPanelMainMenu();
  102. Clockwork.character:SetPanelOpen(false);
  103. else
  104. RunConsoleCommand("disconnect");
  105. end;
  106. end);
  107. self.disconnectButton:SizeToContents();
  108. self.disconnectButton:SetPos((scrW / 2) - (self.disconnectButton:GetWide() / 2), 16);
  109. self.disconnectButton:SetMouseInputEnabled(true);
  110.  
  111. self.previousButton = vgui.Create("cwLabelButton", self);
  112. self.previousButton:SetFont(tinyTextFont);
  113. self.previousButton:SetText("PREVIOUS");
  114. self.previousButton:SetCallback(function(panel)
  115. if (!Clockwork.character:IsCreationProcessActive()) then
  116. local activePanel = Clockwork.character:GetActivePanel();
  117.  
  118. if (activePanel and activePanel.OnPrevious) then
  119. activePanel:OnPrevious();
  120. end;
  121. else
  122. Clockwork.character:OpenPreviousCreationPanel()
  123. end;
  124. end);
  125. self.previousButton:SizeToContents();
  126. self.previousButton:SetMouseInputEnabled(true);
  127. self.previousButton:SetPos((scrW * 0.2) - (self.previousButton:GetWide() / 2), scrH * 0.9);
  128.  
  129. self.nextButton = vgui.Create("cwLabelButton", self);
  130. self.nextButton:SetFont(tinyTextFont);
  131. self.nextButton:SetText("NEXT");
  132. self.nextButton:SetCallback(function(panel)
  133. if (!Clockwork.character:IsCreationProcessActive()) then
  134. local activePanel = Clockwork.character:GetActivePanel();
  135.  
  136. if (activePanel and activePanel.OnNext) then
  137. activePanel:OnNext();
  138. end;
  139. else
  140. Clockwork.character:OpenNextCreationPanel()
  141. end;
  142. end);
  143. self.nextButton:SizeToContents();
  144. self.nextButton:SetMouseInputEnabled(true);
  145. self.nextButton:SetPos((scrW * 0.8) - (self.nextButton:GetWide() / 2), scrH * 0.9);
  146.  
  147. self.cancelButton = vgui.Create("cwLabelButton", self);
  148. self.cancelButton:SetFont(tinyTextFont);
  149. self.cancelButton:SetText("CANCEL");
  150. self.cancelButton:SetCallback(function(panel)
  151. self:ReturnToMainMenu();
  152. end);
  153. self.cancelButton:SizeToContents();
  154. self.cancelButton:SetMouseInputEnabled(true);
  155. self.cancelButton:SetPos((scrW * 0.5) - (self.cancelButton:GetWide() / 2), scrH * 0.9);
  156.  
  157. self.characterModel = vgui.Create("cwCharacterModel", self);
  158. self.characterModel:SetSize(512, 512);
  159. self.characterModel:SetAlpha(0);
  160. self.characterModel:SetModel("models/error.mdl");
  161. self.createTime = SysTime();
  162.  
  163. Clockwork.theme:Call("PostCharacterMenuInit", self)
  164. end;
  165. end;
  166.  
  167. -- A function to fade in the model panel.
  168. function PANEL:FadeInModelPanel(model)
  169. if (ScrH() < 768) then
  170. return true;
  171. end;
  172.  
  173. local panel = Clockwork.character:GetActivePanel();
  174. local x, y = ScrW() - self.characterModel:GetWide() - 8, 16;
  175.  
  176. if (panel) then
  177. x, y = panel.x + panel:GetWide() - 16, panel.y - 80;
  178. end;
  179.  
  180. self.characterModel:SetPos(x, y);
  181.  
  182. if (self.characterModel:FadeIn(0.5)) then
  183. self:SetModelPanelModel(model);
  184. return true;
  185. else
  186. return false;
  187. end;
  188. end;
  189.  
  190. -- A function to fade out the model panel.
  191. function PANEL:FadeOutModelPanel()
  192. self.characterModel:FadeOut(0.5);
  193. end;
  194.  
  195. -- A function to set the model panel's model.
  196. function PANEL:SetModelPanelModel(model)
  197. if (self.characterModel.currentModel != model) then
  198. self.characterModel.currentModel = model;
  199. self.characterModel:SetModel(model);
  200. end;
  201.  
  202. local modelPanel = self.characterModel:GetModelPanel();
  203. local weaponModel = Clockwork.plugin:Call(
  204. "GetModelSelectWeaponModel", model
  205. );
  206. local sequence = Clockwork.plugin:Call(
  207. "GetModelSelectSequence", modelPanel.Entity, model
  208. );
  209.  
  210. if (weaponModel) then
  211. self.characterModel:SetWeaponModel(weaponModel);
  212. else
  213. self.characterModel:SetWeaponModel(false);
  214. end;
  215.  
  216. if (sequence) then
  217. modelPanel.Entity:ResetSequence(sequence);
  218. end;
  219. end;
  220.  
  221. -- A function to return to the main menu.
  222. function PANEL:ReturnToMainMenu()
  223. local panel = Clockwork.character:GetActivePanel();
  224.  
  225. if (panel) then
  226. panel:FadeOut(0.5, function()
  227. Clockwork.character.activePanel = nil;
  228. panel:Remove();
  229. self:FadeInTitle();
  230. end);
  231. else
  232. self:FadeInTitle();
  233. end;
  234.  
  235. self:FadeOutModelPanel();
  236. self:FadeOutNavigation();
  237. end;
  238.  
  239. -- A function to fade out the navigation.
  240. function PANEL:FadeOutNavigation()
  241. self.previousButton:FadeOut(0.5);
  242. self.cancelButton:FadeOut(0.5);
  243. self.nextButton:FadeOut(0.5);
  244. end;
  245.  
  246. -- A function to fade in the navigation.
  247. function PANEL:FadeInNavigation()
  248. self.previousButton:FadeIn(0.5);
  249. self.cancelButton:FadeIn(0.5);
  250. self.nextButton:FadeIn(0.5);
  251. end;
  252.  
  253. -- A function to fade out the title.
  254. function PANEL:FadeOutTitle()
  255. self.subLabel:FadeOut(0.5);
  256. self.titleLabel:FadeOut(0.5);
  257. self.authorLabel:FadeOut(0.5);
  258. end;
  259.  
  260. -- A function to fade in the title.
  261. function PANEL:FadeInTitle()
  262. self.subLabel:FadeIn(0.5);
  263. self.titleLabel:FadeIn(0.5);
  264. self.authorLabel:FadeIn(0.5);
  265. end;
  266.  
  267. -- A function to open a panel.
  268. function PANEL:OpenPanel(vguiName, childData, Callback)
  269. if (!Clockwork.theme:Call("PreCharacterMenuOpenPanel", self, vguiName, childData, Callback)) then
  270. local panel = Clockwork.character:GetActivePanel();
  271.  
  272. if (panel) then
  273. panel:FadeOut(0.5, function()
  274. panel:Remove(); self.childData = childData;
  275.  
  276. Clockwork.character.activePanel = vgui.Create(vguiName, self);
  277. Clockwork.character.activePanel:SetAlpha(0);
  278. Clockwork.character.activePanel:FadeIn(0.5);
  279. Clockwork.character.activePanel:MakePopup();
  280. Clockwork.character.activePanel:SetPos(ScrW() * 0.2, ScrH() * 0.275);
  281.  
  282. if (Callback) then
  283. Callback(Clockwork.character.activePanel);
  284. end;
  285.  
  286. if (childData) then
  287. Clockwork.character.activePanel.bIsCreationProcess = true;
  288. Clockwork.character:FadeInNavigation();
  289. end;
  290. end);
  291. else
  292. self.childData = childData;
  293. self:FadeOutTitle();
  294.  
  295. Clockwork.character.activePanel = vgui.Create(vguiName, self);
  296. Clockwork.character.activePanel:SetAlpha(0);
  297. Clockwork.character.activePanel:FadeIn(0.5);
  298. Clockwork.character.activePanel:MakePopup();
  299. Clockwork.character.activePanel:SetPos(ScrW() * 0.2, ScrH() * 0.275);
  300.  
  301. if (Callback) then
  302. Callback(Clockwork.character.activePanel);
  303. end;
  304.  
  305. if (childData) then
  306. Clockwork.character.activePanel.bIsCreationProcess = true;
  307. Clockwork.character:FadeInNavigation();
  308. end;
  309. end;
  310.  
  311. --[[ Fade out the model panel, we probably don't need it now! --]]
  312. self:FadeOutModelPanel();
  313.  
  314. Clockwork.theme:Call("PostCharacterMenuOpenPanel", self);
  315. end;
  316. end;
  317.  
  318. -- Called when the panel is painted.
  319. function PANEL:Paint(w, h)
  320. if (!Clockwork.theme:Call("PreCharacterMenuPaint", self)) then
  321. local schemaLogo = Clockwork.option:GetKey("schema_logo");
  322. local subLabelAlpha = self.subLabel:GetAlpha();
  323.  
  324. if (schemaLogo != "" and subLabelAlpha > 0) then
  325. if (!self.logoTextureID) then
  326. self.logoTextureID = Material(schemaLogo..".png");
  327. end;
  328.  
  329. self.logoTextureID:SetFloat("$alpha", subLabelAlpha);
  330.  
  331. surface.SetDrawColor(255, 255, 255, subLabelAlpha);
  332. surface.SetMaterial(self.logoTextureID);
  333. surface.DrawTexturedRect(self.titleLabel.x, self.titleLabel.y - 64, 512, 256);
  334. end;
  335.  
  336. Clockwork.theme:Call("PostCharacterMenuPaint", self)
  337. end;
  338.  
  339. local backgroundColor = Clockwork.option:GetColor("background");
  340. local foregroundColor = Clockwork.option:GetColor("foreground");
  341. local colorTargetID = Clockwork.option:GetColor("target_id");
  342. local tinyTextFont = Clockwork.option:GetFont("menu_text_tiny");
  343. local colorWhite = Clockwork.option:GetColor("white");
  344. local scrW, scrH = ScrW(), ScrH();
  345. local height = (self.createButton.y * 2) + self.createButton:GetTall();
  346. local x, y = x, 0;
  347.  
  348. Clockwork.kernel:DrawSimpleGradientBox(0, 0, y, scrW, height, Color(
  349. backgroundColor.r, backgroundColor.g, backgroundColor.b, 100
  350. ));
  351.  
  352. surface.SetDrawColor(
  353. foregroundColor.r, foregroundColor.g, foregroundColor.b, 200
  354. );
  355. surface.DrawRect(0, y + height, scrW, 1);
  356.  
  357. if (Clockwork.character:IsCreationProcessActive()) then
  358. local creationPanels = Clockwork.character:GetCreationPanels();
  359. local numCreationPanels = #creationPanels;
  360. local creationProgress = Clockwork.character:GetCreationProgress();
  361. local progressHeight = 20;
  362. local creationInfo = Clockwork.character:GetCreationInfo();
  363. local progressY = y + height + 1;
  364. local boxColor = Color(
  365. math.min(backgroundColor.r + 50, 255),
  366. math.min(backgroundColor.g + 50, 255),
  367. math.min(backgroundColor.b + 50, 255),
  368. 100
  369. );
  370.  
  371. Clockwork.kernel:DrawSimpleGradientBox(0, 0, progressY, scrW, progressHeight, boxColor);
  372. for i = 1, numCreationPanels do
  373. surface.SetDrawColor(
  374. foregroundColor.r, foregroundColor.g, foregroundColor.b, 150
  375. );
  376. surface.DrawRect((scrW / numCreationPanels) * i, progressY, 1, progressHeight);
  377. end;
  378. Clockwork.kernel:DrawSimpleGradientBox(
  379. 0, 0, progressY, (scrW / 100) * creationProgress, progressHeight, colorTargetID
  380. );
  381.  
  382. if (creationProgress > 0 and creationProgress < 100) then
  383. surface.SetDrawColor(
  384. foregroundColor.r, foregroundColor.g, foregroundColor.b, 200
  385. );
  386. surface.DrawRect((scrW / 100) * creationProgress, progressY, 1, progressHeight);
  387. end;
  388.  
  389. for i = 1, numCreationPanels do
  390. local Condition = creationPanels[i].Condition;
  391. local textX = (scrW / numCreationPanels) * (i - 0.5);
  392. local textY = progressY + (progressHeight / 2);
  393. local color = Color(colorWhite.r, colorWhite.g, colorWhite.b, 200);
  394.  
  395. if (Condition and !Condition(creationInfo)) then
  396. color = Color(colorWhite.r, colorWhite.g, colorWhite.b, 100);
  397. end;
  398.  
  399. Clockwork.kernel:DrawSimpleText(creationPanels[i].friendlyName, textX, textY - 1, color, 1, 1);
  400. end;
  401.  
  402. surface.SetDrawColor(
  403. foregroundColor.r, foregroundColor.g, foregroundColor.b, 200
  404. );
  405. surface.DrawRect(0, progressY + progressHeight, scrW, 1);
  406. end;
  407.  
  408. return true;
  409. end;
  410.  
  411. -- Called each frame.
  412. function PANEL:Think()
  413. if (!Clockwork.theme:Call("PreCharacterMenuThink", self)) then
  414. local characters = table.Count(Clockwork.character:GetAll());
  415. local bIsLoading = Clockwork.character:IsPanelLoading();
  416. local schemaLogo = Clockwork.option:GetKey("schema_logo");
  417. local activePanel = Clockwork.character:GetActivePanel();
  418. local fault = Clockwork.character:GetFault();
  419.  
  420. if (Clockwork.plugin:Call("ShouldDrawCharacterBackgroundBlur")) then
  421. Clockwork.kernel:RegisterBackgroundBlur(self, self.createTime);
  422. else
  423. Clockwork.kernel:RemoveBackgroundBlur(self);
  424. end;
  425.  
  426. if (self.characterModel) then
  427. if (!self.characterModel.currentModel
  428. or self.characterModel.currentModel == "models/error.mdl") then
  429. self.characterModel:SetAlpha(0);
  430. end;
  431. end;
  432.  
  433. if (!Clockwork.character:IsCreationProcessActive()) then
  434. if (activePanel) then
  435. if (activePanel.GetNextDisabled
  436. and activePanel:GetNextDisabled()) then
  437. self.nextButton:SetDisabled(true);
  438. else
  439. self.nextButton:SetDisabled(false);
  440. end;
  441.  
  442. if (activePanel.GetPreviousDisabled
  443. and activePanel:GetPreviousDisabled()) then
  444. self.previousButton:SetDisabled(true);
  445. else
  446. self.previousButton:SetDisabled(false);
  447. end;
  448. end;
  449. else
  450. local previousPanelInfo = Clockwork.character:GetPreviousCreationPanel();
  451.  
  452. if (previousPanelInfo) then
  453. self.previousButton:SetDisabled(false);
  454. else
  455. self.previousButton:SetDisabled(true);
  456. end;
  457.  
  458. self.nextButton:SetDisabled(false);
  459. end;
  460.  
  461. if (schemaLogo == "") then
  462. self.titleLabel:SetVisible(true);
  463. else
  464. self.titleLabel:SetVisible(false);
  465. end;
  466.  
  467. if (characters == 0 or bIsLoading) then
  468. self.loadButton:SetDisabled(true);
  469. else
  470. self.loadButton:SetDisabled(false);
  471. end;
  472.  
  473. if (characters >= Clockwork.player:GetMaximumCharacters()
  474. or Clockwork.character:IsPanelLoading()) then
  475. self.createButton:SetDisabled(true);
  476. else
  477. self.createButton:SetDisabled(false);
  478. end;
  479.  
  480. if (Clockwork.Client:HasInitialized() and !Clockwork.character:IsMenuReset()) then
  481. self.disconnectButton:SetText("CANCEL");
  482. self.disconnectButton:SizeToContents();
  483. else
  484. self.disconnectButton:SetText("LEAVE");
  485. self.disconnectButton:SizeToContents();
  486. end;
  487.  
  488. if (self.animation) then
  489. self.animation:Run();
  490. end;
  491.  
  492. self:SetSize(ScrW(), ScrH());
  493.  
  494. Clockwork.theme:Call("PostCharacterMenuThink", self)
  495. end;
  496. end;
  497.  
  498. vgui.Register("cwCharacterMenu", PANEL, "DPanel");
  499.  
  500. --[[
  501. Add a hook to control clicking outside of the active panel.
  502. --]]
  503.  
  504. hook.Add("VGUIMousePressed", "Clockwork.character:VGUIMousePressed", function(panel, code)
  505. local characterPanel = Clockwork.character:GetPanel();
  506. local activePanel = Clockwork.character:GetActivePanel();
  507.  
  508. if (Clockwork.character:IsPanelOpen() and activePanel
  509. and characterPanel == panel) then
  510. activePanel:MakePopup();
  511. end;
  512. end);
  513.  
  514. local PANEL = {};
  515.  
  516. -- Called when the panel is initialized.
  517. function PANEL:Init()
  518. self.selectedIdx = 1;
  519. self.characterPanels = {};
  520. self.isCharacterList = true;
  521.  
  522. Clockwork.character:FadeInNavigation()
  523. end;
  524.  
  525. -- Called when the panel is painted.
  526. function PANEL:Paint(w, h) end;
  527.  
  528. -- A function to make the panel fade out.
  529. function PANEL:FadeOut(speed, Callback)
  530. if (self:GetAlpha() > 0 and (!self.animation or !self.animation:Active())) then
  531. self.animation = Derma_Anim("Fade Panel", self, function(panel, animation, delta, data)
  532. panel:SetAlpha(255 - (delta * 255));
  533.  
  534. if (animation.Finished) then
  535. panel:SetVisible(false);
  536. end;
  537.  
  538. if (animation.Finished and Callback) then
  539. Callback();
  540. end;
  541. end);
  542.  
  543. if (self.animation) then
  544. self.animation:Start(speed);
  545. end;
  546.  
  547. Clockwork.option:PlaySound("rollover");
  548. else
  549. self:SetVisible(false);
  550. self:SetAlpha(0);
  551.  
  552. if (Callback) then
  553. Callback();
  554. end;
  555. end;
  556. end;
  557.  
  558. -- A function to make the panel fade in.
  559. function PANEL:FadeIn(speed, Callback)
  560. if (self:GetAlpha() == 0 and (!self.animation or !self.animation:Active())) then
  561. self.animation = Derma_Anim("Fade Panel", self, function(panel, animation, delta, data)
  562. panel:SetVisible(true);
  563. panel:SetAlpha(delta * 255);
  564.  
  565. if (animation.Finished) then
  566. self.animation = nil;
  567. end;
  568.  
  569. if (animation.Finished and Callback) then
  570. Callback();
  571. end;
  572. end);
  573.  
  574. if (self.animation) then
  575. self.animation:Start(speed);
  576. end;
  577.  
  578. Clockwork.option:PlaySound("click_release");
  579. else
  580. self:SetVisible(true);
  581. self:SetAlpha(255);
  582.  
  583. if (Callback) then
  584. Callback();
  585. end;
  586. end;
  587. end;
  588.  
  589. -- A function to clear the panel's panels.
  590. function PANEL:Clear()
  591. for k, v in pairs(self.characterPanels) do
  592. v:Remove();
  593. end;
  594.  
  595. self.characterPanels = {};
  596. end;
  597.  
  598. -- A function to add a panel to the panel.
  599. function PANEL:AddPanel(panel)
  600. self.characterPanels[#self.characterPanels + 1] = panel;
  601. end;
  602.  
  603. -- Called to get whether the previous button is disabled.
  604. function PANEL:GetPreviousDisabled()
  605. return (self.characterPanels[self.selectedIdx - 1] == nil);
  606. end;
  607.  
  608. -- Called to get whether the next button is disabled.
  609. function PANEL:GetNextDisabled()
  610. return (self.characterPanels[self.selectedIdx + 1] == nil);
  611. end;
  612.  
  613. -- A function to get the panel's character panels.
  614. function PANEL:GetCharacterPanels()
  615. return self.characterPanels;
  616. end;
  617.  
  618. -- A function to get the panel's selected model.
  619. function PANEL:GetSelectedModel()
  620. return self.characterPanels[self.selectedIdx];
  621. end;
  622.  
  623. -- A function to manage a panel's targets.
  624. function PANEL:ManageTargets(panel, position, alpha)
  625. if (!panel.TargetPosition) then
  626. panel.TargetPosition = position;
  627. end;
  628.  
  629. if (!panel.TargetAlpha) then
  630. panel.TargetAlpha = alpha;
  631. end;
  632.  
  633. local moveSpeed = math.abs(panel.TargetPosition - position) * 2;
  634. local interval = moveSpeed * FrameTime();
  635.  
  636. panel.TargetPosition = math.Approach(panel.TargetPosition, position, interval);
  637. panel.TargetAlpha = math.Approach(panel.TargetAlpha, alpha, interval);
  638. panel:SetAlpha(panel.TargetAlpha);
  639. panel:SetPos(panel.TargetPosition, 0);
  640. end;
  641.  
  642. -- A function to set the panel's selected index.
  643. function PANEL:SetSelectedIdx(index)
  644. self.selectedIdx = index;
  645. end;
  646.  
  647. -- Called when the previous button is pressed.
  648. function PANEL:OnPrevious()
  649. self.selectedIdx = math.max(self.selectedIdx - 1, 1);
  650. self:MakePopup();
  651. end;
  652.  
  653. -- Called when the next button is pressed.
  654. function PANEL:OnNext()
  655. self.selectedIdx = math.min(self.selectedIdx + 1, #self.characterPanels);
  656. self:MakePopup();
  657. end;
  658.  
  659. -- Called each frame.
  660. function PANEL:Think()
  661. self:InvalidateLayout(true);
  662.  
  663. if (self.animation) then self.animation:Run(); end;
  664.  
  665. while (self.selectedIdx > #self.characterPanels) do
  666. self.selectedIdx = self.selectedIdx - 1;
  667. end;
  668.  
  669. if (self.selectedIdx == 0) then self.selectedIdx = 1; end;
  670.  
  671. if (self.characterPanels[self.selectedIdx]) then
  672. local centerPanel = self.characterPanels[self.selectedIdx];
  673. centerPanel:SetActive(true);
  674. self:ManageTargets(centerPanel, (self:GetWide() / 2) - (centerPanel:GetWide() / 2), 255);
  675.  
  676. local rightX = centerPanel.x + centerPanel:GetWide() + 16;
  677. local leftX = centerPanel.x - 16;
  678.  
  679. for i = self.selectedIdx - 1, 1, -1 do
  680. local previousPanel = self.characterPanels[i];
  681.  
  682. if (previousPanel) then
  683. previousPanel:SetActive(false);
  684. self:ManageTargets(previousPanel, leftX - previousPanel:GetWide(), (255 / self.selectedIdx) * i);
  685. leftX = previousPanel.x - 16;
  686. end;
  687. end;
  688.  
  689. for k, v in pairs(self.characterPanels) do
  690. if (k > self.selectedIdx) then
  691. v:SetActive(false);
  692. self:ManageTargets(v, rightX, (255 / ((#self.characterPanels + 1) - self.selectedIdx)) * ((#self.characterPanels + 1) - k));
  693. rightX = v.x + v:GetWide() + 16;
  694. end;
  695. end;
  696. end;
  697. end;
  698.  
  699. -- Called when the layout should be performed.
  700. function PANEL:PerformLayout(w, h)
  701. self:SetPos(0, (ScrH() / 2) - 256);
  702. self:SetSize(ScrW(), 512);
  703. end;
  704.  
  705. vgui.Register("cwCharacterList", PANEL, "EditablePanel");
  706.  
  707. local PANEL = {};
  708.  
  709. -- Called when the panel is initialized.
  710. function PANEL:Init()
  711. local smallTextFont = Clockwork.option:GetFont("menu_text_small");
  712. local tinyTextFont = Clockwork.option:GetFont("menu_text_tiny");
  713. local buttonsList = {};
  714. local colorWhite = Clockwork.option:GetColor("white");
  715. local buttonX = 20;
  716. local buttonY = 0;
  717.  
  718. self.customData = self:GetParent().customData;
  719. self.buttonPanels = {};
  720. self:SetPaintBackground(false);
  721.  
  722. self.nameLabel = vgui.Create("cwLabelButton", self);
  723. self.nameLabel:SetDisabled(true);
  724. self.nameLabel:SetFont(smallTextFont);
  725. self.nameLabel:SetText(string.upper(self.customData.name));
  726. self.nameLabel:SizeToContents();
  727.  
  728. self.factionLabel = vgui.Create("cwLabelButton", self);
  729. self.factionLabel:SetDisabled(true);
  730. self.factionLabel:SetFont(tinyTextFont);
  731. self.factionLabel:SetText(string.upper(self.customData.faction));
  732. self.factionLabel:SizeToContents();
  733. self.factionLabel:SetPos(0, self.nameLabel:GetTall() + 8);
  734.  
  735. self.characterModel = vgui.Create("cwCharacterModel", self);
  736. self.characterModel:SetModel(self.customData.model);
  737. self.characterModel:SetPos(0, self.factionLabel.y + self.factionLabel:GetTall() + 8);
  738. self.characterModel:SetSize(256, 256);
  739. buttonY = self.characterModel.y + self.characterModel:GetTall() + 8;
  740.  
  741. local modelPanel = self.characterModel:GetModelPanel();
  742. local sequence = Clockwork.plugin:Call(
  743. "GetCharacterPanelSequence", modelPanel.Entity, self.customData.charTable
  744. );
  745.  
  746. if (sequence) then
  747. modelPanel.Entity:ResetSequence(sequence);
  748. end;
  749.  
  750. self.useButton = vgui.Create("DImageButton", self);
  751. self.useButton:SetToolTip("Use this character.");
  752. self.useButton:SetImage("icon16/tick.png");
  753. self.useButton:SetSize(16, 16);
  754. self.useButton:SetPos(0, buttonY);
  755.  
  756. self.deleteButton = vgui.Create("DImageButton", self);
  757. self.deleteButton:SetToolTip("Delete this character.");
  758. self.deleteButton:SetImage("icon16/cross.png");
  759. self.deleteButton:SetSize(16, 16);
  760. self.deleteButton:SetPos(20, buttonY);
  761.  
  762. Clockwork.plugin:Call(
  763. "GetCustomCharacterButtons", self.customData.charTable, buttonsList
  764. );
  765.  
  766. for k, v in pairs(buttonsList) do
  767. local button = vgui.Create("DImageButton", self);
  768. buttonX = buttonX + 20;
  769. button:SetToolTip(v.toolTip);
  770. button:SetImage(v.image);
  771. button:SetSize(16, 16);
  772. button:SetPos(buttonX, buttonY);
  773. self.buttonPanels[#self.buttonPanels + 1] = button;
  774.  
  775. -- Called when the button is clicked.
  776. function button.DoClick(button)
  777. local function Callback()
  778. Clockwork.datastream:Start("InteractCharacter", {
  779. characterID = self.customData.characterID, action = k
  780. });
  781. end;
  782.  
  783. if (!v.OnClick or v.OnClick(Callback) != false) then
  784. Callback();
  785. end;
  786. end;
  787. end;
  788.  
  789. -- Called when the button is clicked.
  790. function self.useButton.DoClick(spawnIcon)
  791. Clockwork.datastream:Start("InteractCharacter", {
  792. characterID = self.customData.characterID, action = "use"}
  793. );
  794. end;
  795.  
  796. -- Called when the button is clicked.
  797. function self.deleteButton.DoClick(spawnIcon)
  798. Clockwork.kernel:AddMenuFromData(nil, {
  799. ["Yes"] = function()
  800. Clockwork.datastream:Start("InteractCharacter", {
  801. characterID = self.customData.characterID, action = "delete"}
  802. );
  803. end,
  804. ["No"] = function() end
  805. });
  806. end;
  807.  
  808. local modelPanel = self.characterModel:GetModelPanel();
  809.  
  810. -- Called when the character model is clicked.
  811. function modelPanel.DoClick(modelPanel)
  812. local activePanel = Clockwork.character:GetActivePanel();
  813.  
  814. if (activePanel:GetSelectedModel() == self) then
  815. local options = {};
  816. local panel = Clockwork.character:GetPanel();
  817.  
  818. options["Use"] = function()
  819. Clockwork.datastream:Start("InteractCharacter", {
  820. characterID = self.customData.characterID, action = "use"}
  821. );
  822. end;
  823.  
  824. options["Delete"] = {};
  825. options["Delete"]["No"] = function() end;
  826. options["Delete"]["Yes"] = function()
  827. Clockwork.datastream:Start("InteractCharacter", {
  828. characterID = self.customData.characterID, action = "delete"}
  829. );
  830. end;
  831.  
  832. Clockwork.plugin:Call(
  833. "GetCustomCharacterOptions", self.customData.charTable, options, menu
  834. );
  835.  
  836. Clockwork.kernel:AddMenuFromData(nil, options, function(menu, key, value)
  837. menu:AddOption(key, function()
  838. Clockwork.datastream:Start("InteractCharacter", {
  839. characterID = self.customData.characterID, action = value}
  840. );
  841. end);
  842. end);
  843. else
  844. for k, v in pairs(activePanel:GetCharacterPanels()) do
  845. if (v == self) then
  846. activePanel:SetSelectedIdx(k);
  847. end;
  848. end;
  849. end;
  850. end;
  851.  
  852. local maxWidth = math.max(buttonX, 200);
  853.  
  854. if (self.nameLabel:GetWide() > maxWidth) then
  855. maxWidth = self.nameLabel:GetWide();
  856. end;
  857.  
  858. if (self.factionLabel:GetWide() > maxWidth) then
  859. maxWidth = self.factionLabel:GetWide();
  860. end;
  861.  
  862. self.characterModel:SetPos((maxWidth / 2) - 128, self.characterModel.y);
  863. self.factionLabel:SetPos((maxWidth / 2) - (self.factionLabel:GetWide() / 2), self.factionLabel.y);
  864. self.nameLabel:SetPos((maxWidth / 2) - (self.nameLabel:GetWide() / 2), self.nameLabel.y);
  865. self:SetSize(maxWidth, buttonY + 32);
  866.  
  867. local buttonAddX = ((maxWidth / 2) - (buttonX / 2)) - 10;
  868. self.useButton:SetPos(self.useButton.x + buttonAddX, self.useButton.y);
  869. self.deleteButton:SetPos(self.deleteButton.x + buttonAddX, self.deleteButton.y);
  870. for k, v in pairs(self.buttonPanels) do
  871. v:SetPos(v.x + buttonAddX, v.y);
  872. end;
  873. end;
  874.  
  875. -- A function to set whether the panel is active.
  876. function PANEL:SetActive(bActive)
  877. if (bActive) then
  878. self.nameLabel:OverrideTextColor(
  879. Clockwork.option:GetColor("information")
  880. );
  881. else
  882. self.nameLabel:OverrideTextColor(false);
  883. end;
  884. end;
  885.  
  886. -- Called each frame.
  887. function PANEL:Think()
  888. local informationColor = Clockwork.option:GetColor("information");
  889. local weaponModel = Clockwork.plugin:Call(
  890. "GetCharacterPanelWeaponModel", self, self.customData.charTable
  891. );
  892. local toolTip = Clockwork.plugin:Call(
  893. "GetCharacterPanelToolTip", self, self.customData.charTable
  894. );
  895. local details = Clockwork.kernel:MarkupTextWithColor("[Details]", informationColor);
  896.  
  897. details = Clockwork.kernel:AddMarkupLine(
  898. details, self.customData.details or "This character has no details to display."
  899. );
  900.  
  901. if (toolTip and toolTip != "") then
  902. details = Clockwork.kernel:AddMarkupLine(details, "[Information]", informationColor);
  903. details = Clockwork.kernel:AddMarkupLine(details, toolTip);
  904. end;
  905.  
  906. if (weaponModel) then
  907. self.characterModel:SetWeaponModel(weaponModel);
  908. else
  909. self.characterModel:SetWeaponModel(false);
  910. end;
  911.  
  912. self.characterModel:SetDetails(details);
  913. end;
  914.  
  915. vgui.Register("cwCharacterPanel", PANEL, "DPanel");
  916.  
  917. local PANEL = {};
  918.  
  919. -- Called when the panel is initialized.
  920. function PANEL:Init()
  921. self:SetPaintBackground(false);
  922.  
  923. self.modelPanel = vgui.Create("DModelPanel", self);
  924. self.modelPanel:SetAmbientLight(Color(255, 255, 255, 255));
  925. Clockwork.kernel:CreateMarkupToolTip(self.modelPanel);
  926.  
  927. -- Called when the entity should be laid out.
  928. function self.modelPanel.LayoutEntity(modelPanel, entity)
  929. modelPanel:RunAnimation();
  930. end;
  931. end;
  932.  
  933. -- A function to make the panel fade out.
  934. function PANEL:FadeOut(speed, Callback)
  935. if (self:GetAlpha() > 0 and (!self.animation or !self.animation:Active())) then
  936. self.animation = Derma_Anim("Fade Panel", self, function(panel, animation, delta, data)
  937. panel:SetAlpha(255 - (delta * 255));
  938.  
  939. if (animation.Finished) then
  940. panel:SetVisible(false);
  941. end;
  942.  
  943. if (animation.Finished and Callback) then
  944. Callback();
  945. end;
  946. end);
  947.  
  948. if (self.animation) then
  949. self.animation:Start(speed);
  950. end;
  951.  
  952. Clockwork.option:PlaySound("rollover");
  953.  
  954. return true;
  955. else
  956. self:SetAlpha(0);
  957. self:SetVisible(false);
  958.  
  959. if (Callback) then
  960. Callback();
  961. end;
  962. end;
  963. end;
  964.  
  965. -- A function to make the panel fade in.
  966. function PANEL:FadeIn(speed, Callback)
  967. if (self:GetAlpha() == 0 and (!self.animation or !self.animation:Active())) then
  968. self.animation = Derma_Anim("Fade Panel", self, function(panel, animation, delta, data)
  969. panel:SetAlpha(delta * 255);
  970.  
  971. if (animation.Finished) then
  972. self.animation = nil;
  973. end;
  974.  
  975. if (animation.Finished and Callback) then
  976. Callback();
  977. end;
  978. end);
  979.  
  980. if (self.animation) then
  981. self.animation:Start(speed);
  982. end;
  983.  
  984. Clockwork.option:PlaySound("click_release");
  985. self:SetVisible(true);
  986.  
  987. return true;
  988. else
  989. self:SetVisible(true);
  990. self:SetAlpha(255);
  991.  
  992. if (Callback) then
  993. Callback();
  994. end;
  995. end;
  996. end;
  997.  
  998. -- A function to set the alpha of the panel.
  999. function PANEL:SetAlpha(alpha)
  1000. local color = self.modelPanel:GetColor();
  1001.  
  1002. self.modelPanel:SetColor(Color(color.r, color.g, color.b, alpha));
  1003. end;
  1004.  
  1005. -- A function to get the alpha of the panel.
  1006. function PANEL:GetAlpha(alpha)
  1007. local color = self.modelPanel:GetColor();
  1008.  
  1009. return color.a;
  1010. end;
  1011.  
  1012. -- Called each frame.
  1013. function PANEL:Think()
  1014. local entity = self.modelPanel.Entity;
  1015.  
  1016. if (IsValid(entity)) then
  1017. entity:SetPos(Vector(0, 0, 0));
  1018. end;
  1019.  
  1020. if (self.animation) then
  1021. self.animation:Run();
  1022. end;
  1023.  
  1024. entity:ClearPoseParameters();
  1025. self:InvalidateLayout(true);
  1026. end;
  1027.  
  1028. -- A function to get the panel's model panel.
  1029. function PANEL:GetModelPanel()
  1030. return self.modelPanel;
  1031. end;
  1032.  
  1033. -- Called when the layout should be performed.
  1034. function PANEL:PerformLayout(w, h)
  1035. self.modelPanel:SetSize(w, h);
  1036. end;
  1037.  
  1038. -- A function to set the model details.
  1039. function PANEL:SetDetails(details)
  1040. self.modelPanel:SetMarkupToolTip(details);
  1041. end;
  1042.  
  1043. -- A function to set the model weapon.
  1044. function PANEL:SetWeaponModel(weaponModel)
  1045. if (!weaponModel and IsValid(self.weaponEntity)) then
  1046. self.weaponEntity:Remove();
  1047. return;
  1048. end;
  1049.  
  1050. if (!weaponModel and !IsValid(self.weaponEntity)
  1051. or IsValid(self.weaponEntity) and self.weaponEntity:GetModel() == weaponModel) then
  1052. return;
  1053. end;
  1054.  
  1055. if (IsValid(self.weaponEntity)) then
  1056. self.weaponEntity:Remove();
  1057. end;
  1058.  
  1059. self.weaponEntity = ClientsideModel(weaponModel, RENDER_GROUP_OPAQUE_ENTITY);
  1060. self.weaponEntity:SetParent(self.modelPanel.Entity);
  1061. self.weaponEntity:AddEffects(EF_BONEMERGE);
  1062. end;
  1063.  
  1064. -- A function to set the model.
  1065. function PANEL:SetModel(model)
  1066. self.modelPanel:SetModel(model);
  1067.  
  1068. local entity = ents.CreateClientProp("models/error.mdl");
  1069. entity:SetAngles(Angle(0, 0, 0));
  1070. entity:SetPos(Vector(0, 0, 0));
  1071. entity:SetModel(model);
  1072. entity:Spawn();
  1073. entity:Activate();
  1074. entity:PhysicsInit(SOLID_VPHYSICS);
  1075.  
  1076. local obbCenter = entity:OBBCenter();
  1077. obbCenter.z = obbCenter.z * 1.09;
  1078. local distance = entity:BoundingRadius() * 1.2;
  1079.  
  1080. self.modelPanel:SetLookAt(obbCenter)
  1081. self.modelPanel:SetCamPos(
  1082. obbCenter + Vector(distance * 1.56, distance * 0.31, distance * 0.4)
  1083. );
  1084.  
  1085. entity:Remove();
  1086.  
  1087. if (IsValid(self.modelPanel.Entity)) then
  1088. local sequence = self.modelPanel.Entity:LookupSequence("idle");
  1089. local menuSequence = Clockwork.animation:GetMenuSequence(model, true);
  1090. local leanBackAnims = {"LineIdle01", "LineIdle02", "LineIdle03"};
  1091. local leanBackAnim = self.modelPanel.Entity:LookupSequence(
  1092. leanBackAnims[math.random(1, #leanBackAnims)]
  1093. );
  1094.  
  1095. if (leanBackAnim > 0) then
  1096. sequence = leanBackAnim;
  1097. end;
  1098.  
  1099. if (menuSequence) then
  1100. menuSequence = self.modelPanel.Entity:LookupSequence(menuSequence);
  1101.  
  1102. if (menuSequence > 0) then
  1103. sequence = menuSequence;
  1104. end;
  1105. end;
  1106.  
  1107. if (sequence <= 0) then
  1108. sequence = self.modelPanel.Entity:LookupSequence("idle_unarmed");
  1109. end;
  1110.  
  1111. if (sequence <= 0) then
  1112. sequence = self.modelPanel.Entity:LookupSequence("idle1");
  1113. end;
  1114.  
  1115. if (sequence <= 0) then
  1116. sequence = self.modelPanel.Entity:LookupSequence("walk_all");
  1117. end;
  1118.  
  1119. self.modelPanel.Entity:ResetSequence(sequence);
  1120. end;
  1121. end;
  1122.  
  1123. vgui.Register("cwCharacterModel", PANEL, "DPanel");
  1124.  
  1125. local PANEL = {};
  1126.  
  1127. -- Called when the panel is initialized.
  1128. function PANEL:Init()
  1129. local colorWhite = Clockwork.option:GetColor("white");
  1130. local colorTargetID = Clockwork.option:GetColor("target_id");
  1131.  
  1132. self:SetSize(self:GetWide(), 16);
  1133. self.totalPoints = 0;
  1134. self.maximumPoints = 0;
  1135. self.attributeTable = nil;
  1136. self.attributePanels = {};
  1137. self:SetPaintBackground(false);
  1138.  
  1139. Clockwork.kernel:CreateMarkupToolTip(self);
  1140.  
  1141. self.addButton = vgui.Create("DImageButton", self);
  1142. self.addButton:SetMaterial("icon16/add.png");
  1143. self.addButton:SizeToContents();
  1144.  
  1145. -- Called when the button is clicked.
  1146. function self.addButton.DoClick(imageButton)
  1147. self:AddPoint();
  1148. end;
  1149.  
  1150. self.removeButton = vgui.Create("DImageButton", self);
  1151. self.removeButton:SetMaterial("icon16/exclamation.png");
  1152. self.removeButton:SizeToContents();
  1153.  
  1154. -- Called when the button is clicked.
  1155. function self.removeButton.DoClick(imageButton)
  1156. self:RemovePoint();
  1157. end;
  1158.  
  1159. self.pointsUsed = vgui.Create("DPanel", self);
  1160. self.pointsUsed:SetPos(self.addButton:GetWide() + 8, 0);
  1161. Clockwork.kernel:CreateMarkupToolTip(self.pointsUsed);
  1162.  
  1163. self.pointsLabel = vgui.Create("DLabel", self);
  1164. self.pointsLabel:SetText("N/A");
  1165. self.pointsLabel:SetTextColor(colorWhite);
  1166. self.pointsLabel:SizeToContents();
  1167. self.pointsLabel:SetExpensiveShadow(1, Color(0, 0, 0, 150));
  1168. Clockwork.kernel:CreateMarkupToolTip(self.pointsLabel);
  1169.  
  1170. -- Called when the panel should be painted.
  1171. function self.pointsUsed.Paint(pointsUsed)
  1172. local color = Color(100, 100, 100, 255);
  1173. local width = math.Clamp((pointsUsed:GetWide() / self.attributeTable.maximum) * self.totalPoints, 0, pointsUsed:GetWide());
  1174.  
  1175. if (color) then
  1176. color.r = math.min(color.r - 25, 255);
  1177. color.g = math.min(color.g - 25, 255);
  1178. color.b = math.min(color.b - 25, 255);
  1179. end;
  1180.  
  1181. Clockwork.kernel:DrawSimpleGradientBox(2, 0, 0, pointsUsed:GetWide(), pointsUsed:GetTall(), color);
  1182.  
  1183. if (self.totalPoints > 0 and self.totalPoints < self.attributeTable.maximum) then
  1184. Clockwork.kernel:DrawSimpleGradientBox(0, 2, 2, width - 4, pointsUsed:GetTall() - 4, colorTargetID);
  1185. surface.SetDrawColor(255, 255, 255, 200);
  1186. surface.DrawRect(width, 0, 1, pointsUsed:GetTall());
  1187. end;
  1188. end;
  1189. end;
  1190.  
  1191. -- Called each frame.
  1192. function PANEL:Think()
  1193. self.pointsUsed:SetSize(self:GetWide() - (self.pointsUsed.x * 2), 16);
  1194. self.pointsLabel:SetText(self.attributeTable.name);
  1195. self.pointsLabel:SetPos(self:GetWide() / 2 - self.pointsLabel:GetWide() / 2, self:GetTall() / 2 - self.pointsLabel:GetTall() / 2);
  1196. self.pointsLabel:SizeToContents();
  1197. self.addButton:SetPos(self.pointsUsed.x + self.pointsUsed:GetWide() + 8, 0);
  1198.  
  1199. local informationColor = Clockwork.option:GetColor("information");
  1200. local attributeName = self.attributeTable.name;
  1201. local attributeMax = self.totalPoints.."/"..self.attributeTable.maximum;
  1202. local markupToolTip = Clockwork.kernel:MarkupTextWithColor(
  1203. "["..attributeName..", "..attributeMax.."]", informationColor
  1204. );
  1205.  
  1206. markupToolTip = markupToolTip.."\n"..self.attributeTable.description;
  1207.  
  1208. self:SetMarkupToolTip(markupToolTip);
  1209. self.pointsUsed:SetMarkupToolTip(markupToolTip);
  1210. self.pointsLabel:SetMarkupToolTip(markupToolTip);
  1211. end;
  1212.  
  1213. -- A function to add a point.
  1214. function PANEL:AddPoint()
  1215. local pointsUsed = self:GetPointsUsed();
  1216.  
  1217. if (pointsUsed + 1 <= self.maximumPoints) then
  1218. self.totalPoints = self.totalPoints + 1;
  1219. end;
  1220. end;
  1221.  
  1222. -- A function to remove a point.
  1223. function PANEL:RemovePoint()
  1224. self.totalPoints = math.max(self.totalPoints - 1, 0);
  1225. end;
  1226.  
  1227. -- A function to get the total points.
  1228. function PANEL:GetTotalPoints()
  1229. return self.totalPoints;
  1230. end;
  1231.  
  1232. -- A function to get the points used.
  1233. function PANEL:GetPointsUsed()
  1234. local pointsUsed = 0;
  1235.  
  1236. for k, v in pairs(self.attributePanels) do
  1237. pointsUsed = pointsUsed + v:GetTotalPoints();
  1238. end;
  1239.  
  1240. return pointsUsed;
  1241. end;
  1242.  
  1243. -- A function to get the panel's attribute ID.
  1244. function PANEL:GetAttributeID()
  1245. return self.attributeTable.uniqueID;
  1246. end;
  1247.  
  1248. -- A function to set the panel's attribute panels.
  1249. function PANEL:SetAttributePanels(attributePanels)
  1250. self.attributePanels = attributePanels;
  1251. end;
  1252.  
  1253. -- A function to set the panel's attribute table.
  1254. function PANEL:SetAttributeTable(attributeTable)
  1255. self.attributeTable = attributeTable;
  1256. end;
  1257.  
  1258. -- A function to set the panel's maximum points.
  1259. function PANEL:SetMaximumPoints(maximumPoints)
  1260. self.maximumPoints = maximumPoints;
  1261. end;
  1262.  
  1263. vgui.Register("cwCharacterAttribute", PANEL, "DPanel");
  1264.  
  1265. local PANEL = {};
  1266.  
  1267. -- Called when the panel is initialized.
  1268. function PANEL:Init()
  1269. self.info = Clockwork.character:GetCreationInfo();
  1270.  
  1271. local maximumPoints = Clockwork.config:Get("default_attribute_points"):Get();
  1272. local smallTextFont = Clockwork.option:GetFont("menu_text_small");
  1273. local factionTable = Clockwork.faction:FindByID(self.info.faction);
  1274. local attributes = {};
  1275.  
  1276. if (factionTable.attributePointsScale) then
  1277. maximumPoints = math.Round(maximumPoints * factionTable.attributePointsScale);
  1278. end;
  1279.  
  1280. if (factionTable.maximumAttributePoints) then
  1281. maximumPoints = factionTable.maximumAttributePoints;
  1282. end;
  1283.  
  1284. self.attributesForm = vgui.Create("DForm");
  1285. self.attributesForm:SetName(Clockwork.option:GetKey("name_attributes"));
  1286. self.attributesForm:SetPadding(4);
  1287.  
  1288. self.categoryList = vgui.Create("DCategoryList", self);
  1289. self.categoryList:SetPadding(2);
  1290. self.categoryList:SizeToContents();
  1291.  
  1292. for k, v in pairs(Clockwork.attribute:GetAll()) do
  1293. attributes[#attributes + 1] = v;
  1294. end;
  1295.  
  1296. table.sort(attributes, function(a, b)
  1297. return a.name < b.name;
  1298. end);
  1299.  
  1300. self.attributePanels = {};
  1301. self.info.attributes = {};
  1302. self.helpText = self.attributesForm:Help("You can spend "..maximumPoints.." more point(s).");
  1303.  
  1304. for k, v in pairs(attributes) do
  1305. if (v.isOnCharScreen) then
  1306. local characterAttribute = vgui.Create("cwCharacterAttribute", self.attributesForm);
  1307. characterAttribute:SetAttributeTable(v);
  1308. characterAttribute:SetMaximumPoints(maximumPoints);
  1309. characterAttribute:SetAttributePanels(self.attributePanels);
  1310. self.attributesForm:AddItem(characterAttribute);
  1311.  
  1312. self.attributePanels[#self.attributePanels + 1] = characterAttribute;
  1313. end;
  1314. end;
  1315.  
  1316. self.maximumPoints = maximumPoints;
  1317. self.categoryList:AddItem(self.attributesForm);
  1318. end;
  1319.  
  1320. -- Called when the next button is pressed.
  1321. function PANEL:OnNext()
  1322. for k, v in pairs(self.attributePanels) do
  1323. self.info.attributes[v:GetAttributeID()] = v:GetTotalPoints();
  1324. end;
  1325. end;
  1326.  
  1327. -- Called when the panel is painted.
  1328. function PANEL:Paint(w, h) end;
  1329.  
  1330. -- A function to make the panel fade out.
  1331. function PANEL:FadeOut(speed, Callback)
  1332. if (self:GetAlpha() > 0 and (!self.animation or !self.animation:Active())) then
  1333. self.animation = Derma_Anim("Fade Panel", self, function(panel, animation, delta, data)
  1334. panel:SetAlpha(255 - (delta * 255));
  1335.  
  1336. if (animation.Finished) then
  1337. panel:SetVisible(false);
  1338. end;
  1339.  
  1340. if (animation.Finished and Callback) then
  1341. Callback();
  1342. end;
  1343. end);
  1344.  
  1345. if (self.animation) then
  1346. self.animation:Start(speed);
  1347. end;
  1348.  
  1349. Clockwork.option:PlaySound("rollover");
  1350. else
  1351. self:SetVisible(false);
  1352. self:SetAlpha(0);
  1353.  
  1354. if (Callback) then
  1355. Callback();
  1356. end;
  1357. end;
  1358. end;
  1359.  
  1360. -- A function to make the panel fade in.
  1361. function PANEL:FadeIn(speed, Callback)
  1362. if (self:GetAlpha() == 0 and (!self.animation or !self.animation:Active())) then
  1363. self.animation = Derma_Anim("Fade Panel", self, function(panel, animation, delta, data)
  1364. panel:SetVisible(true);
  1365. panel:SetAlpha(delta * 255);
  1366.  
  1367. if (animation.Finished) then
  1368. self.animation = nil;
  1369. end;
  1370.  
  1371. if (animation.Finished and Callback) then
  1372. Callback();
  1373. end;
  1374. end);
  1375.  
  1376. if (self.animation) then
  1377. self.animation:Start(speed);
  1378. end;
  1379.  
  1380. Clockwork.option:PlaySound("click_release");
  1381. else
  1382. self:SetVisible(true);
  1383. self:SetAlpha(255);
  1384.  
  1385. if (Callback) then
  1386. Callback();
  1387. end;
  1388. end;
  1389. end;
  1390.  
  1391. -- Called each frame.
  1392. function PANEL:Think()
  1393. self:InvalidateLayout(true);
  1394.  
  1395. if (self.helpText) then
  1396. local pointsLeft = self.maximumPoints;
  1397.  
  1398. for k, v in pairs(self.attributePanels) do
  1399. pointsLeft = pointsLeft - v:GetTotalPoints();
  1400. end;
  1401.  
  1402. self.helpText:SetText("You can spend "..pointsLeft.." more point(s).");
  1403. end;
  1404.  
  1405. if (self.animation) then
  1406. self.animation:Run();
  1407. end;
  1408. end;
  1409.  
  1410. -- Called when the layout should be performed.
  1411. function PANEL:PerformLayout(w, h)
  1412. self.categoryList:StretchToParent(0, 0, 0, 0);
  1413. self:SetSize(512, math.min(self.categoryList.pnlCanvas:GetTall() + 8, ScrH() * 0.6));
  1414. end;
  1415.  
  1416. vgui.Register("cwCharacterStageFour", PANEL, "EditablePanel");
  1417.  
  1418. local PANEL = {};
  1419.  
  1420. -- Called when the panel is initialized.
  1421. function PANEL:Init()
  1422. self.info = Clockwork.character:GetCreationInfo();
  1423.  
  1424. self.classesForm = vgui.Create("DForm");
  1425. self.classesForm:SetName("Classes");
  1426. self.classesForm:SetPadding(4);
  1427.  
  1428. self.categoryList = vgui.Create("DCategoryList", self);
  1429. self.categoryList:SetPadding(2);
  1430. self.categoryList:SizeToContents();
  1431.  
  1432. for k, v in pairs(Clockwork.class:GetAll()) do
  1433. if (v.isOnCharScreen and (v.factions and table.HasValue(v.factions, self.info.faction))) then
  1434. self.classTable = v;
  1435. self.overrideData = {
  1436. information = "Select this to make it your character's default class.",
  1437. Callback = function()
  1438. self.info.class = v.index;
  1439. end
  1440. };
  1441. self.classForm:AddItem(vgui.Create("cwClassesItem", self));
  1442. end;
  1443. end;
  1444.  
  1445. self.categoryList:AddItem(self.classForm);
  1446. end;
  1447.  
  1448. -- Called when the panel is painted.
  1449. function PANEL:Paint(w, h) end;
  1450.  
  1451. -- A function to make the panel fade out.
  1452. function PANEL:FadeOut(speed, Callback)
  1453. if (self:GetAlpha() > 0 and (!self.animation or !self.animation:Active())) then
  1454. self.animation = Derma_Anim("Fade Panel", self, function(panel, animation, delta, data)
  1455. panel:SetAlpha(255 - (delta * 255));
  1456.  
  1457. if (animation.Finished) then
  1458. panel:SetVisible(false);
  1459. end;
  1460.  
  1461. if (animation.Finished and Callback) then
  1462. Callback();
  1463. end;
  1464. end);
  1465.  
  1466. if (self.animation) then
  1467. self.animation:Start(speed);
  1468. end;
  1469.  
  1470. Clockwork.option:PlaySound("rollover");
  1471. else
  1472. self:SetVisible(false);
  1473. self:SetAlpha(0);
  1474.  
  1475. if (Callback) then
  1476. Callback();
  1477. end;
  1478. end;
  1479. end;
  1480.  
  1481. -- A function to make the panel fade in.
  1482. function PANEL:FadeIn(speed, Callback)
  1483. if (self:GetAlpha() == 0 and (!self.animation or !self.animation:Active())) then
  1484. self.animation = Derma_Anim("Fade Panel", self, function(panel, animation, delta, data)
  1485. panel:SetVisible(true);
  1486. panel:SetAlpha(delta * 255);
  1487.  
  1488. if (animation.Finished) then
  1489. self.animation = nil;
  1490. end;
  1491.  
  1492. if (animation.Finished and Callback) then
  1493. Callback();
  1494. end;
  1495. end);
  1496.  
  1497. if (self.animation) then
  1498. self.animation:Start(speed);
  1499. end;
  1500.  
  1501. Clockwork.option:PlaySound("click_release");
  1502. else
  1503. self:SetVisible(true);
  1504. self:SetAlpha(255);
  1505.  
  1506. if (Callback) then
  1507. Callback();
  1508. end;
  1509. end;
  1510. end;
  1511.  
  1512. -- Called each frame.
  1513. function PANEL:Think()
  1514. self:InvalidateLayout(true);
  1515.  
  1516. if (self.animation) then
  1517. self.animation:Run();
  1518. end;
  1519. end;
  1520.  
  1521. -- Called when the next button is pressed.
  1522. function PANEL:OnNext()
  1523. if (!self.info.class or !Clockwork.class:FindByID(self.info.class)) then
  1524. Clockwork.character:SetFault("You did not choose a class, or the class that you chose is not valid!");
  1525. return false;
  1526. end;
  1527. end;
  1528.  
  1529. -- Called when the layout should be performed.
  1530. function PANEL:PerformLayout(w, h)
  1531. self.categoryList:StretchToParent(0, 0, 0, 0);
  1532. self:SetSize(512, math.min(self.categoryList.pnlCanvas:GetTall() + 8, ScrH() * 0.6));
  1533. end;
  1534.  
  1535. vgui.Register("cwCharacterStageThree", PANEL, "EditablePanel");
  1536.  
  1537. local PANEL = {};
  1538.  
  1539. -- Called when the panel is initialized.
  1540. function PANEL:Init()
  1541. local smallTextFont = Clockwork.option:GetFont("menu_text_small");
  1542. local panel = Clockwork.character:GetPanel();
  1543.  
  1544. self.categoryList = vgui.Create("DCategoryList", self);
  1545. self.categoryList:SetPadding(2);
  1546. self.categoryList:SizeToContents();
  1547.  
  1548. self.overrideModel = nil;
  1549. self.bSelectModel = nil;
  1550. self.bPhysDesc = (Clockwork.command:FindByID("CharPhysDesc") != nil);
  1551. self.info = Clockwork.character:GetCreationInfo();
  1552.  
  1553. if (!Clockwork.faction.stored[self.info.faction].GetModel) then
  1554. self.bSelectModel = true;
  1555. end;
  1556.  
  1557. local genderModels = Clockwork.faction.stored[self.info.faction].models[string.lower(self.info.gender)];
  1558.  
  1559. if (genderModels and #genderModels == 1) then
  1560. self.bSelectModel = false;
  1561. self.overrideModel = genderModels[1];
  1562.  
  1563. if (!panel:FadeInModelPanel(self.overrideModel)) then
  1564. panel:SetModelPanelModel(self.overrideModel);
  1565. end;
  1566. end;
  1567.  
  1568. if (!Clockwork.faction.stored[self.info.faction].GetName) then
  1569. self.nameForm = vgui.Create("DForm", self);
  1570. self.nameForm:SetPadding(4);
  1571. self.nameForm:SetName("Name");
  1572.  
  1573. if (Clockwork.faction.stored[self.info.faction].useFullName) then
  1574. self.fullNameTextEntry = self.nameForm:TextEntry("Full Name");
  1575. self.fullNameTextEntry:SetAllowNonAsciiCharacters(true);
  1576. else
  1577. self.forenameTextEntry = self.nameForm:TextEntry("Forename");
  1578. self.forenameTextEntry:SetAllowNonAsciiCharacters(true);
  1579.  
  1580. self.surnameTextEntry = self.nameForm:TextEntry("Surname");
  1581. self.surnameTextEntry:SetAllowNonAsciiCharacters(true);
  1582. end;
  1583. end;
  1584.  
  1585. if (self.bSelectModel or self.bPhysDesc) then
  1586. self.appearanceForm = vgui.Create("DForm");
  1587. self.appearanceForm:SetPadding(4);
  1588. self.appearanceForm:SetName("Appearance");
  1589.  
  1590. if (self.bPhysDesc and self.bSelectModel) then
  1591. self.appearanceForm:Help("Write a physical description for your character in full English, and select an appropriate model.");
  1592. elseif (self.bPhysDesc) then
  1593. self.appearanceForm:Help("Write a physical description for your character in full English.");
  1594. end;
  1595.  
  1596. if (self.bPhysDesc) then
  1597. self.physDescTextEntry = self.appearanceForm:TextEntry("Description");
  1598. self.physDescTextEntry:SetAllowNonAsciiCharacters(true);
  1599. end;
  1600.  
  1601. if (self.bSelectModel) then
  1602. self.modelItemsList = vgui.Create("DPanelList", self);
  1603. self.modelItemsList:SetPadding(4);
  1604. self.modelItemsList:SetSpacing(16);
  1605. self.modelItemsList:EnableHorizontal(true);
  1606. self.modelItemsList:EnableVerticalScrollbar(true);
  1607. self.appearanceForm:AddItem(self.modelItemsList);
  1608. end;
  1609. end;
  1610.  
  1611. if (self.nameForm) then
  1612. self.categoryList:AddItem(self.nameForm);
  1613. end;
  1614.  
  1615. if (self.appearanceForm) then
  1616. self.categoryList:AddItem(self.appearanceForm);
  1617. end;
  1618.  
  1619. local informationColor = Clockwork.option:GetColor("information");
  1620. local lowerGender = string.lower(self.info.gender);
  1621. local spawnIcon = nil;
  1622.  
  1623. for k, v in pairs(Clockwork.faction.stored) do
  1624. if (v.name == self.info.faction) then
  1625. if (self.modelItemsList and v.models[lowerGender]) then
  1626. for k2, v2 in pairs(v.models[lowerGender]) do
  1627. spawnIcon = Clockwork.kernel:CreateMarkupToolTip(vgui.Create("cwSpawnIcon", self));
  1628. spawnIcon:SetModel(v2);
  1629.  
  1630. -- Called when the spawn icon is clicked.
  1631. function spawnIcon.DoClick(spawnIcon)
  1632. if (self.selectedSpawnIcon) then
  1633. self.selectedSpawnIcon:SetColor(nil);
  1634. end;
  1635.  
  1636. spawnIcon:SetColor(informationColor);
  1637.  
  1638. if (!panel:FadeInModelPanel(v2)) then
  1639. panel:SetModelPanelModel(v2);
  1640. end;
  1641.  
  1642. self.selectedSpawnIcon = spawnIcon;
  1643. self.selectedModel = v2;
  1644. end;
  1645.  
  1646. self.modelItemsList:AddItem(spawnIcon);
  1647. end;
  1648. end;
  1649. end;
  1650. end;
  1651. end;
  1652.  
  1653. -- Called when the next button is pressed.
  1654. function PANEL:OnNext()
  1655. if (self.overrideModel) then
  1656. self.info.model = self.overrideModel;
  1657. else
  1658. self.info.model = self.selectedModel;
  1659. end;
  1660.  
  1661. if (!Clockwork.faction.stored[self.info.faction].GetName) then
  1662. if (IsValid(self.fullNameTextEntry)) then
  1663. self.info.fullName = self.fullNameTextEntry:GetValue();
  1664.  
  1665. if (self.info.fullName == "") then
  1666. Clockwork.character:SetFault("You did not choose a name, or the name that you chose is not valid!");
  1667. return false;
  1668. end;
  1669. else
  1670. self.info.forename = self.forenameTextEntry:GetValue();
  1671. self.info.surname = self.surnameTextEntry:GetValue();
  1672.  
  1673. if (self.info.forename == "" or self.info.surname == "") then
  1674. Clockwork.character:SetFault("You did not choose a name, or the name that you chose is not valid!");
  1675. return false;
  1676. end;
  1677.  
  1678. if (string.find(self.info.forename, "[%p%s%d]") or string.find(self.info.surname, "[%p%s%d]")) then
  1679. Clockwork.character:SetFault("Your forename and surname must not contain punctuation, spaces or digits!");
  1680. return false;
  1681. end;
  1682.  
  1683. if (!string.find(self.info.forename, "[aeiou]") or !string.find(self.info.surname, "[aeiou]")) then
  1684. Clockwork.character:SetFault("Your forename and surname must both contain at least one vowel!");
  1685. return false;
  1686. end;
  1687.  
  1688. if (string.len(self.info.forename) < 2 or string.len(self.info.surname) < 2) then
  1689. Clockwork.character:SetFault("Your forename and surname must both be at least 2 characters long!");
  1690. return false;
  1691. end;
  1692.  
  1693. if (string.len(self.info.forename) > 16 or string.len(self.info.surname) > 16) then
  1694. Clockwork.character:SetFault("Your forename and surname must not be greater than 16 characters long!");
  1695. return false;
  1696. end;
  1697. end;
  1698. end;
  1699.  
  1700. if (self.bSelectModel and !self.info.model) then
  1701. Clockwork.character:SetFault("You did not choose a model, or the model that you chose is not valid!");
  1702. return false;
  1703. end;
  1704.  
  1705. if (self.bPhysDesc) then
  1706. local minimumPhysDesc = Clockwork.config:Get("minimum_physdesc"):Get();
  1707. self.info.physDesc = self.physDescTextEntry:GetValue();
  1708. if (string.len(self.info.physDesc) < minimumPhysDesc) then
  1709. Clockwork.character:SetFault("The physical description must be at least "..minimumPhysDesc.." characters long!");
  1710. return false;
  1711. end;
  1712. end;
  1713. end;
  1714.  
  1715. -- Called when the panel is painted.
  1716. function PANEL:Paint(w, h) end;
  1717.  
  1718. -- A function to make the panel fade out.
  1719. function PANEL:FadeOut(speed, Callback)
  1720. if (self:GetAlpha() > 0 and (!self.animation or !self.animation:Active())) then
  1721. self.animation = Derma_Anim("Fade Panel", self, function(panel, animation, delta, data)
  1722. panel:SetAlpha(255 - (delta * 255));
  1723.  
  1724. if (animation.Finished) then
  1725. panel:SetVisible(false);
  1726. end;
  1727.  
  1728. if (animation.Finished and Callback) then
  1729. Callback();
  1730. end;
  1731. end);
  1732.  
  1733. if (self.animation) then
  1734. self.animation:Start(speed);
  1735. end;
  1736.  
  1737. Clockwork.option:PlaySound("rollover");
  1738. else
  1739. self:SetVisible(false);
  1740. self:SetAlpha(0);
  1741.  
  1742. if (Callback) then
  1743. Callback();
  1744. end;
  1745. end;
  1746. end;
  1747.  
  1748. -- A function to make the panel fade in.
  1749. function PANEL:FadeIn(speed, Callback)
  1750. if (self:GetAlpha() == 0 and (!self.animation or !self.animation:Active())) then
  1751. self.animation = Derma_Anim("Fade Panel", self, function(panel, animation, delta, data)
  1752. panel:SetVisible(true);
  1753. panel:SetAlpha(delta * 255);
  1754.  
  1755. if (animation.Finished) then
  1756. self.animation = nil;
  1757. end;
  1758.  
  1759. if (animation.Finished and Callback) then
  1760. Callback();
  1761. end;
  1762. end);
  1763.  
  1764. if (self.animation) then
  1765. self.animation:Start(speed);
  1766. end;
  1767.  
  1768. Clockwork.option:PlaySound("click_release");
  1769. else
  1770. self:SetVisible(true);
  1771. self:SetAlpha(255);
  1772.  
  1773. if (Callback) then
  1774. Callback();
  1775. end;
  1776. end;
  1777. end;
  1778.  
  1779. -- Called each frame.
  1780. function PANEL:Think()
  1781. self:InvalidateLayout(true);
  1782.  
  1783. if (self.animation) then
  1784. self.animation:Run();
  1785. end;
  1786. end;
  1787.  
  1788. -- Called when the layout should be performed.
  1789. function PANEL:PerformLayout(w, h)
  1790. self.categoryList:StretchToParent(0, 0, 0, 0);
  1791.  
  1792. if (IsValid(self.modelItemsList)) then
  1793. self.modelItemsList:SetTall(256);
  1794. end;
  1795.  
  1796. self:SetSize(512, math.min(self.categoryList.pnlCanvas:GetTall() + 8, ScrH() * 0.6));
  1797. end;
  1798.  
  1799. vgui.Register("cwCharacterStageTwo", PANEL, "EditablePanel");
  1800.  
  1801. local PANEL = {};
  1802.  
  1803. -- Called when the panel is initialized.
  1804. function PANEL:Init()
  1805. local smallTextFont = Clockwork.option:GetFont("menu_text_small");
  1806. local factions = {};
  1807.  
  1808. for k, v in pairs(Clockwork.faction.stored) do
  1809. if (!v.whitelist or Clockwork.character:IsWhitelisted(v.name)) then
  1810. if (!Clockwork.faction:HasReachedMaximum(k)) then
  1811. factions[#factions + 1] = v.name;
  1812. end;
  1813. end;
  1814. end;
  1815.  
  1816. table.sort(factions, function(a, b)
  1817. return a < b;
  1818. end);
  1819.  
  1820. self.forcedFaction = nil;
  1821. self.info = Clockwork.character:GetCreationInfo();
  1822.  
  1823. self.categoryList = vgui.Create("DCategoryList", self);
  1824. self.categoryList:SetPadding(2);
  1825. self.categoryList:SizeToContents();
  1826.  
  1827. self.settingsForm = vgui.Create("DForm");
  1828. self.settingsForm:SetName("Settings");
  1829. self.settingsForm:SetPadding(4);
  1830.  
  1831. if (#factions > 1) then
  1832. self.settingsForm:Help("The faction defines the overall character and can most likely be unchanged.");
  1833. self.factionMultiChoice = self.settingsForm:ComboBox("Faction");
  1834.  
  1835. -- Called when an option is selected.
  1836. self.factionMultiChoice.OnSelect = function(multiChoice, index, value, data)
  1837. for k, v in pairs(Clockwork.faction.stored) do
  1838. if (v.name == value) then
  1839. if (IsValid(self.genderMultiChoice)) then
  1840. self.genderMultiChoice:Clear();
  1841. else
  1842. self.genderMultiChoice = self.settingsForm:ComboBox("Gender");
  1843. self.settingsForm:Rebuild();
  1844. end;
  1845.  
  1846. if (v.singleGender) then
  1847. self.genderMultiChoice:AddChoice(v.singleGender);
  1848. else
  1849. self.genderMultiChoice:AddChoice(GENDER_FEMALE);
  1850. self.genderMultiChoice:AddChoice(GENDER_MALE);
  1851. end;
  1852.  
  1853. Clockwork.CurrentFactionSelected = {self, value};
  1854.  
  1855. break;
  1856. end;
  1857. end;
  1858. end;
  1859. elseif (#factions == 1) then
  1860. for k, v in pairs(Clockwork.faction.stored) do
  1861. if (v.name == factions[1]) then
  1862. self.genderMultiChoice = self.settingsForm:ComboBox("Gender");
  1863.  
  1864. if (v.singleGender) then
  1865. self.genderMultiChoice:AddChoice(v.singleGender);
  1866. else
  1867. self.genderMultiChoice:AddChoice(GENDER_FEMALE);
  1868. self.genderMultiChoice:AddChoice(GENDER_MALE);
  1869. end;
  1870.  
  1871. Clockwork.CurrentFactionSelected = {self, v.name};
  1872. self.forcedFaction = v.name;
  1873.  
  1874. break;
  1875. end;
  1876. end;
  1877. end;
  1878.  
  1879. if (self.factionMultiChoice) then
  1880. for k, v in pairs(factions) do
  1881. self.factionMultiChoice:AddChoice(v);
  1882. end;
  1883. end;
  1884.  
  1885. self.categoryList:AddItem(self.settingsForm);
  1886. end;
  1887.  
  1888. -- Called when the next button is pressed.
  1889. function PANEL:OnNext()
  1890. if (IsValid(self.genderMultiChoice)) then
  1891. local faction = self.forcedFaction;
  1892. local gender = self.genderMultiChoice:GetValue();
  1893.  
  1894. if (!faction and self.factionMultiChoice) then
  1895. faction = self.factionMultiChoice:GetValue();
  1896. end;
  1897.  
  1898. for k, v in pairs(Clockwork.faction.stored) do
  1899. if (v.name == faction) then
  1900. if (Clockwork.faction:IsGenderValid(faction, gender)) then
  1901. self.info.faction = faction;
  1902. self.info.gender = gender;
  1903. return true;
  1904. end;
  1905. end;
  1906. end;
  1907. end;
  1908.  
  1909. Clockwork.character:SetFault("You did not choose a faction or the one you have chosen is not valid!");
  1910. return false;
  1911. end;
  1912.  
  1913. -- Called when the panel is painted.
  1914. function PANEL:Paint(w, h) end;
  1915.  
  1916. -- A function to make the panel fade out.
  1917. function PANEL:FadeOut(speed, Callback)
  1918. if (self:GetAlpha() > 0 and (!self.animation or !self.animation:Active())) then
  1919. self.animation = Derma_Anim("Fade Panel", self, function(panel, animation, delta, data)
  1920. panel:SetAlpha(255 - (delta * 255));
  1921.  
  1922. if (animation.Finished) then
  1923. panel:SetVisible(false);
  1924. end;
  1925.  
  1926. if (animation.Finished and Callback) then
  1927. Callback();
  1928. end;
  1929. end);
  1930.  
  1931. if (self.animation) then
  1932. self.animation:Start(speed);
  1933. end;
  1934.  
  1935. Clockwork.option:PlaySound("rollover");
  1936. else
  1937. self:SetVisible(false);
  1938. self:SetAlpha(0);
  1939.  
  1940. if (Callback) then
  1941. Callback();
  1942. end;
  1943. end;
  1944. end;
  1945.  
  1946. -- A function to make the panel fade in.
  1947. function PANEL:FadeIn(speed, Callback)
  1948. if (self:GetAlpha() == 0 and (!self.animation or !self.animation:Active())) then
  1949. self.animation = Derma_Anim("Fade Panel", self, function(panel, animation, delta, data)
  1950. panel:SetVisible(true);
  1951. panel:SetAlpha(delta * 255);
  1952.  
  1953. if (animation.Finished) then
  1954. self.animation = nil;
  1955. end;
  1956.  
  1957. if (animation.Finished and Callback) then
  1958. Callback();
  1959. end;
  1960. end);
  1961.  
  1962. if (self.animation) then
  1963. self.animation:Start(speed);
  1964. end;
  1965.  
  1966. Clockwork.option:PlaySound("click_release");
  1967. else
  1968. self:SetVisible(true);
  1969. self:SetAlpha(255);
  1970.  
  1971. if (Callback) then
  1972. Callback();
  1973. end;
  1974. end;
  1975. end;
  1976.  
  1977. -- Called each frame.
  1978. function PANEL:Think()
  1979. self:InvalidateLayout(true);
  1980.  
  1981. if (self.animation) then
  1982. self.animation:Run();
  1983. end;
  1984. end;
  1985.  
  1986. -- Called when the layout should be performed.
  1987. function PANEL:PerformLayout(w, h)
  1988. self.categoryList:StretchToParent(0, 0, 0, 0);
  1989. self:SetSize(512, math.min(self.categoryList.pnlCanvas:GetTall() + 8, ScrH() * 0.6));
  1990. end;
  1991.  
  1992. vgui.Register("cwCharacterStageOne", PANEL, "EditablePanel");
  1993.  
  1994. Clockwork.datastream:Hook("CharacterRemove", function(data)
  1995. local characters = Clockwork.character:GetAll();
  1996. local characterID = data;
  1997.  
  1998. if (table.Count(characters) == 0) then
  1999. return;
  2000. end;
  2001.  
  2002.  
  2003. if (!characters[characterID]) then
  2004. return;
  2005. end;
  2006.  
  2007. characters[characterID] = nil;
  2008.  
  2009. if (!Clockwork.character:IsPanelLoading()) then
  2010. Clockwork.character:RefreshPanelList();
  2011. end;
  2012.  
  2013. if (Clockwork.character:GetPanelList()) then
  2014. if (table.Count(characters) == 0) then
  2015. Clockwork.character:GetPanel():ReturnToMainMenu();
  2016. end;
  2017. end;
  2018. end);
  2019.  
  2020. Clockwork.datastream:Hook("SetWhitelisted", function(data)
  2021. local whitelisted = Clockwork.character:GetWhitelisted();
  2022.  
  2023. for k, v in pairs(whitelisted) do
  2024. if (v == data[1]) then
  2025. if (!data[2]) then
  2026. whitelisted[k] = nil;
  2027.  
  2028. return;
  2029. end;
  2030. end;
  2031. end;
  2032.  
  2033. if (data[2]) then
  2034. whitelisted[#whitelisted + 1] = data[1];
  2035. end;
  2036. end);
  2037.  
  2038. Clockwork.datastream:Hook("CharacterAdd", function(data)
  2039. Clockwork.character:Add(data.characterID, data);
  2040.  
  2041. if (!Clockwork.character:IsPanelLoading()) then
  2042. Clockwork.character:RefreshPanelList();
  2043. end;
  2044. end);
  2045.  
  2046. Clockwork.datastream:Hook("CharacterMenu", function(data)
  2047. local menuState = data;
  2048.  
  2049. if (menuState == CHARACTER_MENU_LOADED) then
  2050. if (Clockwork.character:GetPanel()) then
  2051. Clockwork.character:SetPanelLoading(false);
  2052. Clockwork.character:RefreshPanelList();
  2053. end;
  2054. elseif (menuState == CHARACTER_MENU_CLOSE) then
  2055. Clockwork.character:SetPanelOpen(false);
  2056. elseif (menuState == CHARACTER_MENU_OPEN) then
  2057. Clockwork.character:SetPanelOpen(true);
  2058. end;
  2059. end);
  2060.  
  2061. Clockwork.datastream:Hook("CharacterOpen", function(data)
  2062. Clockwork.character:SetPanelOpen(true);
  2063.  
  2064. if (data) then
  2065. Clockwork.character.isMenuReset = true;
  2066. end;
  2067. end);
  2068.  
  2069. Clockwork.datastream:Hook("CharacterFinish", function(data)
  2070. if (data.bSuccess) then
  2071. Clockwork.character:SetPanelMainMenu();
  2072. Clockwork.character:SetPanelOpen(false, true);
  2073. Clockwork.character:SetFault(nil);
  2074. else
  2075. Clockwork.character:SetFault(data.fault);
  2076. end;
  2077. end);
  2078.  
  2079. Clockwork.character:RegisterCreationPanel("Persuasion", "cwCharacterStageOne");
  2080. Clockwork.character:RegisterCreationPanel("Description", "cwCharacterStageTwo");
  2081.  
  2082. Clockwork.character:RegisterCreationPanel("Default Class", "cwCharacterStageThree",
  2083. function(info)
  2084. local classTable = Clockwork.class:GetAll();
  2085.  
  2086. if (table.Count(classTable) > 0) then
  2087. for k, v in pairs(classTable) do
  2088. if (v.isOnCharScreen and (v.factions
  2089. and table.HasValue(v.factions, info.faction))) then
  2090. return true;
  2091. end;
  2092. end;
  2093. end;
  2094.  
  2095. return false;
  2096. end
  2097. );
  2098.  
  2099. Clockwork.character:RegisterCreationPanel(
  2100. Clockwork.option:GetKey("name_attributes"), "cwCharacterStageFour",
  2101. function(info)
  2102. local attributeTable = Clockwork.attribute:GetAll();
  2103.  
  2104. if (table.Count(attributeTable) > 0) then
  2105. for k, v in pairs(attributeTable) do
  2106. if (v.isOnCharScreen) then
  2107. return true;
  2108. end;
  2109. end;
  2110. end;
  2111.  
  2112. return false;
  2113. end
  2114. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement