import { _decorator, Component, Node, Prefab, instantiate, UITransform, Label, find, v3, EventHandler } from 'cc'; import { Http } from '../core/net/Http'; import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils'; import { Window } from '../core/ui/window/Window'; import { g } from '../Data/g'; import { RotatingLightAnim } from '../SpecialEffects/RotatingLightAnim'; import { StarAnim } from '../SpecialEffects/StarAnim'; import { FsUtils } from "../FsUtils/FsUtils"; import { UIEffect } from '../Main/UIEffect'; import { WindowManager } from '../core/ui/window/WindowManager'; import { WindowOpenMode } from '../core/ui/window/WindowOpenMode'; import { LoginWaitWin } from './LoginWaitWin'; const { ccclass, property } = _decorator; @ccclass('GetGoldWin') export class GetGoldWin extends Component { @property({ tooltip: "旋转光效节点", type: Node }) public turnLightNode: Node; @property({ tooltip: "旋转光效预制体路径" }) public lightEfficiency = ""; @property({ tooltip: "星星特效节点", type: Node }) public starNode: Node; @property({ tooltip: "星星特效预制体路径" }) public starEfficiency = ""; @property({ tooltip: "领取金币按键", type: Node }) public getMoneyBtn: Node; @property({ tooltip: "金币金额", type: Node }) public moneyTxt: Node; @property({ tooltip: "http服务", type: Http }) public http: Http; @property({ tooltip: "内容框", type: Node }) public Group: Node; public titleArray = ["获得金币", "离线收益", "恭喜获得", "获得金币"]; public httpString = ["/api/wealth/OpenFlyBox", "/api/wealth/GetOffMoney"]; public type = 0; public getGoldBack: EventHandler; public toGetMoney: number = 0;//领取金币金额 start() { g.gameData.isPlayAddMoneyAnim = true; g.gameData.isPlayVideo = false; } /** * 设置界面信息 * @param data 0:金币金额 * 1:类型(0:飞行宝箱,1:离线,2:金币不足,3:轮盘抽奖金币) * 2:窗口关闭回调方法 */ public setData(data: any[]) { this.type = data[1]; this.moneyTxt.getComponent(Label).string = FsUtils.moneyFormat(data[0]); this.toGetMoney = data[0]; if (data[2]) { this.getGoldBack = data[2]; } } public async addStar() { for (let i = 0; i < 20; i++) { let prefabsData = await ResourcesUtils.load(this.starEfficiency, null, this.node); var starNode = instantiate(prefabsData); starNode.parent = this.starNode; let starAnim = starNode.getComponent(StarAnim); let wrapMode = Math.random() < 0.5 ? 38 : 2; let startTime = Math.random() * 3; let _size = this.starNode.getComponent(UITransform).contentSize; let tempWidth = Math.random() * _size.width; let temp_x = tempWidth > _size.width / 2 ? -(tempWidth - (_size.width / 2)) : tempWidth; let tempHeight = Math.random() * _size.height; let temp_y = tempHeight > _size.height / 2 ? -(tempHeight - (_size.height / 2)) : tempHeight; starAnim.setData(wrapMode, startTime, temp_x, temp_y, Math.random() * 1.3, "star1"); } } public isSend = false; public async close() { if (g.gameData.isPlayVideo) { return; } g.gameData.isPlayVideo = true; if (this.type != 3 && this.type != 2) { //#region 打开加载等待界面 let _window = await WindowManager.open("Prefabs/Windows/加载等待窗口", WindowOpenMode.NotCloseAndCover); //#endregion let data = await this.http.send(this.httpString[this.type]);//领取金币 _window.getComponent(LoginWaitWin).close();//关闭加载等待界面 switch (data.code) { case 0: if (this.type == 0) { g.gameData.flyBoxIntervalTime = 1000 * 60 * 4;//宝箱领取成功,出现时间间隔改为四分钟 g.gameData.flyBoxTimes = data.data.times;//宝箱领取成功,出现次数更新 } this.toGetMoney = data.data.addMoney; break; default: if (data.code) { WindowManager.showTips(g.CodeMsg[data.code]); } else { WindowManager.showTips("获取金币消息错误"); } this.getComponent(Window).close(); return; } } let times = this.toGetMoney > 0 ? this.toGetMoney : 1; times = times > 10 ? 10 : times; let _window = await WindowManager.open("Prefabs/Windows/货币飞行控制器", WindowOpenMode.NotCloseAndAdd); _window.getComponent(UIEffect).changeMoney(this.toGetMoney, times); _window.getComponent(UIEffect).showEffect(1, times); this.getGoldBack && this.getGoldBack.emit([]);//领取完奖励回调 this.getComponent(Window).close(); } update() { if (g.gameData.isPlayMoneyAnim == this.Group.active) { this.Group.active = !g.gameData.isPlayMoneyAnim; this.Group.active && this.addStar(); } } onDestroy() { g.gameData.isPlayVideo = false; } }