import { _decorator, Component, Node, SpriteFrame, Sprite, Vec3, v3, UITransform, Label, find, macro } from 'cc'; import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils'; import { WindowManager } from '../core/ui/window/WindowManager'; import { Utils } from '../core/utils/Utils'; import { g } from '../Data/g'; import { platform } from '../Data/platform'; import { FsUtils } from '../FsUtils/FsUtils'; import { NoviceWindow } from '../Windows/NoviceWindow'; import { Trajectory } from './Trajectory'; const { ccclass, property } = _decorator; @ccclass('UIEffect') export class UIEffect extends Component { // @property({ tooltip: "飞行资源合集", type: [SpriteFrame] }) public partics: Array = []; // @property({ tooltip: "飞行目标点合集", type: [Node] }) public endPoints: Array = []; // @property({ tooltip: "金币文本", type: Node }) public moneyLabel: Node; // @property({ tooltip: "神石文本", type: Node }) public diamondLabel: Node; start() { } public backNum = 0;//缓动动画回调次数 public _window: Node;//新窗口node public async iniUItData() { let _diamondIcon = find("Canvas/UI/MainUI/顶部/用户数据组/神石信息/图标底/神石图标"); let _goldIcon = find("Canvas/UI/MainUI/顶部/用户数据组/金币信息/图标底/金币图标"); let _diamondLabel = find("Canvas/UI/MainUI/顶部/用户数据组/神石信息/文本/神石文本"); let _goldLabel = find("Canvas/UI/MainUI/顶部/用户数据组/金币信息/文本/金币文本"); let imgDiamond = await ResourcesUtils.load("Images/Money/goldIcon/spriteFrame", SpriteFrame, this.node); let imgGold = await ResourcesUtils.load("Images/Money/moneyIcon/spriteFrame", SpriteFrame, this.node); this.partics.push(imgDiamond); this.partics.push(imgGold); this.endPoints.push(_diamondIcon); this.endPoints.push(_goldIcon); this.moneyLabel = _goldLabel; this.diamondLabel = _diamondLabel; } /** * @param type (0:神石,1:金币)飞行资源类型 * @param nodeNum 飞行数目 * @param startPoint 起始点坐标 * @param window 新窗口node */ public async showEffect(type: number, nodeNum: number, startPoint: Vec3 = v3(0, 95, 0), window?: Node) { if (nodeNum <= 0) { let self = this; this.scheduleOnce(() => { WindowManager.close(self.node); }) g.gameData.isPlayMoneyAnim = false; switch (type) { case 0: g.gameData.isPlayAddDiamondAnim = false; break; case 1: g.gameData.isPlayAddMoneyAnim = false; break; } return; } await this.iniUItData(); this.tweenType = type; this.backNum = nodeNum; this._window = window; // this.node.active = true; for (let i = 0; i < nodeNum; i++) { let node = new Node(); //附加图片显示组件 node.addComponent(Sprite); node.getComponent(Sprite)!.spriteFrame = this.partics[type]; node.addComponent(Trajectory); let trajectory = node.getComponent(Trajectory); trajectory.startPoint = startPoint; trajectory.ctrl1Point = new Vec3(Utils.random_both(300, -300), Utils.random_both(0, -500)); trajectory.ctrl2Point = new Vec3(Utils.random_both(100, -100), Utils.random_both(300, -300)); trajectory.endPoint = this.node.getComponent(UITransform).convertToNodeSpaceAR(this.endPoints[type].getWorldPosition()); trajectory.backNode = this.node; node.position = startPoint; this.node.addChild(node); } } public backFun() { this.backNum--; switch (this.tweenType) { case 0: this.startDiamond += this.change_diamond; // this.diamondLabel.getComponent(Label).string = this.startDiamond + g.userData.diamond + ""; this.diamondLabel.getComponent(Label).string = FsUtils.goldFormat(this.startDiamond + g.userData.diamond); break; case 1: this.startMoney += this.change_money; this.moneyLabel.getComponent(Label).string = FsUtils.moneyFormat(this.startMoney + g.userData.money); break; } if (this.backNum <= 0) { if (NoviceWindow.isNovicing) { NoviceWindow.isLastStep = true; } if (this._window) { this._window.active = true; } this.backNum = 0; // switch (this.tweenType) { // case 0: // g.userData.diamond += this.addAllDiamond; // g.gameData.isPlayAddDiamondAnim = false; // break; // case 1: // g.userData.money += this.addAllMoney; // g.gameData.isPlayAddMoneyAnim = false; // break; // } // g.gameData.isPlayMoneyAnim = false; WindowManager.close(this.node); } } public startMoney = 0;//初始金币 public change_money = 0;//每次金币变化值 public addAllMoney = 0;//金币变化总值 public tweenType = 0;//变化货币类型 public changeMoney(addMoney: number, times: number) { // g.userData.money = 19710000000;//测试 // addMoney = 757990000;//测试 this.startMoney = 0; this.addAllMoney = addMoney; this.change_money = Math.floor(addMoney / times); } public startDiamond = 0;//初始神石 public change_diamond = 0;//每次神石变化值 public addAllDiamond = 0;//神石变化总值 public changeDiamond(addDiamond: number, times: number) { this.startDiamond = 0; this.addAllDiamond = addDiamond; this.change_diamond = Math.floor(addDiamond / times); } onDestroy() { if (NoviceWindow.isNovicing) { NoviceWindow.isLastStep = true; } switch (this.tweenType) { case 0: g.userData.diamond += this.addAllDiamond; platform.volcanicReport('addDiamond'); g.gameData.isPlayAddDiamondAnim = false; break; case 1: g.userData.money += this.addAllMoney; g.gameData.isPlayAddMoneyAnim = false; break; } g.gameData.isPlayMoneyAnim = false; } }