Browse Source

商店跳转

181404010226 1 month ago
parent
commit
e5b5a36cbe

+ 7 - 11
assets/scripts/CombatSystem/BlockSelection/GameBlockSelection.ts

@@ -761,6 +761,11 @@ export class GameBlockSelection extends Component {
     // ——— 引导期间按钮禁用与颜色处理 ———
     private isGuideRestrictActive(): boolean {
         try {
+            // 仅在第1关启用引导期限制;进入其他关卡一律不限制
+            const sdm = SaveDataManager.getInstance();
+            const currentLevel = sdm ? sdm.getCurrentLevel() : 1;
+            if (currentLevel !== 1) return false;
+
             const guideMgr = NewbieGuideManager.getInstance();
             const isGuide = guideMgr && guideMgr.isNewbieGuideInProgress();
             if (!isGuide) return false;
@@ -822,17 +827,8 @@ export class GameBlockSelection extends Component {
     }
 
     private updateGuideButtonStates = () => {
-        // 每关开始时检测:第一关禁用按钮,其它关卡不禁用
-        let restrict = false;
-        try {
-            const sdm = SaveDataManager.getInstance();
-            const currentLevel = sdm ? sdm.getCurrentLevel() : 1;
-            restrict = currentLevel === 1;
-        } catch (e) {
-            // 获取关卡失败时默认不禁用
-            restrict = false;
-        }
-
+        // 根据引导期与波次实时计算禁用状态(仅第1关的第1/2波禁用)
+        const restrict = this.isGuideRestrictActive();
         this.applyGuideDisabledVisual(this.addCoinButton, restrict);
         this.applyGuideDisabledVisual(this.refreshButton, restrict);
     };

+ 15 - 0
assets/scripts/FourUI/NavBarController.ts

@@ -313,4 +313,19 @@ export class NavBarController extends Component {
     public getCurrentActiveButtonIndex(): number {
         return this.currentActiveButtonIndex;
     }
+
+    /**
+     * 公开方法:直接打开商店面板(忽略按钮锁定)
+     */
+    public openShopPanel(): void {
+        this.switchTo(2);
+    }
+
+    /**
+     * 公开方法:当前是否处于商店面板
+     */
+    public isShopPanelActive(): boolean {
+        const shopPanel = this.panels && this.panels.length > 2 ? this.panels[2] : null;
+        return !!(shopPanel && shopPanel.active);
+    }
 }

+ 27 - 2
assets/scripts/FourUI/TopBarController.ts

@@ -4,6 +4,7 @@ import { SaveDataManager } from '../LevelSystem/SaveDataManager';
 import EventBus, { GameEvents } from '../Core/EventBus';
 import { Audio } from '../AudioManager/AudioManager';
 import { AdManager } from '../Ads/AdManager';
+import { NavBarController } from './NavBarController';
 const { ccclass, property } = _decorator;
 
 @ccclass('TopBarController')
@@ -56,8 +57,32 @@ export class TopBarController extends Component {
   /* 绑定按钮事件 */
   //看广告才能获取的货币
   private bindButtons() {
-    this.moneyAddBtn?.on(Button.EventType.CLICK, () => this.addMoney(100), this);
-    this.diamondAddBtn?.on(Button.EventType.CLICK, () => this.addDiamonds(20), this);
+    // 顶部加号:直接跳转到商店界面;如果已在商店界面则不做任何反馈
+    this.moneyAddBtn?.on(Button.EventType.CLICK, this.onPlusClick, this);
+    this.diamondAddBtn?.on(Button.EventType.CLICK, this.onPlusClick, this);
+  }
+
+  private onPlusClick() {
+    this.openShopIfNotAlready();
+  }
+
+  private openShopIfNotAlready() {
+    const navBarNode = find('Canvas/NavBar');
+    if (!navBarNode) {
+      console.warn('[TopBarController] 未找到 Canvas/NavBar 节点,无法打开商店');
+      return;
+    }
+    const navBar = navBarNode.getComponent(NavBarController);
+    if (!navBar) {
+      console.warn('[TopBarController] NavBarController 未挂载,无法打开商店');
+      return;
+    }
+    // 如果已经是商店面板,什么都不做
+    if (navBar.isShopPanelActive()) {
+      return;
+    }
+    // 直接打开商店面板(忽略按钮锁定状态)
+    navBar.openShopPanel();
   }
 
   /* ================= 业务逻辑 ================= */