UIWelfareView.ts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import auto_welfareView from "../../../ui/uidata/Interface/auto_welfareView";
  2. import UIBase from "../../../framework/ui/UIBase";
  3. import UIHelp from "../../../framework/ui/UIHelp";
  4. import rewardDtMgr from "../../../dataManager/rewardDtMgr";
  5. import itemDtManager from "../../../dataManager/itemDtManager";
  6. import gameData from "../../../gameLogic/utrl/gameData";
  7. import gameEventManager from "../../../gameLogic/utrl/gameEventManager";
  8. import {EVENT_TYPE, ITEM_TYPE} from "../../../gameLogic/utrl/gameEnum";
  9. import UIObtainView from "./UIObtainView";
  10. import AccountModel from "../../../data/Account/AccountModel";
  11. import EventManager from "../../../framework/event/EventManager";
  12. import game = cc.game;
  13. import UIAirdropItem from "./UIAirdropItem";
  14. import UiGuideHand from "../common/uiGuideHand";
  15. import {GameEvent} from "../../../constant/constant-game";
  16. const {ccclass, menu, property} = cc._decorator;
  17. //奖励类型
  18. enum rewardType {
  19. npc = 'npc',
  20. weapon = 'weapon',
  21. gun = 'gun',
  22. bullet = 'bullet'
  23. }
  24. @ccclass
  25. @menu("UI/Interface/UIWelfareView")
  26. export default class UIWelfareView extends UIBase {
  27. ui: auto_welfareView = null;
  28. protected static prefabUrl = "Interface/welfareView";
  29. protected static className = "UIWelfareView";
  30. @property(cc.Prefab)
  31. itemPrefab: cc.Prefab = null;
  32. @property(cc.Prefab)
  33. guideHandPrefab: cc.Prefab = null;
  34. onUILoad() {
  35. this.ui = this.node.addComponent(auto_welfareView);
  36. }
  37. onShow() {
  38. const list = rewardDtMgr.getInstance().getSurvivorRewardList();
  39. for (let key in list) {
  40. const infos = list[key];
  41. for (let i = 1; i <= 4; i++) {
  42. if (infos.rewardType == rewardType.npc) {
  43. continue;
  44. }
  45. const node = cc.instantiate(this.itemPrefab);
  46. node.scale = 0.9;
  47. const id = infos[`rewardID${i}`];
  48. const itemInfo = itemDtManager.getDataByID(id);
  49. const component = node.getComponent(UIAirdropItem);
  50. if (infos.rewardType == rewardType.weapon) {
  51. component.refresh(itemInfo, 0, false)
  52. this.ui.weapon_list.addChild(node);
  53. } else if (infos.rewardType == rewardType.gun) {
  54. component.refresh(itemInfo, 1, false)
  55. this.ui.gun_list.addChild(node);
  56. } else if (infos.rewardType == rewardType.bullet) {
  57. component.refresh(itemInfo, 2, false)
  58. this.ui.bullet_list.addChild(node);
  59. }
  60. }
  61. this.guideHandler();
  62. }
  63. const curWelfare = AccountModel.getInstance().curWelfare;
  64. for (let welfare of curWelfare) {
  65. this.switchBtn(welfare, false);
  66. }
  67. }
  68. private guideHandler() {
  69. if (!GameEvent.isNeedGuideVideo){
  70. return;
  71. }
  72. if (AccountModel.getInstance().curWelfare.length != 0){
  73. return
  74. }
  75. if (AccountModel.getInstance().is_new == 1) {
  76. const node = cc.instantiate(this.guideHandPrefab);
  77. node.getComponent(UiGuideHand).init(this.ui.npc);
  78. this.node.addChild(node);
  79. }
  80. }
  81. onHide() {
  82. }
  83. onStart() {
  84. }
  85. clickBtn(event: any, type: string) {
  86. console.log('zh:clickBtn ' + type);
  87. let result = null;
  88. const infos = rewardDtMgr.getInstance().getSurvivorRewardList();
  89. for (let key in infos) {
  90. const info = infos[key];
  91. if (info.rewardType == type) {
  92. result = info;
  93. }
  94. }
  95. if (!result) {
  96. return;
  97. }
  98. this.showTag(type);
  99. let self = this
  100. const params = {
  101. payType: zjSdk?.TYPE.VIDEO,
  102. success() {
  103. self.doGet(result, type);
  104. },
  105. fail() {
  106. // self.doGet(result, type);
  107. }
  108. };
  109. zjSdk?.doPay(params);
  110. }
  111. showTag(type){
  112. if (type == rewardType.npc) {
  113. zjSdk?.sendEvent('点击幸存者')
  114. }
  115. if (type == rewardType.bullet) {
  116. zjSdk?.sendEvent('点击子弹资源')
  117. }
  118. if (type == rewardType.weapon) {
  119. zjSdk?.sendEvent('点击武器资源')
  120. }
  121. if (type == rewardType.gun) {
  122. zjSdk?.sendEvent('点击枪械资源')
  123. }
  124. }
  125. private doGet(result, type: string) {
  126. const arr = this.parseArr(result);
  127. let nums = [];
  128. for (let id of arr) {
  129. const data = itemDtManager.getDataByID(id);
  130. if (type == rewardType.npc) {
  131. zjSdk?.sendEvent('幸存者成功获取')
  132. gameEventManager.emit(EVENT_TYPE.ADD_HERO_BY_ID, id);
  133. nums.push(1);
  134. }
  135. if (type == rewardType.bullet) {
  136. zjSdk?.sendEvent('子弹资源成功获取')
  137. gameData.curBulletNum += data.value;
  138. nums.push(data.value);
  139. }
  140. if (type == rewardType.weapon) {
  141. zjSdk?.sendEvent('武器资源成功获取')
  142. let damage = itemDtManager.getDataByID(data.id).value;
  143. gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, true);
  144. nums.push(1);
  145. }
  146. if (type == rewardType.gun) {
  147. zjSdk?.sendEvent('枪械资源成功获取')
  148. let damage = itemDtManager.getDataByID(data.id).value;
  149. gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, false);
  150. nums.push(1);
  151. }
  152. }
  153. UIHelp.ShowUI(UIObtainView, null, {ids: arr, nums: nums, isHero: type == rewardType.npc})
  154. // 关闭按钮
  155. const curWelfare = AccountModel.getInstance().curWelfare;
  156. curWelfare.push(type);
  157. AccountModel.getInstance().curWelfare = curWelfare;
  158. this.switchBtn(type, false);
  159. }
  160. private switchBtn(type: string, flag) {
  161. this.ui[`${type}`].getComponent(cc.Button).interactable = flag
  162. }
  163. private parseArr(result) {
  164. let arr = [];
  165. [1, 2, 3, 4].forEach(value => {
  166. const id = result[`rewardID${value}`];
  167. arr.push(id)
  168. })
  169. return arr;
  170. }
  171. clickClose() {
  172. gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS, false);
  173. this.onClose();
  174. }
  175. onClose() {
  176. UIHelp.CloseUI(UIWelfareView);
  177. }
  178. }