import { _decorator, Component, Label, Sprite } from 'cc'; 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 { GetType } from '../UI/GetWindow/GetType'; const { ccclass, property } = _decorator; @ccclass('AchievementItem') export class AchievementItem extends Component { @property({ type: BitmapFont }) public gradeRight: BitmapFont = null; @property({ type: BitmapFont }) public title: BitmapFont = null; @property({ type: Label }) public redNum: Label = null; @property({ type: Sprite }) public unGet: Sprite = null; @property({ type: Sprite }) public canGet: Sprite = null; @property({ type: Sprite }) public geted: Sprite = null; private http: Http; start() { this.http = this.node.getComponent(Http); } /** * Item ID */ public id: number; onUngetClick() { WindowManager.showTips("未到达指定等级"); } async onCangetClick() { let result = await this.http.send("/api/ad/watchVideoAD"); if (result.code == 0) { platform.reportThinking("ad_init", JSON.stringify({ ad_id: "farm_reward", 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 (result.code == 106) { WindowManager.showTips("今日视频次数已用完,请明日再继续"); } else if (result.code == HttpErrorCode.VideoADCD) { WindowManager.showTips("请求频繁,请稍后再试"); } else { WindowManager.showTips("视频准备中,请稍后再试"); } } /** * 视频结束 */ private async onVideoOver() { let data = await this.http.send("/api/levelReward/getLevelReward", { configID: this.id, adData: g.adData }) if (data.code == 0) { platform.reportThinking("ad_end", JSON.stringify({ ad_id: "farm_reward", ad_time: Utils.formatDate(new Date()), id: g.userData.id, role_name: g.userData.nickName, level: g.userData.getLevel(), award: this.redNum.string })) platform.umUp("lvReward");//成就埋点 platform.reportThinking("envelope_increase", JSON.stringify({ previous_number: g.userData.bonus, increase_number: parseInt(this.redNum.string), current_number: g.userData.bonus + parseInt(this.redNum.string), reasons: "LevelReward" })); WindowManager.open("Prefabs/GetWindow", WindowOpenMode.CloseAndAdd, [{ count: (Number)(this.redNum.string), type: GetType.RedBag, needBezierEffect: true }]); this.canGet.node.active = false; this.unGet.node.active = !this.canGet.node.active; } } }