Reward.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import { AdFun } from "../../../data/AdData";
  2. const { ccclass, property } = cc._decorator;
  3. /**
  4. * 获取奖励界面-红包
  5. * @author 薛鸿潇
  6. */
  7. @ccclass
  8. export default class Reward extends cc.Component {
  9. @property({ displayName: '幸运红包', type: cc.Node })
  10. private node_luck: cc.Node = null;
  11. @property({ displayName: '通关红包', type: cc.Node })
  12. private node_mission: cc.Node = null;
  13. @property({ displayName: '开红包动画', type: cc.Animation })
  14. private anim_open_redbag: cc.Animation = null;
  15. @property({ displayName: '按钮看视频', type: cc.Button })
  16. private btn_watch_video: cc.Button = null;
  17. @property({ displayName: '红包图标', type: cc.Node })
  18. private node_redBag: cc.Node = null;
  19. @property({ displayName: '金猪图标', type: cc.Node })
  20. private node_pig: cc.Node = null;
  21. @property({ displayName: '奖励数量', type: cc.Label })
  22. private lbl_reward_value: cc.Label = null;
  23. // 底部提现相关
  24. @property({ displayName: 'spr提现进度', type: cc.Sprite })
  25. private spr_cash_out: cc.Sprite = null;
  26. @property({ displayName: 'lbl提现进度', type: cc.Label })
  27. private lbl_cash_out: cc.Label = null;
  28. @property({ displayName: '提现金额', type: cc.Label })
  29. private lbl_cash: cc.Label = null;
  30. onLoad() {
  31. this.lbl_reward_value.string = '0';
  32. // 测试数据
  33. gData.reward.data.push({
  34. /** 奖励类型 */
  35. rewardType: 1,
  36. /** 奖励数量 */
  37. rewardNum: 100,
  38. /** 玩家剩余数量 */
  39. rewardTotal: 0
  40. })
  41. }
  42. start() {
  43. /** 盖子 */
  44. this.initLid();
  45. }
  46. update(dt) {
  47. if (gData.reward.init_luck_style) {
  48. gData.reward.init_luck_style = null;
  49. this.initLid();
  50. return;
  51. }
  52. if (gData.reward.init_cash_style) {
  53. gData.reward.init_cash_style = null;
  54. this.initCashOutStyle();
  55. return;
  56. }
  57. if (gData.reward.adData) {
  58. // 展示奖励
  59. this.watchVideoCall();
  60. gData.reward.adData = null;
  61. return;
  62. }
  63. }
  64. /**
  65. * 初始化封面样式
  66. */
  67. private initLid() {
  68. if (gData.reward.is_luck) {
  69. this.node_luck.active = true;
  70. this.node_mission.active = false;
  71. } else {
  72. this.node_luck.active = false;
  73. this.node_mission.active = true;
  74. }
  75. }
  76. /**
  77. * 底部提现相关样式
  78. */
  79. private initCashOutStyle() {
  80. // 测试数据
  81. this.lbl_cash.string = 0.0 + '元';
  82. this.lbl_cash_out.string = 0 + '/' + 100;
  83. this.spr_cash_out.fillRange = 0.8;
  84. }
  85. /**
  86. * 看广告
  87. */
  88. private clickWatchVideo() {
  89. cc.log('看广告请求');
  90. if (gData.reward.data[0].rewardType === 1) {
  91. gData.adData.watchVideo(AdFun.settlement)// 关卡结算视频
  92. } else {
  93. gData.adData.watchVideo(AdFun.bubble);// 气泡视频
  94. }
  95. // 测试数据
  96. gData.reward.adData = gData.reward.data;
  97. }
  98. /**
  99. * 看广告回调:开奖
  100. */
  101. private watchVideoCall() {
  102. gData.reward.data = gData.reward.adData;
  103. // 数据排序:多条奖励,只展示红包,把红包放在首位
  104. const r_count = gData.reward.adData.length;
  105. if (r_count >= 2) {
  106. for (let i = 0; i < r_count; i++) {
  107. if (gData.reward.adData[i].rewardType === 1) {
  108. let new_data = gData.reward.adData.splice(i, 1);
  109. gData.reward.adData.unshift(new_data);
  110. break;
  111. }
  112. }
  113. }
  114. // 图标展示
  115. if (gData.reward.data[0].rewardType === 1) {
  116. this.node_redBag.active = true;
  117. this.node_pig.active = false;
  118. } else {
  119. this.node_redBag.active = false;
  120. this.node_pig.active = true;
  121. }
  122. let rewardNum = gData.reward.data[0].rewardNum || 0;
  123. this.lbl_reward_value.string = `${rewardNum}`;
  124. // 动画
  125. this.anim_open_redbag.play();
  126. this.node_luck.active = false;
  127. this.node_mission.active = false;
  128. this.btn_watch_video.node.active = false;
  129. }
  130. /**
  131. * 获得奖励
  132. */
  133. private clickGetReward() {
  134. cc.log('获取奖励:', gData.reward.data);
  135. }
  136. /**
  137. * 提现操作
  138. */
  139. private clickCashOut() {
  140. cc.log('提现:');
  141. }
  142. /**
  143. * 下一关操作
  144. */
  145. private clickNextMission() {
  146. }
  147. }