| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- import { _decorator, Component, Node, ImageAsset, SpriteFrame, Texture2D, Label, Sprite } from 'cc';
- import { JSB } from 'cc/env';
- import { Http } from '../../core/net/Http';
- import { ResourcesUtils } from '../../core/resourceManager/ResourcesUtils';
- 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';
- const { ccclass, property } = _decorator;
- /**合成红包 */
- @ccclass('MixRedPacket')
- export class MixRedPacket extends Component {
- @property({ type: Label, tooltip: "名字文本" }) titleLabel: Label;
- @property({ type: Sprite, tooltip: "图标" }) icon: Sprite;
- @property({ tooltip: "http服务", type: Http }) http: Http;
- async start() {
- }
- private async onOpenHander() {
- let data = g.downLoadData.recommendData[Math.floor(Math.random() * g.downLoadData.recommendData.length)];
- this.titleLabel.string = data.title;
- if (JSB) {
- let img = await ResourcesUtils.loadRemote<ImageAsset>(data.icon, { ext: ".png" }, this);
- const spriteFrame = new SpriteFrame();
- const texture = new Texture2D();
- texture.image = img;
- spriteFrame.texture = texture;
- this.icon.spriteFrame = spriteFrame;
- }
- }
- /**领取合成红包 */
- private async onGet() {
- let result = await this.http.send("/api/ad/watchVideoAD");
- if (result.code == 0) {
- //播放视频
- let adData = await g.showRewardVideo();
- if (adData) {
- this.videoBack();
- } else {
- //视频观看失败
- WindowManager.showTips("视频观看时间不足");
- }
- } else if (result.code == 108) {
- WindowManager.showTips("今日视频次数已用完,请明日再继续");
- } else {
- WindowManager.showTips("视频准备中,请稍后再试");
- }
- }
- //视频结束回调,合成红包
- public async videoBack() {
- let data = await this.http.send("/api/wealth/AddDiamondForVideo", { multipleType: 1, adData: g.adData });
- 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, 1]);
- this.getComponent(Window).close();
- }
- } else {
- g.gameData.isPlayVideo = false;
- WindowManager.showTips(g.CodeMsg[data.code]);
- }
- }
- }
|