| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- /*
- * @Author: mojunshou 1637302775@qq.com
- * @Date: 2025-04-20 10:00:00
- * @LastEditors: mojunshou 1637302775@qq.com
- * @LastEditTime: 2025-04-19 18:23:18
- * @Description: 消除游戏UI管理器
- */
- import { Button, Label, Node } from "cc";
- import { LabelChange } from "db://oops-framework/libs/gui/label/LabelChange";
- import { oops } from "db://oops-framework/core/Oops";
- import { UIID } from "../../common/config/GameUIConfig";
- import { DeviceUtil } from "db://oops-framework/core/utils/DeviceUtil";
- import { ServerHandler } from "../../common/manager/ServerHandler";
- import { Format } from "../../utils/Format";
- import { smc } from "../../common/SingletonModuleComp";
- export class EliminateUIManager {
- // UI元素
- private lab_wxCoin: LabelChange | null = null;
- private lab_hbCoin: LabelChange | null = null;
- private lab_score: Label | null = null;
- private lab_taget: Label | null = null;
- private lab_total: Label | null = null;
- private lab_goldNum: Label | null = null;
- private lab_doubleTime: Label | null = null;
- private autoBtn: Button | null = null;
- // 游戏数据
- private score: number = 0;
- private money: number = 0;
- private cash: number = 0;
- private targetScore: number = 0;
- private doubleSpeedTime: number = 0;
- private eliminateTotal: number = 0;
- private autoState: boolean = false;
- // 福利弹窗类型
- private popupType: string = "";
- constructor(
- lab_wxCoin: LabelChange,
- lab_hbCoin: LabelChange,
- lab_score: Label,
- lab_taget: Label,
- lab_total: Label,
- lab_goldNum: Label,
- lab_doubleTime: Label,
- autoBtn: Button
- ) {
- this.lab_wxCoin = lab_wxCoin;
- this.lab_hbCoin = lab_hbCoin;
- this.lab_score = lab_score;
- this.lab_taget = lab_taget;
- this.lab_total = lab_total;
- this.lab_goldNum = lab_goldNum;
- this.lab_doubleTime = lab_doubleTime;
- this.autoBtn = autoBtn;
- }
- /**
- * 初始化数据
- */
- public initData(): void {
- this.score = 0;
- this.targetScore = 0;
- this.money = 0;
- this.cash = 0;
- this.autoState = false;
- this.eliminateTotal = 0;
- }
- /**
- * 设置数据
- */
- public setData(): void {
- this.score = smc.game.GameModel.curScore;
- this.money = smc.account.AccountModel.wxCoin;
- this.cash = smc.account.AccountModel.hbCoin;
- this.targetScore = smc.game.GameModel.targetScore;
- this.popupType = smc.game.GameModel.popupType;
- this.updateLabels();
- }
- /**
- * 更新标签显示
- */
- private updateLabels(): void {
- if (this.lab_score) {
- this.lab_score.string = this.score.toString();
- }
- if (this.lab_wxCoin) {
- this.lab_wxCoin.string = Format.formatWxCoin(this.money);
- }
- if (this.lab_hbCoin) {
- this.lab_hbCoin.string = Format.formatRedPacketCoin(this.cash);
- }
- if (this.lab_taget) {
- this.lab_taget.string = this.targetScore.toString();
- }
- if (this.lab_goldNum) {
- this.lab_goldNum.string = smc.account.AccountModel.goldCoin.toString();
- }
- }
- /**
- * 更新游戏分数
- */
- public updateGameScore(newScore: number): void {
- this.score = newScore;
- if (this.lab_score) {
- this.lab_score.string = this.score.toString();
- }
- if (this.score >= this.targetScore) {
- // 弹出通关奖励界面
- if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
- ServerHandler.inst.getGameAwardInfo();
- } else {
- console.log("打开通关奖励");
- oops.gui.open(UIID.GamePass);
- }
- }
- }
- /**
- * 更新消除总数
- */
- public updateEliminateTotal(count: number): void {
- this.eliminateTotal += count;
- console.log("消除总数", this.eliminateTotal);
- if (this.lab_total) {
- this.lab_total.string = this.eliminateTotal.toString();
- }
- }
- /**
- * 更新金币值
- */
- public updateCoin(): void {
- this.money = smc.account.AccountModel.wxCoin;
- this.cash = smc.account.AccountModel.hbCoin;
- if (this.lab_wxCoin) {
- this.lab_wxCoin.string = Format.formatWxCoin(this.money);
- }
- if (this.lab_hbCoin) {
- this.lab_hbCoin.string = Format.formatRedPacketCoin(this.cash);
- }
- }
- /**
- * 初始化按钮状态
- */
- public initButtonState(state: boolean): void {
- if (this.autoBtn) {
- const on = this.autoBtn.node.getChildByName("on");
- if (on) {
- on.active = state;
- }
- const off = this.autoBtn.node.getChildByName("off");
- if (off) {
- off.active = !state;
- }
- this.autoState = state;
- }
- }
- /**
- * 打开特定视图
- */
- public openView(viewId: string): void {
- switch (viewId) {
- case "openRedBagView":
- oops.gui.open(UIID.RedPacketWithdraw);
- break;
- case "openPassView":
- oops.gui.open(UIID.GamePass);
- break;
- case "openDoubleSurprise":
- oops.gui.open(UIID.DoubleRewards);
- break;
- case "openRebateView":
- oops.gui.open(UIID.CashRebate);
- break;
- case "openCashWithdrawalView":
- oops.gui.open(UIID.WithSussce); // 提现成功
- break;
- case "openWechatWithdrawalView":
- oops.gui.open(UIID.WechatWithdraw); // 微信提现页
- break;
- case "openDoubleSpeedView":
- oops.gui.open(UIID.DoubleSpeed);
- break;
- case "openRecordView":
- oops.gui.open(UIID.WithdrawRecord);
- break;
- }
- }
- /**
- * 更新福利点
- */
- public updateWelfarePoint(): void {
- switch (this.popupType) {
- case "weal_1":
- oops.gui.open(UIID.WarmReminder);
- ServerHandler.inst.GetGuideInfo();
- break;
- case "weal_2":
- oops.gui.open(UIID.WelfareTwo);
- ServerHandler.inst.GetGuideInfo();
- break;
- case "weal_3":
- oops.gui.open(UIID.WelfareThree);
- break;
- }
- if (smc.game.GameModel.curLevelConfig) {
- if (smc.game.GameModel.curLevelConfig.eventType && smc.game.GameModel.curLevelConfig.eventType === "SIGN_POINT") {
- // 展示提现信息
- oops.gui.open(UIID.ReservePopup);
- }
- }
- }
- /**
- * 更新二倍速时间
- */
- public updateDoubleSpeedTime(time: number): void {
- if (!this.lab_doubleTime) return;
- if (time <= 0) {
- this.lab_doubleTime.string = "二倍速";
- return;
- }
- const minutes = Math.floor(time / 60);
- const seconds = time % 60;
- const formattedTime = `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;
- this.lab_doubleTime.string = formattedTime;
- }
- /**
- * 获取消除总数
- */
- public getEliminateTotal(): number {
- return this.eliminateTotal;
- }
- /**
- * 获取分数
- */
- public getScore(): number {
- return this.score;
- }
- /**
- * 设置分数
- */
- public setScore(score: number): void {
- this.score = score;
- this.updateLabels();
- }
- /**
- * 获取目标分数
- */
- public getTargetScore(): number {
- return this.targetScore;
- }
- /**
- * 获取自动状态
- */
- public getAutoState(): boolean {
- return this.autoState;
- }
- /**
- * 设置自动状态
- */
- public setAutoState(state: boolean): void {
- this.autoState = state;
- this.initButtonState(state);
- }
- /**
- * 游戏设置按钮点击
- */
- public onSettingBtnClick(): void {
- oops.gui.open(UIID.Setting);
- }
- /**
- * 微信提现按钮点击
- */
- public onWithdrawBtnClick(): void {
- if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
- ServerHandler.inst.getWechatTxInfo();
- } else {
- oops.gui.open(UIID.WechatWithdraw);
- }
- }
- /**
- * 红包提现按钮点击
- */
- public onAwardBtnClick(): void {
- if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
- ServerHandler.inst.getHbTxInfo();
- } else {
- oops.gui.open(UIID.RedPacketWithdraw);
- }
- }
- /**
- * 二倍速按钮点击
- */
- public onDoubleBtnClick(): void {
- if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
- ServerHandler.inst.getDoubleSpeedTime();
- } else {
- oops.gui.open(UIID.DoubleSpeed);
- }
- }
- }
|