ProjectModuleCard.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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 80";
  57. MinExtent = "250 80";
  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.addEmptySpace(30, %this.chain);
  97. %this.addSubSection("Declared Assets");
  98. %this.assetList = new GuiChainCtrl()
  99. {
  100. Class = ProjectModuleAssetList;
  101. HorizSizing="width";
  102. VertSizing="height";
  103. Position = "0 0";
  104. Extent = "286 100";
  105. IsVertical = "1";
  106. ChildSpacing = 2;
  107. };
  108. ThemeManager.setProfile(%this.assetList, "emptyProfile");
  109. %this.chain.add(%this.assetList);
  110. %this.button = new GuiButtonCtrl()
  111. {
  112. Class="ProjectModuleCardButton";
  113. HorizSizing="left";
  114. VertSizing="bottom";
  115. Position = "184 40";
  116. Extent = "100 30";
  117. MinExtent = "100 30";
  118. Text = "";
  119. };
  120. ThemeManager.setProfile(%this.button, "primaryButtonProfile");
  121. %this.add(%this.button);
  122. %this.startListening(%this.button);
  123. %this.startListening(ThemeManager);
  124. }
  125. function ProjectModuleCard::addSubSection(%this, %name)
  126. {
  127. %chain = new GuiChainCtrl()
  128. {
  129. HorizSizing="width";
  130. VertSizing="height";
  131. Position = "0 0";
  132. Extent = "286 0";
  133. IsVertical = "1";
  134. ChildSpacing = -4;
  135. };
  136. ThemeManager.setProfile(%chain, "emptyProfile");
  137. %this.chain.add(%chain);
  138. %subSection = new GuiControl()
  139. {
  140. HorizSizing="width";
  141. Extent = "286 24";
  142. Text = %name;
  143. FontSizeAdjust = "0.8";
  144. };
  145. ThemeManager.setProfile(%subSection, "titleProfile");
  146. %chain.add(%subSection);
  147. %this.addSpacer(%chain);
  148. %this.addEmptySpace(8, %chain);
  149. return %chain;
  150. }
  151. function ProjectModuleCard::addSpacer(%this, %chain)
  152. {
  153. %spacer = new GuiControl()
  154. {
  155. HorizSizing="width";
  156. Position = "0 0";
  157. Extent = "286 6";
  158. };
  159. ThemeManager.setProfile(%spacer, "spacerProfile");
  160. %chain.add(%spacer);
  161. return %spacer;
  162. }
  163. function ProjectModuleCard::addEmptySpace(%this, %size, %chain)
  164. {
  165. %empty = new GuiControl()
  166. {
  167. HorizSizing="width";
  168. Position = "0 0";
  169. Extent = "286" SPC %size;
  170. };
  171. ThemeManager.setProfile(%empty, "emptyProfile");
  172. %chain.add(%empty);
  173. return %empty;
  174. }
  175. function ProjectModuleCard::onThemeChange(%this, %theme)
  176. {
  177. %this.authorText.FontColor = %theme.color5;
  178. %this.versionText.FontColor = %theme.setAlpha(%theme.color4, 150);
  179. }
  180. function ProjectModuleCard::show(%this, %module)
  181. {
  182. if(isObject(%module))
  183. {
  184. %this.activeModule = %module;
  185. %this.moduleID = %module.moduleID;
  186. %this.versionID = %module.versionID;
  187. %this.titleText.setText(%module.moduleID);
  188. %this.setAuthor(%module);
  189. %this.setVersion(%module);
  190. %this.descriptionText.setText(%module.description);
  191. %this.button.visible = false;
  192. %projectModule = %this.getInstalledModule(%module.moduleID, %module.versionID);
  193. if(%projectModule != %module)
  194. {
  195. if(!isObject(%projectModule))
  196. {
  197. %this.button.setText("Install");
  198. %this.button.visible = true;
  199. }
  200. else if(%projectmodule.buildID < %module.buildID)
  201. {
  202. %this.button.setText("Update");
  203. %this.button.visible = true;
  204. }
  205. }
  206. else
  207. {
  208. }
  209. %this.optionGroup.visible = false;
  210. if(!%module.Synchronized)
  211. {
  212. %this.optionGroup.visible = true;
  213. %this.launchGroupCheckBox.setStateOn(%module.Group $= "launch");
  214. for(%i = 0; %i < %this.toggleLaunchGroupCount; %i++)
  215. {
  216. if(%this.toggleLaunchGroup[%i] $= %this.activeModule.getModulePath())
  217. {
  218. %this.launchGroupCheckBox.setStateOn(!%this.launchGroupCheckBox.getStateOn());
  219. break;
  220. }
  221. }
  222. }
  223. %this.visible = true;
  224. %this.dependList.show(%module);
  225. %this.assetList.show(%module);
  226. %this.postEvent("ModuleShown", %module);
  227. }
  228. }
  229. function ProjectModuleCard::hide(%this)
  230. {
  231. %this.activeModule = 0;
  232. %this.moduleID = "";
  233. %this.versionID = 0;
  234. %this.visible = false;
  235. }
  236. function ProjectModuleCard::setAuthor(%this, %module)
  237. {
  238. %author = %module.author;
  239. if(%author $= "")
  240. {
  241. %author = "Torque2D";
  242. }
  243. %type = %module.type;
  244. if(%type $= "")
  245. {
  246. %type = "Module";
  247. }
  248. %this.authorText.setText(%type SPC "by" SPC %author);
  249. }
  250. function ProjectModuleCard::setVersion(%this, %module)
  251. {
  252. %version = %module.versionID;
  253. if(%version $= "")
  254. {
  255. %version = 1;
  256. }
  257. %build = %module.buildID;
  258. if(%build $= "")
  259. {
  260. %build = 0;
  261. }
  262. %this.versionText.setText("Version:" SPC %version @ " Build:" SPC %build);
  263. }
  264. function ProjectModuleCard::getInstalledModule(%this, %moduleID, %versionID)
  265. {
  266. %allModules = ModuleDatabase.findModules(false);
  267. %count = getWordCount(%allModules);
  268. for(%i = 0; %i < %count; %i++)
  269. {
  270. %projectModule = getWord(%allModules, %i);
  271. if(%moduleID $= %projectModule.ModuleID && %versionID == %projectModule.VersionID)
  272. {
  273. return %projectModule;
  274. }
  275. }
  276. return 0;
  277. }
  278. function ProjectModuleCardButton::onClick(%this)
  279. {
  280. %this.postEvent("ButtonClick");
  281. }
  282. function ProjectModuleCard::onButtonClick(%this)
  283. {
  284. %this.postEvent(%this.button.getText() @ "Click");
  285. }
  286. function ProjectManagerLaunchGroupCheckBox::onClick(%this)
  287. {
  288. %state = %this.getStateOn();
  289. %this.postEvent("LauchGroupClick", %state);
  290. }
  291. function ProjectModuleCard::onLauchGroupClick(%this, %state)
  292. {
  293. %this.startListening(ProjectManager);
  294. if(isObject(%this.activeModule))
  295. {
  296. if((%state && %this.activeModule.group $= "launch") || (!%state && %this.activeModule.group !$= "launch"))
  297. {
  298. %path = %this.activeModule.getModulePath();
  299. for(%i = 0; %i < %this.toggleLaunchGroupCount; %i++)
  300. {
  301. if(%this.toggleLaunchGroup[%i] $= %path)
  302. {
  303. %this.toggleLaunchGroup[%i] = "";
  304. }
  305. }
  306. }
  307. else
  308. {
  309. %this.toggleLaunchGroup[%this.toggleLaunchGroupCount] = %this.activeModule.getModulePath();
  310. %this.toggleLaunchGroupCount++;
  311. }
  312. }
  313. }
  314. function ProjectModuleCard::onShutDown(%this)
  315. {
  316. for(%i = 0; %i < %this.toggleLaunchGroupCount; %i++)
  317. {
  318. %path = pathConcat(%this.toggleLaunchGroup[%i], "module.taml");
  319. if(%path !$= "" && isFile(%path))
  320. {
  321. %this.toggleLaunchGroupForPath(%path);
  322. }
  323. }
  324. }
  325. function ProjectModuleCard::toggleLaunchGroupForPath(%this, %path)
  326. {
  327. %module = TamlRead(%path);
  328. if(%module.group $= "launch")
  329. {
  330. %module.group = "";
  331. }
  332. else
  333. {
  334. %module.group = "launch";
  335. }
  336. TamlWrite(%module, %path);
  337. }