MenuExtension.ts 3.9 KB

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