VerticalRecommentPanel.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import { utils } from "./Utils";
  2. import RecommendGamesNode from "./RecommendGamesNode";
  3. import { SubLocation } from "./YZ_Constant";
  4. import PlatUtils from "./PlatUtils";
  5. import GameItem from "./GameItem";
  6. import CompatibleTool from "./CompatibleTool";
  7. const { ccclass, property } = cc._decorator;
  8. @ccclass
  9. export default class VerticalRecommentPanel extends cc.Component {
  10. _recommendNode: cc.Node = null;
  11. _isInit: boolean = false;
  12. _gameList: Array<GameItem> = [];
  13. _data: any = null;
  14. onLoad() {
  15. this._recommendNode = cc.find("Panel/RecommendGamesNode", this.node);
  16. this._recommendNode.active = false;
  17. for (let i = 0; i < this._recommendNode.childrenCount; i++) {
  18. let gameItem: GameItem = this._recommendNode.children[i].getComponent("GameItem");
  19. this._gameList.push(gameItem);
  20. }
  21. }
  22. onEnable() {
  23. utils.registerServerInitEvent(() => {
  24. this._initWidget();
  25. }, this);
  26. }
  27. onDisable() {
  28. utils.unregisterServerInitEvent(this);
  29. }
  30. _initWidget() {
  31. if (this._isInit) return;
  32. let valid: boolean = true;
  33. if (utils.isVerticalRecommentPanel()) {
  34. if (PlatUtils.IsDouyin) {
  35. if (!utils.Tool_Douyin.isShowMoreGamesModal()) {
  36. this.node.destroy();
  37. }
  38. }
  39. this._data = utils.getRecommondGameList();
  40. if (this.node.parent.getComponentsInChildren(VerticalRecommentPanel).length > 1) {
  41. var temp = []
  42. for (var i = this._data.length - 1; i >= 0; i--) {
  43. temp.push(this._data[i]);
  44. }
  45. this._data = temp;
  46. }
  47. if (this._data) {
  48. if (this._data.length > 0) {
  49. this._isInit = true;
  50. this._initData();
  51. this._recommendNode.active = true;
  52. this.schedule(this._initData, 3)
  53. } else {
  54. console.warn("交叉推广数据长度为0");
  55. valid = false;
  56. }
  57. } else {
  58. console.warn("交叉推广数据为null!");
  59. valid = false;
  60. }
  61. }
  62. if (!valid) {
  63. this.node.destroy();
  64. }
  65. }
  66. _curIndex: number = 0;
  67. _initData() {
  68. this._gameList.forEach(gameItem => {
  69. if (this._curIndex > this._data.length - 1) {
  70. this._curIndex = 0;
  71. }
  72. gameItem.init(this._data[this._curIndex], SubLocation.isVerticalPanel);
  73. let duration = 0.03;
  74. if (CompatibleTool.engineVersion >= 220) {
  75. // let action = cc.repeat(cc.sequence(cc.rotateTo(duration, 85), cc.rotateTo(duration, 90), cc.rotateTo(duration, 95), cc.rotateTo(duration, 90)), 5);
  76. // gameItem.node.runAction(action);
  77. //@ts-ignore
  78. cc.tween(gameItem.node)
  79. //@ts-ignore
  80. .repeat(5, cc.tween()
  81. .to(duration, { angle: 85 })
  82. .to(duration, { angle: 90 })
  83. .to(duration, { angle: 95 })
  84. .to(duration, { angle: 90 })
  85. )
  86. .start();
  87. } else {
  88. let action = cc.repeat(cc.sequence(cc.rotateTo(duration, -85), cc.rotateTo(duration, -90), cc.rotateTo(duration, -95), cc.rotateTo(duration, -90)), 5);
  89. gameItem.node.runAction(action);
  90. }
  91. this._curIndex++;
  92. });
  93. }
  94. }