BeforGameOverRecGamesPanel.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import GameItem from "./GameItem";
  2. import { utils } from "./Utils";
  3. import { BannerLocation, SubLocation } from "./YZ_Constant";
  4. import PlatUtils from "./PlatUtils";
  5. const { ccclass, property } = cc._decorator;
  6. @ccclass
  7. export default class BeforGameOverRecGamesPanel extends cc.Component {
  8. _panel: cc.Node = null;
  9. _gameList: cc.Node = null;
  10. _originScale: number = 1;
  11. _gameItems: GameItem[] = [];
  12. _jumpList: any = null;
  13. _dataDirty: boolean = false;
  14. _is_Horizontal: boolean = false;
  15. _closeBtnRight: cc.Node = null;
  16. _closeBtnLine: cc.Node = null;
  17. _star: cc.Node = null;
  18. private gameItemNode: cc.Node = null;
  19. _location: SubLocation = SubLocation.isMoreGame;
  20. onLoad() {
  21. if (utils.otherConfig && utils.otherConfig.group) {
  22. this.node.group = utils.otherConfig.group;
  23. }
  24. if (!PlatUtils.IsNativeAndroid) {
  25. utils.adManager.HideBanner(BannerLocation.Home);
  26. }
  27. this._panel = this.node.getChildByName("Panel");
  28. this.node.active = false;
  29. let ratio: number = 1;
  30. if (cc.winSize.height < cc.winSize.width) {
  31. // 横屏游戏
  32. ratio = cc.winSize.width / 1920;
  33. this._is_Horizontal = true;
  34. } else {
  35. ratio = cc.winSize.width / 1080;
  36. }
  37. if (this._is_Horizontal) {
  38. this._panel.getChildByName("VGameScrollView").active = false
  39. this._panel.getChildByName("VHead").active = false
  40. this._gameList = this._panel.getChildByName("HGameScrollView").getComponent(cc.ScrollView).content;
  41. this.gameItemNode = this._gameList.children[0];
  42. this._gameList.removeAllChildren();
  43. } else {
  44. this._panel.getChildByName("HGameScrollView").active = false;
  45. this._panel.getChildByName("HHead").active = false
  46. this._gameList = this._panel.getChildByName("VGameScrollView").getComponent(cc.ScrollView).content;
  47. this.gameItemNode = this._gameList.children[0];
  48. this._gameList.removeAllChildren();
  49. }
  50. this._panel.scale = ratio;
  51. this._originScale = this._panel.scale;
  52. }
  53. private _initWidget() {
  54. this.scheduleOnce(() => {
  55. this._gameList.removeAllChildren();
  56. let clo = this._is_Horizontal ? 7 : 4;
  57. let totalRow = Math.floor(this._jumpList.length / clo);
  58. let totalClo = clo * totalRow;
  59. for (let i = 0; i < totalClo; i++) {
  60. let data: any = this._jumpList[i];
  61. if (data && data.logo) {
  62. let tempNode = cc.instantiate(this.gameItemNode);
  63. let gameItem: GameItem = tempNode.getComponent("GameItem");
  64. gameItem.init(data, this._location);
  65. this._gameList.addChild(tempNode);
  66. }
  67. }
  68. })
  69. }
  70. update() {
  71. if (this._dataDirty) {
  72. this._dataDirty = false;
  73. this._updatePanel();
  74. }
  75. }
  76. _updatePanel() {
  77. utils.postRecommentShowData(this._location);
  78. this._initWidget();
  79. return;
  80. }
  81. public init(jumpList: any) {
  82. this._jumpList = jumpList;
  83. this._dataDirty = true;
  84. }
  85. public show() {
  86. this.node.active = true;
  87. }
  88. public hide() {
  89. let self = this;
  90. self.node.active = false;
  91. if (utils.rewardRecGamePanelCloseFunc) {
  92. utils.rewardRecGamePanelCloseFunc();
  93. utils.rewardRecGamePanelCloseFunc = null;;
  94. } else {
  95. utils.rewardCloseFunc && utils.rewardCloseFunc();
  96. utils.rewardCloseFunc = null;
  97. }
  98. }
  99. public onCloseBtnHandler(event: any, data: any) {
  100. this.hide();
  101. }
  102. }