ProjectGamePanel.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. function ProjectGamePanel::onAdd(%this)
  2. {
  3. %this.init("Project");
  4. %this.buttonBar.addButton("createNewModule", 11, "Create Module", "");
  5. %this.buttonBar.addButton("editModule", 49, "Edit Module", "editModuleAvailable");
  6. }
  7. function ProjectGamePanel::onOpen(%this, %allModules)
  8. {
  9. %appCore = ModuleDatabase.findModule("AppCore", 1);
  10. if(isObject(%appCore))
  11. {
  12. %this.setTitle(%appCore.project);
  13. }
  14. %loadedModules = ModuleDatabase.findModules(true);
  15. %this.clearModules();
  16. for(%i = 0; %i < getWordCount(%allModules); %i++)
  17. {
  18. %mod = getWord(%allModules, %i);
  19. %this.addModule(%mod, %loadedModules);
  20. }
  21. %this.list.sortByText();
  22. if(%this.card.visible)
  23. {
  24. %this.refreshCard();
  25. }
  26. else
  27. {
  28. %this.buttonBar.refreshEnabled();
  29. }
  30. }
  31. function ProjectGamePanel::addModule(%this, %module, %loadedModules)
  32. {
  33. %color = %this.gray;
  34. if(%module.Deprecated)
  35. {
  36. %color = %this.darkRed;
  37. }
  38. for(%i = 0; %i < getWordCount(%loadedModules); %i++)
  39. {
  40. %loadedModule = getWord(%loadedModules, %i);
  41. if(%loadedModule == %module)
  42. {
  43. %color = %this.yellow;
  44. if(%module.Deprecated)
  45. {
  46. %color = %this.darkRed;
  47. }
  48. }
  49. }
  50. %this.list.addItemWithID(%this.getModuleName(%module), %module);
  51. %index = %this.list.findItemID(%module);
  52. %this.list.setItemColor(%index, %color);
  53. }
  54. function ProjectGamePanel::refreshCard(%this)
  55. {
  56. %module = ModuleDatabase.findModule(%this.card.moduleID, %this.card.versionID);
  57. %indexList = %this.list.findItemText(%this.getModuleName(%module));
  58. %index = getWord(%indexList, 0);
  59. if(%index != -1)
  60. {
  61. %this.list.setCurSel(%index);
  62. }
  63. %this.card.show(%module);
  64. }
  65. function ProjectGamePanel::createNewModule(%this)
  66. {
  67. %width = 500;
  68. %height = 190;
  69. %dialog = new GuiControl()
  70. {
  71. class = "NewModuleDialog";
  72. superclass = "EditorDialog";
  73. dialogSize = (%width + 8) SPC (%height + 8);
  74. dialogCanClose = true;
  75. dialogText = "Create Module";
  76. };
  77. %dialog.init(%width, %height);
  78. %this.startListening(%dialog);
  79. Canvas.pushDialog(%dialog);
  80. }
  81. function ProjectGamePanel::onModuleCreated(%this, %data)
  82. {
  83. if(%data.template !$= "none")
  84. {
  85. %templatePath = pathConcat(getMainDotCsDir(), "library", %data.template);
  86. if(isDirectory(%templatePath))
  87. {
  88. pathCopy(%templatePath, %data.path);
  89. %obj = TamlRead(pathConcat(%data.path, "module.taml"));
  90. %obj.ModuleID = %data.moduleName;
  91. %obj.Type = "";
  92. TamlWrite(%obj, pathConcat(%data.path, "module.taml"));
  93. }
  94. }
  95. else
  96. {
  97. %obj = new ModuleDefinition()
  98. {
  99. ModuleID = %data.moduleName;
  100. VersionID = "1";
  101. BuildID = "1";
  102. Synchronized = false;
  103. Description = "";
  104. Author = "";
  105. };
  106. createPath(%data.path);
  107. TamlWrite(%obj, pathConcat(%data.path, "module.taml"));
  108. }
  109. ModuleDatabase.scanModules(%data.path);
  110. %this.onOpen(ModuleDatabase.findModules(false));
  111. }
  112. function ProjectGamePanel::editModule(%this)
  113. {
  114. %width = 500;
  115. %height = 520;
  116. %dialog = new GuiControl()
  117. {
  118. class = "EditModuleDialog";
  119. superclass = "EditorDialog";
  120. dialogSize = (%width + 8) SPC (%height + 8);
  121. dialogCanClose = true;
  122. dialogText = "Edit Module";
  123. module = %this.card.activeModule;
  124. };
  125. %dialog.init(%width, %height);
  126. %this.startListening(%dialog);
  127. Canvas.pushDialog(%dialog);
  128. }
  129. function ProjectGamePanel::editModuleAvailable(%this)
  130. {
  131. if(isObject(%this.card.activeModule) && !%this.card.activeModule.Synchronized)
  132. {
  133. return true;
  134. }
  135. return false;
  136. }
  137. function ProjectGamePanel::onModuleEdited(%this, %data)
  138. {
  139. if(%this.moduleHasChanged(%data))
  140. {
  141. %module = %this.card.activeModule;
  142. %moduleID = %this.card.activeModule.moduleID;
  143. %projectPath = ProjectManager.getProjectFolder();
  144. %modulePath = pathConcat(%projectPath, %module.moduleID);
  145. if(ModuleDatabase.isModuleLoaded(%module.moduleID))
  146. {
  147. if(%module.group !$= "")
  148. {
  149. ModuleDatabase.unloadGroup(%module.group);
  150. }
  151. else
  152. {
  153. ModuleDatabase.unloadExplicit(%module.moduleID);
  154. }
  155. }
  156. ModuleDatabase.unregisterModule(%module.moduleID, %module.versionID);
  157. %newModulePath = pathConcat(%projectPath, %data.moduleID);
  158. if(%moduleID !$= %data.moduleID && !isDirectory(%newModulePath))
  159. {
  160. if(pathCopy(%modulePath, %newModulePath))
  161. {
  162. directoryDelete(%modulePath);
  163. %modulePath = %newModulePath;
  164. }
  165. }
  166. echo("Editing Module at " @ %modulePath);
  167. %file = TamlRead(pathConcat(%modulePath, "module.taml"));
  168. %file.moduleID = %data.moduleID;
  169. %file.versionID = %data.versionID;
  170. %file.buildID = %data.buildID;
  171. %file.description = %data.description;
  172. %file.type = %data.type;
  173. %file.author = %data.author;
  174. TamlWrite(%file, pathConcat(%modulePath, "module.taml"));
  175. ModuleDatabase.scanModules(%modulePath, true);
  176. %this.card.moduleID = %data.moduleID;
  177. %this.card.versionID = %data.versionID;
  178. %allModules = ModuleDatabase.findModules(false);
  179. %this.onOpen(%allModules);
  180. }
  181. }
  182. function ProjectGamePanel::moduleHasChanged(%this, %data)
  183. {
  184. %module = %this.card.activeModule;
  185. return %module.moduleID !$= %data.moduleID ||
  186. %module.versionID !$= %data.versionID ||
  187. %module.buildID !$= %data.buildID ||
  188. %module.description !$= %data.description ||
  189. %module.type !$= %data.type ||
  190. %module.author !$= %data.author;
  191. }