UILevelProp.ts 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. import DataMgr from "../data/DataMgr";
  2. import { GameMode, PlaceBallType, POWER_TIME } from "../data/Define";
  3. import UIBase from "../fgui/core/UIBase";
  4. import ui_UILevelProp from "../fgui/res/game/ui_UILevelProp";
  5. import { xGame } from "../xGame";
  6. import MoneyNode from "./item/MoneyNode";
  7. import ShowItem from "./item/ShowItem";
  8. import UIAddProp from "./UIAddProp";
  9. import { UIGame } from "./UIGame";
  10. import UILevelDisplay from "./UILevelDisplay";
  11. import UIMain from "./UIMain";
  12. import UIPower from "./UIPower";
  13. import JSBridgeUtils from "../utils/JSBridgeUtils";
  14. import { LocalStorageManager } from "../utils/LocalStorageManager";
  15. /**
  16. * 摆球达人界面,选择关卡界面
  17. */
  18. export default class UILevelProp extends UIBase {
  19. public ui: ui_UILevelProp;
  20. public moneyNode: MoneyNode;
  21. public level: number;
  22. public data: cfgTable.placeball;
  23. public firstPos: number = 385;
  24. public secondPos: number = 467;
  25. //
  26. public showItemArr: Array<ShowItem> = [];
  27. public constructor() {
  28. super();
  29. // try {
  30. // Laya.loader.load("res/font/arial.ttf", Laya.Handler.create(this, this.onFontLoaded));
  31. // console.log("zh: constructor加载arial字体成功");
  32. // } catch (error) {
  33. // console.log("zh: constructor加载arial字体失败");
  34. // }
  35. }
  36. // private onFontLoaded(): void {
  37. // try {
  38. // Laya.Text.defaultFont = "arial";//仅这样设置无效
  39. // this.ui.myNode.conditionTxt.font = "arial";
  40. // console.log("zh: onFontLoaded 设置arial字体成功");
  41. // } catch (error) {
  42. // console.log("zh: constructor onFontLoaded加载arial字体失败");
  43. // }
  44. // }
  45. public onConstructor(): void {
  46. this.ui = ui_UILevelProp.createInstance();
  47. this.contentPane = this.ui;
  48. this.isEject = false;
  49. this.addUIClick(this.ui.closeBtn, this.hideWin);
  50. this.moneyNode = new MoneyNode(this.ui.moneyNode);
  51. this.addUIClick(this.ui.myNode.startBtn, this.startGame);
  52. this.addUIClick(this.ui.myNode.n_yd_zzq_btn3, this.startGame);
  53. }
  54. public show(level): void {
  55. console.log('zh:show.')
  56. super.show();
  57. this.ui.t1.play();
  58. //
  59. this.level = level;
  60. this.data = cfgTable.placeballData[this.level];
  61. this.updateSelf();
  62. this.showPreView();
  63. this.moneyNode.ui.c1.selectedIndex = 2;
  64. this.moneyNode.checkPowerTime();
  65. this.moneyNode.powerChange();
  66. // this.setGlobalFont("arial", this.ui);
  67. this.yinDaoForLianxi();
  68. this.setGlobalFont(this.ui)
  69. }
  70. /**
  71. * 练习模式 引导 ,他给人家起名字是什么挑战模式
  72. */
  73. yinDaoForLianxi() {
  74. let lianXiGuide = DataMgr.getLianXiGuide();
  75. console.log('zh:lianXiGuide=', lianXiGuide);
  76. if (lianXiGuide === 0) {
  77. this.ui.myNode.n_yd_3.visible = true;
  78. console.log('zh:yinDaoForLianxi 333 set ok')
  79. // let x = this.ui.myNode.startBtn.x;
  80. // let y = this.ui.myNode.startBtn.y;
  81. // this.ui.n_yd_zzq_btn.x = x;
  82. // this.ui.n_yd_zzq_btn.y = y;
  83. // let x1 = this.ui.myNode.x;
  84. // let y1 = this.ui.myNode.y;
  85. // this.ui.n_lc3.x = x1;
  86. // this.ui.n_lc3.y = y1;
  87. } else {
  88. this.ui.myNode.n_yd_3.visible = false;
  89. console.log('zh:无需引导33')
  90. }
  91. }
  92. //展示关卡预览图
  93. showPreView() {
  94. let item: ShowItem;
  95. let data;
  96. for (let index = 0; index < this.showItemArr.length; index++) {
  97. item = this.showItemArr[index];
  98. item.destroySelf();
  99. }
  100. this.showItemArr = [];
  101. let cfgData = xGame.cfgMgr.getPlaceBallByLevel(this.level);
  102. for (const key in cfgData) {
  103. data = cfgData[key];
  104. item = new ShowItem();
  105. item.setParent(this.ui.myNode.displayRoot);
  106. item.setPos(data.x, data.y);
  107. item.setUrl(data.value);
  108. this.showItemArr.push(item);
  109. }
  110. }
  111. updateSelf() {
  112. this.ui.myNode.levelTxt.text = `Level ${this.level}`
  113. this.ui.myNode.modeNode.c1.selectedIndex = this.data.type;
  114. // try {
  115. // this.ui.myNode.conditionTxt.font = "arial";
  116. // console.log('zh: set arial 字体OK')
  117. // } catch (error) {
  118. // console.log('zh: 加载arial字体失败')
  119. // }
  120. if (this.data.ball == -1) {
  121. //打进场上所有球
  122. this.ui.myNode.conditionTxt.text = "Pocket all the balls on the table";
  123. }
  124. else {
  125. this.ui.myNode.conditionTxt.text = `Successfully pocketed ${this.data.ball} balls in total` //`累计打进${this.data.ball}个球`;
  126. }
  127. // 或者动态加载字体后设置
  128. // Laya.loader.load("res/font/arial", laya.utils.Handler.create(this, onFontLoaded));
  129. // function onFontLoaded() {
  130. // // txt.font = "fontName"; // 替换为实际的字体名
  131. // }
  132. let localData = DataMgr.getPlaceBallLevel(this.level);
  133. let getAward = localData.getAward;
  134. let cfg = cfgTable.placeballData[this.level];
  135. //
  136. let coin = this.data.award[0];
  137. let diamond = this.data.award[1];
  138. if (cfg.type == PlaceBallType.challenge) {
  139. diamond = 0;
  140. coin = 100;
  141. }
  142. this.ui.myNode.coinNode.visible = coin == 0 ? false : true;
  143. this.ui.myNode.diamondNode.visible = diamond == 0 ? false : true;
  144. this.ui.myNode.coinNode.numTxt.text = coin + "";
  145. if (cfg.type == PlaceBallType.challenge) {
  146. this.ui.myNode.coinNode.numTxt.text = "";
  147. }
  148. this.ui.myNode.diamondNode.numTxt.text = diamond + "";
  149. if (coin > 0 && diamond > 0) {
  150. this.ui.myNode.diamondNode.x = 385;
  151. this.ui.myNode.coinNode.x = 467;
  152. }
  153. else {
  154. this.ui.myNode.diamondNode.x = 385;
  155. this.ui.myNode.coinNode.x = 385;
  156. }
  157. if (!getAward) {
  158. this.ui.myNode.coinNode.c1.selectedIndex = 0;
  159. this.ui.myNode.diamondNode.c1.selectedIndex = 0;
  160. }
  161. else {
  162. this.ui.myNode.diamondNode.c1.selectedIndex = 1;
  163. this.ui.myNode.coinNode.c1.selectedIndex = 1;
  164. }
  165. }
  166. startGame() {
  167. //let needCoin = xGame.common.enterPlaceBallNeedCoin;
  168. console.log("zh:startGame");
  169. if (DataMgr.powerEnough()) {
  170. console.log('zh:powerEnough =' + DataMgr.powerEnough());
  171. this.ui.myNode.startBtn.touchable = false;
  172. this.ui.myNode.startBtn.powerEft.t0.play(Laya.Handler.create(this, () => {
  173. console.log('zh:startGame dh ')
  174. //
  175. this.ui.myNode.startBtn.touchable = true;
  176. DataMgr.setPower(-1);
  177. xGame.eventMgr.event(POWER_TIME);
  178. //
  179. xGame.common.gameMode = GameMode.placeBall;
  180. xGame.common.placeBallCurLevel = this.level;
  181. xGame.uiMgr.Show(UIGame);
  182. //关闭选择关卡界面和主界面
  183. xGame.uiMgr.Hide(UILevelDisplay);
  184. xGame.uiMgr.Hide(UIMain);
  185. this.logEventForChallenge_level_start(this.level);
  186. this.hideWin();
  187. //
  188. }))
  189. //
  190. console.log('zh:eeeee')
  191. }
  192. else {
  193. let guide = DataMgr.getLianXiGuide();
  194. if (guide == 0 && xGame.common.gameMode == GameMode.placeBall) {
  195. console.log('zh:自动添加2点体力,以便于完成练习引导模式')
  196. DataMgr.setPower(2);
  197. }
  198. console.log('zh:guide = ' + guide)
  199. console.log('zh:xGame.common.gameMode = ' + xGame.common.gameMode)
  200. console.log('zh:powerEnough不足=' + DataMgr.powerEnough());
  201. xGame.uiMgr.Show(UIPower);
  202. }
  203. }
  204. /**
  205. * 埋点challenge模式开始 challenge_level_start
  206. * @param level
  207. */
  208. logEventForChallenge_level_start(level) {
  209. // 埋点:challenge模式开始 challenge_level_start 参数: 1开始了几次 // - 2金币数量// - 3当前是第几关// - 4钻石数量
  210. let keyStr = 'sjmd_challenge_level_start';
  211. let jsonStr = {
  212. "count": 1,
  213. "gold_balance ": DataMgr.getCoin(),
  214. "level": level,
  215. "diamond_balance ": DataMgr.getDiamond()
  216. }
  217. if (LocalStorageManager.hasJosnKey(keyStr)) {
  218. const d = LocalStorageManager.getItem<{ count: number, level: number }>(keyStr);
  219. if (level > d.level) {
  220. jsonStr.count = d.count + 1;
  221. LocalStorageManager.setItem(keyStr, jsonStr);
  222. } else {
  223. //NO
  224. }
  225. } else {
  226. LocalStorageManager.setItem(keyStr, jsonStr);
  227. }
  228. const reqStr = JSON.stringify(jsonStr);
  229. JSBridgeUtils.instance.logEventForAdHaveParams('challenge_level_start', reqStr);
  230. }
  231. public hideWin() {
  232. super.hide();
  233. // 重置start按钮状态
  234. if (this.ui.myNode.startBtn) {
  235. this.ui.myNode.startBtn.touchable = true;
  236. // 停止可能正在播放的动画
  237. if (this.ui.myNode.startBtn.powerEft.t0) {
  238. this.ui.myNode.startBtn.powerEft.t0.stop();
  239. }
  240. }
  241. }
  242. }
  243. UILevelProp.uiName = "UILevelProp";