Browse Source

遮罩调整

181404010226 1 month ago
parent
commit
2951ab71f2

File diff suppressed because it is too large
+ 1565 - 20
assets/Scenes/GameLevel.scene


+ 9 - 0
assets/scripts/Animations/MoneyAni.ts

@@ -62,6 +62,11 @@ export class MoneyAni extends Component {
     
     private saveDataManager: SaveDataManager = null;
     
+    // 新增:统一派发奖励动画完成事件
+    private emitRewardCompleted(money: number, diamonds: number): void {
+        EventBus.getInstance().emit(GameEvents.REWARD_ANIMATION_COMPLETED, { money, diamonds });
+    }
+    
     onLoad() {
         this.saveDataManager = SaveDataManager.getInstance();
         
@@ -94,12 +99,14 @@ export class MoneyAni extends Component {
         // 如果奖励为0,直接返回不播放动画
         if (coinAmount <= 0 && diamondAmount <= 0) {
             console.log('[MoneyAni] 奖励为0,跳过动画播放');
+            this.emitRewardCompleted(coinAmount, diamondAmount);
             if (onComplete) onComplete();
             return;
         }
         
         if (!this.canvasNode) {
             console.error('[MoneyAni] Canvas节点未设置,请在编辑器中拖拽Canvas节点到canvasNode属性');
+            this.emitRewardCompleted(coinAmount, diamondAmount);
             if (onComplete) onComplete();
             return;
         }
@@ -111,6 +118,7 @@ export class MoneyAni extends Component {
             animationsCompleted++;
             if (animationsCompleted >= totalAnimations) {
                 console.log('[MoneyAni] 所有奖励动画播放完成');
+                this.emitRewardCompleted(coinAmount, diamondAmount);
                 if (onComplete) onComplete();
             }
         };
@@ -129,6 +137,7 @@ export class MoneyAni extends Component {
         
         // 如果没有奖励,直接调用完成回调
         if (totalAnimations === 0) {
+            this.emitRewardCompleted(coinAmount, diamondAmount);
             if (onComplete) onComplete();
         }
     }

+ 127 - 0
assets/scripts/CombatSystem/GainUI.ts

@@ -0,0 +1,127 @@
+import { _decorator, Component, Node, Label, Sprite, Button } from 'cc';
+import EventBus, { GameEvents } from '../Core/EventBus';
+import { JsonConfigLoader } from '../Core/JsonConfigLoader';
+import { BundleLoader } from '../Core/BundleLoader';
+
+const { ccclass, property } = _decorator;
+
+@ccclass('GainUI')
+export class GainUI extends Component {
+    @property(Node) panel: Node = null;               // 弹窗根节点
+    @property(Label) titleLabel: Label = null;        // 标题,如“新武器”
+    @property(Sprite) iconSprite: Sprite = null;      // 武器图标
+    @property(Label) nameLabel: Label = null;         // 武器名称
+    @property(Button) confirmBtn: Button = null;      // 确认按钮
+
+    private weaponsConfig: any = null;
+    private bundleLoader: BundleLoader = null;
+
+    // 等待展示的武器名称队列(来自 UpgradeController 派发的 NEW_WEAPONS_UNLOCKED)
+    private pendingWeapons: string[] = [];
+    // 是否已经完成奖励动画(由 MoneyAni 派发 REWARD_ANIMATION_COMPLETED)
+    private rewardAnimationCompleted = false;
+    // 当前是否正在显示弹窗
+    private showing = false;
+
+    async onLoad() {
+        this.bundleLoader = BundleLoader.getInstance();
+        // 默认隐藏弹窗
+        if (this.panel) this.panel.active = false;
+
+        // 绑定事件
+        EventBus.getInstance().on(GameEvents.NEW_WEAPONS_UNLOCKED, this.onNewWeaponsUnlocked, this);
+        EventBus.getInstance().on(GameEvents.REWARD_ANIMATION_COMPLETED, this.onRewardAnimationCompleted, this);
+
+        // 绑定确认按钮
+        this.confirmBtn?.node.on(Button.EventType.CLICK, this.onConfirm, this);
+    }
+
+    async start() {
+        // 预加载武器配置,便于查找图标与名称
+        try {
+            this.weaponsConfig = await JsonConfigLoader.getInstance().loadConfig('weapons');
+        } catch (err) {
+            console.warn('[GainUI] 加载武器配置失败:', err);
+        }
+    }
+
+    onDestroy() {
+        EventBus.getInstance().off(GameEvents.NEW_WEAPONS_UNLOCKED, this.onNewWeaponsUnlocked, this);
+        EventBus.getInstance().off(GameEvents.REWARD_ANIMATION_COMPLETED, this.onRewardAnimationCompleted, this);
+        this.confirmBtn?.node.off(Button.EventType.CLICK, this.onConfirm, this);
+    }
+
+    // 处理新武器解锁事件
+    private onNewWeaponsUnlocked = (weaponNames: string[]) => {
+        if (!weaponNames || weaponNames.length === 0) return;
+        this.pendingWeapons.push(...weaponNames);
+        this.tryShowPopup();
+    }
+
+    // 处理奖励动画完成事件
+    private onRewardAnimationCompleted = () => {
+        this.rewardAnimationCompleted = true;
+        this.tryShowPopup();
+    }
+
+    // 在满足条件时显示弹窗:需要奖励动画已完成且队列非空
+    private async tryShowPopup() {
+        if (this.showing) return;
+        if (!this.rewardAnimationCompleted) return;
+        if (this.pendingWeapons.length === 0) return;
+
+        const nextName = this.pendingWeapons.shift();
+        await this.renderWeapon(nextName);
+        this.panel.active = true;
+        this.showing = true;
+    }
+
+    // 确认按钮逻辑:继续展示队列中的下一个或关闭弹窗
+    private async onConfirm() {
+        if (this.pendingWeapons.length > 0) {
+            const nextName = this.pendingWeapons.shift();
+            await this.renderWeapon(nextName);
+        } else {
+            this.panel.active = false;
+            this.showing = false;
+        }
+    }
+
+    // 根据武器名称渲染弹窗内容(标题、图标、名称)
+    private async renderWeapon(weaponName: string) {
+        if (this.titleLabel) this.titleLabel.string = '新武器';
+        if (this.nameLabel) this.nameLabel.string = weaponName || '';
+
+        // 查找武器配置,加载图标
+        const config = this.findWeaponConfigByName(weaponName);
+        if (config && config.visualConfig && config.visualConfig.weaponSprites) {
+            let spritePath: string;
+            const sprites = config.visualConfig.weaponSprites;
+            if (typeof sprites === 'string') {
+                spritePath = sprites;
+            } else {
+                spritePath = sprites['I'] || sprites['H-I'] || sprites['L'] || sprites['S'] || sprites['D-T'];
+            }
+            if (spritePath && this.iconSprite) {
+                await this.loadWeaponSprite(this.iconSprite, spritePath);
+            }
+        }
+    }
+
+    private findWeaponConfigByName(name: string) {
+        if (!this.weaponsConfig || !this.weaponsConfig.weapons) return null;
+        return this.weaponsConfig.weapons.find((w: any) => w.name === name);
+    }
+
+    private async loadWeaponSprite(sprite: Sprite, spritePath: string) {
+        const bundlePath = spritePath.replace(/^images\//, '');
+        try {
+            const spriteFrame = await this.bundleLoader.loadSpriteFrame(bundlePath + '/spriteFrame');
+            if (spriteFrame && sprite && sprite.isValid) {
+                sprite.spriteFrame = spriteFrame;
+            }
+        } catch (err) {
+            console.warn(`[GainUI] 加载武器图标失败: ${spritePath}`, err);
+        }
+    }
+}

+ 9 - 0
assets/scripts/CombatSystem/GainUI.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "4.0.24",
+  "importer": "typescript",
+  "imported": true,
+  "uuid": "67a37df5-edf1-4b22-b6a1-9e76e1429ab0",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 3 - 0
assets/scripts/Core/EventBus.ts

@@ -42,6 +42,9 @@ export enum GameEvents {
     CURRENCY_CHANGED = 'CURRENCY_CHANGED',
     UI_PANEL_SWITCHED = 'UI_PANEL_SWITCHED',
     APP_STATE_CHANGED = 'APP_STATE_CHANGED',
+    // 新增:奖励动画与武器解锁事件
+    REWARD_ANIMATION_COMPLETED = 'REWARD_ANIMATION_COMPLETED',
+    NEW_WEAPONS_UNLOCKED = 'NEW_WEAPONS_UNLOCKED',
     
     // UI状态切换事件(根据游戏管理文档)
     ENTER_BATTLE_PREPARATION = 'ENTER_BATTLE_PREPARATION',  // 进入备战阶段

+ 3 - 0
assets/scripts/FourUI/UpgradeSystem/UpgradeController.ts

@@ -950,6 +950,9 @@ export class UpgradeController extends Component {
             
             console.log(`[UpgradeController] 关卡完成后解锁了 ${newlyUnlockedWeapons.length} 个武器:`, newlyUnlockedWeapons);
             
+            // 通知系统有新武器解锁(供 GainUI 等组件使用)
+            EventBus.getInstance().emit(GameEvents.NEW_WEAPONS_UNLOCKED, newlyUnlockedWeapons);
+            
             // 可以在这里添加解锁提示UI
             this.showWeaponUnlockNotification(newlyUnlockedWeapons);
         } else {

Some files were not shown because too many files changed in this diff