YZ_NativeBanner.ts 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. import PlatUtils from "./PlatUtils";
  2. import { utils } from "./Utils";
  3. import YZ_Constant, { BannerLocation } from "./YZ_Constant";
  4. import { NativeBannerInfo } from "./CommonConfig";
  5. import CompatibleTool from "./CompatibleTool";
  6. import { YwAdType, YwAdStatus, AdEventParameter } from "./YouWanSDK/EventAdInfo";
  7. import YouWanAnalytics from "./YouWanSDK/YouWanAnalytics";
  8. const { ccclass, property } = cc._decorator;
  9. @ccclass
  10. export default class YZ_NativeBanner extends cc.Component {
  11. _panel: cc.Node = null;
  12. _icon: cc.Sprite = null;
  13. _hW_icon: cc.Sprite = null;
  14. _sourceLable: cc.Label = null
  15. _titleLabel: cc.Label = null;
  16. _desLabel: cc.Label = null;
  17. _btnLabel: cc.Label = null;
  18. _widget: cc.Widget = null;
  19. _closeBtn: cc.Node = null;
  20. _nativeAd: any = null;
  21. _data: any = null;
  22. _dataDirty: boolean = false;
  23. _panel_widget: cc.Widget = null;
  24. _closeBtn_widget: cc.Widget = null;
  25. _mask_widget: cc.Widget = null;
  26. _st_Panel: cc.Node = null;
  27. _st_Icon: cc.Sprite = null;
  28. _st_TitleLabel: cc.Label = null;
  29. _st_DesLabel: cc.Label = null;
  30. _st_BtnLabel: cc.Label = null;
  31. _st_Widget: cc.Widget = null;
  32. _st_Img: cc.Sprite = null;
  33. _st_CloseBtn: cc.Node = null;
  34. _st_BtnDown: cc.Node = null;
  35. _st_adMask: cc.Node = null;
  36. _st_down_btn_default_img: cc.SpriteFrame = null;
  37. nativeBannerInfo: NativeBannerInfo = null;
  38. _st_TitleLabel_Widget: cc.Widget = null;
  39. _st_DesLabel_Widget: cc.Widget = null;
  40. _st_Img_Widget: cc.Widget = null;
  41. _st_CloseBtn_Widget: cc.Widget = null;
  42. _st_BtnDown_Widget: cc.Widget = null;
  43. _st_adMask_Widget: cc.Widget = null;
  44. _st_Icon_widget: cc.Widget = null;
  45. _bg_mask: cc.Node = null;
  46. _alignType: string = "";
  47. _xmMask: cc.Node = null;
  48. public get ServerConfig() {
  49. return utils.ServerConfig;
  50. }
  51. onLoad() {
  52. if (utils.otherConfig && utils.otherConfig.group) {
  53. this.node.group = utils.otherConfig.group;
  54. }
  55. cc.game.addPersistRootNode(this.node);
  56. this._panel = this.node.getChildByName("Panel");
  57. this._icon = this._panel.getChildByName("Icon").getComponent(cc.Sprite);
  58. this._hW_icon = this._panel.getChildByName("HuaweiIcon").getComponent(cc.Sprite);
  59. this._titleLabel = this._panel.getChildByName("TitleLabel").getComponent(cc.Label);
  60. this._desLabel = this._panel.getChildByName("DesLabel").getComponent(cc.Label);
  61. this._sourceLable = this._panel.getChildByName("source").getComponent(cc.Label);
  62. let btnDown = this._panel.getChildByName("Btn_Download");
  63. this._btnLabel = btnDown.getComponentInChildren(cc.Label);
  64. this._widget = this.getComponent(cc.Widget);
  65. this._panel_widget = this._panel.getComponent(cc.Widget);
  66. this._closeBtn = this._panel.getChildByName("Btn_Close");
  67. this._closeBtn_widget = this._closeBtn.getComponent(cc.Widget);
  68. this._mask_widget = this._panel.getChildByName("Mask").getComponent(cc.Widget);
  69. this._widget.left = 0;
  70. this._widget.right = 0;
  71. this._widget.bottom = 0;
  72. this._st_Panel = this.node.getChildByName("Panel_Statement");
  73. this._st_Widget = this._st_Panel.getComponent(cc.Widget);
  74. this._bg_mask = this.node.getChildByName("bgMask")
  75. this._st_Icon = this._st_Panel.getChildByName("IconMask").getChildByName("Icon").getComponent(cc.Sprite);
  76. this._st_TitleLabel = this._st_Panel.getChildByName("TitleLabel").getComponent(cc.Label);
  77. this._st_DesLabel = this._st_Panel.getChildByName("DesLabel").getComponent(cc.Label);
  78. this._st_BtnDown = this._st_Panel.getChildByName("Btn_Download");
  79. // this._st_BtnLabel = stBtnDown.getComponentInChildren(cc.Label);
  80. this._st_Img = this._st_Panel.getChildByName("adImage").getComponent(cc.Sprite)
  81. this._st_CloseBtn = this._st_Panel.getChildByName("Btn_Close");
  82. this._st_adMask = this._st_Panel.getChildByName("Mask");
  83. this._st_down_btn_default_img = this._st_BtnDown.getComponent(cc.Sprite).spriteFrame;
  84. this._st_TitleLabel_Widget = this._st_TitleLabel.getComponent(cc.Widget);
  85. this._st_DesLabel_Widget = this._st_DesLabel.getComponent(cc.Widget);
  86. this._st_Img_Widget = this._st_Img.getComponent(cc.Widget);
  87. this._st_CloseBtn_Widget = this._st_CloseBtn.getComponent(cc.Widget);
  88. this._st_BtnDown_Widget = this._st_BtnDown.getComponent(cc.Widget);
  89. this._st_adMask_Widget = this._st_adMask.getComponent(cc.Widget);
  90. this._st_Icon_widget = this._st_Panel.getChildByName("IconMask").getComponent(cc.Widget);
  91. if (PlatUtils.IsXiaoMi || CC_DEBUG) {
  92. this._panel.getChildByName("Xm_Mark").active = true;
  93. this._mask_widget.node.active = false;
  94. }
  95. let ratio: number = 1;
  96. if (cc.winSize.height < cc.winSize.width) {
  97. // 横屏游戏
  98. this._widget.left = cc.winSize.width * 0.25;
  99. this._widget.right = cc.winSize.width * 0.25;
  100. this._titleLabel.node.width = 400;
  101. ratio = cc.winSize.width / 1920;
  102. } else {
  103. ratio = cc.winSize.width / 1080;
  104. }
  105. this.node.scale = ratio;
  106. }
  107. onShow() {
  108. cc.game.emit("HuaWeiOnShow");
  109. }
  110. onEnable() {
  111. this._st_Panel.targetOff(this);
  112. this._panel.targetOff(this);
  113. cc.game.targetOff(this);
  114. if (PlatUtils.IsHuaWei) {
  115. console.log("注册监听事件 >>>>>.");
  116. cc.game.on(cc.game.EVENT_SHOW, () => {
  117. console.log("HuaWeiOnShow >>>>>>");
  118. this._reportAdShow();
  119. }, this);
  120. }
  121. if (PlatUtils.IsOPPO || PlatUtils.IsVIVO || PlatUtils.IsHuaWei || PlatUtils.IsXiaoMi) {
  122. this._st_Panel.on(cc.Node.EventType.TOUCH_START, (event: cc.Event) => {
  123. this._reportAdClick();
  124. }, this);
  125. this._panel.on(cc.Node.EventType.TOUCH_START, (event: cc.Event) => {
  126. this._reportAdClick();
  127. }, this);
  128. cc.game.on(YZ_Constant.YZ_NativeAdClick, () => {
  129. this._reportAdClick();
  130. }, this);
  131. }
  132. }
  133. onDisable() {
  134. if (PlatUtils.IsOPPO || PlatUtils.IsVIVO || PlatUtils.IsHuaWei || PlatUtils.IsXiaoMi) {
  135. this._st_Panel.targetOff(this);
  136. this._panel.targetOff(this);
  137. }
  138. cc.game.targetOff(this);
  139. }
  140. init(nativeAd: any, data: any, nativeBannerInfo: NativeBannerInfo) {
  141. this._nativeAd = nativeAd;
  142. this._data = data;
  143. this._dataDirty = true;
  144. this.nativeBannerInfo = nativeBannerInfo;
  145. // this.nativeBannerInfo.banner_show_height = 500;
  146. // this.nativeBannerInfo.st_banner_style = 1;
  147. // this.nativeBannerInfo.st_banner_down_but_show = 2;
  148. // this.nativeBannerInfo.show_st_banner = "true";
  149. // this.nativeBannerInfo.st_banner_width = 800;
  150. // this.nativeBannerInfo.st_banner_height = 300;
  151. if (this.nativeBannerInfo.show_st_banner == "true") {
  152. if (this.nativeBannerInfo.st_banner_style > -1) {
  153. if (this._data.imgUrlList && this._data.imgUrlList.length > 0) {
  154. this._panel.active = false;
  155. this._st_Panel.active = true;
  156. } else {
  157. this._panel.active = false;
  158. this._st_Panel.active = false;
  159. }
  160. } else {
  161. this._panel.active = false;
  162. this._st_Panel.active = true;
  163. }
  164. } else {
  165. this._panel.active = true;
  166. this._st_Panel.active = false;
  167. }
  168. // if(this.nativeBannerInfo._alignType === "top")
  169. // {
  170. // this._widget.top = 0;
  171. // this._widget.isAlignTop = true;
  172. // this._widget.isAlignBottom = false;
  173. // this._widget.updateAlignment();
  174. // }
  175. // utils.showLog("当前显示位置为:", this.nativeBannerInfo.location, ">>显示参数为:", this.nativeBannerInfo.toStrong());
  176. }
  177. update(dt: number) {
  178. if (this._data && this._dataDirty) {
  179. this._dataDirty = false;
  180. this._updateContent();
  181. }
  182. if (!this._data) {
  183. this._st_Panel.active = false;
  184. this._panel.active = false;
  185. }
  186. }
  187. _updateContent() {
  188. if (this._data) {
  189. // 上报展示
  190. this._reportAdShow();
  191. if (PlatUtils.IsHuaWei) {
  192. this._data.icon = "";
  193. }
  194. utils.nativeBannerShowCount++;
  195. if (this.nativeBannerInfo.show_st_banner == "true" && this.nativeBannerInfo.st_banner_style > -1) {
  196. if (this.nativeBannerInfo.st_banner_style == 1 || this.nativeBannerInfo.st_banner_style == 2) {
  197. if (this.nativeBannerInfo.st_banner_width > -1) {
  198. this._st_Panel.width = this.nativeBannerInfo.st_banner_width;
  199. } else {
  200. this._st_Panel.width = 821.4;
  201. }
  202. if (this.nativeBannerInfo.st_banner_height > -1) {
  203. this._st_Panel.height = this.nativeBannerInfo.st_banner_height;
  204. } else {
  205. this._st_Panel.height = 589;
  206. }
  207. this._st_Widget.updateAlignment();
  208. this._st_adMask_Widget.updateAlignment();
  209. this._st_CloseBtn_Widget.updateAlignment();
  210. this._st_BtnDown_Widget.updateAlignment();
  211. this._st_Icon_widget.updateAlignment();
  212. } else {
  213. this._st_Panel.width = 821.4;
  214. this._st_Panel.height = 589;
  215. this._st_Widget.updateAlignment();
  216. this._st_adMask_Widget.updateAlignment();
  217. this._st_CloseBtn_Widget.updateAlignment()
  218. this._st_BtnDown_Widget.updateAlignment();
  219. this._st_Icon_widget.updateAlignment();
  220. }
  221. if (this.nativeBannerInfo.st_banner_style == 0 || this.nativeBannerInfo.st_banner_style == 1) {
  222. utils.showLog("//单图片样式,拉伸图片,并且隐藏标题和描述");
  223. this._st_Img_Widget.top = 0;
  224. this._st_Img_Widget.bottom = 0;
  225. this._st_Img_Widget.isAlignTop = true;
  226. this._st_Img_Widget.isAlignBottom = true;
  227. this._st_Img_Widget.updateAlignment();
  228. this._st_DesLabel.node.active = false;
  229. this._st_TitleLabel.node.active = false;
  230. this._st_Icon_widget.updateAlignment();
  231. } else if (this.nativeBannerInfo.st_banner_style == 2) {
  232. utils.showLog("默认样式自定义宽高:展示标题和描述");
  233. this._st_DesLabel.node.active = true;
  234. this._st_TitleLabel.node.active = true;
  235. this._st_DesLabel_Widget.updateAlignment();
  236. this._st_TitleLabel_Widget.updateAlignment();
  237. this._st_Img_Widget.isAlignTop = true;
  238. this._st_Img_Widget.isAlignBottom = true;
  239. this._st_Img_Widget.top = this._st_TitleLabel.node.height + this._st_TitleLabel_Widget.top;
  240. this._st_Img_Widget.bottom = this._st_DesLabel_Widget.node.height + this._st_DesLabel_Widget.bottom;
  241. this._st_Img_Widget.updateAlignment();
  242. this._st_Icon_widget.updateAlignment();
  243. } else {
  244. this._st_Img_Widget.isAlignTop = true;
  245. this._st_Img_Widget.isAlignBottom = true;
  246. this._st_Img_Widget.updateAlignment();
  247. this._st_DesLabel.node.active = true;
  248. this._st_TitleLabel.node.active = true;
  249. this._st_Icon_widget.updateAlignment();
  250. }
  251. } else if (this.nativeBannerInfo.show_st_banner == "true") {
  252. utils.showLog("结算banner使用默认样式!");
  253. this._st_Panel.width = 821.4;
  254. this._st_Panel.height = 589;
  255. this._st_Img_Widget.isAlignTop = false;
  256. this._st_Img_Widget.isAlignBottom = false;
  257. this._st_Img_Widget.updateAlignment();
  258. this._st_DesLabel.node.active = true;
  259. this._st_TitleLabel.node.active = true;
  260. this._st_Widget.updateAlignment();
  261. this._st_adMask_Widget.updateAlignment();
  262. this._st_CloseBtn_Widget.updateAlignment()
  263. this._st_BtnDown_Widget.updateAlignment();
  264. this._st_Icon_widget.updateAlignment();
  265. }
  266. this._st_CloseBtn.scale = this.nativeBannerInfo.st_banner_scale < 1 ? this._st_CloseBtn.scale * this.nativeBannerInfo.st_banner_scale : 1;
  267. this._st_adMask.scale = this.nativeBannerInfo.st_banner_scale < 1 ? this._st_adMask.scale * this.nativeBannerInfo.st_banner_scale : 1;
  268. this._st_CloseBtn.active = this.nativeBannerInfo.st_banner_close_but_show == "true";
  269. this._st_CloseBtn.opacity = this.nativeBannerInfo.st_banner_close_but_alpha;
  270. if (this.ServerConfig.first_native_banner_delayed_count_close) {
  271. if (utils.nativeBannerShowCount > 3 && this.ServerConfig.first_native_banner_delayed_count_close) {
  272. utils.nativeBannerResizeCloseBtnShowCount++;
  273. if (utils.nativeBannerResizeCloseBtnShowCount % this.ServerConfig.native_banner_delayed_count_close == 0) {
  274. utils.showLog(`原生banner关闭按钮设置服务器配置大小${this.ServerConfig.intersititia_close_but_size}`);
  275. if (this.nativeBannerInfo.st_banner_close_but_range) {
  276. this._st_CloseBtn.setContentSize(cc.size(this.nativeBannerInfo.st_banner_close_but_range, this.nativeBannerInfo.st_banner_close_but_range));
  277. this._st_CloseBtn.getChildByName("Background").setContentSize(cc.size(this.nativeBannerInfo.st_banner_close_but_size, this.nativeBannerInfo.st_banner_close_but_size));
  278. }
  279. }
  280. }
  281. } else {
  282. if (this.nativeBannerInfo.st_banner_close_but_range) {
  283. this._st_CloseBtn.setContentSize(cc.size(this.nativeBannerInfo.st_banner_close_but_range, this.nativeBannerInfo.st_banner_close_but_range));
  284. this._st_CloseBtn.getChildByName("Background").setContentSize(cc.size(this.nativeBannerInfo.st_banner_close_but_size, this.nativeBannerInfo.st_banner_close_but_size));
  285. }
  286. }
  287. if (this.nativeBannerInfo.st_banner_down_but_show) {
  288. this._st_BtnDown.active = true;
  289. if (this.nativeBannerInfo.st_banner_down_btn_image) {
  290. utils.showLog("this.nativeBannerInfo.st_banner_down_btn_image", this.nativeBannerInfo.st_banner_down_btn_image);
  291. CompatibleTool.LoadRes(this.nativeBannerInfo.st_banner_down_btn_image, (err, res) => {
  292. if (!err && cc.isValid(this) && this._st_BtnDown) {
  293. this._st_BtnDown.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(res);
  294. if (this.nativeBannerInfo.st_banner_down_but_margin_top) {
  295. this._st_BtnDown_Widget.top = - (this._st_BtnDown.getContentSize().height + this.nativeBannerInfo.st_banner_down_but_margin_top);
  296. this._st_BtnDown_Widget.updateAlignment();
  297. } else {
  298. this._st_BtnDown_Widget.top = - this._st_BtnDown.getContentSize().height;
  299. this._st_BtnDown_Widget.updateAlignment();
  300. }
  301. }
  302. });
  303. } else {
  304. this._st_BtnDown.getComponent(cc.Sprite).spriteFrame = this._st_down_btn_default_img;
  305. if (this.nativeBannerInfo.st_banner_down_but_margin_top) {
  306. this._st_BtnDown_Widget.top -= this.nativeBannerInfo.st_banner_down_but_margin_top;
  307. this._st_BtnDown_Widget.updateAlignment();
  308. }
  309. }
  310. if (this.nativeBannerInfo.st_banner_down_but_show == 2) {
  311. this._st_BtnDown.runAction(cc.sequence(cc.scaleTo(0.3, 1.2), cc.scaleTo(0.3, 1)).repeatForever());
  312. } else {
  313. this._st_BtnDown.stopAllActions();
  314. }
  315. this._st_BtnDown.scale = this.node.scale;
  316. } else {
  317. this._st_BtnDown.active = false;
  318. this._st_BtnDown.stopAllActions();
  319. }
  320. this._closeBtn.active = this.nativeBannerInfo.banner_close_but_show == "true";
  321. this._closeBtn.opacity = this.nativeBannerInfo.banner_close_but_alpha;
  322. if (this.ServerConfig.first_native_banner_delayed_count_close) {
  323. if (utils.nativeBannerShowCount > 3 && this.ServerConfig.first_native_banner_delayed_count_close) {
  324. if (utils.nativeBannerResizeCloseBtnShowCount % this.ServerConfig.native_banner_delayed_count_close == 0) {
  325. utils.showLog(`原生banner关闭按钮设置服务器配置大小${this.ServerConfig.intersititia_close_but_size}`);
  326. this._closeBtn.setContentSize(cc.size(this.nativeBannerInfo.banner_close_but_range, this.nativeBannerInfo.banner_close_but_range));
  327. this._closeBtn.getChildByName("Background").setContentSize(cc.size(this.nativeBannerInfo.banner_close_but_size, this.nativeBannerInfo.banner_close_but_size));
  328. }
  329. }
  330. } else {
  331. this._closeBtn.setContentSize(cc.size(this.nativeBannerInfo.banner_close_but_range, this.nativeBannerInfo.banner_close_but_range));
  332. this._closeBtn.getChildByName("Background").setContentSize(cc.size(this.nativeBannerInfo.banner_close_but_size, this.nativeBannerInfo.banner_close_but_size));
  333. }
  334. if (this.nativeBannerInfo.show_st_banner == "false") {
  335. // this.node.setContentSize(cc.size(this.node.getContentSize().width,));
  336. this._panel_widget.isAlignTop = false;
  337. this._panel_widget.bottom = 0;
  338. this._panel.setContentSize(cc.size(this.node.getContentSize().width, this.nativeBannerInfo.banner_show_height < 160 ? 160 : this.nativeBannerInfo.banner_show_height));
  339. this._panel_widget.updateAlignment();
  340. this._closeBtn_widget.updateAlignment();
  341. this._mask_widget.updateAlignment();
  342. } else {
  343. //缩放
  344. this._st_Panel.scale = this.nativeBannerInfo.st_banner_scale ? this.nativeBannerInfo.st_banner_scale : 1;
  345. this._st_Widget.bottom = this.nativeBannerInfo.st_banner_bottom ? this.nativeBannerInfo.st_banner_bottom : 0;
  346. this._st_Widget.updateAlignment();
  347. }
  348. if (this.nativeBannerInfo._alignType === "top") {
  349. if (this.nativeBannerInfo.show_st_banner == "true") {
  350. this.node.height = this._st_Panel.height;
  351. this.node.width = this._st_Panel.width;
  352. this._st_CloseBtn_Widget.updateAlignment();
  353. this._st_adMask_Widget.updateAlignment();
  354. } else {
  355. this.node.height = this.nativeBannerInfo.banner_show_height < 160 ? 160 : this.nativeBannerInfo.banner_show_height;
  356. this._panel_widget.updateAlignment();
  357. this._closeBtn_widget.updateAlignment();
  358. this._mask_widget.updateAlignment();
  359. }
  360. this._widget.isAlignTop = true;
  361. // this._widget.top = 0;
  362. this._widget.isAlignBottom = false;
  363. this._widget.updateAlignment();
  364. }
  365. if (this.nativeBannerInfo.show_st_banner == "true") {
  366. utils.showLog("服务器配置显示为结算banner >>>>>");
  367. if (this.nativeBannerInfo.st_banner_bg_mask_opacity > 0) {
  368. this._bg_mask.opacity = this.nativeBannerInfo.st_banner_bg_mask_opacity;
  369. this._bg_mask.setContentSize(cc.size(this.node.getContentSize().width, this._st_Panel.height));
  370. this._st_adMask.active = false;
  371. } else {
  372. this._bg_mask.active = false;
  373. }
  374. // 居底部距离
  375. this._st_TitleLabel.string = this._data.title ? this._data.title : "";
  376. this._st_DesLabel.string = this._data.desc ? this._data.desc : "";
  377. // this._data.imgUrlList = null;
  378. // this._st_BtnLabel.string = this._data.clickBtnTxt ? this._data.clickBtnTxt : "查看详情";
  379. if (this._data.imgUrlList && this._data.imgUrlList.length > 0) {
  380. // 有图片,优先显示图片
  381. this._st_Icon.node.active = false;
  382. this._st_Img.node.active = true;
  383. CompatibleTool.LoadRes(this._data.imgUrlList[0], (err, res) => {
  384. if (!err && cc.isValid(this) && this._st_Img) {
  385. this._st_Img.spriteFrame = new cc.SpriteFrame(res);
  386. }
  387. });
  388. } else if (PlatUtils.IsOPPO && this._data.iconUrlList && this._data.iconUrlList.length > 0) {
  389. // 有icon
  390. this._st_Icon.node.active = true;
  391. this._st_Img.node.active = false;
  392. if (this.nativeBannerInfo.st_banner_style == 0 || this.nativeBannerInfo.st_banner_style == 1) {
  393. utils.showLog("单图片样式-没有大图,显示默认原生样式banner");
  394. this._titleLabel.string = this._data.title;
  395. this._desLabel.string = this._data.desc;
  396. this._btnLabel.string = this._data.clickBtnTxt ? this._data.clickBtnTxt : "查看详情";
  397. let iconUrl = PlatUtils.IsOPPO ? this._data.iconUrlList[0] : this._data.icon;
  398. CompatibleTool.LoadRes(iconUrl, (err, res) => {
  399. if (!err && cc.isValid(this) && this._icon) {
  400. this._icon.spriteFrame = new cc.SpriteFrame(res);
  401. }
  402. });
  403. this._st_Panel.active = false;
  404. this._panel.active = true;
  405. } else {
  406. CompatibleTool.LoadRes(this._data.iconUrlList[0], (err, res) => {
  407. if (!err && cc.isValid(this) && this._st_Icon) {
  408. this._st_Icon.spriteFrame = new cc.SpriteFrame(res);
  409. }
  410. });
  411. }
  412. } else if ((PlatUtils.IsVIVO || PlatUtils.IsHuaWei) && this._data.icon) {
  413. // 有icon
  414. this._st_Icon.node.active = true;
  415. this._st_Img.node.active = false;
  416. CompatibleTool.LoadRes(this._data.icon, (err, res) => {
  417. if (!err && cc.isValid(this) && this._st_Icon) {
  418. this._st_Icon.spriteFrame = new cc.SpriteFrame(res);
  419. }
  420. });
  421. }
  422. } else {
  423. this._titleLabel.string = this._data.title ? this._data.title : "";
  424. this._desLabel.string = this._data.desc ? this._data.desc : "";
  425. this._btnLabel.string = this._data.clickBtnTxt ? this._data.clickBtnTxt : "查看详情";
  426. if (PlatUtils.IsHuaWei) {
  427. this._sourceLable.string = this._data.source ? this._data.source : "";
  428. this._panel.getChildByName("Hw_Mark").active = true;
  429. this._mask_widget.node.active = false;
  430. }
  431. let iconUrl = "";
  432. if (PlatUtils.IsOPPO) {
  433. iconUrl = this._data.iconUrlList[0];
  434. } else {
  435. iconUrl = this._data.icon;
  436. }
  437. if (iconUrl) {
  438. CompatibleTool.LoadRes(iconUrl, (err, res) => {
  439. if (!err && cc.isValid(this) && this._icon) {
  440. this._icon.spriteFrame = new cc.SpriteFrame(res);
  441. }
  442. });
  443. } else {
  444. if (this._data.imgUrlList && this._data.imgUrlList.length > 0) {
  445. CompatibleTool.LoadRes(this._data.imgUrlList[0], (err, res) => {
  446. if (!err && cc.isValid(this) && this._icon) {
  447. if (PlatUtils.IsHuaWei) {
  448. this._icon.node.active = false;
  449. this._hW_icon.node.active = true;
  450. this._hW_icon.spriteFrame = new cc.SpriteFrame(res);
  451. } else {
  452. this._icon.spriteFrame = new cc.SpriteFrame(res);
  453. }
  454. }
  455. });
  456. }
  457. }
  458. }
  459. // this.nativeBannerInfo.banner_close_but_range = 20;
  460. // this.nativeBannerInfo.banner_close_but_size = 50;
  461. if (PlatUtils.IsHuaWei) {
  462. this._closeBtn.setContentSize(cc.size(this.nativeBannerInfo.banner_close_but_range, this.nativeBannerInfo.banner_close_but_range));
  463. this._closeBtn.getChildByName("Background").setContentSize(cc.size(this.nativeBannerInfo.banner_close_but_size, this.nativeBannerInfo.banner_close_but_size));
  464. }
  465. // this.nativeBannerInfo.st_banner_down_but_margin_top = -500;
  466. if (this.nativeBannerInfo.st_banner_down_but_margin_top != 0) {
  467. this._st_BtnDown_Widget.top = this.nativeBannerInfo.st_banner_down_but_margin_top;
  468. this._st_BtnDown_Widget.updateAlignment();
  469. }
  470. if (this.nativeBannerInfo.st_banner_down_but_show > 0) {
  471. this._st_BtnDown.active = true;
  472. if (this.nativeBannerInfo.st_banner_down_but_show === 2) {
  473. this._st_BtnDown.runAction(cc.sequence(cc.scaleTo(0.3, 1.3), cc.scaleTo(0.3, 1)).repeatForever());
  474. } else {
  475. this._st_BtnDown.stopAllActions();
  476. }
  477. } else {
  478. this._st_BtnDown.active = false;
  479. this._st_BtnDown.stopAllActions();
  480. }
  481. }
  482. }
  483. onBtnClickHandler(event: cc.Event, data: any) {
  484. switch (event.target.name) {
  485. case "Btn_Close": {
  486. this.node.active = false;
  487. if (PlatUtils.IsOPPO) {
  488. utils.oppoTool.countBannerCloseCount();
  489. }
  490. utils._bannerCloseTime = new Date().getTime();
  491. break;
  492. }
  493. case "Btn_Download":
  494. case "bgMask": {
  495. this._reportAdClick();
  496. break;
  497. }
  498. }
  499. }
  500. _reportAdShow() {
  501. if (this._data) {
  502. if (this._nativeAd) {
  503. if (!this._data.isReportShow || PlatUtils.IsHuaWei) {
  504. YouWanAnalytics.EventAdWithObj(YwAdType.NATIVE_BANNER, YwAdStatus.SHOW_SUCCESS, new AdEventParameter(this._data.adId));
  505. this._data.isReportShow = true;
  506. utils.showLog("上报原生广告条展示!adId:" + this._data.adId);
  507. this._nativeAd.reportAdShow({
  508. adId: this._data.adId
  509. });
  510. utils.SendEvent("上报原生Banner广告展示,位置:" + this.nativeBannerInfo.location);
  511. } else {
  512. utils.showLog("当前广告已经过上报展示!adId:" + this._data.adId, ",当前不做上报");
  513. }
  514. }
  515. }
  516. }
  517. _reportAdClick() {
  518. if (this._data) {
  519. utils.showLog("上报原生广告条点击! adId:" + this._data.adId);
  520. if (this._nativeAd) {
  521. if (!this._data.isReportClick || PlatUtils.IsHuaWei) {
  522. YouWanAnalytics.EventAdWithObj(YwAdType.NATIVE_BANNER, YwAdStatus.CLICK, new AdEventParameter(this._data.adId));
  523. this._data.isReportClick = true;
  524. this._nativeAd.reportAdClick({
  525. adId: this._data.adId,
  526. isAutoDownload: true
  527. });
  528. if (PlatUtils.IsHuaWei) {
  529. this.downLoadAd();
  530. }
  531. }
  532. this._data = null;
  533. if (this.nativeBannerInfo.banner_click_refresh == "true" && !PlatUtils.IsHuaWei) {
  534. utils.showLog("点击之后-先隐藏广告-再刷新广告条!");
  535. utils.adManager.HideBanner(this.nativeBannerInfo.location);
  536. // 刷新banner
  537. utils.adManager.ShowBanner(this.nativeBannerInfo.location, { isRefresh: true });
  538. } else {
  539. cc.game.targetOff(this);
  540. this.node.active = false;
  541. }
  542. }
  543. }
  544. }
  545. downLoadAd() {
  546. return;
  547. const resultCode = this._nativeAd.startDownload({
  548. adId: this._data.adId
  549. })
  550. utils.showLog('原生广告主动下载 resumeDownloadresultCode = ' + resultCode);
  551. }
  552. }