MoreGamesWidget.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import MoreGamesPanel from "./MoreGamesPanel";
  2. import { utils } from "./Utils";
  3. import PlatUtils from "./PlatUtils";
  4. import AldUtils from "./AldUtils";
  5. import CompatibleTool from "./CompatibleTool";
  6. import { SubLocation } from "./YZ_Constant";
  7. const { ccclass, property } = cc._decorator;
  8. @ccclass
  9. export default class MoreGamesWidget extends cc.Component {
  10. @property(cc.Prefab)
  11. prefab: cc.Prefab = null;
  12. @property(cc.Prefab)
  13. prefab1: cc.Prefab = null;
  14. btnMoreGames: cc.Node = null;
  15. moreGamesPanel: MoreGamesPanel = null;
  16. bgTexture: cc.SpriteFrame;
  17. onLoad() {
  18. this.btnMoreGames = this.node.getChildByName("Btn_MoreGames");
  19. this.btnMoreGames.active = false;
  20. let self = this;
  21. let back = this.btnMoreGames.getChildByName("Background").getComponent(cc.Sprite);
  22. let backUrl
  23. if (utils.ServerConfig) {
  24. backUrl = utils.ServerConfig.more_game_icon;
  25. } else {
  26. cc.warn("没有服务器配置");
  27. }
  28. if (backUrl && !this.bgTexture) {
  29. CompatibleTool.LoadRes(backUrl, (err, texture) => {
  30. if (!err && cc.isValid(this) && back.node) {
  31. let size: cc.Size = back.node.getContentSize();
  32. self.bgTexture = new cc.SpriteFrame(texture);
  33. back.spriteFrame = self.bgTexture;
  34. back.node.setContentSize(size);
  35. }
  36. });
  37. }
  38. }
  39. onEnable() {
  40. utils.registerServerInitEvent(() => {
  41. this._setBtnVisible();
  42. }, this);
  43. }
  44. onDisable() {
  45. utils.unregisterServerInitEvent(this);
  46. }
  47. _setBtnVisible() {
  48. let valid: boolean = true;
  49. if (utils.isShowMoreGamesWidget()) {
  50. if (PlatUtils.IsQQ) {
  51. this.btnMoreGames.active = true;
  52. } else if (PlatUtils.Is4399) {
  53. this.btnMoreGames.active = true;
  54. } else if (PlatUtils.IsNativeAndroid && utils.Tool_Native && utils.config.nativeAndroidConfig.channel == "oppo") {
  55. this.btnMoreGames.active = true;
  56. } else if (utils.ServerConfig.show_oppo_rec && utils.ServerConfig.show_oppo_rec == "true") {
  57. this.btnMoreGames.active = true;
  58. } else {
  59. let gameList: any = utils.getRecommondGameList();
  60. if (gameList) {
  61. if (gameList.length > 0 || CC_DEBUG) {
  62. this.btnMoreGames.active = true;
  63. } else {
  64. cc.warn("交叉推广数据列表长度为0, 更多游戏按钮不显示!");
  65. valid = false;
  66. }
  67. } else {
  68. cc.warn("交叉推广数据列表数据为null, 更多游戏按钮不显示!");
  69. valid = false;
  70. }
  71. }
  72. } else {
  73. valid = false;
  74. }
  75. if (!valid) {
  76. this.node.destroy();
  77. }
  78. }
  79. onBtnClickedHandler(event: cc.Event, data: any) {
  80. if (PlatUtils.IsQQ) {
  81. utils.adManager.ShowAppBox(true);
  82. return;
  83. } else if (PlatUtils.Is4399) {
  84. utils.Tool_4399.showRecommend();
  85. return;
  86. } else if (PlatUtils.IsNativeAndroid && utils.Tool_Native && utils.Tool_Native.moreGameShowType == 1) {
  87. //如果是原生平台,判断显示的类型
  88. utils.Tool_Native.showMoreGames();
  89. utils.postDataByLocation("123", SubLocation.isMoreGame, 0);
  90. } else if (PlatUtils.IsDouyin) {
  91. utils.Tool_Douyin.showMoreGamesModal();
  92. }
  93. // else if (PlatUtils.IsOPPO) {
  94. // utils.oppoTool.showOppoGamePortal();
  95. // }
  96. else {
  97. if (utils.ServerConfig.show_oppo_rec && utils.ServerConfig.show_oppo_rec == "true") {
  98. utils.showLog("服务器配置显示官方互推!");
  99. utils.oppoTool.showOppoGamePortal();
  100. return;
  101. }
  102. let jumpList: any = utils.getRecommondGameList();
  103. if (jumpList && jumpList.length > 0) {
  104. utils.showLog("MoreGamePanel 交叉推广数据:", JSON.stringify(jumpList));
  105. let panel;
  106. if (utils.ServerConfig.more_game_skin == 2 || CC_DEBUG) {
  107. panel = cc.instantiate(this.prefab1);
  108. panel.zIndex = 999999;
  109. this.moreGamesPanel = panel.getComponent("MoreGamesPanel1");
  110. } else {
  111. panel = cc.instantiate(this.prefab);
  112. panel.zIndex = 999999;
  113. this.moreGamesPanel = panel.getComponent("MoreGamesPanel");
  114. }
  115. cc.director.getScene().addChild(panel);
  116. this.moreGamesPanel._location = SubLocation.isMoreGame;
  117. this.moreGamesPanel.init(jumpList);
  118. this.moreGamesPanel.show();
  119. AldUtils.SendEvent("点击更多游戏按钮");
  120. } else {
  121. utils.showLog("获取交叉推广数据失败!");
  122. }
  123. }
  124. }
  125. }