UITimePage.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import UIPage from "../Framework/UIPage";
  2. import { PanelName } from "../Framework/Constant";
  3. import { cocosz } from "../Framework/CocosZ";
  4. import { utils } from "../../common-plugin/Scripts/Utils";
  5. import TweenEffect from "../Framework/TweenEffect";
  6. import GameDate from "../Game/gameDate";
  7. const { ccclass, property } = cc._decorator;
  8. class ItemTime {
  9. private _id: number = 0;
  10. private _node: cc.Node = null;
  11. private _info: { time: number, coinNum: number, diamondNum: number };
  12. private _txt_zxsc: cc.Node = null;
  13. private _txt_ylq: cc.Node = null;
  14. private _btn: cc.Node = null;
  15. private _label_coin: cc.Label = null;
  16. private _label_diamond: cc.Label = null;
  17. private _label_time: cc.Label = null;
  18. constructor(i, n: cc.Node) {
  19. this._id = i;
  20. this._node = n;
  21. this._info = GameDate.TimeReward[i];
  22. this._txt_zxsc = this._node.getChildByName("txt_zxsc");
  23. this._txt_ylq = this._node.getChildByName("txt_ylq");
  24. this._btn = this._node.getChildByName("btn");
  25. this._btn.on(cc.Node.EventType.TOUCH_END, this.click, this);
  26. this._label_coin = this._node.getChildByName("label_coin").getComponent(cc.Label);
  27. this._label_coin.string = this._info.coinNum + "";
  28. this._label_diamond = this._node.getChildByName("label_diamond").getComponent(cc.Label);
  29. this._label_diamond.string = this._info.diamondNum + "";
  30. this._label_time = this._node.getChildByName("label_time").getComponent(cc.Label);
  31. this._label_time.string = cocosz.StoHMS(this._info.time);
  32. }
  33. click() {
  34. // 领取奖励
  35. let arrRecieve = cocosz.dataMgr.receiveToday;
  36. if (arrRecieve[this._id] == 0) {
  37. cocosz.audioMgr.playBtnEffect();
  38. arrRecieve[this._id] = 1;
  39. cocosz.dataMgr.receiveToday = arrRecieve;
  40. this.update();
  41. cocosz.dataMgr.CoinCount += this._info.coinNum;
  42. cocosz.dataMgr.DiamondCount += this._info.diamondNum;
  43. }
  44. }
  45. update() {
  46. // 时间达到
  47. if (cocosz.dataMgr.OnlineToday >= this._info.time) {
  48. let arrRecieve = cocosz.dataMgr.receiveToday;
  49. // 已领取
  50. if (arrRecieve[this._id]) {
  51. this._btn.active = this._txt_zxsc.active = this._label_time.node.active = false;
  52. this._txt_ylq.active = true;
  53. }
  54. // 待领取
  55. else {
  56. this._txt_ylq.active = this._txt_zxsc.active = this._label_time.node.active = false;
  57. this._btn.active = true;
  58. }
  59. }
  60. // 时间未达到
  61. else {
  62. this._txt_ylq.active = this._btn.active = false;
  63. this._txt_zxsc.active = this._label_time.node.active = true;
  64. }
  65. }
  66. }
  67. /**
  68. * 皮肤试用面板
  69. */
  70. @ccclass
  71. export default class UITimePanel extends UIPage {
  72. private mask: cc.Node = null;
  73. private panel: cc.Node = null;
  74. private label_online: cc.Label = null;
  75. private itemList: ItemTime[] = [];
  76. constructor() {
  77. super(PanelName.UITimePanel);
  78. this.isValid() && this.onLoad();
  79. }
  80. protected onLoad() {
  81. this.mask = this._page.getChildByName("mask");
  82. this.panel = this._page.getChildByName("panel");
  83. // 按钮
  84. let btnNames: string[] = ["BtnBack"];
  85. for (let i = 0; i < btnNames.length; i++) {
  86. let btn: cc.Node = cc.find(btnNames[i], this.panel);
  87. if (btn) {
  88. btn.on(cc.Node.EventType.TOUCH_END, this._onBtnClickedHandler, this);
  89. }
  90. }
  91. // 在线时间
  92. this.label_online = this.panel.getChildByName("label_online").getComponent(cc.Label);
  93. }
  94. protected onOpen() {
  95. utils.SendEvent("页面-在线奖励");
  96. this._initPanel();
  97. }
  98. protected onClose(): void { }
  99. private _initPanel() {
  100. TweenEffect.panel_mask_opacity(this.mask)
  101. TweenEffect.panel_open_moveY(this.panel);
  102. // 列表
  103. for (let i = 0; i < 5; i++) {
  104. let n = this.panel.getChildByName("item" + i);
  105. if (n) {
  106. let item = new ItemTime(i, n);
  107. this.itemList.push(item);
  108. }
  109. }
  110. cc.tween(this._page)
  111. .call(() => { this.updateTime(); })
  112. .delay(1)
  113. .union()
  114. .repeatForever()
  115. .start();
  116. }
  117. updateTime() {
  118. // 显示在线时间
  119. this.label_online.string = cocosz.StoHMS(cocosz.dataMgr.OnlineToday);
  120. // 更新列表
  121. this.itemList.forEach(v => {
  122. v.update();
  123. })
  124. }
  125. /**
  126. * 所有按钮点击事件
  127. * @param event
  128. * @param data
  129. */
  130. private async _onBtnClickedHandler(event: cc.Event, data: any) {
  131. cocosz.audioMgr.playBtnEffect();
  132. switch (event.target.name) {
  133. case "BtnBack": {
  134. TweenEffect.panel_close_moveY(this.panel, () => {
  135. cocosz.uiMgr.closePanel(PanelName.UITimePanel);
  136. });
  137. break;
  138. }
  139. }
  140. }
  141. }