Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.86 KB | None | 0 0
  1. local PANEL = {};
  2.  
  3. -- Called when the panel is initialized.
  4. function PANEL:Init()
  5. local smallTextFont = Clockwork.option:GetFont("menu_text_small");
  6. local minimum = tostring(math.floor(Clockwork.config:Get("minimum_age"):Get()));
  7. local maximum = tostring(math.floor(Clockwork.config:Get("maximum_age"):Get()));
  8. local minimum = tostring(math.floor(Clockwork.config:Get("minimum_city"):Get()));
  9. local maximum = tostring(math.floor(Clockwork.config:Get("maximum_city"):Get()));
  10. local factions = {};
  11.  
  12. for k, v in pairs(Clockwork.faction.stored) do
  13. if (!v.whitelist or Clockwork.character:IsWhitelisted(v.name)) then
  14. if (!Clockwork.faction:HasReachedMaximum(k)) then
  15. factions[#factions + 1] = v.name;
  16. end;
  17. end;
  18. end;
  19.  
  20. table.sort(factions, function(a, b)
  21. return a < b;
  22. end);
  23.  
  24. self.forcedFaction = nil;
  25. self.info = Clockwork.character:GetCreationInfo();
  26.  
  27. self.categoryList = vgui.Create("DCategoryList", self);
  28. self.categoryList:SetPadding(2);
  29. self.categoryList:SizeToContents();
  30.  
  31. self.settingsForm = vgui.Create("DForm");
  32. self.settingsForm:SetName("Character Creation");
  33. self.settingsForm:SetPadding(4);
  34.  
  35. local label = vgui.Create("cwInfoText", self);
  36. label:SetText("Choose your age.");
  37. label:SetInfoColor("blue");
  38. self.settingsForm:AddItem(label);
  39.  
  40. --self.settingsForm:Help("NB: Choose your age.");
  41. self.age = self.settingsForm:TextEntry("Age");
  42.  
  43. if (#city > 1) then
  44. --self.settingsForm:Help("Choose your originating city.");
  45. self.cityMultiChoice = self.settingsForm:ComboBox("City");
  46.  
  47. -- Called when an option is selected.
  48. self.cityMultiChoice.OnSelect = function(multiChoice, index, value, data)
  49. for k, v in pairs(Clockwork.city.stored) do
  50. if (v.name == value) then
  51. if (IsValid(self.cityMultiChoice)) then
  52. self.cityMultiChoice:Clear();
  53. else
  54. self.cityMultiChoice = self.settingsForm:ComboBox("City");
  55. self.settingsForm:Rebuild();
  56. end;
  57.  
  58. if (v.singleCity) then
  59. self.genderMultiChoice:AddChoice(v.singleCity);
  60. else
  61. self.cityMultiChoice:AddChoice("City 1");
  62. self.cityMultiChoice:AddChoice("City 2");
  63. end;
  64.  
  65. Clockwork.CurrentFactionSelected = {self, value};
  66.  
  67. break;
  68. end;
  69. end;
  70. end;
  71.  
  72. if (#factions > 1) then
  73. --self.settingsForm:Help("The faction defines the overall character and can most likely be unchanged.");
  74. self.factionMultiChoice = self.settingsForm:ComboBox("Faction");
  75.  
  76. -- Called when an option is selected.
  77. self.factionMultiChoice.OnSelect = function(multiChoice, index, value, data)
  78. for k, v in pairs(Clockwork.faction.stored) do
  79. if (v.name == value) then
  80. if (IsValid(self.genderMultiChoice)) then
  81. self.genderMultiChoice:Clear();
  82. else
  83. self.genderMultiChoice = self.settingsForm:ComboBox("Gender");
  84. self.settingsForm:Rebuild();
  85. end;
  86.  
  87. if (v.singleGender) then
  88. self.genderMultiChoice:AddChoice(v.singleGender);
  89. else
  90. self.genderMultiChoice:AddChoice(GENDER_FEMALE);
  91. self.genderMultiChoice:AddChoice(GENDER_MALE);
  92. end;
  93.  
  94. Clockwork.CurrentFactionSelected = {self, value};
  95.  
  96. break;
  97. end;
  98. end;
  99. end;
  100. elseif (#factions == 1) then
  101. for k, v in pairs(Clockwork.faction.stored) do
  102. if (v.name == factions[1]) then
  103. self.genderMultiChoice = self.settingsForm:ComboBox("Gender");
  104.  
  105. if (v.singleGender) then
  106. self.genderMultiChoice:AddChoice(v.singleGender);
  107. else
  108. self.genderMultiChoice:AddChoice(GENDER_FEMALE);
  109. self.genderMultiChoice:AddChoice(GENDER_MALE);
  110. end;
  111.  
  112. Clockwork.CurrentFactionSelected = {self, v.name};
  113. self.forcedFaction = v.name;
  114.  
  115. break;
  116. end;
  117. end;
  118. end;
  119.  
  120. if (self.factionMultiChoice) then
  121. for k, v in pairs(factions) do
  122. self.factionMultiChoice:AddChoice(v);
  123. end;
  124. end;
  125.  
  126. self.categoryList:AddItem(self.settingsForm);
  127. end;
  128.  
  129. -- Called when the next button is pressed.
  130. function PANEL:OnNext()
  131. local age = tonumber(self.info.age);
  132. local minimum = math.floor(Clockwork.config:Get("minimum_age"):Get());
  133. local maximum = math.floor(Clockwork.config:Get("maximum_age"):Get());
  134.  
  135. if (!age or age < minimum or age > maximum) then
  136. Clockwork.character:SetFault("You did not choose an age or the one you have chosen is not valid!");
  137.  
  138. return false;
  139. end;
  140.  
  141. if (IsValid(self.genderMultiChoice)) then
  142. local faction = self.forcedFaction;
  143. local gender = self.genderMultiChoice:GetValue();
  144.  
  145. if (!faction and self.factionMultiChoice) then
  146. faction = self.factionMultiChoice:GetValue();
  147. end;
  148.  
  149. for k, v in pairs(Clockwork.faction.stored) do
  150. if (v.name == faction) then
  151. if (Clockwork.faction:IsGenderValid(faction, gender)) then
  152. self.info.faction = faction;
  153. self.info.gender = gender;
  154. return true;
  155. end;
  156. end;
  157. end;
  158. end;
  159.  
  160. Clockwork.character:SetFault("You did not choose a faction or the one you have chosen is not valid!");
  161. return false;
  162. end;
  163.  
  164. -- Called when the panel is painted.
  165. function PANEL:Paint(w, h) end;
  166.  
  167. -- A function to make the panel fade out.
  168. function PANEL:FadeOut(speed, Callback)
  169. if (self:GetAlpha() > 0 and (!self.animation or !self.animation:Active())) then
  170. self.animation = Derma_Anim("Fade Panel", self, function(panel, animation, delta, data)
  171. panel:SetAlpha(255 - (delta * 255));
  172.  
  173. if (animation.Finished) then
  174. panel:SetVisible(false);
  175. end;
  176.  
  177. if (animation.Finished and Callback) then
  178. Callback();
  179. end;
  180. end);
  181.  
  182. if (self.animation) then
  183. self.animation:Start(speed);
  184. end;
  185.  
  186. Clockwork.option:PlaySound("rollover");
  187. else
  188. self:SetVisible(false);
  189. self:SetAlpha(0);
  190.  
  191. if (Callback) then
  192. Callback();
  193. end;
  194. end;
  195. end;
  196.  
  197. -- A function to make the panel fade in.
  198. function PANEL:FadeIn(speed, Callback)
  199. if (self:GetAlpha() == 0 and (!self.animation or !self.animation:Active())) then
  200. self.animation = Derma_Anim("Fade Panel", self, function(panel, animation, delta, data)
  201. panel:SetVisible(true);
  202. panel:SetAlpha(delta * 255);
  203.  
  204. if (animation.Finished) then
  205. self.animation = nil;
  206. end;
  207.  
  208. if (animation.Finished and Callback) then
  209. Callback();
  210. end;
  211. end);
  212.  
  213. if (self.animation) then
  214. self.animation:Start(speed);
  215. end;
  216.  
  217. Clockwork.option:PlaySound("click_release");
  218. else
  219. self:SetVisible(true);
  220. self:SetAlpha(255);
  221.  
  222. if (Callback) then
  223. Callback();
  224. end;
  225. end;
  226. end;
  227.  
  228. -- Called each frame.
  229. function PANEL:Think()
  230. self:InvalidateLayout(true);
  231.  
  232. if (self.animation) then
  233. self.animation:Run();
  234. end;
  235. end;
  236.  
  237. -- Called when the layout should be performed.
  238. function PANEL:PerformLayout(w, h)
  239. self.categoryList:StretchToParent(0, 0, 0, 0);
  240. self:SetSize(512, math.min(self.categoryList.pnlCanvas:GetTall() + 8, ScrH() * 0.6));
  241. end;
  242.  
  243. vgui.Register("cwCharacterStageOne", PANEL, "EditablePanel");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement