import { _decorator, Component, instantiate, Label, Node, sp, Sprite, Tween, tween, UIOpacity, UITransform, v3, Vec3 } from 'cc'; import { I18nManager } from '../../Main/Scripts/managers/I18nManager'; import { getLanguage, gold2cash } from '../../Main/Scripts/main/comm'; import { UIManager } from '../../Main/Scripts/managers/UIManager'; import { AudioManager } from '../../Main/Scripts/managers/AudioManager'; const { ccclass, property } = _decorator; @ccclass('SlotMsg') export class SlotMsg extends Component { // 展示文字信息 @property(sp.Skeleton) smallMsgSpine: sp.Skeleton = null; // 展示普通赢分信息 @property(sp.Skeleton) middleMsgSpine: sp.Skeleton = null; // 展示总赢分信息 @property(sp.Skeleton) largeMsgSpine: sp.Skeleton = null; @property(Sprite) i18nSpriteMsg: Sprite = null; @property(Node) grayMsgNode: Node = null; protected onLoad(): void { this.grayMsgNode.active = false; } startPos: Vec3 = new Vec3(-259.5, 0, 0); maxWidth: number = 540; showLabelMsgForTween() { Tween.stopAllByTarget(this.i18nSpriteMsg.node); this.smallMsgSpine.node.active = true; this.smallMsgSpine.setAnimation(0, '2', false); this.smallMsgSpine.setCompleteListener(() => { this.smallMsgSpine.setAnimation(0, '1', true); this.smallMsgSpine.setCompleteListener(null); }); this.middleMsgSpine.node.active = false; this.largeMsgSpine.node.active = false; let add = 0; let isFirst = true; let startPos = new Vec3(0, 0, 0); let endPos = new Vec3(0, 0, 0); let speed = 1080 / 8; let delayTime = 0; let moveTime = 0; // 通过数字获取name let spriteName = ['Normal1', 'Normal6', 'Normal8', 'Normal9']; let setSpriteFrame = () => { startPos.x = this.startPos.x; let spriteFrame = I18nManager.instance.getSpriteFrame(spriteName[add]); this.i18nSpriteMsg.spriteFrame = spriteFrame; let distane = spriteFrame.rect.width + 109; let X = -430 - distane; endPos.x = X; delayTime = 1; moveTime = distane / speed; if (spriteFrame.rect.width < this.maxWidth) { startPos.x = -spriteFrame.rect.width / 2; endPos.x = -spriteFrame.rect.width / 2; delayTime = 2; moveTime = 1; } } setSpriteFrame(); let tweenFun = () => { tween(this.i18nSpriteMsg.node) .set({ position: startPos }) .delay(delayTime) .to(moveTime, { position: endPos }) .call(() => { isFirst = false; add = add + 1 >= spriteName.length ? 0 : add + 1; setSpriteFrame(); tweenFun(); }) .start(); } tweenFun(); } showTotalWinAnimaiton(startScore: number, endScore: number, cb) { this.smallMsgSpine.node.active = false; this.middleMsgSpine.node.active = false; this.largeMsgSpine.node.active = true; this.largeMsgSpine.setAnimation(0, '2', false); this.largeMsgSpine.setCompleteListener(() => { this.largeMsgSpine.setAnimation(0, '1', true); this.largeMsgSpine.setCompleteListener(null); }); let msg = this.largeMsgSpine.node.getChildByName('msg'); let winCount = msg.getChildByName('winCount'); winCount.getComponent(Label).string = gold2cash(startScore); AudioManager.instance.playSFX('Gold_Up'); UIManager.instance.tweenScorelinear(startScore, endScore, 2) .onUpdate((v: number) => { winCount.getComponent(Label).string = gold2cash(v); }) .onComplete(() => { winCount.getComponent(Label).string = gold2cash(endScore); AudioManager.instance.stopSFX('Gold_Up'); tween(winCount) .to(0.2, { scale: v3(1.1, 1.1, 1.1) }) .to(0.2, { scale: v3(1, 1, 1) }) .start() this.scheduleOnce(() => { if (cb) cb(); }, 1) }) .start(); } showWinMsg(endScore: number) { if (endScore === 0) return; this.smallMsgSpine.node.active = false; this.middleMsgSpine.node.active = true; this.largeMsgSpine.node.active = false; this.middleMsgSpine.setAnimation(0, '2', false); this.middleMsgSpine.setCompleteListener(() => { this.middleMsgSpine.setAnimation(0, '1', true); this.middleMsgSpine.setCompleteListener(null); }); let msg = this.middleMsgSpine.node.getChildByName('msg'); let winCount = msg.getChildByName('winCount'); winCount.getComponent(Label).string = gold2cash(endScore); } showTotalWinMsg(endScore: number) { if (endScore === 0) return; this.smallMsgSpine.node.active = false; this.middleMsgSpine.node.active = false; this.largeMsgSpine.node.active = true; this.largeMsgSpine.setAnimation(0, '2', false); this.largeMsgSpine.setCompleteListener(() => { this.largeMsgSpine.setAnimation(0, '1', true); this.largeMsgSpine.setCompleteListener(null); }); let msg = this.largeMsgSpine.node.getChildByName('msg'); let winCount = msg.getChildByName('winCount'); winCount.getComponent(Label).string = gold2cash(endScore); AudioManager.instance.playSFX('Slot_Msg_Total_Win'); } hideWinSpine() { this.smallMsgSpine.node.active = true; this.middleMsgSpine.node.active = false; this.largeMsgSpine.node.active = false; } showTipSmall(tips: string, Type: string = "") { Tween.stopAllByTarget(this.grayMsgNode); let bgWidth, bgHeigt = 0; if (Type != "") { this.grayMsgNode.getChildByName('layout').getChildByName('fast').active = true; bgWidth = 142; this.grayMsgNode.getChildByPath('layout/fast/toast_Turboon').active = Type == "onFast"; this.grayMsgNode.getChildByPath('layout/fast/toast_Turbooff').active = Type == "offFast"; } else { this.grayMsgNode.getChildByName('layout').getChildByName('fast').active = false; bgWidth = 100; } let lab = this.grayMsgNode.getChildByPath('layout/lab').getComponent(Label); lab.string = tips; lab.updateRenderData(true); let tipWidth = this.grayMsgNode.getChildByPath('layout/lab').getComponent(UITransform).width; let frame = this.grayMsgNode.getChildByName('sp'); frame.getComponent(UITransform).setContentSize(tipWidth + bgWidth, 132); this.grayMsgNode.setScale(0, 0, 0); this.grayMsgNode.active = true; tween(this.grayMsgNode) .set({ scale: v3(0, 0, 0) }) .to(0.1, { scale: v3(1, 1, 1) }) .delay(1) .call(() => { this.grayMsgNode.active = false; }) .start(); } }