EliminateUIManager.ts 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /*
  2. * @Author: mojunshou 1637302775@qq.com
  3. * @Date: 2025-04-20 10:00:00
  4. * @LastEditors: mojunshou 1637302775@qq.com
  5. * @LastEditTime: 2025-04-19 18:23:18
  6. * @Description: 消除游戏UI管理器
  7. */
  8. import { Button, Label, Node } from "cc";
  9. import { LabelChange } from "db://oops-framework/libs/gui/label/LabelChange";
  10. import { oops } from "db://oops-framework/core/Oops";
  11. import { UIID } from "../../common/config/GameUIConfig";
  12. import { DeviceUtil } from "db://oops-framework/core/utils/DeviceUtil";
  13. import { ServerHandler } from "../../common/manager/ServerHandler";
  14. import { Format } from "../../utils/Format";
  15. import { smc } from "../../common/SingletonModuleComp";
  16. export class EliminateUIManager {
  17. // UI元素
  18. private lab_wxCoin: LabelChange | null = null;
  19. private lab_hbCoin: LabelChange | null = null;
  20. private lab_score: Label | null = null;
  21. private lab_taget: Label | null = null;
  22. private lab_total: Label | null = null;
  23. private lab_goldNum: Label | null = null;
  24. private lab_doubleTime: Label | null = null;
  25. private autoBtn: Button | null = null;
  26. // 游戏数据
  27. private score: number = 0;
  28. private money: number = 0;
  29. private cash: number = 0;
  30. private targetScore: number = 0;
  31. private doubleSpeedTime: number = 0;
  32. private eliminateTotal: number = 0;
  33. private autoState: boolean = false;
  34. // 福利弹窗类型
  35. private popupType: string = "";
  36. constructor(
  37. lab_wxCoin: LabelChange,
  38. lab_hbCoin: LabelChange,
  39. lab_score: Label,
  40. lab_taget: Label,
  41. lab_total: Label,
  42. lab_goldNum: Label,
  43. lab_doubleTime: Label,
  44. autoBtn: Button
  45. ) {
  46. this.lab_wxCoin = lab_wxCoin;
  47. this.lab_hbCoin = lab_hbCoin;
  48. this.lab_score = lab_score;
  49. this.lab_taget = lab_taget;
  50. this.lab_total = lab_total;
  51. this.lab_goldNum = lab_goldNum;
  52. this.lab_doubleTime = lab_doubleTime;
  53. this.autoBtn = autoBtn;
  54. }
  55. /**
  56. * 初始化数据
  57. */
  58. public initData(): void {
  59. this.score = 0;
  60. this.targetScore = 0;
  61. this.money = 0;
  62. this.cash = 0;
  63. this.autoState = false;
  64. this.eliminateTotal = 0;
  65. }
  66. /**
  67. * 设置数据
  68. */
  69. public setData(): void {
  70. this.score = smc.game.GameModel.curScore;
  71. this.money = smc.account.AccountModel.wxCoin;
  72. this.cash = smc.account.AccountModel.hbCoin;
  73. this.targetScore = smc.game.GameModel.targetScore;
  74. this.popupType = smc.game.GameModel.popupType;
  75. this.updateLabels();
  76. }
  77. /**
  78. * 更新标签显示
  79. */
  80. private updateLabels(): void {
  81. if (this.lab_score) {
  82. this.lab_score.string = this.score.toString();
  83. }
  84. if (this.lab_wxCoin) {
  85. this.lab_wxCoin.string = Format.formatWxCoin(this.money);
  86. }
  87. if (this.lab_hbCoin) {
  88. this.lab_hbCoin.string = Format.formatRedPacketCoin(this.cash);
  89. }
  90. if (this.lab_taget) {
  91. this.lab_taget.string = this.targetScore.toString();
  92. }
  93. if (this.lab_goldNum) {
  94. this.lab_goldNum.string = smc.account.AccountModel.goldCoin.toString();
  95. }
  96. }
  97. /**
  98. * 更新游戏分数
  99. */
  100. public updateGameScore(newScore: number): void {
  101. this.score = newScore;
  102. if (this.lab_score) {
  103. this.lab_score.string = this.score.toString();
  104. }
  105. if (this.score >= this.targetScore) {
  106. // 弹出通关奖励界面
  107. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  108. ServerHandler.inst.getGameAwardInfo();
  109. } else {
  110. console.log("打开通关奖励");
  111. oops.gui.open(UIID.GamePass);
  112. }
  113. }
  114. }
  115. /**
  116. * 更新消除总数
  117. */
  118. public updateEliminateTotal(count: number): void {
  119. this.eliminateTotal += count;
  120. console.log("消除总数", this.eliminateTotal);
  121. if (this.lab_total) {
  122. this.lab_total.string = this.eliminateTotal.toString();
  123. }
  124. }
  125. /**
  126. * 更新金币值
  127. */
  128. public updateCoin(): void {
  129. this.money = smc.account.AccountModel.wxCoin;
  130. this.cash = smc.account.AccountModel.hbCoin;
  131. if (this.lab_wxCoin) {
  132. this.lab_wxCoin.string = Format.formatWxCoin(this.money);
  133. }
  134. if (this.lab_hbCoin) {
  135. this.lab_hbCoin.string = Format.formatRedPacketCoin(this.cash);
  136. }
  137. }
  138. /**
  139. * 初始化按钮状态
  140. */
  141. public initButtonState(state: boolean): void {
  142. if (this.autoBtn) {
  143. const on = this.autoBtn.node.getChildByName("on");
  144. if (on) {
  145. on.active = state;
  146. }
  147. const off = this.autoBtn.node.getChildByName("off");
  148. if (off) {
  149. off.active = !state;
  150. }
  151. this.autoState = state;
  152. }
  153. }
  154. /**
  155. * 打开特定视图
  156. */
  157. public openView(viewId: string): void {
  158. switch (viewId) {
  159. case "openRedBagView":
  160. oops.gui.open(UIID.RedPacketWithdraw);
  161. break;
  162. case "openPassView":
  163. oops.gui.open(UIID.GamePass);
  164. break;
  165. case "openDoubleSurprise":
  166. oops.gui.open(UIID.DoubleRewards);
  167. break;
  168. case "openRebateView":
  169. oops.gui.open(UIID.CashRebate);
  170. break;
  171. case "openCashWithdrawalView":
  172. oops.gui.open(UIID.WithSussce); // 提现成功
  173. break;
  174. case "openWechatWithdrawalView":
  175. oops.gui.open(UIID.WechatWithdraw); // 微信提现页
  176. break;
  177. case "openDoubleSpeedView":
  178. oops.gui.open(UIID.DoubleSpeed);
  179. break;
  180. case "openRecordView":
  181. oops.gui.open(UIID.WithdrawRecord);
  182. break;
  183. }
  184. }
  185. /**
  186. * 更新福利点
  187. */
  188. public updateWelfarePoint(): void {
  189. switch (this.popupType) {
  190. case "weal_1":
  191. oops.gui.open(UIID.WarmReminder);
  192. ServerHandler.inst.GetGuideInfo();
  193. break;
  194. case "weal_2":
  195. oops.gui.open(UIID.WelfareTwo);
  196. ServerHandler.inst.GetGuideInfo();
  197. break;
  198. case "weal_3":
  199. oops.gui.open(UIID.WelfareThree);
  200. break;
  201. }
  202. if (smc.game.GameModel.curLevelConfig) {
  203. if (smc.game.GameModel.curLevelConfig.eventType && smc.game.GameModel.curLevelConfig.eventType === "SIGN_POINT") {
  204. // 展示提现信息
  205. oops.gui.open(UIID.ReservePopup);
  206. }
  207. }
  208. }
  209. /**
  210. * 更新二倍速时间
  211. */
  212. public updateDoubleSpeedTime(time: number): void {
  213. if (!this.lab_doubleTime) return;
  214. if (time <= 0) {
  215. this.lab_doubleTime.string = "二倍速";
  216. return;
  217. }
  218. const minutes = Math.floor(time / 60);
  219. const seconds = time % 60;
  220. const formattedTime = `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;
  221. this.lab_doubleTime.string = formattedTime;
  222. }
  223. /**
  224. * 获取消除总数
  225. */
  226. public getEliminateTotal(): number {
  227. return this.eliminateTotal;
  228. }
  229. /**
  230. * 获取分数
  231. */
  232. public getScore(): number {
  233. return this.score;
  234. }
  235. /**
  236. * 设置分数
  237. */
  238. public setScore(score: number): void {
  239. this.score = score;
  240. this.updateLabels();
  241. }
  242. /**
  243. * 获取目标分数
  244. */
  245. public getTargetScore(): number {
  246. return this.targetScore;
  247. }
  248. /**
  249. * 获取自动状态
  250. */
  251. public getAutoState(): boolean {
  252. return this.autoState;
  253. }
  254. /**
  255. * 设置自动状态
  256. */
  257. public setAutoState(state: boolean): void {
  258. this.autoState = state;
  259. this.initButtonState(state);
  260. }
  261. /**
  262. * 游戏设置按钮点击
  263. */
  264. public onSettingBtnClick(): void {
  265. oops.gui.open(UIID.Setting);
  266. }
  267. /**
  268. * 微信提现按钮点击
  269. */
  270. public onWithdrawBtnClick(): void {
  271. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  272. ServerHandler.inst.getWechatTxInfo();
  273. } else {
  274. oops.gui.open(UIID.WechatWithdraw);
  275. }
  276. }
  277. /**
  278. * 红包提现按钮点击
  279. */
  280. public onAwardBtnClick(): void {
  281. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  282. ServerHandler.inst.getHbTxInfo();
  283. } else {
  284. oops.gui.open(UIID.RedPacketWithdraw);
  285. }
  286. }
  287. /**
  288. * 二倍速按钮点击
  289. */
  290. public onDoubleBtnClick(): void {
  291. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  292. ServerHandler.inst.getDoubleSpeedTime();
  293. } else {
  294. oops.gui.open(UIID.DoubleSpeed);
  295. }
  296. }
  297. }