-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.ts
More file actions
executable file
·150 lines (117 loc) · 5.78 KB
/
main.ts
File metadata and controls
executable file
·150 lines (117 loc) · 5.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import { FairyGUI, FairyEditor, System } from 'csharp';
import { genCodeTs } from './GenCode_TypeScript';
import { genCodeCS } from './GenCode_CSharp';
const App = FairyEditor.App;
App.pluginManager.LoadUIPackage(App.pluginManager.basePath + "/" + eval("__dirname") + '/CustomInspector')
class ExportCodeFlagInspector extends FairyEditor.View.PluginInspector {
private combo: FairyGUI.GButton;
private ctrl_ref: FairyGUI.Controller
public constructor() {
super();
this.panel = FairyGUI.UIPackage.CreateObject("CustomInspector", "ExportCodeFlag").asCom;
this.ctrl_ref = this.panel.GetController("ref")
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 gencode:" + obj._res.packageItem.id)
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")
}
});
this.updateAction = () => { return this.updateUI(); };
}
private updateUI(): boolean {
let sels = App.activeDoc.inspectingTargets
let obj = sels.get_Item(0) as FairyEditor.FComponent
this.ctrl_ref.SetSelectedPage("false")
if (obj.docElement.isRoot) {
this.combo.selected = obj.scriptData.GetAttribute("gencode" + obj._res.packageItem.id) == "1"
} else {
this.combo.selected = obj.parent.scriptData.GetAttribute("gencode" + obj._res.packageItem.id) == "1"
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
}
}
//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 FairyEditor.View.PluginInspector {
private combo: FairyGUI.GButton;
public constructor() {
super();
this.panel = 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(); };
}
private updateUI(): boolean {
let sels = App.activeDoc.inspectingTargets
let obj = sels.get_Item(0) as FairyEditor.FComponent
// 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: FairyEditor.FPackageItem) {
let file = System.IO.File.ReadAllText(pkgItem.file)
let xml = new 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: FairyEditor.PublishHandler) {
if (!handler.genCode) return;
handler.genCode = false; //prevent default output
console.log('开始生成代码');
// genCodeTs(handler);
genCodeCS(handler);
}
function onDestroy() {
//do cleanup here
}
export { onPublish, onDestroy };