123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.onDestroy = exports.onPublish = void 0;
- const csharp_1 = require("csharp");
- const GenCode_CSharp_1 = require("./GenCode_CSharp");
- const App = csharp_1.FairyEditor.App;
- App.pluginManager.LoadUIPackage(App.pluginManager.basePath + "/" + eval("__dirname") + '/CustomInspector');
- class ExportCodeFlagInspector extends csharp_1.FairyEditor.View.PluginInspector {
- // 是否生成代码按钮
- combo;
- ctrl_ref;
- // UIType下拉框
- uitypeBox;
- // UILayer下拉框
- uilayerBox;
- genCodeKey = "gencode";
- genuitypeKey = "genuitype";
- genuilayerKey = "genuilayer";
- constructor() {
- super();
- this.panel = csharp_1.FairyGUI.UIPackage.CreateObject("CustomInspector", "ExportCodeFlag").asCom;
- this.ctrl_ref = this.panel.GetController("ref");
- this.combo = this.panel.GetChild("check").asButton;
- this.uitypeBox = this.panel.GetChild("UITypeBox").asComboBox;
- this.uilayerBox = this.panel.GetChild("UILayerBox").asComboBox;
- //生成代码开关
- this.combo.onChanged.Add(() => {
- let obj = App.activeDoc.inspectingTarget;
- //use obj.docElement.SetProperty('xxx',..) instead of obj.xxx = ... to enable undo/redo mechanism
- // obj.docElement.SetProperty("customData", this.combo.value)
- // console.log("set gencode:" + obj._res.packageItem.id)
- this.SetScriptData(obj, this.genCodeKey, this.combo.selected ? "1" : "0");
- // if (obj.docElement.isRoot) {
- // obj.docElement.SetScriptData("gencode" + obj._res.packageItem.id, this.combo.selected ? "1" : "0")
- // } else {
- // obj.parent.docElement.SetScriptData("gencode" + obj._res.packageItem.id, this.combo.selected ? "1" : "0")
- // }
- });
- //选择UIType
- this.uitypeBox.onChanged.Add(() => {
- App.consoleView.Log(`uitypeBox onChanged index:${this.uitypeBox.selectedIndex}`);
- let obj = App.activeDoc.inspectingTarget;
- this.SetScriptData(obj, this.genuitypeKey, this.uitypeBox.selectedIndex.toString());
- });
- //选择UILayer
- this.uilayerBox.onChanged.Add(() => {
- App.consoleView.Log(`uilayerBox onChanged index:${this.uilayerBox.selectedIndex}`);
- let obj = App.activeDoc.inspectingTarget;
- this.SetScriptData(obj, this.genuilayerKey, this.uilayerBox.selectedIndex.toString());
- });
- this.updateAction = () => { return this.updateUI(); };
- }
- updateUI() {
- let sels = App.activeDoc.inspectingTargets;
- let obj = sels.get_Item(0);
- this.ctrl_ref.SetSelectedPage("false");
- this.uitypeBox.selectedIndex = 0; // 默认UIPanel
- if (obj.docElement.isRoot) {
- this.combo.selected = this.GetAttribute(obj, this.genCodeKey) == "1";
- //TODO 初始化赋值
- this.uitypeBox.selectedIndex = Number(this.GetAttribute(obj, this.genuitypeKey));
- let genuilayer = this.GetAttribute(obj, this.genuilayerKey);
- if (genuilayer == null || genuilayer == "")
- genuilayer = "1"; // 默认为Normal
- this.uilayerBox.selectedIndex = Number(genuilayer);
- }
- else {
- this.combo.selected = this.GetAttribute(obj.parent, this.genCodeKey) == "1";
- this.uitypeBox.selectedIndex = Number(this.GetAttribute(obj.parent, this.genuitypeKey));
- let genuilayer = this.GetAttribute(obj.parent, this.genuilayerKey);
- if (genuilayer == null || genuilayer == "")
- genuilayer = "1"; // 默认为Normal
- this.uilayerBox.selectedIndex = Number(genuilayer);
- this.ctrl_ref.SetSelectedPage("true");
- // if (obj._pkg.name != obj.parent.pkg.name) {
- // this.ctrl_ref.SetSelectedPage("true")
- // } else {
- // this.ctrl_ref.SetSelectedPage("false")
- // }
- }
- // console.log("current gencode " + obj._res.packageItem.id + " : " + this.combo.selected)
- return true; //if everything is ok, return false to hide the inspector
- }
- SetScriptData(obj, key, value) {
- if (!obj.docElement.isRoot) {
- obj = obj.parent;
- }
- obj.docElement.SetScriptData(key + obj._res.packageItem.id, value);
- }
- GetAttribute(obj, key) {
- return obj.scriptData.GetAttribute(key + obj._res.packageItem.id);
- }
- }
- //Register a inspector
- App.inspectorView.AddInspector(() => new ExportCodeFlagInspector(), "GenCodeFlag", "标记是否生成代码");
- //Condition to show it
- //App.docFactory.ConnectInspector("GenCodeFlag", "mixed", true, false);
- App.docFactory.ConnectInspector("GenCodeFlag", "component", false, false);
- App.docFactory.ConnectInspector("GenCodeFlag", "component", true, false);
- class LangFlagInspector extends csharp_1.FairyEditor.View.PluginInspector {
- combo;
- constructor() {
- super();
- this.panel = csharp_1.FairyGUI.UIPackage.CreateObject("CustomInspector", "LangFlag").asCom;
- this.combo = this.panel.GetChild("check").asButton;
- this.combo.onChanged.Add(() => {
- let obj = App.activeDoc.inspectingTarget;
- //use obj.docElement.SetProperty('xxx',..) instead of obj.xxx = ... to enable undo/redo mechanism
- // obj.docElement.SetProperty("customData", this.combo.value)
- console.log("set lang:" + obj.id);
- if (obj.docElement.isRoot) {
- obj.docElement.SetScriptData("lang" + obj.id, this.combo.selected ? "1" : "0");
- }
- else {
- obj.parent.docElement.SetScriptData("lang" + obj.id, this.combo.selected ? "1" : "0");
- }
- });
- this.updateAction = () => { return this.updateUI(); };
- }
- updateUI() {
- let sels = App.activeDoc.inspectingTargets;
- let obj = sels.get_Item(0);
- // console.log(obj.objectType)
- if (obj.objectType == "component") {
- let ext = checkOtherPackageItemSuperClassType(obj._res.packageItem);
- // console.log(ext)
- if (!(ext == "Button" || ext == "Label")) {
- return false;
- }
- }
- else if (!(obj.objectType == "loader" || obj.objectType == "text" || obj.objectType == "richtext")) {
- return false;
- }
- console.log("lang" + obj.id);
- if (obj.docElement.isRoot) {
- this.combo.selected = obj.scriptData.GetAttribute("lang" + obj.id) == "1";
- }
- else {
- this.combo.selected = obj.parent.scriptData.GetAttribute("lang" + obj.id) == "1";
- }
- return true; //if everything is ok, return false to hide the inspector
- }
- }
- function checkOtherPackageItemSuperClassType(pkgItem) {
- let file = csharp_1.System.IO.File.ReadAllText(pkgItem.file);
- let xml = new csharp_1.FairyGUI.Utils.XML(file);
- let ext = xml?.GetAttribute("extention");
- return ext;
- }
- //Register a inspector
- App.inspectorView.AddInspector(() => new LangFlagInspector(), "LangFlag", "标记是否多语言对象");
- //Condition to show it
- App.docFactory.ConnectInspector("LangFlag", "mixed", false, false);
- App.docFactory.ConnectInspector("LangFlag", "loader", false, false);
- App.docFactory.ConnectInspector("LangFlag", "text", false, false);
- App.docFactory.ConnectInspector("LangFlag", "richtext", false, false);
- // -------------------开始生成代码----------------------------
- function onPublish(handler) {
- if (!handler.genCode)
- return;
- handler.genCode = false; //prevent default output
- console.log('开始生成CS代码');
- // genCodeTs(handler);
- (0, GenCode_CSharp_1.genCodeCS)(handler);
- }
- exports.onPublish = onPublish;
- function onDestroy() {
- //do cleanup here
- }
- exports.onDestroy = onDestroy;
|