diff --git a/xplan-ios/Main/Mine/View/XPMineViewController.m b/xplan-ios/Main/Mine/View/XPMineViewController.m index 539d3335..b0666697 100644 --- a/xplan-ios/Main/Mine/View/XPMineViewController.m +++ b/xplan-ios/Main/Mine/View/XPMineViewController.m @@ -202,9 +202,10 @@ [Api getRoomInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { if (code == 200) { RoomInfoModel * roomInfo = [RoomInfoModel modelWithJSON:data.data]; - roomInfo.isReselect = YES; if (roomInfo.isReselect) { XPLittleGameRoomOpenView * roomOpenView = [[XPLittleGameRoomOpenView alloc] init]; + roomOpenView.roomInfo = roomInfo; + roomOpenView.currentVC = self; [TTPopup popupView:roomOpenView style:TTPopupStyleActionSheet]; } else { [XPRoomViewController openRoom:roomUid viewController:self]; diff --git a/xplan-ios/Main/Room/Api/Api+Room.h b/xplan-ios/Main/Room/Api/Api+Room.h index f5f4cd4b..2d69cad5 100644 --- a/xplan-ios/Main/Room/Api/Api+Room.h +++ b/xplan-ios/Main/Room/Api/Api+Room.h @@ -29,6 +29,7 @@ NS_ASSUME_NONNULL_BEGIN /// @param backPic 房间背景 /// @param uid 用户的uid /// @param ticket 用户的ticket +/// @param mgId 小游戏的id + (void)openRoom:(HttpRequestHelperCompletion)complection title:(NSString *)title type:(RoomType)type @@ -36,7 +37,8 @@ NS_ASSUME_NONNULL_BEGIN roomDesc:(NSString *)roomDesc backPic:(NSString *)backPic uid:(NSString *)uid - ticket:(NSString *)ticket; + ticket:(NSString *)ticket + mgId:(NSString *)mgId; /// 房间上麦 /// @param complection 完成 diff --git a/xplan-ios/Main/Room/Api/Api+Room.m b/xplan-ios/Main/Room/Api/Api+Room.m index eece8fb8..aac81668 100644 --- a/xplan-ios/Main/Room/Api/Api+Room.m +++ b/xplan-ios/Main/Room/Api/Api+Room.m @@ -27,6 +27,7 @@ /// @param backPic 房间背景 /// @param uid 用户的uid /// @param ticket 用户的ticket +/// @param mgId 小游戏的id + (void)openRoom:(HttpRequestHelperCompletion)complection title:(NSString *)title type:(RoomType)type @@ -34,8 +35,9 @@ roomDesc:(NSString *)roomDesc backPic:(NSString *)backPic uid:(NSString *)uid - ticket:(NSString *)ticket { - [Api makeRequest:@"room/open" method:HttpRequestHelperMethodPOST completion:complection, __FUNCTION__, title, @(type), roomPwd, roomDesc, backPic, uid, ticket,nil]; + ticket:(NSString *)ticket + mgId:(NSString *)mgId { + [Api makeRequest:@"room/open" method:HttpRequestHelperMethodPOST completion:complection, __FUNCTION__, title, @(type), roomPwd, roomDesc, backPic, uid, ticket, mgId,nil]; } diff --git a/xplan-ios/Main/Room/Model/RoomInfoModel.h b/xplan-ios/Main/Room/Model/RoomInfoModel.h index 88a0df3c..35a325ab 100644 --- a/xplan-ios/Main/Room/Model/RoomInfoModel.h +++ b/xplan-ios/Main/Room/Model/RoomInfoModel.h @@ -11,7 +11,8 @@ NS_ASSUME_NONNULL_BEGIN typedef NS_ENUM(NSInteger, RoomType) { RoomType_Game = 3, - RoomType_Anchor = 6 // 个播房 + RoomType_Anchor = 6, // 个播房 + RoomType_MiniGame = 7//小游戏房 }; typedef NS_ENUM(NSInteger, RoomModeType){ diff --git a/xplan-ios/Main/Room/Presenter/XPRoomPresenter.h b/xplan-ios/Main/Room/Presenter/XPRoomPresenter.h index 4383a5cb..e449113b 100644 --- a/xplan-ios/Main/Room/Presenter/XPRoomPresenter.h +++ b/xplan-ios/Main/Room/Presenter/XPRoomPresenter.h @@ -24,11 +24,13 @@ NS_ASSUME_NONNULL_BEGIN /// @param roomPwd 房间密码 /// @param roomDesc 房间介绍 /// @param backPic 房间背景 +/// @param mgId 小游戏的id - (void)openRoom:(NSString *)title type:(RoomType)type roomPwd:(NSString *)roomPwd roomDesc:(NSString *)roomDesc - backPic:(NSString *)backPic; + backPic:(NSString *)backPic + mgId:(NSString *)mgId; ///福袋礼物爆出的礼物的bug ///进入房间的时候需要获取一次礼物信息 因为如果有人送礼物的话 如果是福袋礼物的话 爆出的礼物需要从礼物列表中获取 会导致公屏不显示那个礼物 diff --git a/xplan-ios/Main/Room/Presenter/XPRoomPresenter.m b/xplan-ios/Main/Room/Presenter/XPRoomPresenter.m index 0c8af736..8c641bc0 100644 --- a/xplan-ios/Main/Room/Presenter/XPRoomPresenter.m +++ b/xplan-ios/Main/Room/Presenter/XPRoomPresenter.m @@ -97,11 +97,13 @@ /// @param roomPwd 房间密码 /// @param roomDesc 房间介绍 /// @param backPic 房间背景 +/// @param mgId 小游戏的id - (void)openRoom:(NSString *)title type:(RoomType)type roomPwd:(NSString *)roomPwd roomDesc:(NSString *)roomDesc - backPic:(NSString *)backPic { + backPic:(NSString *)backPic + mgId:(NSString *)mgId{ NSString * uid = [AccountInfoStorage instance].getUid; NSString * ticket = [AccountInfoStorage instance].getTicket; if (title.length <= 0) { @@ -119,13 +121,17 @@ if (backPic.length <= 0) { backPic = @""; } + + if (mgId.length <= 0) { + mgId = @""; + } [Api openRoom:[self createHttpCompletion:^(BaseModel * _Nonnull data) { RoomInfoModel * infoModel = [RoomInfoModel modelWithJSON:data.data]; [[self getView] openRoomSuccess:infoModel]; } fail:^(NSInteger code, NSString * _Nullable msg) { [[self getView] enterRoomFail:code]; - } showLoading:YES] title:title type:type roomPwd:roomPwd roomDesc:roomDesc backPic:backPic uid:uid ticket:ticket]; + } showLoading:YES] title:title type:type roomPwd:roomPwd roomDesc:roomDesc backPic:backPic uid:uid ticket:ticket mgId:mgId]; } ///福袋礼物爆出的礼物的bug diff --git a/xplan-ios/Main/Room/View/LittleGame/Cell/XPCreateLittleGameCollectionViewCell.m b/xplan-ios/Main/Room/View/LittleGame/Cell/XPCreateLittleGameCollectionViewCell.m index 30ef9225..01e46c0d 100644 --- a/xplan-ios/Main/Room/View/LittleGame/Cell/XPCreateLittleGameCollectionViewCell.m +++ b/xplan-ios/Main/Room/View/LittleGame/Cell/XPCreateLittleGameCollectionViewCell.m @@ -48,7 +48,6 @@ } - (void)setGameInfo:(LittleGameInfoModel *)gameInfo{ if (gameInfo) { - NSString *encodedUrl = [gameInfo.pic stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; self.logoImageView.imageUrl = gameInfo.pic; if (gameInfo.isSelect) { self.logoImageView.layer.borderWidth = 2; diff --git a/xplan-ios/Main/Room/View/LittleGame/XPLittleGameRoomOpenView.h b/xplan-ios/Main/Room/View/LittleGame/XPLittleGameRoomOpenView.h index 714dbfae..a7c151c4 100644 --- a/xplan-ios/Main/Room/View/LittleGame/XPLittleGameRoomOpenView.h +++ b/xplan-ios/Main/Room/View/LittleGame/XPLittleGameRoomOpenView.h @@ -8,9 +8,12 @@ #import NS_ASSUME_NONNULL_BEGIN - +@class RoomInfoModel; @interface XPLittleGameRoomOpenView : UIView - +///当前房间的信息 +@property (nonatomic,weak) UIViewController *currentVC; +///当前房间的信息 +@property (nonatomic,strong) RoomInfoModel *roomInfo; @end NS_ASSUME_NONNULL_END diff --git a/xplan-ios/Main/Room/View/LittleGame/XPLittleGameRoomOpenView.m b/xplan-ios/Main/Room/View/LittleGame/XPLittleGameRoomOpenView.m index 88049609..a4b810a1 100644 --- a/xplan-ios/Main/Room/View/LittleGame/XPLittleGameRoomOpenView.m +++ b/xplan-ios/Main/Room/View/LittleGame/XPLittleGameRoomOpenView.m @@ -14,10 +14,17 @@ #import "TTPopup.h" #import "XPMacro.h" #import "Api+LittleGame.h" +#import "AccountInfoStorage.h" +#import "DESEncrypt.h" +#import "XPConstant.h" +#import "Api+RoomSetting.h" +#import "XCHudTool.h" ///Model #import "LittleGameInfoModel.h" +#import "RoomInfoModel.h" ///View #import "XPCreateLittleGameCollectionViewCell.h" +#import "XPRoomViewController.h" @interface XPLittleGameRoomOpenView () ///背景图 @@ -127,16 +134,16 @@ [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(118); - }]; - - [self.normalRoomButton mas_makeConstraints:^(MASConstraintMaker *make) { - make.height.mas_equalTo(135); + make.width.mas_equalTo(KScreenWidth - 16 * 2); }]; [self.gameRoomButton mas_makeConstraints:^(MASConstraintMaker *make) { - make.height.mas_equalTo(135); + make.width.mas_equalTo(125); }]; + [self.normalRoomButton mas_makeConstraints:^(MASConstraintMaker *make) { + make.width.mas_equalTo(125); + }]; [self.modelStackView mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(65); }]; @@ -186,6 +193,20 @@ [TTPopup dismiss]; } +- (void)createRoomButtonAction:(UIButton *)sender { + if (self.normalRoomButton.selected) { + [XPRoomViewController openRoom:[AccountInfoStorage instance].getUid viewController:self.currentVC]; + }else { + RoomInfoModel * roomInfo = self.roomInfo; + if (self.selectGameInfo.mgId.length > 0 && roomInfo) { + [XPRoomViewController openRoom:[AccountInfoStorage instance].getUid mgId:self.selectGameInfo.mgId viewController:self.currentVC]; + } else { + [XCHUDTool showErrorWithMessage:@"请求房间信息失败请重试!"]; + [TTPopup dismiss]; + } + } +} + #pragma mark - Getters And Setters - (UIImageView *)backImageView { if (!_backImageView) { @@ -220,7 +241,7 @@ _stackView = [[UIStackView alloc] init]; _stackView.axis = UILayoutConstraintAxisVertical; _stackView.distribution = UIStackViewDistributionFill; - _stackView.alignment = UIStackViewAlignmentFill; + _stackView.alignment = UIStackViewAlignmentLeading; _stackView.spacing = 16; } return _stackView; @@ -261,6 +282,7 @@ [_normalRoomButton setImage:[UIImage imageNamed:@"room_little_game_normal_room"] forState:UIControlStateNormal]; [_normalRoomButton setImage:[UIImage imageNamed:@"room_little_game_normal_room_select"] forState:UIControlStateSelected]; [_normalRoomButton addTarget:self action:@selector(normalRoomButtonAction:) forControlEvents:UIControlEventTouchUpInside]; + _normalRoomButton.selected = YES; } return _normalRoomButton; } @@ -271,6 +293,7 @@ [_gameRoomButton setImage:[UIImage imageNamed:@"room_little_game_game_room"] forState:UIControlStateNormal]; [_gameRoomButton setImage:[UIImage imageNamed:@"room_little_game_game_room_select"] forState:UIControlStateSelected]; [_gameRoomButton addTarget:self action:@selector(gameRoomButtonAction:) forControlEvents:UIControlEventTouchUpInside]; + _gameRoomButton.selected = NO; } return _gameRoomButton; } @@ -284,6 +307,7 @@ _createRoomButton.titleLabel.textColor = [ThemeColor confirmButtonTextColor]; _createRoomButton.layer.cornerRadius = 20; _createRoomButton.layer.masksToBounds = YES; + [_createRoomButton addTarget:self action:@selector(createRoomButtonAction:) forControlEvents:UIControlEventTouchUpInside]; } return _createRoomButton; } diff --git a/xplan-ios/Main/Room/View/XPRoomViewController.h b/xplan-ios/Main/Room/View/XPRoomViewController.h index 92d29dca..d6d190db 100644 --- a/xplan-ios/Main/Room/View/XPRoomViewController.h +++ b/xplan-ios/Main/Room/View/XPRoomViewController.h @@ -26,6 +26,13 @@ NS_ASSUME_NONNULL_BEGIN */ + (BOOL)openRoom:(NSString*)roomUid fromNick:(NSString * __nullable)fromNick fromType:(UserEnterRoomFromType)fromType fromUid:(NSString * __nullable)fromUid viewController:(UIViewController*)viewController; +/** XPRoomViewController 不允许外部 init ,请通过该方法启动房间。 + * @params roomUid 房主uid + * @params viewController 启动方 + * @params mgId 小游戏的id + */ ++ (BOOL)openRoom:(NSString*)roomUid mgId:(NSString *)mgId viewController:(UIViewController*)viewController; + - (instancetype)init NS_UNAVAILABLE; + (instancetype)new NS_UNAVAILABLE; - (id)copy NS_UNAVAILABLE; diff --git a/xplan-ios/Main/Room/View/XPRoomViewController.m b/xplan-ios/Main/Room/View/XPRoomViewController.m index 93acaa5d..990b6f9f 100644 --- a/xplan-ios/Main/Room/View/XPRoomViewController.m +++ b/xplan-ios/Main/Room/View/XPRoomViewController.m @@ -74,6 +74,8 @@ UIKIT_EXTERN NSString * const kRoomMiniNotificationKey; @property (nonatomic,strong) XPRoomFunctionContainerView *functionView; ///房间的Uid @property (nonatomic,copy) NSString * roomUid; +///小游戏的id +@property (nonatomic,copy) NSString *mgId; ///用户信息 @property (nonatomic,strong) UserInfoModel *userInfo; ///房间信息 @@ -104,6 +106,21 @@ UIKIT_EXTERN NSString * const kRoomMiniNotificationKey; return YES; } +/** XPRoomViewController 不允许外部 init ,请通过该方法启动房间。 + * @params roomUid 房主uid + * @params viewController 启动方 + * @params mgId 小游戏的id + */ ++ (BOOL)openRoom:(NSString*)roomUid mgId:(NSString *)mgId viewController:(UIViewController*)viewController { + XPRoomViewController * roomVC = [[self alloc] init]; + roomVC.roomUid = roomUid; + roomVC.mgId = mgId; + BaseNavigationController * baseNav = [[BaseNavigationController alloc] initWithRootViewController:roomVC]; + baseNav.modalPresentationStyle = UIModalPresentationFullScreen; + [viewController presentViewController:baseNav animated:YES completion:nil]; + return YES; +} + - (void)dealloc { #warning to dox - 时刻注意这个方法 功能做完的时候删除此方法 @@ -378,10 +395,14 @@ UIKIT_EXTERN NSString * const kRoomMiniNotificationKey; } else { // 房间无效,分是否为自己房间进行处理 if ([self.roomUid isEqualToString:[NSString stringWithFormat:@"%ld", userInfo.uid]]) { // 当前用户进入自己房间 if (roomInfo.roomId > 0) { // 存在房间信息,直接使用房间信息开房 - [self.presenter openRoom:roomInfo.title type:roomInfo.type roomPwd:roomInfo.roomPwd roomDesc:roomInfo.roomDesc backPic:@""]; + [self.presenter openRoom:roomInfo.title type:roomInfo.type roomPwd:roomInfo.roomPwd roomDesc:roomInfo.roomDesc backPic:@"" mgId:self.mgId]; } else { // 不存在房间信息,全新开房 NSString* title = [NSString stringWithFormat:@"%@的房间", userInfo.nick]; - [self.presenter openRoom:title type:RoomType_Game roomPwd:@"" roomDesc:@"" backPic:@""]; + RoomType type = RoomType_Game; + if (self.mgId.length > 0) { + type = RoomType_MiniGame; + } + [self.presenter openRoom:title type:type roomPwd:@"" roomDesc:@"" backPic:@"" mgId:self.mgId]; } } else { // 当前用户进入别人房间 // TODO: 房主已经下线。