UISignView.ts 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. public refreshForAdEveventForQianDaoAdEnd() {
  88. this.canSign = false;
  89. this.times = AccountModel.singleInstance.sign_times;
  90. this.timeStamp = AccountModel.singleInstance.sign_timestamp;
  91. // 没有时间戳
  92. if (!this.timeStamp) {
  93. this.canSign = true;
  94. } else if (new Date(this.timeStamp).getDate() != new Date().getDate()) {
  95. this.canSign = true;
  96. }
  97. //签完不要再签了
  98. if (this.times == 7) {
  99. this.canSign = false;
  100. this.ui.all_comp.active = true;
  101. }
  102. const doneFrame = this.ui.done.getComponent(cc.Sprite).spriteFrame;
  103. for (let i = 1; i <= 7; i++) {
  104. this.ui[`singleNode${i}`].getChildByName('comp').active = i < this.times + 1;
  105. if (this.ui[`singleNode${i}`].getChildByName('comp').active) {
  106. this.ui[`singleNode${i}`].getChildByName(`day${i}`).getComponent(cc.Sprite).spriteFrame = doneFrame;
  107. }
  108. this.ui[`singleNode${i}`].getChildByName('tip').active = false;
  109. this.ui[`singleNode${i}`].getChildByName('receive').active = false;
  110. this.ui[`singleNode${i}`].getChildByName('aureole').active = false;
  111. }
  112. if (this.canSign) {
  113. this.ui[`singleNode${this.times + 1}`].getChildByName('tip').active = true;
  114. this.ui[`singleNode${this.times + 1}`].getChildByName('receive').active = true;
  115. this.ui[`singleNode${this.times + 1}`].getChildByName('aureole').active = true;
  116. }
  117. }
  118. onHide() {
  119. }
  120. onStart() {
  121. }
  122. clickItem(event: any, type: string) {
  123. console.log('zh: clickItem 签到clickItem type=',type,'event='+event);
  124. const day = parseInt(type);
  125. if (this.canSign && day == this.times + 1) {
  126. this.doSign(day);
  127. }
  128. }
  129. doSign(day: number) {
  130. gameEventManager.emit(EVENT_TYPE.OFF_SIGN_TIP)
  131. const list = rewardDtMgr.getInstance().getSignRewardList();
  132. const info = list[this.times + 1];
  133. const itemID = info.itemID;
  134. const itemNum = info.itemNum;
  135. let itemArr = [];
  136. let numArr = [];
  137. if (typeof itemID == 'number') {
  138. itemArr.push(itemID);
  139. numArr.push(itemNum);
  140. } else {
  141. itemArr = itemID.split(',');
  142. numArr = info.itemNum.split(',');
  143. }
  144. //处理数量
  145. itemArr.forEach((value, index) => {
  146. value = parseInt(value);
  147. const data = itemDtManager.getDataByID(value);
  148. if (this.checkNeedMultiply(value)) {
  149. numArr[index] *= data.value;
  150. }
  151. })
  152. //分给玩家
  153. itemArr.forEach((value, index) => {
  154. const data = itemDtManager.getDataByID(value);
  155. let damage: number = 0;
  156. // (食物1,药品2,子弹3,近战武器4, 远程武器5)
  157. switch (data.type) {
  158. case 1:
  159. gameData.curPowerNum += numArr[index];
  160. break;
  161. case 2:
  162. break;
  163. case 3:
  164. gameData.curBulletNum += numArr[index];
  165. break;
  166. case 4:
  167. for (let i = 0; i < numArr[index]; i++) {
  168. damage = itemDtManager.getDataByID(data.id).value;
  169. gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, true);
  170. }
  171. break;
  172. case 5:
  173. for (let i = 0; i < numArr[index]; i++) {
  174. damage = itemDtManager.getDataByID(data.id).value;
  175. gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, false);
  176. }
  177. break;
  178. }
  179. });
  180. let modelIds = [];
  181. if (info.modelID != 0) {
  182. const fixedRoleIds = AccountModel.singleInstance.fixed_role_ids;
  183. fixedRoleIds.push(info.modelID)
  184. AccountModel.singleInstance.fixed_role_ids = fixedRoleIds;
  185. gameEventManager.emit(EVENT_TYPE.ADD_HERO_BY_ID, info.modelID);
  186. modelIds.push(info.modelID);
  187. }
  188. UIHelp.ShowUI(UIObtainView, null, {ids: itemArr, nums: numArr, modelIds: modelIds, type: 'sign'});
  189. AccountModel.singleInstance.sign_times++;
  190. AccountModel.singleInstance.sign_timestamp = Utils.getTimeStamp(true);
  191. this.refresh();
  192. }
  193. clickClose() {
  194. gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS, false);
  195. this.onClose();
  196. }
  197. onClose() {
  198. EventManager.emit(EVENT_TYPE.closeSign);
  199. UIHelp.CloseUI(UISignView);
  200. }
  201. }