117 lines
4.3 KiB
TypeScript
117 lines
4.3 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 { getGameId } from '../../Main/Scripts/main/comm';
|
|
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;
|
|
|
|
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;
|
|
confirmCb: Function = null;
|
|
|
|
open(diff: number, confirmCb: () => void) {
|
|
this.chooseDiffSkeleton.setAnimation(0, null, false);
|
|
this.currentDiff = diff;
|
|
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;
|
|
|
|
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.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(() => {
|
|
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() {
|
|
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() {
|
|
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() {
|
|
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();
|
|
}
|
|
}
|
|
|