YZ_GameExitDialog.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import { utils } from "./Utils";
  2. import QCrossWidgetItem from "./QCrossWidgetItem";
  3. import { SubLocation } from "./YZ_Constant";
  4. const { ccclass, property } = cc._decorator;
  5. @ccclass
  6. export default class YZ_GameExitDialog extends cc.Component {
  7. private _jumpList: any = null;
  8. private _items: QCrossWidgetItem[] = [];
  9. _pageView: cc.PageView = null;
  10. _pageItem: cc.Node = null;
  11. _pageRecItem: cc.Node = null;
  12. _btnCanel: cc.Node = null;
  13. _btnOk: cc.Node = null;
  14. _panel: cc.Node = null;
  15. public nativeData: any = null;
  16. _nativeIsShow: boolean = false;
  17. onLoad() {
  18. this._panel = this.node.getChildByName("Panel");
  19. this._pageView = this._panel.getChildByName("PageView").getComponent(cc.PageView);
  20. this._pageItem = this._pageView.content.getChildByName("Panel");
  21. this._pageRecItem = this._pageItem.children[0];
  22. this._pageView.content.removeAllChildren();
  23. this._btnCanel = this._panel.getChildByName("btnCancel");
  24. this._btnOk = this._panel.getChildByName("btnOk");
  25. if (utils.otherConfig && utils.otherConfig.group) {
  26. this.node.group = utils.otherConfig.group;
  27. }
  28. let ratio: number = 1;
  29. if (cc.winSize.height < cc.winSize.width) {
  30. // 横屏游戏
  31. ratio = cc.winSize.width / 1920 * 0.7;
  32. } else {
  33. ratio = cc.winSize.width / 1080;
  34. }
  35. this._panel.scale = ratio;
  36. }
  37. start() {
  38. this._jumpList = utils.getRecommondGameList();
  39. if (this._jumpList && this._jumpList.length > 0) {
  40. this._initWidget();
  41. }
  42. }
  43. hideLastNode() {
  44. for (let i = 5; i > 2; i--) {
  45. this._items[i].node.active = false;
  46. }
  47. }
  48. onBtnCanelHandler(event: cc.Event, data: any) {
  49. utils.showLog("点击取消按钮!");
  50. this.node.destroy();
  51. }
  52. onBtnOkHandler(event: cc.Event, data: any) {
  53. utils.showLog("点击确定按钮!");
  54. utils.Tool_Native.GameExit();
  55. }
  56. private _initWidget() {
  57. utils.postRecommentShowData(SubLocation.isGameExitDialog);
  58. let totalPage: number = Math.floor(this._jumpList.length / 6);
  59. // utils.showLog(`qcrosswidget >>> totalPage = ${totalPage}`);
  60. utils.showLog(`qcrosswidget >>> totalPage = ${totalPage}`);
  61. let indx: number = 0;
  62. for (let i = 0; i < totalPage; i++) {
  63. let page = cc.instantiate(this._pageItem);
  64. page.removeAllChildren();
  65. this._pageView.addPage(page);
  66. for (let j = 0; j < 6; j++) {
  67. if (!this._jumpList[indx]) break;
  68. let tempNode = cc.instantiate(this._pageRecItem);
  69. page.addChild(tempNode);
  70. let qcrossWidgetItem: QCrossWidgetItem = tempNode.getComponent("QCrossWidgetItem");
  71. qcrossWidgetItem._location = SubLocation.isStatement;
  72. let data = this._jumpList[indx];
  73. tempNode.getComponent("QCrossWidgetItem").init(data);
  74. indx++;
  75. }
  76. }
  77. this.autoRefrshPageView();
  78. // let idx: number = 0;
  79. // for (let i = 0; i < this._jumpList.length; i++) {
  80. // let data: any = this._jumpList[i];
  81. // if (data && data.logo) {
  82. // let itemIdx: number = idx;
  83. // if (itemIdx >= this._items.length) {
  84. // return;
  85. // }
  86. // idx++;
  87. // this._items[itemIdx].init(data);
  88. // }
  89. // }
  90. }
  91. autoRefrshPageView() {
  92. this.unscheduleAllCallbacks();
  93. // utils.showLog(">>>>>>> autoRefrshPageView");
  94. let interval = 3;
  95. if (utils.ServerConfig && utils.ServerConfig.statement_auto_refresh) {
  96. interval = utils.ServerConfig.statement_auto_refresh;
  97. }
  98. utils.showLog(`退出弹窗组件${interval}秒自动刷新`);
  99. this.schedule(() => {
  100. let count = this._pageView.getPages().length;
  101. let index = this._pageView.getCurrentPageIndex();
  102. index = ((index < count) && (index + 1 !== count)) ? (index + 1) : 0;
  103. if (index == 0) {
  104. this._pageView.scrollToPage(index, 0);
  105. } else {
  106. this._pageView.scrollToPage(index, 2);
  107. }
  108. }, interval); //10秒一换
  109. }
  110. }