feat: 基本完成 boom 需求

This commit is contained in:
eggmanQQQ
2024-10-11 12:31:37 +08:00
parent 5c87f850e7
commit b79adfa576
9 changed files with 137 additions and 93 deletions

View File

@@ -729,10 +729,12 @@ typedef NS_ENUM(NSUInteger, CustomMessageTypeCPGift) {
};
@interface AttachmentModel : PIBaseModel<NIMCustomAttachment>
@property (nonatomic, strong) id data;
@property (nonatomic,assign) int first;
@property (nonatomic,assign) int second;
@property (nonatomic, strong) id data;
@property(nonatomic,assign) BOOL isBroadcast;
@end
NS_ASSUME_NONNULL_END

View File

@@ -15,55 +15,48 @@
id<NIMCustomAttachment> attachment;
NSData *data = [content dataUsingEncoding:NSUTF8StringEncoding];
if (data) {
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data
options:0
error:nil];
if ([dict isKindOfClass:[NSDictionary class]]) {
int first = [dict[@"first"] intValue];
int second = [dict[@"second"] intValue];
NSDictionary *data = dict[@"data"];
if ([data isKindOfClass:[NSString class]]) {
data = [self dictionaryWithJsonString:(NSString *)data];
}
if ([data isKindOfClass:[NSDictionary class]]) {
AttachmentModel *attachment = [[AttachmentModel alloc]init];
attachment.first = (short)first;
attachment.second = (short)second;
attachment.data = data;
return attachment;
}
id originalData = dict[@"data"];
AttachmentModel *model = [[AttachmentModel alloc]init];
model.first = (short)first;
model.second = (short)second;
if ([originalData isKindOfClass:[NSArray class]]) {
model.data = originalData;
} else if ([originalData isKindOfClass:[NSDictionary class]]) {
model.data = originalData;
} else if ([originalData isKindOfClass:[NSString class]]) {
NSDictionary *jsonDict = [self dictionaryWithJsonString:(NSString *)originalData];
if ([jsonDict isKindOfClass:[NSDictionary class]]) {
model.data = jsonDict;
}
}
attachment = model;
}
}
return attachment;
}
//json
- (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
if (jsonString == nil) {
if (jsonString == nil || jsonString.length == 0) {
return nil;
}
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSError *err;
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
options:NSJSONReadingMutableContainers
error:&err];
if(err) {
NSLog(@"json解析失败%@",err);
return nil;
}
return dic;
}
@end

View File

@@ -25,19 +25,18 @@
dispatch_async(dispatch_get_main_queue(), ^{
@kStrongify(self);
self.icon.imageUrl = boomModel.pic;
CGFloat progress = boomModel.speed * 1.0 / 100.0;
if (progress == 0) {
self.progress.hidden = YES;
} else {
self.progress.hidden = NO;
[UIView animateWithDuration:0.3 animations:^{
[self.progress mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(32) * progress);
}];
//
[self layoutIfNeeded];
}];
}
// CGFloat progress = boomModel.speed * 1.0 / 100.0;
// if (progress == 0) {
// self.progress.hidden = YES;
// } else {
// self.progress.hidden = NO;
// [UIView animateWithDuration:0.3 animations:^{
// [self.progress mas_updateConstraints:^(MASConstraintMaker *make) {
// make.width.mas_equalTo(kGetScaleWidth(32) * progress);
// }];
// [self layoutIfNeeded];
// }];
// }
});
}
@@ -60,8 +59,8 @@
[self addSubview:self.progress];
[self.progress mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.progressBG);
make.leading.mas_equalTo(self.icon).offset(4);
make.width.mas_equalTo(0);
make.leading.mas_equalTo(self.icon).offset(4.5);
make.width.mas_equalTo(kGetScaleWidth(32));
make.height.mas_equalTo(5);
}];
}

View File

@@ -49,7 +49,7 @@
instance.giftEventsQueue = @[].mutableCopy;
instance.bannerEventsQueue = @[].mutableCopy;
// [[NIMSDK sharedSDK].chatManager addDelegate:instance];
[[NIMSDK sharedSDK].chatManager addDelegate:instance];
[[NIMSDK sharedSDK].broadcastManager addDelegate:instance];
});
return instance;
@@ -141,6 +141,17 @@
}
}
- (void)explosionEnd {
self.isBooming = NO;
if (self.giftEventsQueue.count > 0) {
id obj = self.giftEventsQueue.firstObject;
[self handleBoomGiftUpdate:obj];
[self.giftEventsQueue removeObjectAtIndex:0];
} else {
[self checkAndStartBoomEvent];
}
}
- (void)checkAndStartBannerEvent {
if (self.isBannering) {
return;
@@ -153,17 +164,6 @@
}
}
- (void)explosionEnd {
self.isBooming = NO;
if (self.giftEventsQueue.count > 0) {
id obj = self.giftEventsQueue.firstObject;
[self handleBoomGiftUpdate:obj];
[self.giftEventsQueue removeObjectAtIndex:0];
} else {
[self checkAndStartBoomEvent];
}
}
- (void)giftDisplayEnd {
[self checkAndStartBoomEvent];
}
@@ -239,7 +239,7 @@
// TODO:
switch (attachment.second) {
case Custom_Message_Room_Boom_EXP: {
NSLog(@" -------- 631 : %@", attachment.data);
NSLog(@" 火箭 -------- 631 : %@", attachment.data);
BoomDetailModel *boomDetail = [BoomDetailModel modelWithJSON:attachment.data];
[self handleProgressUpdate:boomDetail];
}
@@ -314,17 +314,17 @@
#pragma mark -
- (void)onRecvMessages:(NSArray *)messages
{
// for (NIMMessage * message in messages) {
// if (message.messageType == NIMMessageTypeCustom) {
// NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
// if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) {
// AttachmentModel * attachment = (AttachmentModel *)obj.attachment;
// if (attachment.first == CustomMessageType_RoomBoom) {
// [self receiveNIMResponse:attachment];
// }
// }
// }
// }
for (NIMMessage * message in messages) {
if (message.messageType == NIMMessageTypeCustom) {
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) {
AttachmentModel * attachment = (AttachmentModel *)obj.attachment;
if (attachment.first == CustomMessageType_RoomBoom) {
[self receiveNIMResponse:attachment];
}
}
}
}
}
- (void)onReceiveBroadcastMessage:(NIMBroadcastMessage *)broadcastMessage {

View File

@@ -7,13 +7,13 @@
#import <UIKit/UIKit.h>
@class AttachmentModel;
NS_ASSUME_NONNULL_BEGIN
@interface RoomBoomResultView : UIView
+ (void)displayEmptyView:(UIView *)superView;
+ (void)display:(UIView *)superView gifts:(NSArray *)giftsArray;
+ (void)display:(UIView *)superView attachment:(AttachmentModel *)attachment;
@end

View File

@@ -7,9 +7,14 @@
#import "RoomBoomResultView.h"
#import "BoomInfoModel.h"
#import "RoomBoomManager.h"
#import "AttachmentModel.h"
@interface RoomBoomResultCollectionViewCell : UICollectionViewCell
@property (nonatomic, strong) NetImageView *giftPic;
@property (nonatomic, strong) BoomGiftModel *model;
@end
@@ -34,6 +39,11 @@
return self;
}
- (void)setModel:(BoomGiftModel *)model {
_model = model;
self.giftPic.imageUrl = model.awardPic;
}
- (UIImageView *)bgView {
UIImageView *bg = [[UIImageView alloc] initWithImage:kImage(@"room_boom_result_gift_cell_bg")];
return bg;
@@ -54,6 +64,7 @@
@property (nonatomic, strong) UILabel *contentLabel;
@property (nonatomic, strong) UIButton *bottomButton;
@property (nonatomic, strong) UICollectionView *giftsCollectionView;
@property (nonatomic, copy) NSArray <BoomGiftModel *> * dataSource;
@end
@@ -77,7 +88,7 @@
}];
}
+ (void)display:(UIView *)superView gifts:(NSArray *)giftsArray {
+ (void)display:(UIView *)superView gifts:(NSArray <BoomGiftModel *> *)giftsArray {
RoomBoomResultView *resultView = [[RoomBoomResultView alloc] init];
resultView.alpha = 0;
[superView addSubview:resultView];
@@ -88,18 +99,46 @@
make.height.mas_equalTo(kGetScaleWidth(394));
}];
[resultView setupFroGifts:giftsArray.count];
[resultView setupFroGifts];
resultView.dataSource = giftsArray;
[UIView animateWithDuration:0.2 animations:^{
resultView.alpha = 1;
}];
}
+ (void)display:(UIView *)superView attachment:(AttachmentModel *)attachment {
if (!attachment ||
![attachment.data isKindOfClass:[NSArray class]] ||
[attachment.data count] == 0) {
return;
}
NSMutableArray *myGifts = @[].mutableCopy;
NSArray *gifts = [BoomGiftModel modelsWithArray:attachment.data];
for (BoomGiftModel *model in gifts) {
if (model.uid == [[AccountInfoStorage instance].getUid integerValue]) {
[myGifts addObject:model];
}
}
if (myGifts.count == 0) {
[RoomBoomResultView displayEmptyView:superView];
} else {
[RoomBoomResultView display:superView gifts:myGifts];
}
}
- (instancetype)init {
if (self = [super init]) {}
return self;
}
- (void)setDataSource:(NSArray<BoomGiftModel *> *)dataSource {
_dataSource = dataSource;
[self.giftsCollectionView reloadData];
}
- (void)setupForEmpty {
self.backgroundImageView.image = kImage(@"room_boom_empty_result_bg");
[self addSubview:self.backgroundImageView];
@@ -125,7 +164,7 @@
}];
}
- (void)setupFroGifts:(NSInteger)giftsCount {
- (void)setupFroGifts {
self.backgroundImageView.image = kImage(@"room_boom_gifts_result_bg");
[self addSubview:self.backgroundImageView];
[self.backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
@@ -174,12 +213,13 @@
}
- (void)didTapBottomButton {
[[RoomBoomManager sharedManager] giftDisplayEnd];
[self removeFromSuperview];
}
#pragma mark - UICollectionView delegate & datasource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return arc4random()%30;
return self.dataSource.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

View File

@@ -93,4 +93,17 @@ NS_ASSUME_NONNULL_BEGIN
@end
@interface BoomGiftModel : PIBaseModel
@property (nonatomic, copy) NSString *nick;
@property (nonatomic, copy) NSString *awardName;
@property (nonatomic, copy) NSString *awardPic;
@property (nonatomic, assign) NSInteger uid;
@property (nonatomic, assign) NSInteger roomUid;
@property (nonatomic, assign) NSInteger level;
@property (nonatomic, assign) NSInteger roleType;
@end
NS_ASSUME_NONNULL_END

View File

@@ -45,5 +45,9 @@
@implementation Boom632Model
@end
@implementation BoomGiftModel
@end

View File

@@ -342,6 +342,9 @@ XPCandyTreeInsufficientBalanceViewDelegate>
// [b addTarget:self action:@selector(test) forControlEvents:UIControlEventTouchUpInside];
//#endif
}
//- (void)test {
//
//}
- (void)setupFroBoom {
@kWeakify(self);
@@ -357,7 +360,7 @@ XPCandyTreeInsufficientBalanceViewDelegate>
[[RoomBoomManager sharedManager] registerBoomGiftDisplay:^(id _Nonnull sth) {
@kStrongify(self);
dispatch_async(dispatch_get_main_queue(), ^{
[RoomBoomResultView displayEmptyView:self.view];
[RoomBoomResultView display:self.view attachment:sth];
});
} target:self];
@@ -371,19 +374,11 @@ XPCandyTreeInsufficientBalanceViewDelegate>
} target:self];
}
//- (void)test {
//
//}
- (void)loadRoomDataAndUsers {
[XNDJTDDLoadingTool showAnchorLoading:self.navigationController.view];
[self.presenter initEnterRoom:self.roomUid user:[AccountInfoStorage instance].getUid];
}
- (void)loadRoomBoom {
// [self.presenter getBoomInfo:s];
}
- (void)setupNotifications {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myGiftEffectUpdate:) name:kRoomGiftEffectUpdateNotificationKey object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showRoomFirstChargeWindowFormNot:) name:kShowFirstRechargeView object:nil];
@@ -1820,9 +1815,6 @@ XPCandyTreeInsufficientBalanceViewDelegate>
[self.littleGameView handleNIMNotificationMessage:message];
} else if (message.messageType == NIMMessageTypeCustom) {
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
633 attachment nil data
if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) {
AttachmentModel * attachment = (AttachmentModel *)obj.attachment;
[self.stageView handleNIMCustomMessage:message];
@@ -1935,13 +1927,14 @@ XPCandyTreeInsufficientBalanceViewDelegate>
[self.presenter getFreeGiftData];
[[NSNotificationCenter defaultCenter]postNotificationName:kFreeGiftCountdownNotification object:nil userInfo:@{@"updateGiftInfo":attachment.data ?: @""}];
}
} else if (attachment.first == CustomMessageType_RoomBoom) {
if (attachment.second == 631) {
[[RoomBoomManager sharedManager] receiveNIMResponse:attachment];
} else if (attachment.second == 633) {
[[RoomBoomManager sharedManager] receiveNIMResponse:attachment];
}
}
// else if (attachment.first == CustomMessageType_RoomBoom) {
// if (attachment.second == 631) {
// [[RoomBoomManager sharedManager] receiveNIMResponse:attachment];
// } else if (attachment.second == 633) {
// [[RoomBoomManager sharedManager] receiveNIMResponse:attachment];
// }
// }
[self.messageContainerView handleNIMCustomMessage:message];
}