小游戏调试完成

This commit is contained in:
fengshuo
2022-02-15 14:38:09 +08:00
committed by chenguilong
parent 3a6e9d731b
commit 96d7e1ee80
8 changed files with 137 additions and 85 deletions

View File

@@ -12,6 +12,8 @@ NS_ASSUME_NONNULL_BEGIN
@interface XPRoomFunctionContainerView : XPRoomAnimationHitView <RoomGuestDelegate>
- (instancetype)initWithdelegate:(id<RoomHostDelegate>)delegate;
- (void)hiddenSudGamePostionView;
@end
NS_ASSUME_NONNULL_END

View File

@@ -44,6 +44,7 @@
#import "XPSendGiftView.h"
#import "XPUserCardViewController.h"
#import "XPRoomViewController.h"
#import "XPLittleGameMiniStageView.h"
@interface XPRoomFunctionContainerView ()<XPAcrpssRoomPKPanelViewDelegate>
///host
@property (nonatomic,weak) id<RoomHostDelegate>delegate;
@@ -63,6 +64,8 @@
@property (nonatomic,strong) UIButton *editButton;
///pk
@property (nonatomic,strong) XPAcrpssRoomPKPanelView *acrossPKPanelView;
///
@property (nonatomic,strong) XPLittleGameMiniStageView *littleGameMiniView;
@end
@implementation XPRoomFunctionContainerView
@@ -83,6 +86,11 @@
return self;
}
#pragma mark - Public Method
- (void)hiddenSudGamePostionView {
[self.littleGameMiniView hiddenSudGamePostionView];
}
#pragma mark - Private Method
- (void)initSubViews {
[self addSubview:self.contributionButton];
@@ -95,7 +103,7 @@
- (void)initSubViewConstraints {
[self.contributionButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(-12);
make.top.mas_equalTo(kNavigationHeight+4);
make.top.mas_equalTo(kNavigationHeight);
make.width.mas_equalTo(90);
make.height.mas_equalTo(26);
}];
@@ -112,6 +120,23 @@
}];
}
- (void)showLittleGameMiniView:(RoomType)type {
if (type == RoomType_MiniGame) {
if (!self.littleGameMiniView.superview) {
[self addSubview:self.littleGameMiniView];
[self.littleGameMiniView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(0);
make.top.mas_equalTo(kNavigationHeight);
make.height.mas_equalTo(23);
}];
}
} else {
if (self.littleGameMiniView.superview) {
[self.littleGameMiniView removeFromSuperview];
}
}
}
#pragma mark - RoomGuestDelegate
- (void)onRoomUpdate {
RoomInfoModel * roomInfo = self.delegate.getRoomInfo;
@@ -201,8 +226,6 @@
}
} roomUid:roomUid];
}
if (roomInfo.type == RoomType_Anchor) {
[self.contributionButton setTitle:@"主播榜" forState:UIControlStateNormal];
self.anchorGiftValueView.hidden = !roomInfo.showGiftValue;
@@ -378,7 +401,6 @@
}
}
#pragma mark - XPAcrpssRoomPKPanelViewDelegate
- (void)xPAcrpssRoomPKPanelView:(XPAcrpssRoomPKPanelView *)view onlookRoom:(NSString *)roomUid {
[self.delegate exitRoom];
@@ -719,4 +741,13 @@
}
return _acrossPKPanelView;
}
- (XPLittleGameMiniStageView *)littleGameMiniView {
if (!_littleGameMiniView) {
_littleGameMiniView = [[XPLittleGameMiniStageView alloc] init];
}
return _littleGameMiniView;
}
@end

View File

@@ -20,7 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
///代理
@property (nonatomic,weak) id<XPLittleGameMiniStageViewDelegate> delegate;
///隐藏小游戏房大坑位
- (void)hideSudGamePostionView;
- (void)hiddenSudGamePostionView;
@end
NS_ASSUME_NONNULL_END

View File

@@ -44,7 +44,7 @@ UIKIT_EXTERN NSString * const kRoomRoomLittleGameMiniStageNotificationKey;
}
#pragma mark - Public Method
- (void)hideSudGamePostionView {
- (void)hiddenSudGamePostionView {
self.foldButton.selected = NO;
[self tapAvatarRecognizer];
}
@@ -124,7 +124,7 @@ UIKIT_EXTERN NSString * const kRoomRoomLittleGameMiniStageNotificationKey;
_foldButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_foldButton setImage:[UIImage imageNamed:@"room_position_little_game_right_arrow"] forState:UIControlStateNormal];
[_foldButton setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
_foldButton.userInteractionEnabled = NO;
[_foldButton addTarget:self action:@selector(tapAvatarRecognizer) forControlEvents:UIControlEventTouchUpInside];
}
return _foldButton;
}

View File

@@ -10,8 +10,24 @@
#import "RoomGuestDelegate.h"
NS_ASSUME_NONNULL_BEGIN
@protocol XPRoomLittleGameContainerViewDelegate <NSObject>
- (void)hiddenSudGamePostionView;
@end
@interface XPRoomLittleGameContainerView : UIView<RoomGuestDelegate>
- (instancetype)initWithDelegate:(id<RoomHostDelegate>)delegate;
///代理
@property (nonatomic,weak) id<XPRoomLittleGameContainerViewDelegate> delegate;
///销毁游戏的引擎
- (void)destroyMG;
//自己是否在游戏中
- (BOOL)isInSudGame;
@end
NS_ASSUME_NONNULL_END

View File

@@ -25,8 +25,6 @@
#import "MicroExtModel.h"
#import "AttachmentModel.h"
#import "XPKickUserModel.h"
///View
#import "XPLittleGameMiniStageView.h"
///P
#import <SudMGP/ISudFSMMG.h>
#import <SudMGP/ISudFSTAPP.h>
@@ -46,10 +44,6 @@
@property (nonatomic, assign) BOOL keyWordHiting;
///
@property (nonatomic, assign) LittleGamePlayStatus sudGameStatus;
///
@property (nonatomic, assign) BOOL isPlaying;
///
@property (nonatomic,strong) XPLittleGameMiniStageView *littleGameMiniView;
@end
@implementation XPRoomLittleGameContainerView
@@ -63,25 +57,6 @@
return self;
}
#pragma mark -
- (void)showLittleGameMiniView:(RoomType)type {
if (type == RoomType_MiniGame) {
if (!self.littleGameMiniView.superview) {
[self addSubview:self.littleGameMiniView];
[self.littleGameMiniView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(0);
make.top.mas_equalTo(kNavigationHeight + 4);
make.height.mas_equalTo(23);
}];
}
} else {
if (self.littleGameMiniView.superview) {
[self.littleGameMiniView removeFromSuperview];
}
}
}
#pragma mark - Private Method
- (void)updateSudGame {
RoomInfoModel * roomInfo = self.hostDelegate.getRoomInfo;
@@ -99,14 +74,12 @@
NSLog(@"updateLittleGame---%lld", self.currentmgId);
if (self.currentmgId != 0) {
[self destroyMG];
self.isPlaying = NO;
[self updateMicInfoWithGameStatus:LittleGamePlayStatus_NoIn];
[self gameSetUp];
}
}
}
}
[self showLittleGameMiniView:roomInfo.type];
}
- (void)initLittleGame {
@@ -135,7 +108,7 @@
return;
}
NSString * userId = [AccountInfoStorage instance].getUid;
NSString * roomId = [NSString stringWithFormat:@"%ld", self.hostDelegate.getRoomInfo.roomId];
NSString * roomId = [NSString stringWithFormat:@"%ld", self.hostDelegate.getRoomInfo.uid];
NSLog(@"用户ID%@房间ID%@, 游戏ID%lld, code:%@", userId, roomId, self.currentmgId, self.code);
self.fsmAPP2MG = [SudMGP loadMG:userId roomId:roomId code:self.code mgId:self.currentmgId language:@"zh-CN" fsmMG:self rootView:self];
} else {
@@ -562,7 +535,7 @@
}
} roomUid:[NSString stringWithFormat:@"%ld", roomInfo.uid] mgId:mgid];
} else if (retCode == 0 && [state isEqualToString:APP_COMMON_SELF_END]) {//
self.isPlaying = NO;
}
}];
}
@@ -738,14 +711,14 @@
isPlaying = [[dic objectForKey:@"isPlaying"] boolValue];
}
if ([userId isEqualToString:[AccountInfoStorage instance].getUid]) {
self.isPlaying = isPlaying;
if (isPlaying) {
//
if ([self isOnMicro:[userId longLongValue]]) {
[self updateMicInfoWithGameStatus:LittleGamePlayStatus_Plying];
}
///
[self.littleGameMiniView hideSudGamePostionView];
if (self.delegate && [self.delegate respondsToSelector:@selector(hiddenSudGamePostionView)]) {
[self.delegate hiddenSudGamePostionView];
}
self.sudGameStatus = LittleGamePlayStatus_Plying;
}else {
if ([self isOnMicro:[userId longLongValue]]) {
@@ -788,7 +761,9 @@
/// MG
- (void)destroyMG {
[self.fsmAPP2MG destroyMG];
if (self.hostDelegate.getRoomInfo.type == RoomType_MiniGame) {
[self.fsmAPP2MG destroyMG];
}
}
#pragma mark - RoomGuestDelegate
@@ -805,21 +780,13 @@
- (void)onRoomUpdate {
if (self.hostDelegate.getRoomInfo.type != RoomType_MiniGame) {
self.hidden = YES;
[self destroyMG];
} else {
self.hidden = NO;
}
[self updateSudGame];
}
#pragma mark - RoomGuestDelegate
- (void)onMicroQueueUpdate:(NSMutableDictionary<NSString *,MicroQueueModel *> *)queue {
if (self.hostDelegate.getRoomInfo.type != RoomType_MiniGame) {
return;
}
if (self.hostDelegate.getRoomInfo.type == RoomType_MiniGame) {
[self.littleGameMiniView needRefreshPosition:queue];
}
}
- (void)handleNIMCustomMessage:(NIMMessage *)message {
if (self.hostDelegate.getRoomInfo.type != RoomType_MiniGame) {
return;
@@ -858,15 +825,6 @@
break;
}
}
#pragma mark - Getters And Setters
- (XPLittleGameMiniStageView *)littleGameMiniView {
if (!_littleGameMiniView) {
_littleGameMiniView = [[XPLittleGameMiniStageView alloc] init];
}
return _littleGameMiniView;
}
@end

View File

@@ -20,15 +20,10 @@ UIKIT_EXTERN NSString * const kRoomRoomLittleGameMiniStageNotificationKey;
#define mcHeight (mcWidth + 10 + 12)
// padding 12
#define paddingH 12 * kScreenScale
#define foldButtonHeight 23
#define marginV1 4
//
#define firstRowTop (foldButtonHeight + marginV1 + marginV1)
@interface LittleGameStageView ()
///
@property (nonatomic,strong) UIButton *foldButton;
@end
@implementation LittleGameStageView
@@ -39,13 +34,6 @@ UIKIT_EXTERN NSString * const kRoomRoomLittleGameMiniStageNotificationKey;
- (instancetype)initWithDelegate:(id<RoomHostDelegate>)delegate {
if (self = [super initWithDelegate:delegate]) {
[self addSubview:self.foldButton];
[self.foldButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(26);
make.height.mas_equalTo(foldButtonHeight);
make.right.mas_equalTo(self);
make.top.mas_equalTo(self).offset(marginV1);
}];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeViewState:) name:kRoomRoomLittleGameMiniStageNotificationKey object:nil];
}
return self;
@@ -69,11 +57,11 @@ UIKIT_EXTERN NSString * const kRoomRoomLittleGameMiniStageNotificationKey;
- (CGRect)rectForViewAtIndex:(NSInteger)index {
CGFloat spaceWidth = (KScreenWidth - mcWidth * 6 - paddingH * 2) / 5;
return CGRectMake(paddingH + index * (mcWidth + spaceWidth), firstRowTop, mcWidth, mcHeight);
return CGRectMake(paddingH + index * (mcWidth + spaceWidth), 0, mcWidth, mcHeight);
}
- (CGFloat)hightForStageView {
return firstRowTop + mcHeight + marginV1;
return mcHeight;
}
#pragma mark -

View File

@@ -56,8 +56,8 @@ UIKIT_EXTERN NSString * const kRoomGiftEffectUpdateNotificationKey;
UIKIT_EXTERN NSString * const kRoomRoomSettingNotificationKey;
UIKIT_EXTERN NSString * const kRoomMiniNotificationKey;
@interface XPRoomViewController ()<XPRoomProtocol, RoomHostDelegate, NIMChatroomManagerDelegate, NIMChatManagerDelegate, NIMLoginManagerDelegate, XPRoomSettingInputViewDelegate>
@interface XPRoomViewController ()<XPRoomProtocol, RoomHostDelegate, NIMChatroomManagerDelegate, NIMChatManagerDelegate, NIMLoginManagerDelegate, XPRoomSettingInputViewDelegate,XPRoomLittleGameContainerViewDelegate>
///
@property (nonatomic,strong) XPRoomBackContainerView *backContainerView;
///
@@ -289,13 +289,15 @@ UIKIT_EXTERN NSString * const kRoomMiniNotificationKey;
if (!self.stageView.superview) {
[self.view insertSubview:self.stageView belowSubview:self.roomHeaderView];
}
[self.stageView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.view);
make.top.mas_equalTo(self.roomHeaderView.mas_bottom);
make.height.mas_equalTo(self.stageView.hightForStageView);
}];
if (self.roomInfo.type == RoomType_MiniGame) {
[self.stageView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.view);
make.top.mas_equalTo(self.roomHeaderView.mas_bottom).offset(23 + 4);
make.height.mas_equalTo(self.stageView.hightForStageView);
}];
[self.messageContainerView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(50);
make.bottom.mas_equalTo(self.menuContainerView.mas_top).offset(-5);
@@ -310,6 +312,12 @@ UIKIT_EXTERN NSString * const kRoomMiniNotificationKey;
make.width.mas_equalTo(80);
}];
} else {
[self.stageView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.view);
make.top.mas_equalTo(self.roomHeaderView.mas_bottom);
make.height.mas_equalTo(self.stageView.hightForStageView);
}];
[self.messageContainerView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.stageView.mas_bottom);
make.bottom.mas_equalTo(self.menuContainerView.mas_top).offset(-5);
@@ -694,6 +702,27 @@ UIKIT_EXTERN NSString * const kRoomMiniNotificationKey;
[self.presenter reportUserOutRoom:roomUid];
[self dismissViewControllerAnimated:YES completion:nil];
} roomUid:roomUid operUid:uid page:@"1" pageSize:@"50"];
} else if(self.roomInfo.type == RoomType_MiniGame) {
if ([self.littleGameView isInSudGame]) {
TTAlertConfig *config = [[TTAlertConfig alloc] init];
config.cancelButtonConfig.title = @"取消";
config.confirmButtonConfig.title = @"确认";
config.message = @"退出房间则默认认输逃跑,是否退房?";
[TTPopup alertWithConfig:config confirmHandler:^{ //
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.presenter exitNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId]];
[[RtcManager instance] exitRoom];
[self.littleGameView destroyMG];
[self dismissViewControllerAnimated:YES completion:nil];
});
} cancelHandler:^{
}];
} else {
[self.presenter exitNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId]];
[[RtcManager instance] exitRoom];
[self.littleGameView destroyMG];
[self dismissViewControllerAnimated:YES completion:nil];
}
} else {
[self.presenter exitNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId]];
[[XPRoomMiniManager shareManager] resetLocalMessage];
@@ -704,11 +733,34 @@ UIKIT_EXTERN NSString * const kRoomMiniNotificationKey;
}
- (void)miniRoom {
[[XPRoomMiniManager shareManager] configRoomInfo:self.roomInfo];
NSDictionary * dic = @{@"roomInfo":self.roomInfo.model2dictionary, @"userInfo":self.userInfo.model2dictionary, @"microQueue":self.getMicroQueue};
[[NSNotificationCenter defaultCenter] postNotificationName:kRoomMiniNotificationKey object:nil userInfo:dic];
[self.view endEditing:YES];
[self dismissViewControllerAnimated:YES completion:nil];
if(self.roomInfo.type == RoomType_MiniGame) {
if ([self.littleGameView isInSudGame]) {
TTAlertConfig *config = [[TTAlertConfig alloc] init];
config.cancelButtonConfig.title = @"取消";
config.confirmButtonConfig.title = @"确认";
config.message = @"退出房间则默认认输逃跑,是否退房?";
[TTPopup alertWithConfig:config confirmHandler:^{ //
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.presenter exitNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId]];
[[RtcManager instance] exitRoom];
[self.littleGameView destroyMG];
[self dismissViewControllerAnimated:YES completion:nil];
});
} cancelHandler:^{
}];
} else {
[self.presenter exitNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId]];
[[RtcManager instance] exitRoom];
[self.littleGameView destroyMG];
[self dismissViewControllerAnimated:YES completion:nil];
}
}else {
[[XPRoomMiniManager shareManager] configRoomInfo:self.roomInfo];
NSDictionary * dic = @{@"roomInfo":self.roomInfo.model2dictionary, @"userInfo":self.userInfo.model2dictionary, @"microQueue":self.getMicroQueue};
[[NSNotificationCenter defaultCenter] postNotificationName:kRoomMiniNotificationKey object:nil userInfo:dic];
[self.view endEditing:YES];
[self dismissViewControllerAnimated:YES completion:nil];
}
}
- (UINavigationController *)getCurrentNav {
@@ -722,7 +774,7 @@ UIKIT_EXTERN NSString * const kRoomMiniNotificationKey;
- (void)onMicroQueueUpdate:(NSMutableDictionary<NSString *,MicroQueueModel *> *)queue {
[self.menuContainerView onMicroQueueUpdate:queue];
[self.functionView onRoomUpdate];
[self.littleGameView onMicroQueueUpdate:queue];
[self.functionView onMicroQueueUpdate:queue];
}
- (void)onMicroGiftValueUpdate:(NSDictionary *)data {
@@ -732,6 +784,10 @@ UIKIT_EXTERN NSString * const kRoomMiniNotificationKey;
- (CGPoint)animationPointAtStageViewByUid:(NSString *)uid {
return [self.stageView animationPointAtStageViewByUid:uid];
}
#pragma mark - XPRoomLittleGameContainerViewDelegate
- (void)hiddenSudGamePostionView {
[self.functionView hiddenSudGamePostionView];
}
#pragma mark - XPRoomSettingInputViewDelegate
///
@@ -820,6 +876,7 @@ UIKIT_EXTERN NSString * const kRoomMiniNotificationKey;
- (XPRoomLittleGameContainerView *)littleGameView {
if (!_littleGameView) {
_littleGameView = [[XPRoomLittleGameContainerView alloc] initWithDelegate:self];
_littleGameView.delegate = self;
}
return _littleGameView;
}