新增礼物特效开关的用户覆盖标记功能,更新 TurboModeStateManager 以支持从用户手动操作的状态更新,同时在房间进入时重置用户覆盖标记。确保在处理房间信息更新时同步礼物特效状态。

This commit is contained in:
edwinQQQ
2025-09-23 10:47:34 +08:00
parent 253a3480f5
commit a0b4cc5495
4 changed files with 58 additions and 4 deletions

View File

@@ -32,6 +32,12 @@ NS_ASSUME_NONNULL_BEGIN
// 🔧 新增:更新礼物特效开关状态(通过 RoomInfo.hasAnimationEffect 更新) // 🔧 新增:更新礼物特效开关状态(通过 RoomInfo.hasAnimationEffect 更新)
- (void)updateGiftEffectsForRoom:(NSString *)roomId enabled:(BOOL)enabled; - (void)updateGiftEffectsForRoom:(NSString *)roomId enabled:(BOOL)enabled;
// 支持来源标记fromUser=YES 表示用户手动开关,打上覆盖标记
- (void)updateGiftEffectsForRoom:(NSString *)roomId enabled:(BOOL)enabled fromUser:(BOOL)fromUser;
// 用户覆盖标记:用于阻止服务端推送覆盖用户选择
- (void)setGiftEffectsOverrideForRoom:(NSString *)roomId enabled:(BOOL)enabled;
- (BOOL)isGiftEffectsUserOverriddenForRoom:(NSString *)roomId;
// 🔧 新增:获取各开关状态 // 🔧 新增:获取各开关状态
- (BOOL)isGiftEffectsEnabledForRoom:(NSString *)roomId; - (BOOL)isGiftEffectsEnabledForRoom:(NSString *)roomId;

View File

@@ -87,11 +87,43 @@
// 🔧 便UI // 🔧 便UI
[[NSNotificationCenter defaultCenter] postNotificationName:kTurboGiftEffectsEnabledChanged [[NSNotificationCenter defaultCenter] postNotificationName:kTurboGiftEffectsEnabledChanged
object:nil object:nil
userInfo:@{@"roomId": roomId, @"on": @(enabled)}]; userInfo:@{ @"roomId": roomId, @"on": @(enabled) }];
NSLog(@"🎮 TurboModeStateManager: 房间 %@ 礼物特效开关更新为 %@", roomId, enabled ? @"开启" : @"关闭"); NSLog(@"🎮 TurboModeStateManager: 房间 %@ 礼物特效开关更新为 %@", roomId, enabled ? @"开启" : @"关闭");
} }
//
- (void)updateGiftEffectsForRoom:(NSString *)roomId enabled:(BOOL)enabled fromUser:(BOOL)fromUser {
if (!roomId) return;
[self ensureRoomSwitchStatesExist:roomId];
NSMutableDictionary *roomStates = [self.roomSwitchStates[roomId] mutableCopy];
roomStates[@"giftEffects"] = @(enabled);
if (fromUser) {
roomStates[@"giftEffectsOverride"] = @(YES);
}
self.roomSwitchStates[roomId] = roomStates;
[[NSNotificationCenter defaultCenter] postNotificationName:kTurboGiftEffectsEnabledChanged
object:nil
userInfo:@{ @"roomId": roomId, @"on": @(enabled) }];
NSLog(@"🎮 TurboModeStateManager: 房间 %@ 礼物特效开关更新为 %@ (fromUser=%@)", roomId, enabled ? @"开启" : @"关闭", fromUser ? @"YES" : @"NO");
}
//
- (void)setGiftEffectsOverrideForRoom:(NSString *)roomId enabled:(BOOL)enabled {
if (!roomId) return;
[self ensureRoomSwitchStatesExist:roomId];
NSMutableDictionary *roomStates = [self.roomSwitchStates[roomId] mutableCopy];
roomStates[@"giftEffectsOverride"] = @(enabled);
self.roomSwitchStates[roomId] = roomStates;
}
- (BOOL)isGiftEffectsUserOverriddenForRoom:(NSString *)roomId {
if (!roomId) return NO;
[self ensureRoomSwitchStatesExist:roomId];
return [self.roomSwitchStates[roomId][@"giftEffectsOverride"] boolValue];
}
// 🔧 turbo mode // 🔧 turbo mode
- (BOOL)isGiftEffectsEnabledForRoom:(NSString *)roomId { - (BOOL)isGiftEffectsEnabledForRoom:(NSString *)roomId {
if (!roomId) return NO; if (!roomId) return NO;
@@ -259,6 +291,7 @@
// RoomAnimationView roomInfo // RoomAnimationView roomInfo
BOOL giftEffects = YES; BOOL giftEffects = YES;
BOOL giftEffectsOverride = NO;
id giftScreenObj = [defaults objectForKey:kTurboGlobalGiftScreenEnabledKey(roomId)]; id giftScreenObj = [defaults objectForKey:kTurboGlobalGiftScreenEnabledKey(roomId)];
BOOL globalGiftScreen = (giftScreenObj != nil) ? [defaults boolForKey:kTurboGlobalGiftScreenEnabledKey(roomId)] : NO; BOOL globalGiftScreen = (giftScreenObj != nil) ? [defaults boolForKey:kTurboGlobalGiftScreenEnabledKey(roomId)] : NO;
@@ -438,6 +471,7 @@
// //
BOOL giftEffects = YES; BOOL giftEffects = YES;
BOOL giftEffectsOverride = NO;
// NSUserDefaults // NSUserDefaults
id giftScreenObj = [defaults objectForKey:kTurboGlobalGiftScreenEnabledKey(roomId)]; id giftScreenObj = [defaults objectForKey:kTurboGlobalGiftScreenEnabledKey(roomId)];
@@ -451,6 +485,7 @@
self.roomSwitchStates[roomId] = @{ self.roomSwitchStates[roomId] = @{
@"giftEffects": @(giftEffects), @"giftEffects": @(giftEffects),
@"giftEffectsOverride": @(giftEffectsOverride),
@"globalGiftScreen": @(globalGiftScreen), @"globalGiftScreen": @(globalGiftScreen),
@"globalGameScreen": @(globalGameScreen), @"globalGameScreen": @(globalGameScreen),
@"cpMic": @(cpMic) @"cpMic": @(cpMic)

View File

@@ -211,8 +211,8 @@
TurboModeStateManager *manager = [TurboModeStateManager sharedManager]; TurboModeStateManager *manager = [TurboModeStateManager sharedManager];
if (sender.tag == 0) { // if (sender.tag == 0) { //
// //
[manager updateGiftEffectsForRoom:self.roomId enabled:isOn]; [manager updateGiftEffectsForRoom:self.roomId enabled:isOn fromUser:YES];
} else if (sender.tag == 1) { // } else if (sender.tag == 1) { //
[manager setGlobalGiftScreenEnabledForRoom:self.roomId enabled:isOn]; [manager setGlobalGiftScreenEnabledForRoom:self.roomId enabled:isOn];

View File

@@ -1727,7 +1727,10 @@ XPCandyTreeInsufficientBalanceViewDelegate>
// roominfo // roominfo
NSString *roomId = @(roomInfo.roomId).stringValue; NSString *roomId = @(roomInfo.roomId).stringValue;
[[TurboModeStateManager sharedManager] updateGiftEffectsForRoom:roomId [[TurboModeStateManager sharedManager] updateGiftEffectsForRoom:roomId
enabled:roomInfo.hasAnimationEffect]; enabled:roomInfo.hasAnimationEffect
fromUser:NO];
//
[[TurboModeStateManager sharedManager] setGiftEffectsOverrideForRoom:roomId enabled:NO];
[self requestBoomData]; [self requestBoomData];
@@ -2498,6 +2501,16 @@ XPCandyTreeInsufficientBalanceViewDelegate>
RoomInfoModel * roomInfo = [RoomInfoModel modelWithDictionary:dic]; RoomInfoModel * roomInfo = [RoomInfoModel modelWithDictionary:dic];
self.roomInfo.hasAnimationEffect = roomInfo.hasAnimationEffect; self.roomInfo.hasAnimationEffect = roomInfo.hasAnimationEffect;
[self.roomHeaderView onRoomUpdate]; [self.roomHeaderView onRoomUpdate];
// TurboModeStateManager
{
NSString *roomId = @(self.roomInfo.roomId).stringValue;
BOOL userOverridden = [[TurboModeStateManager sharedManager] isGiftEffectsUserOverriddenForRoom:roomId];
if (!userOverridden) {
[[TurboModeStateManager sharedManager] updateGiftEffectsForRoom:roomId
enabled:self.roomInfo.hasAnimationEffect
fromUser:NO];
}
}
} }
break; break;
} }