Files
peko-ios/YuMi/Modules/YMRoom/View/AnimationView/RoomAnimationView.m
2025-01-15 19:02:58 +08:00

1647 lines
59 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// RoomAnimationView.m
// YuMi
//
// Created by P on 2025/1/13.
//
#import "RoomAnimationView.h"
#import <POP.h>
#import <SVGA.h>
#import <libpag/libpag.h>
#import <NIMSDK/NIMSDK.h>
#import "UIView+VAP.h"
#import "ClientConfig.h"
#import "XPGiftStorage.h"
#import "UserInfoModel.h"
#import "RoomInfoModel.h"
#import "MicroQueueModel.h"
#import "AttachmentModel.h"
#import "QGVAPConfigModel.h"
#import "ActivityInfoModel.h"
#import "GiftReceiveInfoModel.h"
#import "XPRoomEnterHideTipView.h"
#import "XPMessageRemoteExtModel.h"
#import "PIBaseAnimationViewModel.h"
#import "XPRoomGiftAnimationParser.h"
#import "GiftComboManager.h"
#import "GiftAnimationManager.h"
#import "MSRoomGameWebVC.h"
#import "XPRoomAnimationView.h"
#import "XPRoomViewController.h"
#import "PIUniversalBannerView.h"
#import "PIUniversalBannerModel.h"
#import "CPGiftBanner.h"
#import "CPLevelUpAnimation.h"
#import "CPBindingAnimation.h"
#import "GameUniversalBannerView.h"
#import "LuckyGiftWinningFlagView.h"
#import "LuckyGiftWinningBannerView.h"
#import "RoomHighValueGiftBannerAnimation.h"
static const CGFloat kTipViewStayDuration = 3.0;
static const CGFloat kTipViewMoveDuration = 0.5;
@interface RoomAnimationView () <
PAGViewListener,
SVGAPlayerDelegate,
HWDMP4PlayDelegate,
GiftAnimationDelegate,
NIMBroadcastManagerDelegate
>
@property (nonatomic, weak) id<RoomHostDelegate>hostDelegate;
///最底层
@property (nonatomic, strong) XPRoomAnimationHitView *bottomContainer;
///中层
@property (nonatomic, strong) XPRoomAnimationHitView *middleContainer;
///顶层
@property (nonatomic, strong) XPRoomAnimationHitView *topContainer;
@property (nonatomic, strong) XPRoomAnimationHitView *bannerContainer;
/// --- 进场
/// 存放进房待播放动画的“队列”(这里用数组模拟队列 FIFO
@property (nonatomic, strong) NSMutableArray<NSDictionary *> *enterRoomAnimationQueue;
/// 标记当前是否有进房动画在执行
@property (nonatomic, assign) BOOL isEnterRoomAnimating;
@property (nonatomic, strong) SVGAImageView *enterEffectView;
/// --- 礼物
@property(nonatomic, strong) PAGView *pagGiftEffectView;
@property(nonatomic, strong) SVGAParser *vggParser;
@property(nonatomic, assign) BOOL isPlayingGiftEffect;
@property(nonatomic, strong) NSMutableArray *svgaQueue;
@property(nonatomic, strong) VAPView *vapGiftEffectView;
@property(nonatomic,strong) SVGAImageView *vggGiftEffectView;
@property(nonatomic, strong) NSMutableArray *mp4AvatarLoaders;
@property(nonatomic, copy) NSString *GiftDynamicEffectListPath;
@property(nonatomic, strong) dispatch_source_t giftEffectTimer;
@property(nonatomic, strong) dispatch_queue_t giftEffectsQueue;
@property(nonatomic, strong) XPRoomGiftAnimationParser *vapParser;
@property(nonatomic, strong) GiftAnimationManager *giftAnimationManager;
@property(nonatomic, strong) GiftReceiveInfoModel *mp4TempReceiveInfoModel;
/// --- 飘屏
@property (nonatomic, strong) NSMutableArray *roomBannertModelsQueueV2; // 特效播放队列,包括幸运礼物 banner CP banner 和 CP 特效
@property (nonatomic, assign) BOOL isRoomBannerV2Displaying;
/// --- 座驾
///座驾pag动效
@property(nonatomic, strong) PAGView *carPagEffectView;
///座驾VAP特效
@property(nonatomic, strong) VAPView *carVapEffectView;
@property(nonatomic, strong) SVGAImageView *carSVGAEffectView;
@property(nonatomic, strong) NSMutableArray<NSDictionary *> *carEffectQueue;
@end
@implementation RoomAnimationView
- (void)dealloc
{
if (self.giftEffectTimer) {
dispatch_source_cancel(self.giftEffectTimer);
self.giftEffectTimer = nil;
}
if (self.giftEffectsQueue) {
self.giftEffectsQueue = NULL;
}
[self.enterRoomAnimationQueue removeAllObjects];
[self.enterEffectView stopAnimation];
[[NIMSDK sharedSDK].broadcastManager removeDelegate:self];
}
-(void)resumeTimer{
if(self.giftEffectTimer != nil){
dispatch_source_cancel(self.giftEffectTimer);
self.giftEffectTimer = nil;
}
[self.pagGiftEffectView removeListener:self];
self.hostDelegate = nil;
[[GiftComboManager sharedManager] removeComboFlag];
}
- (instancetype)initWithHostDelegate:(id<RoomHostDelegate>)hDelegate {
if (self = [super init]) {
self.hostDelegate = hDelegate;
[[NIMSDK sharedSDK].broadcastManager addDelegate:self];
[self setup];
}
return self;
}
#pragma mark - SETUP
- (void)setup {
[self setupUI];
[self setupEnterRoom];
[self setupGiftEffects];
[self setupBanner];
[self setupCar];
}
- (void)setupUI {
[self addSubview:self.bottomContainer];
[self insertSubview:self.middleContainer aboveSubview:self.bottomContainer];
[self insertSubview:self.topContainer aboveSubview:self.middleContainer];
[self insertSubview:self.bannerContainer aboveSubview:self.topContainer];
[self.bottomContainer mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self);
}];
[self.middleContainer mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self);
}];
[self.topContainer mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self);
}];
[self.bannerContainer mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self).offset(kNavigationHeight);
make.leading.trailing.mas_equalTo(self);
make.bottom.mas_equalTo(self.mas_centerY);
}];
}
- (void)setupEnterRoom {
self.enterRoomAnimationQueue = [NSMutableArray array];
}
- (void)setupGiftEffects {
self.GiftDynamicEffectListPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) xpSafeObjectAtIndex:0] stringByAppendingPathComponent:@"GiftDynamicEffectList"];
self.giftAnimationManager = [[GiftAnimationManager alloc] initWithContainerView:self.bottomContainer];
self.giftAnimationManager.delegate = self;
_giftEffectsQueue = dispatch_queue_create("com.RoomGiftEffects.queue", DISPATCH_QUEUE_SERIAL);
}
- (void)setupBanner {
_roomBannertModelsQueueV2 = [NSMutableArray array];
[self addBnnerContainGesture];
}
- (void)setupCar {
_carEffectQueue = [NSMutableArray array];
}
#pragma mark - Method: Enter Roooooom
- (void)enterRoom:(NIMMessage *)message content:(NIMChatroomNotificationContent *)content {
NIMMessageChatroomExtension *messageExt = (NIMMessageChatroomExtension *)message.messageExt;
NSDictionary * dic = [(NSDictionary *)messageExt.roomExt.toJSONObject objectForKey:message.from];
XPMessageRemoteExtModel *extModel = [XPMessageRemoteExtModel modelWithJSON:dic];
if (extModel.enterHide) {
//隐身进房
if ([message.from isEqualToString:[AccountInfoStorage instance].getUid]) {
[self createEnterHideAnimation];
}
} else {
[self userEnterRoom:content ext:extModel];
}
}
///自己的隐身进房提示
- (void)createEnterHideAnimation {
NSDictionary * dic= @{@"title":@"隐身进房",
@"experLevelSeq":@"",
@"effectPath" : @""};
[self.enterRoomAnimationQueue addObject:dic];
[self tryDequeueAnimation];
}
- (void)userEnterRoom:(NIMChatroomNotificationContent *)content ext:(XPMessageRemoteExtModel *)extModel {
NSString *userName = [self _resolveUserNameFromContent:content extModel:extModel];
NSString *title = [NSString stringWithFormat:YMLocalizedString(@"XPRoomAnimationView0"), userName];
NSDictionary * dic= @{@"title":title,
@"experLevelSeq":[NSString stringWithFormat:@"%ld", extModel.experLevelSeq],
@"effectPath" : extModel.enterRoomEffects.length ? extModel.enterRoomEffects : @""};
[self.enterRoomAnimationQueue addObject:dic];
[self tryDequeueAnimation];
}
- (void)tryDequeueAnimation {
// 如果当前正有动画在播放或者队列里啥都没有直接return
if (self.isEnterRoomAnimating || self.enterRoomAnimationQueue.count == 0) {
return;
}
self.isEnterRoomAnimating = YES;
// 取出队列头部的动画信息并移除
NSDictionary *dic = [self.enterRoomAnimationQueue firstObject];
[self.enterRoomAnimationQueue removeObjectAtIndex:0];
NSString *title = [dic objectForKey:@"title"];
if ([title isEqualToString:@"隐身进房"]) {
[self playHideEnterRoomAnimation];
} else {
// 开始执行动画
[self playUserEnterRoomAnimation:[dic objectForKey:@"title"]
experLevelSeq:[dic objectForKey:@"experLevelSeq"]
effectPath:[dic objectForKey:@"effectPath"]];
}
}
- (void)playHideEnterRoomAnimation {
XPRoomEnterHideTipView *enterHideTipView = [[XPRoomEnterHideTipView alloc] initWithFrame:CGRectMake(KScreenWidth,
(KScreenHeight - 48) * 0.5,
KScreenWidth,
48)];
[self.bottomContainer addSubview:enterHideTipView];
@kWeakify(self);
[self enterRoomAnimationFor:enterHideTipView
startFrom:enterHideTipView.center
startTo:CGPointMake(enterHideTipView.frame.size.width / 2, enterHideTipView.center.y)
endFrom:CGPointMake(0, enterHideTipView.center.y)
endTo:CGPointMake(-KScreenWidth / 2, enterHideTipView.center.y)
duration:CACurrentMediaTime() + kTipViewStayDuration
completion:^(BOOL finished) {
@kStrongify(self);
[self endAnimationEnterEffect];
}];
}
- (void)playUserEnterRoomAnimation:(NSString *)title
experLevelSeq:(NSString *)experLevelSeq
effectPath:(NSString *)effectPath {
NSDictionary *attributes = @{
NSFontAttributeName:kFontRegular(26),
NSForegroundColorAttributeName:[UIColor whiteColor]
};
NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:title
attributes:attributes];
[attributeString setYy_alignment:NSTextAlignmentLeft];
BOOL hasEffectPath = ![NSString isEmpty:effectPath];
[self addEnterEffectView: hasEffectPath];
if (hasEffectPath) {
[self playEnterRoomSvga:effectPath
content:attributeString
needMoveAnimation:YES];
} else {
[self playEnterRoomSvgaWith:experLevelSeq
content:attributeString];
}
}
- (void)addEnterEffectView:(BOOL)hasEffectPath {
if (self.enterEffectView.superview == nil) {
[self.bottomContainer addSubview:self.enterEffectView];
}
self.enterEffectView.loops = hasEffectPath ? 0 : 1;
self.enterEffectView.frame = CGRectMake(hasEffectPath ? KScreenWidth : 0,
340 + kSafeAreaTopHeight,
KScreenWidth,
hasEffectPath ? 75 : 50);
}
- (void)playEnterRoomSvga:(NSString *)path
content:(NSAttributedString *)content
needMoveAnimation:(BOOL)isNeed {
@kWeakify(self);
SVGAParser *parser = [[SVGAParser alloc] init];
[parser parseWithURL:[NSURL URLWithString:path]
completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
@kStrongify(self);
self.enterEffectView.alpha = 1;
self.enterEffectView.videoItem = videoItem;
[self.enterEffectView setAttributedText:content forKey:@"room_text"];
[self.enterEffectView startAnimation];
if (isNeed) {
[self popAnimationEnterEffect];
}
} failureBlock:^(NSError * _Nullable error) {
@kStrongify(self);
[self endAnimationEnterEffect];
}];
}
- (void)playEnterRoomSvgaWith:(NSString *)seq
content:(NSAttributedString *)content {
NSInteger seqNum = [NSString isEmpty:seq] ? 0 : [seq integerValue];
NSString *path = [self _mapExperLevelSeqToLocalKey:seqNum];
if ([NSString isEmpty:path]) {
[self endAnimationEnterEffect];
return;
}
NSString *targetPath = [NSString stringWithFormat:@"%@/%@.svga", @"https://image.molistar.xyz", path];
[self playEnterRoomSvga:targetPath content:content needMoveAnimation:NO];
}
- (void)popAnimationEnterEffect {
@kWeakify(self);
[self enterRoomAnimationFor:self.enterEffectView
startFrom:self.enterEffectView.center
startTo:CGPointMake(self.enterEffectView.frame.size.width / 2, self.enterEffectView.center.y)
endFrom:CGPointMake(0, self.enterEffectView.center.y)
endTo:CGPointMake(-KScreenWidth / 2, self.enterEffectView.center.y)
duration:CACurrentMediaTime() + kTipViewStayDuration
completion:^(BOOL finished) {
@kStrongify(self);
[self endAnimationEnterEffect];
}];
}
- (void)endAnimationEnterEffect {
self.isEnterRoomAnimating = NO;
[self tryDequeueAnimation];
}
#pragma mark - Method: Banner
- (void)processNextRoomEffectAttachment {
// 检查队列是否有元素
if (self.roomBannertModelsQueueV2.count == 0) {
// 如果队列为空,停止处理
self.isRoomBannerV2Displaying = NO;
return;
}
// 从队列中取出第一个元素并移出队列
AttachmentModel *nextAttachment = [self.roomBannertModelsQueueV2 firstObject];
[self.roomBannertModelsQueueV2 removeObjectAtIndex:0];
// 设置为正在显示的状态
self.isRoomBannerV2Displaying = YES;
switch (nextAttachment.second) {
case Custom_Message_Sub_General_Floating_Screen_One_Room:
case Custom_Message_Sub_General_Floating_Screen_All_Room:
// 通用飘屏
[self playGameBanner:nextAttachment];
break;
case Custom_Message_Sub_Super_Gift_Winning_Coins_ALL_Room:
[self playLuckyWinningBanner:nextAttachment];
break;
case Custom_Message_Sub_CP_Gift:
[self playCPGiftBanner:nextAttachment];
break;
case Custom_Message_Sub_CP_Upgrade:
[self playCPLevelUp:nextAttachment];
break;
case Custom_Message_Sub_CP_Binding:
[self playCPBinding:nextAttachment];
break;
case Custom_Message_Sub_Gift_ChannelNotify:
[self playRoomGiftBanner:nextAttachment];
break;
default:
break;
}
}
- (void)receiveRoomGiftBanner:(AttachmentModel *)obj {
[self.roomBannertModelsQueueV2 addObject:obj];
if (!self.isRoomBannerV2Displaying) {
[self processNextRoomEffectAttachment];
}
}
- (void)playRoomGiftBanner:(AttachmentModel *)obj {
@kWeakify(self);
[RoomHighValueGiftBannerAnimation display:self.bannerContainer
with:obj
complete:^{
@kStrongify(self);
[self processNextRoomEffectAttachment];
}];
}
- (void)receiveCPEvent:(AttachmentModel *)attachment {
[self.roomBannertModelsQueueV2 addObject:attachment];
if (!self.isRoomBannerV2Displaying) {
[self processNextRoomEffectAttachment];
}
}
- (void)playCPBinding:(AttachmentModel *)attachment {
@kWeakify(self);
[CPBindingAnimation display:self.topContainer
with:attachment
complete:^{
@kStrongify(self);
[self processNextRoomEffectAttachment];
}];
}
- (void)playCPGiftBanner:(AttachmentModel *)attachMent {
@kWeakify(self);
[CPGiftBanner display:self.bannerContainer
with:attachMent
complete:^{
@kStrongify(self);
[self processNextRoomEffectAttachment];
}];
}
- (void)playCPLevelUp:(AttachmentModel *)attachMent {
@kWeakify(self);
[CPLevelUpAnimation display:self.topContainer
with:attachMent
complete:^{
@kStrongify(self);
[self processNextRoomEffectAttachment];
}];
}
- (void)receiveLuckGiftWinning:(AttachmentModel *)attachment {
RoomInfoModel *roomInfo = self.hostDelegate.getRoomInfo;
[LuckyGiftWinningFlagView display:self.topContainer
with:attachment
roomID:roomInfo.roomId
uID:[AccountInfoStorage instance].getUid];
}
- (void)receiveLuckGiftBanner:(AttachmentModel *)attachment {
[self.roomBannertModelsQueueV2 addObject:attachment];
if (!self.isRoomBannerV2Displaying) {
[self processNextRoomEffectAttachment];
}
}
- (void)playLuckyWinningBanner:(AttachmentModel *)nextAttachment {
RoomInfoModel *roomInfo = self.hostDelegate.getRoomInfo;
@kWeakify(self);
[LuckyGiftWinningBannerView display:self.bannerContainer
inRoomUid:roomInfo.uid
with:nextAttachment
complete:^{
@kStrongify(self);
[self processNextRoomEffectAttachment];
} exitCurrentRoom:^{
@kStrongify(self);
[self.hostDelegate exitRoom];
}];
}
-(void)receiveRoomGeneralFloatingScreen:(AttachmentModel *)attachment{
PIBaseAnimationViewModel *roomGraffiti = [PIBaseAnimationViewModel new];
roomGraffiti.data = attachment.data;
roomGraffiti.type = GiftBannerType_General_Floating_Screen;
roomGraffiti.first = attachment.first;
roomGraffiti.second = attachment.second;
PIUniversalBannerModel *model = [PIUniversalBannerModel modelWithDictionary:attachment.data];
if (model.skipType == 7 &&
(attachment.second == Custom_Message_Sub_General_Floating_Screen_One_Room ||
attachment.second == Custom_Message_Sub_General_Floating_Screen_All_Room)) {
[self receiveGameBanner:attachment];
} else {
// if(self.animationListB.count == 0 && self.isPlayOfB == NO){
// [self createGeneralFloatingScreenAnimation:roomGraffiti bannerModel:model];
// }
// [self.animationListB addObject:roomGraffiti];
}
}
- (void)receiveGameBanner:(AttachmentModel *)attachment {
[self.roomBannertModelsQueueV2 addObject:attachment];
if (!self.isRoomBannerV2Displaying) {
[self processNextRoomEffectAttachment];
}
}
- (void)playGameBanner:(AttachmentModel *)attachment {
@kWeakify(self);
[GameUniversalBannerView display:self.bannerContainer
with:attachment
complete:^{
@kStrongify(self);
[self processNextRoomEffectAttachment];
} goToGame:^(NSInteger gameID) {
@kStrongify(self);
NSArray *baishunList = [self.hostDelegate getPlayList];
for (ActivityInfoModel *model in baishunList) {
if (model.id == gameID) {
MSRoomGameWebVC *vc = [[MSRoomGameWebVC alloc]initWithDelegate:self.hostDelegate
gameModel:model];
vc.view.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
XPRoomViewController *roomVC = (XPRoomViewController *)self.hostDelegate;
[roomVC addChildViewController:vc];
XPRoomAnimationView *animationView;
for (id obj in self.hostDelegate.getSuperView.subviews) {
if ([obj isKindOfClass:[XPRoomAnimationView class]]){
animationView = obj;
break;
}
}
[self.hostDelegate.getSuperView addSubview:vc.view];
vc.view.tag = 913;
return;
}
}
}];
}
#pragma mark - Method: Car
- (void)handleCarEnter:(AttachmentModel *)attachment {
if (attachment.second == Custom_Message_Sub_Car_EnterRoom) {
if (self.isPlayingGiftEffect) {
return;
}
if ([self _isInSudGame]) {
return;
}
if (!self.hostDelegate.getRoomInfo.hasAnimationEffect) {
return;
}
NSInteger otherViewType = [attachment.data[@"otherViewType"] integerValue];
NSString *viewUrl = attachment.data[@"viewUrl"];
NSString *effect = attachment.data[@"effect"];
NSDictionary *dic = nil;
if (![NSString isEmpty:viewUrl]) {
dic = @{@"otherViewType":@(otherViewType), @"viewUrl":viewUrl};
} else if(![NSString isEmpty:effect]) {
dic = @{@"effect":effect};
}
[self starHandleCarEffect:dic];
}
}
- (void)starHandleCarEffect:(NSDictionary *)dic {
if (!dic) {
return;
}
[self.carEffectQueue addObject:dic];
[self playCarEffect:dic];
}
- (void)nextCarEffect {
if (self.carEffectQueue.count > 0) {
[self.carEffectQueue removeObjectAtIndex:0];
}
if (self.carEffectQueue.count > 0) {
[self playCarEffect:self.carEffectQueue.firstObject];
}
}
- (void)playCarEffect:(NSDictionary *)effectDict {
NSString *viewUrl = [effectDict objectForKey:@"viewUrl"];
NSString *carEffect = [effectDict objectForKey:@"effect"];
@kWeakify(self);
if (![NSString isEmpty:viewUrl]) {
[self.vapParser parseWithURL:viewUrl completionBlock:^(NSString * _Nullable videoUrl) {
@kStrongify(self);
if (![NSString isEmpty:videoUrl]) {
if([videoUrl.lowercaseString containsString:@".pag"]){
self.carPagEffectView.hidden = NO;
[self _addSubviewToMiddleContainer:self.carPagEffectView];
[self.carPagEffectView setPath:videoUrl];
[self.carPagEffectView play];
} else {
self.carVapEffectView.hidden = NO;
[self _addSubviewToMiddleContainer:self.carVapEffectView];
[self.carVapEffectView setMute:NO];
[self.carVapEffectView playHWDMP4:videoUrl repeatCount:1 delegate:self];
}
}
} failureBlock:^(NSError * _Nullable error) {
@kStrongify(self);
[self nextCarEffect];
}];
} else if (![NSString isEmpty:carEffect]) {
[self.vggParser parseWithURL:[NSURL URLWithString:carEffect]
completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
@kStrongify(self);
if (videoItem) {
[self _addSubviewToMiddleContainer:self.carSVGAEffectView];
[self _updateGiftEffectContentMode:self.carSVGAEffectView
size:videoItem.videoSize];
self.carSVGAEffectView.videoItem = videoItem;
[self.carSVGAEffectView startAnimation];
}
} failureBlock:^(NSError * _Nullable error) {
@kStrongify(self);
[self nextCarEffect];
}];
}
}
#pragma mark - Method: Send Gifts
- (void)receiveGiftHandleSendGiftAnimationWith:(GiftReceiveInfoModel *)receiveInfo attachment:(AttachmentModel *)attachment {
if (!self.hostDelegate.getRoomInfo.hasAnimationEffect) {
return;
}
GiftInfoModel *giftInfo = receiveInfo.gift;
if (attachment.second == Custom_Message_Sub_AllMicroLuckySend ||
attachment.second == Custom_Message_Sub_AllBatchMicroLuckySend ||
attachment.second == Custom_Message_Sub_Gift_LuckySend) {
NSString * giftId = [NSString stringWithFormat:@"%ld", receiveInfo.luckyGiftList.giftList.firstObject.giftId];
giftInfo = [[XPGiftStorage shareStorage] findGiftInfo:giftId];
}
if (giftInfo == nil) {
giftInfo = [[XPGiftStorage shareStorage] findGiftInfo:receiveInfo.giftId];
}
receiveInfo.gift = giftInfo;
RoomInfoModel * roomInfo = [self.hostDelegate getRoomInfo];
if ((giftInfo.otherViewType == GiftOtherViewTypeMp4 ||
giftInfo.otherViewType == GiftOtherViewTypePag) &&
giftInfo.viewUrl.length > 0 && roomInfo.hasAnimationEffect) {
receiveInfo.mp4Url = giftInfo.viewUrl;
} else if (giftInfo.hasVggPic &&
giftInfo.vggUrl.length > 0
&& roomInfo.hasAnimationEffect) {///SVGA动画
receiveInfo.vggUrl = giftInfo.vggUrl;
}
[self.giftAnimationManager enqueueGift:receiveInfo];
}
- (void)receiveGift:(GiftReceiveInfoModel *)receiveInfo {
if (receiveInfo.isHomeShow) {
return;
}
// 单独处理 combo
[[GiftComboManager sharedManager] receiveGiftInfoForDisplayComboFlags:receiveInfo
container:self];
RoomInfoModel * roomInfo = [self.hostDelegate getRoomInfo];
if (receiveInfo.isLuckyBagGift) {
} else {
if (![NSString isEmpty:receiveInfo.mp4Url] || ![NSString isEmpty:receiveInfo.vggUrl]) {
[self.svgaQueue addObject:receiveInfo];
}
}
if (self.giftEffectTimer == nil &&
self.svgaQueue.count > 0) {
[self startHandleGiftEffectTimer];
}
}
- (void)startHandleGiftEffectTimer {
NSTimeInterval period = 2.0;
dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
dispatch_source_set_timer(timer, dispatch_walltime(NULL, 0), period * NSEC_PER_SEC, 0); //每秒执行
@kWeakify(self);
dispatch_source_set_event_handler(timer, ^{
@kStrongify(self)
if (!self) {
return;
}
dispatch_async(self.giftEffectsQueue, ^{
NSLog(@"******************* 当前队列个数: %@image loader 个数: %@", @(self.svgaQueue.count), @(self.mp4AvatarLoaders.count));
if (self.svgaQueue.count == 0) {
dispatch_source_cancel(timer);
dispatch_async(dispatch_get_main_queue(), ^{
self.giftEffectTimer = nil;
});
} else {
if (self.isPlayingGiftEffect == NO) {
self.isPlayingGiftEffect = YES;
GiftReceiveInfoModel *receiveModel = [self.svgaQueue xpSafeObjectAtIndex:0];
if ([receiveModel isKindOfClass:[GiftReceiveInfoModel class]]) {
dispatch_async(dispatch_get_main_queue(), ^{
[self createGiftSvgaAnimation:receiveModel];
});
}else {
[self.svgaQueue removeObjectAtIndex:0];
self.isPlayingGiftEffect = NO;
}
}
}
});
});
self.giftEffectTimer = timer;
dispatch_resume(timer);
}
-(void)createGiftSvgaAnimation:(GiftReceiveInfoModel *)receiveInfo {
GiftInfoModel *giftInfo = receiveInfo.gift;
NSString *targetURL = @"";
if (receiveInfo.isLuckyBagGift) {
// 播放背包礼物动画
if (![NSString isEmpty:receiveInfo.mp4Url]) {
[self stopCarEffect:giftInfo.goldPrice];
targetURL = receiveInfo.mp4Url;
[self playGiftEffectWithPagUrl:giftInfo.viewUrl];
} else if (![NSString isEmpty:receiveInfo.luckyGiftSvgaUrl]) {
[self stopCarEffect:giftInfo.goldPrice];
targetURL = receiveInfo.luckyGiftSvgaUrl;
[self playGiftEffectWithVapUrl:receiveInfo.luckyGiftSvgaUrl];
} else if (![NSString isEmpty:giftInfo.luckyGiftSvgaUrl]) {
[self stopCarEffect:giftInfo.goldPrice];
targetURL = giftInfo.luckyGiftSvgaUrl;
[self playGiftEffectWithVapUrl:giftInfo.luckyGiftSvgaUrl];
}
} else {
if (giftInfo.otherViewType == GiftOtherViewTypePag ||
giftInfo.otherViewType == GiftOtherViewTypeMp4) {
[self stopCarEffect:giftInfo.goldPrice];
if (giftInfo.otherViewType == GiftOtherViewTypePag) {
[self playGiftEffectWithPagUrl:giftInfo.viewUrl];
targetURL = giftInfo.viewUrl;
} else {
self.mp4TempReceiveInfoModel = receiveInfo;
[self playGiftEffectWithVapUrl:giftInfo.viewUrl];
targetURL = giftInfo.viewUrl;
}
} else if (giftInfo.hasVggPic && giftInfo.vggUrl.length > 0) {
[self stopCarEffect:giftInfo.goldPrice];
[self playGiftEffectWithVggUrl:giftInfo.vggUrl];
targetURL = giftInfo.vggUrl;
}
}
NSLog(@"******************* 执行播放 %@ - %@, self.svgaQueue num: %@", @(giftInfo.otherViewType), targetURL, @(self.svgaQueue.count));
[[NSNotificationCenter defaultCenter] postNotificationName:@"kExchangeRoomAnimationViewAndGameViewIndex"
object:nil];
@kWeakify(self);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
@kStrongify(self);
dispatch_async(self.giftEffectsQueue, ^{
if (self.svgaQueue.count > 0) {
[self.svgaQueue removeObjectAtIndex:0];
}
});
});
}
- (void)stopCarEffect:(double)goldPrice {
if ([ClientConfig shareConfig].configInfo.hideCarEffectGiftPrice <= goldPrice) {
[self.carEffectQueue removeAllObjects];
[self.carSVGAEffectView stopAnimation];
[self.carVapEffectView stopHWDMP4];
[self.carPagEffectView stop];
}
}
- (void)playGiftEffectWithPagUrl:(NSString *)pagUrl {
@kWeakify(self);
[self.vapParser parseWithURL:pagUrl
completionBlock:^(NSString * _Nullable videoUrl) {
@kStrongify(self);
if ([NSString isEmpty:videoUrl]) {
[self playPAGFailure];
} else {
[self _addSubviewToMiddleContainer:self.pagGiftEffectView];
[self.pagGiftEffectView setPath:videoUrl];
[self.pagGiftEffectView play];
}
} failureBlock:^(NSError * _Nullable error) {
@kStrongify(self);
[self playPAGFailure];
}];
}
- (void)playGiftEffectWithVapUrl:(NSString *)vapUrl {
NSString *encodingUrl = [vapUrl pureURLString];
NSString *fullPath = [self _findFullPath:vapUrl];
self.mp4AvatarLoaders = @[].mutableCopy;
if ([[NSFileManager defaultManager] fileExistsAtPath:fullPath]){
[self playVAG:fullPath];
}else {
@kWeakify(self);
[self.vapParser parseWithURL:encodingUrl
completionBlock:^(NSString * _Nullable videoUrl) {
@kStrongify(self);
if ([NSString isEmpty:videoUrl]) {
[self playVAGFailure];
} else {
[self playVAG:videoUrl];
}
} failureBlock:^(NSError * _Nullable error) {
@kStrongify(self);
[self playVAGFailure];
}];
}
}
- (void)playGiftEffectWithVggUrl:(NSString *)vggUrl {
NSString *encodingUrl = [vggUrl pureURLString];
NSString *fullPath = [self _findFullPath:vggUrl];
NSLog(@"******************* 解释 SVGA : %@ | %@", encodingUrl, fullPath);
if (![NSString isEmpty:fullPath] && [[NSFileManager defaultManager] fileExistsAtPath:fullPath]) {
NSData *data = [NSData dataWithContentsOfFile:fullPath options:0 error:NULL];
NSString *fileName = [[encodingUrl componentsSeparatedByString:@"/"] lastObject];
@kWeakify(self);
[self.vggParser parseWithData:data
cacheKey:fileName
completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
@kStrongify(self);
if (videoItem) {
[self playVGG:videoItem];
} else {
[self playVGGFailure];
}
} failureBlock:^(NSError * _Nonnull error) {
@kStrongify(self);
[self playVGGFailure];
}];
} else {
@kWeakify(self);
[self.vggParser parseWithURL:[NSURL URLWithString:encodingUrl]
completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
@kStrongify(self);
NSLog(@"******************* 解释 SVGA 成功");
if (videoItem) {
[self playVGG:videoItem];
} else {
[self playVGGFailure];
}
} failureBlock:^(NSError * _Nullable error) {
@kStrongify(self);
NSLog(@"******************* 解释 SVGA 失败:%@", error);
[self playVGGFailure];
}];
}
}
- (void)playVGG:(SVGAVideoEntity *)videoItem {
[self _addSubviewToMiddleContainer:self.vggGiftEffectView];
[self _updateGiftEffectContentMode:self.vggGiftEffectView
size:videoItem.videoSize];
self.vggGiftEffectView.videoItem = videoItem;
[self.vggGiftEffectView startAnimation];
}
- (void)playVGGFailure {
[self playVGGEnd];
}
- (void)playVGGEnd {
self.isPlayingGiftEffect = NO;
self.vggGiftEffectView.hidden = YES;
}
- (void)playVAG:(NSString *)url {
@kWeakify(self);
dispatch_async(dispatch_get_main_queue(), ^{
@kStrongify(self);
[self _addSubviewToMiddleContainer:self.vapGiftEffectView];
[self.vapGiftEffectView setMute:NO];
[self.vapGiftEffectView playHWDMP4:url
repeatCount:1
delegate:self];
});
}
- (void)playVAGFailure {
[self playVAGEnd];
}
- (void)playVAGEnd {
self.isPlayingGiftEffect = NO;
self.vapGiftEffectView.hidden = YES;
[self.vapGiftEffectView setMute:YES];
[self.vapGiftEffectView stopHWDMP4];
}
- (void)playPAGFailure {
self.isPlayingGiftEffect = NO;
self.pagGiftEffectView.hidden = YES;
}
#pragma mark - Delegates
#pragma mark - SVGA delegate
- (void)svgaPlayerDidFinishedAnimation:(SVGAPlayer *)player {
if (player == self.enterEffectView && player.loops == 1) {
[self endAnimationEnterEffect];
}
else if (player == self.vggGiftEffectView) {
[self playVGGEnd];
}
else if (player == self.carSVGAEffectView) {
self.carSVGAEffectView.hidden = YES;
[self.carSVGAEffectView removeFromSuperview];
[self nextCarEffect];
}
}
#pragma mark - HWDMP4PlayDelegate
- (BOOL)shouldStartPlayMP4:(VAPView *)container config:(QGVAPConfigModel *)config {
CGFloat width = config.info.size.width;
CGFloat height = config.info.size.height;
container.center = self.center;
[container mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(KScreenWidth);
make.height.mas_equalTo(KScreenWidth * height / width);
}];
return YES;
}
- (void)viewDidFinishPlayMP4:(NSInteger)totalFrameCount view:(VAPView *)container {
dispatch_async(dispatch_get_main_queue(), ^{
container.hidden = YES;
if (container == self.carVapEffectView) {
[self.carVapEffectView removeFromSuperview];
self.carVapEffectView = nil;
[self nextCarEffect];
}
else if (container == self.vapGiftEffectView) {
[self playVAGEnd];
}
// else
// if(container == self.luckyVapGiftEffectView) {
// [self.luckyVapGiftEffectView removeFromSuperview];
// self.luckyVapGiftEffectView = nil;
// }
});
}
- (void)viewDidStopPlayMP4:(NSInteger)lastFrameIndex view:(VAPView *)container {
dispatch_async(dispatch_get_main_queue(), ^{
container.hidden = YES;
if (container == self.carVapEffectView) {
[self.carVapEffectView removeFromSuperview];
[self nextCarEffect];
}
else if (container == self.vapGiftEffectView) {
[self playVAGEnd];
}
// else if(container == self.luckyVapGiftEffectView) {
// [self.luckyVapGiftEffectView removeFromSuperview];
// self.luckyVapGiftEffectView = nil;
// } else if(container == self.wishGiftEffectView) {
// [self.wishGiftEffectView removeFromSuperview];
// self.wishGiftEffectView = nil;
// }
});
}
- (void)viewDidFailPlayMP4:(NSError *)error{
[self playVAGFailure];
}
- (void)loadVapImageWithURL:(NSString *)urlStr
context:(NSDictionary *)context
completion:(VAPImageCompletionBlock)completionBlock {
if (self.mp4TempReceiveInfoModel) {
dispatch_async(dispatch_get_main_queue(), ^{
QGVAPSourceInfo *info = (QGVAPSourceInfo *)context[@"resource"];
NSLog(@" MP4 的 key - info.contentTag : %@", info.contentTag);
[self _loadMP4AvatarURL:urlStr
info:info
completion:completionBlock];
});
}
}
- (void)_loadMP4AvatarURL:(NSString *)urlStr
info:(QGVAPSourceInfo *)info
completion:(VAPImageCompletionBlock)completionBlock {
NSString *path = @"";
switch (self.mp4TempReceiveInfoModel.gift.showAvatarType) {
case 1: // 只使用 avatar
case 3:
path = self.mp4TempReceiveInfoModel.avatar;
if ([NSString isEmpty:path]) {
path = self.mp4TempReceiveInfoModel.sendUserAvatar;
}
break;
case 2: // 只使用 target avatar
path = self.mp4TempReceiveInfoModel.targetAvatar;
if ([NSString isEmpty:path]) {
path = self.mp4TempReceiveInfoModel.recvUserAvatar;
}
break;
default:
break;
}
if ([NSString isEmpty:path]) {
completionBlock(kImage(@"common_avatar"), nil, @"dafeult image");
} else {
NetImageView *avatar_Loader = [[NetImageView alloc] init];
[avatar_Loader loadImageWithUrl:path
completion:^(UIImage * _Nullable image, NSURL * _Nonnull url) {
completionBlock(image, nil, urlStr);
}];
[self.mp4AvatarLoaders addObject:avatar_Loader];
}
}
#pragma mark - PAGViewListener
- (void)onAnimationEnd:(PAGView*)pagView{
dispatch_async(dispatch_get_main_queue(), ^{
pagView.hidden = YES;
if (pagView == self.pagGiftEffectView) {
self.isPlayingGiftEffect = NO;
}
else if(pagView == self.carPagEffectView){
[self.carPagEffectView removeFromSuperview];
self.carPagEffectView = nil;
[self nextCarEffect];
}
});
}
- (void)onAnimationCancel:(PAGView*)pagView{
dispatch_async(dispatch_get_main_queue(), ^{
pagView.hidden = YES;
if (pagView == self.pagGiftEffectView) {
self.isPlayingGiftEffect = NO;
}
});
}
#pragma mark - RoomHostDelegate
#pragma mark - RoomGuestDelegate: NIMCustomMessage
- (void)handleNIMCustomMessage:(NIMMessage *)message {
if (![message.messageObject isKindOfClass:[NIMCustomObject class]]) {
return;
}
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
if (obj.attachment == nil || ![obj.attachment isKindOfClass:[AttachmentModel class]]) {
return;
}
AttachmentModel *attachment = (AttachmentModel *)obj.attachment;
switch (attachment.first) {
case CustomMessageType_Gift:
[self _handleGiftMessage:attachment];
break;
case CustomMessageType_AllMicroSend:
[self _handleGiftMessage:attachment];
break;
case CustomMessageType_Car_Notify:
[self handleCarEnter:attachment];
break;
case CustomMessageType_CP:
[self receiveCPEvent:attachment];
break;
case CustomMessageType_Super_Gift:
[self _handleSuperGift:attachment];
break;
case CustomMessageType_General_Floating_Screen:
[self _handleCommonBanner:attachment];
break;
case CustomMessageType_LuckyBag:
// TODO: 福袋
break;
case CustomMessageType_Look_Love:
// TODO: 寻爱 / 砸蛋
break;
case CustomMessageType_RoomPlay_Dating:
// TODO: 相亲
break;
case CustomMessageType_Across_Room_PK:
// TODO: 跨房/个播 PK
break;
case CustomMessageType_Anchor_FansTeam:
// TODO: 个播粉丝团
break;
case CustomMessageType_Anchor_Hour_Rank:
// TODO: 个播小时榜
break;
case CustomMessageType_License_Hour_Rank:
// TODO: 牌照房小时榜
break;
case CustomMessageType_Gift_Compound:
// TODO: 魔法小屋合成礼物
break;
case CustomMessageType_Room_Sailing:
// TODO: 航海
break;
case CustomMessageType_Graffiti_Gift:
// TODO: 涂鸦礼物
break;
case CustomMessageType_Graffiti_Star_Kitchen:
// TODO: 星级厨房飘屏
break;
case CustomMessageType_Treasure_Fairy:
// TODO: 夺宝精灵
break;
case CustomMessageType_Tarot:
// TODO: 夺宝精灵
break;
case CustomMessageType_Common_H5:
// TODO: 通用 H5 页面
break;
default:
break;
}
}
- (void)_handleGiftMessage:(AttachmentModel *)attachment {
if ([self _isInSudGame]) {
return;
}
GiftReceiveInfoModel * receiveInfo = [GiftReceiveInfoModel modelWithJSON:attachment.data];
[receiveInfo giftDataAlignment];
receiveInfo.isLuckyBagGift = (attachment.second == Custom_Message_Sub_Gift_LuckySend);
receiveInfo.isBatch = (attachment.second == Custom_Message_Sub_AllBatchSend ||
attachment.second == Custom_Message_Sub_AllBatchMicroLuckySend);
receiveInfo.isComboBatch = (attachment.second == Custom_Message_Sub_AllMicroSend);
switch (attachment.second) {
case Custom_Message_Sub_Gift_Send:
[self _handleGift:receiveInfo attachment:attachment];
break;
case Custom_Message_Sub_AllMicroSend:
[self _handleGift:receiveInfo attachment:attachment];
break;
case Custom_Message_Sub_Gift_ChannelNotify:
#if DEBUG
// [self playLuckyWinningBanner:attachment];
// return;
#endif
//处理原广播通用飘屏 banner 逻辑
[self receiveRoomGiftBanner:attachment];
return;
break;
case Custom_Message_Sub_Gift_LuckySend:
// TODO: 福袋礼物
break;
case Custom_Message_Sub_Gift_EmbeddedStyle:
[self _handleGiftEmbeddedStyle:receiveInfo attachment:attachment];
break;
default:
return;
break;
}
if (receiveInfo.isLuckyBagGift) {
[self receiveGiftHandleSendGiftAnimationWith:receiveInfo
attachment:attachment];
[self _handleBagGift:receiveInfo];
} else {
if (receiveInfo.gift.notifyFull == 1 &&
attachment.second == Custom_Message_Sub_Gift_Send) {
// 全服礼物,但由自己发送,不在此逻辑播放
return;
}
[self receiveGiftHandleSendGiftAnimationWith:receiveInfo
attachment:attachment];
[self receiveGift:receiveInfo];
}
}
- (void)_handleBagGift:(GiftReceiveInfoModel *)receiveInfo {
if (!self.hostDelegate.getRoomInfo.hasAnimationEffect) {
return;
}
[self receiveGift:receiveInfo];
}
- (void)_handleGift:(GiftReceiveInfoModel *)receiveInfo
attachment:(AttachmentModel *)attachment {
// 确认接受者有 uid
if (receiveInfo.targetUsers.count == 0) {
GiftReceiveUserInfoModel *model = [[GiftReceiveUserInfoModel alloc] init];
model.nick = receiveInfo.targetNick;
model.avatar = receiveInfo.targetAvatar;
model.uid = receiveInfo.uid.integerValue;
receiveInfo.targetUsers = @[model];
}
if (receiveInfo.targetUids.count == 0) {
receiveInfo.targetUids = @[@(receiveInfo.uid.integerValue)];
}
}
- (void)_handleGiftEmbeddedStyle:(GiftReceiveInfoModel *)receiveInfo
attachment:(AttachmentModel *)attachment {
// 数据对齐
receiveInfo.targetUid = [[attachment.data objectForKey:@"recvUserUid"] stringValue];
receiveInfo.targetNick = [attachment.data objectForKey:@"recvUserNick"];
receiveInfo.targetAvatar = [attachment.data objectForKey:@"recvUserAvatar"];
receiveInfo.avatar = [attachment.data objectForKey:@"sendUserAvatar"];
receiveInfo.nick = [attachment.data objectForKey:@"sendUserNick"];
receiveInfo.uid = [[attachment.data objectForKey:@"sendUserUid"] stringValue];
// 确认接受者有 uid
if (receiveInfo.targetUsers.count > 0 && receiveInfo.targetUids.count <= 0) {
receiveInfo.targetUids = [receiveInfo.targetUsers valueForKeyPath:@"uid"];
}
}
- (void)_handleSuperGift:(AttachmentModel *)attachment {
switch (attachment.second) {
case Custom_Message_Sub_Super_Gift_Winning_Coins:
[self receiveLuckGiftWinning:attachment];
break;
case Custom_Message_Sub_Super_Gift_Winning_Coins_ALL_Room:
[self receiveLuckGiftBanner:attachment];
break;
default:
break;
}
}
- (void)_handleCommonBanner:(AttachmentModel *)attachment {
switch (attachment.second) {
case Custom_Message_Sub_General_Floating_Screen_One_Room:
case Custom_Message_Sub_General_Floating_Screen_All_Room:
[self receiveRoomGeneralFloatingScreen:attachment];
break;
default:
break;
}
}
- (NSString *)_findFullPath:(NSString *)url {
NSString *encodingUrl = [url pureURLString];
NSString *fileName = [[encodingUrl componentsSeparatedByString:@"/"] lastObject];
NSString *fullPath = [self.GiftDynamicEffectListPath stringByAppendingPathComponent:fileName];
return fullPath;
}
- (void)_updateGiftEffectContentMode:(UIView *)view
size:(CGSize)size {
CGFloat width = size.width;
CGFloat height = size.height;
if (width > height) {
view.contentMode = UIViewContentModeScaleAspectFit;
} else {//高大于宽
CGFloat resizeH = KScreenWidth * height / width;//按照屏幕的宽度去缩放,获得高度
if (resizeH > KScreenHeight) {//如果大于屏幕高度,填充
view.contentMode = UIViewContentModeScaleAspectFill;
} else {//小于屏幕高度,
view.contentMode = UIViewContentModeScaleAspectFit;
}
}
}
#pragma mark - RoomGuestDelegate: NIMNotificationMessageDelegate
- (void)handleNIMNotificationMessage:(NIMMessage *)message {
NIMNotificationObject *notiMsg = (NIMNotificationObject *)message.messageObject;
NIMChatroomNotificationContent *content = (NIMChatroomNotificationContent *)notiMsg.content;
if (!content) {
return;
}
switch (content.eventType) {
case NIMChatroomEventTypeEnter:
[self enterRoom:message content:content];
break;
default:
break;
}
}
#pragma mark - NIMBroadcastManagerDelegate
- (void)onReceiveBroadcastMessage:(NIMBroadcastMessage *)broadcastMessage {
if (broadcastMessage.content) {
NSDictionary *msgDictionary = [broadcastMessage.content toJSONObject];
AttachmentModel *attachment = [AttachmentModel modelWithJSON:msgDictionary[@"body"]];
NSString *partitionId = [NSString stringWithFormat:@"%@",attachment.data[@"partitionId"]];
if(![partitionId isEqualToString:self.hostDelegate.getUserInfo.partitionId]){
return;
}
switch (attachment.first) {
case CustomMessageType_General_Floating_Screen:
[self _handleCommonBanner:attachment];
break;
default:
break;
}
}
}
#pragma mark - GiftAnimationManagerDelegate
- (CGPoint)animationPointAtStageViewByUid:(NSString *)uid {
return [self.hostDelegate animationPointAtStageViewByUid:uid];
}
#pragma mark - Gesture
- (void)addBnnerContainGesture {
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:@selector(handleSwipe)];
swipe.direction = UISwipeGestureRecognizerDirectionLeft;
[self.bannerContainer addGestureRecognizer:swipe];
}
- (void)handleSwipe {
[[NSNotificationCenter defaultCenter] postNotificationName:@"SwipeOutBanner" object:nil];
}
#pragma mark - Animations
- (void)enterRoomAnimationFor:(UIView *)targetView
startFrom:(CGPoint)sfPoint
startTo:(CGPoint)stPoint
endFrom:(CGPoint)efPoint
endTo:(CGPoint)etPoint
duration:(CFTimeInterval)duration
completion:(void (^)(BOOL finished))completion {
@kWeakify(self);
[self enterRoomMoveInAnimationFor:targetView
fromValue:sfPoint
toValue:stPoint
completion:^(BOOL finished) {
if (finished) {
@kStrongify(self);
@kWeakify(self);
[self enterRoomMoveOutAnimationFor:targetView
fromValue:efPoint
toValue:etPoint
beginTime:duration
completion:^(BOOL finished) {
if (finished) {
@kStrongify(self);
[self cleanupAnimationsForView:targetView];
if (completion) {
completion(finished);
}
}
}];
}
}];
}
- (void)enterRoomMoveInAnimationFor:(UIView *)view
fromValue:(CGPoint)fromValue
toValue:(CGPoint)toValue
completion:(void (^)(BOOL finished))completion {
POPSpringAnimation *springAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewCenter];
springAnimation.springSpeed = 12;
springAnimation.springBounciness = 10.f;
springAnimation.fromValue = [NSValue valueWithCGPoint:fromValue];
springAnimation.toValue = [NSValue valueWithCGPoint:toValue];
[springAnimation setCompletionBlock:^(POPAnimation *anim, BOOL finished) {
if (completion) completion(finished);
}];
[view pop_addAnimation:springAnimation forKey:@"amationSpringIn"];
}
- (void)enterRoomMoveOutAnimationFor:(UIView *)view
fromValue:(CGPoint)fromValue
toValue:(CGPoint)toValue
beginTime:(CFTimeInterval)beginTime
completion:(void (^)(BOOL finished))completion {
POPSpringAnimation *moveAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewCenter];
moveAnimation.fromValue = [NSValue valueWithCGPoint:fromValue];
moveAnimation.toValue = [NSValue valueWithCGPoint:toValue];
moveAnimation.beginTime = beginTime;
moveAnimation.springSpeed = 8;
moveAnimation.springBounciness = 15.f;
[moveAnimation setCompletionBlock:^(POPAnimation *anim, BOOL finished) {
if (completion) completion(finished);
}];
[view pop_addAnimation:moveAnimation forKey:@"animetionMoveOut"];
}
- (void)cleanupAnimationsForView:(UIView *)view {
[view pop_removeAllAnimations];
[view removeFromSuperview];
}
#pragma mark - Common methods
- (NSString *)_resolveUserNameFromContent:(NIMChatroomNotificationContent *)content
extModel:(XPMessageRemoteExtModel *)extModel {
// 1) extModel.nick 优先
if (![NSString isEmpty:extModel.nick]) {
return extModel.nick;
}
// 2) 如果 extModel.nick 为空,看 content.source.nick
if (![NSString isEmpty:content.source.nick]) {
return content.source.nick;
}
// 3) 如果依然空,并且是自己,则取本地 nick
if (content.source.userId.intValue == self.hostDelegate.getUserInfo.uid &&
![NSString isEmpty:self.hostDelegate.getUserInfo.nick]) {
return self.hostDelegate.getUserInfo.nick;
}
// 4) 兜底
return @"";
}
- (NSString *)_mapExperLevelSeqToLocalKey:(NSInteger)seq {
if (seq >= 30 && seq <= 39) {
return @"experience_entre_effect_30";
} else if (seq >= 40 && seq <= 49) {
return @"experience_entre_effect_40";
} else if (seq >= 50 && seq <= 59) {
return @"experience_entre_effect_50";
} else if (seq >= 60 && seq <= 69) {
return @"experience_entre_effect_60";
} else if (seq >= 70 && seq <= 79) {
return @"experience_entre_effect_70";
} else if (seq >= 80 && seq <= 89) {
return @"experience_entre_effect_80";
} else if (seq >= 90) {
return @"experience_entre_effect_90";
}
return @"";
}
- (void)_handleLuckyBagGift:(GiftReceiveInfoModel *)receiveInfo attachment:(AttachmentModel *)attachment {
// [self receiveGiftHandleSendGiftAnimation:attachment];
// if (!self.delegate.getRoomInfo.hasAnimationEffect) {
// return;
// }
// if (receiveInfo.viewUrl.length > 0) {
// [self playLuckyGiftEffectWithVapUrl:receiveInfo.viewUrl];
// } else {
// NSString *svgaString = receiveInfo.luckyGiftSvgaUrl.length > 0 ? receiveInfo.luckyGiftSvgaUrl : receiveInfo.gift.luckyGiftSvgaUrl;
// NSURL * luckyGiftSvgaUrl = [NSURL URLWithString:svgaString];
// if (luckyGiftSvgaUrl.absoluteString.length > 0) {
// [self playLuckyGiftEffect:luckyGiftSvgaUrl];
// }
// }
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// [self receiveGift:receiveInfo];
// });
}
- (BOOL)_isInSudGame {
BOOL isGamePlaying = NO;
if (self.hostDelegate.getRoomInfo.type == RoomType_MiniGame) {
NSInteger micCount = self.hostDelegate.getRoomInfo.mgMicNum;
for (int i = -1; i<micCount; i++) {
NSMutableDictionary * micQueue = self.hostDelegate.getMicroQueue;
MicroQueueModel *micSequence = [micQueue objectForKey:[NSString stringWithFormat:@"%d", i]];
if (micSequence == nil || micSequence.userInfo == nil) {
continue;
}
if (micSequence.userInfo.uid == [AccountInfoStorage instance].getUid.integerValue &&
micSequence.userInfo.gameStatus == LittleGamePlayStatus_Plying) {
isGamePlaying = YES;
break;
}
}
}
return isGamePlaying;
}
- (void)_addSubviewToMiddleContainer:(UIView *)view {
if (view.superview == nil) {
[self.middleContainer addSubview:view];
[view mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self.middleContainer);
make.width.mas_equalTo(KScreenWidth);
make.height.mas_equalTo(KScreenHeight);
}];
}
view.hidden = NO;
}
#pragma mark - Lazy init
- (XPRoomAnimationHitView *)bottomContainer {
if (!_bottomContainer) {
_bottomContainer = [[XPRoomAnimationHitView alloc] init];
}
return _bottomContainer;
}
- (XPRoomAnimationHitView *)middleContainer {
if (!_middleContainer) {
_middleContainer = [[XPRoomAnimationHitView alloc] init];
}
return _middleContainer;
}
- (XPRoomAnimationHitView *)topContainer {
if (!_topContainer) {
_topContainer = [[XPRoomAnimationHitView alloc] init];
}
return _topContainer;
}
- (XPRoomAnimationHitView *)bannerContainer {
if (!_bannerContainer) {
_bannerContainer = [[XPRoomAnimationHitView alloc] init];
#if DEBUG
_bannerContainer.backgroundColor = [UIColor colorWithWhite:1 alpha:0.4];
#endif
}
return _bannerContainer;
}
- (SVGAImageView *)enterEffectView {
if (_enterEffectView == nil) {
_enterEffectView = [[SVGAImageView alloc]init];
_enterEffectView.delegate = self;
_enterEffectView.contentMode = UIViewContentModeScaleAspectFit;
_enterEffectView.frame = CGRectMake(0, 0, KScreenWidth, 50);
_enterEffectView.backgroundColor = [UIColor clearColor];
_enterEffectView.alpha = 0;
_enterEffectView.userInteractionEnabled = NO;
}
return _enterEffectView;
}
- (NSMutableArray *)svgaQueue{
if(!_svgaQueue){
_svgaQueue = [NSMutableArray array];
}
return _svgaQueue;
}
- (XPRoomGiftAnimationParser *)vapParser {
if (!_vapParser) {
_vapParser = [[XPRoomGiftAnimationParser alloc] init];
}
return _vapParser;
}
- (PAGView *)pagGiftEffectView{
if(!_pagGiftEffectView){
_pagGiftEffectView = [[PAGView alloc]init];
[_pagGiftEffectView addListener:self];
_pagGiftEffectView.backgroundColor = [UIColor clearColor];
_pagGiftEffectView.userInteractionEnabled = NO;
_pagGiftEffectView.repeatCount = 1;
_pagGiftEffectView.scaleMode = PAGScaleModeStretch;
}
return _pagGiftEffectView;
}
- (VAPView *)vapGiftEffectView {
if (!_vapGiftEffectView) {
_vapGiftEffectView = [[VAPView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
_vapGiftEffectView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
_vapGiftEffectView.contentMode = UIViewContentModeScaleAspectFill;
_vapGiftEffectView.hidden = YES;
_vapGiftEffectView.userInteractionEnabled = NO;
}
return _vapGiftEffectView;
}
- (SVGAParser *)vggParser {
if (!_vggParser) {
_vggParser = [[SVGAParser alloc] init];
}
return _vggParser;
}
- (SVGAImageView *)vggGiftEffectView {
if (!_vggGiftEffectView) {
_vggGiftEffectView = [[SVGAImageView alloc]init];
_vggGiftEffectView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
_vggGiftEffectView.userInteractionEnabled = NO;
_vggGiftEffectView.delegate = self;
_vggGiftEffectView.hidden = YES;
_vggGiftEffectView.loops = 1;
_vggGiftEffectView.clearsAfterStop = YES;
}
return _vggGiftEffectView;
}
- (VAPView *)carVapEffectView {
if (!_carVapEffectView) {
_carVapEffectView = [[VAPView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
_carVapEffectView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
_carVapEffectView.contentMode = UIViewContentModeScaleAspectFill;
_carVapEffectView.hidden = YES;
}
return _carVapEffectView;
}
- (SVGAImageView *)carSVGAEffectView {
if (_carSVGAEffectView == nil) {
_carSVGAEffectView = [[SVGAImageView alloc]init];
_carSVGAEffectView.delegate = self;
_carSVGAEffectView.contentMode = UIViewContentModeScaleAspectFit;
_carSVGAEffectView.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
_carSVGAEffectView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
_carSVGAEffectView.hidden = YES;
_carSVGAEffectView.userInteractionEnabled = NO;
_carSVGAEffectView.loops = 1;
_carSVGAEffectView.clearsAfterStop = YES;
}
return _carSVGAEffectView;
}
- (PAGView *)carPagEffectView{
if(!_carPagEffectView){
_carPagEffectView = [[PAGView alloc]init];
[_carPagEffectView addListener:self];
_carPagEffectView.backgroundColor = [UIColor clearColor];
_carPagEffectView.userInteractionEnabled = NO;
_carPagEffectView.repeatCount = 1;
_carPagEffectView.scaleMode = PAGScaleModeStretch;
}
return _carPagEffectView;
}
@end