游戏中各种状态的处理

This commit is contained in:
fengshuo
2022-02-15 17:59:05 +08:00
committed by chenguilong
parent 2d0e8e120a
commit d56f5845fc
9 changed files with 140 additions and 34 deletions

View File

@@ -114,7 +114,7 @@ UIKIT_EXTERN NSString * const kRoomRoomLittleGameMiniStageNotificationKey;
self.foldButton.transform = CGAffineTransformIdentity;
}
}];
[[NSNotificationCenter defaultCenter] postNotificationName:kRoomRoomLittleGameMiniStageNotificationKey object:@{@"isMini": @(!self.foldButton.selected)}];
[[NSNotificationCenter defaultCenter] postNotificationName:kRoomRoomLittleGameMiniStageNotificationKey object:@{@"isMini": @(self.foldButton.selected)}];
}
#pragma mark - Getters And Setters

View File

@@ -11,9 +11,12 @@ NS_ASSUME_NONNULL_BEGIN
@class LittleGameInfoModel, XPLittleGameRoomListView;
@protocol XPRoomLittleGameListViewDelegate <NSObject>
///选择了礼物
///选择某一个类型
- (void)xPRoomLittleGameListView:(XPLittleGameRoomListView *)view didSelectItem:(LittleGameInfoModel *)itemInfo;
///选择类型
- (void)xPRoomLittleGameListView:(XPLittleGameRoomListView *)view didSelectChooseType:(UIButton *)sender;
@end
@interface XPLittleGameRoomListView : UIView
@@ -24,6 +27,7 @@ NS_ASSUME_NONNULL_BEGIN
///列表
@property (nonatomic,strong,readonly) UITableView *tableView;
@end
NS_ASSUME_NONNULL_END

View File

@@ -124,8 +124,9 @@
#pragma mark - Event Response
- (void)gamePlayButtonAction:(UIButton *)sender {
sender.selected = !sender.selected;
self.tableView.hidden = !sender.selected;
if (self.delegate && [self.delegate respondsToSelector:@selector(xPRoomLittleGameListView:didSelectChooseType:)]) {
[self.delegate xPRoomLittleGameListView:self didSelectChooseType:sender];
}
}
#pragma mark - Getters And Setters

View File

@@ -25,6 +25,9 @@ NS_ASSUME_NONNULL_BEGIN
///销毁游戏的引擎
- (void)destroyMG;
/// 退出游戏
- (void)handleSelfInExitEvent;
//自己是否在游戏中
- (BOOL)isInSudGame;

View File

@@ -243,15 +243,17 @@
//
- (BOOL)isInSudGame {
BOOL isGamePlaying = NO;
for (int i = -1; i<5; i++) {
NSMutableDictionary * micQueue = self.hostDelegate.getMicroQueue;
MicroQueueModel *micSequence = [micQueue objectForKey:[NSString stringWithFormat:@"%d", i]];
if (micSequence == nil || micSequence.userInfo == nil) {
continue;
}
if (micSequence.userInfo.uid == [AccountInfoStorage instance].getUid.integerValue && micSequence.userInfo.gameStatus == LittleGamePlayStatus_Plying) {
isGamePlaying = YES;
break;
if (self.hostDelegate.getRoomInfo.type == RoomType_MiniGame) {
for (int i = -1; i<5; i++) {
NSMutableDictionary * micQueue = self.hostDelegate.getMicroQueue;
MicroQueueModel *micSequence = [micQueue objectForKey:[NSString stringWithFormat:@"%d", i]];
if (micSequence == nil || micSequence.userInfo == nil) {
continue;
}
if (micSequence.userInfo.uid == [AccountInfoStorage instance].getUid.integerValue && micSequence.userInfo.gameStatus == LittleGamePlayStatus_Plying) {
isGamePlaying = YES;
break;
}
}
}
return isGamePlaying;
@@ -483,8 +485,11 @@
/// 退
- (void)handleSelfInExitEvent {
if (self.hostDelegate.getRoomInfo.type != RoomType_MiniGame) {
return;
}
/// 退
if ([self isInSudGame]) {
if ([self getCurrentUserSudGameStatus] == LittleGamePlayStatus_Plying) {
[self notifyIsPlayingState:false];
[self nofityPlayerPlaying:NO];
[self notifySetReady:false];
@@ -762,7 +767,9 @@
/// MG
- (void)destroyMG {
if (self.hostDelegate.getRoomInfo.type == RoomType_MiniGame) {
[self.fsmAPP2MG destroyMG];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.fsmAPP2MG destroyMG];
});
}
}

View File

@@ -32,6 +32,7 @@
#import "UserInfoModel.h"
#import "AttachMentModel.h"
#import "LittleGameInfoModel.h"
#import "MicroQueueModel.h"
///View
#import "XPShareView.h"
#import "XPLittleGameRoomListView.h"
@@ -205,6 +206,25 @@
}
}
//
- (BOOL)isInSudGame {
BOOL isGamePlaying = NO;
if (self.hostDelegate.getRoomInfo.type == RoomType_MiniGame) {
for (int i = -1; i<5; i++) {
NSMutableDictionary * micQueue = self.hostDelegate.getMicroQueue;
MicroQueueModel *micSequence = [micQueue objectForKey:[NSString stringWithFormat:@"%d", i]];
if (micSequence == nil || micSequence.userInfo == nil) {
continue;
}
if (micSequence.userInfo.uid == [AccountInfoStorage instance].getUid.integerValue && micSequence.userInfo.gameStatus == LittleGamePlayStatus_Plying) {
isGamePlaying = YES;
break;
}
}
}
return isGamePlaying;
}
#pragma mark - RoomGuestDelegate
- (void)onRoomEntered {
RoomInfoModel* roomInfo = self.hostDelegate.getRoomInfo;
@@ -283,6 +303,16 @@
}
} params:params];
}
- (void)xPRoomLittleGameListView:(XPLittleGameRoomListView *)view didSelectChooseType:(UIButton *)sender {
if ([self isInSudGame]) {
[XCHUDTool showErrorWithMessage:@"游戏中不可切换游戏或玩法!"];
} else {
sender.selected = !sender.selected;
view.tableView.hidden = !sender.selected;
}
}
#pragma mark - Event Response
- (void)showSharePanel {
XPShareItem *cycle = [XPShareItem itemWitTag:XPShareItemTagMoments title:@"朋友圈" imageName:@"share_wechat_circle_normal" disableImageName:@"share_wechat_circle_disable"];

View File

@@ -67,7 +67,7 @@ UIKIT_EXTERN NSString * const kRoomRoomLittleGameMiniStageNotificationKey;
#pragma mark -
- (void)changeViewState:(NSNotification *)notification {
NSDictionary * dic = notification.object;
self.hidden = ![[dic objectForKey:@"isMini"] boolValue];
self.hidden = [[dic objectForKey:@"isMini"] boolValue];
}
@end

View File

@@ -465,6 +465,25 @@
return array;
}
//
- (BOOL)isInSudGame {
BOOL isGamePlaying = NO;
if (self.cardInfo.roomInfo.type == RoomType_MiniGame) {
for (int i = -1; i<5; i++) {
NSMutableDictionary * micQueue = self.cardInfo.micQueue;
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;
}
#pragma mark - XPUserCardProtocol
- (void)onGetUserInfoSuccess:(UserInfoModel *)userInfo {
@@ -682,26 +701,47 @@
break;
case UserCardItemType_KickOut:
{
NSString *message = [NSString stringWithFormat:@"是否需要将%@踢出房间?",self.targetUserInfo.nick];
TTAlertConfig *config = [[TTAlertConfig alloc] init];
config.title = @"操作提醒";
config.message = message;
[TTPopup alertWithConfig:config confirmHandler:^{
[self.presenter makeKickUser:self.cardInfo.uid roomId:roomId];
} cancelHandler:^{
}];
if ([self isInSudGame]) {
NSString *message = [NSString stringWithFormat:@"游戏模式下默认该玩家退出游戏是否要将此用户踢出房间?"];
TTAlertConfig *config = [[TTAlertConfig alloc] init];
config.title = @"";
config.message = message;
[TTPopup alertWithConfig:config confirmHandler:^{
[self.presenter makeKickUser:self.cardInfo.uid roomId:roomId];
} cancelHandler:^{
}];
} else {
NSString *message = [NSString stringWithFormat:@"是否需要将%@踢出房间?",self.targetUserInfo.nick];
TTAlertConfig *config = [[TTAlertConfig alloc] init];
config.title = @"操作提醒";
config.message = message;
[TTPopup alertWithConfig:config confirmHandler:^{
[self.presenter makeKickUser:self.cardInfo.uid roomId:roomId];
} cancelHandler:^{
}];
}
}
break;
case UserCardItemType_Black:
{
NSString *title = [NSString stringWithFormat:@"你正在拉黑%@",self.targetUserInfo.nick];
TTAlertConfig *config = [[TTAlertConfig alloc] init];
config.title = title;
config.message = @"拉黑后他将无法入此房间";
[TTPopup alertWithConfig:config confirmHandler:^{
[self.presenter makeUserBlack:self.cardInfo.uid roomId:roomId];
} cancelHandler:^{
}];
if ([self isInSudGame]) {
TTAlertConfig *config = [[TTAlertConfig alloc] init];
config.title = @"";
config.message = [NSString stringWithFormat: @"是否将%@加入黑名单?加入后他将无法入此房间游戏模式下默认该玩家退出游戏", self.targetUserInfo.nick];
[TTPopup alertWithConfig:config confirmHandler:^{
[self.presenter makeUserBlack:self.cardInfo.uid roomId:roomId];
} cancelHandler:^{
}];
} else {
NSString *title = [NSString stringWithFormat:@"你正在拉黑%@",self.targetUserInfo.nick];
TTAlertConfig *config = [[TTAlertConfig alloc] init];
config.title = title;
config.message = @"拉黑后他将无法加入此房间";
[TTPopup alertWithConfig:config confirmHandler:^{
[self.presenter makeUserBlack:self.cardInfo.uid roomId:roomId];
} cancelHandler:^{
}];
}
}
break;
case UserCardItemType_Manager:
@@ -755,7 +795,23 @@
case UserCardMicroType_UpDown:
{
if (sender.selected) {
[self.presenter kickDownMicro:self.cardInfo.position roomId:roomId];
if ([self isInSudGame]) {
if (self.cardInfo.uid.integerValue == [AccountInfoStorage instance].getUid.integerValue) {
[self showErrorToast:@"游戏中不可主动下麦!"];
[self dismissViewControllerAnimated:YES completion:nil];
} else {
TTAlertConfig *config = [[TTAlertConfig alloc] init];
config.message = @"抱Ta下麦后默认该玩家退出游戏是否继续";
[TTPopup alertWithConfig:config confirmHandler:^{
[self.presenter kickDownMicro:self.cardInfo.position roomId:roomId];
} cancelHandler:^{
}];
}
return;
}else {
[self.presenter kickDownMicro:self.cardInfo.position roomId:roomId];
}
} else {
self.operaStackView.hidden = YES;
int micCount = self.cardInfo.roomInfo.type == RoomType_Anchor ? 4 : 9;

View File

@@ -285,11 +285,12 @@ UIKIT_EXTERN NSString * const kRoomMiniNotificationKey;
} else {
return;
}
if (!self.stageView.superview) {
[self.view insertSubview:self.stageView belowSubview:self.roomHeaderView];
}
if (self.roomInfo.type == RoomType_MiniGame) {
[self.stageView mas_remakeConstraints:^(MASConstraintMaker *make) {
@@ -712,6 +713,7 @@ UIKIT_EXTERN NSString * const kRoomMiniNotificationKey;
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 handleSelfInExitEvent];
[self.littleGameView destroyMG];
[self dismissViewControllerAnimated:YES completion:nil];
});
@@ -720,6 +722,7 @@ UIKIT_EXTERN NSString * const kRoomMiniNotificationKey;
} else {
[self.presenter exitNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId]];
[[RtcManager instance] exitRoom];
[self.littleGameView handleSelfInExitEvent];
[self.littleGameView destroyMG];
[self dismissViewControllerAnimated:YES completion:nil];
}
@@ -743,6 +746,7 @@ UIKIT_EXTERN NSString * const kRoomMiniNotificationKey;
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 handleSelfInExitEvent];
[self.littleGameView destroyMG];
[self dismissViewControllerAnimated:YES completion:nil];
});
@@ -751,6 +755,7 @@ UIKIT_EXTERN NSString * const kRoomMiniNotificationKey;
} else {
[self.presenter exitNIMRoom:[NSString stringWithFormat:@"%ld", self.roomInfo.roomId]];
[[RtcManager instance] exitRoom];
[self.littleGameView handleSelfInExitEvent];
[self.littleGameView destroyMG];
[self dismissViewControllerAnimated:YES completion:nil];
}