Reward.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import { AdFun } from "../../data/AdData";
  2. import { RewardType } from "../../data/GameData";
  3. const { ccclass, property } = cc._decorator;
  4. /**
  5. * 获取奖励界面-红包
  6. * @author 薛鸿潇
  7. */
  8. @ccclass
  9. export default class Reward extends cc.Component {
  10. @property({ displayName: '幸运红包', type: cc.Node })
  11. private node_luck: cc.Node = null;
  12. @property({ displayName: '通关红包', type: cc.Node })
  13. private node_mission: cc.Node = null;
  14. @property({ displayName: '开红包动画', type: cc.Animation })
  15. private anim_open_redbag: cc.Animation = null;
  16. @property({ displayName: '按钮看视频', type: cc.Button })
  17. private btn_watch_video: cc.Button = null;
  18. @property({ displayName: '红包图标', type: cc.Node })
  19. private node_redBag: cc.Node = null;
  20. @property({ displayName: '金猪图标', type: cc.Node })
  21. private node_pig: cc.Node = null;
  22. @property({ displayName: '奖励数量', type: cc.Label })
  23. private lbl_reward_value: cc.Label = null;
  24. // 底部提现相关
  25. @property({ displayName: 'spr提现进度', type: cc.Sprite })
  26. private spr_cash_out: cc.Sprite = null;
  27. @property({ displayName: 'lbl提现进度', type: cc.Label })
  28. private lbl_cash_out: cc.Label = null;
  29. @property({ displayName: '提现金额', type: cc.Label })
  30. private lbl_cash: cc.Label = null;
  31. onLoad() {
  32. this.lbl_reward_value.string = '0';
  33. }
  34. start() {
  35. /** 盖子 */
  36. this.initLid();
  37. }
  38. update(dt) {
  39. if (gData.reward.init_luck_style) {
  40. gData.reward.init_luck_style = null;
  41. this.initLid();
  42. return;
  43. }
  44. if (gData.reward.init_cash_style) {
  45. gData.reward.init_cash_style = null;
  46. this.initCashOutStyle();
  47. return;
  48. }
  49. if (gData.reward.adData) {
  50. // 展示奖励
  51. this.watchVideoCall();
  52. gData.reward.adData = null;
  53. return;
  54. }
  55. }
  56. /**
  57. * 初始化封面样式
  58. */
  59. private initLid() {
  60. if (gData.reward.lid_type === gData.reward.type_lid.none) {// 无盖子样式
  61. this.node_luck.active = false;
  62. this.node_mission.active = false;
  63. this.watchVideoCall();
  64. mk.audio.playEffect("rewardOpen");
  65. } else if (gData.reward.lid_type === gData.reward.type_lid.luck) {
  66. this.node_luck.active = false;
  67. this.node_mission.active = true;
  68. mk.audio.playEffect("reward");
  69. } else if (gData.reward.lid_type === gData.reward.type_lid.mission) {
  70. this.node_luck.active = false;
  71. this.node_mission.active = true;
  72. mk.audio.playEffect("reward");
  73. }
  74. }
  75. /**
  76. * 底部提现相关样式
  77. */
  78. private initCashOutStyle() {
  79. const cash_bar = gData.redBagCash.cash_bar
  80. let cash_data = gData.redBagCash.getItemDataByIndex(cash_bar)
  81. this.lbl_cash.string = cash_data.money + '元';
  82. this.lbl_cash_out.string = gData.gameData.gameData.redMoney + '/' + cash_data.type_value;
  83. this.spr_cash_out.fillRange = gData.gameData.gameData.redMoney / cash_data.type_value;
  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. if (!gData.reward.data || !gData.reward.data.length) return;
  103. // 数据排序:多条奖励,只展示红包,把红包放在首位
  104. const r_count = gData.reward.data.length;
  105. if (r_count >= 2) {
  106. for (let i = 0; i < r_count; i++) {
  107. if (gData.reward.data[i].rewardType === 1) {
  108. let new_data = gData.reward.data.splice(i, 1);
  109. gData.reward.data.unshift(new_data);
  110. break;
  111. }
  112. }
  113. }
  114. // 图标展示
  115. if (gData.reward.data[0].rewardType === RewardType.redBag) {
  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. gData.reward.data = null;
  136. }
  137. /**
  138. * 提现操作
  139. */
  140. private clickCashOut() {
  141. cc.log('提现:');
  142. }
  143. /**
  144. * 下一关操作
  145. */
  146. private clickNextMission() {
  147. }
  148. onDestroy(){
  149. mk.audio.playEffect("rewardClose");
  150. }
  151. }