新增 TurboModeStateManager 类以管理全局 Turbo 模式状态,优化房间动画视图中的开关逻辑,确保与 Turbo 模式一致。同时,更新房间更多菜单的 Action 类以支持新的 Turbo 模式开关,提升代码可维护性和用户体验。

This commit is contained in:
edwinQQQ
2025-09-03 18:39:34 +08:00
parent 8dbb02228f
commit f15d229ae1
10 changed files with 419 additions and 83 deletions

View File

@@ -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 = "<group>"; };
4C38C2AE2D84070600CFA4A8 /* AccountBindingViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AccountBindingViewController.h; sourceTree = "<group>"; };
4C38C2AF2D84070600CFA4A8 /* AccountBindingViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AccountBindingViewController.m; sourceTree = "<group>"; };
4C4283F42E66C769006779B0 /* XPTurboModeViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPTurboModeViewController.h; sourceTree = "<group>"; };
4C4283F52E66C769006779B0 /* XPTurboModeViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPTurboModeViewController.m; sourceTree = "<group>"; };
4C4283F42E66C769006779B0 /* XPEffectPanelViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPEffectPanelViewController.h; sourceTree = "<group>"; };
4C4283F52E66C769006779B0 /* XPEffectPanelViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPEffectPanelViewController.m; sourceTree = "<group>"; };
4C44BD5B2D151B5C00F321FA /* RoomSideMenu.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RoomSideMenu.h; sourceTree = "<group>"; };
4C44BD5C2D151B5C00F321FA /* RoomSideMenu.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RoomSideMenu.m; sourceTree = "<group>"; };
4C45C1A32E6825F300E73A44 /* XPTurboModeConstants.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPTurboModeConstants.h; sourceTree = "<group>"; };
4C45C1A42E6825F300E73A44 /* XPTurboModeConstants.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPTurboModeConstants.m; sourceTree = "<group>"; };
4C45C1A62E6837BF00E73A44 /* TurboModeStateManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TurboModeStateManager.h; sourceTree = "<group>"; };
4C45C1A72E6837BF00E73A44 /* TurboModeStateManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TurboModeStateManager.m; sourceTree = "<group>"; };
4C4707A32D53430300C8CD24 /* NSData+GZIP.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSData+GZIP.h"; sourceTree = "<group>"; };
4C4707A42D53430300C8CD24 /* NSData+GZIP.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSData+GZIP.m"; sourceTree = "<group>"; };
4C4DE6442E2513DA00122763 /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/InfoPlist.strings"; sourceTree = "<group>"; };
@@ -6800,6 +6803,15 @@
path = SubViews;
sourceTree = "<group>";
};
4C45C1A82E6837BF00E73A44 /* Manager */ = {
isa = PBXGroup;
children = (
4C45C1A62E6837BF00E73A44 /* TurboModeStateManager.h */,
4C45C1A72E6837BF00E73A44 /* TurboModeStateManager.m */,
);
path = Manager;
sourceTree = "<group>";
};
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 */,

View File

@@ -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];
}

View File

@@ -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;
}

View File

@@ -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];
}
}

View File

@@ -0,0 +1,31 @@
//
// TurboModeStateManager.h
// YuMi
//
// Created by Linus on 2025/1/13.
//
#import <Foundation/Foundation.h>
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<NSString *, NSNumber *> *)getSwitchStatesAfterTurboModeForRoom:(NSString *)roomId;
// 重置全局 turbo mode
- (void)resetTurboMode;
@end
NS_ASSUME_NONNULL_END

View File

@@ -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 = YES3
[self forceCloseAllSwitches:roomId];
NSLog(@"🎮 TurboModeStateManager: 应用 turbo mode房间 %@ 的3个开关全部关闭", roomId);
} else {
// turbo mode = NO
[self forceOpenAllSwitches:roomId];
NSLog(@"🎮 TurboModeStateManager: turbo mode 关闭,房间 %@ 的3个开关全部打开", roomId);
}
}
- (NSDictionary<NSString *, NSNumber *> *)getSwitchStatesAfterTurboModeForRoom:(NSString *)roomId {
if (!roomId) return @{};
BOOL turboModeEnabled = [self isTurboModeEnabled];
if (turboModeEnabled) {
// turbo mode = YES3
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

View File

@@ -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

View File

@@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
* Turbo模式设置控制器
*/
@interface XPTurboModeViewController : MvpViewController
@interface XPEffectPanelViewController : MvpViewController
@property (nonatomic, strong) RoomInfoModel *roomInfo;

View File

@@ -5,13 +5,12 @@
// Created by Linus on 2025/1/13.
//
#import "XPTurboModeViewController.h"
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "XPEffectPanelViewController.h"
#import "RoomInfoModel.h"
#import "XPTurboModeConstants.h"
#import "TurboModeStateManager.h"
@interface XPTurboModeViewController ()
@interface XPEffectPanelViewController () <UIGestureRecognizerDelegate>
@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 = YES3
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];
}

View File

@@ -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