66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
import FGUtil from "./FGUtil";
|
|
import SKTimeUtil from "../util/SKTimeUtil";
|
|
|
|
export default class FGHUD {
|
|
|
|
private static shared = new FGHUD();
|
|
static packageName: string = "main_ui";
|
|
static resName: string = "loading_main";
|
|
|
|
main: fgui.GComponent;
|
|
title: fgui.GTextField;
|
|
handle: number = 0;
|
|
|
|
constructor() {
|
|
}
|
|
|
|
static showLoading(text: string = "", timeout: number = 15000) {
|
|
this.shared.showLoading(text, timeout);
|
|
}
|
|
|
|
static hideLoading() {
|
|
this.shared.hideLoading();
|
|
}
|
|
|
|
private showLoading(text: string, timeout: number) {
|
|
if (!this.main) {
|
|
this.main = FGUtil.create(FGHUD.packageName, FGHUD.resName);
|
|
this.title = FGUtil.getTextField(this.main, "title");
|
|
}
|
|
if (!this.main) {
|
|
cc.log(`找不到GUI資源:${FGHUD.packageName}:${FGHUD.resName}`);
|
|
return;
|
|
}
|
|
this.handle = SKTimeUtil.cancelDelay(this.handle);
|
|
if (!this.main.parent) {
|
|
let root = FGUtil.root();
|
|
if (root) {
|
|
if (this.title) {
|
|
if (text.length > 0) {
|
|
this.title.text = text;
|
|
this.title.visible = true;
|
|
} else {
|
|
this.title.text = "";
|
|
this.title.visible = false;
|
|
}
|
|
}
|
|
root.addChild(this.main);
|
|
FGUtil.fitScreen(this.main);
|
|
}
|
|
}
|
|
this.handle = SKTimeUtil.delay(this.hideLoading.bind(this), timeout);
|
|
}
|
|
|
|
private hideLoading() {
|
|
if (this.main == null) {
|
|
return;
|
|
}
|
|
if (this.main.parent) {
|
|
if (this.title) {
|
|
this.title.text = "";
|
|
this.title.visible = false;
|
|
}
|
|
this.main.removeFromParent();
|
|
}
|
|
}
|
|
} |