ClockInItem.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 PlayerConst from "../../data/PlayerConst";
  8. import GameConst from "../../data/GameConst";
  9. import EffectMgr from "../../mgr/EffectMgr";
  10. import GameMgr, { UIITEM_NAME } from "../../mgr/GameMgr";
  11. const { ccclass, property } = cc._decorator;
  12. @ccclass
  13. export default class ClockInItem extends cc.Component {
  14. /**普通bg */
  15. @property(cc.Node)
  16. node_nromalClockInBg: cc.Node = null;
  17. /**未打卡bg */
  18. @property(cc.Node)
  19. node_unClockInBg: cc.Node = null;
  20. /**已经打卡icon */
  21. @property(cc.Node)
  22. node_haveClockInIcon: cc.Node = null;
  23. /**红包 */
  24. @property(cc.Node)
  25. node_reaPacket: cc.Node = null;
  26. /**提示 */
  27. @property(cc.Node)
  28. node_tip: cc.Node = null;
  29. /**宝箱 */
  30. @property(cc.Node)
  31. node_box: cc.Node = null;
  32. /**当前打卡天 */
  33. public curClockInDay: number = 0;
  34. /**奖励类型 null 是无奖励 1 红包 2 是宝箱 */
  35. public rewardType: number = null;
  36. /**奖励数量 */
  37. public rewardNum: number = null;
  38. /**红包数目 */
  39. public reaPacketCashNum: number = 0;
  40. /**是否打卡成功 */
  41. public ifClockInDay: boolean = false;
  42. // LIFE-CYCLE CALLBACKS:
  43. // onLoad () {}
  44. start() {
  45. this.node.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
  46. }
  47. // update (dt) {}
  48. init(day: number = null) {
  49. // LogUtil.log("day",day)
  50. // if (!day) {
  51. // return;
  52. // }
  53. if (day) {
  54. this.curClockInDay = day;
  55. }
  56. // LogUtil.log("this.curClockInDay", this.curClockInDay);
  57. let config = GameConst.config_clockIn[this.curClockInDay - 1];
  58. // LogUtil.log("GameConst.config_clockIn", GameConst.config_clockIn);
  59. this.rewardType = config.rewardType;
  60. this.rewardNum = config.rewardNum
  61. this.ifClockInDay = PlayerConst.ifClockInToday;
  62. let curRealClockInDay: number = 0;
  63. //如果已经打卡 1 对应 1
  64. if (this.ifClockInDay) {
  65. curRealClockInDay = this.curClockInDay;
  66. }
  67. //如果未打开 1 对应 0
  68. else {
  69. curRealClockInDay = this.curClockInDay - 1;
  70. }
  71. if (curRealClockInDay < PlayerConst.clockInDay) {
  72. this.node_unClockInBg.active = false;
  73. this.node_nromalClockInBg.active = true;
  74. if (this.rewardType == 1) {
  75. this.node_nromalClockInBg.setScale(1, 1);
  76. }
  77. else {
  78. this.node_nromalClockInBg.setScale(0.8, 0.8);
  79. }
  80. this.node_reaPacket.active = this.rewardType == 1;
  81. this.node_haveClockInIcon.active = true;
  82. this.node_tip.active = false;
  83. this.node_box.active = this.curClockInDay == GameConst.maxClockInDay;
  84. }
  85. else if (curRealClockInDay == (PlayerConst.clockInDay)) {
  86. this.node_unClockInBg.active = false;
  87. this.node_nromalClockInBg.active = true;
  88. this.node_nromalClockInBg.setScale(1, 1);
  89. this.node_reaPacket.active = this.rewardType == 1;
  90. mk.console.log(" this.ifClockInDay", this.ifClockInDay);
  91. this.node_haveClockInIcon.active = this.ifClockInDay;
  92. this.node_tip.active = !this.ifClockInDay;
  93. this.node_box.active = this.curClockInDay == GameConst.maxClockInDay;
  94. }
  95. else {
  96. this.node_haveClockInIcon.active = false;
  97. this.node_nromalClockInBg.active = false;
  98. this.node_unClockInBg.active = true;
  99. this.node_reaPacket.active = this.rewardType == 1;
  100. this.node_box.active = this.rewardType == 2;
  101. }
  102. // if (this.curClockInDay < PlayerConst.clockInDay) {
  103. // //第一天情况特殊
  104. // if (PlayerConst.clockInDay == 0) {
  105. // this.node_unClockInBg.active = false;
  106. // this.node_nromalClockInBg.active = true;
  107. // this.node_nromalClockInBg.setScale(1, 1);
  108. // this.node_reaPacket.active = this.rewardType == 1;
  109. // LogUtil.log(" this.ifClockInDay", this.ifClockInDay);
  110. // this.node_haveClockInIcon.active = this.ifClockInDay;
  111. // this.node_tip.active = !this.ifClockInDay;
  112. // this.node_box.active = this.curClockInDay == GameConst.maxClockInDay;
  113. // }
  114. // else {
  115. // this.node_unClockInBg.active = false;
  116. // this.node_nromalClockInBg.active = true;
  117. // if (this.rewardType == 1) {
  118. // this.node_nromalClockInBg.setScale(1, 1);
  119. // }
  120. // else {
  121. // this.node_nromalClockInBg.setScale(0.8, 0.8);
  122. // }
  123. // this.node_reaPacket.active = this.rewardType == 1;
  124. // this.node_haveClockInIcon.active = true;
  125. // this.node_box.active = this.curClockInDay == GameConst.maxClockInDay;
  126. // }
  127. // }
  128. // else if (this.curClockInDay == (PlayerConst.clockInDay)) {
  129. // this.node_unClockInBg.active = false;
  130. // this.node_nromalClockInBg.active = true;
  131. // this.node_nromalClockInBg.setScale(1, 1);
  132. // this.node_reaPacket.active = this.rewardType == 1;
  133. // LogUtil.log(" this.ifClockInDay", this.ifClockInDay);
  134. // this.node_haveClockInIcon.active = this.ifClockInDay;
  135. // this.node_tip.active = !this.ifClockInDay;
  136. // this.node_box.active = this.curClockInDay == GameConst.maxClockInDay;
  137. // }
  138. // else {
  139. // this.node_haveClockInIcon.active = false;
  140. // this.node_nromalClockInBg.active = false;
  141. // this.node_unClockInBg.active = true;
  142. // this.node_reaPacket.active = this.rewardType == 1;
  143. // this.node_box.active = this.rewardType == 2;
  144. // }
  145. }
  146. onClick() {
  147. GameMgr.Inst.sendEvent(UIITEM_NAME.ClockInItem, `点击${this.curClockInDay}打卡Item`);
  148. if (this.curClockInDay == PlayerConst.clockInDay && this.ifClockInDay) {
  149. if (this.rewardType != null) {
  150. EffectMgr.Inst.addTip(`打卡成功,可以提现啦`);
  151. }
  152. else {
  153. EffectMgr.Inst.addTip(`继续累计打卡,领取后面红包吧`);
  154. }
  155. }
  156. else {
  157. if (this.rewardType != null) {
  158. if (this.curClockInDay == GameConst.maxClockInDay) {
  159. EffectMgr.Inst.addTip(`连续打卡${this.curClockInDay}天,领取神秘宝箱`)
  160. }
  161. else {
  162. EffectMgr.Inst.addTip(`连续打卡${this.curClockInDay}天,提现${this.rewardNum}元`)
  163. }
  164. }
  165. }
  166. }
  167. }