diff --git a/YuMi.xcodeproj/project.pbxproj b/YuMi.xcodeproj/project.pbxproj index 8fa326f2..5f92244f 100644 --- a/YuMi.xcodeproj/project.pbxproj +++ b/YuMi.xcodeproj/project.pbxproj @@ -506,9 +506,10 @@ 4C3851992DD5F4D50089CFCC /* EventConfigModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C3851982DD5F4D50089CFCC /* EventConfigModel.m */; }; 4C38C2AD2D84064400CFA4A8 /* LoginInputItemView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C38C2AC2D84064300CFA4A8 /* LoginInputItemView.m */; }; 4C38C2B02D84070600CFA4A8 /* AccountBindingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C38C2AF2D84070600CFA4A8 /* AccountBindingViewController.m */; }; - 4C4283F62E66C769006779B0 /* XPTurboModeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C4283F52E66C769006779B0 /* XPTurboModeViewController.m */; }; + 4C4283F62E66C769006779B0 /* XPEffectPanelViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C4283F52E66C769006779B0 /* XPEffectPanelViewController.m */; }; 4C44BD5D2D151B5C00F321FA /* RoomSideMenu.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C44BD5C2D151B5C00F321FA /* RoomSideMenu.m */; }; 4C45C1A52E6825F300E73A44 /* XPTurboModeConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C45C1A42E6825F300E73A44 /* XPTurboModeConstants.m */; }; + 4C45C1A92E6837BF00E73A44 /* TurboModeStateManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C45C1A72E6837BF00E73A44 /* TurboModeStateManager.m */; }; 4C4707A52D53430300C8CD24 /* NSData+GZIP.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C4707A42D53430300C8CD24 /* NSData+GZIP.m */; }; 4C51B09C2DA3B4C600D8DFB5 /* LudoGameViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C51B09B2DA3B4C600D8DFB5 /* LudoGameViewController.m */; }; 4C51B09F2DA50FDA00D8DFB5 /* CPRelationshipChangeView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C51B09E2DA50FDA00D8DFB5 /* CPRelationshipChangeView.m */; }; @@ -2678,12 +2679,14 @@ 4C38C2AC2D84064300CFA4A8 /* LoginInputItemView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LoginInputItemView.m; sourceTree = ""; }; 4C38C2AE2D84070600CFA4A8 /* AccountBindingViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AccountBindingViewController.h; sourceTree = ""; }; 4C38C2AF2D84070600CFA4A8 /* AccountBindingViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AccountBindingViewController.m; sourceTree = ""; }; - 4C4283F42E66C769006779B0 /* XPTurboModeViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPTurboModeViewController.h; sourceTree = ""; }; - 4C4283F52E66C769006779B0 /* XPTurboModeViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPTurboModeViewController.m; sourceTree = ""; }; + 4C4283F42E66C769006779B0 /* XPEffectPanelViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPEffectPanelViewController.h; sourceTree = ""; }; + 4C4283F52E66C769006779B0 /* XPEffectPanelViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPEffectPanelViewController.m; sourceTree = ""; }; 4C44BD5B2D151B5C00F321FA /* RoomSideMenu.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RoomSideMenu.h; sourceTree = ""; }; 4C44BD5C2D151B5C00F321FA /* RoomSideMenu.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RoomSideMenu.m; sourceTree = ""; }; 4C45C1A32E6825F300E73A44 /* XPTurboModeConstants.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPTurboModeConstants.h; sourceTree = ""; }; 4C45C1A42E6825F300E73A44 /* XPTurboModeConstants.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPTurboModeConstants.m; sourceTree = ""; }; + 4C45C1A62E6837BF00E73A44 /* TurboModeStateManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TurboModeStateManager.h; sourceTree = ""; }; + 4C45C1A72E6837BF00E73A44 /* TurboModeStateManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TurboModeStateManager.m; sourceTree = ""; }; 4C4707A32D53430300C8CD24 /* NSData+GZIP.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSData+GZIP.h"; sourceTree = ""; }; 4C4707A42D53430300C8CD24 /* NSData+GZIP.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSData+GZIP.m"; sourceTree = ""; }; 4C4DE6442E2513DA00122763 /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/InfoPlist.strings"; sourceTree = ""; }; @@ -6800,6 +6803,15 @@ path = SubViews; sourceTree = ""; }; + 4C45C1A82E6837BF00E73A44 /* Manager */ = { + isa = PBXGroup; + children = ( + 4C45C1A62E6837BF00E73A44 /* TurboModeStateManager.h */, + 4C45C1A72E6837BF00E73A44 /* TurboModeStateManager.m */, + ); + path = Manager; + sourceTree = ""; + }; 4C47079F2D5342C500C8CD24 /* GZIP */ = { isa = PBXGroup; children = ( @@ -11179,6 +11191,7 @@ E8DEC9962764A51F0078CB70 /* MoreView */ = { isa = PBXGroup; children = ( + 4C45C1A82E6837BF00E73A44 /* Manager */, 4C45C1A32E6825F300E73A44 /* XPTurboModeConstants.h */, 4C45C1A42E6825F300E73A44 /* XPTurboModeConstants.m */, 4CD47BB72E619F0B00BCDA46 /* Action */, @@ -11212,8 +11225,8 @@ E8DEC9992764A54C0078CB70 /* View */ = { isa = PBXGroup; children = ( - 4C4283F42E66C769006779B0 /* XPTurboModeViewController.h */, - 4C4283F52E66C769006779B0 /* XPTurboModeViewController.m */, + 4C4283F42E66C769006779B0 /* XPEffectPanelViewController.h */, + 4C4283F52E66C769006779B0 /* XPEffectPanelViewController.m */, E8DEC9A92764A6AF0078CB70 /* Cell */, E8DEC99C2764A5B60078CB70 /* XPRoomMoreMenuViewController.h */, E8DEC99D2764A5B60078CB70 /* XPRoomMoreMenuViewController.m */, @@ -12345,6 +12358,7 @@ 1427218729A75F6F00C7C423 /* MyHTTPConnection.m in Sources */, 23CEFB6C2AFB803B00576D89 /* PISwitchingEnvironmentVC.m in Sources */, E8D55C9D28113218006935A5 /* MessageMenuModel.m in Sources */, + 4C45C1A92E6837BF00E73A44 /* TurboModeStateManager.m in Sources */, E87DF4EF2A42CB90009C1185 /* XPHomeCollectRoomTableViewCell.m in Sources */, 2368ECDF2BC51B2D00EDF4C9 /* XPMineSwitchLanguageCell.m in Sources */, 236B2E442AA07D06003967A8 /* UIColor+RW.m in Sources */, @@ -13419,7 +13433,7 @@ 9BAA5FF0277A23F4007453F3 /* XPPermissionsViewController.m in Sources */, E85E7BA02A4EC99300B6D00A /* XPMineGiveDiamondDetailsModel.m in Sources */, 4CE746C32D9290430094E496 /* RoomBoomManager.m in Sources */, - 4C4283F62E66C769006779B0 /* XPTurboModeViewController.m in Sources */, + 4C4283F62E66C769006779B0 /* XPEffectPanelViewController.m in Sources */, 4CBBB44C2DA66334001B1C6D /* MessageCPNotifyModel.m in Sources */, E81A654C28351D9900F55894 /* XPMonentsTopicCollectionViewCell.m in Sources */, E85E7B9F2A4EC99300B6D00A /* XPMineGiveDiamondPresenter.m in Sources */, diff --git a/YuMi/Modules/YMRoom/View/AnimationView/RoomAnimationView.m b/YuMi/Modules/YMRoom/View/AnimationView/RoomAnimationView.m index dff0d0a5..79272813 100644 --- a/YuMi/Modules/YMRoom/View/AnimationView/RoomAnimationView.m +++ b/YuMi/Modules/YMRoom/View/AnimationView/RoomAnimationView.m @@ -78,6 +78,7 @@ #import "XPRoomAnchorRankEnterView.h" #import "MSRoomOnLineView.h" #import "XPTurboModeConstants.h" +#import "../MoreView/Manager/TurboModeStateManager.h" #import "BannerScheduler.h" #import "GameBannerGestureManager.h" @@ -459,6 +460,20 @@ BannerSchedulerDelegate NSString *roomId = @(self.hostDelegate.getRoomInfo.roomId).stringValue; self.currentRoomId = roomId; + // 1. 先按原逻辑获取状态 + [self loadSwitchStatesFromCache:roomId]; + + // 2. 再按 turbo mode 来调整状态 + [[TurboModeStateManager sharedManager] applyTurboModeToSwitchesForRoom:roomId]; + + // 3. 强制更新本地状态,确保与 turbo mode 一致 + [self forceUpdateLocalSwitchStates:roomId]; + + NSLog(@"🎮 RoomAnimationView Turbo Mode开关初始化完成 - 房间ID: %@", roomId); +} + +// 🔧 新增:从缓存加载开关状态 +- (void)loadSwitchStatesFromCache:(NSString *)roomId { // 礼物特效:从当前会话状态读取(不持久化) self.turboGiftEffectsEnabled = self.hostDelegate.getRoomInfo.hasAnimationEffect; @@ -468,12 +483,40 @@ BannerSchedulerDelegate self.turboGlobalGiftScreenEnabled = (giftScreenObj != nil) ? [defaults boolForKey:kTurboGlobalGiftScreenEnabledKey(roomId)] : YES; id gameScreenObj = [defaults objectForKey:kTurboGlobalGameScreenEnabledKey(roomId)]; self.turboGlobalGameScreenEnabled = (gameScreenObj != nil) ? [defaults boolForKey:kTurboGlobalGameScreenEnabledKey(roomId)] : YES; +} + +// 🔧 新增:更新本地开关状态 +- (void)updateLocalSwitchStates:(NSString *)roomId { + NSDictionary *switchStates = [[TurboModeStateManager sharedManager] getSwitchStatesAfterTurboModeForRoom:roomId]; - NSLog(@"🎮 RoomAnimationView Turbo Mode开关初始化 - 房间ID: %@, 礼物特效: %@, 全局礼物屏幕: %@, 全局游戏屏幕: %@", - roomId, - self.turboGiftEffectsEnabled ? @"开启" : @"关闭", - self.turboGlobalGiftScreenEnabled ? @"开启" : @"关闭", - self.turboGlobalGameScreenEnabled ? @"开启" : @"关闭"); + if (switchStates.count > 0) { + self.turboGiftEffectsEnabled = [switchStates[@"giftEffects"] boolValue]; + self.turboGlobalGiftScreenEnabled = [switchStates[@"globalGiftScreen"] boolValue]; + self.turboGlobalGameScreenEnabled = [switchStates[@"globalGameScreen"] boolValue]; + + NSLog(@"🎮 RoomAnimationView 开关状态已更新 - 礼物特效: %@, 全局礼物屏幕: %@, 全局游戏屏幕: %@", + self.turboGiftEffectsEnabled ? @"开启" : @"关闭", + self.turboGlobalGiftScreenEnabled ? @"开启" : @"关闭", + self.turboGlobalGameScreenEnabled ? @"开启" : @"关闭"); + } +} + +// 🔧 新增:强制更新本地开关状态,确保与 turbo mode 一致 +- (void)forceUpdateLocalSwitchStates:(NSString *)roomId { + // 直接获取 turbo mode 状态并强制设置 + BOOL turboModeEnabled = [[TurboModeStateManager sharedManager] isTurboModeEnabled]; + + if (turboModeEnabled) { + // turbo mode = YES,强制关闭所有开关 + self.turboGiftEffectsEnabled = NO; + self.turboGlobalGiftScreenEnabled = NO; + self.turboGlobalGameScreenEnabled = NO; + + NSLog(@"🎮 RoomAnimationView 强制更新开关状态 - Turbo Mode 开启,所有开关已关闭"); + } else { + // turbo mode = NO,使用原有逻辑 + [self updateLocalSwitchStates:roomId]; + } } // 🔧 新增:设置Turbo Mode通知监听 @@ -934,6 +977,12 @@ BannerSchedulerDelegate } - (void)receiveRoomGiftBanner:(AttachmentModel *)obj { + // 🔧 新增:检查 Turbo Mode 全局礼物屏幕开关 + if (!self.turboGlobalGiftScreenEnabled) { + NSLog(@"🎮 RoomAnimationView 全局礼物屏幕已关闭,跳过 RoomGiftBanner"); + return; + } + [self inserBannerModelToQueue:obj]; } @@ -1161,6 +1210,12 @@ BannerSchedulerDelegate } - (void)receiveLuckGiftBanner:(AttachmentModel *)attachment { + // 🔧 新增:检查 Turbo Mode 全局礼物屏幕开关 + if (!self.turboGlobalGiftScreenEnabled) { + NSLog(@"🎮 RoomAnimationView 全局礼物屏幕已关闭,跳过 LuckyGiftWinningBanner"); + return; + } + [self inserBannerModelToQueue:attachment]; } @@ -1206,6 +1261,12 @@ BannerSchedulerDelegate } - (void)receiveGameBanner:(AttachmentModel *)attachment { + // 🔧 新增:检查 Turbo Mode 全局游戏屏幕开关 + if (!self.turboGlobalGameScreenEnabled) { + NSLog(@"🎮 RoomAnimationView 全局游戏屏幕已关闭,跳过 GameBanner"); + return; + } + [self inserBannerModelToQueue:attachment]; } diff --git a/YuMi/Modules/YMRoom/View/MoreView/Action/XPRoomEffectAction.m b/YuMi/Modules/YMRoom/View/MoreView/Action/XPRoomEffectAction.m index 97de04dc..89f9991c 100644 --- a/YuMi/Modules/YMRoom/View/MoreView/Action/XPRoomEffectAction.m +++ b/YuMi/Modules/YMRoom/View/MoreView/Action/XPRoomEffectAction.m @@ -13,7 +13,7 @@ XPRoomEffectAction *action = [[XPRoomEffectAction alloc] init]; action.title = YMLocalizedString(@"20.20.62_text_14"); action.imageName = @"room_more_menu_gift_effect"; - action.type = RoomMoreMenuType_Turbo_Mode; + action.type = RoomMoreMenuType_MyAnimationEffects_Mode; action.titleColor = [DJDKMIMOMColor appCellBackgroundColor]; return action; } diff --git a/YuMi/Modules/YMRoom/View/MoreView/Action/XPTurboModeAction.m b/YuMi/Modules/YMRoom/View/MoreView/Action/XPTurboModeAction.m index 0e3e4e0b..b25e0f41 100644 --- a/YuMi/Modules/YMRoom/View/MoreView/Action/XPTurboModeAction.m +++ b/YuMi/Modules/YMRoom/View/MoreView/Action/XPTurboModeAction.m @@ -7,6 +7,7 @@ #import "XPTurboModeAction.h" #import "RoomInfoModel.h" +#import "../Manager/TurboModeStateManager.h" @implementation XPTurboModeAction @@ -14,7 +15,7 @@ XPTurboModeAction *action = [[XPTurboModeAction alloc] init]; action.title = YMLocalizedString(@"20.20.62_text_9.1"); action.imageName = @"icon_turbo_mode"; - action.type = RoomMoreMenuType_UI_Effect_Open; + action.type = Room_Turbo_Mode_Open; action.titleColor = [DJDKMIMOMColor appCellBackgroundColor]; return action; } @@ -23,16 +24,21 @@ XPTurboModeAction *action = [[XPTurboModeAction alloc] init]; action.title = YMLocalizedString(@"20.20.62_text_9.2"); action.imageName = @"icon_turbo_mode"; - action.type = RoomMoreMenuType_UI_Effect_Close; + action.type = Room_Turbo_Mode_Close; action.titleColor = [DJDKMIMOMColor appCellBackgroundColor]; return action; } -// 根据房间状态创建对应的 Action +// 根据全局 turbo mode 状态创建对应的 Action + (instancetype)actionWithRoomInfo:(RoomInfoModel *)roomInfo { - if (roomInfo.hasAnimationEffect) { + // 导入 TurboModeStateManager 头文件 + BOOL turboModeEnabled = [[TurboModeStateManager sharedManager] isTurboModeEnabled]; + + if (turboModeEnabled) { + // turbo mode 已开启,显示关闭 Action return [self closeAction]; } else { + // turbo mode 已关闭,显示开启 Action return [self openAction]; } } diff --git a/YuMi/Modules/YMRoom/View/MoreView/Manager/TurboModeStateManager.h b/YuMi/Modules/YMRoom/View/MoreView/Manager/TurboModeStateManager.h new file mode 100644 index 00000000..3efb3f2f --- /dev/null +++ b/YuMi/Modules/YMRoom/View/MoreView/Manager/TurboModeStateManager.h @@ -0,0 +1,31 @@ +// +// TurboModeStateManager.h +// YuMi +// +// Created by Linus on 2025/1/13. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface TurboModeStateManager : NSObject + ++ (instancetype)sharedManager; + +// 全局 turbo mode 开关(不按房间) +- (void)setTurboModeEnabled:(BOOL)enabled; +- (BOOL)isTurboModeEnabled; + +// 将当前全局 turbo mode 应用到指定房间的三个开关(礼物特效临时、两全局屏幕持久化) +- (void)applyTurboModeToSwitchesForRoom:(NSString *)roomId; + +// 获取应用全局 turbo 后的房间三开关视图态 +- (NSDictionary *)getSwitchStatesAfterTurboModeForRoom:(NSString *)roomId; + +// 重置全局 turbo mode +- (void)resetTurboMode; + +@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 new file mode 100644 index 00000000..375ffb3a --- /dev/null +++ b/YuMi/Modules/YMRoom/View/MoreView/Manager/TurboModeStateManager.m @@ -0,0 +1,178 @@ +// +// TurboModeStateManager.m +// YuMi +// +// Created by Linus on 2025/1/13. +// + +#import "TurboModeStateManager.h" +#import "../XPTurboModeConstants.h" + +@interface TurboModeStateManager () + +@property (nonatomic, assign) BOOL globalTurboEnabled; // 全局 turbo 模式 + +@end + +@implementation TurboModeStateManager + +#pragma mark - Singleton + ++ (instancetype)sharedManager { + static TurboModeStateManager *instance = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + instance = [[TurboModeStateManager alloc] init]; + }); + return instance; +} + +- (instancetype)init { + if (self = [super init]) { + // 从全局缓存加载 + self.globalTurboEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"TurboMode_Global"]; + } + return self; +} + +#pragma mark - Public Methods + +- (void)setTurboModeEnabled:(BOOL)enabled { + self.globalTurboEnabled = enabled; + [[NSUserDefaults standardUserDefaults] setBool:enabled forKey:@"TurboMode_Global"]; + [[NSUserDefaults standardUserDefaults] synchronize]; + + NSLog(@"🎮 TurboModeStateManager: 全局 turbo mode 设置为 %@", enabled ? @"开启" : @"关闭"); +} + +- (BOOL)isTurboModeEnabled { + return self.globalTurboEnabled; +} + +- (void)applyTurboModeToSwitchesForRoom:(NSString *)roomId { + if (!roomId) return; + + BOOL turboModeEnabled = [self isTurboModeEnabled]; + + if (turboModeEnabled) { + // turbo mode = YES,3个开关全部关闭 + [self forceCloseAllSwitches:roomId]; + NSLog(@"🎮 TurboModeStateManager: 应用 turbo mode,房间 %@ 的3个开关全部关闭", roomId); + } else { + // turbo mode = NO,按最新需求:全部开关打开 + [self forceOpenAllSwitches:roomId]; + NSLog(@"🎮 TurboModeStateManager: turbo mode 关闭,房间 %@ 的3个开关全部打开", roomId); + } +} + +- (NSDictionary *)getSwitchStatesAfterTurboModeForRoom:(NSString *)roomId { + if (!roomId) return @{}; + + BOOL turboModeEnabled = [self isTurboModeEnabled]; + + if (turboModeEnabled) { + // turbo mode = YES,3个开关全部关闭 + return @{ + @"giftEffects": @(NO), + @"globalGiftScreen": @(NO), + @"globalGameScreen": @(NO) + }; + } else { + // turbo mode = NO,返回当前缓存的状态 + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + + // 礼物特效:按需求不持久化,这里默认开启(面板或 RoomAnimationView 会基于 roomInfo 决定) + BOOL giftEffects = YES; + + // 全局礼物屏幕:从缓存读取 + id giftScreenObj = [defaults objectForKey:kTurboGlobalGiftScreenEnabledKey(roomId)]; + BOOL globalGiftScreen = (giftScreenObj != nil) ? [defaults boolForKey:kTurboGlobalGiftScreenEnabledKey(roomId)] : YES; + + // 全局游戏屏幕:从缓存读取 + id gameScreenObj = [defaults objectForKey:kTurboGlobalGameScreenEnabledKey(roomId)]; + BOOL globalGameScreen = (gameScreenObj != nil) ? [defaults boolForKey:kTurboGlobalGameScreenEnabledKey(roomId)] : YES; + + return @{ + @"giftEffects": @(giftEffects), + @"globalGiftScreen": @(globalGiftScreen), + @"globalGameScreen": @(globalGameScreen) + }; + } +} + +- (void)resetTurboMode { + self.globalTurboEnabled = NO; + [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"TurboMode_Global"]; + [[NSUserDefaults standardUserDefaults] synchronize]; + NSLog(@"🎮 TurboModeStateManager: 全局 turbo mode 状态已重置"); +} + +#pragma mark - Private Methods + +- (void)forceCloseAllSwitches:(NSString *)roomId { + if (!roomId) return; + + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + + // 强制关闭礼物特效开关:不持久化,只发通知 + + // 强制关闭全局礼物屏幕开关 + [defaults setBool:NO forKey:kTurboGlobalGiftScreenEnabledKey(roomId)]; + + // 强制关闭全局游戏屏幕开关 + [defaults setBool:NO forKey:kTurboGlobalGameScreenEnabledKey(roomId)]; + + [defaults synchronize]; + + // 发送通知,让相关组件更新状态 + [self sendSwitchStateChangeNotifications:roomId]; +} + +- (void)forceOpenAllSwitches:(NSString *)roomId { + if (!roomId) return; + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + // 礼物特效:不持久化,只发通知 + // 全局礼物屏幕和全局游戏屏幕:打开并持久化 + [defaults setBool:YES forKey:kTurboGlobalGiftScreenEnabledKey(roomId)]; + [defaults setBool:YES forKey:kTurboGlobalGameScreenEnabledKey(roomId)]; + [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 }]; +} + +- (void)sendSwitchStateChangeNotifications:(NSString *)roomId { + // 发送礼物特效开关状态变化通知 + [[NSNotificationCenter defaultCenter] + postNotificationName:kTurboGiftEffectsEnabledChanged + object:nil + userInfo:@{@"on": @(NO), @"roomId": roomId}]; + + // 发送全局礼物屏幕开关状态变化通知 + [[NSNotificationCenter defaultCenter] + postNotificationName:kTurboGlobalGiftScreenEnabledChanged + object:nil + userInfo:@{@"on": @(NO), @"roomId": roomId}]; + + // 发送全局游戏屏幕开关状态变化通知 + [[NSNotificationCenter defaultCenter] + postNotificationName:kTurboGlobalGameScreenEnabledChanged + object:nil + userInfo:@{@"on": @(NO), @"roomId": roomId}]; +} + +- (void)loadTurboModeStatesFromCache { + // 不再按房间加载,已改为全局 +} + +@end diff --git a/YuMi/Modules/YMRoom/View/MoreView/Model/XPRoomMoreItemModel.h b/YuMi/Modules/YMRoom/View/MoreView/Model/XPRoomMoreItemModel.h index 4dbf9f23..a67ce5ff 100644 --- a/YuMi/Modules/YMRoom/View/MoreView/Model/XPRoomMoreItemModel.h +++ b/YuMi/Modules/YMRoom/View/MoreView/Model/XPRoomMoreItemModel.h @@ -19,9 +19,9 @@ typedef NS_ENUM(NSInteger, RoomMoreMenuType) { // ///公屏开启 // RoomMoreMenuType_Message_Screen_Open = 4, // ///我的礼物特效关闭 - RoomMoreMenuType_UI_Effect_Close = 5, + Room_Turbo_Mode_Close = 5, ///我的礼物特效开启 - RoomMoreMenuType_UI_Effect_Open = 6, + Room_Turbo_Mode_Open = 6, ///房间设置 RoomMoreMenuType_Room_Setting = 7, ///邀请粉丝 @@ -67,7 +67,7 @@ typedef NS_ENUM(NSInteger, RoomMoreMenuType) { RoomMoreMenuType_App_Manager = 28, - RoomMoreMenuType_Turbo_Mode = 29, + RoomMoreMenuType_MyAnimationEffects_Mode = 29, }; @interface XPRoomMoreItemModel : PIBaseModel diff --git a/YuMi/Modules/YMRoom/View/MoreView/View/XPTurboModeViewController.h b/YuMi/Modules/YMRoom/View/MoreView/View/XPEffectPanelViewController.h similarity index 82% rename from YuMi/Modules/YMRoom/View/MoreView/View/XPTurboModeViewController.h rename to YuMi/Modules/YMRoom/View/MoreView/View/XPEffectPanelViewController.h index b06a30a6..0144d7a7 100644 --- a/YuMi/Modules/YMRoom/View/MoreView/View/XPTurboModeViewController.h +++ b/YuMi/Modules/YMRoom/View/MoreView/View/XPEffectPanelViewController.h @@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN /** * Turbo模式设置控制器 */ -@interface XPTurboModeViewController : MvpViewController +@interface XPEffectPanelViewController : MvpViewController @property (nonatomic, strong) RoomInfoModel *roomInfo; diff --git a/YuMi/Modules/YMRoom/View/MoreView/View/XPTurboModeViewController.m b/YuMi/Modules/YMRoom/View/MoreView/View/XPEffectPanelViewController.m similarity index 71% rename from YuMi/Modules/YMRoom/View/MoreView/View/XPTurboModeViewController.m rename to YuMi/Modules/YMRoom/View/MoreView/View/XPEffectPanelViewController.m index df6c269f..4b0916cb 100644 --- a/YuMi/Modules/YMRoom/View/MoreView/View/XPTurboModeViewController.m +++ b/YuMi/Modules/YMRoom/View/MoreView/View/XPEffectPanelViewController.m @@ -5,13 +5,12 @@ // Created by Linus on 2025/1/13. // -#import "XPTurboModeViewController.h" -#import -#import +#import "XPEffectPanelViewController.h" #import "RoomInfoModel.h" #import "XPTurboModeConstants.h" +#import "TurboModeStateManager.h" -@interface XPTurboModeViewController () +@interface XPEffectPanelViewController () @property (nonatomic, strong) UIView *bottomAreaBackground; @property (nonatomic, strong) UIButton *dismissButton; @@ -32,7 +31,7 @@ @end -@implementation XPTurboModeViewController +@implementation XPEffectPanelViewController - (void)viewDidLoad { [super viewDidLoad]; @@ -47,6 +46,7 @@ [self setupDismissButton]; [self setupTitle]; [self setupSwitches]; + [self setupTapGesture]; } - (void)setupBottomArea { @@ -168,15 +168,29 @@ NSString *roomId = @(self.roomInfo.roomId).stringValue; self.roomId = roomId; - // 礼物特效:从当前会话状态读取(不持久化) - self.giftEffectsEnabled = self.roomInfo.hasAnimationEffect; + // 检查 turbo mode 状态(全局) + BOOL turboModeEnabled = [[TurboModeStateManager sharedManager] isTurboModeEnabled]; - // 其他两个开关:从房间特定的 NSUserDefaults 读取(区分未设置与显式 NO) NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - id giftScreenObj = [defaults objectForKey:kTurboGlobalGiftScreenEnabledKey(roomId)]; - self.globalGiftScreenEnabled = (giftScreenObj != nil) ? [defaults boolForKey:kTurboGlobalGiftScreenEnabledKey(roomId)] : YES; // 默认开启 - id gameScreenObj = [defaults objectForKey:kTurboGlobalGameScreenEnabledKey(roomId)]; - self.globalGameScreenEnabled = (gameScreenObj != nil) ? [defaults boolForKey:kTurboGlobalGameScreenEnabledKey(roomId)] : YES; // 默认开启 + + if (turboModeEnabled) { + // turbo mode = YES,3个开关全部关闭 + self.giftEffectsEnabled = NO; + self.globalGiftScreenEnabled = NO; + self.globalGameScreenEnabled = NO; + // 保持所有开关可点击,不设置 enabled = NO + NSLog(@"🎮 Turbo Mode 已开启,所有开关显示关闭状态但可点击"); + } else { + // turbo mode = NO,正常读取开关状态 + // 礼物特效:直接使用房间默认状态,不需要检查持久化 + self.giftEffectsEnabled = self.roomInfo.hasAnimationEffect; + + // 其他两个开关:从房间特定的 NSUserDefaults 读取(区分未设置与显式 NO) + id giftScreenObj = [defaults objectForKey:kTurboGlobalGiftScreenEnabledKey(roomId)]; + self.globalGiftScreenEnabled = (giftScreenObj != nil) ? [defaults boolForKey:kTurboGlobalGiftScreenEnabledKey(roomId)] : YES; // 默认开启 + id gameScreenObj = [defaults objectForKey:kTurboGlobalGameScreenEnabledKey(roomId)]; + self.globalGameScreenEnabled = (gameScreenObj != nil) ? [defaults boolForKey:kTurboGlobalGameScreenEnabledKey(roomId)] : YES; // 默认开启 + } // 设置开关初始状态 self.giftEffectsSwitch.on = self.giftEffectsEnabled; @@ -193,6 +207,30 @@ - (void)switchValueChanged:(UISwitch *)sender { BOOL isOn = sender.isOn; + // 检查当前 turbo mode 状态 + BOOL currentTurboMode = [[TurboModeStateManager sharedManager] isTurboModeEnabled]; + + if (currentTurboMode && isOn) { + // turbo mode 开启时,用户点击开启开关,自动关闭 turbo mode + [[TurboModeStateManager sharedManager] setTurboModeEnabled:NO]; + + // 更新本地状态为开启 + if (sender.tag == 0) { // 礼物特效开关 + self.giftEffectsEnabled = YES; + } else if (sender.tag == 1) { // 全局礼物屏幕 + self.globalGiftScreenEnabled = YES; + } else if (sender.tag == 2) { // 全局游戏屏幕 + self.globalGameScreenEnabled = YES; + } + + // 发送通知,让 RoomAnimationView 更新状态 + [self sendSwitchStateChangeNotification:sender.tag enabled:YES]; + + NSLog(@"🎮 Turbo Mode 已自动关闭,开关 %ld 已开启", (long)sender.tag); + return; + } + + // 正常处理开关状态变化 if (sender.tag == 0) { // 礼物特效开关 // 临时更改房间状态,不影响 roomInfo.hasAnimationEffect self.giftEffectsEnabled = isOn; @@ -222,6 +260,23 @@ NSLog(@"🎮 Turbo Mode开关变化 - 索引: %ld, 状态: %@", (long)sender.tag, isOn ? @"开启" : @"关闭"); } +- (void)sendSwitchStateChangeNotification:(NSInteger)switchTag enabled:(BOOL)enabled { + // 根据开关类型发送对应的通知 + switch (switchTag) { + case 0: // 礼物特效开关 + [self sendTurboGiftEffectsNotification:enabled]; + break; + case 1: // 全局礼物屏幕开关 + [self sendTurboGlobalGiftScreenNotification:enabled]; + break; + case 2: // 全局游戏屏幕开关 + [self sendTurboGlobalGameScreenNotification:enabled]; + break; + default: + break; + } +} + - (void)notifyParentUpdateTurboModeButton { BOOL allSwitchesOn = self.giftEffectsEnabled && self.globalGiftScreenEnabled && @@ -256,6 +311,24 @@ userInfo:@{@"on": @(enabled)}]; } +- (void)setupTapGesture { + // 创建点击手势识别器,点击空白区域时关闭 VC + UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleBackgroundTap:)]; + tapGesture.delegate = self; + [self.view addGestureRecognizer:tapGesture]; +} + +- (void)handleBackgroundTap:(UITapGestureRecognizer *)gesture { + // 获取点击位置 + CGPoint location = [gesture locationInView:self.view]; + + // 检查点击位置是否在底部黑色背景区域外 + if (!CGRectContainsPoint(self.bottomAreaBackground.frame, location)) { + // 点击在空白区域,关闭 VC + [self dismissViewController]; + } +} + - (void)dismissViewController { [self dismissViewControllerAnimated:YES completion:nil]; } diff --git a/YuMi/Modules/YMRoom/View/MoreView/View/XPRoomMoreMenuViewController.m b/YuMi/Modules/YMRoom/View/MoreView/View/XPRoomMoreMenuViewController.m index e9cc09c1..9dea6762 100644 --- a/YuMi/Modules/YMRoom/View/MoreView/View/XPRoomMoreMenuViewController.m +++ b/YuMi/Modules/YMRoom/View/MoreView/View/XPRoomMoreMenuViewController.m @@ -51,9 +51,10 @@ #import "XPRoomMoreMenuAction.h" #import "XPPKAction.h" -#import "XPTurboModeViewController.h" +#import "XPEffectPanelViewController.h" #import "XPTurboModeConstants.h" #import "XPRoomSettingPresenter.h" +#import "../Manager/TurboModeStateManager.h" UIKIT_EXTERN NSString * const kRoomGiftEffectUpdateNotificationKey; @@ -141,7 +142,7 @@ extern NSString *const kTurboModeButtonStateChanged; - (void)turboModeButtonTapped { // 打开 Turbo 配置面板 [self dismissViewControllerAnimated:NO completion:nil]; - XPTurboModeViewController *vc = [[XPTurboModeViewController alloc] init]; + XPEffectPanelViewController *vc = [[XPEffectPanelViewController alloc] init]; vc.roomInfo = self.roomInfo; vc.modalPresentationStyle = UIModalPresentationOverFullScreen; [self.hostDelegate.getCurrentNav presentViewController:vc @@ -377,55 +378,27 @@ extern NSString *const kTurboModeButtonStateChanged; NSString * roomUid = [NSString stringWithFormat:@"%ld",self.roomInfo.uid]; switch (item.type) { - case RoomMoreMenuType_UI_Effect_Open: - case RoomMoreMenuType_UI_Effect_Close: + case Room_Turbo_Mode_Open: + case Room_Turbo_Mode_Close: { - BOOL newOn = !self.roomInfo.hasAnimationEffect; - - // 子开关本地持久化(默认 key 与 Turbo 面板保持一致) - NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; - [ud setBool:newOn forKey:@"kTurboGlobalGiftScreenEnabled"]; - [ud setBool:newOn forKey:@"kTurboGlobalGameScreenEnabled"]; - [ud synchronize]; - - // 广播:子开关通知 - [[NSNotificationCenter defaultCenter] postNotificationName:@"kTurboGlobalGiftScreenEnabledChanged" - object:nil - userInfo:@{ @"on": @(newOn) }]; - [[NSNotificationCenter defaultCenter] postNotificationName:@"kTurboGlobalGameScreenEnabledChanged" - object:nil - userInfo:@{ @"on": @(newOn) }]; - // 广播:总开关通知 - [[NSNotificationCenter defaultCenter] postNotificationName:@"kTurboGiftEffectsEnabledChanged" - object:nil - userInfo:@{ @"on": @(newOn) }]; - - // 同步到服务端房间属性 hasAnimationEffect - XPRoomSettingPresenter *p = [[XPRoomSettingPresenter alloc] init]; - RoomInfoModel *ri = self.roomInfo; - [p updateRoomInfo:ri.title - roomPwd:ri.roomPwd - tagId:ri.roomTag - classifyId:ri.singleRoomSortId - hasAnimationEffect:newOn - roomUid:@(ri.uid).stringValue - roomId:@(ri.roomId).stringValue - type:ri.type - itemType:RoomSettingItemType_Gift_Effect - mgId:@(ri.mgId).stringValue - backPic:ri.backPic - avatar:ri.avatar]; - - // 本地提示 - if (newOn) { - [self showSuccessToast:YMLocalizedString(@"XPRoomMoreMenuViewController4")]; - } else { - [self showSuccessToast:YMLocalizedString(@"XPRoomMoreMenuViewController5")]; - } - - // 更新本地 roomInfo 并关闭 - self.roomInfo.hasAnimationEffect = newOn; [self dismissViewControllerAnimated:YES completion:nil]; + // 获取当前房间的 turbo mode 状态 + NSString *roomId = @(self.roomInfo.roomId).stringValue; + BOOL currentTurboMode = [[TurboModeStateManager sharedManager] isTurboModeEnabled]; + BOOL newTurboMode = !currentTurboMode; + + // 设置新的 turbo mode 状态(全局) + [[TurboModeStateManager sharedManager] setTurboModeEnabled:newTurboMode]; + + // 应用 turbo mode 到3个开关 + [[TurboModeStateManager sharedManager] applyTurboModeToSwitchesForRoom:roomId]; + + // 显示提示 + if (newTurboMode) { + [self showSuccessToast:YMLocalizedString(@"Turbo Mode 已开启")]; + } else { + [self showSuccessToast:YMLocalizedString(@"Turbo Mode 已关闭")]; + } } break; case RoomMoreMenuType_Invite_Fans: @@ -664,9 +637,9 @@ extern NSString *const kTurboModeButtonStateChanged; [self.hostDelegate.getCurrentNav pushViewController:vc animated:YES]; } break; - case RoomMoreMenuType_Turbo_Mode: { + case RoomMoreMenuType_MyAnimationEffects_Mode: { [self dismissViewControllerAnimated:NO completion:nil]; - XPTurboModeViewController *vc = [[XPTurboModeViewController alloc] init]; + XPEffectPanelViewController *vc = [[XPEffectPanelViewController alloc] init]; vc.roomInfo = self.roomInfo; vc.modalPresentationStyle = UIModalPresentationOverFullScreen; [self.hostDelegate.getCurrentNav presentViewController:vc