import { _decorator, Component, Node } from 'cc'; import JNLayerBase from '../../../../../extensions/ngame/assets/ngame/ui/base/JNLayerBase'; import { Label } from 'cc'; import { Button } from 'cc'; import { app } from '../../../App'; const { ccclass, property } = _decorator; export interface SelectionBoxInfo{ cancelText?:string, //取消按钮文字 cancel?:Function, //取消事件 confirmText?:string, //确认按钮文字 confirm?:Function, //确认事件 isHideMake?:boolean, //是否隐藏遮罩 isMaskClose?:boolean, //是否点击遮罩关闭 tigText?:string, //提示内容 titleText?:string, //标题内容 } @ccclass('SelectionBox') export class SelectionBox extends JNLayerBase { //标题 @property(Label) titleLabel:Label; //提示文字 @property(Label) tigLabel:Label; //取消按钮 @property(Button) cancalBtn:Button; //确认按钮 @property(Button) confirmBtn:Button; //按钮列表 @property(Node) btns:Node; data:SelectionBoxInfo; onJNLoad(data?: SelectionBoxInfo): void { this.data = data; //默认不可以 data.isMaskClose = !!data.isMaskClose; data.tigText = data.tigText || "这是一个提示选择框"; data.titleText = data.titleText || "标 题"; data.cancelText = data.cancelText || "取 消"; data.confirmText = data.confirmText || "确 认"; this.mask = !data.isHideMake; this.isClickMaskeClose = data.isMaskClose; this.tigLabel.string = data.tigText; this.titleLabel.string = data.titleText; //没有事件则不显示 this.cancalBtn.node.active = !!data.cancel; this.confirmBtn.node.active = !!data.confirm; //显示按钮文字 this.cancalBtn.getComponentInChildren(Label).string = data.cancelText; this.confirmBtn.getComponentInChildren(Label).string = data.confirmText; //如果都没有则隐藏按钮列表 if(!data.cancel && data.confirm) this.btns.active = false; super.onJNLoad(); } //点击确认 async onClickConfirm(){ this.data.confirm && await this.data.confirm(); //关闭页面 app.layer.CloseNode(this.node); } //点击取消 async onClickCancel(){ this.data.cancel && await this.data.cancel(); //关闭页面 app.layer.CloseNode(this.node); } }