rp_11009/assets/Game/Scripts/Icon.ts

214 lines
6.7 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 { _decorator, Component, director, find, Node, ProgressBarComponent, sp, Sprite, SpriteFrame, tween, Tween, UITransform, v3 } from 'cc';
import { DEV, EDITOR } from 'cc/env';
import { NodePoolManager } from '../../Main/Scripts/managers/NodePoolManager';
import { GameDataManager } from '../../Main/Scripts/managers/GameDataManager';
import { IconMsg } from './IconMsg';
import { AudioManager } from '../../Main/Scripts/managers/AudioManager';
const { ccclass, property } = _decorator;
enum ICON_STATE {
IDLE = 0,
FAST = 1,
HIDE = 2,
}
@ccclass('Icon')
export class Icon extends Component {
@property(Node)
normalNode: Node = null;
@property(Node)
fastNode: Node = null;
@property(Node)
spineNode: Node = null;
@property([SpriteFrame])
multiSpriteFrames: SpriteFrame[] = [];
@property([SpriteFrame])
blurMultiSpriteFrames: SpriteFrame[] = [];
private iconId: number = 99;
private lheight: number = 1;
private rollerId: number = 0;
private state: ICON_STATE = ICON_STATE.IDLE;
private isFastMode: boolean = false;
private isWild: boolean = false;
private isScatter: boolean = false;
private isMulti: boolean = false;
set index(id: number) { this.iconId = id; this.isWild = id === 0; this.isScatter = id === 1; this.isMulti = id === 12 }
get index(): number { return this.iconId }
get isWildOrScatter(): boolean {
return this.isWild || this.isScatter;
}
resetState() {
this.unscheduleAllCallbacks();
Tween.stopAllByTarget(this.node);
this.node.scale = v3(1, 1, 1);
this.state = ICON_STATE.IDLE;
this.node.active = true;
this.normalNode.active = true;
this.showFastIcon(false);
this.spineNode.active = false;
let spine = this.spineNode.getChildByName('spine').getComponent(sp.Skeleton);
if (spine) {
spine.setCompleteListener(null);
}
this.node.targetOff(this.node);
this.node.off(Node.EventType.TOUCH_END);
this.node.on(Node.EventType.TOUCH_END, () => {
this.onClickIconNode();
})
}
initIcon(id: number, lHeight: number = 1, rollerId: number = 0) {
this.resetState();
this.index = id;
this.lheight = lHeight;
this.rollerId = rollerId;
}
showFastIcon(isFast: boolean) {
if (this.isFastMode === isFast) return;
this.isFastMode = isFast;
this.state = isFast ? ICON_STATE.FAST : ICON_STATE.IDLE;
this.normalNode.active = !isFast;
this.fastNode.active = isFast;
}
checkHasAnimation(spine: sp.Skeleton, animationName: string) {
let animations = (spine.skeletonData._skeletonJson as any).animations;
if (animations.hasOwnProperty(animationName)) {
return true;
} else {
return false;
}
}
playIdleSpine(bol: boolean) {
let spine = this.spineNode.getChildByName('spine').getComponent(sp.Skeleton);
// if (spine && this.checkHasAnimation(spine, 'chixu')) {
// if (bol) {
// this.normalNode.active = false;
// this.spineNode.active = true;
// spine.setAnimation(0, 'chixu', true);
// } else {
this.normalNode.active = true;
this.spineNode.active = false;
// }
// }
}
playBounceSpine(isLoop: boolean = false) {
let spine = this.spineNode.getChildByName('spine').getComponent(sp.Skeleton);
if (spine && this.checkHasAnimation(spine, 'tan')) {
// this.normalNode.active = false
this.spineNode.active = true;
spine.setAnimation(0, 'tan', isLoop);
if (!isLoop) {
spine.setCompleteListener(() => {
spine.setCompleteListener(null);
if (this.checkHasAnimation(spine, 'chixu')) {
this.playIdleSpine(true);
} else {
this.normalNode.active = true;
this.spineNode.active = false;
}
})
}
} else {
spine.setCompleteListener(null);
if (this.checkHasAnimation(spine, 'chixu')) {
this.playIdleSpine(true);
} else {
this.normalNode.active = true;
this.spineNode.active = false;
}
}
}
playScatterWaitSpine(bol: boolean) {
let spine = this.spineNode.getChildByName('spine').getComponent(sp.Skeleton);
if (this.iconId == 1) {
if (spine && this.checkHasAnimation(spine, 'dengdai')) {
if (bol) {
// this.normalNode.active = false;
this.spineNode.active = true;
spine.setAnimation(0, 'dengdai', true);
} else {
this.playIdleSpine(true);
}
}
}
}
playDeleteSpine() {
let spine = this.spineNode.getChildByName('spine').getComponent(sp.Skeleton);
if (spine && this.checkHasAnimation(spine, 'xiaoshi')) { // 10帧 icon消失 23帧 全部消失
spine.setCompleteListener(null);
// this.normalNode.active = false;
this.spineNode.active = true;
spine.setAnimation(0, 'xiaoshi', false);
spine.setCompleteListener(() => {
spine.setCompleteListener(null);
this.spineNode.active = false;
})
}
}
playAppearAnimation() {
this.scheduleOnce(() => {
tween(this.node)
.set({ scale: v3(0.1, 0.1, 0.1) })
.to(0.2, { scale: v3(1.15, 1.15, 1.15) })
.to(0.1, { scale: v3(0.95, 0.95, 0.95) })
.to(0.03, { scale: v3(1, 1, 1) })
.call(() => {
this.playIdleSpine(true);
})
.start();
}, 0)
}
getHeight(): number {
return this.lheight;
}
getIsFastMode(): boolean {
return this.isFastMode;
}
getState(): ICON_STATE {
return this.state;
}
async onClickIconNode() {
if (GameDataManager.instance.canClickIconMsg && this.index != 10) {
AudioManager.instance.playSFX('Click_Icon');
let iconMsg = await NodePoolManager.instance.getNodeFromPoolDynamic('IconMsg', 'Prefab/Others/IconMsg', 'Game');
let gameNode = find('Canvas/main/game');
if (!gameNode) return;
gameNode.addChild(iconMsg);
let isLeft = this.rollerId < 3;
iconMsg.getComponent(IconMsg).showIconMsg(this, isLeft);
}
}
}