UIWelfareView.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. import AESUtil from "../../../AESUtil"
  17. import ATSDK from "../../../AnyThinkAds/ATJSSDK";
  18. import ATRewardedVideoSDK from "../../../AnyThinkAds/ATRewardedVideoJSSDK";
  19. import AAJS2 from "../../../ATAndroidJS2";
  20. import GlobalManager from '../../../GlobalManager';
  21. const {ccclass, menu, property} = cc._decorator;
  22. //奖励类型
  23. enum rewardType {
  24. npc = 'npc',
  25. weapon = 'weapon',
  26. gun = 'gun',
  27. bullet = 'bullet'
  28. }
  29. @ccclass
  30. @menu("UI/Interface/UIWelfareView")
  31. export default class UIWelfareView extends UIBase {
  32. ui: auto_welfareView = null;
  33. protected static prefabUrl = "Interface/welfareView";
  34. protected static className = "UIWelfareView";
  35. @property(cc.Prefab)
  36. itemPrefab: cc.Prefab = null;
  37. @property(cc.Prefab)
  38. guideHandPrefab: cc.Prefab = null;
  39. onUILoad() {
  40. this.ui = this.node.addComponent(auto_welfareView);
  41. this.initAdForPage();
  42. }
  43. initAdForPage() {
  44. if (cc.sys.os === cc.sys.OS_ANDROID) {
  45. let deviceId = AAJS2.getDeviceUserId();
  46. console.log("zh:checkstatus:", ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId()));
  47. var setting = {};
  48. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  49. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  50. }
  51. }
  52. onShow() {
  53. const list = rewardDtMgr.getInstance().getSurvivorRewardList();
  54. for (let key in list) {
  55. const infos = list[key];
  56. for (let i = 1; i <= 4; i++) {
  57. if (infos.rewardType == rewardType.npc) {
  58. continue;
  59. }
  60. const node = cc.instantiate(this.itemPrefab);
  61. node.scale = 0.9;
  62. const id = infos[`rewardID${i}`];
  63. const itemInfo = itemDtManager.getDataByID(id);
  64. const component = node.getComponent(UIAirdropItem);
  65. if (infos.rewardType == rewardType.weapon) {
  66. component.refresh(itemInfo, 0, false)
  67. this.ui.weapon_list.addChild(node);
  68. } else if (infos.rewardType == rewardType.gun) {
  69. component.refresh(itemInfo, 1, false)
  70. this.ui.gun_list.addChild(node);
  71. } else if (infos.rewardType == rewardType.bullet) {
  72. component.refresh(itemInfo, 2, false)
  73. this.ui.bullet_list.addChild(node);
  74. }
  75. }
  76. this.guideHandler();
  77. }
  78. const curWelfare = AccountModel.getInstance().curWelfare;
  79. for (let welfare of curWelfare) {
  80. this.switchBtn(welfare, false);
  81. }
  82. }
  83. private guideHandler() {
  84. if (!GameEvent.isNeedGuideVideo){
  85. return;
  86. }
  87. if (AccountModel.getInstance().curWelfare.length != 0){
  88. return
  89. }
  90. if (AccountModel.getInstance().is_new == 1) {
  91. const node = cc.instantiate(this.guideHandPrefab);
  92. node.getComponent(UiGuideHand).init(this.ui.npc);
  93. this.node.addChild(node);
  94. }
  95. }
  96. onHide() {
  97. }
  98. onStart() {
  99. }
  100. clickBtn(event: any, type: string) {
  101. console.log('zh:clickBtn ' + type);
  102. let result = null;
  103. const infos = rewardDtMgr.getInstance().getSurvivorRewardList();
  104. for (let key in infos) {
  105. const info = infos[key];
  106. if (info.rewardType == type) {
  107. result = info;
  108. }
  109. }
  110. if (!result) {
  111. return;
  112. }
  113. this.showTag(type);
  114. console.log('zh:clickBtn 2' );
  115. let self = this
  116. if(2>1){//zh:diy
  117. if (cc.sys.os === cc.sys.OS_ANDROID) {
  118. // 注册方法 , this.ClickClose.bind(this));
  119. // result, type: string
  120. GlobalManager.getInstance().registerMethod('doGetForAdEvent', (result:any,type: string) => {
  121. //console.log();
  122. });
  123. GlobalManager.getInstance().registerMethod('doGetForAdEvent', this.doGetForAdEvent.bind(this));
  124. let adKey = "zh_ad_type"
  125. if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) {
  126. cc.sys.localStorage.setItem(adKey, 'doGetForAdEvent');
  127. let monthParams = {result,type};
  128. cc.sys.localStorage.setItem('doGetForAdEvent_monthParams', JSON.stringify(monthParams));
  129. console.log('zh:AD ready for idx2')
  130. ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
  131. } else {
  132. console.log('zh:AD not ready for idx2')
  133. self.doGetForAdEvent(result, type);
  134. }
  135. }
  136. return;
  137. }
  138. //下面是原始的代码
  139. const params = {
  140. payType: zjSdk?.TYPE.VIDEO,
  141. success() {
  142. self.doGet(result, type);
  143. },
  144. fail() {
  145. // self.doGet(result, type);
  146. }
  147. };
  148. console.log('zh:clickBtn 3' );
  149. zjSdk?.doPay(params);
  150. }
  151. showTag(type){
  152. if (type == rewardType.npc) {
  153. zjSdk?.sendEvent('点击幸存者')
  154. }
  155. if (type == rewardType.bullet) {
  156. zjSdk?.sendEvent('点击子弹资源')
  157. }
  158. if (type == rewardType.weapon) {
  159. zjSdk?.sendEvent('点击武器资源')
  160. }
  161. if (type == rewardType.gun) {
  162. zjSdk?.sendEvent('点击枪械资源')
  163. }
  164. }
  165. private doGet(result, type: string) {
  166. const arr = this.parseArr(result);
  167. let nums = [];
  168. for (let id of arr) {
  169. const data = itemDtManager.getDataByID(id);
  170. if (type == rewardType.npc) {
  171. zjSdk?.sendEvent('幸存者成功获取')
  172. gameEventManager.emit(EVENT_TYPE.ADD_HERO_BY_ID, id);
  173. nums.push(1);
  174. }
  175. if (type == rewardType.bullet) {
  176. zjSdk?.sendEvent('子弹资源成功获取')
  177. gameData.curBulletNum += data.value;
  178. nums.push(data.value);
  179. }
  180. if (type == rewardType.weapon) {
  181. zjSdk?.sendEvent('武器资源成功获取')
  182. let damage = itemDtManager.getDataByID(data.id).value;
  183. gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, true);
  184. nums.push(1);
  185. }
  186. if (type == rewardType.gun) {
  187. zjSdk?.sendEvent('枪械资源成功获取')
  188. let damage = itemDtManager.getDataByID(data.id).value;
  189. gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, false);
  190. nums.push(1);
  191. }
  192. }
  193. UIHelp.ShowUI(UIObtainView, null, {ids: arr, nums: nums, isHero: type == rewardType.npc})
  194. // 关闭按钮
  195. const curWelfare = AccountModel.getInstance().curWelfare;
  196. curWelfare.push(type);
  197. AccountModel.getInstance().curWelfare = curWelfare;
  198. this.switchBtn(type, false);
  199. }
  200. /**
  201. * zh:diy
  202. * @param result
  203. * @param type
  204. */
  205. public doGetForAdEvent(result, type: string) {
  206. console.log('zh:doGetForAdEvent 被触发1 ' + result);
  207. console.log('zh:doGetForAdEvent 被触发2 ' + type);
  208. const arr = this.parseArr(result);
  209. let nums = [];
  210. for (let id of arr) {
  211. const data = itemDtManager.getDataByID(id);
  212. if (type == rewardType.npc) {
  213. zjSdk?.sendEvent('幸存者成功获取')
  214. gameEventManager.emit(EVENT_TYPE.ADD_HERO_BY_ID, id);
  215. nums.push(1);
  216. }
  217. if (type == rewardType.bullet) {
  218. zjSdk?.sendEvent('子弹资源成功获取')
  219. gameData.curBulletNum += data.value;
  220. nums.push(data.value);
  221. }
  222. if (type == rewardType.weapon) {
  223. zjSdk?.sendEvent('武器资源成功获取')
  224. let damage = itemDtManager.getDataByID(data.id).value;
  225. gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, true);
  226. nums.push(1);
  227. }
  228. if (type == rewardType.gun) {
  229. zjSdk?.sendEvent('枪械资源成功获取')
  230. let damage = itemDtManager.getDataByID(data.id).value;
  231. gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, false);
  232. nums.push(1);
  233. }
  234. }
  235. UIHelp.ShowUI(UIObtainView, null, {ids: arr, nums: nums, isHero: type == rewardType.npc})
  236. // 关闭按钮
  237. const curWelfare = AccountModel.getInstance().curWelfare;
  238. curWelfare.push(type);
  239. AccountModel.getInstance().curWelfare = curWelfare;
  240. this.switchBtn(type, false);
  241. }
  242. private switchBtn(type: string, flag) {
  243. this.ui[`${type}`].getComponent(cc.Button).interactable = flag
  244. }
  245. private parseArr(result) {
  246. let arr = [];
  247. [1, 2, 3, 4].forEach(value => {
  248. const id = result[`rewardID${value}`];
  249. arr.push(id)
  250. })
  251. return arr;
  252. }
  253. clickClose() {
  254. gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS, false);
  255. this.onClose();
  256. }
  257. onClose() {
  258. UIHelp.CloseUI(UIWelfareView);
  259. }
  260. }