新增 CP SVGA 逻辑迁移测试报告,详细记录了在 MicMidpointRectManager 中新增的 CP 业务逻辑方法及其在 XPRoomViewController 中的简化调用。修复了编译错误,优化了代码结构,提升了可维护性和可测试性。同时,更新了 MicMidpointRectManager 的头文件,添加了新方法的声明,确保代码一致性和清晰性。
This commit is contained in:
@@ -1071,7 +1071,7 @@ XPCandyTreeInsufficientBalanceViewDelegate>
|
||||
|
||||
// 🔧 新增:stage view类型变化时调用CP相关API
|
||||
NSMutableDictionary<NSString *,MicroQueueModel *> *currentQueue = [self.stageView getMicroQueue];
|
||||
[self callMicCpListByUidListOnMicChangeWithQueue:currentQueue];
|
||||
[self callMicCpListByUidListWithQueue:currentQueue];
|
||||
|
||||
// 🔧 新增:检查19 mic房间中央位置(position 6)用户资格
|
||||
[self checkCentralPositionUserQualification:currentQueue];
|
||||
@@ -2566,10 +2566,52 @@ XPCandyTreeInsufficientBalanceViewDelegate>
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case CustomMessageType_CP:
|
||||
switch (attachment.second) {
|
||||
case Custom_Message_Sub_CP_Binding:
|
||||
case Custom_Message_Sub_CP_Upgrade:
|
||||
[self handleCPBindingOrUpgradeMessage:attachment];
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 处理CP绑定或升级消息
|
||||
- (void)handleCPBindingOrUpgradeMessage:(AttachmentModel *)attachment {
|
||||
NSLog(@"🔧 处理CP绑定或升级消息:first=%ld, second=%ld", (long)attachment.first, (long)attachment.second);
|
||||
|
||||
// 只有在完成进房初始化后才处理CP相关逻辑
|
||||
if (!self.hasCompletedRoomInitialization) {
|
||||
NSLog(@"🔧 进房初始化中,跳过CP绑定/升级处理");
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取当前麦位队列
|
||||
NSMutableDictionary<NSString *,MicroQueueModel *> *currentQueue = [self.stageView getMicroQueue];
|
||||
if (!currentQueue) {
|
||||
NSLog(@"⚠️ 无法获取当前麦位队列,跳过CP绑定/升级处理");
|
||||
return;
|
||||
}
|
||||
|
||||
// 使用 MicMidpointRectManager 处理CP绑定/升级消息
|
||||
MicMidpointRectManager *manager = (MicMidpointRectManager *)[self.stageView performSelector:@selector(midpointRectManager)];
|
||||
if (manager) {
|
||||
// 计算麦位总数
|
||||
NSInteger micCount = [self getMicCountForRoomType:self.roomInfo.type];
|
||||
[manager handleCPBindingOrUpgradeMessageWithStageView:self.stageView
|
||||
micCount:micCount
|
||||
queue:currentQueue];
|
||||
}
|
||||
|
||||
// 调用CP API更新状态
|
||||
[self callMicCpListByUidListWithQueue:currentQueue];
|
||||
|
||||
NSLog(@"✅ CP绑定/升级消息处理完成");
|
||||
}
|
||||
|
||||
/// 处理麦位变化相关的CP逻辑
|
||||
- (void)handleMicChangeForCP:(NSMutableDictionary<NSString *,MicroQueueModel *> *)queue {
|
||||
NSLog(@"🔧 处理麦位变化相关的CP逻辑");
|
||||
@@ -2577,19 +2619,22 @@ XPCandyTreeInsufficientBalanceViewDelegate>
|
||||
// 更新当前用户的麦位状态
|
||||
[self updateCurrentUserMicStatus:queue];
|
||||
|
||||
// 更新麦位快照
|
||||
[self updateMicMidpointRectManagerSnapshot];
|
||||
|
||||
// 只有在完成进房初始化后才处理CP相关逻辑
|
||||
if (self.hasCompletedRoomInitialization) {
|
||||
// 检测下麦用户并处理CP关系缓存
|
||||
[self handleDownMicEventIfNeeded:queue];
|
||||
|
||||
// 🔧 新增:处理用户切换mic场景,确保所有CP SVGA状态正确更新
|
||||
[self handleMicSwitchScenarioIfNeeded:queue];
|
||||
// 使用 MicMidpointRectManager 处理CP逻辑
|
||||
MicMidpointRectManager *manager = (MicMidpointRectManager *)[self.stageView performSelector:@selector(midpointRectManager)];
|
||||
if (manager) {
|
||||
// 计算麦位总数
|
||||
NSInteger micCount = [self getMicCountForRoomType:self.roomInfo.type];
|
||||
[manager handleMicChangeForCPWithStageView:self.stageView
|
||||
micCount:micCount
|
||||
queue:queue
|
||||
currentUserUid:[AccountInfoStorage instance].getUid.integerValue
|
||||
roomType:self.roomInfo.type];
|
||||
}
|
||||
|
||||
// 调用CP API
|
||||
[self callMicCpListByUidListOnMicChangeWithQueue:queue];
|
||||
[self callMicCpListByUidListWithQueue:queue];
|
||||
|
||||
// 🔧 新增:检查19 mic房间中央位置用户资格
|
||||
[self checkCentralPositionUserQualification:queue];
|
||||
@@ -2640,8 +2685,11 @@ XPCandyTreeInsufficientBalanceViewDelegate>
|
||||
// 更新当前CP列表
|
||||
self.currentCpList = cpList.copy;
|
||||
|
||||
// 更新 MicMidpointRectManager 的缓存
|
||||
[self updateMicMidpointRectManagerCache:cpList];
|
||||
// 使用 MicMidpointRectManager 处理麦位关系CP消息
|
||||
MicMidpointRectManager *manager = (MicMidpointRectManager *)[self.stageView performSelector:@selector(midpointRectManager)];
|
||||
if (manager) {
|
||||
[manager handleMicRelationshipCPMessage:cpList];
|
||||
}
|
||||
|
||||
// 刷新CP SVGA显示
|
||||
[self drawSocialStageMidpointRects];
|
||||
@@ -3208,28 +3256,42 @@ XPCandyTreeInsufficientBalanceViewDelegate>
|
||||
[[RoomBoomManager sharedManager] receiveEnterRoomBoom:model];
|
||||
}
|
||||
|
||||
- (void)getMicCpListByRoomUidSuccess:(NSArray <MicCpInfoModel *> *)cpList {
|
||||
self.currentCpList = cpList;
|
||||
// 写入 MicMidpointRectManager 缓存后再刷新绘制
|
||||
[self updateMicMidpointRectManagerCache:cpList];
|
||||
// 刷新绘制,按CP关系播放对应SVGA
|
||||
[self drawSocialStageMidpointRects];
|
||||
}
|
||||
|
||||
- (void)getMicCpListByUidListSuccess:(NSArray<MicCpInfoModel *> *)cpList {
|
||||
/// 统一的CP API成功回调方法
|
||||
- (void)handleMicCpListSuccess:(NSArray<MicCpInfoModel *> *)cpList {
|
||||
NSLog(@"🔧 CP API成功回调:接收到 %lu 条CP数据", (unsigned long)cpList.count);
|
||||
|
||||
self.currentCpList = cpList;
|
||||
|
||||
// 🔧 :更新 MicMidpointRectManager 的缓存
|
||||
[self updateMicMidpointRectManagerCache:cpList];
|
||||
|
||||
// 刷新绘制,按CP关系播放对应SVGA
|
||||
[self drawSocialStageMidpointRects];
|
||||
// 使用 MicMidpointRectManager 更新CP列表缓存并重绘
|
||||
MicMidpointRectManager *manager = (MicMidpointRectManager *)[self.stageView performSelector:@selector(midpointRectManager)];
|
||||
if (manager) {
|
||||
// 计算麦位总数
|
||||
NSInteger micCount = [self getMicCountForRoomType:self.roomInfo.type];
|
||||
[manager updateCpListCacheAndRedraw:cpList
|
||||
stageView:self.stageView
|
||||
micCount:micCount
|
||||
roomType:self.roomInfo.type];
|
||||
}
|
||||
|
||||
// 如果当前用户麦位状态发生变化(上麦、下麦、换位),发送 NIM message
|
||||
if (self.currentUserMicStatusChanged) {
|
||||
[self sendMicRelationshipNIMessage:cpList];
|
||||
self.currentUserMicStatusChanged = NO; // 重置标志
|
||||
}
|
||||
|
||||
NSLog(@"🔧 CP API成功回调:处理完成");
|
||||
}
|
||||
|
||||
/// 按房间UID获取CP列表成功回调
|
||||
- (void)getMicCpListByRoomUidSuccess:(NSArray <MicCpInfoModel *> *)cpList {
|
||||
NSLog(@"🔧 按房间UID获取CP列表成功:接收到 %lu 条CP数据", (unsigned long)cpList.count);
|
||||
[self handleMicCpListSuccess:cpList];
|
||||
}
|
||||
|
||||
/// 按用户UID列表获取CP列表成功回调
|
||||
- (void)getMicCpListByUidListSuccess:(NSArray<MicCpInfoModel *> *)cpList {
|
||||
NSLog(@"🔧 按用户UID列表获取CP列表成功:接收到 %lu 条CP数据", (unsigned long)cpList.count);
|
||||
[self handleMicCpListSuccess:cpList];
|
||||
}
|
||||
|
||||
#pragma mark - 首次退出非自己的房间,处理是否需要弹新用户充值优惠
|
||||
@@ -3640,110 +3702,17 @@ XPCandyTreeInsufficientBalanceViewDelegate>
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *stageViewClass = NSStringFromClass([self.stageView class]);
|
||||
NSLog(@"🔧 开始绘制 %@ 中点矩形", stageViewClass);
|
||||
|
||||
// 移除旧的调试矩形
|
||||
if ([self.stageView respondsToSelector:@selector(midpointRectManager)]) {
|
||||
// 使用新的管理器移除所有中点矩形
|
||||
id manager = [self.stageView valueForKey:@"midpointRectManager"];
|
||||
if ([manager respondsToSelector:@selector(removeAllMidpointRects)]) {
|
||||
[manager removeAllMidpointRects];
|
||||
}
|
||||
// 设置房间类型到管理器
|
||||
if ([manager respondsToSelector:@selector(setRoomType:)]) {
|
||||
[manager setRoomType:self.roomInfo.type];
|
||||
}
|
||||
// 使用 MicMidpointRectManager 绘制社交舞台中点矩形
|
||||
MicMidpointRectManager *manager = (MicMidpointRectManager *)[self.stageView performSelector:@selector(midpointRectManager)];
|
||||
if (manager) {
|
||||
// 计算麦位总数
|
||||
NSInteger micCount = [self getMicCountForRoomType:self.roomInfo.type];
|
||||
[manager drawSocialStageMidpointRectsWithStageView:self.stageView
|
||||
micCount:micCount
|
||||
roomType:self.roomInfo.type];
|
||||
} else {
|
||||
// 兼容旧方式
|
||||
NSArray<UIView *> *subviews = [self.stageView.subviews copy];
|
||||
for (UIView *view in subviews) {
|
||||
if (view.tag == 56002) {
|
||||
[view removeFromSuperview];
|
||||
}
|
||||
}
|
||||
NSLog(@"🔧 无法获取 midpointRectManager,跳过中点矩形绘制");
|
||||
}
|
||||
|
||||
// 根据不同的 StageView 类型绘制相应的中点矩形
|
||||
NSArray *validPairs = nil;
|
||||
|
||||
if ([self.stageView isKindOfClass:[SocialStageView class]]) {
|
||||
validPairs = @[@[@1, @2], @[@2, @3], @[@3, @4], @[@5, @6], @[@6, @7], @[@7, @8]];
|
||||
} else if ([self.stageView isKindOfClass:[TenMicStageView class]]) {
|
||||
validPairs = @[@[@0, @1], @[@1, @2], @[@2, @3], @[@3, @4], @[@5, @6], @[@6, @7], @[@7, @8], @[@8, @9]];
|
||||
} else if ([self.stageView isKindOfClass:[FifteenMicStageView class]]) {
|
||||
validPairs = @[@[@0, @1], @[@1, @2], @[@2, @3], @[@3, @4], @[@5, @6], @[@6, @7], @[@7, @8], @[@8, @9], @[@10, @11], @[@11, @12], @[@12, @13], @[@13, @14]];
|
||||
} else if ([self.stageView isKindOfClass:[NineteenMicStageView class]]) {
|
||||
validPairs = @[@[@0, @1], @[@1, @2], @[@2, @3], @[@3, @4], @[@5, @6], @[@8, @9], @[@10, @11], @[@12, @13], @[@14, @15], @[@15, @16], @[@16, @17], @[@17, @18]];
|
||||
} else if ([self.stageView isKindOfClass:[TwentyMicStageView class]]) {
|
||||
validPairs = @[@[@0, @1], @[@1, @2], @[@2, @3], @[@3, @4], @[@5, @6], @[@6, @7], @[@7, @8], @[@8, @9], @[@10, @11], @[@11, @12], @[@12, @13], @[@13, @14], @[@15, @16], @[@16, @17], @[@17, @18], @[@18, @19]];
|
||||
} else if ([self.stageView isKindOfClass:[AnchorStageView class]]) {
|
||||
validPairs = @[@[@1, @2], @[@2, @3]];
|
||||
} else if ([self.stageView isKindOfClass:[DatingStageView class]]) {
|
||||
validPairs = @[@[@1, @2], @[@3, @4], @[@5, @6], @[@7, @8]];
|
||||
} else if ([self.stageView isKindOfClass:[LittleGameStageView class]]) {
|
||||
validPairs = @[@[@0, @1], @[@1, @2], @[@2, @3], @[@3, @4], @[@4, @5]];
|
||||
} else if ([self.stageView isKindOfClass:[LittleGameScrollStageView class]]) {
|
||||
// 根据实际麦位数量动态生成相邻对
|
||||
NSInteger micCount = [self.stageView countOfMicroView];
|
||||
NSMutableArray *pairs = [NSMutableArray array];
|
||||
for (NSInteger i = 0; i < micCount - 1; i++) {
|
||||
[pairs addObject:@[@(i), @(i + 1)]];
|
||||
}
|
||||
validPairs = pairs;
|
||||
} else if ([self.stageView isKindOfClass:[AnchorPKStageView class]]) {
|
||||
validPairs = @[@[@0, @1]];
|
||||
} else {
|
||||
NSLog(@"🔧 未支持的 StageView 类型: %@", stageViewClass);
|
||||
return;
|
||||
}
|
||||
|
||||
NSLog(@"🔧 开始绘制 %@ 中点矩形,共 %lu 对相邻麦位", stageViewClass, (unsigned long)validPairs.count);
|
||||
|
||||
for (NSArray *pair in validPairs) {
|
||||
NSInteger firstIndex = [pair[0] integerValue];
|
||||
NSInteger secondIndex = [pair[1] integerValue];
|
||||
|
||||
CGRect rect = [self.stageView rectForMidpointBetweenMicAtIndex:firstIndex andIndex:secondIndex];
|
||||
if (!CGRectIsEmpty(rect)) {
|
||||
UIView *micRelationshipView = [[UIView alloc] initWithFrame:rect];
|
||||
micRelationshipView.backgroundColor = [[UIColor blueColor] colorWithAlphaComponent:0.3];
|
||||
micRelationshipView.layer.borderColor = [UIColor blueColor].CGColor;
|
||||
micRelationshipView.layer.borderWidth = 2.0;
|
||||
micRelationshipView.layer.cornerRadius = 8.0;
|
||||
micRelationshipView.tag = 56002;
|
||||
micRelationshipView.userInteractionEnabled = NO;
|
||||
|
||||
// 添加标签显示麦位对
|
||||
UILabel *label = [[UILabel alloc] init];
|
||||
label.text = [NSString stringWithFormat:@"%ld-%ld", (long)firstIndex, (long)secondIndex];
|
||||
label.textColor = [UIColor whiteColor];
|
||||
label.font = [UIFont boldSystemFontOfSize:12];
|
||||
label.textAlignment = NSTextAlignmentCenter;
|
||||
label.frame = micRelationshipView.bounds;
|
||||
[micRelationshipView addSubview:label];
|
||||
|
||||
// 统一逻辑:优先通过 midpointRectManager 管理器添加与播放SVGA;无管理器时回退为直接添加
|
||||
if ([self.stageView respondsToSelector:@selector(midpointRectManager)]) {
|
||||
id manager = [self.stageView valueForKey:@"midpointRectManager"];
|
||||
if ([manager respondsToSelector:@selector(addRelationshipAtFrame:micPairText:leftUid:rightUid:cpList:)]) {
|
||||
NSString *micPairText = [NSString stringWithFormat:@"%ld-%ld", (long)firstIndex, (long)secondIndex];
|
||||
UIView<MicroViewProtocol> *leftView = [self.stageView findMicroViewByIndex:firstIndex];
|
||||
UIView<MicroViewProtocol> *rightView = [self.stageView findMicroViewByIndex:secondIndex];
|
||||
NSInteger leftUid = [[leftView getUser] uid];
|
||||
NSInteger rightUid = [[rightView getUser] uid];
|
||||
[manager addRelationshipAtFrame:rect micPairText:micPairText leftUid:leftUid rightUid:rightUid cpList:self.currentCpList ?: @[]];
|
||||
}
|
||||
} else {
|
||||
[self.stageView addSubview:micRelationshipView];
|
||||
}
|
||||
NSLog(@"🔧 绘制中点矩形: %ld-%ld, rect: %@", (long)firstIndex, (long)secondIndex, NSStringFromCGRect(rect));
|
||||
} else {
|
||||
NSLog(@"🔧 跳过无效麦位对: %ld-%ld", (long)firstIndex, (long)secondIndex);
|
||||
}
|
||||
}
|
||||
|
||||
NSLog(@"🔧 %@ 中点矩形绘制完成", stageViewClass);
|
||||
}
|
||||
|
||||
/// 进房成功后调用CP相关API
|
||||
@@ -3783,7 +3752,8 @@ XPCandyTreeInsufficientBalanceViewDelegate>
|
||||
if (currentUserMicPosition == -1) {
|
||||
NSLog(@"🔧 获取mic用户列表:当前用户不在麦上,返回空数据");
|
||||
// 通知 manager 移除该用户 UID 的相关数据
|
||||
[self removeCurrentUserCpDataFromManager];
|
||||
NSInteger currentUid = [AccountInfoStorage instance].getUid.integerValue;
|
||||
[self removeCpDataForUids:@[@(currentUid)]];
|
||||
return micUserUids;
|
||||
}
|
||||
|
||||
@@ -3839,12 +3809,10 @@ XPCandyTreeInsufficientBalanceViewDelegate>
|
||||
}
|
||||
}
|
||||
|
||||
// 如果只有当前用户一个人,返回空数据
|
||||
// 🔧 修复:即使只有当前用户一个人,也返回当前用户的UID,确保能触发NIM message
|
||||
if (micUserUids.count == 1) {
|
||||
NSLog(@"🔧 获取mic用户列表:只有当前用户一个人,返回空数据");
|
||||
// 通知 manager 移除该用户 UID 的相关数据
|
||||
[self removeCurrentUserCpDataFromManager];
|
||||
return [NSArray array];
|
||||
NSLog(@"🔧 获取mic用户列表:只有当前用户一个人,但仍需发送NIM message");
|
||||
// 不返回空数组,保持当前用户UID,确保能触发CP API和NIM message
|
||||
}
|
||||
|
||||
NSLog(@"🔧 获取mic用户列表:当前用户麦位 %ld,找到 %lu 个相关用户: %@",
|
||||
@@ -3852,6 +3820,7 @@ XPCandyTreeInsufficientBalanceViewDelegate>
|
||||
return micUserUids;
|
||||
}
|
||||
|
||||
|
||||
/// 处理其他用户mic变化(包括切换场景)
|
||||
- (void)handleOtherUserMicChange:(UserInfoModel *)userInfo changeType:(NSInteger)changeType {
|
||||
if (!self.stageView || ![self.stageView respondsToSelector:@selector(midpointRectManager)]) {
|
||||
@@ -3859,178 +3828,102 @@ XPCandyTreeInsufficientBalanceViewDelegate>
|
||||
return;
|
||||
}
|
||||
|
||||
MicMidpointRectManager *midpointRectManager = (MicMidpointRectManager *)[self.stageView performSelector:@selector(midpointRectManager)];
|
||||
if (!midpointRectManager) {
|
||||
NSLog(@"🔧 处理其他用户mic变化:无法获取 midpointRectManager,跳过处理");
|
||||
// 获取当前麦位队列
|
||||
NSMutableDictionary<NSString *,MicroQueueModel *> *currentQueue = [self.stageView getMicroQueue];
|
||||
if (!currentQueue) {
|
||||
NSLog(@"🔧 处理其他用户mic变化:无法获取当前麦位队列,跳过处理");
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置房间类型
|
||||
midpointRectManager.roomType = self.roomInfo.type;
|
||||
|
||||
NSInteger userUid = userInfo.uid;
|
||||
NSArray<NSNumber *> *userUids = @[@(userUid)];
|
||||
|
||||
if (changeType == 2) {
|
||||
// 其他用户下麦
|
||||
NSLog(@"🔧 处理其他用户下麦:UID %ld", (long)userUid);
|
||||
|
||||
// 更新快照
|
||||
[self updateMicMidpointRectManagerSnapshot];
|
||||
|
||||
// 清除与该用户相关的cp与SVGA
|
||||
[midpointRectManager removeCpEntriesForUids:userUids];
|
||||
[midpointRectManager removeMidpointRectsForUids:userUids];
|
||||
|
||||
// 重绘(根据现有缓存)
|
||||
[self drawSocialStageMidpointRects];
|
||||
|
||||
NSLog(@"🔧 其他用户下麦处理完成:UID %ld", (long)userUid);
|
||||
} else if (changeType == 1) {
|
||||
// 其他用户上麦
|
||||
NSLog(@"🔧 处理其他用户上麦:UID %ld", (long)userUid);
|
||||
|
||||
// 更新快照
|
||||
[self updateMicMidpointRectManagerSnapshot];
|
||||
|
||||
// 重新绘制所有CP关系(包括新上麦用户可能产生的CP关系)
|
||||
[self drawSocialStageMidpointRects];
|
||||
|
||||
NSLog(@"🔧 其他用户上麦处理完成:UID %ld", (long)userUid);
|
||||
}
|
||||
}
|
||||
|
||||
/// 移除当前用户的CP数据从manager中
|
||||
- (void)removeCurrentUserCpDataFromManager {
|
||||
if (!self.stageView || ![self.stageView respondsToSelector:@selector(midpointRectManager)]) {
|
||||
NSLog(@"🔧 移除当前用户CP数据:stageView 不支持 midpointRectManager,跳过处理");
|
||||
return;
|
||||
// 使用 MicMidpointRectManager 处理其他用户mic变化
|
||||
MicMidpointRectManager *manager = (MicMidpointRectManager *)[self.stageView performSelector:@selector(midpointRectManager)];
|
||||
if (manager) {
|
||||
// 计算麦位总数
|
||||
NSInteger micCount = [self getMicCountForRoomType:self.roomInfo.type];
|
||||
[manager handleOtherUserMicChange:userInfo
|
||||
changeType:changeType
|
||||
stageView:self.stageView
|
||||
micCount:micCount
|
||||
queue:currentQueue
|
||||
roomType:self.roomInfo.type];
|
||||
}
|
||||
|
||||
NSInteger currentUid = [AccountInfoStorage instance].getUid.integerValue;
|
||||
NSArray<NSNumber *> *removedUids = @[@(currentUid)];
|
||||
|
||||
MicMidpointRectManager *midpointRectManager = (MicMidpointRectManager *)[self.stageView performSelector:@selector(midpointRectManager)];
|
||||
if (midpointRectManager) {
|
||||
// 设置房间类型
|
||||
midpointRectManager.roomType = self.roomInfo.type;
|
||||
// 从缓存移除
|
||||
[midpointRectManager removeCpEntriesForUids:removedUids];
|
||||
// 从UI移除
|
||||
[midpointRectManager removeMidpointRectsForUids:removedUids];
|
||||
NSLog(@"🔧 移除当前用户CP数据完成:UID %ld", (long)currentUid);
|
||||
}
|
||||
}
|
||||
|
||||
/// 处理用户切换mic场景,确保所有CP SVGA状态正确更新
|
||||
- (void)handleMicSwitchScenarioIfNeeded:(NSMutableDictionary<NSString *,MicroQueueModel *> *)queue {
|
||||
if (!self.stageView || ![self.stageView respondsToSelector:@selector(midpointRectManager)]) {
|
||||
NSLog(@"🔧 处理切换mic场景:stageView 不支持 midpointRectManager,跳过处理");
|
||||
return;
|
||||
}
|
||||
|
||||
// 🔧 改进:基于当前用户麦位状态变化来检测切换场景
|
||||
// 检查当前用户是否发生了麦位变化
|
||||
BOOL hasMicPositionChanged = self.currentUserMicStatusChanged;
|
||||
|
||||
if (hasMicPositionChanged) {
|
||||
NSLog(@"🔧 检测到当前用户麦位状态变化,可能是切换mic场景");
|
||||
|
||||
// 获取当前舞台类型的麦位总数
|
||||
NSInteger micCount = 0;
|
||||
if (self.roomInfo) {
|
||||
switch (self.roomInfo.type) {
|
||||
case RoomType_Room: micCount = 9; break;
|
||||
case RoomType_10Mic: micCount = 10; break;
|
||||
case RoomType_15Mic: micCount = 15; break;
|
||||
case RoomType_19Mic: micCount = 19; break;
|
||||
case RoomType_20Mic: micCount = 20; break;
|
||||
default: micCount = 9; break;
|
||||
// 处理API调用
|
||||
if (changeType == 2) { // 其他用户下麦
|
||||
// 获取剩余用户列表
|
||||
NSMutableArray<NSString *> *remainingUids = [NSMutableArray array];
|
||||
for (NSString *positionKey in currentQueue.allKeys) {
|
||||
MicroQueueModel *micModel = currentQueue[positionKey];
|
||||
if (micModel && micModel.userInfo && micModel.userInfo.uid > 0) {
|
||||
[remainingUids addObject:[NSString stringWithFormat:@"%ld", (long)micModel.userInfo.uid]];
|
||||
}
|
||||
}
|
||||
|
||||
MicMidpointRectManager *midpointRectManager = (MicMidpointRectManager *)[self.stageView performSelector:@selector(midpointRectManager)];
|
||||
if (midpointRectManager) {
|
||||
// 设置房间类型
|
||||
midpointRectManager.roomType = self.roomInfo.type;
|
||||
|
||||
// 对于麦位变化场景,需要重新构建所有CP关系
|
||||
// 1. 清除所有现有的中点矩形和SVGA
|
||||
[midpointRectManager removeAllMidpointRects];
|
||||
|
||||
// 2. 重新构建麦位快照
|
||||
[midpointRectManager rebuildMicSnapshotWithStageView:self.stageView micCount:micCount];
|
||||
|
||||
// 3. 重新绘制所有CP关系
|
||||
[self drawSocialStageMidpointRects];
|
||||
|
||||
NSLog(@"🔧 用户麦位变化场景处理完成:重新构建了所有CP关系");
|
||||
// 调用API更新剩余用户的CP状态
|
||||
if (remainingUids.count > 0) {
|
||||
[self.presenter micCpListByUidList:remainingUids];
|
||||
}
|
||||
|
||||
// 🔧 注意:不在这里重置状态标志,等待API成功回调后再重置
|
||||
// 状态标志将在 getMicCpListByUidListSuccess 中重置,确保能发送云信消息
|
||||
} else {
|
||||
NSLog(@"🔧 当前用户麦位状态未变化,跳过切换场景处理");
|
||||
// 重绘
|
||||
[self drawSocialStageMidpointRects];
|
||||
|
||||
} else if (changeType == 1) { // 其他用户上麦
|
||||
// 调用CP API更新状态
|
||||
[self callMicCpListByUidListWithQueue:currentQueue];
|
||||
|
||||
// 重新绘制所有CP关系
|
||||
[self drawSocialStageMidpointRects];
|
||||
}
|
||||
}
|
||||
|
||||
/// 检测并处理下麦事件
|
||||
- (void)handleDownMicEventIfNeeded:(NSMutableDictionary<NSString *,MicroQueueModel *> *)queue {
|
||||
|
||||
/// 通用的CP数据移除方法
|
||||
- (void)removeCpDataForUids:(NSArray<NSNumber *> *)uids {
|
||||
if (!self.stageView || ![self.stageView respondsToSelector:@selector(midpointRectManager)]) {
|
||||
NSLog(@"🔧 处理下麦事件:stageView 不支持 midpointRectManager,跳过处理");
|
||||
NSLog(@"🔧 移除CP数据:stageView 不支持 midpointRectManager,跳过处理");
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取当前舞台类型的麦位总数
|
||||
NSInteger micCount = 0;
|
||||
if (self.roomInfo) {
|
||||
switch (self.roomInfo.type) {
|
||||
case RoomType_Room: micCount = 9; break;
|
||||
case RoomType_10Mic: micCount = 10; break;
|
||||
case RoomType_15Mic: micCount = 15; break;
|
||||
case RoomType_19Mic: micCount = 19; break;
|
||||
case RoomType_20Mic: micCount = 20; break;
|
||||
default: micCount = 9; break;
|
||||
}
|
||||
if (uids.count == 0) {
|
||||
NSLog(@"🔧 移除CP数据:没有需要移除的用户,跳过处理");
|
||||
return;
|
||||
}
|
||||
|
||||
// 使用 MicMidpointRectManager 检测麦位变化
|
||||
// MicMidpointRectManager *midpointRectManager = [self.stageView midpointRectManager];
|
||||
MicMidpointRectManager *midpointRectManager = (MicMidpointRectManager *)[self.stageView performSelector:@selector(midpointRectManager)];
|
||||
if (midpointRectManager) {
|
||||
// 设置房间类型
|
||||
midpointRectManager.roomType = self.roomInfo.type;
|
||||
NSDictionary<NSString *, NSArray<NSNumber *> *> *micChanges =
|
||||
[midpointRectManager diffMicChangeWithStageView:self.stageView micCount:micCount];
|
||||
|
||||
NSArray<NSNumber *> *removedUids = micChanges[@"removed"];
|
||||
if (removedUids && removedUids.count > 0) {
|
||||
NSLog(@"🔧 检测到下麦用户:%@", removedUids);
|
||||
|
||||
// 调用 MicMidpointRectManager 处理下麦事件
|
||||
[midpointRectManager handleDownMicEvent:removedUids stageView:self.stageView micCount:micCount];
|
||||
}
|
||||
// 使用 MicMidpointRectManager 移除CP数据
|
||||
MicMidpointRectManager *manager = (MicMidpointRectManager *)[self.stageView performSelector:@selector(midpointRectManager)];
|
||||
if (manager) {
|
||||
[manager removeCpDataForUids:uids];
|
||||
NSLog(@"🔧 移除CP数据完成:UIDs %@", uids);
|
||||
}
|
||||
}
|
||||
|
||||
/// mic位变动时调用CP相关API
|
||||
- (void)callMicCpListByUidListOnMicChangeWithQueue:(NSMutableDictionary<NSString *,MicroQueueModel *> *)queue {
|
||||
NSLog(@"🔧 mic位变动:开始调用 micCpListByUidList API");
|
||||
|
||||
/// 统一的CP API调用方法
|
||||
- (void)callMicCpListByUidListWithQueue:(NSMutableDictionary<NSString *,MicroQueueModel *> *)queue {
|
||||
NSLog(@"🔧 调用CP API:开始获取mic用户列表");
|
||||
|
||||
NSArray<NSString *> *micUserUids = [self getAllMicUserUidsWithQueue:queue];
|
||||
// 直接从queue获取当前所有在mic上的用户uid列表,确保数据是最新的
|
||||
NSMutableArray<NSString *> *micUserUids = [NSMutableArray array];
|
||||
|
||||
if (queue) {
|
||||
for (NSString *positionKey in queue.allKeys) {
|
||||
MicroQueueModel *micModel = queue[positionKey];
|
||||
if (micModel && micModel.userInfo && micModel.userInfo.uid > 0) {
|
||||
[micUserUids addObject:[NSString stringWithFormat:@"%ld", (long)micModel.userInfo.uid]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (micUserUids.count == 0) {
|
||||
NSLog(@"🔧 mic位变动:没有相关用户在mic上,跳过API调用");
|
||||
NSLog(@"🔧 调用CP API:没有用户在mic上,跳过API调用");
|
||||
return;
|
||||
}
|
||||
|
||||
// 调用 micCpListByUidList 方法
|
||||
if ([micUserUids containsObject:[AccountInfoStorage instance].getUid]) {
|
||||
NSLog(@"🔧 mic位变动,且包含了当前用户:调用 micCpListByUidList: %@", micUserUids);
|
||||
[self.presenter micCpListByUidList:micUserUids];
|
||||
}
|
||||
NSLog(@"🔧 调用CP API:micCpListByUidList: %@", micUserUids);
|
||||
[self.presenter micCpListByUidList:micUserUids];
|
||||
|
||||
NSLog(@"🔧 mic位变动:micCpListByUidList API调用完成");
|
||||
NSLog(@"🔧 调用CP API:完成");
|
||||
}
|
||||
|
||||
/// 初始化当前用户的麦位状态
|
||||
@@ -4294,6 +4187,18 @@ XPCandyTreeInsufficientBalanceViewDelegate>
|
||||
}
|
||||
}
|
||||
|
||||
/// 根据房间类型获取麦位总数
|
||||
- (NSInteger)getMicCountForRoomType:(NSInteger)roomType {
|
||||
switch (roomType) {
|
||||
case RoomType_Room: return 9;
|
||||
case RoomType_10Mic: return 10;
|
||||
case RoomType_15Mic: return 15;
|
||||
case RoomType_19Mic: return 19;
|
||||
case RoomType_20Mic: return 20;
|
||||
default: return 9;
|
||||
}
|
||||
}
|
||||
|
||||
/// 检查19 mic房间中央位置(position 6)用户资格
|
||||
- (void)checkCentralPositionUserQualification:(NSMutableDictionary<NSString *,MicroQueueModel *> *)queue {
|
||||
// 只检查19 mic房间
|
||||
|
Reference in New Issue
Block a user