驾驶座驾进房

This commit is contained in:
fengshuo
2021-12-16 20:22:01 +08:00
parent 286d617fba
commit 5c1e4ed381
11 changed files with 216 additions and 46 deletions

View File

@@ -33,7 +33,7 @@
#import "XPRoomCandyGiftView.h"
@interface XPRoomAnimationView ()<SVGAPlayerDelegate, NIMChatManagerDelegate,NIMBroadcastManagerDelegate, XPRoomGiftBroadcastViewDelegate>
@interface XPRoomAnimationView ()<SVGAPlayerDelegate,NIMBroadcastManagerDelegate, XPRoomGiftBroadcastViewDelegate>
///
///
@property (nonatomic,strong) XPRoomAnimationHitView * lowLevelView;
@@ -74,18 +74,21 @@
@property (nonatomic,strong) NSMutableSet<NetImageView *> * giftVisibleArray;
///
@property (nonatomic,strong) NSMutableArray *candyTreegiftQueue;
#pragma mark -
@property (nonatomic, strong) NSMutableArray<NSString *> *carEffectQueue;
@property (nonatomic,strong) SVGAImageView *carEffectView;
@end
@implementation XPRoomAnimationView
- (void)dealloc {
[NSObject cancelPreviousPerformRequestsWithTarget:self];
[[NIMSDK sharedSDK].broadcastManager removeDelegate:self];
}
- (instancetype)initWithdelegate:(id<RoomHostDelegate>)delegate {
self = [super init];
if (self) {
[[NIMSDK sharedSDK].chatManager addDelegate:self];
[[NIMSDK sharedSDK].broadcastManager addDelegate:self];
self.delegate = delegate;
[self initSubViews];
@@ -114,13 +117,6 @@
make.edges.mas_equalTo(self);
}];
}
#pragma mark - NIMChatManagerDelegate
- (void)onRecvMessages:(NSArray<NIMMessage *> *)messages {
for (NIMMessage * message in messages) {
[self handleMessage:message];
}
}
#pragma mark - NIMBroadcastDelegate
// 广
- (void)onReceiveBroadcastMessage:(NIMBroadcastMessage *)broadcastMessage{
@@ -132,36 +128,71 @@
}
}
}
//
- (void)sendMessage:(NIMMessage *)message didCompleteWithError:(NSError *)error {
[self handleMessage:message];
#pragma mark - RoomGuestDelegate
- (void)handleNIMCustomMessage:(AttachmentModel *)attachment {
if (attachment.first == CustomMessageType_Gift) {
GiftReceiveInfoModel * receiveInfo = [GiftReceiveInfoModel modelWithJSON:attachment.data];
receiveInfo.isLuckyBagGift = attachment.second == Custom_Message_Sub_Gift_LuckySend;
receiveInfo.isBatch = YES;
[self receiveGiftHandleSendGiftAnimation:attachment];
[self receiveGift:receiveInfo];
} else if (attachment.first == CustomMessageType_AllMicroSend) { //
GiftReceiveInfoModel * receiveInfo = [GiftReceiveInfoModel modelWithJSON:attachment.data];
receiveInfo.isLuckyBagGift = (attachment.second == Custom_Message_Sub_AllMicroLuckySend || attachment.second == Custom_Message_Sub_AllBatchMicroLuckySend);
receiveInfo.isBatch = (attachment.second == Custom_Message_Sub_AllBatchSend || attachment.second == Custom_Message_Sub_AllBatchMicroLuckySend);
[self receiveGiftHandleSendGiftAnimation:attachment];
[self receiveGift:receiveInfo];
} else if (attachment.first == CustomMessageType_LuckyBag) {//
[self receiveLuckyGiftBigPrize:attachment];
} else if (attachment.first == CustomMessageType_Candy_Tree && (attachment.second == Custom_Message_Sub_Candy_Tree_InRoom_NeedAllMicSend || attachment.second == Custom_Message_Sub_Candy_Tree_AllRoom_Notify) ) {//
[self receiveCandyTreeGiftHighLevle:attachment];
} else if (attachment.first == CustomMessageType_Car_Notify && attachment.second == Custom_Message_Sub_Car_EnterRoom ) {//
[self receiveDriveCarEnterRoom:attachment];
}
}
#pragma mark -
- (void)receiveDriveCarEnterRoom:(AttachmentModel *)attatchment {
NSString * effect = attatchment.data[@"effect"];
if (effect.length <= 0) return;
if (self.carEffectQueue.count == 0) {
[self playCarEffect:effect];
return;
}
[self.carEffectQueue addObject:effect];
}
- (void)handleMessage:(NIMMessage *)message {
if (message.session.sessionType == NIMSessionTypeChatroom && 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_Gift) {
GiftReceiveInfoModel * receiveInfo = [GiftReceiveInfoModel modelWithJSON:attachment.data];
receiveInfo.isLuckyBagGift = attachment.second == Custom_Message_Sub_Gift_LuckySend;
receiveInfo.isBatch = YES;
[self receiveGiftHandleSendGiftAnimation:attachment];
[self receiveGift:receiveInfo];
} else if (attachment.first == CustomMessageType_AllMicroSend) { //
GiftReceiveInfoModel * receiveInfo = [GiftReceiveInfoModel modelWithJSON:attachment.data];
receiveInfo.isLuckyBagGift = (attachment.second == Custom_Message_Sub_AllMicroLuckySend || attachment.second == Custom_Message_Sub_AllBatchMicroLuckySend);
receiveInfo.isBatch = (attachment.second == Custom_Message_Sub_AllBatchSend || attachment.second == Custom_Message_Sub_AllBatchMicroLuckySend);
[self receiveGiftHandleSendGiftAnimation:attachment];
[self receiveGift:receiveInfo];
} else if (attachment.first == CustomMessageType_LuckyBag) {//
[self receiveLuckyGiftBigPrize:attachment];
} else if (attachment.first == CustomMessageType_Candy_Tree && (attachment.second == Custom_Message_Sub_Candy_Tree_InRoom_NeedAllMicSend || attachment.second == Custom_Message_Sub_Candy_Tree_AllRoom_Notify)) {//
[self receiveCandyTreeGiftHighLevle:attachment];
}
}
- (void)playCarEffect:(NSString *)carEffect {
if (self.carEffectView.superview == nil) {
[self.middleLevelView addSubview:self.carEffectView];
[self.carEffectView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self.middleLevelView);
make.width.mas_equalTo(KScreenWidth);
make.height.mas_equalTo(KScreenHeight);
}];
}
[self.parser parseWithURL:[NSURL URLWithString:carEffect] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
if (videoItem != nil) {
CGFloat width = videoItem.videoSize.width;
CGFloat height = videoItem.videoSize.height;
if (width > height) {
self.giftEffectView.contentMode = UIViewContentModeScaleAspectFit;
} else {//
CGFloat resizeH = KScreenWidth * height / width;//
if (resizeH > KScreenHeight) {//
self.giftEffectView.contentMode = UIViewContentModeScaleAspectFill;
} else {//
self.giftEffectView.contentMode = UIViewContentModeScaleAspectFit;
}
}
self.carEffectView.alpha = 1;
self.carEffectView.loops = 1;
self.carEffectView.clearsAfterStop = YES;
self.carEffectView.videoItem = videoItem;
[self.carEffectView startAnimation];
}
} failureBlock:^(NSError * _Nullable error) {
}];
}
#pragma mark -
@@ -714,7 +745,7 @@
if (self.giftEffectView.superview == nil) {
[self.middleLevelView addSubview:self.giftEffectView];
[self.giftEffectView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self.lowLevelView);
make.center.mas_equalTo(self.middleLevelView);
make.width.mas_equalTo(KScreenWidth);
make.height.mas_equalTo(KScreenHeight);
}];
@@ -758,6 +789,11 @@
- (void)svgaPlayerDidFinishedAnimation:(SVGAPlayer *)player {
if (player == self.giftEffectView) {
self.giftEffectView.hidden = YES;
} else if(self.carEffectView) {
if (self.carEffectQueue.count > 0) {
[self playCarEffect:self.carEffectQueue.firstObject];
[self.carEffectQueue removeObjectAtIndex:0];
}
}
}
@@ -869,4 +905,24 @@
return _candyTreegiftQueue;
}
- (NSMutableArray<NSString *> *)carEffectQueue {
if (_carEffectQueue == nil) {
_carEffectQueue = [NSMutableArray array];
}
return _carEffectQueue;
}
- (SVGAImageView *)carEffectView {
if (_carEffectView == nil) {
_carEffectView = [[SVGAImageView alloc]init];
_carEffectView.delegate = self;
_carEffectView.contentMode = UIViewContentModeScaleAspectFit;
_carEffectView.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
_carEffectView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
_carEffectView.alpha = 0;
_carEffectView.userInteractionEnabled = NO;
}
return _carEffectView;
}
@end