1 Star 0 Fork 0

NoBug/NBC-FGUI-Plugins

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
LanguageCustomInspector.ts 5.48 KB
一键复制 编辑 原始数据 按行查看 历史
Bob.Song 提交于 2023-01-05 11:00 . fist commit
import { FairyGUI, FairyEditor, System, UnityEngine } from 'csharp';
const App = FairyEditor.App;
import languageSetting from './LanguageSettings'
class MembersLanguageCustomInspector extends FairyEditor.View.PluginInspector {
private setUseKey: FairyGUI.GButton;
private btnRefresh: FairyGUI.GButton;
private languageKey: FairyEditor.Component.TextInput;
public constructor() {
super();
this.panel = FairyGUI.UIPackage.CreateObject("NBCCustomInspector", "LanguageComponent").asCom;
this.setUseKey = this.panel.GetChild("SetUseKey").asButton;
this.btnRefresh = this.panel.GetChild("btnRefresh").asButton;
this.languageKey = this.panel.GetChild("languageKey") as FairyEditor.Component.TextInput
this.btnRefresh.onClick.Add(() => {
let sels = App.activeDoc.inspectingTargets
let obj = sels.get_Item(0);
languageSetting.updateItemTitle(obj, this.languageKey.title)
})
this.setUseKey.onChanged.Add(() => {
this.updateData()
});
this.languageKey.onFocusOut.Add(() => {
this.updateData()
})
this.updateAction = () => { return this.updateUI(); };
}
private updateData() {
let sels = App.activeDoc.inspectingTargets
let obj = sels.get_Item(0);
let activeDoc = App.activeDoc
let packageName = activeDoc.packageItem.owner.name;
let docUrl = activeDoc.docURL;
let objId = obj.id
let useable = this.setUseKey.selected
let change = languageSetting.update(packageName, docUrl, objId, this.languageKey.title, useable)
if (change) {
//如果key变化了。
languageSetting.updateItemTitle(obj, this.languageKey.title)
}
}
private updateUI(): boolean {
let sels = App.activeDoc.inspectingTargets
let obj = sels.get_Item(0);
let activeDoc = App.activeDoc
let packageName = activeDoc.packageItem.owner.name;
let docUrl = activeDoc.docURL;
let objId = obj.id
let data = languageSetting.get(packageName, docUrl, objId)
if (data != null) {
this.setUseKey.selected = data.useable == 1
this.languageKey.title = data.key
} else {
this.setUseKey.selected = false
this.languageKey.title = ''
}
return true; //if everything is ok, return false to hide the inspector
}
}
class LanguageCustomInspector extends FairyEditor.View.PluginInspector {
private btnRefresh: FairyGUI.GButton;
public constructor() {
super();
this.panel = FairyGUI.UIPackage.CreateObject("NBCCustomInspector", "LanguageComponentRoot").asCom;
this.btnRefresh = this.panel.GetChild("btnRefresh").asButton;
this.btnRefresh.onClick.Add(() => {
this.updateAll()
})
this.updateAction = () => { return this.updateUI(); };
}
private updateAll() {
console.log("")
let activeDoc = App.activeDoc
// activeDoc.content
let packageName = activeDoc.packageItem.owner.name;
let docUrl = activeDoc.docURL;
let count = activeDoc.content.numChildren;
for (let index = 0; index < count; index++) {
const obj = activeDoc.content.GetChildAt(index)
if (obj == null) continue
let data = languageSetting.get(packageName, docUrl, obj.id)
if (data != null && data.useable == 1) {
languageSetting.updateItemTitle(obj, data.key)
}
}
}
private updateUI(): boolean {
return true; //if everything is ok, return false to hide the inspector
}
}
function runLanguageCustom() {
//Register a inspector
App.inspectorView.AddInspector(() => new MembersLanguageCustomInspector(), "MembersLanguageCustomInspectorJS", "多语言设置");
//Condition to show it
App.docFactory.ConnectInspector("MembersLanguageCustomInspectorJS", "Button", false, false);
App.docFactory.ConnectInspector("MembersLanguageCustomInspectorJS", "Label", false, false);
App.docFactory.ConnectInspector("MembersLanguageCustomInspectorJS", "text", false, false);
App.docFactory.ConnectInspector("MembersLanguageCustomInspectorJS", "richtext", false, false);
App.docFactory.ConnectInspector("MembersLanguageCustomInspectorJS", "inputtext", false, false);
// App.libView.tooltips.
console.log("多语言设置===")
// //Register a inspector
App.inspectorView.AddInspector(() => new LanguageCustomInspector(), "LanguageCustomInspectorJS", "多语言设置");
//Condition to show it
App.docFactory.ConnectInspector("LanguageCustomInspectorJS", "component", true, false);
// App.workspaceSettings.
let helpMenu = App.menu.GetSubMenu("help")
helpMenu.AddItem("NBC框架帮助", "NBCHelp", () => {
console.log("点击菜单===")
UnityEngine.Application.OpenURL("https://nobug.cn/")
})
// let keys = App.preferences.hotkeys.Keys
// let nmsl = App.preferences.hotkeys.get_Item("languagePath")
// console.log("nmslnmsl=", nmsl)
// "none", "graph", "image", "text", "richtext", "inputtext",
// "movieclip", "swf", "loader", "group", "list", "loader3D",
// "component", "Button", "Label", "Slider", "ProgressBar", "ScrollBar", "ComboBox", "mixed"
}
function languageDestroy() {
let helpMenu = App.menu.GetSubMenu("help")
helpMenu.RemoveItem("NBCHelp")
}
export { runLanguageCustom, languageDestroy };
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/no_bug_cn/nbc-fgui-plugins.git
[email protected]:no_bug_cn/nbc-fgui-plugins.git
no_bug_cn
nbc-fgui-plugins
NBC-FGUI-Plugins
master

搜索帮助