新增连击计数逻辑修正总结文档,详细记录了连击计数的修正目标、发现的问题及其根源,主要修改内容包括 GiftComboManager、GiftComboView 和 XPSendGiftView 的接口优化和逻辑调整,确保连击计数基于 API 成功回调,提升了用户体验和代码可维护性。同时,更新了相关方法以支持新的逻辑流程和状态管理。
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
# 连击计数逻辑修正总结
|
||||
|
||||
## 修正目标
|
||||
确保所有的 combo/comboCount 增加都基于 API "gift/sendV5" 的成功回调,重置时机是 comboView 展示时。
|
||||
|
||||
## 发现的问题
|
||||
|
||||
### 🚨 关键问题:comboView 没有显示
|
||||
通过日志分析发现:
|
||||
1. combo状态在变化,但`isCombing: NO`
|
||||
2. ComboAction_ShowPanel没有被触发
|
||||
3. comboView没有显示,但后台状态在继续变化
|
||||
|
||||
### 🔍 问题根源
|
||||
`resetOnComboViewShow`方法不完整,缺少UI显示逻辑:
|
||||
- 只重置了combo计数,但没有触发UI显示
|
||||
- 缺少设置`isCombing = YES`的逻辑
|
||||
- 缺少调用`actionCallback(ComboAction_ShowPanel)`的逻辑
|
||||
|
||||
## 主要修改内容
|
||||
|
||||
### 1. GiftComboManager.m 修改
|
||||
|
||||
#### 新增简化接口方法
|
||||
- `reset()` - 实现简化接口,调用 resetCombo
|
||||
- `activate()` - 激活连击功能
|
||||
- `deactivate()` - 停用连击功能
|
||||
- `isActive()` - 检查是否激活
|
||||
- `currentCount()` - 获取当前连击计数
|
||||
- `incrementCount()` - 增加连击计数
|
||||
- `clear()` - 清除连击状态
|
||||
- `send()` - 发送连击礼物
|
||||
- `stateInfo()` - 获取完整状态信息
|
||||
- `canStartCombo()` - 检查是否可以开始连击
|
||||
- `validateState()` - 验证并修复状态
|
||||
- `handleError()` - 处理错误
|
||||
- `lastErrorMessage()` - 获取最后错误信息
|
||||
- `clearError()` - 清除错误
|
||||
|
||||
#### 修改 API 成功回调逻辑
|
||||
- 在 `handleSendGiftSuccess()` 方法中,将 combo 递增逻辑从用户点击时移到 API 成功时
|
||||
- 在 API 成功时递增 combo 计数:`self.combo += 1;`
|
||||
|
||||
#### 修改强制重置逻辑
|
||||
- 在 `forceRemove()` 和 `forceBoomStateReset()` 方法中,重置 combo 计数为 0
|
||||
|
||||
### 2. GiftComboView.m 修改
|
||||
|
||||
#### 移除用户点击时的 combo 递增
|
||||
- 在 `handleTap()` 方法中,移除 `loadComboCountFromSendGiftView` 调用
|
||||
- 移除用户点击时的 combo 计数更新
|
||||
- 改为直接发送礼物,combo 计数在 API 成功回调时递增
|
||||
|
||||
### 3. XPSendGiftView.m 修改
|
||||
|
||||
#### 修正方法调用
|
||||
- 使用 `resetCombo` 方法,确保在 comboView 展示时正确触发UI显示
|
||||
- `resetCombo` 方法包含完整的逻辑:重置combo计数 + 触发UI显示 + 设置状态
|
||||
|
||||
## 修正后的逻辑流程
|
||||
|
||||
### 1. 第一个礼物发送时(sendGiftSuccess)
|
||||
```objc
|
||||
[[GiftComboManager sharedManager] resetCombo]; // combo = 1, 触发UI显示
|
||||
[self sendCustomMessage:receiveInfo oringinDic:originDic]; // 发送 comboCount = 1
|
||||
```
|
||||
|
||||
### 2. 用户点击连击面板时
|
||||
```objc
|
||||
[[GiftComboManager sharedManager] sendGift]; // 直接触发 API 请求,不递增 combo
|
||||
```
|
||||
|
||||
### 3. API "gift/sendV5" 成功回调时
|
||||
```objc
|
||||
self.combo += 1; // 在 API 成功时递增 combo 计数
|
||||
NSInteger comboToSet = self.combo; // 使用递增后的值
|
||||
[dic setObject:@(comboToSet) forKey:@"comboCount"]; // 发送云信消息
|
||||
```
|
||||
|
||||
### 4. comboView 展示时
|
||||
```objc
|
||||
_combo = 1; // 重置为 1
|
||||
self.actionCallback(ComboAction_ShowPanel); // 触发UI显示
|
||||
self.isCombing = YES; // 设置状态
|
||||
```
|
||||
|
||||
### 5. combo 结束时
|
||||
```objc
|
||||
_combo = 0; // 重置为 0
|
||||
```
|
||||
|
||||
## 关键改进点
|
||||
|
||||
1. **时机修正**:combo 计数递增从用户点击时移到 API 成功时
|
||||
2. **UI显示修复**:使用 `resetCombo` 方法确保 comboView 正确显示
|
||||
3. **状态管理**:正确设置 `isCombing` 状态
|
||||
4. **逻辑清晰**:所有 combo 计数变化都基于 API 成功回调
|
||||
|
||||
## 验证要点
|
||||
|
||||
1. 第一个礼物发送时,combo 计数为 1,comboView 正确显示
|
||||
2. 用户点击连击面板时,combo 计数不变
|
||||
3. API 成功时,combo 计数递增
|
||||
4. comboView 展示时,combo 计数重置为 1,UI正确显示
|
||||
5. combo 结束时,combo 计数重置为 0
|
||||
|
||||
## 问题解决
|
||||
|
||||
✅ **comboView 显示问题已解决**:使用 `resetCombo` 方法确保UI正确显示
|
||||
✅ **combo 计数时机已修正**:所有递增都基于API成功回调
|
||||
✅ **状态管理已完善**:正确设置和重置combo状态
|
@@ -151,8 +151,78 @@ NSString * const kBoomStateForceResetNotification = @"BoomStateForceResetNotific
|
||||
self.actionCallback = action;
|
||||
}
|
||||
|
||||
// 新增:实现简化接口reset方法
|
||||
- (void)reset {
|
||||
NSLog(@"[Combo effect] 🔄 调用简化接口reset方法");
|
||||
[self resetCombo];
|
||||
}
|
||||
|
||||
// 新增:实现其他简化接口方法
|
||||
- (void)activate {
|
||||
NSLog(@"[Combo effect] 🔧 激活连击功能");
|
||||
self.enableCombo = YES;
|
||||
}
|
||||
|
||||
- (void)deactivate {
|
||||
NSLog(@"[Combo effect] 🔧 停用连击功能");
|
||||
self.enableCombo = NO;
|
||||
}
|
||||
|
||||
- (BOOL)isActive {
|
||||
return self.isCombing && self.enableCombo;
|
||||
}
|
||||
|
||||
- (NSInteger)currentCount {
|
||||
return [self loadComboCount];
|
||||
}
|
||||
|
||||
- (void)incrementCount {
|
||||
NSLog(@"[Combo effect] 🔢 增加连击计数 - 当前: %ld -> %ld", (long)self.combo, (long)(self.combo + 1));
|
||||
self.combo += 1;
|
||||
}
|
||||
|
||||
- (void)clear {
|
||||
NSLog(@"[Combo effect] 🗑️ 清除连击状态");
|
||||
[self forceRemove];
|
||||
}
|
||||
|
||||
- (void)send {
|
||||
NSLog(@"[Combo effect] 📤 发送连击礼物");
|
||||
[self sendGift];
|
||||
}
|
||||
|
||||
- (NSDictionary *)stateInfo {
|
||||
return [self getComboStateInfo];
|
||||
}
|
||||
|
||||
- (BOOL)canStartCombo {
|
||||
return self.enableCombo && self.giftInfo != nil && self.sendGiftToUIDs.count > 0;
|
||||
}
|
||||
|
||||
- (void)validateState {
|
||||
[self validateAndFixComboCount];
|
||||
}
|
||||
|
||||
- (void)handleError:(NSError *)error {
|
||||
NSLog(@"[Combo effect] ❌ 处理错误: %@", error.localizedDescription);
|
||||
self.errorMessage = error.localizedDescription;
|
||||
}
|
||||
|
||||
- (NSString *)lastErrorMessage {
|
||||
return self.errorMessage ?: @"";
|
||||
}
|
||||
|
||||
- (void)clearError {
|
||||
self.errorMessage = @"";
|
||||
}
|
||||
|
||||
- (void)forceRemove {
|
||||
NSLog(@"[Combo effect] 🚨 触发forceRemove - combo: %ld, isCombing: %@", (long)self.combo, self.isCombing ? @"YES" : @"NO");
|
||||
|
||||
// 重置combo计数为0
|
||||
_combo = 0;
|
||||
NSLog(@"[Combo effect] 🔄 combo计数重置为0");
|
||||
|
||||
// 调用新的强制重置方法
|
||||
[self forceBoomStateReset];
|
||||
|
||||
@@ -179,13 +249,14 @@ NSString * const kBoomStateForceResetNotification = @"BoomStateForceResetNotific
|
||||
self.isCombing ? @"YES" : @"NO");
|
||||
self.isCombing = NO;
|
||||
|
||||
// 4. 重置combo计数为0
|
||||
_combo = 0;
|
||||
NSLog(@"[Combo effect] 🔄 combo计数重置为0");
|
||||
|
||||
// 注意:不重置 enableCombo,保持连击功能可用状态
|
||||
// self.enableCombo = NO; // 移除这行,保持连击功能可用
|
||||
|
||||
// 注意:不重置 combo 计数,保持连击计数的连续性
|
||||
// 连击计数应该在下次 resetCombo 时重置为 1
|
||||
|
||||
// 4. 注意:不清理 actionCallback,保持回调可用,以便重新进入连击状态
|
||||
// 注意:不清理 actionCallback,保持回调可用,以便重新进入连击状态
|
||||
// self.actionCallback = nil; // 移除这行,保持回调可用
|
||||
|
||||
// 5. 发送通知(优先级最高,通知所有相关组件)
|
||||
@@ -755,9 +826,12 @@ NSString * const kBoomStateForceResetNotification = @"BoomStateForceResetNotific
|
||||
// 验证连击计数有效性
|
||||
[self validateAndFixComboCount];
|
||||
|
||||
// 更新连击计数(连击面板点击时)
|
||||
// 在API成功时递增combo计数
|
||||
if (self.isCombing) {
|
||||
NSLog(@"[Combo effect] 🔢 连击进行中,更新连击计数");
|
||||
NSLog(@"[Combo effect] 🔢 API成功,递增连击计数 - 当前: %ld -> %ld", (long)self.combo, (long)(self.combo + 1));
|
||||
self.combo += 1;
|
||||
|
||||
// 更新UI显示
|
||||
if (self.actionCallback) {
|
||||
self.actionCallback(ComboAction_Combo_Count_Update);
|
||||
}
|
||||
|
@@ -133,7 +133,7 @@
|
||||
|
||||
- (void)updateCount {
|
||||
// 在连击面板点击时,需要先更新连击计数
|
||||
NSInteger comboCount = [[GiftComboManager sharedManager] loadComboCount];
|
||||
NSInteger comboCount = [[GiftComboManager sharedManager] currentCount];
|
||||
NSLog(@"[Combo effect] 🔢 更新连击次数显示 - combo: %ld", (long)comboCount);
|
||||
NSString *countStr = [NSString stringWithFormat:@"x%ld", comboCount];
|
||||
NSShadow *shadow = [[NSShadow alloc] init];
|
||||
@@ -253,7 +253,7 @@
|
||||
@kStrongify(self);
|
||||
NSLog(@"[Combo effect] ⏰ 连击倒计时结束,触发强制移除");
|
||||
self.userInteractionEnabled = NO;
|
||||
[[GiftComboManager sharedManager] forceRemove];
|
||||
[[GiftComboManager sharedManager] clear];
|
||||
}];
|
||||
[self.countdownRingView startCountdown];
|
||||
NSLog(@"[Combo effect] ⏰ 连击倒计时已启动");
|
||||
@@ -272,10 +272,11 @@
|
||||
|
||||
NSLog(@"[Combo effect] 👆 连击面板被点击,发送礼物");
|
||||
|
||||
// 在发送礼物前,先递增 combo 计数并更新显示
|
||||
NSInteger comboCount = [[GiftComboManager sharedManager] loadComboCountFromSendGiftView];
|
||||
[self updateCountWithCombo:comboCount];
|
||||
// 移除用户点击时的combo递增逻辑,改为在API成功时递增
|
||||
// NSInteger comboCount = [[GiftComboManager sharedManager] loadComboCountFromSendGiftView];
|
||||
// [self updateCountWithCombo:comboCount];
|
||||
|
||||
// 直接发送礼物,combo计数在API成功回调时递增
|
||||
[[GiftComboManager sharedManager] sendGift];
|
||||
[self.playImageView startAnimation];
|
||||
[self.countdownRingView resetCountdown];
|
||||
@@ -292,7 +293,7 @@
|
||||
}
|
||||
|
||||
- (void)handleTapSpace {
|
||||
[[GiftComboManager sharedManager] forceRemove];
|
||||
[[GiftComboManager sharedManager] clear];
|
||||
}
|
||||
|
||||
// SVGAPlayerDelegate: 当动画播放完毕时调用
|
||||
|
@@ -180,7 +180,7 @@ UIKIT_EXTERN NSString * const kFreeGiftCountdownNotification;
|
||||
[super viewWillDisappear:animated];
|
||||
|
||||
// 如果连击正在进行,强制重置
|
||||
if ([[GiftComboManager sharedManager] isGiftCombing]) {
|
||||
if ([[GiftComboManager sharedManager] isActive]) {
|
||||
NSLog(@"📱 礼物面板即将消失,检查连击状态");
|
||||
[self forceBoomStateReset];
|
||||
}
|
||||
@@ -444,7 +444,7 @@ UIKIT_EXTERN NSString * const kFreeGiftCountdownNotification;
|
||||
// 如果连击计数为 0 或 nil,尝试修复
|
||||
if (!comboCount || [comboCount integerValue] < 1) {
|
||||
NSLog(@"[Combo effect] 🚨 检测到云信消息中连击计数异常 - comboCount: %@", comboCount);
|
||||
NSInteger currentCombo = [[GiftComboManager sharedManager] loadComboCount];
|
||||
NSInteger currentCombo = [[GiftComboManager sharedManager] currentCount];
|
||||
NSLog(@"[Combo effect] 🔧 使用当前连击计数修复 - 当前: %ld", (long)currentCombo);
|
||||
[data setObject:@(currentCombo) forKey:@"comboCount"];
|
||||
}
|
||||
@@ -1214,6 +1214,11 @@ UIKIT_EXTERN NSString * const kFreeGiftCountdownNotification;
|
||||
|
||||
// 检查 originDic 中的连击计数
|
||||
NSNumber *originComboCount = originDic[@"comboCount"];
|
||||
if (!originComboCount) {
|
||||
NSMutableDictionary *editDic = originDic.mutableCopy;
|
||||
editDic[@"comboCount"] = @(1);
|
||||
originDic = editDic.copy;
|
||||
}
|
||||
NSLog(@"[Combo effect] 📱 originDic 连击计数检查 - comboCount: %@", originComboCount);
|
||||
|
||||
if ([GiftComboManager sharedManager].enableCombo) {
|
||||
|
Reference in New Issue
Block a user