112 lines
2.6 KiB
TypeScript
112 lines
2.6 KiB
TypeScript
import { _decorator, Component, Node, Label, tween, Vec3, UIOpacity } from "cc";
|
|
import li_BaseView from "../../../Main/Common/li_BaseView";
|
|
import Utils from "../../../Main/Common/Utils";
|
|
import { ViewManager } from "../../../Main/Manager/ViewManager";
|
|
import { GButton } from "../../../Main/Common/GButton";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
interface TipsPanelData {
|
|
content: string;
|
|
duration?: number;
|
|
autoClose?: boolean;
|
|
}
|
|
|
|
@ccclass("TipsPanel")
|
|
export class TipsPanel extends li_BaseView {
|
|
private _nodeTab: any = {};
|
|
private _data: TipsPanelData;
|
|
private contentLabel: Label;
|
|
|
|
static show(content: string, duration: number = 1) {
|
|
ViewManager.I.openBundlesPopupView("TipsPanel", {
|
|
content: content,
|
|
duration: duration,
|
|
autoClose: true,
|
|
});
|
|
}
|
|
|
|
onLoadCT() {
|
|
Utils.parseNode(this.node, this._nodeTab);
|
|
this.contentLabel = this._nodeTab.text.getComponent(Label);
|
|
this.setupUI();
|
|
|
|
// 如果数据已经传入,立即更新内容
|
|
if (this._data) {
|
|
this.updateContent();
|
|
}
|
|
}
|
|
|
|
openUIData(data: TipsPanelData) {
|
|
this._data = data;
|
|
|
|
// 如果UI已经初始化,立即更新内容
|
|
if (this.contentLabel) {
|
|
this.updateContent();
|
|
}
|
|
}
|
|
|
|
private setupUI() {
|
|
if (this._nodeTab.mask) {
|
|
GButton.BandClick(this._nodeTab.mask, this.onMaskClick, this);
|
|
}
|
|
|
|
this.node.setScale(Vec3.ZERO);
|
|
const uiOpacity =
|
|
this.node.getComponent(UIOpacity) || this.node.addComponent(UIOpacity);
|
|
uiOpacity.opacity = 0;
|
|
|
|
this.playShowAnimation();
|
|
}
|
|
|
|
private updateContent() {
|
|
if (this.contentLabel && this._data) {
|
|
this.contentLabel.string = this._data.content;
|
|
|
|
if (this._data.autoClose !== false) {
|
|
const duration = this._data.duration || 1;
|
|
this.scheduleOnce(this.autoClose, duration);
|
|
}
|
|
}
|
|
}
|
|
|
|
private playShowAnimation() {
|
|
const uiOpacity = this.node.getComponent(UIOpacity);
|
|
|
|
tween(this.node)
|
|
.to(0.3, { scale: Vec3.ONE }, { easing: "backOut" })
|
|
.start();
|
|
|
|
tween(uiOpacity).to(0.3, { opacity: 255 }).start();
|
|
}
|
|
|
|
private playHideAnimation(callback?: () => void) {
|
|
const uiOpacity = this.node.getComponent(UIOpacity);
|
|
|
|
tween(this.node)
|
|
.to(0.2, { scale: new Vec3(0.8, 0.8, 1) })
|
|
.start();
|
|
|
|
tween(uiOpacity)
|
|
.to(0.2, { opacity: 0 })
|
|
.call(() => {
|
|
callback && callback();
|
|
})
|
|
.start();
|
|
}
|
|
|
|
private onMaskClick() {
|
|
this.closePanel();
|
|
}
|
|
|
|
private autoClose() {
|
|
this.closePanel();
|
|
}
|
|
|
|
private closePanel() {
|
|
this.playHideAnimation(() => {
|
|
this.close();
|
|
});
|
|
}
|
|
}
|