ProjectLibraryPanel.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. function ProjectLibraryPanel::onAdd(%this)
  2. {
  3. %this.init("Library");
  4. }
  5. function ProjectLibraryPanel::load(%this)
  6. {
  7. %this.manager = new ModuleManager();
  8. %this.manager.addListener(AssetDatabase);
  9. %this.manager.EchoInfo = false;
  10. %this.manager.ScanModules(pathConcat(getMainDotCsDir(), "library"));
  11. %allModules = %this.manager.findModules(false);
  12. for(%i = 0; %i < getWordCount(%allModules); %i++)
  13. {
  14. %mod = getWord(%allModules, %i);
  15. %this.addModule(%mod);
  16. }
  17. %this.list.sortByText();
  18. }
  19. function ProjectLibraryPanel::addModule(%this, %module)
  20. {
  21. if(%module.type !$= "Template")
  22. {
  23. %this.list.addItemWithID(%this.getModuleName(%module), %module);
  24. }
  25. }
  26. function ProjectLibraryPanel::onOpen(%this, %allModules)
  27. {
  28. %count = %this.list.getItemCount();
  29. for(%i = 0; %i < %count; %i++)
  30. {
  31. %module = %this.list.getItemID(%i);
  32. %this.refreshColor(%module, %i, %allModules);
  33. }
  34. if(%this.card.visible)
  35. {
  36. %this.refreshCard();
  37. }
  38. }
  39. function ProjectLibraryPanel::refreshColor(%this, %module, %index, %projectModules)
  40. {
  41. %color = %this.gray;
  42. if(%module.Deprecated)
  43. {
  44. %color = %this.darkRed;
  45. }
  46. for(%i = 0; %i < getWordCount(%projectModules); %i++)
  47. {
  48. %projectModule = getWord(%projectModules, %i);
  49. if(%projectModule.ModuleId $= %module.ModuleId && %projectModule.VersionId $= %module.VersionId)
  50. {
  51. %color = %this.yellow;
  52. if(%module.Deprecated)
  53. {
  54. %color = %this.darkRed;
  55. }
  56. else if(%module.BuildID > %projectModule.BuildID)
  57. {
  58. %color = %this.purple;
  59. }
  60. }
  61. }
  62. %this.list.setItemColor(%index, %color);
  63. }
  64. function ProjectLibraryPanel::onInstallClick(%this)
  65. {
  66. %index = %this.list.getSelectedItem();
  67. %module = %this.list.getItemID(%index);
  68. if(isObject(%module))
  69. {
  70. %this.manager.CopyModule(%module.moduleID, %module.versionID, %module.moduleID, ProjectManager.getProjectFolder(), true);
  71. %this.manager.synchronizeDependencies(%module, ProjectManager.getProjectFolder());
  72. ModuleDatabase.ScanModules(ProjectManager.getProjectFolder());
  73. %installedModule = ModuleDatabase.findModule(%module.moduleID, %module.versionID);
  74. %this.postEvent("ModuleInstalled", %installedModule);
  75. }
  76. else
  77. {
  78. warn("Project Manager - Could not install module.");
  79. }
  80. }
  81. function ProjectLibraryPanel::onUpdateClick(%this)
  82. {
  83. %index = %this.list.getSelectedItem();
  84. %module = %this.list.getItemID(%index);
  85. %installedModule = ModuleDatabase.findModule(%module.moduleID, %module.versionID);
  86. if(isObject(%module) && isObject(%installedModule))
  87. {
  88. %path = %installedModule.getModulePath();
  89. %wasLoaded = false;
  90. if(ModuleDatabase.isModuleLoaded(%installedModule.moduleID))
  91. {
  92. %wasLoaded = true;
  93. ModuleDatabase.UnloadExplicit(%installedModule.moduleID);
  94. }
  95. ModuleDatabase.unregisterModule(%installedModule.moduleID, %installedModule.versionID);
  96. directoryDelete(%path);
  97. %this.manager.CopyModule(%module.moduleID, %module.versionID, %module.moduleID, ProjectManager.getProjectFolder(), true);
  98. %this.manager.synchronizeDependencies(%module, ProjectManager.getProjectFolder());
  99. ModuleDatabase.ScanModules(ProjectManager.getProjectFolder());
  100. %installedModule = ModuleDatabase.findModule(%module.moduleID, %module.versionID);
  101. if(%wasLoaded)
  102. {
  103. ModuleDatabase.LoadExplicit(%installedModule.moduleID, %installedModule.versionID);
  104. }
  105. %this.postEvent("ModuleInstalled", %installedModule);
  106. }
  107. else
  108. {
  109. warn("Project Manager - Could not update module.");
  110. }
  111. }
  112. function ProjectLibraryPanel::refreshCard(%this)
  113. {
  114. %module = %this.manager.findModule(%this.card.moduleID, %this.card.versionID);
  115. %this.card.show(%module);
  116. }