| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- import { _decorator, instantiate, Component, Node, TERRAIN_SOUTH_INDEX, Label, UITransform, Widget, Prefab, math } from 'cc';
- import { OpenWindow } from '../core/ui/window/OpenWindow';
- import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils';
- import { RotatingLightAnim } from '../SpecialEffects/RotatingLightAnim';
- import { StarAnim } from '../SpecialEffects/StarAnim';
- import { FsUtils } from "../FsUtils/FsUtils";
- import { Http } from '../core/net/Http';
- import { g } from '../Data/g';
- import { WindowManager } from '../core/ui/window/WindowManager';
- import { LoginWaitWin } from './LoginWaitWin';
- import { WindowOpenMode } from '../core/ui/window/WindowOpenMode';
- import { MultipleType } from '../Data/ADData';
- import { ADHelper } from '../ADHelper';
- const { ccclass, property } = _decorator;
- @ccclass('ToGetGoldWin')
- export class ToGetGoldWin extends Component {
- @property({ tooltip: "窗口标题", type: Node }) public title: Node;
- @property({ tooltip: "当天剩余的领取次数", type: Node }) public getGoldTimes: Node;
- @property({ tooltip: "不看视频,领取少量金币", type: Node }) public getLittleGold: Node;
- @property({ tooltip: "视频观看按键,显示文字内容", type: Node }) public videoBtnTxt: Node;
- @property({ tooltip: "视频观看按键", type: Node }) public videoBtn: Node;
- @property({ tooltip: "界面关闭按钮", type: Node }) public closeBtn: Node;
- @property({ tooltip: "界面展示窗口", type: Node }) public windowBox: Node;
- @property({ tooltip: "离线文字box", type: Node }) public offlineTile: Node;
- @property({ tooltip: "离线时间文本", type: Node }) public offlineTime: Node;
- @property({ tooltip: "奖励金币box", type: Node }) public offlineMoneyBox: Node;
- @property({ tooltip: "奖励金币txt", type: Node }) public offlineMoney: Node;
- @property({ tooltip: "金币不足专用按钮", type: Node }) public videoBtn0: Node;
- @property({ tooltip: "光效预制体根目录" }) public lightEfficiency = '';
- @property({ tooltip: "旋转光效父节点", type: Node }) public turnLight: Node;
- @property({ tooltip: "星星特效预制体根目录" }) public starEfficiency = '';
- @property({ tooltip: "星星特效节点", type: Node }) public starEffects: Node;
- @property({ tooltip: "http服务", type: Http }) public http: Http;
- @property({ tooltip: "广告控制器", type: Node }) public AD: Node;
- public uiData: any[];
- public multiple = 1;//视频金币倍数
- public windowType = [//0:飞行宝箱,1:离线收益,2:金币不足
- {
- isShowClosebtn: false,
- title: "获取金币奖励",
- bgWidth: 660,
- bgHeight: 660,
- isShowGetTimes: true,
- isShowGetLittleGold: true,
- videoBtnBottom: -18,
- isShowOfflineTime: false,
- http: MultipleType.FlyBox,
- isShowVideoBtn: false
- },
- {
- isShowClosebtn: true,
- title: "离线收益",
- bgWidth: 600,
- bgHeight: 750,
- isShowGetTimes: false,
- isShowGetLittleGold: false,
- videoBtnBottom: -80,
- isShowOfflineTime: true,
- http: MultipleType.OffLine,
- isShowVideoBtn: false
- },
- {
- isShowClosebtn: true,
- title: "金币不足",
- bgWidth: 600,
- bgHeight: 660,
- isShowGetTimes: false,
- isShowGetLittleGold: false,
- videoBtnBottom: -18,
- isShowOfflineTime: false,
- http: MultipleType.LessMoney,
- isShowVideoBtn: true
- },
- ];
- start() {
- // this.initUI(1, "");
- g.gameData.isPlayVideo = false;
- }
- /**
- * 加载光效
- */
- public async addLigthEffects() {
- let prefabsData = await ResourcesUtils.load<Prefab>(this.lightEfficiency, null, this.node);
- var lightNode = instantiate(prefabsData);
- lightNode.parent = this.turnLight;
- let rotatingLight = lightNode.getComponent(RotatingLightAnim);
- rotatingLight.set_Data(800, 800, 0.3, false, "light");
- }
- /**
- * 加载星星特效
- */
- public async addStar() {
- for (let i = 0; i < 25; i++) {
- let prefabsData = await ResourcesUtils.load<Prefab>(this.starEfficiency, null, this.node);
- var starNode = instantiate(prefabsData);
- starNode.parent = this.starEffects;
- let starAnim = starNode.getComponent(StarAnim);
- let wrapMode = Math.random() < 0.5 ? 38 : 2;
- let startTime = Math.random() * 3;
- let _size = this.starEffects.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");
- }
- }
- /**
- * @zh 获取金币视频弹窗初始化
- * @param data 0:(0:飞行宝箱,1:离线奖励,2:金币不足看视频领金币);
- * 1:可领取金币金额;
- * 2:翻倍领取倍数;
- * 3:离线时间(非离线奖励可不填)
- */
- public initUI(data: any[]) {
- this.uiData = data;
- let uiData = this.windowType[data[0]];
- this.closeBtn.active = uiData.isShowClosebtn;
- this.title.getComponent(Label).string = uiData.title;
- this.windowBox.getComponent(UITransform).setContentSize(uiData.bgWidth, uiData.bgHeight);
- this.getGoldTimes.active = uiData.isShowGetTimes;
- this.getLittleGold.active = uiData.isShowGetLittleGold;
- this.videoBtn.getComponent(Widget).bottom = uiData.videoBtnBottom;
- this.videoBtn0.active = uiData.isShowVideoBtn;
- this.videoBtn.active = !uiData.isShowVideoBtn;
- if (uiData.isShowVideoBtn) {
- this.AD.destroy();
- }
- //获取界面相关文本
- if (uiData.isShowGetTimes) {
- this.getGoldTimes.getComponent(Label).string = "今日剩余领取次数:" + g.gameData.flyBoxTimes;
- }
- if (data[2]) {
- this.videoBtnTxt.getComponent(Label).string = data[2] + "倍领取";
- this.multiple = data[2];
- }
- this.offlineMoney.getComponent(Label).string = FsUtils.moneyFormat(data[1]);
- if (uiData.isShowOfflineTime) {
- this.offlineMoneyBox.getComponent(Widget).bottom = 40;
- this.offlineTile.getComponent(Widget).bottom = 130;
- var tempMin = Math.floor(data[3] / 60) % 60;
- var tempHour = Math.floor((Math.floor(data[3] / 60) - tempMin) / 60);
- tempHour = tempHour > 2 ? 2 : tempHour;
- var tempText = tempHour > 0 ? "您已离线" + tempHour + "小时" : "您已离线";
- if (tempHour != 2) {
- tempText = tempMin > 0 ? tempText + tempMin + "分钟" : tempText;
- }
- this.offlineTime.getComponent(Label).string = tempText;
- } else {
- this.offlineMoneyBox.getComponent(Widget).bottom = 112;
- this.offlineTile.active = false;
- }
- this.addLigthEffects();
- this.addStar();
- }
- public isSend = false;
- // 播放视频
- public async playVideo() {
- if (g.gameData.isPlayVideo) {
- return;
- }
- g.gameData.isPlayVideo = true;
- //#region 打开加载等待界面
- let _window = await WindowManager.open("Prefabs/Windows/加载等待窗口", WindowOpenMode.NotCloseAndCover);
- let data = await this.http.send("/api/ad/WatchVideoAD");//观看视频起始
- _window.getComponent(LoginWaitWin).close();//关闭加载等待界面
- 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("视频准备中,请稍后再试");
- // WindowManager.showTips(g.CodeMsg[data.code]);
- // this.close();
- g.gameData.isPlayVideo = false;
- break;
- }
- }
- //视频结束回调
- public async videoBack() {
- //#region 打开加载等待界面
- let _window = await WindowManager.open("Prefabs/Windows/加载等待窗口", WindowOpenMode.NotCloseAndCover);
- //#endregion
- let data = await this.http.send("/api/wealth/AddDiamondForVideo", { multipleType: this.windowType[this.uiData[0]].http, adData: g.adData })
- _window.getComponent(LoginWaitWin).close();//关闭加载等待界面
- if (data.code == 0) {//视频观看成功
- if (data.data.addDiamond > 0) {
- this.getComponent(OpenWindow).prefabPath = "Prefabs/Windows/神石领取界面";
- let _window = this.getComponent(OpenWindow);
- _window.open([data.data.addDiamond, 0, [this.uiData[1] * this.multiple, this.uiData[0]]]);
- WindowManager.close(this.node);
- } else {
- WindowManager.open("Prefabs/Windows/金币领取窗口", WindowOpenMode.CloseAndAdd, [this.uiData[1] * this.multiple, this.uiData[0]])
- WindowManager.close(this.node);
- }
- } else {
- g.gameData.isPlayVideo = false;
- WindowManager.showTips(g.CodeMsg[data.code]);
- }
- }
- //未看视频领取
- public setGoldData() {
- let _window = this.getComponent(OpenWindow);
- _window.open([this.uiData[1], this.uiData[0]]);
- }
- //直接关闭窗口,离线奖励点击关闭按钮也会领取金币
- public close() {
- if (this.uiData[0] == 1) {
- let _window = this.getComponent(OpenWindow);
- _window.open([this.uiData[1], this.uiData[0]]);
- WindowManager.close(this.node);
- } else {
- WindowManager.close(this.node);
- }
- }
- onDestroy() {
- g.gameData.isPlayVideo = false;
- }
- }
|