UISignView.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import auto_signView from "../../../ui/uidata/Interface/auto_signView";
  2. import UIBase from "../../../framework/ui/UIBase";
  3. import UIHelp from "../../../framework/ui/UIHelp";
  4. import Utils from "../../../framework/utils/utils";
  5. import EventManager from "../../../framework/event/EventManager";
  6. import {EVENT_TYPE} from "../../../gameLogic/utrl/gameEnum";
  7. import gameEventManager from "../../../gameLogic/utrl/gameEventManager";
  8. import AccountModel from "../../../data/Account/AccountModel";
  9. import UIObtainView from "./UIObtainView";
  10. import rewardDtMgr from "../../../dataManager/rewardDtMgr";
  11. import value = cc.js.value;
  12. import itemDtManager from "../../../dataManager/itemDtManager";
  13. import gameData from "../../../gameLogic/utrl/gameData";
  14. import game = cc.game;
  15. import UiGuideHand from "../common/uiGuideHand";
  16. import SignUtil from "../../../framework/utils/signUtil";
  17. const {ccclass, menu, property} = cc._decorator;
  18. const wp_reward = 48;
  19. const role_reward = 51;
  20. @ccclass
  21. @menu("UI/Interface/UISignView")
  22. export default class UISignView extends UIBase {
  23. ui: auto_signView = null;
  24. protected static prefabUrl = "Interface/signView";
  25. protected static className = "UISignView";
  26. @property(cc.Prefab)
  27. guideHandPrefab: cc.Prefab = null;
  28. onUILoad() {
  29. this.ui = this.node.addComponent(auto_signView);
  30. }
  31. private times = 0;
  32. private timeStamp = 0;
  33. private canSign = false;
  34. onShow() {
  35. this.refresh();
  36. this.guideHandler();
  37. }
  38. private guideHandler() {
  39. if (!SignUtil.canSign()){
  40. return;
  41. }
  42. if (AccountModel.getInstance().is_new == 1) {
  43. this.scheduleOnce(() => {
  44. if (!this.guideHandPrefab) {
  45. return;
  46. }
  47. const node = cc.instantiate(this.guideHandPrefab);
  48. node.getComponent(UiGuideHand).init(this.ui[`singleNode${1}`]);
  49. this.node.addChild(node);
  50. }, 0)
  51. }
  52. }
  53. checkNeedMultiply(id: number) {
  54. return id >= 1 && id <= 12;
  55. }
  56. private refresh() {
  57. this.canSign = false;
  58. this.times = AccountModel.singleInstance.sign_times;
  59. this.timeStamp = AccountModel.singleInstance.sign_timestamp;
  60. // 没有时间戳
  61. if (!this.timeStamp) {
  62. this.canSign = true;
  63. } else if (new Date(this.timeStamp).getDate() != new Date().getDate()) {
  64. this.canSign = true;
  65. }
  66. //签完不要再签了
  67. if (this.times == 7) {
  68. this.canSign = false;
  69. this.ui.all_comp.active = true;
  70. }
  71. const doneFrame = this.ui.done.getComponent(cc.Sprite).spriteFrame;
  72. for (let i = 1; i <= 7; i++) {
  73. this.ui[`singleNode${i}`].getChildByName('comp').active = i < this.times + 1;
  74. if (this.ui[`singleNode${i}`].getChildByName('comp').active) {
  75. this.ui[`singleNode${i}`].getChildByName(`day${i}`).getComponent(cc.Sprite).spriteFrame = doneFrame;
  76. }
  77. this.ui[`singleNode${i}`].getChildByName('tip').active = false;
  78. this.ui[`singleNode${i}`].getChildByName('receive').active = false;
  79. this.ui[`singleNode${i}`].getChildByName('aureole').active = false;
  80. }
  81. if (this.canSign) {
  82. this.ui[`singleNode${this.times + 1}`].getChildByName('tip').active = true;
  83. this.ui[`singleNode${this.times + 1}`].getChildByName('receive').active = true;
  84. this.ui[`singleNode${this.times + 1}`].getChildByName('aureole').active = true;
  85. }
  86. }
  87. onHide() {
  88. }
  89. onStart() {
  90. }
  91. clickItem(event: any, type: string) {
  92. const day = parseInt(type);
  93. if (this.canSign && day == this.times + 1) {
  94. this.doSign(day);
  95. }
  96. }
  97. doSign(day: number) {
  98. gameEventManager.emit(EVENT_TYPE.OFF_SIGN_TIP)
  99. const list = rewardDtMgr.getInstance().getSignRewardList();
  100. const info = list[this.times + 1];
  101. const itemID = info.itemID;
  102. const itemNum = info.itemNum;
  103. let itemArr = [];
  104. let numArr = [];
  105. if (typeof itemID == 'number') {
  106. itemArr.push(itemID);
  107. numArr.push(itemNum);
  108. } else {
  109. itemArr = itemID.split(',');
  110. numArr = info.itemNum.split(',');
  111. }
  112. //处理数量
  113. itemArr.forEach((value, index) => {
  114. value = parseInt(value);
  115. const data = itemDtManager.getDataByID(value);
  116. if (this.checkNeedMultiply(value)) {
  117. numArr[index] *= data.value;
  118. }
  119. })
  120. //分给玩家
  121. itemArr.forEach((value, index) => {
  122. const data = itemDtManager.getDataByID(value);
  123. let damage: number = 0;
  124. // (食物1,药品2,子弹3,近战武器4, 远程武器5)
  125. switch (data.type) {
  126. case 1:
  127. gameData.curPowerNum += numArr[index];
  128. break;
  129. case 2:
  130. break;
  131. case 3:
  132. gameData.curBulletNum += numArr[index];
  133. break;
  134. case 4:
  135. for (let i = 0; i < numArr[index]; i++) {
  136. damage = itemDtManager.getDataByID(data.id).value;
  137. gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, true);
  138. }
  139. break;
  140. case 5:
  141. for (let i = 0; i < numArr[index]; i++) {
  142. damage = itemDtManager.getDataByID(data.id).value;
  143. gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, false);
  144. }
  145. break;
  146. }
  147. });
  148. let modelIds = [];
  149. if (info.modelID != 0) {
  150. const fixedRoleIds = AccountModel.singleInstance.fixed_role_ids;
  151. fixedRoleIds.push(info.modelID)
  152. AccountModel.singleInstance.fixed_role_ids = fixedRoleIds;
  153. gameEventManager.emit(EVENT_TYPE.ADD_HERO_BY_ID, info.modelID);
  154. modelIds.push(info.modelID);
  155. }
  156. UIHelp.ShowUI(UIObtainView, null, {ids: itemArr, nums: numArr, modelIds: modelIds, type: 'sign'});
  157. AccountModel.singleInstance.sign_times++;
  158. AccountModel.singleInstance.sign_timestamp = Utils.getTimeStamp(true);
  159. this.refresh();
  160. }
  161. clickClose() {
  162. gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS, false);
  163. this.onClose();
  164. }
  165. onClose() {
  166. EventManager.emit(EVENT_TYPE.closeSign);
  167. UIHelp.CloseUI(UISignView);
  168. }
  169. }