UITry.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import DataMgr from "../data/DataMgr";
  2. import { EAdType } from "../data/Define";
  3. import UIBase from "../fgui/core/UIBase";
  4. import ui_UITry from "../fgui/res/game/ui_UITry";
  5. import PlatMgr from "../game/PlatMgr";
  6. import { xGame } from "../xGame";
  7. import GlobalManager from "../utils/GlobalManager";
  8. import JSBridgeUtils from "../utils/JSBridgeUtils";
  9. export default class UITry extends UIBase {
  10. protected ui: ui_UITry;
  11. private closeTime = 0;
  12. private closeNum = 0;
  13. private skillUrl = xGame.common.skillIconList;
  14. public constructor() {
  15. super();
  16. }
  17. protected onConstructor(): void {
  18. this.ui = ui_UITry.createInstance();
  19. this.contentPane = this.ui;
  20. this.addUIClick(this.ui.myNode.cancelBtn, this.onCancel);
  21. this.addUIClick(this.ui.myNode.videoBtn, this.onTry);
  22. }
  23. public show(): void {
  24. super.show();
  25. this.closeNum = 0;
  26. this.closeTime = 15;
  27. this.ui.t0.play();
  28. PlatMgr.showRateBanner();
  29. this.ui.myNode.txtTime.text = this.closeTime.toString();
  30. Laya.timer.loop(1000, this, this.updateTime);
  31. //
  32. let iconStr = this.skillUrl[xGame.common.curPlayerSkillType];
  33. this.ui.myNode.n29.skillicon.url = xGame.common.getGameIconUrl(iconStr);
  34. //
  35. xGame.common.gameMgr.gamePause = true;
  36. //
  37. }
  38. updateTime() {
  39. if (this.closeTime > 1) {
  40. this.closeTime--;
  41. this.ui.myNode.txtTime.text = this.closeTime.toString();
  42. }
  43. else
  44. this.hide();
  45. }
  46. public hide() {
  47. Laya.timer.clearAll(this);
  48. Moyu.showBannerAd(false);
  49. super.hide();
  50. //
  51. xGame.common.gameMgr.gamePause = false;
  52. }
  53. onTry() {
  54. console.log('zh:qjff_AD_for_uitry')
  55. // GlobalManager.instance.registerMethod('xxxxx',this.xxxxx);
  56. // JSBridgeUtils.instance.showRewardAd('xxxxx');
  57. if (JSBridgeUtils.instance.showRewardAd('qjff_AD_for_uitry')) {
  58. } else {
  59. console.log('zh:AD 失败,直接发放奖励')
  60. this.qjff_AD_for_uitry();
  61. }
  62. // //试用
  63. // Moyu.showVideoAd(() => {
  64. // let select = xGame.common.curPlayerSkillType
  65. // DataMgr.gameData.trySkill = select; //当前试用技能ID
  66. // DataMgr.gameData.tryTime = Laya.timer.currTimer + 300000;
  67. // DataMgr.saveGameData();
  68. // DataMgr.setBigSkill(select, 1);
  69. // xGame.showTip("Trial Successful");//试用成功
  70. // this.hide();
  71. // }, EAdType.try);
  72. }
  73. public qjff_AD_for_uitry() {
  74. let select = xGame.common.curPlayerSkillType
  75. DataMgr.gameData.trySkill = select; //当前试用技能ID
  76. DataMgr.gameData.tryTime = Laya.timer.currTimer + 300000;
  77. DataMgr.saveGameData();
  78. DataMgr.setBigSkill(select, 1);
  79. xGame.showTip("Trial Successful");//试用成功
  80. this.hide();
  81. }
  82. onCancel() {
  83. if (this.closeNum > 0) {
  84. this.closeNum--;
  85. if (this.closeNum < 2)
  86. this.hide();
  87. return;
  88. }
  89. else if (PlatMgr.getRand() < PlatMgr.tryVideoRate) {
  90. this.onTry();
  91. }
  92. else if (PlatMgr.getRand() < PlatMgr.tryClose3Rate) {
  93. this.closeNum = 3;
  94. }
  95. else
  96. this.hide();
  97. }
  98. }
  99. UITry.uiName = "UITry";