114 lines
3.9 KiB
TypeScript
114 lines
3.9 KiB
TypeScript
import ItemUtil from "../../core/ItemUtil";
|
|
import FGUtil from "./FGUtil";
|
|
import GoodsMgr = require("../../../game/GoodsMgr");
|
|
|
|
export default class FGAlert {
|
|
|
|
private static shared = new FGAlert();
|
|
static packageName: string = "main_ui";
|
|
static resName: string = "alert_main";
|
|
|
|
main: fgui.GComponent;
|
|
title: fgui.GTextField;
|
|
tip1: fgui.GTextField;
|
|
tip2: fgui.GTextField;
|
|
cancelBtn: fgui.GButton;
|
|
sureBtn: fgui.GButton;
|
|
progressBar: fgui.GProgressBar;
|
|
|
|
constructor() {
|
|
}
|
|
|
|
static show(text: string, cancelBlock: () => void, sureBlock: () => void) {
|
|
this.shared.show(text, cancelBlock, sureBlock);
|
|
}
|
|
static show2(text: string, tip1, tip2, btn1Title, btn2Title, list, cancelBlock: () => void, sureBlock: () => void) {
|
|
this.shared.show2(text, tip1, tip2, btn1Title, btn2Title, list, cancelBlock, sureBlock);
|
|
}
|
|
static hide() {
|
|
this.shared.hide();
|
|
}
|
|
|
|
static showProgress() {
|
|
this.shared.showProgress();
|
|
}
|
|
|
|
private show(text: string, cancelBlock: () => void, sureBlock: () => void) {
|
|
FGUtil.dispose(this.main);
|
|
this.main = FGUtil.create(FGAlert.packageName, FGAlert.resName);
|
|
let alert = FGUtil.getComponent(this.main, "alert");
|
|
this.title = FGUtil.getTextField(alert, "title");
|
|
this.cancelBtn = FGUtil.getButton(alert, "cancel_btn");
|
|
this.sureBtn = FGUtil.getButton(alert, "sure_btn")
|
|
this.progressBar = FGUtil.getProgressBar(alert, "progress");
|
|
this.cancelBtn.onClick(() => {
|
|
cancelBlock();
|
|
});
|
|
this.sureBtn.onClick(() => {
|
|
sureBlock();
|
|
})
|
|
this.cancelBtn.visible = true;
|
|
this.sureBtn.visible = true;
|
|
this.progressBar.visible = false;
|
|
let root = FGUtil.root();
|
|
if (root) {
|
|
this.title.text = text;
|
|
root.addChild(this.main);
|
|
FGUtil.fitScreen(this.main);
|
|
}
|
|
}
|
|
|
|
private show2(text: string, tip1: string, tip2: string, btn1Title: string, btn2Title: string, listData: any, cancelBlock: () => void, sureBlock: () => void) {
|
|
FGUtil.dispose(this.main);
|
|
this.main = FGUtil.create(FGAlert.packageName, "alert_main2");
|
|
let alert = FGUtil.getComponent(this.main, "alert");
|
|
this.title = FGUtil.getTextField(alert, "title");
|
|
this.tip1 = FGUtil.getTextField(alert, "tip1");
|
|
this.tip2 = FGUtil.getTextField(alert, "tip2");
|
|
this.cancelBtn = FGUtil.getButton(alert, "btn1");
|
|
this.sureBtn = FGUtil.getButton(alert, "btn2")
|
|
this.cancelBtn.onClick(() => {
|
|
cancelBlock();
|
|
this.hide();
|
|
});
|
|
this.sureBtn.onClick(() => {
|
|
sureBlock();
|
|
this.hide();
|
|
})
|
|
var list = FGUtil.getList(alert, "list");
|
|
list.removeChildrenToPool();
|
|
for (let i in listData) {
|
|
let item = list.addItemFromPool().asCom;
|
|
let itemData = ItemUtil.getItemData(listData[i]);
|
|
FGUtil.getLoader(item, "icon").url = `ui://main_ui/${itemData.icon}`;
|
|
let count = GoodsMgr.getItem(listData[i]).count;
|
|
FGUtil.getTextField(item, "title").text = count;
|
|
FGUtil.getControl(item, "isZero").selectedIndex = count > 0 ? 0 : 1
|
|
}
|
|
list.resizeToFit(listData.length);
|
|
let root = FGUtil.root();
|
|
if (root) {
|
|
this.title.text = text;
|
|
this.tip1.text = tip1;
|
|
this.tip2.text = tip2;
|
|
this.cancelBtn.title = btn1Title;
|
|
this.sureBtn.title = btn2Title;
|
|
root.addChild(this.main);
|
|
FGUtil.fitScreen(this.main);
|
|
}
|
|
FGUtil.getComponent(this.main, "bg").onClick(() => {
|
|
this.hide();
|
|
})
|
|
}
|
|
|
|
hide() {
|
|
FGUtil.dispose(this.main);
|
|
this.main = null;
|
|
}
|
|
|
|
showProgress() {
|
|
this.cancelBtn.visible = false;
|
|
this.sureBtn.visible = false;
|
|
this.progressBar.visible = true;
|
|
}
|
|
} |