rp_11009/assets/Main/Scripts/main/TipMessagePanel.ts
2026-04-01 11:10:33 +08:00

114 lines
3.0 KiB
TypeScript

import { _decorator, Component, Label, Node, tween, v3 } from 'cc';
import { I18nManager } from '../managers/I18nManager';
import { AudioManager } from '../managers/AudioManager';
const { ccclass, property } = _decorator;
@ccclass('TipMessagePanel')
export class TipMessagePanel extends Component {
@property(Node)
mainNode: Node = null;
@property(Label)
titleLabel: Label = null;
@property(Label)
msgLabel: Label = null;
@property(Node)
btnClose: Node = null;
@property(Node)
btnConfirm: Node = null;
@property(Node)
btnConfirmCenter: Node = null;
onConfirmCb: () => void = () => { };
onCloseCb: () => void = () => { };
canClickBtn: boolean = false;
hasTip: boolean = false;
setIsCenter(isCenter: boolean) {
this.canClickBtn = false;
this.btnConfirmCenter.active = isCenter;
this.btnConfirm.active = !isCenter;
this.btnClose.active = !isCenter;
}
setTitle(title: string) {
this.titleLabel.string = I18nManager.instance.t(title);
}
setMsg(msg: string) {
this.msgLabel.string = I18nManager.instance.t(msg);
}
setConfirmCallBack(cb: () => void) {
this.onConfirmCb = cb || (() => { });
}
setCloseCallBack(cb: () => void) {
this.onCloseCb = cb || (() => { });
}
setBtnLabel(isCenter: boolean, confirmStr: string, cancelStr: string) {
if (isCenter) {
this.btnConfirmCenter
.getChildByName("confirm_1")
.getComponent(Label).string = confirmStr;
} else {
this.btnConfirm.getChildByName("confirm").getComponent(Label).string =
confirmStr;
this.btnClose.getChildByName("cancel").getComponent(Label).string =
confirmStr = cancelStr;
}
}
show() {
this.node.active = true;
this.hasTip = true;
this.mainNode.scale = v3(0.1, 0.1, 0.1);
tween(this.mainNode)
.to(0.1, { scale: v3(1, 1, 1) }, { easing: 'quadOut' })
.call(() => {
this.canClickBtn = true;
})
.start();
this.btnClose.on(Node.EventType.TOUCH_START, this.onClickClose, this);
this.btnConfirm.on(Node.EventType.TOUCH_START, this.onClickConfirm, this);
this.btnConfirmCenter.on(Node.EventType.TOUCH_START, this.onClickConfirm, this);
// this.closeNode.on(Node.EventType.TOUCH_START, this.onClickClose, this);
}
onClickClose() {
if (!this.canClickBtn) return;
this.node.targetOff(this);
AudioManager.instance.playSFX('Click_Menu');
this.canClickBtn = false;
if (this.onCloseCb) this.onCloseCb();
this.node.active = false;
this.hasTip = false;
}
onClickConfirm() {
if (!this.canClickBtn) return;
this.node.targetOff(this);
AudioManager.instance.playSFX('Click_Menu');
this.canClickBtn = false;
if (this.onClickConfirm) this.onConfirmCb();
this.node.active = false;
this.hasTip = false;
}
getHasTip() {
return this.hasTip;
}
}