UISignPage.ts 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. import UIPage from "../Framework/UIPage";
  2. import Constant, { PageName, PanelName } from "../Framework/Constant";
  3. import { cocosz } from "../Framework/CocosZ";
  4. import Msg from "../Framework/Msg";
  5. import FlyCoin from "../Framework/FlyCoin";
  6. import { utils } from "../../common-plugin/Scripts/Utils";
  7. import TweenEffect from "../Framework/TweenEffect";
  8. // @ts-ignore
  9. const i18n = require('LanguageData');
  10. const { ccclass, property } = cc._decorator;
  11. const REWARD_SIGN: number[] = [500, 1000, 1500, 50, 2000, 2500, 100];
  12. class DayItem {
  13. private _index: number = -1;
  14. private _node: cc.Node = null;
  15. private _normal: cc.Node = null;
  16. private _current: cc.Node = null;
  17. private _got: cc.Node = null;
  18. private _label: cc.Label = null;
  19. constructor(index: number, node: cc.Node) {
  20. this._index = index;
  21. this._node = node;
  22. this._normal = this._node.getChildByName("st1");
  23. this._current = this._node.getChildByName("st2");
  24. this._got = this._node.getChildByName("st3");
  25. if (this._node.getChildByName("rewardLabel")) {
  26. this._label = this._node.getChildByName("rewardLabel").getComponent(cc.Label);
  27. this._label.node.scale = 0.7;
  28. this._label.node.setPosition(this._node.x, this._node.y - 60);
  29. this._label.node.setParent(this._node.parent);
  30. this._label.string = "+" + REWARD_SIGN[this._index];
  31. }
  32. }
  33. public setStatus(status: number) {
  34. if (status == 0) {
  35. this._normal.active = true;
  36. this._current.active = false;
  37. this._got.active = false;
  38. this._label.node.active = true;
  39. }
  40. else if (status == 1) {
  41. this._normal.active = false;
  42. this._current.active = true;
  43. this._got.active = false;
  44. this._label.node.active = true;
  45. }
  46. else if (status == 2) {
  47. this._normal.active = true;
  48. this._current.active = false;
  49. this._got.active = true;
  50. this._label.node.active = false;
  51. }
  52. }
  53. public update() {
  54. // 上一次领取的是第几天,从0开始
  55. let lastDayIndex: number = cocosz.dataMgr.LastDailyBonusIndex;
  56. // 超过一天, 重置一下天数
  57. if (lastDayIndex == 6) {
  58. lastDayIndex = -1;
  59. }
  60. // 上次领取的时间
  61. const lastDayTime: string = cocosz.dataMgr.LastDailyBonusTime;
  62. let canGet: boolean = false;
  63. if (new Date().toDateString() != lastDayTime && this._index == lastDayIndex + 1) {
  64. canGet = true;
  65. }
  66. // cc.log(`lastDayIndex: ${lastDayIndex} --- lastDayTime: ${lastDayTime}`);
  67. // this._got.active = false;
  68. // this._normal.active = false;
  69. // this._current.active = false;
  70. if (this._index <= lastDayIndex) {
  71. // 已经领取过了
  72. // this._got.active = true;
  73. this.setStatus(2)
  74. } else {
  75. if (canGet) {
  76. this.setStatus(1)
  77. // this._current.active = true;
  78. } else {
  79. this.setStatus(0)
  80. // this._normal.active = true;
  81. }
  82. }
  83. }
  84. }
  85. @ccclass
  86. export default class UISignPanel extends UIPage {
  87. private _mask: cc.Node = null;
  88. private _panel: cc.Node = null;
  89. private _btnGet: cc.Node = null;
  90. private _btnDouble: cc.Node = null;
  91. private _btnClose: cc.Node = null;
  92. private _day: DayItem[] = [];
  93. constructor() {
  94. super(PanelName.UISignPanel);
  95. this.isValid() && this.onLoad();
  96. }
  97. protected onLoad() {
  98. this._panel = this._page.getChildByName("Panel");
  99. this._mask = this._page.getChildByName("mask");
  100. let btnNames: string[] = ["BtnClose", "BtnDouble", "BtnGet"];
  101. for (let i = 0; i < btnNames.length; i++) {
  102. let btn: cc.Node = cc.find(btnNames[i], this._panel);
  103. if (!btn) continue
  104. btn.on(cc.Node.EventType.TOUCH_END, this._onBtnClickedHandler, this);
  105. if (btn.name == "BtnGet") {
  106. this._btnGet = btn;
  107. } else if (btn.name == "BtnDouble") {
  108. this._btnDouble = btn;
  109. this._btnDouble.active = cocosz.isADON;
  110. }
  111. else {
  112. this._btnClose = btn;
  113. }
  114. }
  115. for (let i = 0; i < 6; i++) {
  116. let dayItem: DayItem = new DayItem(i, this._panel.getChildByName("Day_" + (i + 1)));
  117. this._day.push(dayItem);
  118. }
  119. }
  120. protected onOpen() {
  121. // 上报 首页签到
  122. utils.umaEvent("gamegamesign");
  123. utils.SendEvent("页面-签到");
  124. this._initPanel();
  125. }
  126. private _initPanel() {
  127. TweenEffect.panel_open_scale(this._panel);
  128. // 缩放
  129. this._updateDayItem();
  130. }
  131. private _updateDayItem() {
  132. for (let i = 0; i < 6; i++) {
  133. this._day[i].update();
  134. }
  135. }
  136. private async _onBtnClickedHandler(event: cc.Event, data: any) {
  137. cocosz.audioMgr.playBtnEffect();
  138. switch (event.target.name) {
  139. case "BtnGet": {
  140. if (!this._canGetBonus()) {
  141. Msg.Show(i18n.t("msg.jryqd"));//今日已领取奖励
  142. return;
  143. }
  144. this._getReward(false);
  145. break;
  146. }
  147. case "BtnDouble": {
  148. if (!this._canGetBonus()) {
  149. Msg.Show(i18n.t("msg.jryqd"));//今日已领取奖励
  150. return;
  151. }
  152. utils.SendEvent("视频-双倍签到-播放")
  153. cocosz.watchAD(() => {
  154. utils.SendEvent("视频-双倍签到-成功")
  155. this._getReward(true);
  156. }, () => {
  157. utils.SendEvent("视频-双倍签到-失败")
  158. });
  159. break;
  160. }
  161. case "BtnClose": {
  162. cocosz.uiMgr.closePanel(PanelName.UISignPanel);
  163. break;
  164. }
  165. }
  166. }
  167. private _getReward(double: boolean) {
  168. if (double == false) {
  169. // 上报 普通签到
  170. utils.umaEvent("gamesignordinary");
  171. utils.SendEvent("签到-普通");
  172. } else {
  173. // 上报 双倍签到
  174. utils.umaEvent("gamedoublesign");
  175. utils.SendEvent("签到-双倍");
  176. }
  177. // 签到索引
  178. let lastDayIndex: number = cocosz.dataMgr.LastDailyBonusIndex;
  179. if (lastDayIndex == 6) {
  180. lastDayIndex = -1;
  181. }
  182. let curDayIndex = lastDayIndex + 1;
  183. // 奖励数量
  184. let count: number = REWARD_SIGN[curDayIndex];
  185. if (double) { count *= 2; }
  186. if (curDayIndex == 3 || curDayIndex == 6) {
  187. // 钻石
  188. Msg.Show(i18n.t("msg.gxhdzs") + count);
  189. cocosz.dataMgr.DiamondCount += count;
  190. // 飞金币事件
  191. setTimeout(() => {
  192. cc.game.emit(Constant.E_GAME_LOGIC, { type: Constant.E_Fly_Coin, iconName: 'diamond', frameNodeName: 'CoinLabel2' })
  193. }, 500);
  194. } else {
  195. // 金币
  196. Msg.Show(i18n.t("msg.gxhdjb") + count);
  197. cocosz.dataMgr.CoinCount += count;
  198. // 飞金币事件
  199. setTimeout(() => {
  200. cc.game.emit(Constant.E_GAME_LOGIC, { type: Constant.E_Fly_Coin, iconName: 'coin', frameNodeName: 'CoinLabel' })
  201. }, 500);
  202. }
  203. // 本地信息
  204. cocosz.dataMgr.LastDailyBonusIndex = curDayIndex;
  205. cocosz.dataMgr.LastDailyBonusTime = new Date().toDateString();
  206. // 刷新UI
  207. // this._updateDayItem();
  208. // 关闭弹窗
  209. cocosz.uiMgr.closePanel(PanelName.UISignPanel);
  210. }
  211. private _canGetBonus() {
  212. return (new Date().toDateString() != cocosz.dataMgr.LastDailyBonusTime);
  213. }
  214. }