| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- import { _decorator, Component, Prefab, instantiate, UITransform, Node, Label, Sprite, Button } from 'cc';
- import InfiniteCell from '../core/InfiniteList/InfiniteCell';
- import { IFDataSource, InfiniteList } from '../core/InfiniteList/InfiniteList';
- import { Http } from '../core/net/Http';
- import { BitmapFont } from '../core/ui/BitmapFont';
- import { OpenWindow } from '../core/ui/window/OpenWindow';
- import { WindowManager } from '../core/ui/window/WindowManager';
- import { WindowOpenMode } from '../core/ui/window/WindowOpenMode';
- import { Utils } from '../core/utils/Utils';
- import { g } from '../Data/g';
- import { HttpErrorCode } from '../Data/HttpErrorCode';
- import { platform } from '../Data/platform';
- import { DayPrizeItem } from './DayPrizeItem';
- const { ccclass, property } = _decorator;
- @ccclass('DayPrize')
- export class DayPrize extends Component implements IFDataSource {
- @property({ type: Prefab, tooltip: "子项节点" })
- public dayPrizeItem: Prefab = null;
- @property({ type: Node, tooltip: "列表节点" })
- public list: Node = null;
- @property({ type: Sprite })
- public button: Sprite = null;
- @property({ type: BitmapFont })
- public times: BitmapFont = null;
- private http: Http;
- private prefabHeight: number;
- private itemArr: Array<any>;
- private infiniteList: InfiniteList;
- private _timesNum: number = 0;
- set timesNum(times: number) {
- this._timesNum = times;
- this.times.string = times + "";
- }
- get timesNum() {
- return this._timesNum;
- }
- async start() {
- let prefab = instantiate(this.dayPrizeItem);
- this.prefabHeight = prefab.getComponent(UITransform).height;
- prefab.destroy();
- this.infiniteList = this.list.getComponent(InfiniteList);
- this.http = this.getComponent(Http);
- await this.queryData();
- this.infiniteList.Init(this);
- }
- /**
- * 观看视频
- */
- async onVideo() {
- let applyReturn = await this.http.send("/api/ad/watchVideoAD");
- //可以观看视频
- if (applyReturn.code == 0) {
- platform.reportThinking("ad_init", JSON.stringify({ ad_id: "daily_process", ad_time: Utils.formatDate(new Date()), id: g.userData.id, role_name: g.userData.nickName, level: g.userData.getLevel() }));
- //播放视频
- let adData = await g.showRewardVideo();
- if (adData) {
- this.onVideoOver();
- } else {
- //视频观看失败
- WindowManager.showTips("视频观看时间不足");
- }
- } else if (applyReturn.code == 106) {
- WindowManager.showTips("今日视频次数已用完,请明日再继续");
- } else if (applyReturn.code == HttpErrorCode.VideoADCD) {
- WindowManager.showTips("请求频繁,请稍后再试");
- } else {
- WindowManager.showTips("视频准备中,请稍后再试");
- }
- }
- /**
- * 视频播放完毕
- */
- async onVideoOver() {
- let data = await this.http.send("/api/dailyprize/watchDailyPrizeVideoAD", { adData: g.adData });
- if (data.code == 0) {
- platform.reportThinking("ad_end", JSON.stringify({ ad_id: "diamond_get", ad_time: Utils.formatDate(new Date()), id: g.userData.id, role_name: g.userData.nickName, level: g.userData.getLevel() }));
- platform.umUp("dailyReward");//每日奖励埋点
- this.timesNum = this.timesNum - 1;
- this.updateItem(data.data);
- this.infiniteList.Refresh();
- //观看成功
- WindowManager.open("Prefabs/DayPrize/DayPrizeTips", WindowOpenMode.NotCloseAndAdd, " ");
- } else if (data.code == HttpErrorCode.VideoADCD) {
- WindowManager.showTips("请求频繁,请稍后再试");
- }
- }
- /**
- * 查询每日奖励数据
- */
- private async queryData() {
- let data = await this.http.send("/api/dailyprize/getdailyprize");
- if (data.code == 0) {
- this.itemArr = data.data.prizeList;
- this.timesNum = data.data.videoTimes;
- this.infiniteList.Refresh()
- } else {
- WindowManager.showTips("发生错误,请重试");
- }
- }
- /**
- * 根据次数禁用观看视频按钮
- */
- update() {
- if (this.timesNum == 0) {
- this.button.grayscale = true;
- this.button.getComponent(Button).interactable = false;
- } else {
- this.button.grayscale = false;
- this.button.getComponent(Button).interactable = true;
- }
- }
- /**
- * 更新子项进度
- * @returns
- */
- public updateItem(updateData: any) {
- for (let i = 0; i < this.itemArr.length; i++) {
- let id = this.itemArr[i].id;
- let value = updateData[`${id}`];
- this.itemArr[i]["value"] = value;
- }
- }
- /**
- * 向子项提供数据
- * @returns
- */
- GetCellNumber(): number {
- return this.itemArr.length;
- }
- GetCellIdentifer(dataIndex: number): string {
- return "DayPrizeItem";
- }
- GetCellSize(dataIndex: number): number {
- return this.prefabHeight;
- }
- GetCellView(dataIndex: number, identifier?: string): InfiniteCell {
- let prefab = instantiate(this.dayPrizeItem);
- return prefab.getComponent(DayPrizeItem);
- }
- GetCellData?(dataIndex: number) {
- return this.itemArr[dataIndex];
- }
- }
|