diff --git a/YuMi/Modules/YMNewHome/View/XPHomePagingViewController.m b/YuMi/Modules/YMNewHome/View/XPHomePagingViewController.m index 031f5153..ca61e499 100644 --- a/YuMi/Modules/YMNewHome/View/XPHomePagingViewController.m +++ b/YuMi/Modules/YMNewHome/View/XPHomePagingViewController.m @@ -24,6 +24,7 @@ @property (nonatomic, strong) UIView *topControlView; @property (nonatomic, strong) UIButton *mineButton; @property (nonatomic, strong) UIButton *recommendButton; +@property (nonatomic, strong) UIButton *layoutButton; @property (nonatomic, strong) UIPageViewController *pageContainer; @property (nonatomic, strong) NSArray *viewControllers; // 存储子视图控制器的数组 @@ -160,6 +161,19 @@ make.trailing.mas_equalTo(self.topControlView).offset(-16); make.width.height.mas_equalTo(28); }]; + + _layoutButton = [UIButton buttonWithType:UIButtonTypeCustom]; + [_layoutButton setImage:kImage(@"room_layout_type_1") forState:UIControlStateNormal]; + [_layoutButton setImage:kImage(@"room_layout_type_2") forState:UIControlStateSelected]; + [_topControlView addSubview:_layoutButton]; + [_layoutButton addTarget:self + action:@selector(didTapLayoutButton) + forControlEvents:UIControlEventTouchUpInside]; + [_layoutButton mas_makeConstraints:^(MASConstraintMaker *make) { + make.centerY.mas_equalTo(searchButton); + make.trailing.mas_equalTo(searchButton.mas_leading).offset(-16); + make.width.height.mas_equalTo(28); + }]; } - (void)displayMineTab { @@ -201,6 +215,10 @@ completion:nil]; } +- (void)didTapLayoutButton { + self.layoutButton.selected = !self.layoutButton.isSelected; +} + #pragma mark - UIPageViewController Delegate & DataSource - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController { return nil; diff --git a/YuMi/Modules/YMRoom/View/AnimationView/RoomAnimationView.m b/YuMi/Modules/YMRoom/View/AnimationView/RoomAnimationView.m index 375f3e09..f3f8604d 100644 --- a/YuMi/Modules/YMRoom/View/AnimationView/RoomAnimationView.m +++ b/YuMi/Modules/YMRoom/View/AnimationView/RoomAnimationView.m @@ -191,6 +191,12 @@ BannerSchedulerDelegate // 🔧 移除:本地开关状态,改为使用 TurboModeStateManager @property (nonatomic, strong) NSString *currentRoomId; // 当前房间 ID +// 🔧 新增:本地开关状态缓存,减少频繁调用 TurboModeStateManager +@property (nonatomic, assign) BOOL cachedGiftEffectsEnabled; +@property (nonatomic, assign) BOOL cachedGlobalGiftScreenEnabled; +@property (nonatomic, assign) BOOL cachedGlobalGameScreenEnabled; +@property (nonatomic, assign) BOOL cachedCpMicEnabled; + @end @implementation RoomAnimationView @@ -221,34 +227,14 @@ BannerSchedulerDelegate NSLog(@"⚠️ 检测到重要动画正在播放,延迟清理"); // 延迟清理,给动画完成的时间 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [self forceCancelAllAnimations]; + [self cancelAllAnimations]; }); return; } - [self forceCancelAllAnimations]; + [self cancelAllAnimations]; } -- (void)forceCancelAllAnimations { - NSLog(@"🔄 强制取消所有动画"); - - // 取消所有 POP 动画 - [self pop_removeAllAnimations]; - - // 取消所有子视图的 POP 动画 - NSArray *containers = @[self.bannerContainer, self.topContainer, self.middleContainer, self.bottomContainer]; - for (UIView *container in containers) { - if (!container) continue; - for (UIView *subview in container.subviews) { - [subview pop_removeAllAnimations]; - } - } - - // 取消所有 UIView 动画 - [UIView setAnimationsEnabled:NO]; - - NSLog(@"🔄 所有动画取消完成"); -} - (void)cleanupAllSubviews { NSLog(@"🔄 清理所有子视图"); @@ -260,12 +246,12 @@ BannerSchedulerDelegate NSLog(@"⚠️ 检测到重要动画正在播放,延迟清理子视图"); // 延迟清理,给动画完成的时间 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [self forceCleanupAllSubviews]; + [self cleanupAllSubviews]; }); return; } - [self forceCleanupAllSubviews]; + [self cleanupAllSubviews]; } - (void)forceCleanupAllSubviews { @@ -503,6 +489,12 @@ BannerSchedulerDelegate name:kTurboCurrentRoomIdSet object:nil]; + // 🔧 新增:监听 Turbo Mode 状态变化通知 + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(handleTurboModeStateChanged:) + name:@"TurboModeStateChanged" + object:nil]; + NSLog(@"🎮 Turbo Mode通知监听设置完成"); } @@ -598,8 +590,8 @@ BannerSchedulerDelegate effectPath:(NSString *)effectPath isCPEnter:(BOOL)isCP { - // 🔧 修改:直接使用 TurboModeStateManager 检查进房特效开关 - if (![[TurboModeStateManager sharedManager] isGiftEffectsEnabledForRoom:self.currentRoomId]) { + // 🔧 修改:使用本地缓存检查进房特效开关 + if (!self.cachedGiftEffectsEnabled) { NSLog(@"🎮 Turbo Mode进房特效已关闭,跳过进房动画"); return; } @@ -728,11 +720,11 @@ BannerSchedulerDelegate return; } - // 🔧 修改:直接使用 TurboModeStateManager 检查 Banner 开关 + // 🔧 优化:统一在 inserBannerModelToQueue 中检查所有开关 if (obj.second == Custom_Message_Sub_General_Floating_Screen_One_Room || obj.second == Custom_Message_Sub_General_Floating_Screen_All_Room) { // 游戏相关banner - if (![[TurboModeStateManager sharedManager] isGlobalGameScreenEnabledForRoom:self.currentRoomId]) { + if (!self.cachedGlobalGameScreenEnabled) { NSLog(@"🎮 Turbo Mode全局游戏屏幕已关闭,跳过游戏banner"); return; } @@ -740,10 +732,18 @@ BannerSchedulerDelegate obj.second == Custom_Message_Sub_Gift_ChannelNotify || obj.second == Custom_Message_Sub_LuckyPackage) { // 礼物相关banner - if (![[TurboModeStateManager sharedManager] isGlobalGiftScreenEnabledForRoom:self.currentRoomId]) { + if (!self.cachedGlobalGiftScreenEnabled) { NSLog(@"🎮 Turbo Mode全局礼物屏幕已关闭,跳过礼物banner"); return; } + } else if (obj.second == Custom_Message_Sub_CP_Gift || + obj.second == Custom_Message_Sub_CP_Upgrade || + obj.second == Custom_Message_Sub_CP_Binding) { + // CP相关banner - 需要检查礼物特效开关 + if (!self.cachedGiftEffectsEnabled) { + NSLog(@"🎮 Turbo Mode礼物特效已关闭,跳过CP banner"); + return; + } } #if 0 @@ -944,12 +944,7 @@ BannerSchedulerDelegate } - (void)receiveRoomGiftBanner:(AttachmentModel *)obj { - // 🔧 修改:直接使用 TurboModeStateManager 检查全局礼物屏幕开关 - if (![[TurboModeStateManager sharedManager] isGlobalGiftScreenEnabledForRoom:self.currentRoomId]) { - NSLog(@"🎮 RoomAnimationView 全局礼物屏幕已关闭,跳过 RoomGiftBanner"); - return; - } - + // 🔧 优化:开关检查已移至 inserBannerModelToQueue 统一处理 [self inserBannerModelToQueue:obj]; } @@ -976,12 +971,7 @@ BannerSchedulerDelegate } - (void)receiveCPEvent:(AttachmentModel *)attachment { - // 🔧 修改:直接使用 TurboModeStateManager 检查礼物特效开关 - if (![[TurboModeStateManager sharedManager] isGiftEffectsEnabledForRoom:self.currentRoomId]) { - NSLog(@"🎮 RoomAnimationView 礼物特效已关闭,跳过CP动画"); - return; - } - + // 🔧 优化:开关检查已移至 inserBannerModelToQueue 统一处理 [self inserBannerModelToQueue:attachment]; } @@ -1177,12 +1167,7 @@ BannerSchedulerDelegate } - (void)receiveLuckGiftBanner:(AttachmentModel *)attachment { - // 🔧 修改:直接使用 TurboModeStateManager 检查全局礼物屏幕开关 - if (![[TurboModeStateManager sharedManager] isGlobalGiftScreenEnabledForRoom:self.currentRoomId]) { - NSLog(@"🎮 RoomAnimationView 全局礼物屏幕已关闭,跳过 LuckyGiftWinningBanner"); - return; - } - + // 🔧 优化:开关检查已移至 inserBannerModelToQueue 统一处理 [self inserBannerModelToQueue:attachment]; } @@ -1228,12 +1213,7 @@ BannerSchedulerDelegate } - (void)receiveGameBanner:(AttachmentModel *)attachment { - // 🔧 修改:直接使用 TurboModeStateManager 检查全局游戏屏幕开关 - if (![[TurboModeStateManager sharedManager] isGlobalGameScreenEnabledForRoom:self.currentRoomId]) { - NSLog(@"🎮 RoomAnimationView 全局游戏屏幕已关闭,跳过 GameBanner"); - return; - } - + // 🔧 优化:开关检查已移至 inserBannerModelToQueue 统一处理 [self inserBannerModelToQueue:attachment]; } @@ -1367,8 +1347,8 @@ BannerSchedulerDelegate #pragma mark - Method: Send Gifts - (void)receiveGiftHandleSendGiftAnimationWith:(GiftReceiveInfoModel *)receiveInfo attachment:(AttachmentModel *)attachment { - // 🔧 修改:直接使用 TurboModeStateManager 检查礼物特效开关 - if (![[TurboModeStateManager sharedManager] isGiftEffectsEnabledForRoom:self.currentRoomId]) { + // 🔧 修改:使用本地缓存检查礼物特效开关 + if (!self.cachedGiftEffectsEnabled) { NSLog(@"🎮 RoomAnimationView 礼物特效已关闭,跳过动画"); return; } @@ -4285,6 +4265,9 @@ BannerSchedulerDelegate - (void)handleTurboGiftEffectsChanged:(NSNotification *)notification { BOOL enabled = [notification.userInfo[@"on"] boolValue]; + // 🔧 新增:更新本地缓存 + self.cachedGiftEffectsEnabled = enabled; + // 如果关闭,清理当前效果 if (!enabled) { [self cleanupGiftEffects]; @@ -4297,6 +4280,9 @@ BannerSchedulerDelegate - (void)handleTurboGlobalGiftScreenChanged:(NSNotification *)notification { BOOL enabled = [notification.userInfo[@"on"] boolValue]; + // 🔧 新增:更新本地缓存 + self.cachedGlobalGiftScreenEnabled = enabled; + // 如果关闭,清理礼物相关 banner if (!enabled) { [self cleanupGiftBanners]; @@ -4309,6 +4295,9 @@ BannerSchedulerDelegate - (void)handleTurboGlobalGameScreenChanged:(NSNotification *)notification { BOOL enabled = [notification.userInfo[@"on"] boolValue]; + // 🔧 新增:更新本地缓存 + self.cachedGlobalGameScreenEnabled = enabled; + // 如果关闭,清理游戏相关 banner if (!enabled) { [self cleanupGameBanners]; @@ -4321,6 +4310,9 @@ BannerSchedulerDelegate - (void)handleTurboCpMicChanged:(NSNotification *)notification { BOOL enabled = [notification.userInfo[@"on"] boolValue]; + // 🔧 新增:更新本地缓存 + self.cachedCpMicEnabled = enabled; + // CP麦位开关的变化由 MicMidpointRectManager 处理,这里只记录日志 NSLog(@"🎮 RoomAnimationView CP麦位开关状态变化: %@", enabled ? @"开启" : @"关闭"); } @@ -4333,13 +4325,79 @@ BannerSchedulerDelegate self.currentRoomId = roomId; // 更新礼物特效开关状态(基于房间信息) - [[TurboModeStateManager sharedManager] updateGiftEffectsForRoom:roomId + [[TurboModeStateManager sharedManager] updateGiftEffectsForRoom:roomId enabled:self.hostDelegate.getRoomInfo.hasAnimationEffect]; + // 🔧 新增:更新本地缓存 + [self updateLocalSwitchCache]; + NSLog(@"🎮 RoomAnimationView: 收到房间ID设置通知,房间ID: %@", roomId); } } +// 🔧 新增:更新本地开关状态缓存 +- (void)updateLocalSwitchCache { + if (!self.currentRoomId) return; + + TurboModeStateManager *manager = [TurboModeStateManager sharedManager]; + self.cachedGiftEffectsEnabled = [manager isGiftEffectsEnabledForRoom:self.currentRoomId]; + self.cachedGlobalGiftScreenEnabled = [manager isGlobalGiftScreenEnabledForRoom:self.currentRoomId]; + self.cachedGlobalGameScreenEnabled = [manager isGlobalGameScreenEnabledForRoom:self.currentRoomId]; + self.cachedCpMicEnabled = [manager isCpMicEnabledForRoom:self.currentRoomId]; + + NSLog(@"🎮 RoomAnimationView: 本地开关缓存已更新 - 礼物特效:%@, 全局礼物:%@, 全局游戏:%@, CP麦位:%@", + self.cachedGiftEffectsEnabled ? @"开启" : @"关闭", + self.cachedGlobalGiftScreenEnabled ? @"开启" : @"关闭", + self.cachedGlobalGameScreenEnabled ? @"开启" : @"关闭", + self.cachedCpMicEnabled ? @"开启" : @"关闭"); +} + +// 🔧 新增:处理 Turbo Mode 状态变化通知 +- (void)handleTurboModeStateChanged:(NSNotification *)notification { + BOOL turboModeEnabled = [notification.userInfo[@"enabled"] boolValue]; + + if (turboModeEnabled) { + // Turbo Mode 开启时,停止所有 banner 和动画 + [self stopAllBannersAndAnimations]; + NSLog(@"🎮 RoomAnimationView: Turbo Mode 已开启,停止所有 banner 和动画"); + } else { + // Turbo Mode 关闭时,恢复正常的 banner 和动画控制 + NSLog(@"🎮 RoomAnimationView: Turbo Mode 已关闭,恢复正常的 banner 和动画控制"); + } +} + +// 🔧 新增:停止所有 banner 和动画 +- (void)stopAllBannersAndAnimations { + // 停止所有 banner + if (self.bannerScheduler) { + [self.bannerScheduler clearQueue]; + [self.bannerScheduler pause]; + } + + // 注意:礼物动画清理由 cleanupGiftEffects 专门处理,避免重复 + + // 停止其他可能的动画 + for (UIView *subview in self.topContainer.subviews) { + if ([subview respondsToSelector:@selector(stopAnimation)]) { + [subview performSelector:@selector(stopAnimation)]; + } + } + + // 停止中间容器的动画 + for (UIView *subview in self.middleContainer.subviews) { + if ([subview respondsToSelector:@selector(stopAnimation)]) { + [subview performSelector:@selector(stopAnimation)]; + } + } + + // 停止底部容器的动画 + for (UIView *subview in self.bottomContainer.subviews) { + if ([subview respondsToSelector:@selector(stopAnimation)]) { + [subview performSelector:@selector(stopAnimation)]; + } + } +} + // 🔧 新增:检查重要动画状态 - (BOOL)hasImportantAnimationPlaying { // 检查 topContainer 中是否有正在播放的重要动画 diff --git a/YuMi/Modules/YMRoom/View/MoreView/Action/XPRoomEffectAction.h b/YuMi/Modules/YMRoom/View/MoreView/Action/XPRoomEffectAction.h index b05f6f88..a24d3320 100644 --- a/YuMi/Modules/YMRoom/View/MoreView/Action/XPRoomEffectAction.h +++ b/YuMi/Modules/YMRoom/View/MoreView/Action/XPRoomEffectAction.h @@ -5,7 +5,7 @@ // Created by P on 2025/9/2. // -#import "../Model/XPRoomMoreMenuAction.h" +#import "XPRoomMoreMenuAction.h" NS_ASSUME_NONNULL_BEGIN diff --git a/YuMi/Modules/YMRoom/View/MoreView/Action/XPTurboModeAction.h b/YuMi/Modules/YMRoom/View/MoreView/Action/XPTurboModeAction.h index a970269b..1dea847d 100644 --- a/YuMi/Modules/YMRoom/View/MoreView/Action/XPTurboModeAction.h +++ b/YuMi/Modules/YMRoom/View/MoreView/Action/XPTurboModeAction.h @@ -5,7 +5,7 @@ // Created by Linus on 2025/1/13. // -#import "../Model/XPRoomMoreMenuAction.h" +#import "XPRoomMoreMenuAction.h" @class RoomInfoModel; diff --git a/YuMi/Modules/YMRoom/View/MoreView/Action/XPTurboModeAction.m b/YuMi/Modules/YMRoom/View/MoreView/Action/XPTurboModeAction.m index b25e0f41..02a7179b 100644 --- a/YuMi/Modules/YMRoom/View/MoreView/Action/XPTurboModeAction.m +++ b/YuMi/Modules/YMRoom/View/MoreView/Action/XPTurboModeAction.m @@ -7,14 +7,14 @@ #import "XPTurboModeAction.h" #import "RoomInfoModel.h" -#import "../Manager/TurboModeStateManager.h" +#import "TurboModeStateManager.h" @implementation XPTurboModeAction + (instancetype)openAction { XPTurboModeAction *action = [[XPTurboModeAction alloc] init]; action.title = YMLocalizedString(@"20.20.62_text_9.1"); - action.imageName = @"icon_turbo_mode"; + action.imageName = @"icon_turbo_mode_on"; action.type = Room_Turbo_Mode_Open; action.titleColor = [DJDKMIMOMColor appCellBackgroundColor]; return action; @@ -23,7 +23,7 @@ + (instancetype)closeAction { XPTurboModeAction *action = [[XPTurboModeAction alloc] init]; action.title = YMLocalizedString(@"20.20.62_text_9.2"); - action.imageName = @"icon_turbo_mode"; + action.imageName = @"icon_turbo_mode_off"; action.type = Room_Turbo_Mode_Close; action.titleColor = [DJDKMIMOMColor appCellBackgroundColor]; return action; diff --git a/YuMi/Modules/YMRoom/View/MoreView/Manager/TurboModeStateManager.h b/YuMi/Modules/YMRoom/View/MoreView/Manager/TurboModeStateManager.h index 097b3a87..dc362927 100644 --- a/YuMi/Modules/YMRoom/View/MoreView/Manager/TurboModeStateManager.h +++ b/YuMi/Modules/YMRoom/View/MoreView/Manager/TurboModeStateManager.h @@ -47,6 +47,10 @@ NS_ASSUME_NONNULL_BEGIN - (void)setCurrentRoomId:(NSString *)roomId; - (NSString *)loadCurrentRoomId; +// 🔧 新增:强制打开/关闭当前房间的所有开关(含通知与缓存更新) +- (void)forceCloseAllSwitches:(NSString *)roomId; +- (void)forceOpenAllSwitches:(NSString *)roomId; + @end NS_ASSUME_NONNULL_END diff --git a/YuMi/Modules/YMRoom/View/MoreView/Manager/TurboModeStateManager.m b/YuMi/Modules/YMRoom/View/MoreView/Manager/TurboModeStateManager.m index 28432888..ee75ea4e 100644 --- a/YuMi/Modules/YMRoom/View/MoreView/Manager/TurboModeStateManager.m +++ b/YuMi/Modules/YMRoom/View/MoreView/Manager/TurboModeStateManager.m @@ -6,7 +6,7 @@ // #import "TurboModeStateManager.h" -#import "../XPTurboModeConstants.h" +#import "XPTurboModeConstants.h" @interface TurboModeStateManager () @@ -32,8 +32,9 @@ - (instancetype)init { if (self = [super init]) { - // 从全局缓存加载 - self.globalTurboEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"TurboMode_Global"]; + // 🔧 修复:按照规则2,app启动后首次初始化时turbo mode为关闭状态 + // 只有在用户主动操作过turbo mode后才从缓存加载 + self.globalTurboEnabled = NO; self.roomSwitchStates = [NSMutableDictionary dictionary]; self.currentUserId = nil; } @@ -267,14 +268,26 @@ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - // 强制关闭礼物特效开关:不持久化,只发通知 + // 🔧 修复:强制关闭所有开关并更新roomSwitchStates + [self ensureRoomSwitchStatesExist:roomId]; + NSMutableDictionary *roomStates = [self.roomSwitchStates[roomId] mutableCopy]; + + // 强制关闭礼物特效开关:不持久化,只更新内存状态 + roomStates[@"giftEffects"] = @(NO); // 强制关闭全局礼物屏幕开关 + roomStates[@"globalGiftScreen"] = @(NO); [defaults setBool:NO forKey:kTurboGlobalGiftScreenEnabledKey(roomId)]; // 强制关闭全局游戏屏幕开关 + roomStates[@"globalGameScreen"] = @(NO); [defaults setBool:NO forKey:kTurboGlobalGameScreenEnabledKey(roomId)]; + // 强制关闭CP麦位开关 + roomStates[@"cpMic"] = @(NO); + [defaults setBool:NO forKey:kTurboCpMicEnabledKey(roomId)]; + + self.roomSwitchStates[roomId] = roomStates; [defaults synchronize]; // 发送通知,让相关组件更新状态 @@ -283,25 +296,33 @@ - (void)forceOpenAllSwitches:(NSString *)roomId { if (!roomId) return; + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - // 礼物特效:不持久化,只发通知 - // 全局礼物屏幕和全局游戏屏幕:打开并持久化 + + // 🔧 修复:强制打开所有开关并更新roomSwitchStates + [self ensureRoomSwitchStatesExist:roomId]; + NSMutableDictionary *roomStates = [self.roomSwitchStates[roomId] mutableCopy]; + + // 强制打开礼物特效开关:不持久化,只更新内存状态 + roomStates[@"giftEffects"] = @(YES); + + // 强制打开全局礼物屏幕开关 + roomStates[@"globalGiftScreen"] = @(YES); [defaults setBool:YES forKey:kTurboGlobalGiftScreenEnabledKey(roomId)]; + + // 强制打开全局游戏屏幕开关 + roomStates[@"globalGameScreen"] = @(YES); [defaults setBool:YES forKey:kTurboGlobalGameScreenEnabledKey(roomId)]; + + // 强制打开CP麦位开关 + roomStates[@"cpMic"] = @(YES); + [defaults setBool:YES forKey:kTurboCpMicEnabledKey(roomId)]; + + self.roomSwitchStates[roomId] = roomStates; [defaults synchronize]; - // 通知三开关打开 - [[NSNotificationCenter defaultCenter] - postNotificationName:kTurboGiftEffectsEnabledChanged - object:nil - userInfo:@{ @"on": @(YES), @"roomId": roomId }]; - [[NSNotificationCenter defaultCenter] - postNotificationName:kTurboGlobalGiftScreenEnabledChanged - object:nil - userInfo:@{ @"on": @(YES), @"roomId": roomId }]; - [[NSNotificationCenter defaultCenter] - postNotificationName:kTurboGlobalGameScreenEnabledChanged - object:nil - userInfo:@{ @"on": @(YES), @"roomId": roomId }]; + + // 发送通知,让相关组件更新状态 + [self sendSwitchStateChangeNotificationsForOpen:roomId]; } - (void)sendSwitchStateChangeNotifications:(NSString *)roomId { @@ -322,6 +343,38 @@ postNotificationName:kTurboGlobalGameScreenEnabledChanged object:nil userInfo:@{@"on": @(NO), @"roomId": roomId}]; + + // 发送CP麦位开关状态变化通知 + [[NSNotificationCenter defaultCenter] + postNotificationName:kTurboCpMicEnabledChanged + object:nil + userInfo:@{@"on": @(NO), @"roomId": roomId}]; +} + +- (void)sendSwitchStateChangeNotificationsForOpen:(NSString *)roomId { + // 发送礼物特效开关状态变化通知 + [[NSNotificationCenter defaultCenter] + postNotificationName:kTurboGiftEffectsEnabledChanged + object:nil + userInfo:@{@"on": @(YES), @"roomId": roomId}]; + + // 发送全局礼物屏幕开关状态变化通知 + [[NSNotificationCenter defaultCenter] + postNotificationName:kTurboGlobalGiftScreenEnabledChanged + object:nil + userInfo:@{@"on": @(YES), @"roomId": roomId}]; + + // 发送全局游戏屏幕开关状态变化通知 + [[NSNotificationCenter defaultCenter] + postNotificationName:kTurboGlobalGameScreenEnabledChanged + object:nil + userInfo:@{@"on": @(YES), @"roomId": roomId}]; + + // 发送CP麦位开关状态变化通知 + [[NSNotificationCenter defaultCenter] + postNotificationName:kTurboCpMicEnabledChanged + object:nil + userInfo:@{@"on": @(YES), @"roomId": roomId}]; } - (void)loadTurboModeStatesFromCache { @@ -395,15 +448,16 @@ _currentRoomId = roomId; - // 确保当前房间的开关状态存在 + // 🔧 修复:按照规则1,进房后先读取缓存状态,然后应用turbo mode的影响 [self ensureRoomSwitchStatesExist:roomId]; + [self applyTurboModeToSwitchesForRoom:roomId]; // 发送通知,告知其他组件房间ID已设置 [[NSNotificationCenter defaultCenter] postNotificationName:kTurboCurrentRoomIdSet object:nil userInfo:@{@"roomId": roomId}]; - NSLog(@"🎮 TurboModeStateManager: 设置当前房间ID: %@", roomId); + NSLog(@"🎮 TurboModeStateManager: 设置当前房间ID: %@,已应用turbo mode影响", roomId); } // 🔧 新增:获取当前房间ID diff --git a/YuMi/Modules/YMRoom/View/MoreView/View/XPEffectPanelViewController.m b/YuMi/Modules/YMRoom/View/MoreView/View/XPEffectPanelViewController.m index 800da459..a1ae3bfe 100644 --- a/YuMi/Modules/YMRoom/View/MoreView/View/XPEffectPanelViewController.m +++ b/YuMi/Modules/YMRoom/View/MoreView/View/XPEffectPanelViewController.m @@ -35,6 +35,7 @@ [super viewDidLoad]; [self setupUI]; [self setupSwitchStates]; + [self setupNotifications]; } - (void)setupUI { @@ -173,13 +174,11 @@ NSString *roomId = @(self.roomInfo.roomId).stringValue; self.roomId = roomId; - // 🔧 修改:直接使用 TurboModeStateManager 获取开关状态 + // 🔧 修复:只获取开关状态,不重置礼物特效开关 + // 礼物特效开关的更新应该只在进房成功后进行一次,由 RoomAnimationView 处理 TurboModeStateManager *manager = [TurboModeStateManager sharedManager]; - // 更新礼物特效开关状态(基于房间信息) - [manager updateGiftEffectsForRoom:roomId enabled:self.roomInfo.hasAnimationEffect]; - - // 获取各开关状态 + // 获取各开关状态(不调用 updateGiftEffectsForRoom) BOOL giftEffectsEnabled = [manager isGiftEffectsEnabledForRoom:roomId]; BOOL globalGiftScreenEnabled = [manager isGlobalGiftScreenEnabledForRoom:roomId]; BOOL globalGameScreenEnabled = [manager isGlobalGameScreenEnabledForRoom:roomId]; @@ -346,4 +345,113 @@ NSLog(@"🎮 显示 Toast: %@", message); } +#pragma mark - Notifications + +- (void)setupNotifications { + // 监听 Turbo Mode 状态变化 + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(handleTurboModeStateChanged:) + name:@"TurboModeStateChanged" + object:nil]; + + // 监听各个开关状态变化 + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(handleGiftEffectsChanged:) + name:kTurboGiftEffectsEnabledChanged + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(handleGlobalGiftScreenChanged:) + name:kTurboGlobalGiftScreenEnabledChanged + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(handleGlobalGameScreenChanged:) + name:kTurboGlobalGameScreenEnabledChanged + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(handleCpMicChanged:) + name:kTurboCpMicEnabledChanged + object:nil]; +} + +- (void)handleTurboModeStateChanged:(NSNotification *)notification { + BOOL turboModeEnabled = [notification.userInfo[@"enabled"] boolValue]; + + // 🔧 修复:按照规则3,确保TurboModeStateManager和XPEffectPanelViewController状态完全同步 + TurboModeStateManager *manager = [TurboModeStateManager sharedManager]; + + if (turboModeEnabled) { + // Turbo Mode 开启时,强制关闭所有开关 + [manager forceCloseAllSwitches:self.roomId]; + [self updateSwitchesUIForTurboMode:YES]; + NSLog(@"🎮 Turbo Mode 已开启,所有开关已强制关闭"); + } else { + // Turbo Mode 关闭时,强制打开所有开关 + [manager forceOpenAllSwitches:self.roomId]; + [self updateSwitchesUIForTurboMode:NO]; + NSLog(@"🎮 Turbo Mode 已关闭,所有开关已强制打开"); + } +} + +- (void)updateSwitchesUIForTurboMode:(BOOL)turboModeEnabled { + if (turboModeEnabled) { + // 🔧 修复:Turbo Mode 开启时,所有开关显示为关闭状态 + // 注意:这里只更新UI显示,实际状态已由forceCloseAllSwitches更新 + self.giftEffectsSwitch.on = NO; + self.globalGiftScreenSwitch.on = NO; + self.globalGameScreenSwitch.on = NO; + self.cpMicSwitch.on = NO; + } else { + // 🔧 修复:Turbo Mode 关闭时,不直接查询状态,而是等待通知更新 + // 因为 forceOpenAllSwitches 会发送通知,各个 handleXxxChanged 方法会处理UI更新 + NSLog(@"🎮 Turbo Mode 已关闭,等待开关状态变化通知更新UI"); + } +} + +- (void)handleGiftEffectsChanged:(NSNotification *)notification { + BOOL enabled = [notification.userInfo[@"on"] boolValue]; + NSString *roomId = notification.userInfo[@"roomId"]; + + if ([roomId isEqualToString:self.roomId]) { + self.giftEffectsSwitch.on = enabled; + NSLog(@"🎮 礼物特效开关状态已更新: %@", enabled ? @"开启" : @"关闭"); + } +} + +- (void)handleGlobalGiftScreenChanged:(NSNotification *)notification { + BOOL enabled = [notification.userInfo[@"on"] boolValue]; + NSString *roomId = notification.userInfo[@"roomId"]; + + if ([roomId isEqualToString:self.roomId]) { + self.globalGiftScreenSwitch.on = enabled; + NSLog(@"🎮 全局礼物屏幕开关状态已更新: %@", enabled ? @"开启" : @"关闭"); + } +} + +- (void)handleGlobalGameScreenChanged:(NSNotification *)notification { + BOOL enabled = [notification.userInfo[@"on"] boolValue]; + NSString *roomId = notification.userInfo[@"roomId"]; + + if ([roomId isEqualToString:self.roomId]) { + self.globalGameScreenSwitch.on = enabled; + NSLog(@"🎮 全局游戏屏幕开关状态已更新: %@", enabled ? @"开启" : @"关闭"); + } +} + +- (void)handleCpMicChanged:(NSNotification *)notification { + BOOL enabled = [notification.userInfo[@"on"] boolValue]; + NSString *roomId = notification.userInfo[@"roomId"]; + + if ([roomId isEqualToString:self.roomId]) { + self.cpMicSwitch.on = enabled; + NSLog(@"🎮 CP麦位开关状态已更新: %@", enabled ? @"开启" : @"关闭"); + } +} + +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + @end diff --git a/YuMi/Modules/YMRoom/View/MoreView/View/XPRoomMoreMenuViewController.m b/YuMi/Modules/YMRoom/View/MoreView/View/XPRoomMoreMenuViewController.m index 800ddddd..7dd890d3 100644 --- a/YuMi/Modules/YMRoom/View/MoreView/View/XPRoomMoreMenuViewController.m +++ b/YuMi/Modules/YMRoom/View/MoreView/View/XPRoomMoreMenuViewController.m @@ -56,7 +56,7 @@ #import "XPEffectPanelViewController.h" #import "XPTurboModeConstants.h" #import "XPRoomSettingPresenter.h" -#import "../Manager/TurboModeStateManager.h" +#import "TurboModeStateManager.h" UIKIT_EXTERN NSString * const kRoomGiftEffectUpdateNotificationKey; @@ -88,31 +88,6 @@ extern NSString *const kTurboModeButtonStateChanged; @implementation XPRoomMoreMenuViewController -// 🔧 新增:设置 Turbo_Mode 按钮 -- (void)setupTurboModeButton { - self.turboModeButton = [UIButton buttonWithType:UIButtonTypeCustom]; - [self.turboModeButton setTitle:YMLocalizedString(@"20.20.62_text_9") forState:UIControlStateNormal]; - [self.turboModeButton setImage:[UIImage imageNamed:@"icon_turbo_mode"] forState:UIControlStateNormal]; - [self.turboModeButton addTarget:self action:@selector(turboModeButtonTapped) forControlEvents:UIControlEventTouchUpInside]; - - // 设置按钮样式 - self.turboModeButton.backgroundColor = [UIColor colorWithWhite:0.1 alpha:0.8]; - self.turboModeButton.layer.cornerRadius = 8; - self.turboModeButton.titleLabel.font = [UIFont systemFontOfSize:14]; - - [self.view addSubview:self.turboModeButton]; - - // 设置约束 - 使用 Masonry - [self.turboModeButton mas_makeConstraints:^(MASConstraintMaker *make) { - make.top.mas_equalTo(self.topView.mas_bottom).offset(20); - make.centerX.mas_equalTo(self.view); - make.width.mas_equalTo(120); - make.height.mas_equalTo(40); - }]; - - // 初始化按钮状态 - [self updateTurboModeButtonStateOnRoomEnter]; -} // 🔧 新增:设置 Turbo Mode 通知监听 - (void)setupTurboModeNotifications { @@ -152,33 +127,10 @@ extern NSString *const kTurboModeButtonStateChanged; completion:nil]; } -// 🔧 新增:进入房间时更新按钮状态 - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; - [self updateTurboModeButtonStateOnRoomEnter]; } -- (void)updateTurboModeButtonStateOnRoomEnter { - NSString *roomId = @(self.roomInfo.roomId).stringValue; - - // 🔧 修改:直接使用 TurboModeStateManager 获取开关状态 - TurboModeStateManager *manager = [TurboModeStateManager sharedManager]; - - // 更新礼物特效开关状态(基于房间信息) - [manager updateGiftEffectsForRoom:roomId enabled:self.roomInfo.hasAnimationEffect]; - - // 获取各开关状态 - BOOL giftEffectsEnabled = [manager isGiftEffectsEnabledForRoom:roomId]; - BOOL globalGiftScreenEnabled = [manager isGlobalGiftScreenEnabledForRoom:roomId]; - BOOL globalGameScreenEnabled = [manager isGlobalGameScreenEnabledForRoom:roomId]; - BOOL cpMicEnabled = [manager isCpMicEnabledForRoom:roomId]; - - BOOL allOn = giftEffectsEnabled && globalGiftScreenEnabled && globalGameScreenEnabled && cpMicEnabled; - [self updateTurboModeButtonState:allOn]; -} - - - - (instancetype)initWithDelegate:(id)delegate isUserOnMic:(BOOL)isOnMic { if (self = [super init]) { self.modalPresentationStyle = UIModalPresentationOverFullScreen; @@ -196,7 +148,6 @@ extern NSString *const kTurboModeButtonStateChanged; - (void)viewDidLoad { [super viewDidLoad]; [self initSubViews]; -// [self setupTurboModeButton]; [self setupTurboModeNotifications]; [self initSubViewConstraints];