ProjectModuleCard.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. %this.titleText.setText(%module.moduleID);
  93. %this.setAuthor(%module);
  94. %this.setVersion(%module);
  95. %this.descriptionText.setText(%module.description);
  96. %this.button.visible = false;
  97. %projectModule = %this.getInstalledModule(%module.moduleID, %module.versionID);
  98. if(%projectModule != %module)
  99. {
  100. if(!isObject(%projectModule))
  101. {
  102. %this.button.setText("Install");
  103. %this.button.visible = true;
  104. }
  105. else if(%projectmodule.buildID < %module.buildID)
  106. {
  107. %this.button.setText("Update");
  108. %this.button.visible = true;
  109. }
  110. }
  111. else
  112. {
  113. }
  114. %this.visible = true;
  115. }
  116. function ProjectModuleCard::hide(%this)
  117. {
  118. %this.visible = false;
  119. }
  120. function ProjectModuleCard::setAuthor(%this, %module)
  121. {
  122. %author = %module.author;
  123. if(%author $= "")
  124. {
  125. %author = "Torque2D";
  126. }
  127. %type = %module.type;
  128. if(%type $= "")
  129. {
  130. %type = "Module";
  131. }
  132. %this.authorText.setText(%type SPC "by" SPC %author);
  133. }
  134. function ProjectModuleCard::setVersion(%this, %module)
  135. {
  136. %version = %module.versionID;
  137. if(%version $= "")
  138. {
  139. %version = 1;
  140. }
  141. %build = %module.buildID;
  142. if(%build $= "")
  143. {
  144. %build = 0;
  145. }
  146. %this.versionText.setText("Version:" SPC %version @ " Build:" SPC %build);
  147. }
  148. function ProjectModuleCard::getInstalledModule(%this, %moduleID, %versionID)
  149. {
  150. %allModules = ModuleDatabase.findModules(false);
  151. %count = getWordCount(%allModules);
  152. for(%i = 0; %i < %count; %i++)
  153. {
  154. %projectModule = getWord(%allModules, %i);
  155. if(%moduleID $= %projectModule.ModuleID && %versionID == %projectModule.VersionID)
  156. {
  157. return %projectModule;
  158. }
  159. }
  160. return 0;
  161. }
  162. function ProjectModuleCardButton::onClick(%this)
  163. {
  164. %this.postEvent("ButtonClick");
  165. }
  166. function ProjectModuleCard::onButtonClick(%this)
  167. {
  168. %this.postEvent(%this.button.getText() @ "Click");
  169. }