import { _decorator, Component, Node, find, tween, v3, Button, Sprite, Animation, Event, EventHandler, Label, Vec3 } from 'cc'; import { Http } from '../core/net/Http'; import { Sound } from '../core/sound/Sound'; import { OpenWindow } from '../core/ui/window/OpenWindow'; import { WindowManager } from '../core/ui/window/WindowManager'; import { WindowOpenMode } from '../core/ui/window/WindowOpenMode'; import { MultipleType } from '../Data/ADData'; import { ConfigData } from '../Data/ConfigData'; import { g } from '../Data/g'; import { LoginWaitWin } from '../Windows/LoginWaitWin'; const { ccclass, property } = _decorator; @ccclass('DrawAPrize') export class DrawAPrize extends Component { @property({ tooltip: "开奖选中动画图片", type: Node }) public prize: Node; @property({ tooltip: "开奖边框等效", type: Node }) public prizeBg: Node; @property({ tooltip: "http服务", type: Http }) public http: Http; @property({ tooltip: "领完神石回调", type: EventHandler }) public getDiamondBack: EventHandler; @property({ tooltip: "领取完奖品回调", type: EventHandler }) public getPrizeBack: EventHandler; @property({ tooltip: "转盘窗口", type: Node }) public turntableWin: Node; @property({ tooltip: "申请抽奖成功回调", type: EventHandler }) public drawBack: EventHandler; @property({ tooltip: "今日剩余次数文本", type: Node }) public drawTimes: Node; @property({ tooltip: "关闭按钮", type: Node }) public closeBtn: Node; @property({ tooltip: "规则按钮", type: Node }) public ruleBtn: Node; @property({ tooltip: "转盘抽奖音效控制器", type: Sound }) public turntableSound: Sound; @property({ tooltip: "抽奖按键", type: Node }) public drawaBtn: Node; private button: Button; private tempAnimation: Animation; public ligthAnimation: Animation; start() { g.gameData.isPlayVideo = false; g.gameData.playAddMoneySound = false; this.button = this.drawaBtn.getComponent(Button); this.tempAnimation = this.prize.getComponent(Animation); this.ligthAnimation = this.prizeBg.getComponent(Animation); this.drawTimes.getComponent(Label).string = "今日剩余次数:" + g.gameData.drawTimes + "次 "; if (g.gameData.drawTimes <= 0) { this.button.interactable = false;//禁用鼠标事件 this.drawaBtn.getComponent(Sprite).grayscale = true;//按键置灰 } } public isSend = false; //请求服务器抽奖 public async drawPrize() { this.initUIButton(true); if (g.gameData.drawTimes <= 0) { WindowManager.showTips("视频次数已经用完"); return; } if (g.gameData.isPlayVideo) { return; } g.gameData.isPlayVideo = true; //观看视频抽奖,视频开始观看 let data = await this.http.send("/api/ad/WatchVideoAD"); switch (data.code) { case 0: //播放视频 let adData = await g.showRewardVideo(); if (adData) { this.videoBack(); } else { //视频观看失败 WindowManager.showTips("视频观看时间不足"); } break; case 108: WindowManager.showTips("今日视频次数已用完,请明日再继续"); g.gameData.isPlayVideo = false; break; default: // WindowManager.showTips(g.CodeMsg[data.code]); WindowManager.showTips("视频准备中,请稍后再试"); g.gameData.isPlayVideo = false; break; } this.initUIButton(false); } //视频结束回调 public async videoBack() { this.initUIButton(true); //#region 打开加载等待界面 let _window = await WindowManager.open("Prefabs/Windows/加载等待窗口", WindowOpenMode.NotCloseAndCover); //#endregion let data = await this.http.send("/api/wealth/AddDiamondForVideo", { multipleType: MultipleType.Turntable, adData: g.adData }); _window.getComponent(LoginWaitWin).close();//关闭加载等待界面 if (data.code == 0) { if (data.data.addDiamond > 0) { this.turntableWin.active = false; this.getComponent(OpenWindow).prefabPath = "Prefabs/Windows/神石领取界面"; let _window = this.getComponent(OpenWindow); _window.open([data.data.addDiamond, -1, null, this.getDiamondBack]); } else { this.getDiamondBack.emit([]); } } else { this.initUIButton(false); WindowManager.showTips(g.CodeMsg[data.code]); } g.gameData.isPlayVideo = false; } //领取神石后回调 public getDiamondBackFun() { this.turntableWin.active = true; this.playEffect(); } public prizeData: any;//获奖ID //请求抽奖 public async playEffect() { //#region 打开加载等待界面 let _window = await WindowManager.open("Prefabs/Windows/加载等待窗口", WindowOpenMode.NotCloseAndCover); //#endregion let data = await this.http.send("/api/turntalbe/Draw"); _window.getComponent(LoginWaitWin).close();//关闭加载等待界面 if (data.code == 0) {//播放抽奖动画 // this.turntableSound.play();//音效 this.prizeData = data.data; // this.prizeData.id = 6;//测试 this.drawBack.emit([data.data.id]); this.tempAnimation.getState('openPrize').speed = 0.3; this.ligthAnimation.play('openPrizeBoxLight'); this.tempAnimation.play('openPrize'); } else { this.initUIButton(false); WindowManager.showTips(data.code); } } /** * 开奖动画结束回调 */ public animationStop() { // this.turntableSound.stop();//停止音效 let data = ConfigData.configMap.get("turntable").prizeList; for (let i = 0; i < data.length; i++) { if (data[i].id == this.prizeData.id) { switch (data[i].id) { case 1: this.openGoldWin(); break; case 2: this.openGoldWin(); break; case 3: this.openGoldWin(); break; case 4: this.openGoldWin(); break; case 5: this.openGoldWin(); break; case 6: this.openTenfoldWin(); break; case 7: this.openDiamondWin(); break; case 8: this.openDiamondWin(); break; } break; } } this.ligthAnimation.stop(); g.gameData.drawTimes--;//更新轮盘剩余次数 g.gameData.drawTimes = g.gameData.drawTimes <= 0 ? 0 : g.gameData.drawTimes; this.drawTimes.getComponent(Label).string = "今日剩余次数:" + g.gameData.drawTimes + "次 ";//更新轮盘剩余次数 this.turntableWin.active = false; if (g.gameData.drawTimes > 0) { this.drawaBtn.getComponent(Sprite).grayscale = false; this.button.interactable = true; } this.closeBtn.active = true; this.ruleBtn.active = true; this.prize.setPosition(new Vec3(-180, 180)); } //打开奖品金币领取界面 public openGoldWin() { let _openWindow = this.getComponent(OpenWindow); _openWindow.prefabPath = "Prefabs/Windows/金币领取窗口"; _openWindow.open([this.prizeData.preze, 3, this.getPrizeBack]); } public getPrizeBackFun() { this.turntableWin.active = true; } //打开奖品神石领取界面 public openDiamondWin() { let _openWindow = this.getComponent(OpenWindow); _openWindow.prefabPath = "Prefabs/Windows/神石领取界面"; _openWindow.open([this.prizeData.preze, -1, null, this.getPrizeBack]); } //打开下次奖励十倍领取界面 public openTenfoldWin() { let _openWindow = this.getComponent(OpenWindow); _openWindow.prefabPath = "Prefabs/Windows/翻倍奖励窗口"; _openWindow.open([this.prizeData.preze, this.getPrizeBack]); } /** * 重置按钮状态 * @param isDraw 是否在抽奖 */ public initUIButton(isDraw: boolean) { this.drawaBtn.getComponent(Sprite).grayscale = isDraw;//按键置灰 this.button.interactable = !isDraw; this.closeBtn.active = !isDraw; this.ruleBtn.active = !isDraw; } onDestroy() { g.gameData.playAddMoneySound = false; g.gameData.isPlayVideo = false; } }