MatchMaster/assets/gacha_bundle/script/GachaManager.ts
2026-07-30 12:22:02 +08:00

786 lines
30 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import JiaZai from "../../Script/JiaZai";
import Utils from "../../Script/module/Pay/Utils";
import { MiniGameManager } from "../../Script/Sdk/MiniGameManager";
import { MiniGameSdk } from "../../Script/Sdk/MiniGameSdk";
const { ccclass, property } = cc._decorator;
//排行榜
@ccclass
export default class GachaManager extends cc.Component {
@property(cc.Node) //用户头像换图
avatar: cc.Node = null;
@property(cc.Node) //用户头像换图
catNode: cc.Node = null;
@property({ type: [cc.SpriteFrame], tooltip: "头像图片" })
icon: Array<cc.SpriteFrame> = [];
@property({ type: [cc.SpriteFrame], tooltip: "头像稀有度" })
kuang: Array<cc.SpriteFrame> = [];
@property({ type: [cc.SpriteFrame], tooltip: "猫图片" })
cat_Icon: Array<cc.SpriteFrame> = [];
@property(cc.AudioClip)
buttonAudio: cc.AudioClip = null;
@property(cc.AudioClip)
dropAudio: cc.AudioClip = null;
@property(cc.AudioClip)
openAudio: cc.AudioClip = null;
avatarData: any = null;
catArr: any = null;
headArr: any = null;
own = 0;
cat = 0;
reward = 0;
phase = 2;
private _phaseCenterX: number = 0;
private _phaseSwitching: boolean = false;
private _phaseTweens: cc.Tween[] = [];
private _phaseTabTweens: cc.Tween[] = [];
private _phaseTabOrigin: { [key: string]: any } = {};
private readonly _phaseMoveDuration: number = 0.3;
private _showReward2Button = () => {
const rewardNode = this.node.getChildByName("getReward2");
if (rewardNode) {
rewardNode.getChildByName("btn").active = true;
}
};
onLoad() {
this.avatarData = [];
this.own = 0;
this.cat = 0;
this.reward = 0;
const phase2Node = this.node.getChildByName("Phase2");
const phase1Node = this.node.getChildByName("Phase1");
this._phaseCenterX = phase2Node ? phase2Node.x : (phase1Node ? phase1Node.x : 0);
this._cachePhaseTabLayout();
this._showPhaseImmediately(2);
// this.init();
}
//初始化数据
init(data, film, catArr, keepCurrentPhase: boolean = false) {
this.avatarData = [];
this.own = 0;
this.cat = 0;
if (!keepCurrentPhase) {
this.phase = 2;
}
this.catArr = [];
if (catArr) {
this.catArr = catArr;
this.cat = this.catArr.length;
}
console.log("222222初始化数据", data, film, catArr);
cc.fx.GameConfig.GM_INFO.film = film;
if (data) {
this.avatarData = data;
this.own = this.avatarData.length;
}
this._refreshOwnedStates();
let botoom = this.node.getChildByName("Phase1").getChildByName("bottom");
if (this.phase == 1) {
this.node.getChildByName("Phase2").active = false;
this.node.getChildByName("Phase1").active = true;
botoom.getChildByName("no").active = false;
botoom.getChildByName("yes").active = false;
if (this.own >= 8) {
botoom.getChildByName("total").active = false;
botoom.active = false;
this.node.getChildByName("Phase1").getChildByName("finishi").active = true;
}
else {
let cost = this.getCostFilm();
botoom.getChildByName("total").getComponent(cc.Label).string = cost.toString();
console.log("抽卡所需film", cost);
if (film >= cost) {
botoom.getChildByName("yes").active = true;
console.log("有足够film");
botoom.getChildByName("yes").getComponent(cc.Label).string = film.toString();
}
else {
console.log("没有足够film");
botoom.getChildByName("no").active = true;
botoom.getChildByName("no").getComponent(cc.Label).string = film.toString();
}
console.log("拥有film", film);
cc.fx.GameConfig.GM_INFO.film = film;
}
}
else if (this.phase == 2) {
botoom = this.node.getChildByName("Phase2").getChildByName("bottom");
let btn = botoom.getChildByName("dayinBtn");
cc.tween(btn)
.delay(1)
.to(0.5, { rotation: 0 })
.start();
this.node.getChildByName("Phase2").active = true;
this.node.getChildByName("Phase1").active = false;
botoom.getChildByName("no").active = false;
botoom.getChildByName("yes").active = false;
if (this.cat >= 8) {
botoom.getChildByName("total").active = false;
this.node.getChildByName("Phase2").getChildByName("finishi").active = true;
}
else {
let cost = this.getCostFilm2();
botoom.getChildByName("total").getComponent(cc.Label).string = cost.toString();
console.log("抽卡所需film", cost);
if (film >= cost) {
botoom.getChildByName("yes").active = true;
console.log("有足够film");
botoom.getChildByName("yes").getComponent(cc.Label).string = film.toString();
}
else {
console.log("没有足够film");
botoom.getChildByName("no").active = true;
botoom.getChildByName("no").getComponent(cc.Label).string = film.toString();
}
console.log("拥有film", film);
cc.fx.GameConfig.GM_INFO.film = film;
}
}
this._showPhaseImmediately(this.phase);
this._refreshPhaseCurrency(this.phase);
}
getCostFilm() {
let film = [5, 10, 25, 35, 55, 70, 100, 120];
if (this.own > film.length)
this.own = film.length - 1;
let count = film[this.own];
return count;
}
getCostFilm2() {
let film = [5, 10, 25, 35, 55, 70, 100, 120];
if (this.cat > film.length)
this.cat = film.length - 1;
let count = film[this.cat];
return count;
}
closeGacha() {
const jiazaiNode = cc.find("Canvas"); // 假设 JiaZai 挂在 Canvas 节点
const jiazaiComp = jiazaiNode.getComponent(JiaZai);
if (jiazaiComp) {
jiazaiComp.closeGacha();
} else {
console.log("无法获取JiaZai组件");
}
}
playGacha() {
if (this.own >= 8) {
MiniGameSdk.API.showToast("已拥有当期所有头像");
return;
}
else {
let cost = this.getCostFilm();
if (cc.fx.GameConfig.GM_INFO.film < cost) {
MiniGameSdk.API.showToast("代币不足,闯关获取更多代币!");
return;
}
}
this.openLoad(null);
Utils.getGacha(res => {
console.log("抽卡结果", res);
if (res.code == 1) {
console.log("抽卡成功");
cc.fx.GameConfig.GM_INFO.film = res.data.film;
console.log("所剩余代币", cc.fx.GameConfig.GM_INFO.film);
let headArr = cc.fx.GameTool.getAvatarData(res.data.headArr);
const rewardId = Number(res.data.reward);
if (headArr.indexOf(rewardId) === -1) {
headArr.push(rewardId);
}
this.init(headArr, cc.fx.GameConfig.GM_INFO.film, this.catArr, true);
this.openReward(res.data.reward);
cc.fx.GameTool.shushu_Track("avatar_gacha", {
pool_id: "spring",
pull_count: (this.own + 1),
film_count: (8 - this.own),
film_left: (8 - this.own - 1),
is_success: true,
result: "spring_" + res.data.reward.toString(),
});
}
else if (res.code == 0) {
MiniGameSdk.API.showToast(res.msg);
cc.fx.GameTool.shushu_Track("avatar_gacha", {
pool_id: "spring",
pull_count: (this.own + 1),
film_count: (8 - this.own),
film_left: (8 - this.own),
is_success: false,
result: "",
});
}
else {
MiniGameSdk.API.showToast("网络异常,请稍后再试");
cc.fx.GameTool.shushu_Track("avatar_gacha", {
pool_id: "spring",
pull_count: (this.own + 1),
film_count: (8 - this.own),
film_left: (8 - this.own),
is_success: false,
result: "",
});
}
this.closeLoad();
});
// let cost = this.getCostFilm();
// if (cc.fx.GameConfig.GM_INFO.film >= cost) {
// }
}
playGacha2() {
// 点击按钮的一瞬间播放抽猫专用按钮音效。
this.playGachaEffect("button");
let btn = this.node.getChildByName("Phase2").getChildByName("bottom").getChildByName("dayinBtn");
if (this.cat >= 8) {
MiniGameSdk.API.showToast("已拥有当期所有猫咪");
return;
}
else {
let cost = this.getCostFilm2();
if (cc.fx.GameConfig.GM_INFO.film < cost) {
MiniGameSdk.API.showToast("代币不足,闯关获取更多代币!");
return;
}
}
btn.runAction(cc.rotateTo(0.8, 90));
this.openLoad("drop");
setTimeout(() => {
Utils.getCat(res => {
console.log("抽卡结果", res);
if (res.code == 1) {
console.log("抽卡成功");
cc.fx.GameConfig.GM_INFO.film = res.data.film;
cc.fx.GameConfig.GM_INFO.catArr = Array.isArray(res.data.catArr)
? res.data.catArr.slice()
: [];
console.log("所剩余代币", cc.fx.GameConfig.GM_INFO.film);
let catArr = cc.fx.GameTool.getCatData(res.data.catArr);
const rewardId = Number(res.data.reward);
if (catArr.indexOf(rewardId) === -1) {
catArr.push(rewardId);
}
this.init(this.avatarData, cc.fx.GameConfig.GM_INFO.film, catArr, true);
this.openReward2(res.data.reward);
cc.fx.GameTool.shushu_Track("avatar_gacha", {
pool_id: "summer1",
pull_count: (this.cat + 1),
film_count: (8 - this.cat),
film_left: (8 - this.cat - 1),
is_success: true,
result: "summer_" + res.data.reward.toString(),
});
}
else if (res.code == 0) {
MiniGameSdk.API.showToast(res.msg);
cc.fx.GameTool.shushu_Track("avatar_gacha", {
pool_id: "summer1",
pull_count: (this.cat + 1),
film_count: (8 - this.cat),
film_left: (8 - this.cat),
is_success: false,
result: "",
});
}
else {
MiniGameSdk.API.showToast("网络异常,请稍后再试");
cc.fx.GameTool.shushu_Track("avatar_gacha", {
pool_id: "summer1",
pull_count: (this.cat + 1),
film_count: (8 - this.cat),
film_left: (8 - this.cat),
is_success: false,
result: "",
});
}
this.closeLoad();
});
}, 1000);
}
/** 播放抽猫流程音效,并沿用游戏现有的音效开关。 */
public playGachaEffect(type: string) {
if (cc.fx.GameConfig.GM_INFO
&& cc.fx.GameConfig.GM_INFO.effectOpen === false) {
return;
}
let clip: cc.AudioClip = null;
if (type === "button") {
clip = this.buttonAudio;
}
else if (type === "drop") {
clip = this.dropAudio;
}
else if (type === "open") {
clip = this.openAudio;
}
if (!clip) {
return;
}
const audioManager = cc.fx.AudioManager && cc.fx.AudioManager._instance;
if (audioManager && audioManager.play) {
audioManager.play(clip, false, null, false);
}
else {
cc.audioEngine.playEffect(clip, false);
}
}
openReward(data) {
this.reward = data;
this.node.getChildByName("getReward").active = true;
this.node.getChildByName("getReward").getChildByName("r").zIndex = 100;
this.node.getChildByName("getReward").getChildByName("sr").zIndex = 100;
this.node.getChildByName("getReward").getChildByName("ssr").zIndex = 100;
this.node.getChildByName("getReward").getChildByName("r").active = false;
this.node.getChildByName("getReward").getChildByName("sr").active = false;
this.node.getChildByName("getReward").getChildByName("ssr").active = false;
this.node.getChildByName("getReward").getChildByName("btn").active = false;
let kuang = 0;
if (data == 24 || data == 25)
kuang = 1;
else if (data == 26)
kuang = 2;
else
kuang = 0;
this.node.getChildByName("getReward").getChildByName("paper").getChildByName("bg").getComponent(cc.Sprite).spriteFrame = this.kuang[kuang];
this.node.getChildByName("getReward").getChildByName("paper").getChildByName("icon").getComponent(cc.Sprite).spriteFrame = this.icon[this.reward - 19];
this.node.getChildByName("getReward").getChildByName("paper").opacity = 0;
this.node.getChildByName("getReward").getChildByName("dayin1").opacity = 0;
this.node.getChildByName("getReward").getChildByName("dayin2").opacity = 0;
this.node.getChildByName("getReward").getChildByName("dayin1").zIndex = 2;
this.node.getChildByName("getReward").getChildByName("dayin2").zIndex = 4;
this.node.getChildByName("getReward").getChildByName("paper").getChildByName("bg").getComponent("CardFlipEffect").init();
this.node.getChildByName("getReward").getChildByName("paper").getChildByName("icon").getComponent("CardFlipEffect").init();
cc.tween(this.node.getChildByName("getReward").getChildByName("paper"))
.to(0.2, { opacity: 255 })
.start();
cc.tween(this.node.getChildByName("getReward").getChildByName("dayin1"))
.to(0.2, { opacity: 255 })
.start();
cc.tween(this.node.getChildByName("getReward").getChildByName("dayin2"))
.to(0.2, { opacity: 255 })
.start();
}
openReward2(data) {
this.reward = data;
const rewardNode = this.node.getChildByName("getReward2");
const animeNode = rewardNode.getChildByName("gatchaAnime");
const wasActive = rewardNode.active;
this.unschedule(this._showReward2Button);
rewardNode.getChildByName("btn").active = false;
console.log("具体奖励:", this.reward);
animeNode.getChildByName("4").getComponent(cc.Sprite).spriteFrame = this.cat_Icon[this.reward];
rewardNode.active = true;
// 正常的关闭后重开由 GachaDrawAnime.onEnable 自动重播;
// 如果重复调用时节点本来就是打开的,也主动从头重播。
if (wasActive) {
const anime = animeNode.getComponent("GachaDrawAnime") as any;
if (anime && anime.playAnime) {
anime.playAnime();
}
}
this.scheduleOnce(this._showReward2Button, 2);
}
showReward() {
this.node.getChildByName("getReward").getChildByName("btn").active = true;
let actionName = cc.fx.GameTool.getActionName(this.reward.toString());
if (this.reward < 24) {
this.node.getChildByName("getReward").getChildByName("r").active = true;
cc.fx.GameTool.loadSpineSimple(this.node.getChildByName("getReward").getChildByName("r").getChildByName("sp"), actionName);
}
else if (this.reward == 24 || this.reward == 25) {
this.node.getChildByName("getReward").getChildByName("sr").active = true;
cc.fx.GameTool.loadSpineSimple(this.node.getChildByName("getReward").getChildByName("sr").getChildByName("sp"), actionName);
if (this.reward == 24) {
this.node.getChildByName("getReward").getChildByName("sr").getChildByName("sp").y = 60
} else {
this.node.getChildByName("getReward").getChildByName("sr").getChildByName("sp").y = 35
}
}
else if (this.reward == 26) {
this.node.getChildByName("getReward").getChildByName("ssr").active = true;
cc.fx.GameTool.loadSpineSimple(this.node.getChildByName("getReward").getChildByName("ssr").getChildByName("sp"), actionName);
}
}
closeReward() {
this.unschedule(this._showReward2Button);
this.node.getChildByName("getReward").active = false;
this.node.getChildByName("getReward2").active = false;
}
openLoad(type) {
this.node.getChildByName("Loading").active = true;
this.node.getChildByName("Loading").getChildByName("load").stopAllActions();
this.node.getChildByName("Loading").getChildByName("load").runAction(cc.rotateTo(2, 1080).repeatForever());
if (type === "drop") {
this.node.getChildByName("Loading").getChildByName("load").opacity = 0;
this.node.getChildByName("Loading").getChildByName("label").opacity = 0;
this.node.getChildByName("Loading").getChildByName("bg").opacity = 0;
}
setTimeout(() => {
if (this.node) {
this.node.getChildByName("Loading").getChildByName("load").opacity = 255;
this.node.getChildByName("Loading").getChildByName("label").opacity = 255;
this.node.getChildByName("Loading").getChildByName("bg").opacity = 120;
}
}, 1000);
}
closeLoad() {
this.node.getChildByName("Loading").active = false;
this.node.getChildByName("Phase2").getChildByName("bottom").getChildByName("dayinBtn").rotation = 0;
}
start() {
}
changePhase(event, customEventData) {
const phaseName = (customEventData || "").toString().toLowerCase();
const targetPhase = phaseName === "phase1" ? 1 : (phaseName === "phase2" ? 2 : 0);
if (targetPhase === 0) {
console.warn("changePhase收到无效参数:", customEventData);
return;
}
if (this._phaseSwitching || targetPhase === this.phase) {
return;
}
const phase1Node = this.node.getChildByName("Phase1");
const phase2Node = this.node.getChildByName("Phase2");
if (!phase1Node || !phase2Node) {
return;
}
this._stopPhaseTweens();
this._phaseSwitching = true;
this.phase = targetPhase;
this._refreshPhaseCurrency(targetPhase);
const offsetX = this._getPhaseOffsetX(phase1Node, phase2Node);
const incomingNode = targetPhase === 1 ? phase1Node : phase2Node;
const outgoingNode = targetPhase === 1 ? phase2Node : phase1Node;
const incomingStartX = this._phaseCenterX + (targetPhase === 1 ? -offsetX : offsetX);
const outgoingEndX = this._phaseCenterX + (targetPhase === 1 ? offsetX : -offsetX);
// Phase 根节点有全屏 Widget。先停用 Widget 并设置屏外坐标,
// 再激活节点,避免 Widget 在激活首帧把节点拉回中间造成闪烁。
this._setPhaseWidgetEnabled(incomingNode, false);
this._setPhaseWidgetEnabled(outgoingNode, false);
incomingNode.x = incomingStartX;
outgoingNode.x = this._phaseCenterX;
incomingNode.active = true;
outgoingNode.active = true;
const incomingTween: cc.Tween = cc.tween(incomingNode)
.to(this._phaseMoveDuration, { x: this._phaseCenterX }, { easing: "sineInOut" })
.call(() => {
incomingNode.x = this._phaseCenterX;
this._setPhaseWidgetEnabled(incomingNode, true);
this._phaseSwitching = false;
this._phaseTweens = [];
});
const outgoingTween: cc.Tween = cc.tween(outgoingNode)
.to(this._phaseMoveDuration, { x: outgoingEndX }, { easing: "sineInOut" })
.call(() => {
outgoingNode.x = outgoingEndX;
outgoingNode.active = false;
this._setPhaseWidgetEnabled(outgoingNode, true);
});
this._phaseTweens = [incomingTween, outgoingTween];
incomingTween.start();
outgoingTween.start();
this._playPhaseTabTweens(targetPhase);
}
private _showPhaseImmediately(targetPhase: number) {
const phase1Node = this.node.getChildByName("Phase1");
const phase2Node = this.node.getChildByName("Phase2");
if (!phase1Node || !phase2Node) {
return;
}
this._stopPhaseTweens();
const offsetX = this._getPhaseOffsetX(phase1Node, phase2Node);
this.phase = targetPhase === 1 ? 1 : 2;
this._setPhaseWidgetEnabled(phase1Node, false);
this._setPhaseWidgetEnabled(phase2Node, false);
if (this.phase === 1) {
phase1Node.x = this._phaseCenterX;
phase1Node.active = true;
phase2Node.x = this._phaseCenterX + offsetX;
phase2Node.active = false;
}
else {
phase2Node.x = this._phaseCenterX;
phase2Node.active = true;
phase1Node.x = this._phaseCenterX - offsetX;
phase1Node.active = false;
}
this._setPhaseWidgetEnabled(phase1Node, true);
this._setPhaseWidgetEnabled(phase2Node, true);
this._showPhaseTabsImmediately(this.phase);
}
private _getPhaseOffsetX(phase1Node: cc.Node, phase2Node: cc.Node): number {
return Math.max(
this.node.width,
cc.winSize.width,
phase1Node.width,
phase2Node.width
);
}
private _setPhaseWidgetEnabled(phaseNode: cc.Node, enabled: boolean) {
const widget = phaseNode.getComponent(cc.Widget);
if (!widget) {
return;
}
widget.enabled = enabled;
if (enabled && phaseNode.active) {
widget.updateAlignment();
}
}
private _stopPhaseTweens() {
for (let i = 0; i < this._phaseTweens.length; i++) {
if (this._phaseTweens[i]) {
this._phaseTweens[i].stop();
}
}
this._phaseTweens = [];
this._stopPhaseTabTweens();
this._phaseSwitching = false;
}
private _cachePhaseTabLayout() {
const tabNames = ["first", "two", "three"];
for (let i = 0; i < tabNames.length; i++) {
const node = this.node.getChildByName(tabNames[i]);
if (node) {
this._phaseTabOrigin[tabNames[i]] = {
x: node.x,
y: node.y,
width: node.width,
height: node.height,
scaleX: node.scaleX,
scaleY: node.scaleY
};
}
}
}
private _playPhaseTabTweens(targetPhase: number) {
const firstNode = this.node.getChildByName("first");
const twoNode = this.node.getChildByName("two");
const threeNode = this.node.getChildByName("three");
const firstOrigin = this._phaseTabOrigin.first;
const twoOrigin = this._phaseTabOrigin.two;
const threeOrigin = this._phaseTabOrigin.three;
if (!firstNode || !twoNode || !threeNode || !firstOrigin || !twoOrigin || !threeOrigin) {
return;
}
this._stopPhaseTabTweens();
firstNode.active = true;
twoNode.active = true;
threeNode.active = true;
const firstTarget = targetPhase === 1 ? twoOrigin : firstOrigin;
const twoTarget = targetPhase === 1 ? threeOrigin : twoOrigin;
const threeTarget = targetPhase === 1
? {
x: this._getPhaseTabRightOutX(threeNode),
y: threeOrigin.y,
width: threeOrigin.width,
height: threeOrigin.height,
scaleX: threeOrigin.scaleX,
scaleY: threeOrigin.scaleY
}
: threeOrigin;
const firstTween: cc.Tween = cc.tween(firstNode)
.to(this._phaseMoveDuration, firstTarget, { easing: "sineInOut" });
const twoTween: cc.Tween = cc.tween(twoNode)
.to(this._phaseMoveDuration, twoTarget, { easing: "sineInOut" });
const threeTween: cc.Tween = cc.tween(threeNode)
.to(this._phaseMoveDuration, threeTarget, { easing: "sineInOut" });
this._phaseTabTweens = [firstTween, twoTween, threeTween];
firstTween.start();
twoTween.start();
threeTween.start();
}
private _showPhaseTabsImmediately(targetPhase: number) {
const firstNode = this.node.getChildByName("first");
const twoNode = this.node.getChildByName("two");
const threeNode = this.node.getChildByName("three");
const firstOrigin = this._phaseTabOrigin.first;
const twoOrigin = this._phaseTabOrigin.two;
const threeOrigin = this._phaseTabOrigin.three;
if (!firstNode || !twoNode || !threeNode || !firstOrigin || !twoOrigin || !threeOrigin) {
return;
}
this._stopPhaseTabTweens();
this._applyPhaseTabState(firstNode, targetPhase === 1 ? twoOrigin : firstOrigin);
this._applyPhaseTabState(twoNode, targetPhase === 1 ? threeOrigin : twoOrigin);
this._applyPhaseTabState(threeNode, targetPhase === 1
? {
x: this._getPhaseTabRightOutX(threeNode),
y: threeOrigin.y,
width: threeOrigin.width,
height: threeOrigin.height,
scaleX: threeOrigin.scaleX,
scaleY: threeOrigin.scaleY
}
: threeOrigin);
}
private _applyPhaseTabState(node: cc.Node, state: any) {
node.x = state.x;
node.y = state.y;
node.width = state.width;
node.height = state.height;
node.scaleX = state.scaleX;
node.scaleY = state.scaleY;
}
private _getPhaseTabRightOutX(threeNode: cc.Node): number {
const viewWidth = Math.max(this.node.width, cc.winSize.width);
return this._phaseCenterX + viewWidth / 2 + threeNode.width * Math.abs(threeNode.scaleX) / 2 + 20;
}
private _stopPhaseTabTweens() {
for (let i = 0; i < this._phaseTabTweens.length; i++) {
if (this._phaseTabTweens[i]) {
this._phaseTabTweens[i].stop();
}
}
this._phaseTabTweens = [];
}
private _refreshPhaseCurrency(targetPhase: number) {
const phaseNode = this.node.getChildByName(targetPhase === 1 ? "Phase1" : "Phase2");
if (!phaseNode) {
return;
}
const bottomNode = phaseNode.getChildByName("bottom");
if (!bottomNode) {
return;
}
const noNode = bottomNode.getChildByName("no");
const yesNode = bottomNode.getChildByName("yes");
const totalNode = bottomNode.getChildByName("total");
if (!noNode || !yesNode || !totalNode) {
return;
}
noNode.active = false;
yesNode.active = false;
const ownedCount = targetPhase === 1 ? this.own : this.cat;
if (ownedCount >= 8) {
totalNode.active = false;
if (this.phase == 1) bottomNode.active = false;
return;
}
bottomNode.active = true;
totalNode.active = true;
const cost = targetPhase === 1 ? this.getCostFilm() : this.getCostFilm2();
const film = Number(cc.fx.GameConfig.GM_INFO.film) || 0;
const totalLabel = totalNode.getComponent(cc.Label);
if (totalLabel) {
totalLabel.string = cost.toString();
}
const filmNode = film >= cost ? yesNode : noNode;
filmNode.active = true;
const filmLabel = filmNode.getComponent(cc.Label);
if (filmLabel) {
filmLabel.string = film.toString();
}
}
private _refreshOwnedStates() {
this._setOwnedStates(this.avatar, this.avatarData, 19);
this._setOwnedStates(this.catNode, this.catArr, 4);
}
private _setOwnedStates(container: cc.Node, ownedData: any[], idOffset: number) {
if (!container) {
return;
}
for (let i = 0; i < container.childrenCount; i++) {
const ownNode = container.children[i].getChildByName("own");
if (ownNode) {
ownNode.active = false;
}
}
if (!ownedData) {
return;
}
for (let i = 0; i < ownedData.length; i++) {
const itemIndex = Number(ownedData[i]) - idOffset;
if (itemIndex < 0 || itemIndex >= container.childrenCount) {
continue;
}
const ownNode = container.children[itemIndex].getChildByName("own");
if (ownNode) {
ownNode.active = true;
}
}
}
}