ProjectModuleCard.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. function ProjectModuleCard::onAdd(%this)
  2. {
  3. %this.toggleLaunchGroupCount = 0;
  4. %this.chain = new GuiChainCtrl()
  5. {
  6. HorizSizing="width";
  7. VertSizing="height";
  8. Position = "0 0";
  9. Extent = "286 100";
  10. IsVertical = "1";
  11. ChildSpacing = -4;
  12. };
  13. ThemeManager.setProfile(%this.chain, "emptyProfile");
  14. %this.add(%this.chain);
  15. %this.titleText = new GuiControl()
  16. {
  17. HorizSizing="width";
  18. Position = "0 13";
  19. Extent = "286 38";
  20. Text = "";
  21. FontSizeAdjust = "1.4";
  22. };
  23. ThemeManager.setProfile(%this.titleText, "titleProfile");
  24. %this.chain.add(%this.titleText);
  25. %this.authorText = new GuiControl()
  26. {
  27. HorizSizing="width";
  28. Position = "0 0";
  29. Extent = "180 22";
  30. MinExtent = "180 22";
  31. Text = "Module by Torque2D";
  32. TextWrap = 1;
  33. TextExtend = 1;
  34. FontSizeAdjust = "1.1";
  35. FontColor = ThemeManager.activeTheme.color5;
  36. OverrideFontColor = true;
  37. };
  38. ThemeManager.setProfile(%this.authorText, "codeProfile");
  39. %this.chain.add(%this.authorText);
  40. %this.versionText = new GuiControl()
  41. {
  42. HorizSizing="width";
  43. Position = "0 0";
  44. Extent = "180 26";
  45. Text = "Version: 1 Build: 1";
  46. FontColor = ThemeManager.activeTheme.setAlpha(ThemeManager.activeTheme.color4, 150);
  47. OverrideFontColor = true;
  48. };
  49. ThemeManager.setProfile(%this.versionText, "codeProfile");
  50. %this.chain.add(%this.versionText);
  51. %this.addSpacer(%this.chain);
  52. %this.descriptionText = new GuiControl()
  53. {
  54. HorizSizing="width";
  55. Position = "0 10";
  56. Extent = "286 150";
  57. MinExtent = "250 150";
  58. Text = "";
  59. TextWrap = 1;
  60. TextExtend = 1;
  61. };
  62. ThemeManager.setProfile(%this.descriptionText, "normalTextProfile");
  63. %this.chain.add(%this.descriptionText);
  64. %this.optionGroup = %this.addSubSection("Module Options");
  65. %this.launchGroupCheckBox = new GuiCheckBoxCtrl()
  66. {
  67. Class="ProjectManagerLaunchGroupCheckBox";
  68. HorizSizing="width";
  69. Position = "0 0";
  70. Extent = "286 26";
  71. Text = "Start on Project Launch";
  72. BoxOffset = "0 2";
  73. TextOffset = "22 0";
  74. TextExtent = "264 26";
  75. vAlign = "Middle";
  76. Tooltip = "This change will be applied after restarting.";
  77. };
  78. ThemeManager.setProfile(%this.launchGroupCheckBox, "checkboxProfile");
  79. ThemeManager.setProfile(%this.launchGroupCheckBox, "tipProfile", "TooltipProfile");
  80. %this.optionGroup.add(%this.launchGroupCheckBox);
  81. %this.launchGroupCheckBox.addListener(%this);
  82. %this.addEmptySpace(30, %this.optionGroup);
  83. %this.addSubSection("Dependencies");
  84. %this.dependList = new GuiChainCtrl()
  85. {
  86. Class = ProjectModuleDependList;
  87. HorizSizing="width";
  88. VertSizing="height";
  89. Position = "0 0";
  90. Extent = "286 100";
  91. IsVertical = "1";
  92. ChildSpacing = 2;
  93. };
  94. ThemeManager.setProfile(%this.dependList, "emptyProfile");
  95. %this.chain.add(%this.dependList);
  96. %this.button = new GuiButtonCtrl()
  97. {
  98. Class="ProjectModuleCardButton";
  99. HorizSizing="left";
  100. VertSizing="bottom";
  101. Position = "184 40";
  102. Extent = "100 30";
  103. MinExtent = "100 30";
  104. Text = "";
  105. };
  106. ThemeManager.setProfile(%this.button, "primaryButtonProfile");
  107. %this.add(%this.button);
  108. %this.startListening(%this.button);
  109. %this.startListening(ThemeManager);
  110. }
  111. function ProjectModuleCard::addSubSection(%this, %name)
  112. {
  113. %chain = new GuiChainCtrl()
  114. {
  115. HorizSizing="width";
  116. VertSizing="height";
  117. Position = "0 0";
  118. Extent = "286 0";
  119. IsVertical = "1";
  120. ChildSpacing = -4;
  121. };
  122. ThemeManager.setProfile(%chain, "emptyProfile");
  123. %this.chain.add(%chain);
  124. %subSection = new GuiControl()
  125. {
  126. HorizSizing="width";
  127. Extent = "286 24";
  128. Text = %name;
  129. FontSizeAdjust = "0.8";
  130. };
  131. ThemeManager.setProfile(%subSection, "titleProfile");
  132. %chain.add(%subSection);
  133. %this.addSpacer(%chain);
  134. %this.addEmptySpace(8, %chain);
  135. return %chain;
  136. }
  137. function ProjectModuleCard::addSpacer(%this, %chain)
  138. {
  139. %spacer = new GuiControl()
  140. {
  141. HorizSizing="width";
  142. Position = "0 0";
  143. Extent = "286 6";
  144. };
  145. ThemeManager.setProfile(%spacer, "spacerProfile");
  146. %chain.add(%spacer);
  147. return %spacer;
  148. }
  149. function ProjectModuleCard::addEmptySpace(%this, %size, %chain)
  150. {
  151. %empty = new GuiControl()
  152. {
  153. HorizSizing="width";
  154. Position = "0 0";
  155. Extent = "286" SPC %size;
  156. };
  157. ThemeManager.setProfile(%empty, "emptyProfile");
  158. %chain.add(%empty);
  159. return %empty;
  160. }
  161. function ProjectModuleCard::onThemeChange(%this, %theme)
  162. {
  163. %this.authorText.FontColor = %theme.color5;
  164. %this.versionText.FontColor = %theme.setAlpha(%theme.color4, 150);
  165. }
  166. function ProjectModuleCard::show(%this, %module)
  167. {
  168. if(isObject(%module))
  169. {
  170. %this.activeModule = %module;
  171. %this.moduleID = %module.moduleID;
  172. %this.versionID = %module.versionID;
  173. %this.titleText.setText(%module.moduleID);
  174. %this.setAuthor(%module);
  175. %this.setVersion(%module);
  176. %this.descriptionText.setText(%module.description);
  177. %this.button.visible = false;
  178. %projectModule = %this.getInstalledModule(%module.moduleID, %module.versionID);
  179. if(%projectModule != %module)
  180. {
  181. if(!isObject(%projectModule))
  182. {
  183. %this.button.setText("Install");
  184. %this.button.visible = true;
  185. }
  186. else if(%projectmodule.buildID < %module.buildID)
  187. {
  188. %this.button.setText("Update");
  189. %this.button.visible = true;
  190. }
  191. }
  192. else
  193. {
  194. }
  195. %this.optionGroup.visible = false;
  196. if(!%module.Synchronized)
  197. {
  198. %this.optionGroup.visible = true;
  199. %this.launchGroupCheckBox.setStateOn(%module.Group $= "launch");
  200. for(%i = 0; %i < %this.toggleLaunchGroupCount; %i++)
  201. {
  202. if(%this.toggleLaunchGroup[%i] $= %this.activeModule.getModulePath())
  203. {
  204. %this.launchGroupCheckBox.setStateOn(!%this.launchGroupCheckBox.getStateOn());
  205. break;
  206. }
  207. }
  208. }
  209. %this.visible = true;
  210. %this.dependList.show(%module);
  211. }
  212. }
  213. function ProjectModuleCard::hide(%this)
  214. {
  215. %this.activeModule = 0;
  216. %this.moduleID = "";
  217. %this.versionID = 0;
  218. %this.visible = false;
  219. }
  220. function ProjectModuleCard::setAuthor(%this, %module)
  221. {
  222. %author = %module.author;
  223. if(%author $= "")
  224. {
  225. %author = "Torque2D";
  226. }
  227. %type = %module.type;
  228. if(%type $= "")
  229. {
  230. %type = "Module";
  231. }
  232. %this.authorText.setText(%type SPC "by" SPC %author);
  233. }
  234. function ProjectModuleCard::setVersion(%this, %module)
  235. {
  236. %version = %module.versionID;
  237. if(%version $= "")
  238. {
  239. %version = 1;
  240. }
  241. %build = %module.buildID;
  242. if(%build $= "")
  243. {
  244. %build = 0;
  245. }
  246. %this.versionText.setText("Version:" SPC %version @ " Build:" SPC %build);
  247. }
  248. function ProjectModuleCard::getInstalledModule(%this, %moduleID, %versionID)
  249. {
  250. %allModules = ModuleDatabase.findModules(false);
  251. %count = getWordCount(%allModules);
  252. for(%i = 0; %i < %count; %i++)
  253. {
  254. %projectModule = getWord(%allModules, %i);
  255. if(%moduleID $= %projectModule.ModuleID && %versionID == %projectModule.VersionID)
  256. {
  257. return %projectModule;
  258. }
  259. }
  260. return 0;
  261. }
  262. function ProjectModuleCardButton::onClick(%this)
  263. {
  264. %this.postEvent("ButtonClick");
  265. }
  266. function ProjectModuleCard::onButtonClick(%this)
  267. {
  268. %this.postEvent(%this.button.getText() @ "Click");
  269. }
  270. function ProjectManagerLaunchGroupCheckBox::onClick(%this)
  271. {
  272. %state = %this.getStateOn();
  273. %this.postEvent("LauchGroupClick", %state);
  274. }
  275. function ProjectModuleCard::onLauchGroupClick(%this, %state)
  276. {
  277. %this.startListening(ProjectManager);
  278. if(isObject(%this.activeModule))
  279. {
  280. if((%state && %this.activeModule.group $= "launch") || (!%state && %this.activeModule.group !$= "launch"))
  281. {
  282. %path = %this.activeModule.getModulePath();
  283. for(%i = 0; %i < %this.toggleLaunchGroupCount; %i++)
  284. {
  285. if(%this.toggleLaunchGroup[%i] $= %path)
  286. {
  287. %this.toggleLaunchGroup[%i] = "";
  288. }
  289. }
  290. }
  291. else
  292. {
  293. %this.toggleLaunchGroup[%this.toggleLaunchGroupCount] = %this.activeModule.getModulePath();
  294. %this.toggleLaunchGroupCount++;
  295. }
  296. }
  297. }
  298. function ProjectModuleCard::onShutDown(%this)
  299. {
  300. for(%i = 0; %i < %this.toggleLaunchGroupCount; %i++)
  301. {
  302. %path = pathConcat(%this.toggleLaunchGroup[%i], "module.taml");
  303. if(%path !$= "" && isFile(%path))
  304. {
  305. %this.toggleLaunchGroupForPath(%path);
  306. }
  307. }
  308. }
  309. function ProjectModuleCard::toggleLaunchGroupForPath(%this, %path)
  310. {
  311. %module = TamlRead(%path);
  312. if(%module.group $= "launch")
  313. {
  314. %module.group = "";
  315. }
  316. else
  317. {
  318. %module.group = "launch";
  319. }
  320. TamlWrite(%module, %path);
  321. }