MoreGamesPanel1.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import GameItem from "./GameItem";
  2. import { SubLocation } from "./YZ_Constant";
  3. import { utils } from "./Utils";
  4. import QCrossWidgetItem from "./QCrossWidgetItem";
  5. import CompatibleTool from "./CompatibleTool";
  6. import List from "./List";
  7. const { ccclass, property } = cc._decorator;
  8. const _panelSize: cc.Size[] = [cc.size(225, 1000), cc.size(506, 1000)];
  9. const _titleSize: cc.Size[] = [cc.size(111, 54), cc.size(275, 54)];
  10. const _titleBgSize: cc.Size[] = [cc.size(376, 104), cc.size(545, 104)];
  11. const _starSize: cc.Size[] = [cc.size(251, 89), cc.size(425, 89)];
  12. @ccclass
  13. export default class MoreGamesPanel extends cc.Component {
  14. _panel: cc.Node = null;
  15. _gameList: cc.Node = null;
  16. _originScale: number = 1;
  17. _gameItems: GameItem[] = [];
  18. _jumpList: any = null;
  19. _dataDirty: boolean = false;
  20. _closeBtnRight: cc.Node = null;
  21. _closeBtnLine: cc.Node = null;
  22. _title: cc.Node = null;
  23. _titleBg: cc.Node = null;
  24. _star: cc.Node = null;
  25. private gameItemNode: cc.Node = null;
  26. listView: List = null;
  27. onLoad() {
  28. if (utils.otherConfig && utils.otherConfig.group) {
  29. this.node.group = utils.otherConfig.group;
  30. }
  31. this._panel = this.node.getChildByName("Panel");
  32. this.listView = this._panel.getChildByName("GameList").getComponent(List)
  33. // this._gameList = this._panel.getChildByName("GameList").getComponent(cc.ScrollView).content;
  34. // this.gameItemNode = this._gameList.children[0];
  35. // this._gameList.removeAllChildren();
  36. this._closeBtnRight = this._panel.getChildByName("Btn_Close");
  37. this._closeBtnRight.active = true;
  38. this._closeBtnLine = this._panel.getChildByName("Btn_CloseSide");
  39. this._closeBtnLine.active = false;
  40. this._titleBg = cc.find("Title/TitleBg", this._panel);
  41. this._title = cc.find("Title/Txt", this._panel);
  42. this._star = cc.find("Title/Star", this._panel);
  43. this.node.active = false;
  44. let ratio: number = 1;
  45. if (cc.winSize.height < cc.winSize.width) {
  46. // 横屏游戏
  47. ratio = cc.winSize.width / 1920 * 0.5;
  48. } else {
  49. ratio = cc.winSize.width / 1080;
  50. }
  51. this._panel.scale = ratio;
  52. this._originScale = this._panel.scale;
  53. }
  54. update(dt) {
  55. if (this.autoScorll && !this.listView.scrollView.isScrolling()) {
  56. this.listView.content.y += dt * 100;
  57. this.listView._onScrolling();
  58. }
  59. }
  60. onListRender(item: cc.Node, idx: number) {
  61. let qcrossWidgetItem: GameItem = item.getComponent(GameItem);
  62. qcrossWidgetItem.init(this._jumpList[idx], SubLocation.isMoreGame);
  63. }
  64. autoScorll: boolean = false;
  65. private _initWidget() {
  66. if (this._jumpList.length > 5) {
  67. if (utils.ServerConfig.more_game_pannel_auto_scroll && utils.ServerConfig.more_game_pannel_auto_scroll == "false") {
  68. utils.showLog("服务器不开启自动滚动!");
  69. } else {
  70. this.scheduleOnce(() => {
  71. this.autoScorll = true;
  72. }, 1);
  73. }
  74. }
  75. utils.postRecommentShowData(SubLocation.isMoreGame);
  76. }
  77. public init(jumpList: any) {
  78. this._jumpList = jumpList;
  79. this._dataDirty = true;
  80. if (this._jumpList && this._jumpList.length > 0) {
  81. this._initWidget();
  82. this.listView.numItems = this._jumpList.length;
  83. } else {
  84. cc.warn("交叉推广数据为null, 6元素交叉推广组件不显示!");
  85. this.node.destroy();
  86. }
  87. }
  88. public show() {
  89. this.node.active = true;
  90. // this._panel.x = -this._panel.getContentSize().width;
  91. this._panel.y = 0;
  92. this._panel.runAction(cc.moveBy(0.3, cc.v2(this._panel.getContentSize().width, 0)).easing(cc.easeQuadraticActionOut()));
  93. }
  94. public hide() {
  95. let self = this;
  96. this._panel.runAction(cc.sequence(cc.moveBy(0.3, cc.v2(-this._panel.getContentSize().width, 0)).easing(cc.easeQuadraticActionOut()), cc.callFunc(() => {
  97. self.node.active = false;
  98. })));
  99. }
  100. public onCloseBtnHandler(event: any, data: any) {
  101. this.hide();
  102. }
  103. }