UISign.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import DataMgr from "../data/DataMgr";
  2. import { AwardType, EAdType } from "../data/Define";
  3. import UIBase from "../fgui/core/UIBase";
  4. import ui_SignNormal from "../fgui/res/game/ui_SignNormal";
  5. import ui_UISign from "../fgui/res/game/ui_UISign";
  6. import PlatMgr from "../game/PlatMgr";
  7. import Common from "../utils/Common";
  8. import { xGame } from "../xGame";
  9. import MoneyNode from "./item/MoneyNode";
  10. import SignMax from "./item/SignMax";
  11. import SignNormal from "./item/SignNormal";
  12. export default class UISign extends UIBase {
  13. public ui: ui_UISign;
  14. public signArr: Array<SignNormal>;
  15. public signMax: SignMax;
  16. //
  17. public curDayIndex: number = 0;
  18. public starX: number = 0;
  19. public moneyNode: MoneyNode;
  20. public constructor() {
  21. super();
  22. }
  23. protected onConstructor(): void {
  24. this.ui = ui_UISign.createInstance();
  25. this.contentPane = this.ui;
  26. this.isEject = false;
  27. //
  28. this.moneyNode = new MoneyNode(this.ui.moneyNode);
  29. this.addUIClick(this.ui.closeNode.closeBtn, this.closeSelf);
  30. //
  31. this.initSignItem();
  32. this.addUIClick(this.ui.normalBtn, this.normalGetAward);
  33. this.addUIClick(this.ui.againBtn, this.againGetAward);
  34. }
  35. public show(): void {
  36. super.show();
  37. this.ui.t0.play();
  38. this.playSecretaryIdle();
  39. this.updateSign();
  40. }
  41. initSignItem() {
  42. this.signArr = [];
  43. for (let index = 0; index < 6; index++) {
  44. let temp = new SignNormal(this.ui.myNode["day" + (index + 1)]);
  45. this.signArr.push(temp);
  46. }
  47. this.signMax = new SignMax(this.ui.myNode.day7);
  48. if (Moyu.isKs)
  49. this.ui.closeNode.closeBtn.x += 100;
  50. }
  51. updateSign() {
  52. //初始化签到状态
  53. let sameDay = xGame.common.judgeSameDay();
  54. let max = 7;
  55. this.curDayIndex = DataMgr.getSignData();
  56. //首次签到或者循环完毕后又开始新一轮签到
  57. if (!this.curDayIndex || (this.curDayIndex >= max && !sameDay)) this.curDayIndex = 0;
  58. if (!sameDay) {
  59. //未领取奖励
  60. this.ui.normalBtn.visible = true;
  61. this.ui.tipsNode.visible = false;
  62. this.ui.againBtn.visible = false;
  63. }
  64. else {
  65. //已经领取过奖励了
  66. this.ui.normalBtn.visible = false;
  67. //判断是否再次领取了奖励,并且该奖励只能是钻石或者金币
  68. let again = DataMgr.getExtraSign();
  69. let isCurrency = false;//是否是货币
  70. let index = this.curDayIndex;
  71. if (index == 0) index = 7;
  72. let award = cfgTable.signData[index].award;
  73. let num = award[0].split("-")[0];
  74. if (num == "1" || num == "2") isCurrency = true;
  75. //
  76. let showAgain = again == 0 && isCurrency;
  77. this.ui.againBtn.visible = showAgain;
  78. this.ui.tipsNode.visible = !showAgain;
  79. }
  80. //
  81. for (let index = 0; index < this.signArr.length; index++) {
  82. this.signArr[index].updateSelf(index, sameDay, this.curDayIndex);
  83. }
  84. this.signMax.updateSelf(max - 1, sameDay, this.curDayIndex);
  85. }
  86. playSecretaryIdle() {
  87. let parent = this.ui.secretary.displayObject;
  88. parent.destroyChildren();
  89. let xx = this.ui.secretary.width / 2
  90. let yy = this.ui.secretary.height;
  91. let scale = xGame.common.getSecretaryScale();
  92. let data = { x: xx, y: yy, scaleX: scale, scaleY: scale };
  93. // xGame.common.secretary.play(data, 1, true, parent);
  94. xGame.common.secretary.play(data, 0, true, parent);
  95. }
  96. closeSelf() {
  97. this.hide();
  98. }
  99. normalGetAward() {
  100. let sameDay = xGame.common.judgeSameDay();
  101. if (!sameDay) {
  102. let award = cfgTable.signData[this.curDayIndex + 1].award;
  103. let temp;
  104. let type;
  105. let num;
  106. let arr = [];
  107. for (let index = 0; index < award.length; index++) {
  108. temp = award[index].split("-");
  109. type = parseInt(temp[0]);
  110. num = parseInt(temp[1]);
  111. let awardType = new AwardType();
  112. awardType.num = num;
  113. awardType.type = type;
  114. arr.push(awardType);
  115. }
  116. xGame.common.getAward(arr, (watchVideo) => {
  117. //
  118. this.curDayIndex++;
  119. if (this.curDayIndex > 7) this.curDayIndex = 0;
  120. DataMgr.setSignData(this.curDayIndex);
  121. DataMgr.setSignTime(new Date().getTime());
  122. //
  123. if (watchVideo) {
  124. DataMgr.setExtraSign(1);
  125. Moyu.sendDataEvent("signIn1");
  126. }
  127. this.updateSign();
  128. });
  129. }
  130. }
  131. againGetAward() {
  132. Moyu.sendDataEvent("signIn2");
  133. Moyu.showVideoAd(() => {
  134. //
  135. //已经领取了奖励的情况
  136. let index = this.curDayIndex;
  137. if (index == 0) index = 7;
  138. let award = cfgTable.signData[index].award;
  139. let temp;
  140. let type;
  141. let num;
  142. for (let index = 0; index < award.length; index++) {
  143. temp = award[index].split("-");
  144. type = parseInt(temp[0]);
  145. num = parseInt(temp[1]) * 3;//三倍再次领取所有奖励
  146. xGame.common.playObjFlyAnim(num, type);
  147. }
  148. //
  149. DataMgr.setExtraSign(1);
  150. this.updateSign();
  151. //
  152. }, EAdType.againSign)
  153. }
  154. }
  155. UISign.uiName = "UISign";