UISign.ts 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. import GlobalManager from "../utils/GlobalManager";
  13. import JSBridgeUtils from "../utils/JSBridgeUtils";
  14. export default class UISign extends UIBase {
  15. public ui: ui_UISign;
  16. public signArr: Array<SignNormal>;
  17. public signMax: SignMax;
  18. //
  19. public curDayIndex: number = 0;
  20. public starX: number = 0;
  21. public moneyNode: MoneyNode;
  22. public constructor() {
  23. super();
  24. }
  25. protected onConstructor(): void {
  26. this.ui = ui_UISign.createInstance();
  27. this.contentPane = this.ui;
  28. this.isEject = false;
  29. //
  30. this.moneyNode = new MoneyNode(this.ui.moneyNode);
  31. this.addUIClick(this.ui.closeNode.closeBtn, this.closeSelf);
  32. //
  33. this.initSignItem();
  34. this.addUIClick(this.ui.normalBtn, this.normalGetAward);
  35. this.addUIClick(this.ui.againBtn, this.againGetAward);
  36. }
  37. public show(): void {
  38. super.show();
  39. this.ui.t0.play();
  40. this.playSecretaryIdle();
  41. this.updateSign();
  42. }
  43. initSignItem() {
  44. this.signArr = [];
  45. for (let index = 0; index < 6; index++) {
  46. let temp = new SignNormal(this.ui.myNode["day" + (index + 1)]);
  47. this.signArr.push(temp);
  48. }
  49. this.signMax = new SignMax(this.ui.myNode.day7);
  50. if (Moyu.isKs)
  51. this.ui.closeNode.closeBtn.x += 100;
  52. }
  53. updateSign() {
  54. //初始化签到状态
  55. let sameDay = xGame.common.judgeSameDay();
  56. let max = 7;
  57. this.curDayIndex = DataMgr.getSignData();
  58. //首次签到或者循环完毕后又开始新一轮签到
  59. if (!this.curDayIndex || (this.curDayIndex >= max && !sameDay)) this.curDayIndex = 0;
  60. if (!sameDay) {
  61. //未领取奖励
  62. this.ui.normalBtn.visible = true;
  63. this.ui.tipsNode.visible = false;
  64. this.ui.againBtn.visible = false;
  65. }
  66. else {
  67. //已经领取过奖励了
  68. this.ui.normalBtn.visible = false;
  69. //判断是否再次领取了奖励,并且该奖励只能是钻石或者金币
  70. let again = DataMgr.getExtraSign();
  71. let isCurrency = false;//是否是货币
  72. let index = this.curDayIndex;
  73. if (index == 0) index = 7;
  74. let award = cfgTable.signData[index].award;
  75. let num = award[0].split("-")[0];
  76. if (num == "1" || num == "2") isCurrency = true;
  77. //
  78. let showAgain = again == 0 && isCurrency;
  79. this.ui.againBtn.visible = showAgain;
  80. this.ui.tipsNode.visible = !showAgain;
  81. }
  82. //
  83. for (let index = 0; index < this.signArr.length; index++) {
  84. this.signArr[index].updateSelf(index, sameDay, this.curDayIndex);
  85. }
  86. this.signMax.updateSelf(max - 1, sameDay, this.curDayIndex);
  87. }
  88. playSecretaryIdle() {
  89. let parent = this.ui.secretary.displayObject;
  90. parent.destroyChildren();
  91. let xx = this.ui.secretary.width / 2
  92. let yy = this.ui.secretary.height;
  93. let scale = xGame.common.getSecretaryScale();
  94. let data = { x: xx, y: yy, scaleX: scale, scaleY: scale };
  95. // xGame.common.secretary.play(data, 1, true, parent);
  96. xGame.common.secretary.play(data, 0, true, parent);
  97. }
  98. closeSelf() {
  99. this.hide();
  100. }
  101. normalGetAward() {
  102. let sameDay = xGame.common.judgeSameDay();
  103. if (!sameDay) {
  104. let award = cfgTable.signData[this.curDayIndex + 1].award;
  105. let temp;
  106. let type;
  107. let num;
  108. let arr = [];
  109. for (let index = 0; index < award.length; index++) {
  110. temp = award[index].split("-");
  111. type = parseInt(temp[0]);
  112. num = parseInt(temp[1]);
  113. let awardType = new AwardType();
  114. awardType.num = num;
  115. awardType.type = type;
  116. arr.push(awardType);
  117. }
  118. xGame.common.getAward(arr, (watchVideo) => {
  119. //
  120. this.curDayIndex++;
  121. if (this.curDayIndex > 7) this.curDayIndex = 0;
  122. DataMgr.setSignData(this.curDayIndex);
  123. DataMgr.setSignTime(new Date().getTime());
  124. //
  125. if (watchVideo) {
  126. DataMgr.setExtraSign(1);
  127. Moyu.sendDataEvent("signIn1");
  128. }
  129. this.updateSign();
  130. });
  131. }
  132. }
  133. againGetAward() {
  134. Moyu.sendDataEvent("signIn2");
  135. // GlobalManager.instance.registerMethod('xxxxx',this.xxxxx);
  136. // JSBridgeUtils.instance.showRewardAd('xxxxx');
  137. console.log('zh:qjff_AD_for_uisign')
  138. if (Laya.Browser.onAndroid) {
  139. let boo = JSBridgeUtils.instance.getNetworkAvailable();
  140. if (!boo) {
  141. JSBridgeUtils.instance.showToast2("Network error, reward unavailable");
  142. return;
  143. }
  144. }
  145. if (JSBridgeUtils.instance.showRewardAd('qjff_AD_for_uisign')) {
  146. } else {
  147. console.log('zh:AD 失败,直接发放奖励')
  148. this.qjff_AD_for_uisign();
  149. }
  150. //Moyu.showVideoAd(() => {
  151. // //
  152. // //已经领取了奖励的情况
  153. // let index = this.curDayIndex;
  154. // if (index == 0) index = 7;
  155. // let award = cfgTable.signData[index].award;
  156. // let temp;
  157. // let type;
  158. // let num;
  159. // for (let index = 0; index < award.length; index++) {
  160. // temp = award[index].split("-");
  161. // type = parseInt(temp[0]);
  162. // num = parseInt(temp[1]) * 3;//三倍再次领取所有奖励
  163. // xGame.common.playObjFlyAnim(num, type);
  164. // }
  165. // //
  166. // DataMgr.setExtraSign(1);
  167. // this.updateSign();
  168. // //
  169. //}, EAdType.againSign)
  170. }
  171. public qjff_AD_for_uisign() {
  172. //已经领取了奖励的情况
  173. let index = this.curDayIndex;
  174. if (index == 0) index = 7;
  175. let award = cfgTable.signData[index].award;
  176. let temp;
  177. let type;
  178. let num;
  179. for (let index = 0; index < award.length; index++) {
  180. temp = award[index].split("-");
  181. type = parseInt(temp[0]);
  182. num = parseInt(temp[1]) * 3;//三倍再次领取所有奖励
  183. xGame.common.playObjFlyAnim(num, type);
  184. }
  185. //
  186. DataMgr.setExtraSign(1);
  187. this.updateSign();
  188. }
  189. }
  190. UISign.uiName = "UISign";