UIAddProp.ts 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. import DataMgr from "../data/DataMgr";
  2. import { EAdType, Prop } from "../data/Define";
  3. import UIBase from "../fgui/core/UIBase";
  4. import ui_UIAddProp from "../fgui/res/game/ui_UIAddProp";
  5. import PlatMgr from "../game/PlatMgr";
  6. import { xGame } from "../xGame";
  7. import { UIGame } from "./UIGame";
  8. import UIGameEnd from "./UIGameEnd";
  9. import UILevelDisplay from "./UILevelDisplay";
  10. import UIMain from "./UIMain";
  11. import UISkill from "./UISkill";
  12. import UIMsg from "./UIMsg";
  13. import GlobalManager from "../utils/GlobalManager";
  14. import JSBridgeUtils from "../utils/JSBridgeUtils";
  15. export default class UIAddProp extends UIBase {
  16. protected ui: ui_UIAddProp;
  17. //
  18. public curType: string = "";
  19. public constructor() {
  20. super();
  21. }
  22. protected onConstructor(): void {
  23. this.ui = ui_UIAddProp.createInstance();
  24. this.contentPane = this.ui;
  25. this.isEject = false;
  26. this.addUIClick(this.ui.closeBtn, this.closeSelf);
  27. this.addUIClick(this.ui.myNode.coinBtn, this.switchBtn, ["coin"]);
  28. this.addUIClick(this.ui.myNode.diamondBtn, this.switchBtn, ["diamond"]);
  29. this.updateUI();
  30. this.addUIClick(this.ui.myNode.node1, this.shareGetDiamond);
  31. this.addUIClick(this.ui.myNode.node2, this.videoGetDiamond);
  32. this.addUIClick(this.ui.myNode.node6, this.openPutBallView);
  33. // this.addUIClick(this.ui.myNode.node3, this.convertCoin, [3]);
  34. this.addUIClick(this.ui.myNode.node3, this.videoGetCoin);
  35. this.addUIClick(this.ui.myNode.node4, this.convertCoin, [4]);
  36. this.addUIClick(this.ui.myNode.node5, this.convertCoin, [5]);
  37. }
  38. public show(type): void {
  39. super.show();
  40. //type,0-金币,1-钻石
  41. this.curType = type == 0 ? "coin" : "diamond";
  42. this.switchBtn("");
  43. this.ui.t0.play();
  44. //
  45. this.ui.myNode.node1.c1.selectedIndex = Moyu.isTT ? 0 : 1;
  46. PlatMgr.showInsert(true);
  47. }
  48. public closeSelf() {
  49. this.hide();
  50. }
  51. updateUI() {
  52. let data = cfgTable.moneyData;
  53. let temp: cfgTable.money;
  54. let obj;
  55. for (const key in data) {
  56. temp = data[key];
  57. obj = this.ui.myNode["node" + key];
  58. if (parseInt(key) <= 2) {
  59. //钻石
  60. obj.diamondTxt.text = "+" + temp.num;
  61. }
  62. else {
  63. //金币
  64. obj.coinTxt.text = temp.num;
  65. obj.diamondTxt.text = temp.get.split('_')[1];
  66. }
  67. }
  68. //
  69. this.updateDiamondShare();
  70. }
  71. updateDiamondShare() {
  72. let data = DataMgr.getShareDiamondTimes();
  73. if (data >= xGame.common.maxShareDiamondTimes) {
  74. this.ui.myNode.node1.shareTxt.text = "Available Tomorrow"
  75. this.ui.myNode.node1.touchable = false;
  76. xGame.uiMgr.Show(UIMsg, "Come back tomorrow");
  77. }
  78. else {
  79. this.ui.myNode.node1.shareTxt.text = `(${data}/${xGame.common.maxShareDiamondTimes})`
  80. this.ui.myNode.node1.touchable = true;
  81. }
  82. }
  83. switchBtn(type) {
  84. if (type == "") type = this.curType;
  85. else {
  86. if (this.curType == type) {
  87. return;
  88. }
  89. else {
  90. this.curType = type;
  91. }
  92. }
  93. if (type == "coin") {
  94. this.ui.myNode.coinBtn.c1.selectedIndex = 0;
  95. this.ui.myNode.diamondBtn.c1.selectedIndex = 1;
  96. this.ui.myNode.coinBtn.displayObject.zOrder = 10;
  97. this.ui.myNode.diamondBtn.displayObject.zOrder = 9;
  98. //
  99. this.ui.myNode.c1.selectedIndex = 0;
  100. }
  101. else {
  102. this.ui.myNode.coinBtn.c1.selectedIndex = 1;
  103. this.ui.myNode.diamondBtn.c1.selectedIndex = 0;
  104. this.ui.myNode.coinBtn.displayObject.zOrder = 9;
  105. this.ui.myNode.diamondBtn.displayObject.zOrder = 10;
  106. //
  107. this.ui.myNode.c1.selectedIndex = 1;
  108. }
  109. }
  110. convertCoin(index) {
  111. let data = cfgTable.moneyData[index];
  112. let coinNum = data.num;
  113. let str = data.get.split('_')[1];
  114. let needDiamond = parseInt(str);
  115. if (DataMgr.diamondEnough(needDiamond)) {
  116. DataMgr.setDiamond(-needDiamond);
  117. xGame.common.playObjFlyAnim(coinNum, Prop.coin);
  118. //兑换成功
  119. xGame.uiMgr.Show(UIMsg, "Exchange successful!");
  120. }
  121. else {
  122. //钻石不足~
  123. xGame.uiMgr.Show(UIMsg, "Diamond shortage");
  124. //切换到钻石栏
  125. this.switchBtn("diamond");
  126. }
  127. }
  128. videoGetDiamond() {
  129. console.log('zh:qjff_AD_for_uiAddProp_videoGetDiamond')
  130. // GlobalManager.instance.registerMethod('xxxxx',this.xxxxx);
  131. // JSBridgeUtils.instance.showRewardAd('xxxxx');
  132. //需要传递参数
  133. //Laya.LocalStorage.setItem('temp_qjff_AD_for_uiGameEnd_level', level+'');
  134. if (JSBridgeUtils.instance.showRewardAd('qjff_AD_for_uiAddProp_videoGetDiamond')) {
  135. } else {
  136. console.log('zh:AD 失败,直接发放奖励')
  137. this.qjff_AD_for_uiAddProp_videoGetDiamond();
  138. }
  139. // let num = cfgTable.moneyData[2].num;
  140. // Moyu.showVideoAd(() => {
  141. // xGame.common.playObjFlyAnim(num, Prop.diamond);
  142. // this.closeSelf();
  143. // }, EAdType.addDiamond)
  144. }
  145. public qjff_AD_for_uiAddProp_videoGetDiamond() {
  146. let num = cfgTable.moneyData[2].num;
  147. xGame.common.playObjFlyAnim(num, Prop.diamond);
  148. this.closeSelf();
  149. }
  150. videoGetCoin() {
  151. console.log('zh:qjff_AD_for_uiAddProp_videoGetCoin')
  152. // GlobalManager.instance.registerMethod('xxxxx',this.xxxxx);
  153. // JSBridgeUtils.instance.showRewardAd('xxxxx');
  154. //需要传递参数
  155. //Laya.LocalStorage.setItem('temp_qjff_AD_for_uiGameEnd_level', level+'');
  156. if (JSBridgeUtils.instance.showRewardAd('qjff_AD_for_uiAddProp_videoGetCoin')) {
  157. } else {
  158. console.log('zh:AD 失败,直接发放奖励')
  159. this.qjff_AD_for_uiAddProp_videoGetCoin();
  160. }
  161. // Moyu.showVideoAd(() => {
  162. // xGame.common.playObjFlyAnim(2000, Prop.coin);
  163. // this.closeSelf();
  164. // }, EAdType.addCoin)
  165. }
  166. public qjff_AD_for_uiAddProp_videoGetCoin() {
  167. xGame.common.playObjFlyAnim(2000, Prop.coin);
  168. this.closeSelf();
  169. }
  170. shareGetDiamond() {
  171. let times = DataMgr.getShareDiamondTimes();
  172. if (times >= xGame.common.maxShareDiamondTimes) {
  173. console.log('zh: 233333333333 maxShareDiamondTimes')
  174. xGame.uiMgr.Show(UIMsg, "Come back tomorrow");
  175. }
  176. else {
  177. console.log('zh:33333333333333ad')
  178. // if (Moyu.isTT) {
  179. // let num = cfgTable.moneyData[1].num;
  180. // Moyu.shareVideo = ''
  181. // Moyu.shareGame((success) => {
  182. // if (success) {
  183. // xGame.uiMgr.Show(UIMsg, "分享成功!");
  184. // xGame.common.playObjFlyAnim(num, Prop.diamond);
  185. // DataMgr.setShareDiamondTimes(1);
  186. // this.updateDiamondShare();
  187. // }
  188. // else {
  189. // xGame.uiMgr.Show(UIMsg, "分享失败!");
  190. // }
  191. // })
  192. // }
  193. // else {
  194. // //
  195. // Moyu.showVideoAd(() => {//分享
  196. // let diamond = xGame.common.randomNum(50, 100);
  197. // xGame.common.playObjFlyAnim(diamond, Prop.diamond);
  198. // DataMgr.setShareDiamondTimes(1);
  199. // this.updateDiamondShare();
  200. // }, EAdType.randomDiamond)
  201. // //
  202. // }
  203. // Moyu.showVideoAd(() => {//分享
  204. // let diamond = xGame.common.randomNum(50, 100);
  205. // xGame.common.playObjFlyAnim(diamond, Prop.diamond);
  206. // DataMgr.setShareDiamondTimes(1);
  207. // this.updateDiamondShare();
  208. // }, EAdType.randomDiamond)
  209. console.log('zh:qjff_AD_for_uiAddProp_shareGetDiamond')
  210. // GlobalManager.instance.registerMethod('xxxxx',this.xxxxx);
  211. // JSBridgeUtils.instance.showRewardAd('xxxxx');
  212. //需要传递参数
  213. //Laya.LocalStorage.setItem('temp_qjff_AD_for_uiGameEnd_level', level+'');
  214. if (JSBridgeUtils.instance.showRewardAd('qjff_AD_for_uiAddProp_shareGetDiamond')) {
  215. } else {
  216. console.log('zh:AD 失败,直接发放奖励')
  217. this.qjff_AD_for_uiAddProp_shareGetDiamond();
  218. }
  219. }
  220. }
  221. public qjff_AD_for_uiAddProp_shareGetDiamond() {
  222. let diamond = xGame.common.randomNum(50, 100);
  223. xGame.common.playObjFlyAnim(diamond, Prop.diamond);
  224. DataMgr.setShareDiamondTimes(1);
  225. this.updateDiamondShare();
  226. }
  227. //进入摆球达人界面
  228. openPutBallView() {
  229. let end = xGame.uiMgr.getUI(UIGameEnd);
  230. let skill = xGame.uiMgr.getUI(UISkill);
  231. let level = xGame.uiMgr.getUI(UILevelDisplay);
  232. let uigame = xGame.uiMgr.getUI(UIGame);
  233. //
  234. if (end && !end.isHide) {
  235. xGame.uiMgr.Hide(UIGameEnd);
  236. xGame.uiMgr.Show(UIMain);
  237. }
  238. if (skill && !skill.isHide) xGame.uiMgr.Hide(UISkill);
  239. if (uigame && !uigame.isHide) xGame.uiMgr.Hide(UIGame);
  240. //
  241. if (level && !level.isHide) {
  242. //不做操作
  243. }
  244. else {
  245. xGame.uiMgr.Show(UILevelDisplay);
  246. }
  247. //
  248. this.closeSelf();
  249. }
  250. }
  251. UIAddProp.uiName = "UIAddProp";