Files
peko-ios/YuMi/Modules/YMRoom/View/BaseUIContainerView/XPRoomFunctionContainerView.m

1900 lines
81 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.

//
// YMRoomFunctionContainerView.m
// YUMI
//
// Created by YUMI on 2021/12/15.
//
#import "XPRoomFunctionContainerView.h"
///Third
#import <Masonry/Masonry.h>
#import <ReactiveObjC/ReactiveObjC.h>
#import <NIMSDK/NIMSDK.h>
#import <POP.h>
///Tool
#import "YUMIMacroUitls.h"
#import "AccountInfoStorage.h"
#import "UIImage+Utils.h"
#import "DJDKMIMOMColor.h"
#import "TTPopup.h"
#import "Api+Room.h"
#import "XNDJTDDLoadingTool.h"
#import "YUMIHtmlUrl.h"
#import "Api+Mine.h"
#import "ClientConfig.h"
#import "XCCurrentVCStackManager.h"
#import "YUMIConstant.h"
#import "Api+RoomSetting.h"
#import "RtcManager.h"
#import "XPRoomMiniManager.h"
#import "Api+RoomPK.h"
#import "Api+Room.h"
#import "Api+WishGift.h"
#import "NSObject+MJExtension.h"
#import "NSArray+Safe.h"
#import "NSMutableDictionary+Saft.h"
#import "ClientConfig.h"
///Model
#import "RoomInfoModel.h"
#import "MicroQueueModel.h"
#import "UserInfoModel.h"
#import "AttachmentModel.h"
#import "GiftValueInfoModel.h"
#import "AcrossRoomPKPanelModel.h"
#import "XPAnchorFansRelationModel.h"
#import "XPAnchorFansJoinModel.h"
#import "XPAnchorFansTaskModel.h"
#import "AcrossRoomPKPanelModel.h"
#import "RoomPKDetailInfoModel.h"
#import "RoomPKChooseUserModel.h"
#import "GiftReceiveInfoModel.h"
#import "GiftInfoModel.h"
#import "RoomPKTeamModel.h"
#import "RoomNewUserGreetModel.h"
#import "WishGiftInfoModel.h"
#import "WishGiftInfoUpdateModel.h"
///View
#import "XPRoomHalfWebView.h"
#import "XPAnchorAudienceUpMicView.h"
#import "XPRoomAnchorInfoCardView.h"
#import "XPRoomTopicViewController.h"
#import "XPRoomTopicAlertView.h"
#import "XPAcrossRoomPKInviteView.h"
#import "XPAcrossRoomPKInviteResultView.h"
#import "XPAcrossRoomPKPanelView.h"
#import "XPAcrossRoomPKResultView.h"
#import "XPAcrossRoomPKForceEndResultView.h"
#import "XPAnchorPKInviteView.h"
#import "XPAnchorPKResultView.h"
#import "XPAnchorPKFinishView.h"
#import "XPSendGiftView.h"
#import "UserRoomCardViewController.h"
#import "XPRoomViewController.h"
#import "AcrossRoomPKPrizeModel.h"
#import "XPMineUserInfoViewController.h"
#import "XPRoomRankEntranceView.h"
#import "XPRoomAnchorRankEnterView.h"
#import "XPRoomBackMusicPlayerView.h"
#import "XPRoomNewUserGreetView.h"
#import "XPRoomHalfMessageView.h"
#import "XPAcrossRoomPKCountDownView.h"
#import "XPNewUserRoomGiftView.h"
#import "XPWishGiftViewController.h"
#import "XPWishGiftEnterView.h"
///个播PK
#import "XPAnchorFansTeamEntranceView.h"
#import "XPAnchorFansTeamViewController.h"
#import "XPAnchorFansTaskViewController.h"
#import "XPAnchorPkPanelView.h"
#import "XPWebViewController.h"
#import "XPAnchorPKMatchView.h"
#import "XPRoomOnLineViewController.h"
#import "XPRoomTrumpetView.h"
#import "LittleGameInfoModel.h"
#import "XPLittleGameMiniStageView.h"
#import "XPLittleGameRoomListView.h"
#import "MSRoomOnLineView.h"
#import "XPRoomPKPanelView.h"
@interface XPRoomFunctionContainerView ()<XPAcrossRoomPKPanelViewDelegate, XPAnchorPkPanelViewDelegate, XPRoomBackMusicPlayerViewDelegate, XPRoomNewUserGreetViewDelegate,XPRoomLittleGameListViewDelegate>
///host 代理
@property (nonatomic,weak) id<RoomHostDelegate>delegate;
///榜单容器
@property(nonatomic,strong) UIStackView *rankStackView;
///房间榜
@property (nonatomic,strong) XPRoomRankEntranceView *contributeEnterView;
///相亲阶段的按钮
@property (nonatomic,strong) UIButton *datingProgresButton;
///小游戏 最小化的坑位
@property (nonatomic,strong) XPLittleGameMiniStageView *littleGameMiniView;
///显示游戏的切换
@property (nonatomic,strong) XPLittleGameRoomListView *gameListView;
///关注个播房主倒计时
@property (nonatomic, strong) dispatch_source_t followAnchorTimer;
///个播粉丝团入口
@property (nonatomic, strong) XPAnchorFansTeamEntranceView *fansTeamEntranceView;
///个播小时榜入口按钮
@property (nonatomic, strong) XPRoomAnchorRankEnterView *hourRankEntranceView;
///跨房pk的面板
@property (nonatomic,strong) XPAcrossRoomPKPanelView *acrossPKPanelView;
///跨房PK预约倒计时
@property (nonatomic, strong) XPAcrossRoomPKCountDownView *acrossPKCountView;
///个播PK匹配
@property (nonatomic, strong) XPAnchorPKMatchView *anchorPKMatchView;
///粉丝团数据
@property (nonatomic, strong) XPAnchorFansRelationModel *relationFansModel;
///个播PK面板
@property (nonatomic, strong) XPAnchorPkPanelView *anchorPKPanelView;
///小喇叭
@property (nonatomic, strong) XPRoomTrumpetView *trumpetView;
///小喇叭队列
@property (nonatomic, strong) NSMutableArray *trumpetQueue;
///小喇叭动画定时器
@property (nonatomic, strong) dispatch_source_t trumpetTimer;
///播放器的入口
@property (nonatomic,strong) UIButton *musicEnterButton;
///播放器
@property (nonatomic,strong) XPRoomBackMusicPlayerView *musicPlayView;
///pk详情
@property (nonatomic,strong) RoomPKDetailInfoModel *pkDetailInfo;
///是否正在加载打招呼
@property (nonatomic,assign) BOOL isLoadGreet;
///获取新用户礼物倒计时3s
@property (nonatomic, strong) dispatch_source_t userGiftTimer;
///在线人数
@property(nonatomic,strong) MSRoomOnLineView *onlineView;
// 房间PK面板
@property(nonatomic, strong) XPRoomPKPanelView *pkPanelView;
@end
@implementation XPRoomFunctionContainerView
- (void)dealloc {
if (self.followAnchorTimer != nil) {
dispatch_source_cancel(self.followAnchorTimer);
}
if (self.trumpetTimer != nil) {
dispatch_source_cancel(self.trumpetTimer);
}
if (self.userGiftTimer != nil) {
dispatch_source_cancel(self.userGiftTimer);
}
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (instancetype)initWithDelegate:(id<RoomHostDelegate>)delegate {
self = [super init];
if (self) {
self.delegate = delegate;
[self initSubViews];
[self initSubViewConstraints];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(beginMatchAnchorPK:) name:@"anchorPKMatchBegin" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleTapToFunctionContainer:) name:@"BannerTapToFunctionContainer" object:nil];
}
return self;
}
- (void)handleTapToFunctionContainer:(NSNotification *)note {
NSValue *tapPointValue = note.userInfo[@"point"];
// UIView *bannerContainer = note.userInfo[@"gesture container"];
if (!tapPointValue) {
return;
}
CGPoint tapPoint = [tapPointValue CGPointValue];
// 将 bannerContainer 中的点转换为 FunctionContainer 坐标系中的点
CGPoint convertedPoint = [self convertPoint:tapPoint fromView:nil];
NSLog(@"<EFBFBD><EFBFBD> 坐标转换: 原始点 %@ -> 转换后点 %@", NSStringFromCGPoint(tapPoint), NSStringFromCGPoint(convertedPoint));
// 检查点是否与各个功能视图重合
[self checkPointIntersectionWithSubviews:convertedPoint];
}
- (void)checkPointIntersectionWithSubviews:(CGPoint)point {
// 检查 contributeEnterView
if (self.contributeEnterView && !self.contributeEnterView.hidden) {
CGPoint contributePoint = [self.contributeEnterView convertPoint:point fromView:self];
if (CGRectContainsPoint(self.contributeEnterView.bounds, contributePoint)) {
NSLog(@"🎯 点击位置与 contributeEnterView 重合,触发贡献榜事件");
[self contributionButtonAction:nil];
return;
}
}
// 检查 onlineView
if (self.onlineView && !self.onlineView.hidden) {
CGPoint onlinePoint = [self.onlineView convertPoint:point fromView:self];
if (CGRectContainsPoint(self.onlineView.bounds, onlinePoint)) {
NSLog(@"🎯 点击位置与 onlineView 重合,触发在线人数事件");
[self onlineTapRecognizer];
return;
}
}
// 检查 hourRankEntranceView
if (self.hourRankEntranceView && !self.hourRankEntranceView.hidden) {
CGPoint hourRankPoint = [self.hourRankEntranceView convertPoint:point fromView:self];
if (CGRectContainsPoint(self.hourRankEntranceView.bounds, hourRankPoint)) {
NSLog(@"🎯 点击位置与 hourRankEntranceView 重合,触发小时榜事件");
[self onAnchorHourRankButtonAction:nil];
return;
}
}
// 检查 fansTeamEntranceView
if (self.fansTeamEntranceView && !self.fansTeamEntranceView.hidden) {
CGPoint fansTeamPoint = [self.fansTeamEntranceView convertPoint:point fromView:self];
if (CGRectContainsPoint(self.fansTeamEntranceView.bounds, fansTeamPoint)) {
NSLog(@"🎯 点击位置与 fansTeamEntranceView 重合,触发粉丝团事件");
[self tapFansTeamRecognizer];
return;
}
}
// 检查 musicEnterButton
if (self.musicEnterButton && !self.musicEnterButton.hidden) {
CGPoint musicPoint = [self.musicEnterButton convertPoint:point fromView:self];
if (CGRectContainsPoint(self.musicEnterButton.bounds, musicPoint)) {
NSLog(@"🎯 点击位置与 musicEnterButton 重合,触发音乐播放器事件");
[self musicEnterButtonAction:self.musicEnterButton];
return;
}
}
// 检查 trumpetView如果存在且可见
if (self.trumpetView && !self.trumpetView.hidden) {
CGPoint trumpetPoint = [self.trumpetView convertPoint:point fromView:self];
if (CGRectContainsPoint(self.trumpetView.bounds, trumpetPoint)) {
NSLog(@"<EFBFBD><EFBFBD> 点击位置与 trumpetView 重合,触发小喇叭事件");
// 这里需要根据 trumpetView 的具体实现来触发相应事件
return;
}
}
NSLog(@"❌ 点击位置未与任何功能视图重合");
}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
// 先检查自身状态
if (!self.userInteractionEnabled || self.hidden || self.alpha <= 0.01) {
return nil;
}
// 从后往前遍历子视图,检查是否有子视图能响应
for (NSInteger i = (self.subviews.count - 1) ; i >= 0 ; i--) {
UIView *subView = [self.subviews xpSafeObjectAtIndex:i];
if (!subView) continue;
CGPoint convertPoint = [subView convertPoint:point fromView:self];
// 只有点击在子视图的实际区域内才继续处理
if (CGRectContainsPoint(subView.bounds, convertPoint)) {
UIView *hitTestView = [subView hitTest:convertPoint withEvent:event];
if (hitTestView) {
// 保留音乐播放器的特殊逻辑
if (self.musicPlayView.superview && self.musicEnterButton.hidden == YES && ![subView isEqual:self.musicPlayView]) {
[UIView animateWithDuration:0.2 animations:^{
self.musicEnterButton.hidden = NO;
} completion:nil];
POPBasicAnimation *moveAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPViewCenter];
moveAnimation.fromValue = [NSValue valueWithCGPoint:self.musicPlayView.center];
moveAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(-KScreenWidth, self.musicPlayView.center.y)];
moveAnimation.beginTime = CACurrentMediaTime();
moveAnimation.duration = 0.5;
moveAnimation.repeatCount = 1;
moveAnimation.removedOnCompletion = YES;
[self.musicPlayView pop_addAnimation:moveAnimation forKey:@"moveOutAnimation"];
}
return hitTestView;
}
}
}
// 如果没有子视图能响应,返回 nil 实现点击穿透
return nil;
}
#pragma mark - Public Method
- (void)hiddenSudGamePostionView {
if (self.delegate.getRoomInfo.mgMicNum > 6) {
return;
}
[self.littleGameMiniView hiddenSudGamePostionView];
}
#pragma mark - Public Method
- (Music *)getCurrentMusic {
return self.musicPlayView.currentMusic;
}
- (BOOL)isPlaying {
return self.musicPlayView.isPlaying;
}
- (NSArray *)getRoomPKGroupTeamList {
NSArray * redArray = @[];
if (self.pkPanelView.redChooseArray > 0) {
redArray = self.pkPanelView.redChooseArray;
}
NSArray * blueArray = @[];
if (self.pkPanelView.blueChooseArray > 0) {
blueArray = self.pkPanelView.blueChooseArray;
}
return @[redArray, blueArray];
}
///房间内PK是否正在进行
- (BOOL)isRoomPKPlaying {
return [self.pkPanelView isRoomPKPlaying];
}
#pragma mark - Private Method
- (void)initSubViews {
[self addSubview:self.rankStackView];
[self addSubview:self.onlineView];
[self.rankStackView addArrangedSubview:self.hourRankEntranceView];
[self.rankStackView addArrangedSubview:self.contributeEnterView];
[self.rankStackView addArrangedSubview:self.musicEnterButton];
self.musicEnterButton.hidden = YES;
self.hourRankEntranceView.hidden = YES;
}
- (void)initSubViewConstraints {
[self.rankStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(12);
make.top.mas_equalTo(kNavigationHeight+4);
make.height.mas_equalTo(27);
}];
[self.hourRankEntranceView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(66);
make.height.mas_equalTo(27);
}];
[self.musicEnterButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(27);
}];
[self.contributeEnterView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(27);
make.width.mas_greaterThanOrEqualTo(50);
}];
[self.onlineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.mas_equalTo(-6);
make.height.mas_equalTo(24);
make.width.mas_equalTo(110);
make.centerY.equalTo(self.rankStackView);
}];
}
- (void)configLittleGameState {
RoomInfoModel * roomInfo = self.delegate.getRoomInfo;
if (roomInfo.isPermitRoom != PermitRoomType_License &&
roomInfo.roomModeType != RoomModeType_Open_Blind &&
roomInfo.roomModeType != RoomModeType_Open_PK_Mode &&
roomInfo.roomModeType != RoomModeType_Open_AcrossRoomPK_mode &&
roomInfo.roomModeType != RoomModeType_Open_Micro_Mode &&
!roomInfo.leaveMode && roomInfo.uid == [AccountInfoStorage instance].getUid.integerValue) {
if (!self.gameListView.superview) {
[self addSubview:self.gameListView];
[self.gameListView mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.mas_equalTo(self).offset(-45);
make.top.mas_equalTo(self).offset(kNavigationHeight - 14 - 11 - 19.0 / 2.0);
}];
}
self.gameListView.mgId = roomInfo.mgId > 0 ? [NSString stringWithFormat:@"%lld", roomInfo.mgId] : @"0";
} else {
if (self.gameListView.superview) {
[self.gameListView removeFromSuperview];
}
}
}
//自己是否在游戏中
- (BOOL)isInSudGame {
BOOL isGamePlaying = NO;
if (self.delegate.getRoomInfo.type == RoomType_MiniGame) {
for (int i = -1; i<5; i++) {
NSMutableDictionary * micQueue = self.delegate.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;
}
///当前房间是否在游戏中
- (BOOL)currentRoomIsInSudGame {
BOOL isGamePlaying = NO;
if (self.delegate.getRoomInfo.type == RoomType_MiniGame) {
for (int i = -1; i<5; i++) {
NSMutableDictionary * micQueue = self.delegate.getMicroQueue;
MicroQueueModel *micSequence = [micQueue objectForKey:[NSString stringWithFormat:@"%d", i]];
if (micSequence == nil || micSequence.userInfo == nil) {
continue;
}
if (micSequence.userInfo.gameStatus == LittleGamePlayStatus_Plying) {
isGamePlaying = YES;
break;
}
}
}
return isGamePlaying;
}
#pragma mark - 新用户打招呼动画
- (void)handleNewUserGreet {
if (self.delegate.getUserInfo.fromType == UserEnterRoomFromType_New_User_Greet && !self.isLoadGreet) {
self.isLoadGreet = YES;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSString * roomUid = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.uid];
[Api newUserStartGreet:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200) {
RoomNewUserGreetModel * info = [RoomNewUserGreetModel modelWithDictionary:data.data];
if (info.roomPopup) {
XPRoomNewUserGreetView * greetView = [[XPRoomNewUserGreetView alloc] initWithFrame:CGRectMake(KScreenWidth, kSafeAreaTopHeight + 52, KScreenWidth, 80)];
greetView.delegate = self;
greetView.sayHelloUserAvatarList = info.sayHelloUserAvatarList;
[self addSubview:greetView];
[UIView animateWithDuration:.35 animations:^{
CGRect rect = greetView.frame;
rect.origin.x = 0;
greetView.frame = rect;
} completion:nil];
}
}
} roomUid:roomUid];
});
}
}
- (void)xPRoomNewUserGreetView:(XPRoomNewUserGreetView *)view didClickCheckout:(UIButton *)sender {
UIViewController * controller = (UIViewController *)self.delegate;
XPRoomHalfMessageView *halfMessageView = [[XPRoomHalfMessageView alloc] initWithFrame:CGRectMake(0, KScreenHeight, KScreenWidth, KScreenHeight) controller:controller];
[controller.view addSubview:halfMessageView];
[UIView animateWithDuration:.35 animations:^{
CGRect rect = halfMessageView.frame;
rect.origin.y = 0;
halfMessageView.frame = rect;
}];
}
#pragma mark - DJ 抓个Beat
- (void)showMusicPanel {
[self addSubview:self.musicPlayView];
[self bringSubviewToFront:self.musicPlayView];
self.musicPlayView.frame = CGRectMake(0, KScreenHeight, KScreenWidth, 200);
[UIView animateWithDuration:0.25 animations:^{
self.musicPlayView.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
} completion:nil];
}
#pragma mark - 房间PK
// MARK: ----- 修改开始
- (void)showPKPanelView {
[self showPKPanel_];
}
- (void)showPKPanel_ {
if (self.pkPanelView.superview) {
return;
}
[self addSubview:self.pkPanelView];
}
- (void)removePKPanel_ {
if (_pkPanelView) {
[self.pkPanelView removeFromSuperview];
self.pkPanelView = nil;
}
}
// MARK: ----- 修改结束
- (void)configRoomPKPanelView:(BOOL)isEnter{
RoomInfoModel * roomInfo = self.delegate.getRoomInfo;
if (roomInfo.roomModeType == RoomModeType_Open_PK_Mode) {
self.pkPanelView.roomInfo = roomInfo;
if (self.pkPanelView.isPanelMinion == NO) {
[self showPKPanel_];
}
NSString * roomId = [NSString stringWithFormat:@"%ld", roomInfo.roomId];
NSString * uid = [AccountInfoStorage instance].getUid;
NIMChatroomMembersByIdsRequest *request = [[NIMChatroomMembersByIdsRequest alloc]init];
request.roomId = roomId;
request.userIds = @[uid];
[[NIMSDK sharedSDK].chatroomManager fetchChatroomMembersByIds:request completion:^(NSError * _Nullable error, NSArray<NIMChatroomMember *> * _Nullable members) {
if (error == nil) {
NIMChatroomMember * member = members.firstObject;
self.pkPanelView.isManager = (member.type == NIMChatroomMemberTypeCreator || member.type == NIMChatroomMemberTypeManager);
if (isEnter) {
[self.pkPanelView enterRoomGetRoomPKDetailInfo];
}
}
}];
} else {
[self removePKPanel_];
}
}
#pragma mark - 个播PK
- (void)beginMatchAnchorPK:(NSNotification *)noti {
if (!self.anchorPKMatchView.superview) {
[self addSubview:self.anchorPKMatchView];
self.anchorPKMatchView.roomUid = [NSString stringWithFormat:@"%ld", [self.delegate getRoomInfo].uid];
[self.anchorPKMatchView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.rankStackView.mas_bottom).mas_offset(5+37+5);
make.leading.mas_equalTo(0);
make.width.height.mas_equalTo(52);
}];
NSDictionary *dict = noti.object;
NSNumber *startTime = dict[@"matchPkStartTime"];
self.delegate.getRoomInfo.pkMatchStartTime = [startTime longLongValue];
[self.anchorPKMatchView openCountdownWithTime:[startTime longValue]];
}
}
#pragma mark - RoomGuestDelegate
- (void)onRoomChange {
if (self.followAnchorTimer != nil) {
dispatch_source_cancel(self.followAnchorTimer);
}
if (self.trumpetTimer != nil) {
dispatch_source_cancel(self.trumpetTimer);
}
if (self.userGiftTimer != nil) {
dispatch_source_cancel(self.userGiftTimer);
}
}
///更新在线人数
-(void)updateOnlineCount:(NSString *)count countList:(NSArray *)countList isUpdateCount:(BOOL)isUpdateCount{
self.onlineView.count = count;
if(isUpdateCount == NO){
self.onlineView.avatarList = countList;
}
self.isFirstUpdate = YES;
}
- (void)onlineTapRecognizer {
XPRoomOnLineViewController *onlineVC = [[XPRoomOnLineViewController alloc] initWithDelegate:self.delegate];
[self.delegate.getCurrentNav pushViewController:onlineVC animated:YES];
}
- (void)onRoomUpdate {
RoomInfoModel * roomInfo = self.delegate.getRoomInfo;
MicroQueueModel * model = [self.delegate.getMicroQueue objectForKey:@"-1"];
if (roomInfo.roomModeType == RoomModeType_Open_Blind && model.userInfo && model.userInfo.uid == [AccountInfoStorage instance].getUid.integerValue) {
if (!self.datingProgresButton.superview) {
[self addSubview:self.datingProgresButton];
[self.datingProgresButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(70, 30));
make.centerX.mas_equalTo(self);
make.top.mas_equalTo(self).offset(354 + kSafeAreaTopHeight + 35);
}];
}
switch (roomInfo.blindDateState) {
case RoomPlayDateingType_Talk:
[self.datingProgresButton setTitle:YMLocalizedString(@"XPRoomFunctionContainerView0") forState:UIControlStateNormal];
break;
case RoomPlayDateingType_Pick:
[self.datingProgresButton setTitle:YMLocalizedString(@"XPRoomFunctionContainerView1") forState:UIControlStateNormal];
break;
case RoomPlayDateingType_Result:
[self.datingProgresButton setTitle:YMLocalizedString(@"XPRoomFunctionContainerView2") forState:UIControlStateNormal];
break;
case RoomPlayDateingType_Finish:
[self.datingProgresButton setTitle:YMLocalizedString(@"XPRoomFunctionContainerView3") forState:UIControlStateNormal];
break;
default:
break;
}
} else {
if (self.datingProgresButton.superview) {
[self.datingProgresButton removeFromSuperview];
}
}
[self updateHourRankEntrance];
if (roomInfo.type == RoomType_Anchor) {
if (roomInfo.hadChangeRoomType) {
///切换房间类型初始化当前用户与房间粉丝团关系
[Api requestInRoomFansTeam:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
XPAnchorFansRelationModel *model = [XPAnchorFansRelationModel modelWithJSON:data.data];
[self updateFansTeamEntranceView:model];
} teamUid:[NSString stringWithFormat:@"%ld", roomInfo.uid]];
[self updateContrionEntranceWithRoomUid:[NSString stringWithFormat:@"%ld", roomInfo.uid] type:@"month"];
}
} else {
[self.fansTeamEntranceView removeFromSuperview];
if (roomInfo.hadChangeRoomType) {
[self updateContrionEntranceWithRoomUid:[NSString stringWithFormat:@"%ld", roomInfo.uid] type:@"day"];
}
}
[self updateRoomTopic];
[self configLittleGameState];
[self configPlayMusicRoomTypeChange];
[self configRoomPKPanelView:NO];
///相亲模式下 隐藏许愿礼物 和vip坑位重叠了
// [self roomInfoUpdateConfigWishGift];
}
- (void)onRoomEntered {
RoomInfoModel * roomInfo = self.delegate.getRoomInfo;
self.contributeEnterView.title = roomInfo.serialValue.stringValue;
NSString * roomUid = [NSString stringWithFormat:@"%ld", roomInfo.uid];
[self updateHourRankEntrance];
if (roomInfo.type == RoomType_Anchor) {//个播房
///进房初始化当前用户与房间粉丝团关系
[Api requestInRoomFansTeam:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
XPAnchorFansRelationModel *model = [XPAnchorFansRelationModel modelWithJSON:data.data];
[self updateFansTeamEntranceView:model];
} teamUid:roomUid];
[self updateContrionEntranceWithRoomUid:roomUid type:@"month"];//获取房间榜前三名
} else {
[self updateContrionEntranceWithRoomUid:roomUid type:@"day"];//获取房间榜前三名
}
if (![[AccountInfoStorage instance].getUid isEqualToString:roomUid]) {//非房主
NSString * uid = [[AccountInfoStorage instance] getUid];
[Api attentionStatusCompletion:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {//是否关注了房主
BOOL isLike = ((NSNumber *)data.data).boolValue;
if (!isLike && !roomInfo.isRoomFans) {
[self setFollowAnchorTimer];
}
} uid:uid isLikeUid:roomUid];
}
if (roomInfo.roomModeType == RoomModeType_Open_AcrossRoomPK_mode) {
[Api getAcrossRoomPKDetail:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200) {
AcrossRoomPKPanelModel * acrossPKPanelInfo = [AcrossRoomPKPanelModel modelWithJSON:data.data];
if (data.data[@"amicStatus"] != nil){
acrossPKPanelInfo.aMicStatus = [data.data[@"amicStatus"] intValue];
}
[self updateAnchorPkInfo:acrossPKPanelInfo];
if (acrossPKPanelInfo.pkType == AcrossRoomPkTypeAnchor) {
if (acrossPKPanelInfo.aUid.integerValue > 0) {
if (!self.anchorPKPanelView.superview) {
[self addSubview:self.anchorPKPanelView];
[self.anchorPKPanelView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self);
make.top.mas_equalTo(kNavigationHeight + 87);
}];
}
self.anchorPKPanelView.pkPanelInfo = acrossPKPanelInfo;
}
} else {
AcrossRoomPKPanelModel * acrossPKPanelInfo = [AcrossRoomPKPanelModel modelWithJSON:data.data];
if (data.data[@"amicStatus"] != nil){
acrossPKPanelInfo.aMicStatus = [data.data[@"amicStatus"] intValue];
}
if (acrossPKPanelInfo.aUid.integerValue > 0) {
if (!self.acrossPKPanelView.superview) {
[self addSubview:self.acrossPKPanelView];
[self.acrossPKPanelView startInitUI];
self.acrossPKPanelView.center = self.center;
}
self.acrossPKPanelView.pkPanelInfo = acrossPKPanelInfo;
}
}
} else {
[XNDJTDDLoadingTool showErrorWithMessage:msg];
}
} roomUid:roomUid];
}
if (roomInfo.showPkBeginTime && roomInfo.roomModeType != RoomModeType_Open_AcrossRoomPK_mode) {//显示PK倒计时
[self handleAcrollPKCountView:roomInfo.pkBeginTime];
}
[self updateRoomTopic];
[self configLittleGameState];
[self configRoomPKPanelView:YES];
[self handleNewUserGreet];
///随机PK匹配
[self handleMatchAnchorPK];
}
- (void)onRoomMiniEntered {
if ([XPRoomMiniManager shareManager].getCurrentMusic) {
// if (!self.musicPlayView.superview) {
// [self addSubview:self.musicPlayView];
// self.musicPlayView.frame = CGRectMake(-KScreenWidth, kNavigationHeight + 4, KScreenWidth - 85, 80);
// }
[self.musicPlayView configCurrentPlayingMusic:[XPRoomMiniManager shareManager].getCurrentMusic isPlaying:[XPRoomMiniManager shareManager].musicPlaying];
[[XPRoomMiniManager shareManager] configCurrentMusic:nil isPlaying:NO];
}
}
- (void)updateContributeEnterViewTitle:(AttachmentModel *)attachment {
if (attachment.first == CustomMessageType_MoneyFlow && attachment.second == Custom_Message_Sub_Money_Flow) {
NSNumber *num = [attachment.data objectForKey:@"serialValue"];
if (num) {
self.contributeEnterView.title = num.stringValue;
}
}
}
- (void)handleNIMCustomMessage:(NIMMessage *)message {
RoomInfoModel * roomInfo = self.delegate.getRoomInfo;
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) {
AttachmentModel *attachment = (AttachmentModel *)obj.attachment;
[self updateContributeEnterViewTitle:attachment];
if (attachment.first == CustomMessageType_AnchorRoom_AudienceUpMic) {
[self showAskForUpMic:attachment.data];
} else if(attachment.first == CustomMessageType_Gift && (attachment.second == Custom_Message_Sub_Gift_Send || attachment.second == Custom_Message_Sub_Gift_LuckySend || attachment.second == Custom_Message_Sub_Gift_ChannelNotify)) {
if (roomInfo.roomModeType == RoomModeType_Open_PK_Mode) {
[self.pkPanelView roomPKReceiveGift:attachment];
}
}else if(attachment.first == CustomMessageType_AllMicroSend && (attachment.second == Custom_Message_Sub_AllMicroSend || attachment.second == Custom_Message_Sub_AllBatchSend || attachment.second == Custom_Message_Sub_AllMicroLuckySend || attachment.second == Custom_Message_Sub_AllBatchMicroLuckySend)) {
if (roomInfo.roomModeType == RoomModeType_Open_PK_Mode) {
[self.pkPanelView roomPKReceiveGift:attachment];
}
} else if(attachment.first == CustomMessageType_Room_PK) {
[self.pkPanelView handleRoomPKCustomMessage:attachment];
} else if (attachment.first == CustomMessageType_Across_Room_PK) {
///自己是公会超管
BOOL meIsSuperAdmin = NO;
for (GuildSuperAdminInfoModel *managerInfo in self.delegate.getRoomSuperAdminList) {
if ([managerInfo.uid isEqualToString:[AccountInfoStorage instance].getUid]) {
meIsSuperAdmin = YES;
break;
}
}
switch (attachment.second) {
case Custom_Message_Sub_AcrossRoomPK_Invite:
{
[self.acrossPKCountView removeFromSuperview];
self.acrossPKCountView = nil;
NIMChatroomMembersByIdsRequest *request = [[NIMChatroomMembersByIdsRequest alloc]init];
request.roomId = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.roomId];
request.userIds = @[[AccountInfoStorage instance].getUid];
[[NIMSDK sharedSDK].chatroomManager fetchChatroomMembersByIds:request completion:^(NSError * _Nullable error, NSArray<NIMChatroomMember *> * _Nullable members) {
if (error == nil) {
NIMChatroomMember * member = [members firstObject];
if (member.type == NIMChatroomMemberTypeCreator || meIsSuperAdmin) {
XPAcrossRoomPKInviteView * inviteView = [[XPAcrossRoomPKInviteView alloc] init];
inviteView.roomUid = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.uid];
inviteView.dataDic = attachment.data;
[self addSubview:inviteView];
[inviteView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self);
}];
}
}
}];
}
break;
case Custom_Message_Sub_AcrossRoomPK_Accept:
{
[self.acrossPKCountView removeFromSuperview];
self.acrossPKCountView = nil;
NIMChatroomMembersByIdsRequest *request = [[NIMChatroomMembersByIdsRequest alloc]init];
request.roomId = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.roomId];
request.userIds = @[[AccountInfoStorage instance].getUid];
[[NIMSDK sharedSDK].chatroomManager fetchChatroomMembersByIds:request completion:^(NSError * _Nullable error, NSArray<NIMChatroomMember *> * _Nullable members) {
if (error == nil) {
NIMChatroomMember * member = [members firstObject];
if (member.type == NIMChatroomMemberTypeCreator || meIsSuperAdmin) {
XPAcrossRoomPKInviteResultView * inviteResultView = [[XPAcrossRoomPKInviteResultView alloc] init];
inviteResultView.is_XP_Accept = YES;
[self addSubview:inviteResultView];
[inviteResultView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self).offset(114 + kSafeAreaTopHeight);
make.centerX.mas_equalTo(self);
make.size.mas_equalTo(CGSizeMake(KScreenWidth - 40, 42));
}];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[inviteResultView removeFromSuperview];
});
}
}
}];
}
break;
case Custom_Message_Sub_AcrossRoomPK_Reject:
{
[self.acrossPKCountView removeFromSuperview];
self.acrossPKCountView = nil;
NIMChatroomMembersByIdsRequest *request = [[NIMChatroomMembersByIdsRequest alloc]init];
request.roomId = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.roomId];
request.userIds = @[[AccountInfoStorage instance].getUid];
[[NIMSDK sharedSDK].chatroomManager fetchChatroomMembersByIds:request completion:^(NSError * _Nullable error, NSArray<NIMChatroomMember *> * _Nullable members) {
if (error == nil) {
NIMChatroomMember * member = [members firstObject];
if (member.type == NIMChatroomMemberTypeCreator || meIsSuperAdmin) {
XPAcrossRoomPKInviteResultView * inviteResutView = [[XPAcrossRoomPKInviteResultView alloc] init];
inviteResutView.is_XP_Accept = NO;
[self addSubview:inviteResutView];
[inviteResutView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self).offset(114 + kSafeAreaTopHeight);
make.centerX.mas_equalTo(self);
make.size.mas_equalTo(CGSizeMake(201, 42));
}];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[inviteResutView removeFromSuperview];
});
}
}
}];
}
break;
case Custom_Message_Sub_AcrossRoomPK_Panel:
{
[self.acrossPKCountView removeFromSuperview];
self.acrossPKCountView = nil;
if (!self.acrossPKPanelView.superview) {
[self addSubview:self.acrossPKPanelView];
[self.acrossPKPanelView startInitUI];
self.acrossPKPanelView.center = self.center;
}
AcrossRoomPKPanelModel * acrossPKPanelInfo = [AcrossRoomPKPanelModel modelWithJSON:attachment.data];
if (attachment.data[@"amicStatus"] != nil){
acrossPKPanelInfo.aMicStatus = [attachment.data[@"amicStatus"] intValue];
}
self.acrossPKPanelView.pkPanelInfo = acrossPKPanelInfo;
}
break;
case Custom_Message_Sub_AcrossRoomPK_End:
{
[self.acrossPKCountView removeFromSuperview];
self.acrossPKCountView = nil;
[self.acrossPKPanelView resetAcrossPKViewData];
[self.acrossPKPanelView removeFromSuperview];
AcrossRoomPKPanelModel * model = [AcrossRoomPKPanelModel modelWithJSON:attachment.data];
if (attachment.data[@"amicStatus"] != nil){
model.aMicStatus = [attachment.data[@"amicStatus"] intValue];
}
if (model.isForce) {
XPAcrossRoomPKForceEndResultView *view = [[XPAcrossRoomPKForceEndResultView alloc] initWithFrame:CGRectMake(0, 0, 290, 211)];
view.data = model;
[TTPopup popupView:view style:TTPopupStyleAlert];
} else {
XPAcrossRoomPKResultView *view = [[XPAcrossRoomPKResultView alloc] initWithFrame:CGRectMake(0, 0, 310, 363)];
view.data = model;
[TTPopup popupView:view style:TTPopupStyleAlert];
}
}
break;
///个播跨房PK
case Custom_Message_Sub_AnchorPK_Invite://收到个播PK邀请
{
NIMChatroomMembersByIdsRequest *request = [[NIMChatroomMembersByIdsRequest alloc]init];
request.roomId = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.roomId];
request.userIds = @[[AccountInfoStorage instance].getUid];
[[NIMSDK sharedSDK].chatroomManager fetchChatroomMembersByIds:request completion:^(NSError * _Nullable error, NSArray<NIMChatroomMember *> * _Nullable members) {
if (error == nil) {
NIMChatroomMember * member = [members firstObject];
if (member.type == NIMChatroomMemberTypeCreator) {
XPAnchorPKInviteView * inviteView = [[XPAnchorPKInviteView alloc] init];
inviteView.roomUid = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.uid];
inviteView.dataDic = attachment.data;
[TTPopup popupView:inviteView style:TTPopupStyleAlert];
}
}
}];
}
break;
case Custom_Message_Sub_AnchorPK_Accept://对方接受个播PK邀请
{
[self.anchorPKMatchView removeFromSuperview];
NIMChatroomMembersByIdsRequest *request = [[NIMChatroomMembersByIdsRequest alloc]init];
request.roomId = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.roomId];
request.userIds = @[[AccountInfoStorage instance].getUid];
[[NIMSDK sharedSDK].chatroomManager fetchChatroomMembersByIds:request completion:^(NSError * _Nullable error, NSArray<NIMChatroomMember *> * _Nullable members) {
if (error == nil) {
NIMChatroomMember * member = [members firstObject];
if (member.type == NIMChatroomMemberTypeCreator) {
AcrossRoomPKPanelModel * acrossPKPanelInfo = [AcrossRoomPKPanelModel modelWithJSON:attachment.data];
if (attachment.data[@"amicStatus"] != nil){
acrossPKPanelInfo.aMicStatus = [attachment.data[@"amicStatus"] intValue];
}
[[RtcManager instance] connectOtherRoom:acrossPKPanelInfo.aRoomId userId:acrossPKPanelInfo.aUid];
[self updateAnchorPkInfo:acrossPKPanelInfo];
}
}
}];
}
break;
case Custom_Message_Sub_AnchorPK_Reject://对方拒绝个播PK邀请
{
NIMChatroomMembersByIdsRequest *request = [[NIMChatroomMembersByIdsRequest alloc]init];
request.roomId = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.roomId];
request.userIds = @[[AccountInfoStorage instance].getUid];
[[NIMSDK sharedSDK].chatroomManager fetchChatroomMembersByIds:request completion:^(NSError * _Nullable error, NSArray<NIMChatroomMember *> * _Nullable members) {
if (error == nil) {
NIMChatroomMember * member = [members firstObject];
if (member.type == NIMChatroomMemberTypeCreator) {
XPAcrossRoomPKInviteResultView * inviteResutView = [[XPAcrossRoomPKInviteResultView alloc] init];
inviteResutView.is_XP_Accept = NO;
[self addSubview:inviteResutView];
[inviteResutView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self).offset(114 + kSafeAreaTopHeight);
make.centerX.mas_equalTo(self);
make.size.mas_equalTo(CGSizeMake(201, 42));
}];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[inviteResutView removeFromSuperview];
});
}
}
}];
}
break;
case Custom_Message_Sub_AnchorPK_Panel://个播PK面板消息
{
[self.anchorPKMatchView removeFromSuperview];
self.delegate.getRoomInfo.pkMatchStartTime = 0;
if (!self.anchorPKPanelView.superview) {
[self addSubview:self.anchorPKPanelView];
[self.anchorPKPanelView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self);
make.top.mas_equalTo(kNavigationHeight + 87);
}];
}
AcrossRoomPKPanelModel * acrossPKPanelInfo = [AcrossRoomPKPanelModel modelWithJSON:attachment.data];
if (attachment.data[@"amicStatus"] != nil){
acrossPKPanelInfo.aMicStatus = [attachment.data[@"amicStatus"] intValue];
}
self.anchorPKPanelView.pkPanelInfo = acrossPKPanelInfo;
[self updateAnchorPkInfo:acrossPKPanelInfo];
}
break;
case Custom_Message_Sub_AnchorPK_End://个播PK结束进入惩罚阶段
{
if (!self.anchorPKPanelView.superview) {
[self addSubview:self.anchorPKPanelView];
[self.anchorPKPanelView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self);
make.top.mas_equalTo(kNavigationHeight + 87);
}];
}
AcrossRoomPKPanelModel * acrossPKPanelInfo = [AcrossRoomPKPanelModel modelWithJSON:attachment.data];
if (attachment.data[@"amicStatus"] != nil){
acrossPKPanelInfo.aMicStatus = [attachment.data[@"amicStatus"] intValue];
}
self.anchorPKPanelView.pkPanelInfo = acrossPKPanelInfo;
[self updateAnchorPkInfo:acrossPKPanelInfo];
if (acrossPKPanelInfo.isForce) {
XPAnchorPKFinishView *view = [[XPAnchorPKFinishView alloc] init];
view.data = acrossPKPanelInfo;
[TTPopup popupView:view style:TTPopupStyleAlert];
} else {
XPAnchorPKResultView *view = [[XPAnchorPKResultView alloc] initWithFrame:CGRectMake(0, 0, 300, 472)];
view.data = acrossPKPanelInfo;
[TTPopup popupView:view style:TTPopupStyleAlert];
}
}
break;
case Custom_Message_Sub_AnchorPK_Finish://个播PK完成
{
[self.anchorPKPanelView resetAcrossPKViewData];
[self.anchorPKPanelView removeFromSuperview];
self.anchorPKPanelView = nil;
[self resetAnchorPkInfo];
[[RtcManager instance] disconnectOtherRoom];
}
break;
case Custom_Message_Sub_PK_BeginTime:{
long long time = [attachment.data[@"beginTime"] longLongValue];
[self showAcrossPkCountDownViewWithTime:time];
}
break;
case Custom_Message_Sub_AnchorPK_Match_TimeOut:
{///PK匹配超时
self.delegate.getRoomInfo.pkMatchStartTime = 0;
self.anchorPKMatchView.roomUid = [NSString stringWithFormat:@"%ld", [self.delegate getRoomInfo].uid];
[self.anchorPKMatchView handleMatchTimeOutMessage];
}
break;
case Custom_Message_Sub_AnchorPK_MuteOtherMic:///PK时禁用对方声音
{
[self.anchorPKPanelView updateOtherMicStatus:attachment];
}
break;
default:
break;
}
} else if (attachment.first == CustomMessageType_Anchor_FansTeam) {
[self handleAnchorFansTeam:attachment];
}else if (attachment.first == CustomMessageType_Noble_VIP && attachment.second == Custom_Message_Sub_Room_Trumpet) {
[self handleTrumpet:attachment];
}
}
}
- (void)handleNIMNotificationMessage:(NIMMessage *)message {
NIMNotificationObject *notiMsg = (NIMNotificationObject *)message.messageObject;
NIMChatroomNotificationContent *content = (NIMChatroomNotificationContent *)notiMsg.content;
// [self updateContributeEnterViewTitle:attachment];
switch (content.eventType) {
case NIMChatroomEventTypeAddManager:
{
for (NIMChatroomNotificationMember * member in content.targets) {
if (member.userId.intValue == [AccountInfoStorage instance].getUid.integerValue) {
// self.editButton.hidden = NO;
self.pkPanelView.isManager = YES;
break;
}
}
}
break;
case NIMChatroomEventTypeRemoveManager:
{
for (NIMChatroomNotificationMember * member in content.targets) {
if (member.userId.intValue == [AccountInfoStorage instance].getUid.integerValue) {
// self.editButton.hidden = YES;
self.pkPanelView.isManager = NO;
break;
}
}
}
break;
default:
break;
}
}
- (void)onMicroQueueUpdate:(NSMutableDictionary<NSString *,MicroQueueModel *> *)queue {
if (self.delegate.getRoomInfo.type == RoomType_MiniGame) {
[self.littleGameMiniView needRefreshPosition:queue];
} else if(self.delegate.getRoomInfo.roomModeType == RoomModeType_Open_PK_Mode) {
self.pkPanelView.micQueue = queue;
}else {
MicroQueueModel * currentUserModel;
NSString * uid = [AccountInfoStorage instance].getUid;
for (MicroQueueModel * microModel in queue.allValues) {
if (microModel.userInfo && microModel.userInfo.uid == uid.integerValue) {
currentUserModel = microModel;
}
}
if (currentUserModel) {
self.musicEnterButton.hidden = NO;
} else {
[[RtcManager instance] changePlayState:BackMusicPlayState_Stop];
self.musicEnterButton.hidden = YES;
POPBasicAnimation *moveAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPViewCenter];
moveAnimation.fromValue = [NSValue valueWithCGPoint:self.musicPlayView.center];
moveAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(-KScreenWidth, self.musicPlayView.center.y)];
moveAnimation.beginTime = CACurrentMediaTime();
moveAnimation.duration = 0.5;
moveAnimation.repeatCount = 1;
moveAnimation.removedOnCompletion = YES;
[self.musicPlayView pop_addAnimation:moveAnimation forKey:@"moveOutAnimation"];
[self.musicPlayView resetData];
[self.musicPlayView removeFromSuperview];
}
}
}
#pragma mark - XPAcrossRoomPKPanelViewDelegate
- (void)XPAcrossRoomPKPanelView:(XPAcrossRoomPKPanelView *)view onLookRoom:(NSString *)roomUid {
[self.delegate exitRoom];
///这个为啥加个延迟的 因为会先退房 有一个dismiss的动画 所以加个延迟吧
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[XPRoomViewController openRoom:roomUid viewController:[XCCurrentVCStackManager shareManager].getCurrentVC];
});
}
- (void)XPAcrossRoomPKPanelView:(XPAcrossRoomPKPanelView *)view sendGiftToUser:(NSString *)uid {
NSString * roomUid = [NSString stringWithFormat:@"%ld", [self.delegate getRoomInfo].uid];
XPSendGiftView * giftView = [[XPSendGiftView alloc] initWithType:SendGiftType_Room uid:roomUid];
giftView.delegate = self.delegate;
NSArray * giftUses = [self configGiftUsers:[self.delegate getMicroQueue]];
[giftView configGiftUsers:giftUses];
[self.delegate.getCurrentNav presentViewController:giftView animated:YES completion:nil];
}
- (NSArray<XPGiftUserInfoModel *> *)configGiftUsers:(NSMutableDictionary<NSString *,MicroQueueModel *> *)queue {
NSMutableArray * array = [NSMutableArray array];
for (MicroQueueModel * microModel in queue.allValues) {
if (microModel.userInfo && microModel.userInfo.uid >0) {
UserInfoModel * userInfo = microModel.userInfo;
XPGiftUserInfoModel * userModel = [[XPGiftUserInfoModel alloc] init];
userModel.avatar = userInfo.avatar;
userModel.vipMic = userInfo.vipMic;
userModel.position = [NSString stringWithFormat:@"%d", microModel.microState.position];
userModel.uid = userInfo.uid;
if (self.delegate.getRoomInfo.type == RoomType_Anchor && microModel.microState.position == -1) {///个播房一直为离开模式,不需要添加房主位
continue;
}
[array addObject:userModel];
}
}
if (self.delegate.getRoomInfo.leaveMode) {
RoomInfoModel * roomInfo= self.delegate.getRoomInfo;
XPGiftUserInfoModel * userModel = [[XPGiftUserInfoModel alloc] init];
userModel.avatar = roomInfo.avatar;
userModel.position = @"-1";
userModel.uid = roomInfo.uid;
[array addObject:userModel];
} else if (self.delegate.getRoomInfo.type == RoomType_Anchor) {
RoomInfoModel * roomInfo= self.delegate.getRoomInfo;
BOOL hadContainerOwner = NO;
for (UserInfoModel *userModel in array) {
if (userModel.uid == roomInfo.uid) {
hadContainerOwner = YES;
break;
}
}
if (!hadContainerOwner) {
XPGiftUserInfoModel * userModel = [[XPGiftUserInfoModel alloc] init];
userModel.avatar = roomInfo.avatar;
userModel.position = @"-1";
userModel.uid = roomInfo.uid;
[array addObject:userModel];
}
}
return array;
}
- (void)XPAcrossRoomPKPanelView:(XPAcrossRoomPKPanelView *)view showUserCard:(NSString *)uid {
RoomInfoModel * roomInfo = self.delegate.getRoomInfo;
NSString * targetUid = uid;
XPUserCardInfoModel * model = [[XPUserCardInfoModel alloc] init];
__block MicroQueueModel *micModel = nil;
[[self.delegate.getMicroQueue allValues] enumerateObjectsUsingBlock:^(MicroQueueModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (targetUid.integerValue == obj.userInfo.uid) {
model.position = [NSString stringWithFormat:@"%d", obj.microState.position];
model.posState = obj.microState.posState;
model.micState = obj.microState.micState;
micModel = obj;
*stop = YES;
}
}];
model.nick = self.delegate.getUserInfo.nick;
model.uid = targetUid;
model.delegate = self.delegate;
model.roomInfo = roomInfo;
model.micQueue = self.delegate.getMicroQueue;
model.superMangerList = self.delegate.getRoomSuperAdminList;
model.platformRole = micModel.userInfo.platformRole;
UserRoomCardViewController *vc = [[UserRoomCardViewController alloc] initWithUser:model controlUser:self.delegate.getUserInfo];
vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
[self.delegate.getCurrentNav presentViewController:vc animated:NO completion:nil];
}
#pragma mark - XPAnchorPkPanelViewDelegate
- (void)xPAnchorPKPanelView:(XPAnchorPkPanelView *)view showUserCard:(NSString *)uid {
XPMineUserInfoViewController * userInfoVC = [[XPMineUserInfoViewController alloc] init];
userInfoVC.uid = uid.integerValue;
[self.delegate.getCurrentNav pushViewController:userInfoVC animated:YES];
}
///去房间
- (void)xPAnchorPKPanelView:(XPAnchorPkPanelView *)view onlookRoom:(NSString *)roomUid {
[self.delegate exitRoom];
///这个为啥加个延迟的 因为会先退房 有一个dismiss的动画 所以加个延迟吧
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[XPRoomViewController openRoom:roomUid viewController:[XCCurrentVCStackManager shareManager].getCurrentVC];
});
}
///关注房主成功
- (void)xPAnchorPKPanelViewAttentionSuccess {
if (self.followAnchorTimer != nil) {
dispatch_source_cancel(self.followAnchorTimer);
self.followAnchorTimer = nil;
}
}
- (void)xPAnchorPKPanelViewPenaltyCountDownEnd {
self.delegate.getRoomInfo.pkState = AcrossRoomPkStateTypePenaltyEnd;
}
#pragma mark - XPRoomBackMusicPlayerViewDelegate
- (void)xPRoomBackMusicPlayerView:(XPRoomBackMusicPlayerView *)view musicPlaying:(BOOL)musicPlaying {
if (musicPlaying) {
[self resumeLayer:self.musicEnterButton.imageView.layer];
} else {
[self pauseLayer:self.musicEnterButton.imageView.layer];
}
}
#pragma mark - Event Response
- (void)contributionButtonAction:(UITapGestureRecognizer *)tap {
NSString * roomUid = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.uid];
XPRoomHalfWebView * webView = [[XPRoomHalfWebView alloc] init];
webView.url = [NSString stringWithFormat:@"%@?roomUid=%@", URLWithType(kRoomRankURL), roomUid];
[TTPopup popupView:webView style:TTPopupStyleActionSheet];
if (self.delegate.getRoomInfo.type == RoomType_Anchor) {//点击的时候更新一下
[self updateContrionEntranceWithRoomUid:roomUid type:@"month"];
} else {
[self updateContrionEntranceWithRoomUid:roomUid type:@"day"];
}
}
- (void)onAnchorHourRankButtonAction:(UITapGestureRecognizer *)ges {
NSString * roomUid = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.uid];
NSString * url = self.delegate.getRoomInfo.type == RoomType_Anchor ? URLWithType(kRoomHourRankURL) : URLWithType(kLicenseHourRankURL);
XPRoomHalfWebView * webView = [[XPRoomHalfWebView alloc] init];
webView.url = [NSString stringWithFormat:@"%@?roomUid=%@", url, roomUid];
[TTPopup popupView:webView style:TTPopupStyleActionSheet];
}
- (void)datingProgresButtonAction:(UIButton *)sender {
[TTPopup dismiss];
RoomInfoModel * roomInfo = self.delegate.getRoomInfo;
NSString * message = @"";
if (roomInfo.blindDateState == RoomPlayDateingType_Talk) {
message = YMLocalizedString(@"XPRoomFunctionContainerView8");
} else if(roomInfo.blindDateState == RoomPlayDateingType_Pick) {
message =YMLocalizedString(@"XPRoomFunctionContainerView9");
} else if(roomInfo.blindDateState == RoomPlayDateingType_Result) {
message = YMLocalizedString(@"XPRoomFunctionContainerView10");
} else if (roomInfo.blindDateState == RoomPlayDateingType_Finish) {
message =YMLocalizedString(@"XPRoomFunctionContainerView11");
}
TTAlertConfig * config = [[TTAlertConfig alloc] init];
config.message = message;
[TTPopup alertWithConfig:config confirmHandler:^{
NSString * roomUid = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.uid];
NSString * roundId = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.blindDateState];
[Api changeRoomDatingState:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200) {
} else {
[XNDJTDDLoadingTool showErrorWithMessage:msg];
}
} roomUserId:roomUid roundId:roundId];
} cancelHandler:^{
}];
}
- (void)foldButtonAction:(UIButton *)sender {
sender.selected = !sender.selected;
}
- (void)tapFansTeamRecognizer {
NSString *roomUid = [NSString stringWithFormat:@"%zd", self.delegate.getRoomInfo.uid];
if (self.relationFansModel.isCurrentRoomAnchor) {///是房主
if (self.relationFansModel.hasFansTeamCurrentRoom) {
XPRoomHalfWebView * webView = [[XPRoomHalfWebView alloc] init];
webView.url = [NSString stringWithFormat:@"%@?roomUid=%@", URLWithType(kAnchorFansListURL), roomUid];
[TTPopup popupView:webView style:TTPopupStyleActionSheet];
} else {
XPWebViewController * webVC =[[XPWebViewController alloc] initWithRoomUID:roomUid];
webVC.url = URLWithType(kAnchorFansOpenURL);
[self.delegate.getCurrentNav pushViewController:webVC animated:YES];
}
} else {
if (self.relationFansModel.hasFansTeamCurrentRoom) {//开通了粉丝团
if (self.relationFansModel.isAnchorFans) {
[Api requestFansTeamTask:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code != 200) {
[XNDJTDDLoadingTool showErrorWithMessage:msg];
return;
}
XPAnchorFansTaskModel *model = [XPAnchorFansTaskModel modelWithJSON:data.data];
XPAnchorFansTaskViewController *fansTaskVc = [[XPAnchorFansTaskViewController alloc] initWithRoomUid:roomUid];
fansTaskVc.model = model;
[self.delegate.getCurrentNav presentViewController:fansTaskVc animated:YES completion:nil];
} teamUid:roomUid];
} else {
[Api requestJoinFansTeam:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code != 200) {
[XNDJTDDLoadingTool showErrorWithMessage:msg];
return;
}
XPAnchorFansJoinModel *model = [XPAnchorFansJoinModel modelWithJSON:data.data];
XPAnchorFansTeamViewController *fansTeamVc = [[XPAnchorFansTeamViewController alloc] initWithRoomUid:roomUid];
fansTeamVc.model = model;
[self.delegate.getCurrentNav presentViewController:fansTeamVc animated:YES completion:nil];
} teamUid:roomUid];
}
}
}
}
- (void)musicEnterButtonAction:(UIButton *)sender {
[self showMusicPanel];
// if (!self.musicPlayView.superview) {
// [self addSubview:self.musicPlayView];
// self.musicPlayView.frame = CGRectMake(-KScreenWidth, kNavigationHeight + 4, KScreenWidth - 85, 80);
// }
}
#pragma mark - 房间话题
- (void)updateRoomTopicViewConstraint {
// self.topicStackView.hidden = YES;
// RoomInfoModel * roomInfo = self.delegate.getRoomInfo;
// CGFloat offsetY = kNavigationHeight;
// if (roomInfo.roomModeType == RoomModeType_Open_Blind) {
// offsetY += ((50 + 5) * kScreenScale + 10 + 12 + 3 + 40);
// } else if (roomInfo.type == RoomType_Anchor) {
// self.topicStackView.hidden = NO;
// offsetY += (120 + 5 + 6 + 20 +60 + 3);
// } else {
// offsetY += (50 + 5 + 10 + 12 + 3 + 40);
// }
//
// [self.topicStackView mas_updateConstraints:^(MASConstraintMaker *make) {
// make.top.mas_equalTo(offsetY);
// }];
}
- (void)updateRoomTopic {
// if (self.delegate.getRoomInfo.type == RoomType_Anchor && self.delegate.getRoomInfo.roomModeType == RoomModeType_Open_AcrossRoomPK_mode) {
// self.topicStackView.hidden = YES;
// } else {
// self.topicStackView.hidden = ([ClientConfig shareConfig].configInfo.appStoreAuditNoticeVersion || self.delegate.getRoomInfo.type == RoomType_MiniGame) == YES;
// }
// [self updateRoomTopicViewConstraint];
// if ([AccountInfoStorage instance].getUid.length > 0) {
// NIMChatroomMembersByIdsRequest *request = [[NIMChatroomMembersByIdsRequest alloc]init];
// request.roomId = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.roomId];
// request.userIds = @[[AccountInfoStorage instance].getUid];
// [[NIMSDK sharedSDK].chatroomManager fetchChatroomMembersByIds:request completion:^(NSError * _Nullable error, NSArray<NIMChatroomMember *> * _Nullable members) {
// if (error== nil) {
// NIMChatroomMember* member = members.firstObject;
// if (member.type == NIMChatroomMemberTypeCreator || member.type == NIMChatroomMemberTypeManager) {
// self.editButton.hidden = NO;
// } else {
// self.editButton.hidden = YES;
// }
// }
// }];
// }
// self.topicLabel.text = self.delegate.getRoomInfo.roomDesc.length > 0 ? self.delegate.getRoomInfo.roomDesc : YMLocalizedString(@"XPRoomFunctionContainerView12");
}
- (void)topicGestureRecognizer:(UITapGestureRecognizer *)tap {
NIMChatroomMembersByIdsRequest *request = [[NIMChatroomMembersByIdsRequest alloc]init];
request.roomId = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.roomId];
request.userIds = @[[AccountInfoStorage instance].getUid];
[[NIMSDK sharedSDK].chatroomManager fetchChatroomMembersByIds:request completion:^(NSError * _Nullable error, NSArray<NIMChatroomMember *> * _Nullable members) {
if (error== nil) {
NIMChatroomMember* member = members.firstObject;
RoomInfoModel * roomInfo= self.delegate.getRoomInfo;
if (member.type == NIMChatroomMemberTypeCreator || member.type == NIMChatroomMemberTypeManager) {
XPRoomTopicViewController * editTopicVC = [[XPRoomTopicViewController alloc] init];
editTopicVC.roomInfo = roomInfo;
[self.delegate.getCurrentNav pushViewController:editTopicVC animated:YES];
} else {
TTPopupService * config = [[TTPopupService alloc] init];
XPRoomTopicAlertView * alertView = [[XPRoomTopicAlertView alloc] init];
alertView.title = roomInfo.roomDesc;
alertView.message = roomInfo.introduction;
config.contentView = alertView;
[TTPopup popupWithConfig:config];
}
}
}];
}
#pragma mark - 弹窗关注房主
- (void)setFollowAnchorTimer {
if (self.followAnchorTimer != nil) {
dispatch_source_cancel(self.followAnchorTimer);
}
#ifdef DEBUG
NSInteger totalTime = 5;
NSString *isProduction = [[NSUserDefaults standardUserDefaults]valueForKey:@"kIsProductionEnvironment"];
if([isProduction isEqualToString:@"YES"]){
totalTime = 420;
}
#else
NSInteger totalTime = 420;
#endif
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
self.followAnchorTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
dispatch_source_set_timer(self.followAnchorTimer,dispatch_walltime(NULL, totalTime*NSEC_PER_SEC), totalTime*NSEC_PER_SEC, 0); //每秒执行
@weakify(self);
dispatch_source_set_event_handler(self.followAnchorTimer, ^{
dispatch_async(dispatch_get_main_queue(), ^{
@strongify(self);
if (self.followAnchorTimer != nil) {
dispatch_source_cancel(self.followAnchorTimer);
self.followAnchorTimer = nil;
}
RoomInfoModel* roomInfo = self.delegate.getRoomInfo;
NSString *roomUid = [NSString stringWithFormat:@"%zd", roomInfo.uid];
NSString * uid = [[AccountInfoStorage instance] getUid];
[Api attentionStatusCompletion:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
BOOL isLike = ((NSNumber *)data.data).boolValue;
if (!isLike && !roomInfo.isRoomFans && self.window) { // 还没有关注或收藏房间
[self showFollowAnchorView];
}
} uid:uid isLikeUid:roomUid];
});
});
dispatch_resume(self.followAnchorTimer);
}
//弹出关注主播的窗口
- (void)showFollowAnchorView {
RoomInfoModel* roomInfo = self.delegate.getRoomInfo;
NSString *roomUid = [NSString stringWithFormat:@"%zd", roomInfo.uid];
[Api getUserInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
UserInfoModel *userInfo = [UserInfoModel modelWithDictionary:data.data];
XPRoomAnchorInfoCardView *view = [[XPRoomAnchorInfoCardView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 300)];
view.userInfo = self.delegate.getUserInfo;
view.targetUserInfo = userInfo;
view.roomId =roomInfo.roomId;
[TTPopup popupView:view style:TTPopupStyleActionSheet];
} uid:roomUid];
}
///个播房用户请求上麦弹窗
- (void)showAskForUpMic:(NSDictionary *)dict {
NSString *roomUid = [NSString stringWithFormat:@"%zd", self.delegate.getRoomInfo.uid];
if (![roomUid isEqualToString:[AccountInfoStorage instance].getUid]) {
return;
}
UserInfoModel *model = [UserInfoModel modelWithJSON:dict];
XPAnchorAudienceUpMicView *upMicView = [[XPAnchorAudienceUpMicView alloc] initWithFrame:CGRectMake(0, 0, 300, 226) delegate:self.delegate];
upMicView.info = model;
TTPopupConfig *config = [[TTPopupConfig alloc] init];
config.filterIdentifier = @"audienceRequestUpMic";
config.shouldFilterPopup = YES;
config.contentView = upMicView;
config.style = TTPopupStyleAlert;
[TTPopup popupWithConfig:config];
}
#pragma mark - 个播粉丝团
- (void)updateFansTeamEntranceView:(XPAnchorFansRelationModel *)model {
if (!self.fansTeamEntranceView.superview) {
[self insertSubview:self.fansTeamEntranceView atIndex:0];
[self.fansTeamEntranceView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.rankStackView.mas_bottom).mas_offset(5);
make.leading.mas_equalTo(0);
make.height.mas_equalTo(37);
}];
}
self.fansTeamEntranceView.model = model;
self.relationFansModel = model;
}
- (void)handleAnchorFansTeam:(AttachmentModel *)attachment {
if (attachment.second == Custom_Message_Sub_FansTeam_Open_Success || attachment.second == Custom_Message_Sub_FansTeam_Join_Success || attachment.second == Custom_Message_Sub_FansTeam_Out_Success) {
NSString *roomUid = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.uid];
NSString *uid;
if ([attachment.data[@"uid"] isKindOfClass:[NSNumber class]]) {
uid = [NSString stringWithFormat:@"%@", attachment.data[@"uid"]];
} else if ([attachment.data[@"uid"] isKindOfClass:[NSString class]]) {
uid = attachment.data[@"uid"];
}
if ([uid isEqualToString:[AccountInfoStorage instance].getUid] || [[AccountInfoStorage instance].getUid isEqualToString:roomUid]) {
[Api requestInRoomFansTeam:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
XPAnchorFansRelationModel *model = [XPAnchorFansRelationModel modelWithJSON:data.data];
[self updateFansTeamEntranceView:model];
} teamUid:roomUid];
}
} else if (attachment.second == Custom_Message_Sub_FansTeam_Open_Fail) {
}
}
- (void)updateAnchorPkInfo:(AcrossRoomPKPanelModel *)acrossPKPanelInfo {
self.delegate.getRoomInfo.roundId = acrossPKPanelInfo.roundId;
self.delegate.getRoomInfo.pkUid = acrossPKPanelInfo.aUid;
self.delegate.getRoomInfo.pkRoomId = acrossPKPanelInfo.aRoomId;
self.delegate.getRoomInfo.pkState = acrossPKPanelInfo.pkState;
self.delegate.getRoomInfo.winUid = acrossPKPanelInfo.winUid;
}
- (void)resetAnchorPkInfo {
self.delegate.getRoomInfo.roundId = 0;
self.delegate.getRoomInfo.pkUid = @"";
self.delegate.getRoomInfo.pkRoomId = @"";
self.delegate.getRoomInfo.pkState = AcrossRoomPkStateTypePkEnd;
self.delegate.getRoomInfo.winUid = @"";
self.delegate.getRoomInfo.pkMatchStartTime = 0;
}
#pragma mark - 房间VIP小喇叭
- (void)handleTrumpet:(AttachmentModel *)attachment {
if (self.trumpetQueue.count) {
[self.trumpetQueue addObject:attachment.data];
} else {
[self.trumpetQueue addObject:attachment.data];
__block NSInteger time = 5.0; //倒计时时间
if (_trumpetTimer == nil) {
dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
_trumpetTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
dispatch_source_set_timer(_trumpetTimer,dispatch_walltime(NULL, 0), time*NSEC_PER_SEC, 0); //每秒执行
@weakify(self);
dispatch_source_set_event_handler(_trumpetTimer, ^{
@strongify(self);
if (self.trumpetQueue.count) {
dispatch_sync(dispatch_get_main_queue(), ^{
[self createTrumpetAnimation:self.trumpetQueue.firstObject];
[self.trumpetQueue xpSafeRemoveObjectAtIndex:0];
});
} else {
dispatch_sync(dispatch_get_main_queue(), ^{
[self.trumpetView removeFromSuperview];
});
if (self.trumpetTimer != nil) {
dispatch_source_cancel(self.trumpetTimer);
self.trumpetTimer = nil;
}
}
});
dispatch_resume(_trumpetTimer);
}
}
}
- (void)createTrumpetAnimation:(NSDictionary *)attatchment {
if (!self.trumpetView.superview) {
[self addSubview:self.trumpetView];
[self.trumpetView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.delegate.getRoomInfo.type == RoomType_MiniGame ? kNavigationHeight: kNavigationHeight + 110);
make.leading.mas_equalTo(0);
make.trailing.mas_equalTo(0);
make.height.mas_equalTo(153);
}];
}
self.trumpetView.data = attatchment;
POPBasicAnimation *animation2 = [POPBasicAnimation animationWithPropertyNamed:kPOPViewFrame];
animation2.beginTime = CACurrentMediaTime();
animation2.duration = 0.1;
CGFloat width = self.frame.size.width - 15;
CGFloat height = 28;
animation2.fromValue = [NSValue valueWithCGRect:CGRectMake(0, 153-34-28, width, height)];
animation2.toValue = [NSValue valueWithCGRect:CGRectMake(0, 153-34-28-14, width, height)];
animation2.removedOnCompletion = NO;
animation2.repeatCount = 1;
POPBasicAnimation *animation3 = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerOpacity];
animation3.duration = 0.1;
animation3.beginTime = CACurrentMediaTime();
animation3.fromValue = @1;
animation3.toValue = @0;
animation3.repeatCount = 1;
animation3.removedOnCompletion = NO;
[animation2 setCompletionBlock:^(POPAnimation *anim, BOOL finished) {
if (finished) {
POPBasicAnimation *animation2 = [POPBasicAnimation animationWithPropertyNamed:kPOPViewFrame];
animation2.beginTime = CACurrentMediaTime();
animation2.duration = 0.1;
CGFloat width = self.frame.size.width - 15;
CGFloat height = 28;
animation2.fromValue = [NSValue valueWithCGRect:CGRectMake(0, 153 - 34 - 14, width, height)];
animation2.toValue = [NSValue valueWithCGRect:CGRectMake(0, 153 - 34 - 28, width, height)];
animation2.removedOnCompletion = NO;
animation2.repeatCount = 1;
POPBasicAnimation *animation3 = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerOpacity];
animation3.duration = 0.1;
animation3.beginTime = CACurrentMediaTime();
animation3.fromValue = @0;
animation3.toValue = @1;
animation3.repeatCount = 1;
animation3.removedOnCompletion = NO;
[self.trumpetView.mainView.layer pop_addAnimation:animation2 forKey:@"animation4"];
[self.trumpetView.mainView.layer pop_addAnimation:animation3 forKey:@"animation5"];
}
}];
[self.trumpetView.mainView.layer pop_addAnimation:animation2 forKey:@"animation2"];
[self.trumpetView.mainView.layer pop_addAnimation:animation3 forKey:@"animation3"];
}
#pragma mark - 房间榜入口榜单
- (void)updateContrionEntranceWithRoomUid:(NSString *)roomUid type:(NSString *)type {
}
#pragma mark - 个播小时榜入口
- (void)updateHourRankEntrance {
if (self.delegate.getRoomInfo.type == RoomType_Anchor || self.delegate.getRoomInfo.isPermitRoom == PermitRoomType_License) {
self.hourRankEntranceView.hidden = NO;
} else {
self.hourRankEntranceView.hidden = YES;
}
}
#pragma mark - XPRoomLittleGameListViewDelegate
- (void)xPRoomLittleGameListView:(XPLittleGameRoomListView *)view didSelectItem:(LittleGameInfoModel *)itemInfo {
RoomInfoModel * roomInfo = self.delegate.getRoomInfo;
NSMutableDictionary * params = [NSMutableDictionary dictionary];
NSString * uid = [AccountInfoStorage instance].getUid;
NSString * ticket = [AccountInfoStorage instance].getTicket;
[params setObject:ticket forKey:@"ticket"];
[params setObject:uid forKey:@"uid"];
[params setObject:[NSString stringWithFormat:@"%ld", roomInfo.uid] forKey:@"roomUid"];
if (roomInfo.title.length > 0) {
[params setObject:roomInfo.title forKey:@"title"];
}
if (roomInfo.roomPwd.length > 0) {
[params setObject:roomInfo.roomPwd forKey:@"roomPwd"];
} else{
[params setObject:@"" forKey:@"roomPwd"];
}
if (roomInfo.tagId > 0) {
[params setObject:[NSString stringWithFormat:@"%ld", roomInfo.tagId] forKey:@"tagId"];
}
if ([itemInfo.mgId isEqualToString:@"0"]) {
[params setObject:@(RoomType_Game) forKey:@"type"];
[params setObject:@"0" forKey:@"mgId"];
} else {
[params setObject:@(RoomType_MiniGame) forKey:@"type"];
[params setObject:itemInfo.mgId forKey:@"mgId"];
}
[params setObject:@(roomInfo.hasAnimationEffect) forKey:@"hasAnimationEffect"];
[Api ownerUpdateRoomInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200) {
} else {
[XNDJTDDLoadingTool showErrorWithMessage:msg];
}
} params:params];
}
- (void)xPRoomLittleGameListView:(XPLittleGameRoomListView *)view didSelectChooseType:(UIButton *)sender {
if ([self currentRoomIsInSudGame]) {
[XNDJTDDLoadingTool showErrorWithMessage:YMLocalizedString(@"XPRoomFunctionContainerView18")];
} else {
sender.selected = !sender.selected;
view.tableView.hidden = !sender.selected;
}
}
#pragma mark - 房间背景音乐
-(void)pauseLayer:(CALayer*)layer {
CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];
layer.speed = 0.0;
layer.timeOffset = pausedTime;
}
-(void)resumeLayer:(CALayer*)layer {
CFTimeInterval pausedTime = [layer timeOffset];
layer.speed = 1.0;
layer.timeOffset = 0.0;
layer.beginTime = 0.0;
CFTimeInterval timeSincePause = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;
layer.beginTime = timeSincePause;
}
- (void)configPlayMusicRoomTypeChange {
RoomInfoModel * roomInfo = self.delegate.getRoomInfo;
if (roomInfo.type == RoomType_MiniGame) {
[self pauseLayer:self.musicEnterButton.imageView.layer];
[self.musicEnterButton removeFromSuperview];
[self.musicPlayView resetData];
[self.musicPlayView removeFromSuperview];
[[RtcManager instance] changePlayState:BackMusicPlayState_Stop];
} else {
MicroQueueModel * currentUserModel;
NSString * uid = [AccountInfoStorage instance].getUid;
for (MicroQueueModel * microModel in self.delegate.getMicroQueue.allValues) {
if (microModel.userInfo && microModel.userInfo.uid == uid.integerValue) {
currentUserModel = microModel;
}
}
if (currentUserModel) {
self.musicEnterButton.hidden = NO;
}
}
}
///跨房PK预约倒计时
- (void)showAcrossPkCountDownViewWithTime:(long long)time {
if (self.acrossPKCountView.superview) {
return;
}
if (self.acrossPKPanelView.superview) {//正在PK中
return;
}
if ([self.delegate getRoomInfo].roomModeType == RoomModeType_Open_AcrossRoomPK_mode) {
return;
}
[self handleAcrollPKCountView:time];
}
- (void)handleAcrollPKCountView:(long long)time {
RoomInfoModel * roomInfo = self.delegate.getRoomInfo;
if (!self.acrossPKCountView.superview) {
[self addSubview:self.acrossPKCountView];
[self bringSubviewToFront:self.acrossPKCountView];
self.acrossPKCountView.startTime = time ? time : roomInfo.pkBeginTime;
self.acrossPKCountView.backImageView.image = [UIImage imageNamed:@"acrossPK_countDown_left_bg"];
[self.acrossPKCountView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kNavigationHeight+4+24+4);
make.leading.mas_equalTo(0);
make.width.height.mas_equalTo(52);
}];
}
}
#pragma mark - 随机PK匹配
- (void)handleMatchAnchorPK {
if (self.delegate.getRoomInfo.pkMatchStartTime) {
[self addSubview:self.anchorPKMatchView];
self.anchorPKMatchView.roomUid = [NSString stringWithFormat:@"%ld", [self.delegate getRoomInfo].uid];
[self.anchorPKMatchView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.rankStackView.mas_bottom).mas_offset(5+37+5);
make.leading.mas_equalTo(0);
make.width.height.mas_equalTo(52);
}];
[self.anchorPKMatchView openCountdownWithTime:self.delegate.getRoomInfo.pkMatchStartTime];
}
}
#pragma mark - Getters And Setters
- (XPRoomRankEntranceView *)contributeEnterView {
if (!_contributeEnterView) {
_contributeEnterView = [[XPRoomRankEntranceView alloc] init];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(contributionButtonAction:)];
[_contributeEnterView addGestureRecognizer:tap];
}
return _contributeEnterView;
}
- (XPRoomAnchorRankEnterView *)hourRankEntranceView {
if (!_hourRankEntranceView) {
_hourRankEntranceView = [[XPRoomAnchorRankEnterView alloc] init];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onAnchorHourRankButtonAction:)];
[_hourRankEntranceView addGestureRecognizer:tap];
}
return _hourRankEntranceView;
}
- (UIButton *)datingProgresButton {
if (!_datingProgresButton) {
_datingProgresButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_datingProgresButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[UIColorFromRGB(0xFA7186), UIColorFromRGB(0xFA4972)] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(65, 30)] forState:UIControlStateNormal];
[_datingProgresButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_datingProgresButton.titleLabel.font = [UIFont systemFontOfSize:13];
[_datingProgresButton setTitle:YMLocalizedString(@"XPRoomFunctionContainerView13") forState:UIControlStateNormal];
[_datingProgresButton addTarget:self action:@selector(datingProgresButtonAction:) forControlEvents:UIControlEventTouchUpInside];
_datingProgresButton.layer.masksToBounds = YES;
_datingProgresButton.layer.cornerRadius = 15;
}
return _datingProgresButton;
}
- (XPAnchorFansTeamEntranceView *)fansTeamEntranceView {
if (!_fansTeamEntranceView) {
_fansTeamEntranceView = [[XPAnchorFansTeamEntranceView alloc]init];
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapFansTeamRecognizer)];
[_fansTeamEntranceView addGestureRecognizer:tap];
}
return _fansTeamEntranceView;
}
- (UIStackView *)rankStackView{
if(!_rankStackView){
_rankStackView = [[UIStackView alloc] init];
_rankStackView.axis = UILayoutConstraintAxisHorizontal;
_rankStackView.distribution = UIStackViewDistributionFill;
_rankStackView.alignment = UIStackViewAlignmentFill;
_rankStackView.spacing = 9;
}
return _rankStackView;
}
- (XPAcrossRoomPKPanelView *)acrossPKPanelView {
if (!_acrossPKPanelView) {
_acrossPKPanelView = [[XPAcrossRoomPKPanelView alloc] init];
_acrossPKPanelView.delegate = self;
}
return _acrossPKPanelView;
}
- (XPLittleGameMiniStageView *)littleGameMiniView {
if (!_littleGameMiniView) {
_littleGameMiniView = [[XPLittleGameMiniStageView alloc] init];
}
return _littleGameMiniView;
}
- (XPLittleGameRoomListView *)gameListView {
if (!_gameListView) {
_gameListView = [[XPLittleGameRoomListView alloc] init];
_gameListView.delegate = self;
}
return _gameListView;
}
- (XPAnchorPkPanelView *)anchorPKPanelView {
if (!_anchorPKPanelView) {
_anchorPKPanelView = [[XPAnchorPkPanelView alloc] init];
_anchorPKPanelView.delegate = self;
}
return _anchorPKPanelView;
}
- (UIButton *)musicEnterButton {
if (!_musicEnterButton) {
_musicEnterButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_musicEnterButton setImage:[UIImage imageNamed:@"room_music_player_enter"] forState:UIControlStateNormal];
_musicEnterButton.layer.masksToBounds = YES;
_musicEnterButton.layer.cornerRadius = 27/2;
_musicEnterButton.backgroundColor = UIColorRGBAlpha(0xffffff, 0.2);
[_musicEnterButton addTarget:self action:@selector(musicEnterButtonAction:) forControlEvents:UIControlEventTouchUpInside];
CAKeyframeAnimation *lAni = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"];
lAni.duration = 1.5;
lAni.repeatCount = HUGE;
lAni.values=@[@0,@(M_PI*2)];
//使得动画结束后,保持动画效果
lAni.removedOnCompletion = NO;
lAni.fillMode = kCAFillModeForwards;
[_musicEnterButton.layer addAnimation:lAni forKey:nil];
}
return _musicEnterButton;
}
- (XPRoomBackMusicPlayerView *)musicPlayView {
if (!_musicPlayView) {
_musicPlayView = [[XPRoomBackMusicPlayerView alloc] init];
_musicPlayView.delegate = self;
}
return _musicPlayView;
}
- (XPRoomPKPanelView *)pkPanelView {
if (!_pkPanelView) {
_pkPanelView = [[XPRoomPKPanelView alloc] init];
}
return _pkPanelView;
}
- (XPAcrossRoomPKCountDownView *)acrossPKCountView {
if (!_acrossPKCountView) {
_acrossPKCountView = [[XPAcrossRoomPKCountDownView alloc] initWithFrame:CGRectMake(-52, kNavigationHeight+4+24+4, 52, 52)];
}
return _acrossPKCountView;
}
- (XPAnchorPKMatchView *)anchorPKMatchView {
if (!_anchorPKMatchView) {
_anchorPKMatchView = [[XPAnchorPKMatchView alloc] initWithDelegate:self.delegate];
}
return _anchorPKMatchView;
}
- (XPRoomTrumpetView *)trumpetView {
if (!_trumpetView) {
_trumpetView = [[XPRoomTrumpetView alloc] init];
}
return _trumpetView;
}
- (NSMutableArray *)trumpetQueue {
if (!_trumpetQueue) {
_trumpetQueue = [NSMutableArray array];
}
return _trumpetQueue;
}
- (MSRoomOnLineView *)onlineView{
if(!_onlineView){
_onlineView = [[MSRoomOnLineView alloc]initWithFrame:CGRectZero];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onlineTapRecognizer)];
[_onlineView addGestureRecognizer:tap];
}
return _onlineView;
}
@end