MatchMaster/assets/lose/script/LosePanel.ts
2026-09-21 15:30:27 +08:00

103 lines
3.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { renderGiveUpConfirmation } from "../../Script/GiveUpConfirmation";
const { ccclass, property } = cc._decorator;
type LosePanelAction = (event?: cc.Event, customEventData?: string) => void;
interface LosePanelActions {
[name: string]: LosePanelAction;
}
/** Lose 的按钮桥接和放弃确认展示;结算仍由 Map 管理。 */
@ccclass
export default class LosePanel extends cc.Component {
@property({ type: [cc.SpriteFrame], tooltip: "放弃提示,依次为 giveup1~giveup6" })
giveUpFrames: cc.SpriteFrame[] = [];
private actions: LosePanelActions = null;
private reviveCoin: cc.Node = null;
private reviveCost: number = 0;
private reviveAffordable: boolean = null;
setReviveCoin(node: cc.Node, cost: number) {
this.reviveCoin = node;
this.reviveCost = cost;
this.reviveAffordable = null;
this.update();
}
update() {
if (!this.reviveCoin || !cc.isValid(this.reviveCoin)) return;
const affordable = cc.fx.GameConfig.GM_INFO.coin >= this.reviveCost;
if (affordable === this.reviveAffordable) return;
this.reviveAffordable = affordable;
const color = affordable ? cc.color(255, 215, 0) : cc.color(255, 64, 64);
this.reviveCoin.children.forEach(digit => digit.color = color);
}
bind(actions: LosePanelActions) {
this.actions = actions || {};
}
showGiveUpConfirmation(hp: boolean, day: boolean, winStreak: boolean, rainbow: boolean): boolean {
const lose = this.node.getChildByName("lose");
lose.getChildByName("WinStreak").active = false;
lose.getChildByName("WinStreak2").active = false;
if (!hp && !day && !winStreak) return false;
const panel = lose.getChildByName(rainbow ? "WinStreak2" : "WinStreak");
renderGiveUpConfirmation(panel, this.giveUpFrames, { hp, day, winStreak });
panel.active = true;
return true;
}
shareFriend(event?: cc.Event, customEventData?: string) {
this.invoke("shareFriend", event, customEventData);
}
shareFriend2(event?: cc.Event, customEventData?: string) {
this.invoke("shareFriend2", event, customEventData);
}
shareClose(event?: cc.Event, customEventData?: string) {
this.invoke("shareClose", event, customEventData);
}
homeBtn(event?: cc.Event, customEventData?: string) {
this.invoke("homeBtn", event, customEventData);
}
reviewLevel(event?: cc.Event, customEventData?: string) {
this.invoke("reviewLevel", event, customEventData);
}
closeWinStreak(event?: cc.Event, customEventData?: string) {
this.invoke("closeWinStreak", event, customEventData);
}
openHealth(event?: cc.Event, customEventData?: string) {
this.invoke("openHealth", event, customEventData);
}
returnHome(event?: cc.Event, customEventData?: string) {
this.invoke("returnHome", event, customEventData);
}
againLevel(event?: cc.Event, customEventData?: string) {
this.invoke("againLevel", event, customEventData);
}
private invoke(name: string, event?: cc.Event, customEventData?: string) {
const action = this.actions && this.actions[name];
if (action) {
action(event, customEventData);
return;
}
cc.warn("LosePanel action is not bound:", name);
}
onDestroy() {
this.actions = null;
}
}