ProjectModuleCard.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. function ProjectModuleCard::onAdd(%this)
  2. {
  3. %this.chain = new GuiChainCtrl()
  4. {
  5. HorizSizing="width";
  6. VertSizing="height";
  7. Position = "0 0";
  8. Extent = "286 100";
  9. IsVertical = "1";
  10. ChildSpacing = -4;
  11. };
  12. ThemeManager.setProfile(%this.chain, "emptyProfile");
  13. %this.add(%this.chain);
  14. %this.titleText = new GuiControl()
  15. {
  16. HorizSizing="width";
  17. Position = "0 13";
  18. Extent = "286 38";
  19. Text = "";
  20. FontSizeAdjust = "1.4";
  21. };
  22. ThemeManager.setProfile(%this.titleText, "titleProfile");
  23. %this.chain.add(%this.titleText);
  24. %this.authorText = new GuiControl()
  25. {
  26. HorizSizing="width";
  27. Position = "0 0";
  28. Extent = "180 22";
  29. MinExtent = "180 22";
  30. Text = "Module by Torque2D";
  31. TextWrap = 1;
  32. TextExtend = 1;
  33. FontSizeAdjust = "1.1";
  34. FontColor = ThemeManager.activeTheme.color5;
  35. OverrideFontColor = true;
  36. };
  37. ThemeManager.setProfile(%this.authorText, "codeProfile");
  38. %this.chain.add(%this.authorText);
  39. %this.versionText = new GuiControl()
  40. {
  41. HorizSizing="width";
  42. Position = "0 0";
  43. Extent = "180 26";
  44. Text = "Version: 1 Build: 1";
  45. FontColor = ThemeManager.activeTheme.setAlpha(ThemeManager.activeTheme.color4, 150);
  46. OverrideFontColor = true;
  47. };
  48. ThemeManager.setProfile(%this.versionText, "codeProfile");
  49. %this.chain.add(%this.versionText);
  50. %this.addSpacer();
  51. %this.descriptionText = new GuiControl()
  52. {
  53. HorizSizing="width";
  54. Position = "0 10";
  55. Extent = "286 150";
  56. MinExtent = "250 150";
  57. Text = "";
  58. TextWrap = 1;
  59. TextExtend = 1;
  60. };
  61. ThemeManager.setProfile(%this.descriptionText, "normalTextProfile");
  62. %this.chain.add(%this.descriptionText);
  63. %this.addSubSection("Dependencies");
  64. %this.dependList = new GuiChainCtrl()
  65. {
  66. Class = ProjectModuleDependList;
  67. HorizSizing="width";
  68. VertSizing="height";
  69. Position = "0 0";
  70. Extent = "286 100";
  71. IsVertical = "1";
  72. ChildSpacing = 2;
  73. };
  74. ThemeManager.setProfile(%this.dependList, "emptyProfile");
  75. %this.chain.add(%this.dependList);
  76. %this.button = new GuiButtonCtrl()
  77. {
  78. Class="ProjectModuleCardButton";
  79. HorizSizing="left";
  80. VertSizing="bottom";
  81. Position = "184 40";
  82. Extent = "100 30";
  83. MinExtent = "100 30";
  84. Text = "";
  85. };
  86. ThemeManager.setProfile(%this.button, "primaryButtonProfile");
  87. %this.add(%this.button);
  88. %this.startListening(%this.button);
  89. %this.startListening(ThemeManager);
  90. }
  91. function ProjectModuleCard::addSpacer(%this)
  92. {
  93. %spacer = new GuiControl()
  94. {
  95. HorizSizing="width";
  96. Position = "0 0";
  97. Extent = "286 6";
  98. };
  99. ThemeManager.setProfile(%spacer, "spacerProfile");
  100. %this.chain.add(%spacer);
  101. }
  102. function ProjectModuleCard::addSubSection(%this, %name)
  103. {
  104. %subSection = new GuiControl()
  105. {
  106. HorizSizing="width";
  107. Extent = "286 24";
  108. Text = %name;
  109. FontSizeAdjust = "0.8";
  110. };
  111. ThemeManager.setProfile(%subSection, "titleProfile");
  112. %this.chain.add(%subSection);
  113. %this.addSpacer();
  114. %empty = new GuiControl()
  115. {
  116. HorizSizing="width";
  117. Position = "0 0";
  118. Extent = "286 8";
  119. };
  120. ThemeManager.setProfile(%empty, "emptyProfile");
  121. %this.chain.add(%empty);
  122. }
  123. function ProjectModuleCard::onThemeChange(%this, %theme)
  124. {
  125. %this.authorText.FontColor = %theme.color5;
  126. %this.versionText.FontColor = %theme.setAlpha(%theme.color4, 150);
  127. }
  128. function ProjectModuleCard::show(%this, %module)
  129. {
  130. if(isObject(%module))
  131. {
  132. %this.moduleID = %module.moduleID;
  133. %this.versionID = %module.versionID;
  134. %this.titleText.setText(%module.moduleID);
  135. %this.setAuthor(%module);
  136. %this.setVersion(%module);
  137. %this.descriptionText.setText(%module.description);
  138. %this.button.visible = false;
  139. %projectModule = %this.getInstalledModule(%module.moduleID, %module.versionID);
  140. if(%projectModule != %module)
  141. {
  142. if(!isObject(%projectModule))
  143. {
  144. %this.button.setText("Install");
  145. %this.button.visible = true;
  146. }
  147. else if(%projectmodule.buildID < %module.buildID)
  148. {
  149. %this.button.setText("Update");
  150. %this.button.visible = true;
  151. }
  152. }
  153. else
  154. {
  155. }
  156. %this.visible = true;
  157. %this.dependList.show(%module);
  158. }
  159. }
  160. function ProjectModuleCard::hide(%this)
  161. {
  162. %this.moduleID = "";
  163. %this.versionID = 0;
  164. %this.visible = false;
  165. }
  166. function ProjectModuleCard::setAuthor(%this, %module)
  167. {
  168. %author = %module.author;
  169. if(%author $= "")
  170. {
  171. %author = "Torque2D";
  172. }
  173. %type = %module.type;
  174. if(%type $= "")
  175. {
  176. %type = "Module";
  177. }
  178. %this.authorText.setText(%type SPC "by" SPC %author);
  179. }
  180. function ProjectModuleCard::setVersion(%this, %module)
  181. {
  182. %version = %module.versionID;
  183. if(%version $= "")
  184. {
  185. %version = 1;
  186. }
  187. %build = %module.buildID;
  188. if(%build $= "")
  189. {
  190. %build = 0;
  191. }
  192. %this.versionText.setText("Version:" SPC %version @ " Build:" SPC %build);
  193. }
  194. function ProjectModuleCard::getInstalledModule(%this, %moduleID, %versionID)
  195. {
  196. %allModules = ModuleDatabase.findModules(false);
  197. %count = getWordCount(%allModules);
  198. for(%i = 0; %i < %count; %i++)
  199. {
  200. %projectModule = getWord(%allModules, %i);
  201. if(%moduleID $= %projectModule.ModuleID && %versionID == %projectModule.VersionID)
  202. {
  203. return %projectModule;
  204. }
  205. }
  206. return 0;
  207. }
  208. function ProjectModuleCardButton::onClick(%this)
  209. {
  210. %this.postEvent("ButtonClick");
  211. }
  212. function ProjectModuleCard::onButtonClick(%this)
  213. {
  214. %this.postEvent(%this.button.getText() @ "Click");
  215. }