1
0

UIGetAward.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import { AwardType, EAdType, Prop } from "../data/Define";
  2. import UIBase from "../fgui/core/UIBase";
  3. import ui_AwardItem from "../fgui/res/game/ui_AwardItem";
  4. import ui_UIGetAward from "../fgui/res/game/ui_UIGetAward";
  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 UIGetAward extends UIBase {
  10. public ui: ui_UIGetAward;
  11. //
  12. public awardArr: Array<AwardType>;
  13. public showTriple: boolean = true;
  14. public callback: Function;
  15. public constructor() {
  16. super();
  17. }
  18. protected onConstructor(): void {
  19. this.ui = ui_UIGetAward.createInstance();
  20. this.contentPane = this.ui;
  21. this.isEject = false;
  22. this.addUIClick(this.ui.btnNode.tripleBtn, this.tripleGetAward);
  23. this.addUIClick(this.ui.btnNode.normalBtn, this.normalGetAward);
  24. //
  25. this.ui.myList.itemRenderer = Laya.Handler.create(this, this.renderItem, null, false);
  26. }
  27. public show(arr: Array<AwardType>, showTriple, callback): void {
  28. super.show();
  29. this.ui.t0.play();
  30. this.ui.eftNode.visible = true;
  31. this.ui.eftNode.t0.play(Laya.Handler.create(this, () => {
  32. this.ui.eftNode.visible = false;
  33. }), 1, 0, 0, 0.9);
  34. //
  35. this.awardArr = arr;
  36. this.showTriple = showTriple;
  37. this.callback = callback;
  38. //
  39. this.ui.btnNode.c1.selectedIndex = this.showTriple ? 0 : 1;
  40. this.ui.myList.numItems = arr.length;
  41. //
  42. xGame.soundMgr.playSound("getaward");
  43. }
  44. updateSelf(index, obj: ui_AwardItem) {
  45. let temp: AwardType = this.awardArr[index];
  46. let icon = this.getIcon(temp.type);
  47. let str = icon;
  48. if (temp.type > 2) {
  49. str = "s" + icon;
  50. }
  51. obj.myIcon.url = xGame.common.getGameIconUrl(str);
  52. obj.myIcon.rotation = 0;
  53. obj.numTxt.text = temp.num + "";
  54. obj.numTxt.visible = temp.type > 2 ? false : true;
  55. obj.nameTxt.text = this.getNameStr(temp.type);
  56. }
  57. renderItem(index, obj: ui_AwardItem) {
  58. this.updateSelf(index, obj);
  59. }
  60. public tripleGetAward() {
  61. console.log('zh:qjff_AD_for_uigetAward')
  62. // GlobalManager.instance.registerMethod('xxxxx',this.xxxxx);
  63. // JSBridgeUtils.instance.showRewardAd('xxxxx');
  64. if (Laya.Browser.onAndroid) {
  65. let boo = JSBridgeUtils.instance.getNetworkAvailable();
  66. if (!boo) {
  67. JSBridgeUtils.instance.showToast2("Network error, reward unavailable");
  68. return;
  69. }
  70. }
  71. if (JSBridgeUtils.instance.showRewardAd('qjff_AD_for_uigetAward')) {
  72. } else {
  73. console.log('zh:AD 失败,直接发放奖励')
  74. this.qjff_AD_for_uigetAward();
  75. }
  76. // Moyu.showVideoAd(() => {
  77. // this.getAward(3);
  78. // }, EAdType.triple)
  79. }
  80. public qjff_AD_for_uigetAward() {
  81. this.getAward(3);
  82. }
  83. public normalGetAward() {
  84. if (PlatMgr.isMisVideo())
  85. this.tripleGetAward()
  86. else
  87. this.getAward();
  88. }
  89. public getAward(times = 1) {
  90. this.hide();
  91. for (let index = 0; index < this.awardArr.length; index++) {
  92. this.awardArr[index].num *= times;
  93. }
  94. this.callback && this.callback(times != 1);
  95. }
  96. public getIcon(type) {
  97. switch (type) {
  98. case Prop.diamond:
  99. return "ty_zs";
  100. case Prop.coin:
  101. return "ty_jb";
  102. case Prop.gan1:
  103. return "qg1";
  104. case Prop.gan2:
  105. return "qg2";
  106. case Prop.gan3:
  107. return "qg3";
  108. case Prop.gan4:
  109. return "qg4";
  110. default:
  111. break;
  112. }
  113. }
  114. public getNameStr(type) {
  115. switch (type) {
  116. case Prop.diamond:
  117. return "Diamond";
  118. case Prop.coin:
  119. return "Coins";
  120. case Prop.gan1:
  121. case Prop.gan2:
  122. case Prop.gan3:
  123. case Prop.gan4:
  124. return cfgTable.ballrodData[type - 1].name;
  125. default:
  126. break;
  127. }
  128. }
  129. }
  130. UIGetAward.uiName = "UIGetAward"