RewardInsert.ts 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { utils } from "./Utils";
  2. import QCrossWidgetItem from "./QCrossWidgetItem";
  3. import AldUtils from "./AldUtils";
  4. import { SubLocation } from "./YZ_Constant";
  5. import CompatibleTool from "./CompatibleTool";
  6. const { ccclass, property } = cc._decorator;
  7. /**
  8. * 激励插屏
  9. */
  10. @ccclass
  11. export default class RewardInsert extends cc.Component {
  12. private _jumpList: any = null;
  13. private _items: QCrossWidgetItem[] = [];
  14. public isShow: boolean = false;
  15. _panel: cc.Node = null;
  16. _mask: cc.Node = null;
  17. onLoad() {
  18. cc.game.addPersistRootNode(this.node);
  19. this._mask = this.node.getChildByName("Mask");
  20. this._panel = this.node.getChildByName("Panel");
  21. for (let i = 0; i < 6; i++) {
  22. let item: cc.Node = this._panel.getChildByName(`Item${i}`);
  23. let qcrossWidgetItem: QCrossWidgetItem = item.getComponent("QCrossWidgetItem");
  24. qcrossWidgetItem._location = SubLocation.isReward;
  25. this._items.push(qcrossWidgetItem);
  26. }
  27. let ratio: number = 1;
  28. if (cc.winSize.height < cc.winSize.width) {
  29. // 横屏游戏
  30. ratio = cc.winSize.width / 1920 * 0.7;
  31. } else {
  32. ratio = cc.winSize.width / 1080;
  33. }
  34. this._panel.scale = ratio;
  35. }
  36. start() {
  37. this._jumpList = utils.getRecommondGameList();
  38. if (this._jumpList && this._jumpList.length > 0) {
  39. this._initWidget();
  40. } else {
  41. cc.warn("交叉推广数据为null,激励插屏组件不显示!");
  42. utils.adManager.videoCallBack && utils.adManager.videoCallBack(false, "激励组件加载失败!");
  43. utils.adManager.videoCallBack = null;
  44. this.node.destroy();
  45. }
  46. }
  47. private _initWidget() {
  48. let idx: number = 0;
  49. for (let i = 0; i < this._jumpList.length; i++) {
  50. let data: any = this._jumpList[i];
  51. if (data && data.logo) {
  52. let itemIdx: number = idx;
  53. if (itemIdx >= this._items.length) {
  54. return;
  55. }
  56. idx++;
  57. this._items[itemIdx].init(data);
  58. }
  59. }
  60. }
  61. public hide() {
  62. // this._panel.runAction(cc.sequence(cc.moveTo(0.3, CompatibleTool.position(-this._panel.getContentSize().width, 0)).easing(cc.easeQuadraticActionOut()), cc.callFunc(() => {
  63. this._panel.active = false;
  64. this._mask.active = false;
  65. // })));
  66. }
  67. public onCloseBtnHandler(event: any, data: any) {
  68. this.hide();
  69. utils.adManager.videoCallBack && utils.adManager.videoCallBack(false, "未点击试玩奖励!");
  70. utils.adManager.videoCallBack = null;
  71. }
  72. update(dt: number) {
  73. if (!this.isShow) {
  74. utils.showLog("show insertReward>>>>>");
  75. AldUtils.SendEvent("显示激励插屏");
  76. this.isShow = true;
  77. this._panel.active = true;
  78. this._mask.active = true;
  79. }
  80. }
  81. }