ProjectModuleCard.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 = "ModuleName";
  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.spacer = new GuiControl()
  51. {
  52. HorizSizing="width";
  53. Position = "0 0";
  54. Extent = "286 6";
  55. };
  56. ThemeManager.setProfile(%this.spacer, "spacerProfile");
  57. %this.chain.add(%this.spacer);
  58. %this.descriptionText = new GuiControl()
  59. {
  60. HorizSizing="width";
  61. Position = "0 10";
  62. Extent = "286 150";
  63. MinExtent = "250 150";
  64. Text = "Demonstrates the ability to create rope and chains using joints.";
  65. TextWrap = 1;
  66. TextExtend = 1;
  67. };
  68. ThemeManager.setProfile(%this.descriptionText, "normalTextProfile");
  69. %this.chain.add(%this.descriptionText);
  70. %this.button = new GuiButtonCtrl()
  71. {
  72. Class="ProjectModuleCardButton";
  73. HorizSizing="left";
  74. VertSizing="bottom";
  75. Position = "184 40";
  76. Extent = "100 30";
  77. MinExtent = "100 30";
  78. Text = "";
  79. };
  80. ThemeManager.setProfile(%this.button, "primaryButtonProfile");
  81. %this.add(%this.button);
  82. %this.startListening(%this.button);
  83. %this.startListening(ThemeManager);
  84. }
  85. function ProjectModuleCard::onThemeChange(%this, %theme)
  86. {
  87. %this.authorText.FontColor = %theme.color5;
  88. %this.versionText.FontColor = %theme.setAlpha(%theme.color4, 150);
  89. }
  90. function ProjectModuleCard::show(%this, %module)
  91. {
  92. if(isObject(%module))
  93. {
  94. %this.moduleID = %module.moduleID;
  95. %this.versionID = %module.versionID;
  96. %this.titleText.setText(%module.moduleID);
  97. %this.setAuthor(%module);
  98. %this.setVersion(%module);
  99. %this.descriptionText.setText(%module.description);
  100. %this.button.visible = false;
  101. %projectModule = %this.getInstalledModule(%module.moduleID, %module.versionID);
  102. if(%projectModule != %module)
  103. {
  104. if(!isObject(%projectModule))
  105. {
  106. %this.button.setText("Install");
  107. %this.button.visible = true;
  108. }
  109. else if(%projectmodule.buildID < %module.buildID)
  110. {
  111. %this.button.setText("Update");
  112. %this.button.visible = true;
  113. }
  114. }
  115. else
  116. {
  117. }
  118. %this.visible = true;
  119. }
  120. }
  121. function ProjectModuleCard::hide(%this)
  122. {
  123. %this.moduleID = "";
  124. %this.versionID = 0;
  125. %this.visible = false;
  126. }
  127. function ProjectModuleCard::setAuthor(%this, %module)
  128. {
  129. %author = %module.author;
  130. if(%author $= "")
  131. {
  132. %author = "Torque2D";
  133. }
  134. %type = %module.type;
  135. if(%type $= "")
  136. {
  137. %type = "Module";
  138. }
  139. %this.authorText.setText(%type SPC "by" SPC %author);
  140. }
  141. function ProjectModuleCard::setVersion(%this, %module)
  142. {
  143. %version = %module.versionID;
  144. if(%version $= "")
  145. {
  146. %version = 1;
  147. }
  148. %build = %module.buildID;
  149. if(%build $= "")
  150. {
  151. %build = 0;
  152. }
  153. %this.versionText.setText("Version:" SPC %version @ " Build:" SPC %build);
  154. }
  155. function ProjectModuleCard::getInstalledModule(%this, %moduleID, %versionID)
  156. {
  157. %allModules = ModuleDatabase.findModules(false);
  158. %count = getWordCount(%allModules);
  159. for(%i = 0; %i < %count; %i++)
  160. {
  161. %projectModule = getWord(%allModules, %i);
  162. if(%moduleID $= %projectModule.ModuleID && %versionID == %projectModule.VersionID)
  163. {
  164. return %projectModule;
  165. }
  166. }
  167. return 0;
  168. }
  169. function ProjectModuleCardButton::onClick(%this)
  170. {
  171. %this.postEvent("ButtonClick");
  172. }
  173. function ProjectModuleCard::onButtonClick(%this)
  174. {
  175. %this.postEvent(%this.button.getText() @ "Click");
  176. }