RewardNode.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  7. import AdM from "../manager/AdM";
  8. import GameM, { VIDEO_TYPE, AUDIO_TYPE } from "../manager/GameM";
  9. import UiM, { PANEL_NAME } from "../manager/UiM";
  10. import EffectNode from "./EffectNode";
  11. import TaskItem from "../prefabs/TaskItem";
  12. import { RecordTYPE } from "../datas/CommonData";
  13. import Sciencen_M from "../utils/Sciencen_M";
  14. import Main from "../Main";
  15. import SwitchM from "../manager/SwitchM";
  16. import CashOutData from "../datas/CashOutData";
  17. const { ccclass, property } = cc._decorator;
  18. @ccclass
  19. export default class RewardNode extends cc.Component {
  20. @property(cc.Node)
  21. btn_close: cc.Node = null;
  22. @property(cc.Node)
  23. par: cc.Node = null;
  24. @property(cc.Node)
  25. redNumNode: cc.Node = null;
  26. @property(cc.Label)
  27. redMoneyTxt: cc.Label = null;
  28. @property(cc.Node)
  29. goldNumNode: cc.Node = null;
  30. @property(cc.Label)
  31. goldTxt: cc.Label = null;
  32. @property(cc.Label)
  33. myRedTxt: cc.Label = null;
  34. @property(cc.Label)
  35. myMoneyTxt: cc.Label = null;
  36. //任务与成就领取
  37. @property(cc.Node)
  38. taskNode: cc.Node = null;
  39. @property(cc.Node)
  40. taskSingleBtn: cc.Node = null;
  41. //账号等级提升奖励
  42. @property(cc.Node)
  43. userLvUpNode: cc.Node = null;
  44. @property(cc.Label)
  45. userLvTxt: cc.Label = null;
  46. @property(cc.Node)
  47. userLvUpSingleBtn: cc.Node = null;
  48. @property(cc.Node)
  49. lyRedMoney: cc.Node = null;
  50. taskItem: TaskItem;
  51. start() {
  52. }
  53. onEnable() {
  54. GameM.audioM.playEffect(AUDIO_TYPE.open_interface)
  55. AdM.destroyNative()
  56. }
  57. onClickBtnClose() {
  58. if (this.userLvUpNode.active) {
  59. AdM.createInter(10)
  60. }
  61. this.userLvUpNode.active = false;
  62. this.taskNode.active = false;
  63. this.node.active = false
  64. this.redNumNode.active = false;
  65. this.goldNumNode.active = false;
  66. //显示界面
  67. UiM.Instance.displayPanel();
  68. }
  69. onEnter() {
  70. this.myRedTxt.string = GameM.commonData.redMoney.toString();
  71. if (GameM.commonData.redSwitch) {
  72. this.myMoneyTxt.string = '≈' + (GameM.commonData.redMoney * 0.0001).toFixed(3) + '元';
  73. }
  74. else {
  75. this.myMoneyTxt.string = ''
  76. }
  77. this.lyRedMoney.active = GameM.commonData.redSwitch
  78. }
  79. //账号等级提升奖励
  80. EnterUserLvUpPanel() {
  81. this.btn_close.active = false;
  82. this.taskNode.active = false;
  83. this.node.active = true
  84. this.node.x = 0
  85. this.par.scale = 0;
  86. cc.tween(this.par).to(0.3, { scale: 1 }, { easing: "backOut" }).start();
  87. this.userLvUpNode.active = false;
  88. this.redNumNode.active = true;
  89. this.goldNumNode.active = false;
  90. this.redMoneyTxt.string = Sciencen_M.instance.format(GameM.commonData.roleCft[GameM.commonData.roleData.lv - 1].reward_num.toString());
  91. this.onEnter();
  92. this.userLvUpNode.active = true;
  93. this.userLvTxt.string = GameM.commonData.roleData.lv.toString();
  94. this.userLvUpSingleBtn.active = false;
  95. this.unschedule(this.userTweenCall)
  96. let delayTime = 0
  97. if (SwitchM.forceMakeMoney) {
  98. delayTime = 2
  99. }
  100. this.scheduleOnce(this.userTweenCall, delayTime)
  101. }
  102. userTweenCall() {
  103. this.userLvUpSingleBtn.active = true;
  104. this.userLvUpSingleBtn.opacity = 0;
  105. cc.tween(this.userLvUpSingleBtn).to(0.5, { opacity: 255 }).start();
  106. }
  107. ExitUserLvUpPanel() {
  108. this.onClickBtnClose();
  109. this.unschedule(this.userTweenCall);
  110. if (GameM.commonData.roleData.lv == CashOutData.Instance.cashCft[0].type_value) {
  111. UiM.Instance.hallNode.getComponent(Main).checkNewUser()
  112. }
  113. }
  114. //任务 成就领取
  115. EnterTaskPanel(taskItem: TaskItem) {
  116. this.taskItem = taskItem;
  117. this.btn_close.active = false;
  118. this.userLvUpNode.active = false;
  119. this.node.x = 0
  120. this.node.active = true
  121. this.par.scale = 0;
  122. cc.tween(this.par).to(0.3, { scale: 1 }, { easing: "backOut" }).start();
  123. this.redNumNode.active = true;
  124. this.goldNumNode.active = false;
  125. this.redMoneyTxt.string = Sciencen_M.instance.format(taskItem.data.rewadr_num.toString());
  126. this.onEnter();
  127. this.taskNode.active = true;
  128. this.taskSingleBtn.active = false;
  129. let delayTime = 0
  130. if (SwitchM.forceMakeMoney) {
  131. delayTime = 2
  132. }
  133. this.scheduleOnce(this.taskTweenCall, delayTime)
  134. }
  135. taskTweenCall() {
  136. this.taskSingleBtn.active = true;
  137. this.taskSingleBtn.opacity = 0;
  138. cc.tween(this.taskSingleBtn).to(0.5, { opacity: 255 }).start();
  139. }
  140. ExitTaskPanel() {
  141. this.onClickBtnClose();
  142. this.unschedule(this.taskTweenCall);
  143. }
  144. //-------------------用户等级提升
  145. BtnAdUserlvUpClick() {
  146. AdM.Instance.watchVideo(VIDEO_TYPE.userLvUpAd);
  147. }
  148. BtnAdUserLvUpEnd() {
  149. GameM.commonData.updateRedMoney(Number(GameM.commonData.roleCft[GameM.commonData.roleData.lv - 1].reward_num) + 300, RecordTYPE.roleLevelup);
  150. EffectNode.instance.PlayCoinAnim(1, 20, cc.v2(0, -300));
  151. this.ExitUserLvUpPanel();
  152. EffectNode.instance.PlayTip("感谢您的观看,额外奖励已发放");
  153. }
  154. BtnSingleUserLvUpClick() {
  155. GameM.commonData.updateRedMoney(Number(GameM.commonData.roleCft[GameM.commonData.roleData.lv - 1].reward_num), RecordTYPE.roleLevelup);
  156. EffectNode.instance.PlayCoinAnim(1, 20, cc.v2(0, -300));
  157. this.ExitUserLvUpPanel();
  158. }
  159. //--------------------任务 成就
  160. BtnAdTaskClick() {
  161. AdM.Instance.watchVideo(VIDEO_TYPE.taskRwardAd);
  162. }
  163. BtnAdTaskEnd() {
  164. this.taskItem.AdGet();
  165. this.onClickBtnClose();
  166. }
  167. BtnSingleTaskClick() {
  168. this.taskItem.Get();
  169. this.onClickBtnClose();
  170. }
  171. }