rp_11009/assets/Game/Scripts/ChooseDiff.ts
TJH 6ab5f6ad2c
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 1m19s
首次进入难度选择,多语言修改
2026-05-18 16:45:06 +08:00

136 lines
5.2 KiB
TypeScript

import { _decorator, Component, Node, sp, tween, Vec3 } from 'cc';
import { GameDataManager } from '../../Main/Scripts/managers/GameDataManager';
import { NodePoolManager } from '../../Main/Scripts/managers/NodePoolManager';
import { callGameApi, getGameId } from '../../Main/Scripts/main/comm';
import { AudioManager } from '../../Main/Scripts/managers/AudioManager';
const { ccclass, property } = _decorator;
@ccclass('ChooseDiff')
export class ChooseDiff extends Component {
@property(Node)
mainNode: Node = null;
@property(sp.Skeleton)
chooseDiffSkeleton: sp.Skeleton = null;
@property(Node)
chooseDiffBgNode: Node = null;
@property(Node)
blackBg: Node = null;
currentDiff: number = 1;
lowBgPos: Vec3 = new Vec3(-330, 16, 0);
mediumBgPos: Vec3 = new Vec3(0, 16, 0);
highBgPos: Vec3 = new Vec3(330, 16, 0);
canClickBtn: boolean = true;
animationCb: Function = null;
confirmCb: Function = null;
open(diff: number, animationCb?: () => void, confirmCb?: () => void, isFirst: boolean = false) {
this.blackBg.active = isFirst;
this.node.getChildByName('main').getChildByName('Btn_Close_01').active = !isFirst;
this.chooseDiffSkeleton.setAnimation(0, null, false);
this.currentDiff = diff;
this.animationCb = animationCb;
this.confirmCb = confirmCb;
this.node.getChildByName('grayBg').active = true;
this.canClickBtn = false;
this.mainNode.active = true;
this.mainNode.setScale(0.1, 0.1, 0.1);
tween(this.mainNode)
.to(0.2, { scale: new Vec3(1, 1, 1) }, { easing: 'quadOut' })
.call(() => { this.canClickBtn = true; })
.start();
this.chooseDiffBgNode.setPosition(this.currentDiff == 1 ? this.lowBgPos : this.currentDiff == 2 ? this.mediumBgPos : this.highBgPos);
}
onBtnClose() {
if (!this.canClickBtn) return;
this.canClickBtn = false;
AudioManager.instance.playSFX("Click_Menu");
tween(this.mainNode)
.to(0.2, { scale: new Vec3(0.1, 0.1, 0.1) }, { easing: 'quadOut' })
.call(() => {
this.node.getChildByName('grayBg').active = false;
this.mainNode.active = false;
this.chooseDiffSkeleton.setAnimation(0, 'animation', false);
this.chooseDiffSkeleton.setCompleteListener(() => {
this.chooseDiffSkeleton.setAnimation(0, null, false);
this.chooseDiffSkeleton.setCompleteListener(null);
NodePoolManager.instance.putNodeToPool('ChooseDiff', this.node);
})
})
.start();
}
onBtnConfirm() {
if (!this.canClickBtn) return;
this.blackBg.active = false;
AudioManager.instance.playSFX("Click_Menu");
localStorage.setItem('HasGamePending', "1");
if (this.currentDiff === GameDataManager.instance.chooseDiff) {
this.onBtnClose();
return;
}
this.canClickBtn = false;
GameDataManager.instance.chooseDiff = this.currentDiff;
GameDataManager.instance.gamePending = String(getGameId()) + '_' + this.currentDiff;
localStorage.setItem('HasGamePending', String(this.currentDiff));
tween(this.mainNode)
.to(0.2, { scale: new Vec3(0.1, 0.1, 0.1) }, { easing: 'quadOut' })
.call(() => {
if (this.animationCb) this.animationCb();
this.mainNode.active = false;
this.node.getChildByName('grayBg').active = false;
this.chooseDiffSkeleton.setAnimation(0, 'animation', false);
this.chooseDiffSkeleton.setCompleteListener(() => {
this.chooseDiffSkeleton.setAnimation(0, null, false);
this.chooseDiffSkeleton.setCompleteListener(null);
NodePoolManager.instance.putNodeToPool('ChooseDiff', this.node);
if (this.confirmCb) this.confirmCb();
})
})
.start();
}
onBtnLow() {
AudioManager.instance.playSFX("Click_Menu");
if (this.currentDiff == 1 || !this.canClickBtn) return;
this.currentDiff = 1;
this.canClickBtn = false;
tween(this.chooseDiffBgNode)
.to(0.2, { position: this.lowBgPos }, { easing: 'quadOut' })
.call(() => { this.canClickBtn = true; })
.start();
}
onBtnMedium() {
AudioManager.instance.playSFX("Click_Menu");
if (this.currentDiff == 2 || !this.canClickBtn) return;
this.currentDiff = 2;
this.canClickBtn = false;
tween(this.chooseDiffBgNode)
.to(0.2, { position: this.mediumBgPos }, { easing: 'quadOut' })
.call(() => { this.canClickBtn = true; })
.start();
}
onBtnHigh() {
AudioManager.instance.playSFX("Click_Menu");
if (this.currentDiff == 3 || !this.canClickBtn) return;
this.currentDiff = 3;
this.canClickBtn = false;
tween(this.chooseDiffBgNode)
.to(0.2, { position: this.highBgPos }, { easing: 'quadOut' })
.call(() => { this.canClickBtn = true; })
.start();
}
}