123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- import { MouseConst } from "./MouseConst";
- const { ccclass, property, menu } = cc._decorator;
- const delayFinishTime: number = 0.2;
- const startAudioTime = 17;
- const endAudioTime = 8;
- @ccclass
- @menu("Game/Mouse/MouseWinView")
- export default class MouseWinView extends cc.Component {
- @property(cc.Node)
- winNode: cc.Node = null;
- @property(sp.Skeleton)
- coinSke: sp.Skeleton = null;
- @property(sp.Skeleton)
- bigWinSke: sp.Skeleton = null;
- @property(cc.Sprite)
- winTitle: cc.Sprite;
- @property(cc.Label)
- winLabel: cc.Label = null;
- @property([cc.SpriteFrame])
- winTitleImgs: cc.SpriteFrame[] = [];
- @property({ type: cc.Node, tooltip: '立即完成滚动', displayName: '完成得分滚动' })
- finishNode: cc.Node = null;
- @property({ type: cc.Node, displayName: '关闭winView' })
- touchNode: cc.Node = null;
- private _callback: Function = null;
- private _winScore: number = 0;
- private _bigWinStartAudioId: number = 0;
- private _bigWinEndAudioId: number = 0;
- private _isBigWin: boolean = false;//是否大奖
- private _winType: number = -1;
- private bigWinMultiple: number[];
- start() {
- this.resetView();
- this.finishNode.setContentSize(cc.winSize);
- this.touchNode.setContentSize(cc.winSize); //这个在结算的下面
- }
- winFinish() {
- if (this._callback) {
- this._callback?.();
- this._callback = null;
- this.finishNode.active = false;
- this._bigWinStartAudioId && AudioPlayer.stopEffect(this._bigWinStartAudioId);
- if (this._isBigWin) {
- AudioPlayer.playEffect(MouseConst.Sound.bigWinEnd, false, 1, false, (audioID: number) => {
- this._bigWinEndAudioId = audioID;
- });
- this.scheduleOnce(() => {
- this.resetView();
- }, endAudioTime);
- }
- }
- }
- showWinView(betScore: number, winScore: number, callback: (multiple: number) => void) {
- this.bigWinMultiple = MouseConst.getBigWinMultiple(true);
- cc.warn("========== BigWinMultiple:" + this.bigWinMultiple);
-
- let multiple = winScore / betScore;
- this._isBigWin = multiple >= this.bigWinMultiple[0];
- // 小奖不显示
- if (!this._isBigWin) {
- return callback?.(multiple);
- }
- cc.warn("==================> showWinView, isBigWin:" + this._isBigWin);
- this._winScore = winScore;
- this._callback = callback;
- // let numScrollTime: number;
- if (multiple >= this.bigWinMultiple[2]) { // super
- // numScrollTime = MouseConst.BigWinScrollTime[2];
- this._winType = 2;
- } else if (multiple >= this.bigWinMultiple[1]) { // mega
- // numScrollTime = MouseConst.BigWinScrollTime[1];
- this._winType = 1;
- } else if (multiple >= this.bigWinMultiple[0]) { // big
- // numScrollTime = MouseConst.BigWinScrollTime[0];
- this._winType = 0;
- } else {
- // numScrollTime = multiple / 2;
- }
- // 大奖音效
- this._bigWinStartAudioId && AudioPlayer.stopEffect(this._bigWinStartAudioId);
- AudioPlayer.playEffect(MouseConst.Sound.bigWinStart, false, 1, false, (audioID: number) => {
- this._bigWinStartAudioId = audioID;
- });
- // 滚动时间
- // let audioTime = cc.audioEngine.getDuration(this._bigWinStartAudioId);
- let audioTime = startAudioTime;
- let musicTime = multiple / 90 * audioTime;
- let numScrollTime = musicTime > audioTime ? audioTime : musicTime;
- this.winNode.active = true;
- this.playBigWinAnim(0);
- this.scrollCoin(numScrollTime, betScore, winScore);
- this.initEventGray(true);
- this.initEventUnderButton(true);
- }
- scrollCoin(time: number, betScore: number, winScore: number) {
- let hasWinPlayed = [false, false]; // mega / super
- cc.tween({ a: 0 }).tag(101).to(time, { a: winScore }, { //数字滚动
- progress: (start: number, end: number, current: any, ratio: number) => {
- let now = (start + (end - start) * ratio);
- this.winLabel.string = MouseConst.toFixedString(now);
- if (this._isBigWin) {
- let nowMultiple = now / betScore;
- if (nowMultiple >= this.bigWinMultiple[1] && !hasWinPlayed[0]) {
- hasWinPlayed[0] = true;
- this.playBigWinAnim(1);
- } else if (nowMultiple >= this.bigWinMultiple[2] && !hasWinPlayed[1]) {
- hasWinPlayed[1] = true;
- this.playBigWinAnim(2);
- }
- }
- },
- }).delay(delayFinishTime).call(() => this.winFinish()).start();
- }
- /**
- * 播放大奖
- * 0: big, 1: mega, 2: super
- */
- playBigWinAnim(winType: number, manual?: boolean) {
- if (winType < 0)
- return;
- let anim1: string;
- let anim2: string;
- let titleImg: cc.SpriteFrame;
- switch (winType) {
- case 2: // super
- anim1 = "tansuper";
- anim2 = "xuanzhuansuper";
- titleImg = this.winTitleImgs[2];
- // super金币
- this.coinSke.node.active = true;
- this.coinSke.setAnimation(0, "jinbichuxian", false);
- this.coinSke.setCompleteListener(() => {
- this.coinSke.setCompleteListener(null);
- this.coinSke.setAnimation(0, "jinbixunhuan", true);
- });
- break;
- case 1: // mega
- anim1 = "tanmaga";
- anim2 = "xuanzhuanmaga";
- titleImg = this.winTitleImgs[1];
- break;
- default: // big
- anim1 = "tanbig";
- anim2 = "xuanzhuanbig";
- titleImg = this.winTitleImgs[0];
- break;
- }
- // 大奖动效
- this.bigWinSke.node.active = true;
- this.bigWinSke.setAnimation(0, anim1, false);
- this.bigWinSke.setCompleteListener(() => {
- this.bigWinSke.setCompleteListener(null);
- this.bigWinSke.setAnimation(0, anim2, true);
- });
- if (winType == 0) { // big
- this.winTitle.spriteFrame = titleImg;
- cc.tween(this.winTitle.node)
- .set({ scale: 0 })
- .to(0.3, { scale: 1.2 })
- .to(0.1, { scale: 1 })
- .start();
- } else {
- cc.tween(this.winTitle.node)
- .to(0.1, { scale: 0 })
- .call(() => {
- this.winTitle.spriteFrame = titleImg;
- })
- .to(0.2, { scale: 1.2 })
- .to(0.1, { scale: 1 })
- .start();
- }
- cc.tween(this.winLabel.node.parent)
- .set({ scale: 0.9 })
- .to(0.2, { scale: 1.05 })
- .to(0.1, { scale: 0.9 })
- .start();
- }
- //强行结算完毕
- immediatelyResult() {
- this.initEventGray(false);
- cc.Tween.stopAllByTag(101);
- cc.tween({}).tag(102).delay(delayFinishTime).call(() => {
- this.winFinish();
- }).start();
- this.winLabel.string = MouseConst.toFixedString(this._winScore);
- this.playBigWinAnim(this._winType, true);
- }
- //结束
- clickBigwinHide() {
- this.initEventUnderButton(false);
- this.resetView();
- }
- initEventUnderButton(value: boolean) {
- if (value) {
- this.touchNode.on(cc.Node.EventType.TOUCH_START, this.clickBigwinHide.bind(this), this);
- } else {
- this.touchNode.off(cc.Node.EventType.TOUCH_START);
- }
- this.touchNode.active = value;
- }
- initEventGray(value: boolean) {
- if (value) {
- this.finishNode.on(cc.Node.EventType.TOUCH_START, this.immediatelyResult.bind(this), this);
- } else {
- this.finishNode.off(cc.Node.EventType.TOUCH_START);
- }
- this.finishNode.active = value;
- }
- resetView() {
- cc.Tween.stopAllByTag(101);
- cc.Tween.stopAllByTag(102);
- this.unscheduleAllCallbacks();
- this._winScore = 0;
- this._winType = -1;
- this._callback = null;
- this._isBigWin = false;
- this._bigWinStartAudioId = 0;
- this._bigWinEndAudioId && AudioPlayer.stopEffect(this._bigWinEndAudioId);
- this._bigWinEndAudioId = 0;
- this.coinSke.node.active = false;
- this.winNode.active = false;
- this.finishNode.active = false;
- this.touchNode.active = false;
- }
- protected onDestroy(): void {
- cc.Tween.stopAllByTag(101);
- cc.Tween.stopAllByTag(102);
- }
- }
|