MenuExtension.js 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var FairyEditor = CS.FairyEditor;
  4. const FindFailureAssetsWnd_1 = require("./FindFailureAssetsWnd");
  5. const UIWindow_1 = require("./UIWindow");
  6. const FindDependencyQueryWnd_1 = require("./FindDependencyQueryWnd");
  7. const PsdToFgui_1 = require("./PsdToFgui");
  8. const App = FairyEditor.App;
  9. const XGameMenuName = "XGameMenu";
  10. const NoExportKey = "noexport"; // 不导出的贴图
  11. class MenuExtension {
  12. start() {
  13. this.registerMenu();
  14. }
  15. registerMenu() {
  16. // 主菜单不能加回调事件,否则会报错
  17. App.menu.AddItem("XGame", XGameMenuName, 5, true, null);
  18. let xgMenu = App.menu.GetSubMenu(XGameMenuName);
  19. xgMenu.AddItem("psd->fgui", "psd2fgui", this.onPsd2Fgui.bind(this));
  20. xgMenu.AddSeperator();
  21. xgMenu.AddItem("贴图检测", "CollectAtlas", this.onCollectAtlas.bind(this));
  22. // xgMenu.AddItem("测试导入", "TestImport", () => {
  23. // // let cPackage = FairyEditor.App.project.AddPackage("F:/TJWork/psd2fgui/test/test-fairypackage");
  24. // let cPackage = FairyEditor.App.project.allPackages[0];
  25. // let importQueue = FairyEditor.ResourceImportQueue.Create(cPackage);
  26. // importQueue.Add("F:/TJWork/psd2fgui/test/test.fairypackage");
  27. // importQueue.Process((items)=>{
  28. // App.consoleView.Log(`11111111`);
  29. // });
  30. // App.consoleView.Log(`click TestImport pkgItem:${cPackage?.name ?? "0000"}`);
  31. // // FairyEditor.App.libView.ShowImportResourcesDialog(pkgItem, "F:/CCWork/zhetian_client/fgui-project/assets/test-fairypackage");
  32. // // FairyEditor.BuilderUtil.OpenURL("file://F:/TJWork/psd2fgui/test/test.fairypackage");
  33. // });
  34. xgMenu.AddSeperator();
  35. xgMenu.AddItem("查找组件依赖关系", "findDependency", this.onFindDependency.bind(this));
  36. xgMenu.AddItem("查找无效组件", "findFailureAssets", this.onFindFailureAssets.bind(this));
  37. }
  38. onPsd2Fgui() {
  39. let psd2fgui = new PsdToFgui_1.default();
  40. psd2fgui.start();
  41. }
  42. onFindDependency() {
  43. FindDependencyQueryWnd_1.default.show();
  44. }
  45. onFindFailureAssets() {
  46. FindFailureAssetsWnd_1.default.show();
  47. }
  48. onCollectAtlas() {
  49. let pkgs = App.project.allPackages;
  50. for (let index = 0; index < pkgs.Count; index++) {
  51. let pkg = pkgs.get_Item(index);
  52. for (let j = 0; j < pkg.items.Count; j++) {
  53. let item = pkg.items.get_Item(j);
  54. if (item.type != CS.FairyEditor.FObjectType.IMAGE && item.type != CS.FairyEditor.FObjectType.COMPONENT) {
  55. continue;
  56. }
  57. if (item.path.toLowerCase().includes(NoExportKey)) {
  58. if (!pkg.publishSettings.excludedList.Contains(item.id)) {
  59. pkg.publishSettings.excludedList.Add(item.id);
  60. App.consoleView.Log(`排除资源. pkg:${pkg.name} name:${item.name} file:${item.fileName}`);
  61. }
  62. continue;
  63. }
  64. if (item.type != CS.FairyEditor.FObjectType.IMAGE) {
  65. continue;
  66. }
  67. let isPng = item.fileName.toLowerCase().endsWith(".png");
  68. if (item.GetAtlasIndex() == 0 && isPng) {
  69. continue;
  70. }
  71. let imgAsset = item.GetAsset();
  72. imgAsset.atlas = isPng ? "0" : "9";
  73. item.SetChanged();
  74. App.consoleView.Log(`Image pkg:${pkg.name} fileName:${item.fileName} atlas:${item.folderAtlas} support:${item.supportAtlas} Index:${item.GetAtlasIndex()} file:${imgAsset.file} atlas:${imgAsset.atlas}`);
  75. }
  76. pkg.SetChanged();
  77. pkg.Save();
  78. }
  79. App.RefreshProject();
  80. }
  81. onDestroy() {
  82. UIWindow_1.default.delAll([]);
  83. App.menu.RemoveItem(XGameMenuName);
  84. }
  85. }
  86. exports.default = MenuExtension;