| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- import { _decorator, Component, Node, LabelAtlas, Label, EventHandler, find, Sprite } from 'cc';
- import { Http } from '../core/net/Http';
- import { OpenWindow } from '../core/ui/window/OpenWindow';
- import { Window } from '../core/ui/window/Window';
- import { WindowManager } from '../core/ui/window/WindowManager';
- import { WindowOpenMode } from '../core/ui/window/WindowOpenMode';
- import { g } from '../Data/g';
- import { UIEffect } from '../Main/UIEffect';
- import { LoginWaitWin } from './LoginWaitWin';
- import { NoviceWindow } from './NoviceWindow';
- const { ccclass, property } = _decorator;
- @ccclass('GetDiamondRedBox')
- export class GetDiamondRedBox extends Component {
- @property({ tooltip: "神石文本", type: Node }) public diamondTxt: Node;
- @property({ tooltip: "现金文本", type: Node }) public moneyTxt: Node;
- @property({ tooltip: "双倍领取图标", type: Node }) public doubleIcon: Node;
- @property({ tooltip: "领取图标", type: Node }) public getIcon: Node;
- @property({ tooltip: "http服务", type: Http }) public http: Http;
- @property({ tooltip: "关闭按钮", type: Node }) public closeBtn: Node;
- @property({ tooltip: "单倍直接领取", type: Node }) public getBtn: Node;
- @property({ tooltip: "玩家昵称", type: Label }) public nameTxt: Label;
- public closeBackFun: EventHandler;
- public addDiamond: number = 0;//领取神石数目
- public get2LvRedPath = "/wealth/ReceiveLvRedPacketForTwo";//二级红包URL
- public lvRedType = -1;//红包类型,-1:非等级红包;0:2级红包;1:2级以上红包需要视频领取
- start() {
- this.nameTxt.string = g.userData.nickName;
- g.gameData.isPlayVideo = false;
- }
- /**
- * 设置界面信息
- * @param data 0:获得神石数值
- * 1:界面关闭回调方法
- * 2:有数据为等級红包(-1:非等级红包,0:2级红包,1:2级以上红包需要视频领取)
- */
- public setData(data: any[]) {
- this.addDiamond = data[0];
- this.diamondTxt.getComponent(Label).string = this.addDiamond + "神石";
- // this.diamondTxt.getComponent(Label).string = "(=" + this.addDiamond + "神石)";
- this.moneyTxt.getComponent(Label).string = this.addDiamond / 10000 + "元";
- if (data[1]) {
- this.closeBackFun = data[1];
- }
- switch (data[2]) {
- case 0:
- this.doubleIcon.active = true;
- this.getIcon.active = false;
- this.closeBtn.active = false;
- this.lvRedType = data[2];
- this.getBtn.active = true;
- break;
- case 1:
- this.doubleIcon.active = true;
- this.getIcon.active = false;
- this.closeBtn.active = true;
- this.lvRedType = data[2];
- this.getBtn.active = true;
- break;
- }
- }
- public isSend = false;
- //领取按键
- public async getDiamond() {
- if (g.gameData.isPlayVideo) {
- return;
- }
- g.gameData.isPlayVideo = true;
- switch (this.lvRedType) {//红包类型,-1:非等级红包,0:2级红包,1:2级以上红包需要视频领取
- case 0:
- 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;
- }
- break;
- case 1:
- let data0 = await this.http.send("/api/ad/WatchVideoAD");
- switch (data0.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;
- }
- break;
- default:
- this.close();
- break;
- }
- }
- //视频结束回调,等级红包
- public async videoBack() {
- //#region 打开加载等待界面
- let _window = await WindowManager.open("Prefabs/Windows/加载等待窗口", WindowOpenMode.NotCloseAndCover);
- //#endregion
- let data = await this.http.send("/api/lvRedPacket/ReceiveLvRedPacket", { type: 2, adData: g.adData });
- _window.getComponent(LoginWaitWin).close();//关闭加载等待界面
- if (data.code == 0) {
- this.addDiamond = data.data.addDiamond;
- g.gameData.lvRedPacket = data.data.receiveLv;
- this.close();
- } else {
- WindowManager.showTips(g.CodeMsg[data.code]);
- this.closeBtn.active = true;
- g.gameData.isPlayVideo = false;
- }
- }
- //少量领取
- public async toGetDiamond() {
- if (g.gameData.isPlayVideo) {
- return;
- }
- g.gameData.isPlayVideo = true;
- //#region 打开加载等待界面
- let _window = await WindowManager.open("Prefabs/Windows/加载等待窗口", WindowOpenMode.NotCloseAndCover);
- //#endregion
- let data = await this.http.send("/api/lvRedPacket/ReceiveLvRedPacket", { type: 1, adData: g.adData });
- _window.getComponent(LoginWaitWin).close();//关闭加载等待界面
- switch (data.code) {
- case 0:
- this.addDiamond = data.data.addDiamond;
- g.gameData.lvRedPacket = data.data.receiveLv;
- this.close();
- break;
- default:
- WindowManager.showTips(g.CodeMsg[data.code]);
- this.closeBtn.active = true;
- g.gameData.isPlayVideo = false;
- break;
- }
- }
- public async close() {
- if (this.addDiamond > 0) {
- // this.addDiamond = 0;//测试
- let times = this.addDiamond > 10 ? 10 : this.addDiamond;
- let _window = await WindowManager.open("Prefabs/Windows/货币飞行控制器", WindowOpenMode.NotCloseAndAdd);
- _window.getComponent(UIEffect).changeDiamond(this.addDiamond, times);
- _window.getComponent(UIEffect).showEffect(0, times);
- }
- this.closeBackFun && this.closeBackFun.emit([]);
- this.toClose();
- }
- //直接关闭窗口
- public toClose() {
- this.getComponent(Window).close();
- }
- onDestroy() {
- g.gameData.isPlayVideo = false;
- }
- }
|