ProjectGamePanel.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. function ProjectGamePanel::onAdd(%this)
  2. {
  3. %this.init("Project");
  4. %this.buttonBar.addButton("createNewModule", 11, "Create Module", "");
  5. }
  6. function ProjectGamePanel::onOpen(%this, %allModules)
  7. {
  8. %appCore = ModuleDatabase.findModule("AppCore", 1);
  9. if(isObject(%appCore))
  10. {
  11. %this.setTitle(%appCore.project);
  12. }
  13. %loadedModules = ModuleDatabase.findModules(true);
  14. %this.clearModules();
  15. for(%i = 0; %i < getWordCount(%allModules); %i++)
  16. {
  17. %mod = getWord(%allModules, %i);
  18. %this.addModule(%mod, %loadedModules);
  19. }
  20. %this.list.sortByText();
  21. if(%this.card.visible)
  22. {
  23. %this.refreshCard();
  24. }
  25. }
  26. function ProjectGamePanel::addModule(%this, %module, %loadedModules)
  27. {
  28. %color = %this.gray;
  29. if(%module.Deprecated)
  30. {
  31. %color = %this.darkRed;
  32. }
  33. for(%i = 0; %i < getWordCount(%loadedModules); %i++)
  34. {
  35. %loadedModule = getWord(%loadedModules, %i);
  36. if(%loadedModule == %module)
  37. {
  38. %color = %this.yellow;
  39. if(%module.Deprecated)
  40. {
  41. %color = %this.darkRed;
  42. }
  43. }
  44. }
  45. %this.list.addItemWithID(%this.getModuleName(%module), %module);
  46. %index = %this.list.findItemID(%module);
  47. %this.list.setItemColor(%index, %color);
  48. }
  49. function ProjectGamePanel::refreshCard(%this)
  50. {
  51. %module = ModuleDatabase.findModule(%this.card.moduleID, %this.card.versionID);
  52. %indexList = %this.list.findItemText(%this.getModuleName(%module));
  53. %index = getWord(%indexList, 0);
  54. if(%index != -1)
  55. {
  56. %this.list.setCurSel(%index);
  57. }
  58. %this.card.show(%module);
  59. }
  60. function ProjectGamePanel::createNewModule(%this)
  61. {
  62. %width = 500;
  63. %height = 190;
  64. %dialog = new GuiControl()
  65. {
  66. class = "NewModuleDialog";
  67. superclass = "EditorDialog";
  68. dialogSize = (%width + 8) SPC (%height + 8);
  69. dialogCanClose = true;
  70. dialogText = "Create Module";
  71. };
  72. %dialog.init(%width, %height);
  73. %this.startListening(%dialog);
  74. Canvas.pushDialog(%dialog);
  75. }
  76. function ProjectGamePanel::onDialogClosed(%this, %dialog)
  77. {
  78. %this.dialog = %dialog;
  79. %this.schedule(100, "deleteDialog");
  80. }
  81. function ProjectGamePanel::deleteDialog(%this)
  82. {
  83. %this.dialog.delete();
  84. }
  85. function ProjectGamePanel::onModuleCreated(%this, %data)
  86. {
  87. if(%data.template !$= "none")
  88. {
  89. %templatePath = pathConcat(getMainDotCsDir(), "library", %data.template);
  90. if(isDirectory(%templatePath))
  91. {
  92. pathCopy(%templatePath, %data.path);
  93. %obj = TamlRead(pathConcat(%data.path, "module.taml"));
  94. %obj.ModuleID = %data.moduleName;
  95. %obj.Type = "";
  96. TamlWrite(%obj, pathConcat(%data.path, "module.taml"));
  97. }
  98. }
  99. else
  100. {
  101. %obj = new ModuleDefinition()
  102. {
  103. ModuleID = %data.moduleName;
  104. VersionID = "1";
  105. BuildID = "1";
  106. Synchronized = false;
  107. Description = "";
  108. Author = "";
  109. };
  110. createPath(%data.path);
  111. TamlWrite(%obj, pathConcat(%data.path, "module.taml"));
  112. }
  113. ModuleDatabase.scanModules(%data.path);
  114. %this.onOpen(ModuleDatabase.findModules(false));
  115. }