UIWelfareView.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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. }else{
  136. self.doGetForAdEvent(result, type);
  137. }
  138. return;
  139. }
  140. //下面是原始的代码
  141. const params = {
  142. payType: zjSdk?.TYPE.VIDEO,
  143. success() {
  144. self.doGet(result, type);
  145. },
  146. fail() {
  147. // self.doGet(result, type);
  148. }
  149. };
  150. console.log('zh:clickBtn 3' );
  151. zjSdk?.doPay(params);
  152. }
  153. showTag(type){
  154. if (type == rewardType.npc) {
  155. zjSdk?.sendEvent('点击幸存者')
  156. }
  157. if (type == rewardType.bullet) {
  158. zjSdk?.sendEvent('点击子弹资源')
  159. }
  160. if (type == rewardType.weapon) {
  161. zjSdk?.sendEvent('点击武器资源')
  162. }
  163. if (type == rewardType.gun) {
  164. zjSdk?.sendEvent('点击枪械资源')
  165. }
  166. }
  167. private doGet(result, type: string) {
  168. const arr = this.parseArr(result);
  169. let nums = [];
  170. for (let id of arr) {
  171. const data = itemDtManager.getDataByID(id);
  172. if (type == rewardType.npc) {
  173. zjSdk?.sendEvent('幸存者成功获取')
  174. gameEventManager.emit(EVENT_TYPE.ADD_HERO_BY_ID, id);
  175. nums.push(1);
  176. }
  177. if (type == rewardType.bullet) {
  178. zjSdk?.sendEvent('子弹资源成功获取')
  179. gameData.curBulletNum += data.value;
  180. nums.push(data.value);
  181. }
  182. if (type == rewardType.weapon) {
  183. zjSdk?.sendEvent('武器资源成功获取')
  184. let damage = itemDtManager.getDataByID(data.id).value;
  185. gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, true);
  186. nums.push(1);
  187. }
  188. if (type == rewardType.gun) {
  189. zjSdk?.sendEvent('枪械资源成功获取')
  190. let damage = itemDtManager.getDataByID(data.id).value;
  191. gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, false);
  192. nums.push(1);
  193. }
  194. }
  195. UIHelp.ShowUI(UIObtainView, null, {ids: arr, nums: nums, isHero: type == rewardType.npc})
  196. // 关闭按钮
  197. const curWelfare = AccountModel.getInstance().curWelfare;
  198. curWelfare.push(type);
  199. AccountModel.getInstance().curWelfare = curWelfare;
  200. this.switchBtn(type, false);
  201. }
  202. /**
  203. * zh:diy
  204. * @param result
  205. * @param type
  206. */
  207. public doGetForAdEvent(result, type: string) {
  208. console.log('zh:doGetForAdEvent 被触发1 ' + result);
  209. console.log('zh:doGetForAdEvent 被触发2 ' + type);
  210. const arr = this.parseArr(result);
  211. let nums = [];
  212. for (let id of arr) {
  213. const data = itemDtManager.getDataByID(id);
  214. if (type == rewardType.npc) {
  215. zjSdk?.sendEvent('幸存者成功获取')
  216. gameEventManager.emit(EVENT_TYPE.ADD_HERO_BY_ID, id);
  217. nums.push(1);
  218. }
  219. if (type == rewardType.bullet) {
  220. zjSdk?.sendEvent('子弹资源成功获取')
  221. gameData.curBulletNum += data.value;
  222. nums.push(data.value);
  223. }
  224. if (type == rewardType.weapon) {
  225. zjSdk?.sendEvent('武器资源成功获取')
  226. let damage = itemDtManager.getDataByID(data.id).value;
  227. gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, true);
  228. nums.push(1);
  229. }
  230. if (type == rewardType.gun) {
  231. zjSdk?.sendEvent('枪械资源成功获取')
  232. let damage = itemDtManager.getDataByID(data.id).value;
  233. gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, false);
  234. nums.push(1);
  235. }
  236. }
  237. UIHelp.ShowUI(UIObtainView, null, {ids: arr, nums: nums, isHero: type == rewardType.npc})
  238. // 关闭按钮
  239. const curWelfare = AccountModel.getInstance().curWelfare;
  240. curWelfare.push(type);
  241. AccountModel.getInstance().curWelfare = curWelfare;
  242. this.switchBtn(type, false);
  243. }
  244. private switchBtn(type: string, flag) {
  245. this.ui[`${type}`].getComponent(cc.Button).interactable = flag
  246. }
  247. private parseArr(result) {
  248. let arr = [];
  249. [1, 2, 3, 4].forEach(value => {
  250. const id = result[`rewardID${value}`];
  251. arr.push(id)
  252. })
  253. return arr;
  254. }
  255. clickClose() {
  256. gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS, false);
  257. this.onClose();
  258. }
  259. onClose() {
  260. UIHelp.CloseUI(UIWelfareView);
  261. }
  262. }