ShareRecordPanel.ts 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. import { utils } from "./Utils";
  2. import { YZ_Reward, BannerLocation, SubLocation } from "./YZ_Constant";
  3. import PlatUtils from "./PlatUtils";
  4. import GameItem from "./GameItem";
  5. import QCrossWidgetItem from "./QCrossWidgetItem";
  6. import CompatibleTool from "./CompatibleTool";
  7. const { ccclass, property } = cc._decorator;
  8. /**
  9. * 分享录屏面板
  10. */
  11. @ccclass
  12. export default class ShareRecordPanel extends cc.Component {
  13. bg: cc.Node = null;
  14. btnOk: cc.Node = null;
  15. btnCancel: cc.Node = null;
  16. glodNode: cc.Node = null;
  17. glodLabel: cc.Label = null;
  18. sharePanel: cc.Node = null;
  19. RecPanel: cc.Node = null;
  20. _panel: cc.Node = null;
  21. _gameList: cc.Node = null;
  22. _originScale: number = 1;
  23. _gameItems: GameItem[] = [];
  24. _jumpList: any = null;
  25. _dataDirty: boolean = false;
  26. _star: cc.Node = null;
  27. private gameItemNode: cc.Node = null;
  28. /**
  29. * 奖励回调
  30. */
  31. rewardCallFunc: Function = null;
  32. /**
  33. * 奖励值
  34. */
  35. rewardValue: number = 0;
  36. onLoad() {
  37. utils.SendEvent("结算前广告-分享弹窗-展示成功!");
  38. this.rewardValue = utils.rewardValue;
  39. this.rewardCallFunc = utils.rewardCallFunc;
  40. this.initUi();
  41. if (cc.winSize.height < cc.winSize.width) {
  42. utils.adManager.HideBanner(BannerLocation.Game);
  43. } else {
  44. utils.adManager.ShowBanner(BannerLocation.Game);
  45. }
  46. if (PlatUtils.IsOPPO) {
  47. if (utils.ServerConfig.st_recomment_is_hide_banner && utils.ServerConfig.st_recomment_is_hide_banner == "true") {
  48. utils.showLog("服务器配置显示互推后隐藏banner >>>");
  49. utils.adManager.HideBanner(BannerLocation.Game);
  50. utils.adManager.HideBanner(BannerLocation.Over);
  51. }
  52. }
  53. }
  54. /**
  55. * 初始化UI
  56. */
  57. protected initUi(): void {
  58. if (utils.otherConfig && utils.otherConfig.group) {
  59. this.node.group = utils.otherConfig.group;
  60. }
  61. this.bg = this.node.getChildByName("Bg");
  62. this.sharePanel = this.bg.getChildByName("SharePanel");
  63. this.RecPanel = this.bg.getChildByName("RecPanel");
  64. if (!PlatUtils.IsOPPO) {
  65. this.sharePanel.active = true;
  66. this.RecPanel.active = false;
  67. this.btnCancel = this.sharePanel.getChildByName("btnCancel");
  68. this.btnOk = this.sharePanel.getChildByName("btnOk");
  69. this.glodNode = this.sharePanel.getChildByName("rewardNode");
  70. this.glodLabel = this.glodNode.getChildByName("goldLbl").getComponent(cc.Label);
  71. utils.showSkipBtn(this.btnCancel);
  72. this.glodLabel.string = "/" + this.rewardValue;
  73. if (this.rewardValue == 0) {
  74. this.glodNode.active = false;
  75. }
  76. } else {
  77. this.sharePanel.active = false;
  78. this.RecPanel.active = true;
  79. this.btnCancel = this.RecPanel.getChildByName("btnCancel");
  80. this._gameList = this.RecPanel.getChildByName("PageView").getComponent(cc.PageView).content.getChildByName("Panel");
  81. this.gameItemNode = this._gameList.children[0];
  82. this._initRecPanel();
  83. utils.showSkipBtn(this.btnCancel);
  84. }
  85. }
  86. private _initRecPanel() {
  87. this._gameList.removeAllChildren();
  88. this._jumpList = utils.getRecommondGameList();
  89. for (let i = 0; i < this._jumpList.length; i++) {
  90. let data: any = this._jumpList[i];
  91. if (data && data.logo) {
  92. let tempNode = cc.instantiate(this.gameItemNode);
  93. let qcrossWidgetItem: QCrossWidgetItem = tempNode.getComponent("QCrossWidgetItem");
  94. qcrossWidgetItem._location = SubLocation.isMoreGame;
  95. qcrossWidgetItem.init(data);
  96. this._gameList.addChild(tempNode);
  97. }
  98. }
  99. }
  100. onDestroy() {
  101. utils.adManager.HideBanner(BannerLocation.Game)
  102. if (utils.shareRecordPanelCloseFunc) {
  103. utils.shareRecordPanelCloseFunc();
  104. utils.shareRecordPanelCloseFunc = null;;
  105. } else {
  106. utils.rewardCloseFunc && utils.rewardCloseFunc();
  107. utils.rewardCloseFunc = null;
  108. }
  109. }
  110. onClose() {
  111. this.bg.runAction(cc.sequence(cc.scaleTo(0.3, 0).easing(cc.easeBackIn()), cc.callFunc(() => {
  112. this.node.destroy();
  113. })));
  114. }
  115. onEnable() {
  116. this.bg.scale = 0;
  117. let ratio: number = 1;
  118. if (cc.winSize.height < cc.winSize.width) {
  119. // 横屏游戏
  120. ratio = cc.winSize.width / 1920 * 0.6;
  121. } else {
  122. ratio = cc.winSize.width / 1080;
  123. }
  124. this.bg.runAction(cc.sequence(cc.scaleTo(0.3, ratio).easing(cc.easeBackOut()), cc.callFunc(() => {
  125. if (this.glodNode && this.glodNode.active == true) {
  126. this.glodNode.runAction(cc.sequence(
  127. cc.moveBy(0.3, CompatibleTool.position(0, +50)),
  128. cc.moveBy(0.3, CompatibleTool.position(0, -50))
  129. ).repeatForever());
  130. }
  131. })));
  132. }
  133. // /**
  134. // * 初始化事件回调
  135. // * @param closeCallFunc
  136. // * @param rewardCallFunc
  137. // */
  138. // init(closeCallFunc: Function, rewardCallFunc: Function, reward: number) {
  139. // this.closeCallFunc = closeCallFunc;
  140. // this.rewardCallFunc = rewardCallFunc;
  141. // this.rewardValue = reward;
  142. // }
  143. onCancelClickListener() {
  144. if (PlatUtils.IsDouyin && utils.ServerConfig && utils.ServerConfig.cancel_btn_is_share && utils.ServerConfig.cancel_btn_is_share == "true") {
  145. utils.showLog("服务器配置取消按钮也会触发分享!");
  146. utils.share(this.rewardFunc.bind(this));
  147. } else {
  148. this.onClose();
  149. }
  150. }
  151. onOkBtnClickListener() {
  152. utils.share(this.rewardFunc.bind(this));
  153. }
  154. // /**
  155. // * 初始化监听事件
  156. // */
  157. // protected initListener(): void {
  158. // console.log("this.btnCancel", this.btnCancel);
  159. // this.btnCancel.on(cc.Node.EventType.TOUCH_END, (event: cc.Event) => {
  160. // this.btnCancel.runAction(cc.sequence(cc.scaleTo(0.1, 0.85), cc.scaleTo(0.1, 1), cc.callFunc(() => {
  161. // // if (utils.Tool_Douyin) {
  162. // if (PlatUtils.IsDouyin && utils.ServerConfig && utils.ServerConfig.cancel_btn_is_share && utils.ServerConfig.cancel_btn_is_share == "true") {
  163. // utils.showLog("服务器配置取消按钮也会触发分享!");
  164. // utils.share(this.rewardFunc.bind(this));
  165. // } else {
  166. // this.onClose();
  167. // }
  168. // // }
  169. // })));
  170. // });
  171. // this.btnOk && this.btnOk.on(cc.Node.EventType.TOUCH_END, (event: cc.Event) => {
  172. // this.btnOk.runAction(cc.sequence(cc.scaleTo(0.1, 0.85), cc.scaleTo(0.1, 1), cc.callFunc(() => {
  173. // utils.share(this.rewardFunc.bind(this));
  174. // })));
  175. // })
  176. // }
  177. /**
  178. * 分享回调
  179. * @param ret
  180. * @param msg
  181. */
  182. rewardFunc(ret, msg) {
  183. if (ret) {
  184. utils.SendEvent("结算前广告-分享弹窗-分享成功!");
  185. let result: YZ_Reward = new YZ_Reward();
  186. result.rewardValue = this.rewardValue;
  187. utils.showMsg("分享成功!奖励:+" + this.rewardValue);
  188. if (this.rewardCallFunc) {
  189. this.rewardCallFunc(result);
  190. }
  191. this.onClose();
  192. } else {
  193. utils.SendEvent("结算前广告-分享弹窗-分享失败!");
  194. utils.showMsg(msg ? msg : "分享失败!");
  195. this.onClose();
  196. }
  197. }
  198. /**
  199. * 初始化数据
  200. */
  201. protected initData(): void {
  202. }
  203. // update (dt) {}
  204. }