| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- import GamePlay from "../../../before/GamePlay";
- import { AdFun } from "../../data/AdData";
- import { RewardType } from "../../data/GameData";
- const { ccclass, property } = cc._decorator;
- /**
- * 盖子类型
- */
- enum LidType {
- /** 无盖子 */
- none = 0,
- /** 幸运红包盖子 */
- luck = 1,
- /** 通关红包盖子 */
- mission = 2
- }
- /**
- * 获取奖励界面-红包
- * @author 薛鸿潇
- */
- @ccclass
- export default class Reward extends cc.Component {
- @property({ displayName: '红包类型', type: cc.Enum(LidType), tooltip: 'none无类型,luck幸运红包,mission通关红包' })
- private lid_type: LidType = LidType.none;
- @property({ displayName: '幸运红包', type: cc.Node })
- private node_luck: cc.Node = null;
- @property({ displayName: '通关红包', type: cc.Node })
- private node_mission: cc.Node = null;
- @property({ displayName: '开红包动画', type: cc.Animation })
- private anim_open_redbag: cc.Animation = null;
- @property({ displayName: '按钮看视频', type: cc.Button })
- private btn_watch_video: cc.Button = null;
- @property({ displayName: '红包图标', type: cc.Node })
- private node_redBag: cc.Node = null;
- @property({ displayName: '金猪图标', type: cc.Node })
- private node_pig: cc.Node = null;
- @property({ displayName: '奖励数量', type: cc.Label })
- private lbl_reward_value: cc.Label = null;
- // 底部提现相关
- @property({ displayName: 'spr提现进度', type: cc.Sprite })
- private spr_cash_out: cc.Sprite = null;
- @property({ displayName: 'lbl提现进度', type: cc.Label })
- private lbl_cash_out: cc.Label = null;
- @property({ displayName: '提现金额', type: cc.Label })
- private lbl_cash: cc.Label = null;
- /** 当前阶段 */
- private cur_stage: number = LidType.none;
- onLoad() {
- this.lbl_reward_value.string = '0';
- // gData.reward.data = [{ rewardType: 3, rewardNum: 100 }]// 测试数据
- }
- start() {
- /** 盖子 */
- this.initLid();
- }
- update(dt) {
- if (gData.reward.init_cash_style) {
- this.initCashOutStyle();
- return;
- }
- if (gData.reward.adData) {
- // 展示奖励
- this.watchVideoCall();
- return;
- }
- }
- lateUpdate() {
- gData.reward.init_cash_style = null;
- gData.reward.adData = null;
- }
- /**
- * 初始化封面样式
- */
- private initLid() {
- if (this.lid_type === LidType.none) {// 无盖子样式
- this.node_luck.active = false;
- this.node_mission.active = false;
- this.btn_watch_video.node.active = false;
- this.watchVideoCall();
- } else if (this.lid_type === LidType.luck) {
- this.node_luck.active = true;
- this.node_mission.active = false;
- this.btn_watch_video.node.active = true;
- this.cur_stage = LidType.luck;
- mk.audio.playEffect("reward");
- } else if (this.lid_type === LidType.mission) {
- this.node_luck.active = false;
- this.node_mission.active = true;
- this.btn_watch_video.node.active = true;
- this.cur_stage = LidType.mission;
- mk.audio.playEffect("reward");
- }
- }
- /**
- * 底部提现相关样式
- */
- private initCashOutStyle() {
- const cash_bar = gData.redBagCash.cash_bar;
- let cash_data = gData.redBagCash.getItemDataByIndex(cash_bar);
- if (!cash_data) return;
- this.lbl_cash.string = cash_data.money + '元';
- this.lbl_cash_out.string = gData.gameData.gameData.redMoney + '/' + cash_data.type_value;
- this.spr_cash_out.fillRange = gData.gameData.gameData.redMoney / cash_data.type_value;
- }
- /**
- * 看广告
- */
- private clickWatchVideo() {
- cc.log('看广告请求');
- if (gData.reward.data[0] && gData.reward.data[0].rewardType === 1) {
- // 关卡结算视频
- mk.ad.watchAd((success: boolean) => {
- mk.console.log("watchAD:" + success);
- if (success) {
- gData.adData.watchVideo(AdFun.settlement);
- }
- });
- } else {
- // 气泡视频
- mk.ad.watchAd((success: boolean) => {
- mk.console.log("watchAD:" + success);
- if (success) {
- gData.adData.watchVideo(AdFun.bubble);
- }
- });
- }
- // 测试数据
- // gData.reward.adData = gData.reward.data;
- }
- /**
- * 看广告回调:开奖
- */
- private watchVideoCall() {
- if (gData.reward.adData) {
- gData.reward.data = gData.reward.adData;
- }
- if (!gData.reward.data || !gData.reward.data.length) return;
- mk.audio.playEffect("rewardOpen");
- this.cur_stage = LidType.none;
- // 数据排序:多条奖励,只展示红包,把红包放在首位
- const r_count = gData.reward.data.length;
- if (r_count >= 2) {
- for (let i = 0; i < r_count; i++) {
- if (gData.reward.data[i].rewardType === 1) {
- let new_data = gData.reward.data.splice(i, 1);
- gData.reward.data.unshift(new_data);
- break;
- }
- }
- }
- // 图标展示
- if (gData.reward.data[0].rewardType === RewardType.redBag) {
- this.node_redBag.active = true;
- this.node_pig.active = false;
- } else {
- this.node_redBag.active = false;
- this.node_pig.active = true;
- }
- let rewardNum = gData.reward.data[0].rewardNum || 0;
- this.lbl_reward_value.string = `${rewardNum}`;
- // 动画
- this.anim_open_redbag.play();
- this.node_luck.active = false;
- this.node_mission.active = false;
- this.btn_watch_video.node.active = false;
- }
- /**
- * 点击获得奖励
- */
- private clickGetReward() {
- cc.log('获取奖励:', gData.reward.data);
- gData.reward.addReward();
- this.flyCoinAnim();
- gData.reward.data = [];
- }
- /**
- * 提现操作
- */
- private clickCashOut() {
- let path = 'module/redBagCash/redBagCash';
- mk.ui.openPanel(path);
- }
- /**
- * 飞coin动画
- */
- private flyCoinAnim() {
- if (!gData.reward.data || !gData.reward.data.length) return;
- let target_node = gData.gameData.gameStyle.icon_hb;
- if (gData.reward.data[0].rewardType == RewardType.redBag) {
- target_node = gData.gameData.gameStyle.icon_hb;
- } else if (gData.reward.data[0].rewardType == RewardType.rmb) {
- // target_node = gData.gameData.gameStyle.icon_zb;
- } else if (gData.reward.data[0].rewardType == RewardType.pigRmb) {
- target_node = gData.gameData.gameStyle.icon_zb;
- }
- const end_world_pos = target_node.parent.convertToWorldSpaceAR(target_node.getPosition());
- const end_node_pos = gData.gameData.gameStyle.node.parent.convertToNodeSpaceAR(end_world_pos);
- let start_node_pos = new cc.Vec2(0, -300);
- mk.fly.PlayCoinAnim(gData.reward.data[0].rewardType, 10, start_node_pos, end_node_pos)
- }
- /**
- * 下一关操作
- */
- public clickNextMission() {
- GamePlay.Inst.nextLevel();
- }
- /** 点击返回 */
- public clickBack() {
- GamePlay.Inst.restart(false);//退出不扣体力
- GamePlay.Inst.node.active = false;
- }
- onDestroy() {
- if (this.cur_stage === LidType.none) {
- mk.audio.playEffect("rewardClose");
- }
- }
- }
|