import { GameUILayers, gui, ui_base } from "../../core/ui/ui"; import get_new_wait from "../../core/util_class/Wait"; import { ModuleDef } from "../../scripts/ModuleDef"; import { Layout_UIAlert } from "./Layout_UIAlert"; export class UIAlert extends ui_base { constructor() { super(ModuleDef.BASIC,'ui_alert/UI_Alert', GameUILayers.ALERT, Layout_UIAlert); } /** * 显示一个选择提示 * @param options title?:string 标题,content?:string内容,ok?:string 确认字,cancel?:string 取消字,show?:boolean是否显示取消 * @returns 是否选择确定 */ public static async show(options:{title?:string,content?:string,ok?:string,cancel?:string,show?:boolean}):Promise{ const ui = await gui.show(UIAlert); return await ui.await_choose(options); } protected onCreated(): void { let layout = this.getLayout(); this.onButtonEvent(layout.btnOK, () => { this.wait.resolve(true); this.close(); }); this.onButtonEvent(layout.btnCancel, () => { this.wait.resolve(false); this.close(); }); } protected onDispose(): void { this.wait.resolve(false); this.wait.dispose(); this.wait=null; } private wait=get_new_wait(); public async await_choose(options:{title?:string,content?:string,ok?:string,cancel?:string,show?:boolean}):Promise{ let layout = this.getLayout(); layout.title.string = options.title || '提示'; layout.btnCancel.node.active = options.show; return this.wait.wait(); } }