main.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.onDestroy = exports.onPublish = void 0;
  4. const csharp_1 = require("csharp");
  5. const GenCode_CSharp_1 = require("./GenCode_CSharp");
  6. const App = csharp_1.FairyEditor.App;
  7. App.pluginManager.LoadUIPackage(App.pluginManager.basePath + "/" + eval("__dirname") + '/CustomInspector');
  8. class ExportCodeFlagInspector extends csharp_1.FairyEditor.View.PluginInspector {
  9. combo;
  10. ctrl_ref;
  11. constructor() {
  12. super();
  13. this.panel = csharp_1.FairyGUI.UIPackage.CreateObject("CustomInspector", "ExportCodeFlag").asCom;
  14. this.ctrl_ref = this.panel.GetController("ref");
  15. this.combo = this.panel.GetChild("check").asButton;
  16. this.combo.onChanged.Add(() => {
  17. let obj = App.activeDoc.inspectingTarget;
  18. //use obj.docElement.SetProperty('xxx',..) instead of obj.xxx = ... to enable undo/redo mechanism
  19. // obj.docElement.SetProperty("customData", this.combo.value)
  20. // console.log("set gencode:" + obj._res.packageItem.id)
  21. if (obj.docElement.isRoot) {
  22. obj.docElement.SetScriptData("gencode" + obj._res.packageItem.id, this.combo.selected ? "1" : "0");
  23. }
  24. else {
  25. obj.parent.docElement.SetScriptData("gencode" + obj._res.packageItem.id, this.combo.selected ? "1" : "0");
  26. }
  27. });
  28. this.updateAction = () => { return this.updateUI(); };
  29. }
  30. updateUI() {
  31. let sels = App.activeDoc.inspectingTargets;
  32. let obj = sels.get_Item(0);
  33. this.ctrl_ref.SetSelectedPage("false");
  34. if (obj.docElement.isRoot) {
  35. this.combo.selected = obj.scriptData.GetAttribute("gencode" + obj._res.packageItem.id) == "1";
  36. }
  37. else {
  38. this.combo.selected = obj.parent.scriptData.GetAttribute("gencode" + obj._res.packageItem.id) == "1";
  39. this.ctrl_ref.SetSelectedPage("true");
  40. // if (obj._pkg.name != obj.parent.pkg.name) {
  41. // this.ctrl_ref.SetSelectedPage("true")
  42. // } else {
  43. // this.ctrl_ref.SetSelectedPage("false")
  44. // }
  45. }
  46. // console.log("current gencode " + obj._res.packageItem.id + " : " + this.combo.selected)
  47. return true; //if everything is ok, return false to hide the inspector
  48. }
  49. }
  50. //Register a inspector
  51. App.inspectorView.AddInspector(() => new ExportCodeFlagInspector(), "GenCodeFlag", "标记是否生成代码");
  52. //Condition to show it
  53. //App.docFactory.ConnectInspector("GenCodeFlag", "mixed", true, false);
  54. App.docFactory.ConnectInspector("GenCodeFlag", "component", false, false);
  55. App.docFactory.ConnectInspector("GenCodeFlag", "component", true, false);
  56. class LangFlagInspector extends csharp_1.FairyEditor.View.PluginInspector {
  57. combo;
  58. constructor() {
  59. super();
  60. this.panel = csharp_1.FairyGUI.UIPackage.CreateObject("CustomInspector", "LangFlag").asCom;
  61. this.combo = this.panel.GetChild("check").asButton;
  62. this.combo.onChanged.Add(() => {
  63. let obj = App.activeDoc.inspectingTarget;
  64. //use obj.docElement.SetProperty('xxx',..) instead of obj.xxx = ... to enable undo/redo mechanism
  65. // obj.docElement.SetProperty("customData", this.combo.value)
  66. console.log("set lang:" + obj.id);
  67. if (obj.docElement.isRoot) {
  68. obj.docElement.SetScriptData("lang" + obj.id, this.combo.selected ? "1" : "0");
  69. }
  70. else {
  71. obj.parent.docElement.SetScriptData("lang" + obj.id, this.combo.selected ? "1" : "0");
  72. }
  73. });
  74. this.updateAction = () => { return this.updateUI(); };
  75. }
  76. updateUI() {
  77. let sels = App.activeDoc.inspectingTargets;
  78. let obj = sels.get_Item(0);
  79. // console.log(obj.objectType)
  80. if (obj.objectType == "component") {
  81. let ext = checkOtherPackageItemSuperClassType(obj._res.packageItem);
  82. // console.log(ext)
  83. if (!(ext == "Button" || ext == "Label")) {
  84. return false;
  85. }
  86. }
  87. else if (!(obj.objectType == "loader" || obj.objectType == "text" || obj.objectType == "richtext")) {
  88. return false;
  89. }
  90. console.log("lang" + obj.id);
  91. if (obj.docElement.isRoot) {
  92. this.combo.selected = obj.scriptData.GetAttribute("lang" + obj.id) == "1";
  93. }
  94. else {
  95. this.combo.selected = obj.parent.scriptData.GetAttribute("lang" + obj.id) == "1";
  96. }
  97. return true; //if everything is ok, return false to hide the inspector
  98. }
  99. }
  100. function checkOtherPackageItemSuperClassType(pkgItem) {
  101. let file = csharp_1.System.IO.File.ReadAllText(pkgItem.file);
  102. let xml = new csharp_1.FairyGUI.Utils.XML(file);
  103. let ext = xml?.GetAttribute("extention");
  104. return ext;
  105. }
  106. //Register a inspector
  107. App.inspectorView.AddInspector(() => new LangFlagInspector(), "LangFlag", "标记是否多语言对象");
  108. //Condition to show it
  109. App.docFactory.ConnectInspector("LangFlag", "mixed", false, false);
  110. App.docFactory.ConnectInspector("LangFlag", "loader", false, false);
  111. App.docFactory.ConnectInspector("LangFlag", "text", false, false);
  112. App.docFactory.ConnectInspector("LangFlag", "richtext", false, false);
  113. // -------------------开始生成代码----------------------------
  114. function onPublish(handler) {
  115. if (!handler.genCode)
  116. return;
  117. handler.genCode = false; //prevent default output
  118. console.log('开始生成CS代码');
  119. // genCodeTs(handler);
  120. (0, GenCode_CSharp_1.genCodeCS)(handler);
  121. }
  122. exports.onPublish = onPublish;
  123. function onDestroy() {
  124. //do cleanup here
  125. }
  126. exports.onDestroy = onDestroy;