diff --git a/YuMi.xcodeproj/project.pbxproj b/YuMi.xcodeproj/project.pbxproj index 868e16ef..856e7bab 100644 --- a/YuMi.xcodeproj/project.pbxproj +++ b/YuMi.xcodeproj/project.pbxproj @@ -289,6 +289,8 @@ 237701122BCF742C00D661F1 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 237701112BCF742C00D661F1 /* libz.tbd */; }; 237701192BD6143700D661F1 /* pi_happy_egg_smash.svga in Resources */ = {isa = PBXBuildFile; fileRef = 237701182BD6143700D661F1 /* pi_happy_egg_smash.svga */; }; 237852A12C072D8D00E360AC /* MSRoomGameModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 237852A02C072D8D00E360AC /* MSRoomGameModel.m */; }; + 237852A42C082A9800E360AC /* MSRoomGameSendTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 237852A32C082A9800E360AC /* MSRoomGameSendTextView.m */; }; + 237852A72C08764B00E360AC /* MSRoomGameResultsModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 237852A62C08764B00E360AC /* MSRoomGameResultsModel.m */; }; 237B94BC2A984DA7007853E3 /* XPTrumpetPresenter.m in Sources */ = {isa = PBXBuildFile; fileRef = 237B94AE2A984DA7007853E3 /* XPTrumpetPresenter.m */; }; 237B94BD2A984DA7007853E3 /* XPNobleTrumpetModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 237B94B32A984DA7007853E3 /* XPNobleTrumpetModel.m */; }; 237B94BE2A984DA7007853E3 /* XPRoomTrumpetViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 237B94B72A984DA7007853E3 /* XPRoomTrumpetViewController.m */; }; @@ -2110,6 +2112,10 @@ 237701182BD6143700D661F1 /* pi_happy_egg_smash.svga */ = {isa = PBXFileReference; lastKnownFileType = file; path = pi_happy_egg_smash.svga; sourceTree = ""; }; 2378529F2C072D8D00E360AC /* MSRoomGameModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSRoomGameModel.h; sourceTree = ""; }; 237852A02C072D8D00E360AC /* MSRoomGameModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSRoomGameModel.m; sourceTree = ""; }; + 237852A22C082A9800E360AC /* MSRoomGameSendTextView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSRoomGameSendTextView.h; sourceTree = ""; }; + 237852A32C082A9800E360AC /* MSRoomGameSendTextView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSRoomGameSendTextView.m; sourceTree = ""; }; + 237852A52C08764B00E360AC /* MSRoomGameResultsModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSRoomGameResultsModel.h; sourceTree = ""; }; + 237852A62C08764B00E360AC /* MSRoomGameResultsModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSRoomGameResultsModel.m; sourceTree = ""; }; 237B94AD2A984DA7007853E3 /* XPTrumpetPresenter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XPTrumpetPresenter.h; sourceTree = ""; }; 237B94AE2A984DA7007853E3 /* XPTrumpetPresenter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XPTrumpetPresenter.m; sourceTree = ""; }; 237B94B02A984DA7007853E3 /* XPRoomTrumpetProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XPRoomTrumpetProtocol.h; sourceTree = ""; }; @@ -6063,6 +6069,8 @@ 239D0FD72C047DD8002977CE /* MSTabbarRoomGameModel.m */, 2378529F2C072D8D00E360AC /* MSRoomGameModel.h */, 237852A02C072D8D00E360AC /* MSRoomGameModel.m */, + 237852A52C08764B00E360AC /* MSRoomGameResultsModel.h */, + 237852A62C08764B00E360AC /* MSRoomGameResultsModel.m */, ); path = Model; sourceTree = ""; @@ -6118,6 +6126,8 @@ 239D0FF62C05BD2A002977CE /* MSRoomGameVictoryView.m */, 239D0FFB2C05D086002977CE /* MSRoomGameQuitGameView.h */, 239D0FFC2C05D086002977CE /* MSRoomGameQuitGameView.m */, + 237852A22C082A9800E360AC /* MSRoomGameSendTextView.h */, + 237852A32C082A9800E360AC /* MSRoomGameSendTextView.m */, ); path = SubView; sourceTree = ""; @@ -11322,6 +11332,7 @@ E87A24F1272935920086A794 /* XPMessageRemoteExtModel.m in Sources */, E8D34D5028080362009C4835 /* XPMineDataGiftTableViewCell.m in Sources */, E87C54BE2823CC5B0051AA11 /* XPMineResetLoginPwdPresenter.m in Sources */, + 237852A42C082A9800E360AC /* MSRoomGameSendTextView.m in Sources */, E85E7B322A4EB0D300B6D00A /* XPGuildAnchorIncomeSectionView.m in Sources */, E87C0AA027D9DE6400CB2241 /* RoomFaceSendInfoModel.m in Sources */, 1464C5F629A4CA8C00AF7C94 /* XPIAPRechargeCollectionViewCell.m in Sources */, @@ -12058,6 +12069,7 @@ 239D0FDB2C047F24002977CE /* MSTabbarRoomGameCell.m in Sources */, 239D0FB02BFD8C4D002977CE /* MSRoomSetingBackdropVC.m in Sources */, 235714982BEDF54E004C81D6 /* MsRoomMessageMainView.m in Sources */, + 237852A72C08764B00E360AC /* MSRoomGameResultsModel.m in Sources */, 9BE9F10227FEE5C200667200 /* XPAnchorFansTaskDetailModel.m in Sources */, E8E0DAE6285C280E00566A2F /* XPSessionFindNewAlertView.m in Sources */, E85E7B1A2A4EB0D200B6D00A /* XPMineGoldIncomeRecordVC.m in Sources */, diff --git a/YuMi/Appdelegate/AppDelegate.m b/YuMi/Appdelegate/AppDelegate.m index 196abe31..c3ae6da9 100644 --- a/YuMi/Appdelegate/AppDelegate.m +++ b/YuMi/Appdelegate/AppDelegate.m @@ -88,6 +88,7 @@ UIKIT_EXTERN NSString * const kOpenRoomNotification; } - (void)applicationDidBecomeActive:(UIApplication *)application { [self getAdvertisingTrackingAuthority]; + [[NSNotificationCenter defaultCenter]postNotificationName:@"kAppDidBecomeActive" object:nil]; } - (void)getAdvertisingTrackingAuthority { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ diff --git a/YuMi/Assets.xcassets/main/tab_gameHome_game_normal.imageset/tab_gameHome_game_normal@2x.png b/YuMi/Assets.xcassets/main/tab_gameHome_game_normal.imageset/tab_gameHome_game_normal@2x.png index d35e52ee..84220f87 100644 Binary files a/YuMi/Assets.xcassets/main/tab_gameHome_game_normal.imageset/tab_gameHome_game_normal@2x.png and b/YuMi/Assets.xcassets/main/tab_gameHome_game_normal.imageset/tab_gameHome_game_normal@2x.png differ diff --git a/YuMi/Assets.xcassets/main/tab_gameHome_game_normal.imageset/tab_gameHome_game_normal@3x.png b/YuMi/Assets.xcassets/main/tab_gameHome_game_normal.imageset/tab_gameHome_game_normal@3x.png index 604dc360..e651f252 100644 Binary files a/YuMi/Assets.xcassets/main/tab_gameHome_game_normal.imageset/tab_gameHome_game_normal@3x.png and b/YuMi/Assets.xcassets/main/tab_gameHome_game_normal.imageset/tab_gameHome_game_normal@3x.png differ diff --git a/YuMi/Assets.xcassets/main/tab_gameHome_game_selected.imageset/tab_gameHome_game_selected@2x.png b/YuMi/Assets.xcassets/main/tab_gameHome_game_selected.imageset/tab_gameHome_game_selected@2x.png index 5d3bffab..54f505c4 100644 Binary files a/YuMi/Assets.xcassets/main/tab_gameHome_game_selected.imageset/tab_gameHome_game_selected@2x.png and b/YuMi/Assets.xcassets/main/tab_gameHome_game_selected.imageset/tab_gameHome_game_selected@2x.png differ diff --git a/YuMi/Assets.xcassets/main/tab_gameHome_game_selected.imageset/tab_gameHome_game_selected@3x.png b/YuMi/Assets.xcassets/main/tab_gameHome_game_selected.imageset/tab_gameHome_game_selected@3x.png index a243ada0..d644bc75 100644 Binary files a/YuMi/Assets.xcassets/main/tab_gameHome_game_selected.imageset/tab_gameHome_game_selected@3x.png and b/YuMi/Assets.xcassets/main/tab_gameHome_game_selected.imageset/tab_gameHome_game_selected@3x.png differ diff --git a/YuMi/Assets.xcassets/main/tab_gameHome_normal.imageset/tab_gameHome_normal@2x.png b/YuMi/Assets.xcassets/main/tab_gameHome_normal.imageset/tab_gameHome_normal@2x.png index 8afb8501..e69d3ab7 100644 Binary files a/YuMi/Assets.xcassets/main/tab_gameHome_normal.imageset/tab_gameHome_normal@2x.png and b/YuMi/Assets.xcassets/main/tab_gameHome_normal.imageset/tab_gameHome_normal@2x.png differ diff --git a/YuMi/Assets.xcassets/main/tab_gameHome_normal.imageset/tab_gameHome_normal@3x.png b/YuMi/Assets.xcassets/main/tab_gameHome_normal.imageset/tab_gameHome_normal@3x.png index 65efae04..11452be6 100644 Binary files a/YuMi/Assets.xcassets/main/tab_gameHome_normal.imageset/tab_gameHome_normal@3x.png and b/YuMi/Assets.xcassets/main/tab_gameHome_normal.imageset/tab_gameHome_normal@3x.png differ diff --git a/YuMi/Assets.xcassets/main/tab_gameHome_selected.imageset/tab_gameHome_selected@2x.png b/YuMi/Assets.xcassets/main/tab_gameHome_selected.imageset/tab_gameHome_selected@2x.png index a4e0e8d9..04be2bbd 100644 Binary files a/YuMi/Assets.xcassets/main/tab_gameHome_selected.imageset/tab_gameHome_selected@2x.png and b/YuMi/Assets.xcassets/main/tab_gameHome_selected.imageset/tab_gameHome_selected@2x.png differ diff --git a/YuMi/Assets.xcassets/main/tab_gameHome_selected.imageset/tab_gameHome_selected@3x.png b/YuMi/Assets.xcassets/main/tab_gameHome_selected.imageset/tab_gameHome_selected@3x.png index 8c65bb97..a607abef 100644 Binary files a/YuMi/Assets.xcassets/main/tab_gameHome_selected.imageset/tab_gameHome_selected@3x.png and b/YuMi/Assets.xcassets/main/tab_gameHome_selected.imageset/tab_gameHome_selected@3x.png differ diff --git a/YuMi/Assets.xcassets/main/tab_message_normal.imageset/tab_message_normal@2x.png b/YuMi/Assets.xcassets/main/tab_message_normal.imageset/tab_message_normal@2x.png index 9c769898..0ccb9120 100644 Binary files a/YuMi/Assets.xcassets/main/tab_message_normal.imageset/tab_message_normal@2x.png and b/YuMi/Assets.xcassets/main/tab_message_normal.imageset/tab_message_normal@2x.png differ diff --git a/YuMi/Assets.xcassets/main/tab_message_normal.imageset/tab_message_normal@3x.png b/YuMi/Assets.xcassets/main/tab_message_normal.imageset/tab_message_normal@3x.png index f7293980..66ce7c69 100644 Binary files a/YuMi/Assets.xcassets/main/tab_message_normal.imageset/tab_message_normal@3x.png and b/YuMi/Assets.xcassets/main/tab_message_normal.imageset/tab_message_normal@3x.png differ diff --git a/YuMi/Assets.xcassets/main/tab_message_selected.imageset/tab_message_selected@2x.png b/YuMi/Assets.xcassets/main/tab_message_selected.imageset/tab_message_selected@2x.png index e1db7ff9..3db2ab0a 100644 Binary files a/YuMi/Assets.xcassets/main/tab_message_selected.imageset/tab_message_selected@2x.png and b/YuMi/Assets.xcassets/main/tab_message_selected.imageset/tab_message_selected@2x.png differ diff --git a/YuMi/Assets.xcassets/main/tab_message_selected.imageset/tab_message_selected@3x.png b/YuMi/Assets.xcassets/main/tab_message_selected.imageset/tab_message_selected@3x.png index f213e82f..643bbd8e 100644 Binary files a/YuMi/Assets.xcassets/main/tab_message_selected.imageset/tab_message_selected@3x.png and b/YuMi/Assets.xcassets/main/tab_message_selected.imageset/tab_message_selected@3x.png differ diff --git a/YuMi/Assets.xcassets/main/tab_mine_normal.imageset/tab_mine_normal@2x.png b/YuMi/Assets.xcassets/main/tab_mine_normal.imageset/tab_mine_normal@2x.png index e38a3c52..c8cdafa7 100644 Binary files a/YuMi/Assets.xcassets/main/tab_mine_normal.imageset/tab_mine_normal@2x.png and b/YuMi/Assets.xcassets/main/tab_mine_normal.imageset/tab_mine_normal@2x.png differ diff --git a/YuMi/Assets.xcassets/main/tab_mine_normal.imageset/tab_mine_normal@3x.png b/YuMi/Assets.xcassets/main/tab_mine_normal.imageset/tab_mine_normal@3x.png index e34460df..57465a0c 100644 Binary files a/YuMi/Assets.xcassets/main/tab_mine_normal.imageset/tab_mine_normal@3x.png and b/YuMi/Assets.xcassets/main/tab_mine_normal.imageset/tab_mine_normal@3x.png differ diff --git a/YuMi/Assets.xcassets/main/tab_mine_selected.imageset/tab_mine_selected@2x.png b/YuMi/Assets.xcassets/main/tab_mine_selected.imageset/tab_mine_selected@2x.png index 0fa93c24..c4788730 100644 Binary files a/YuMi/Assets.xcassets/main/tab_mine_selected.imageset/tab_mine_selected@2x.png and b/YuMi/Assets.xcassets/main/tab_mine_selected.imageset/tab_mine_selected@2x.png differ diff --git a/YuMi/Assets.xcassets/main/tab_mine_selected.imageset/tab_mine_selected@3x.png b/YuMi/Assets.xcassets/main/tab_mine_selected.imageset/tab_mine_selected@3x.png index 7c9657e4..f73879cb 100644 Binary files a/YuMi/Assets.xcassets/main/tab_mine_selected.imageset/tab_mine_selected@3x.png and b/YuMi/Assets.xcassets/main/tab_mine_selected.imageset/tab_mine_selected@3x.png differ diff --git a/YuMi/Assets.xcassets/main/tab_monents_normal.imageset/tab_monents_normal@2x.png b/YuMi/Assets.xcassets/main/tab_monents_normal.imageset/tab_monents_normal@2x.png index de7f4392..df659038 100644 Binary files a/YuMi/Assets.xcassets/main/tab_monents_normal.imageset/tab_monents_normal@2x.png and b/YuMi/Assets.xcassets/main/tab_monents_normal.imageset/tab_monents_normal@2x.png differ diff --git a/YuMi/Assets.xcassets/main/tab_monents_normal.imageset/tab_monents_normal@3x.png b/YuMi/Assets.xcassets/main/tab_monents_normal.imageset/tab_monents_normal@3x.png index ad47fd94..12d00d1b 100644 Binary files a/YuMi/Assets.xcassets/main/tab_monents_normal.imageset/tab_monents_normal@3x.png and b/YuMi/Assets.xcassets/main/tab_monents_normal.imageset/tab_monents_normal@3x.png differ diff --git a/YuMi/Assets.xcassets/main/tab_monents_select.imageset/tab_monents_select@2x.png b/YuMi/Assets.xcassets/main/tab_monents_select.imageset/tab_monents_select@2x.png index 0014b849..111b2d0f 100644 Binary files a/YuMi/Assets.xcassets/main/tab_monents_select.imageset/tab_monents_select@2x.png and b/YuMi/Assets.xcassets/main/tab_monents_select.imageset/tab_monents_select@2x.png differ diff --git a/YuMi/Assets.xcassets/main/tab_monents_select.imageset/tab_monents_select@3x.png b/YuMi/Assets.xcassets/main/tab_monents_select.imageset/tab_monents_select@3x.png index f24e5286..790c9e93 100644 Binary files a/YuMi/Assets.xcassets/main/tab_monents_select.imageset/tab_monents_select@3x.png and b/YuMi/Assets.xcassets/main/tab_monents_select.imageset/tab_monents_select@3x.png differ diff --git a/YuMi/Global/YUMIHtmlUrl.m b/YuMi/Global/YUMIHtmlUrl.m index e204b886..79d135dc 100644 --- a/YuMi/Global/YUMIHtmlUrl.m +++ b/YuMi/Global/YUMIHtmlUrl.m @@ -22,7 +22,7 @@ NSString * const URLWithType(URLType type) { @(kGoldEarningsRecord) : @"modules/myincome/index.html#/GoldLog",///金币收益记录 @(kCandyTreeRuleURL) : @"modules/rule/newWishingWellRule.html",///糖果树规则 modules/rank/index.html#/wishingWellRule @(kChannelUrl) : @"modules/%@/index.html?channelType=%@&deviceId=%@", - @(kLUDOUrl) : @"molistar/modules/gameRank/index.html"///LUDO排行榜路径 + @(kLUDOUrl) : @"modules/gameRank/index.html"///LUDO排行榜路径 }; NSString * newUrl = [newDic objectForKey:@(type)]; if(newUrl != nil){ diff --git a/YuMi/Modules/YMMessage/Model/AttachmentModel.h b/YuMi/Modules/YMMessage/Model/AttachmentModel.h index c9a50cef..ba99a90d 100644 --- a/YuMi/Modules/YMMessage/Model/AttachmentModel.h +++ b/YuMi/Modules/YMMessage/Model/AttachmentModel.h @@ -671,7 +671,7 @@ typedef NS_ENUM(NSUInteger, CustomMessageTypeRoomGame) { Custom_Message_Sub_Room_Game_Match_Success = 1091,//匹配成功 Custom_Message_Sub_Room_Game_Match_Fail = 1092,//匹配失败 - + Custom_Message_Sub_Room_Game_Early_Exit = 1093,//提前退出游戏 }; ///家族新协议 diff --git a/YuMi/Modules/YMNewHome/View/CustomView/XPNewHomeHeadView.m b/YuMi/Modules/YMNewHome/View/CustomView/XPNewHomeHeadView.m index 5cc51624..013a4b7d 100644 --- a/YuMi/Modules/YMNewHome/View/CustomView/XPNewHomeHeadView.m +++ b/YuMi/Modules/YMNewHome/View/CustomView/XPNewHomeHeadView.m @@ -90,7 +90,10 @@ _itemList = itemList; self.collectionView.scrollEnabled = _itemList.count > 2; self.collectionView.hidden = _itemList.count == 0; - [self.collectionView reloadData]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [self.collectionView reloadData]; + }); + if (_itemList.count == 0){ [self.collectionView mas_remakeConstraints:^(MASConstraintMaker *make) { make.leading.mas_equalTo(0); diff --git a/YuMi/Modules/YMRoom/View/RoomGame/Api/Api+MSRoomGameApi.h b/YuMi/Modules/YMRoom/View/RoomGame/Api/Api+MSRoomGameApi.h index 71b51f05..d846c1d4 100644 --- a/YuMi/Modules/YMRoom/View/RoomGame/Api/Api+MSRoomGameApi.h +++ b/YuMi/Modules/YMRoom/View/RoomGame/Api/Api+MSRoomGameApi.h @@ -16,6 +16,8 @@ NS_ASSUME_NONNULL_BEGIN +(void)startMatchGame:(HttpRequestHelperCompletion)completion roomId:(NSString *)roomId mgId:(NSString *)mgId gameMode:(NSString *)gameMode; ///得到房间详情 +(void)getRoomGameDetails:(HttpRequestHelperCompletion)completion roomType:(NSString *)roomType; +///退出房间 ++(void)closeRoomGame:(HttpRequestHelperCompletion)completion roomId:(NSString *)roomId; @end NS_ASSUME_NONNULL_END diff --git a/YuMi/Modules/YMRoom/View/RoomGame/Api/Api+MSRoomGameApi.m b/YuMi/Modules/YMRoom/View/RoomGame/Api/Api+MSRoomGameApi.m index 93c6653d..e2097ad2 100644 --- a/YuMi/Modules/YMRoom/View/RoomGame/Api/Api+MSRoomGameApi.m +++ b/YuMi/Modules/YMRoom/View/RoomGame/Api/Api+MSRoomGameApi.m @@ -20,4 +20,8 @@ +(void)getRoomGameDetails:(HttpRequestHelperCompletion)completion roomType:(NSString *)roomType{ [self makeRequest:@"chatRoom/getByType" method:HttpRequestHelperMethodGET completion:completion, __FUNCTION__,roomType,nil]; } +///退出房间 ++(void)closeRoomGame:(HttpRequestHelperCompletion)completion roomId:(NSString *)roomId{ + [self makeRequest:@"miniGame/nav/close" method:HttpRequestHelperMethodGET completion:completion, __FUNCTION__,roomId,nil]; +} @end diff --git a/YuMi/Modules/YMRoom/View/RoomGame/Model/MSRoomGameModel.h b/YuMi/Modules/YMRoom/View/RoomGame/Model/MSRoomGameModel.h index 6dbac76f..c86d3132 100644 --- a/YuMi/Modules/YMRoom/View/RoomGame/Model/MSRoomGameModel.h +++ b/YuMi/Modules/YMRoom/View/RoomGame/Model/MSRoomGameModel.h @@ -48,6 +48,7 @@ typedef enum : NSUInteger { @property(nonatomic,copy) NSArray *scores; @property(nonatomic,copy) NSString *configJson; @property(nonatomic,assign) MSRoomGameInfoModelType matchStatus; +@property(nonatomic,copy) NSString *matchRoundId; diff --git a/YuMi/Modules/YMRoom/View/RoomGame/Model/MSRoomGameResultsModel.h b/YuMi/Modules/YMRoom/View/RoomGame/Model/MSRoomGameResultsModel.h new file mode 100644 index 00000000..6ba0432b --- /dev/null +++ b/YuMi/Modules/YMRoom/View/RoomGame/Model/MSRoomGameResultsModel.h @@ -0,0 +1,20 @@ +// +// MSRoomGameResultsModel.h +// YuMi +// +// Created by duoban on 2024/5/30. +// + +#import "PIBaseModel.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface MSRoomGameResultsModel : PIBaseModel +@property(nonatomic,assign) int rank; +@property(nonatomic,copy) NSString *uid; +@property(nonatomic,copy) NSString *avatar; +@property(nonatomic,copy) NSString *nick; +@property(nonatomic,strong) NSNumber *winNum; +@end + +NS_ASSUME_NONNULL_END diff --git a/YuMi/Modules/YMRoom/View/RoomGame/Model/MSRoomGameResultsModel.m b/YuMi/Modules/YMRoom/View/RoomGame/Model/MSRoomGameResultsModel.m new file mode 100644 index 00000000..41c0df41 --- /dev/null +++ b/YuMi/Modules/YMRoom/View/RoomGame/Model/MSRoomGameResultsModel.m @@ -0,0 +1,12 @@ +// +// MSRoomGameResultsModel.m +// YuMi +// +// Created by duoban on 2024/5/30. +// + +#import "MSRoomGameResultsModel.h" + +@implementation MSRoomGameResultsModel + +@end diff --git a/YuMi/Modules/YMRoom/View/RoomGame/Model/MSTabbarRoomGameModel.h b/YuMi/Modules/YMRoom/View/RoomGame/Model/MSTabbarRoomGameModel.h index 208e0022..4b4b3175 100644 --- a/YuMi/Modules/YMRoom/View/RoomGame/Model/MSTabbarRoomGameModel.h +++ b/YuMi/Modules/YMRoom/View/RoomGame/Model/MSTabbarRoomGameModel.h @@ -26,5 +26,6 @@ NS_ASSUME_NONNULL_BEGIN @property(nonatomic,copy) NSString *modeName; @property(nonatomic,copy) NSString *ruleUrl; @property(nonatomic,copy) NSString *ticket; +@property(nonatomic,copy) NSString *roomId; @end NS_ASSUME_NONNULL_END diff --git a/YuMi/Modules/YMRoom/View/RoomGame/Presenter/MSRoomGamePresenter.h b/YuMi/Modules/YMRoom/View/RoomGame/Presenter/MSRoomGamePresenter.h index 168eff2c..5ad0caab 100644 --- a/YuMi/Modules/YMRoom/View/RoomGame/Presenter/MSRoomGamePresenter.h +++ b/YuMi/Modules/YMRoom/View/RoomGame/Presenter/MSRoomGamePresenter.h @@ -20,6 +20,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)enterNIMRoom:(NSString *)roomId user:(UserInfoModel *)userInfo; ///退出房间 - (void)exitNIMRoom:(NSString *)roomId; +///退出房间 +-(void)closeRoomGameWithRoomId:(NSString *)roomId; @end NS_ASSUME_NONNULL_END diff --git a/YuMi/Modules/YMRoom/View/RoomGame/Presenter/MSRoomGamePresenter.m b/YuMi/Modules/YMRoom/View/RoomGame/Presenter/MSRoomGamePresenter.m index 736b603c..7935d2f4 100644 --- a/YuMi/Modules/YMRoom/View/RoomGame/Presenter/MSRoomGamePresenter.m +++ b/YuMi/Modules/YMRoom/View/RoomGame/Presenter/MSRoomGamePresenter.m @@ -118,4 +118,10 @@ [[NIMSDK sharedSDK].chatroomManager exitChatroom:roomId completion:nil]; } +///退出房间 +-(void)closeRoomGameWithRoomId:(NSString *)roomId{ + [Api closeRoomGame:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { + + } roomId:roomId]; +} @end diff --git a/YuMi/Modules/YMRoom/View/RoomGame/View/Cell/MSRoomGameVictoryCell.h b/YuMi/Modules/YMRoom/View/RoomGame/View/Cell/MSRoomGameVictoryCell.h index 58b0ab7e..bcf1627e 100644 --- a/YuMi/Modules/YMRoom/View/RoomGame/View/Cell/MSRoomGameVictoryCell.h +++ b/YuMi/Modules/YMRoom/View/RoomGame/View/Cell/MSRoomGameVictoryCell.h @@ -6,11 +6,11 @@ // #import - +#import "MSRoomGameResultsModel.h" NS_ASSUME_NONNULL_BEGIN @interface MSRoomGameVictoryCell : UITableViewCell - +@property(nonatomic,strong) MSRoomGameResultsModel *resultsModel; @end NS_ASSUME_NONNULL_END diff --git a/YuMi/Modules/YMRoom/View/RoomGame/View/Cell/MSRoomGameVictoryCell.m b/YuMi/Modules/YMRoom/View/RoomGame/View/Cell/MSRoomGameVictoryCell.m index 97a2db87..0b522f13 100644 --- a/YuMi/Modules/YMRoom/View/RoomGame/View/Cell/MSRoomGameVictoryCell.m +++ b/YuMi/Modules/YMRoom/View/RoomGame/View/Cell/MSRoomGameVictoryCell.m @@ -80,6 +80,18 @@ make.trailing.equalTo(self.coinView.mas_leading).mas_offset(-kGetScaleWidth(5)); }]; } +- (void)setResultsModel:(MSRoomGameResultsModel *)resultsModel{ + _resultsModel = resultsModel; + _rankView.image = _resultsModel.rank == 1 ? kImage(@"ms_room_game_victory_rank_first"):kImage(@"ms_room_game_victory_rank_second"); + _avatarView.image = nil; + [_avatarView loadImageWithUrl:_resultsModel.avatar completion:^(UIImage * _Nullable image, NSURL * _Nonnull url) { + self.avatarView.image = image; + }]; + _nameView.text = _resultsModel.nick; + _bgImageView.image = _resultsModel.rank == 1 ? kImage(@"ms_room_game_victory_bg_first"):kImage(@"ms_room_game_victory_bg_second"); + _bgCoinView.image = _resultsModel.rank == 1 ? kImage(@"ms_room_game_victory_coin_bg_first"):kImage(@"ms_room_game_victory_coin_bg_second"); + _coinNumView.text = _resultsModel.rank == 1 ? [NSString stringWithFormat:@"+%@",_resultsModel.winNum.stringValue]:_resultsModel.winNum.stringValue; +} #pragma mark - 懒加载 - (UIImageView *)bgImageView{ if(!_bgImageView){ diff --git a/YuMi/Modules/YMRoom/View/RoomGame/View/MSRoomGameVC.m b/YuMi/Modules/YMRoom/View/RoomGame/View/MSRoomGameVC.m index 6b5a90b1..82a2869e 100644 --- a/YuMi/Modules/YMRoom/View/RoomGame/View/MSRoomGameVC.m +++ b/YuMi/Modules/YMRoom/View/RoomGame/View/MSRoomGameVC.m @@ -10,14 +10,19 @@ #import "MsRoomMessagChatHallView.h" #import "MSRoomGameMsgView.h" #import "MSRoomGameSendMsgView.h" -#import "XPRoomLittleGameContainerView.h" +#import #import "MSRoomGameVictoryView.h" #import "MSRoomGameQuitGameView.h" #import "MSRoomGamePresenter.h" #import "MSRoomGameProtocol.h" #import #import "AttachmentModel.h" -@interface MSRoomGameVC () +#import "MSRoomGameSendTextView.h" +#import "MSRoomGameView.h" +#import "MSRoomGameResultsModel.h" +#import "Api.h" +#import "XPIAPRechargeViewController.h" +@interface MSRoomGameVC () @property(nonatomic,strong) UIImageView *bgImageView; @property(nonatomic,strong) MSRoomGameHeadView *headView; @property(nonatomic,strong) MsRoomMessagChatHallView *chatView; @@ -25,7 +30,9 @@ @property(nonatomic,copy) NSString *roomId; @property(nonatomic,strong) MSRoomGameSendMsgView *sendMsgView; ///小游戏的容器 -@property (nonatomic,strong) XPRoomLittleGameContainerView *littleGameView; +@property(nonatomic,strong) MSRoomGameView *roomGameView; +@property(nonatomic,strong) WalletInfoModel *coinModel; +@property(nonatomic,assign) BOOL isShowResults; @end @implementation MSRoomGameVC @@ -37,7 +44,7 @@ [[NIMSDK sharedSDK].chatManager removeDelegate:self]; [[NIMSDK sharedSDK].loginManager removeDelegate:self]; [[NIMSDK sharedSDK].conversationManager removeDelegate:self]; - + [[NSNotificationCenter defaultCenter]removeObserver:self]; } - (void)viewDidLoad { [super viewDidLoad]; @@ -48,22 +55,32 @@ [[NIMSDK sharedSDK].chatManager addDelegate:self]; [[NIMSDK sharedSDK].loginManager addDelegate:self]; [[NIMSDK sharedSDK].conversationManager addDelegate:self]; - + [self getCoinNum]; + [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(appDidBecomeActive) name:@"kAppDidBecomeActive" object:nil]; + [self networkReachability]; +} +-(void)getCoinNum{ + NSString * uid = [AccountInfoStorage instance].getUid; + NSString * ticket = [AccountInfoStorage instance].getTicket; + [Api getUserWalletInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { + WalletInfoModel * model = [WalletInfoModel modelWithDictionary:data.data]; + self.coinModel = model; + } uid:uid ticket:ticket]; } -(void)installUI{ [self.view addSubview:self.bgImageView]; - [self.view addSubview:self.littleGameView]; [self.view addSubview:self.headView]; [self.view addSubview:self.msgView]; [self.view addSubview:self.sendMsgView]; + + } + -(void)installConstraints{ [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.view); }]; - [self.littleGameView mas_makeConstraints:^(MASConstraintMaker *make) { - make.edges.equalTo(self.view); - }]; + [self.headView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(kGetScaleWidth(22)); make.leading.trailing.equalTo(self.view).inset(kGetScaleWidth(0)); @@ -82,48 +99,153 @@ - (BOOL)isHiddenNavBar { return YES; } - +-(void)appDidBecomeActive{ + if(self.headView.roomGameModel.data.roundStatus == 0 && self.headView.roomGameModel.data.matchStatus == 1){ + [self.presenter getRoomGameDetailWithRoomType:@"0"]; + } +} +///网络监听 +-(void)networkReachability{ + @kWeakify(self); + [[AFNetworkReachabilityManager sharedManager] startMonitoring]; + [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) { + @kStrongify(self); + switch (status) { + case AFNetworkReachabilityStatusUnknown: + + break; + case AFNetworkReachabilityStatusNotReachable: + + break; + case AFNetworkReachabilityStatusReachableViaWWAN: + case AFNetworkReachabilityStatusReachableViaWiFi: + { + if(self.headView.roomGameModel.data.roundStatus == 0 && self.headView.roomGameModel.data.matchStatus == 1){ + [self.presenter getRoomGameDetailWithRoomType:@"0"]; + } + } + break; + default: + break; + } + }]; +} +#pragma mark -MSRoomGameViewDelegate +- (void)getGameRsultsWithList:(NSArray *)list{ + if(self.isShowResults == YES)return; + self.isShowResults = YES; + MSRoomGameVictoryView *victoryView = [[MSRoomGameVictoryView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)]; + for (MSRoomGameResultsModel *obj in list) { + if([obj.uid isEqualToString:self.headView.mineModel.uid]){ + obj.avatar = self.headView.mineModel.avatar; + obj.nick = self.headView.mineModel.nick; + + } + if([obj.uid isEqualToString:self.headView.rivalModel.uid]){ + obj.avatar = self.headView.rivalModel.avatar; + obj.nick = self.headView.rivalModel.nick; + } + obj.winNum = obj.rank == 1 ? self.chooseGameModel.scores.firstObject : self.chooseGameModel.scores.lastObject; + } + victoryView.delegate = self; + victoryView.resultsList = list; + [TTPopup popupView:victoryView style:TTPopupStyleAlert]; + [self.presenter exitNIMRoom:self.roomId]; + [self.roomGameView handleSelfInExitEvent]; + [self.roomGameView destroyMG]; + self.roomGameView = nil; + [self.headView setDataInNull]; +} +#pragma mark- MSRoomGameSendMsgViewDelegate +- (void)clickSendMsgAction{ + MSRoomGameSendTextView *sendTextView = [[MSRoomGameSendTextView alloc]initWithRoomId:self.roomId userInfo:self.userinfo]; + [self.view addSubview:sendTextView]; +} #pragma mark - MSRoomGameProtocol -(void)getRoomGameDetailsSuccessWithModel:(MSRoomGameModel *)model{ self.headView.roomGameModel = model; + self.headView.userInfo = self.userinfo; self.roomId = model.roomId; [self.presenter enterNIMRoom:model.roomId user:self.userinfo]; + if(model.data.matchStatus == MSRoomGameInfoModelMatchSuccessfully && model.data.roundStatus == 0){ + self.roomGameView.gameModel = model; + if(self.roomGameView.superview == nil){ + [self.bgImageView addSubview:self.roomGameView]; + [self.roomGameView mas_makeConstraints:^(MASConstraintMaker *make) { + make.edges.equalTo(self.bgImageView); + }]; + [self.roomGameView onRoomEntered]; + } + + + }else{ + [self.roomGameView handleSelfInExitEvent]; + [self.roomGameView destroyMG]; + self.roomGameView = nil; + [self.headView setDataInNull]; + + } } #pragma mark -MSRoomGameVictoryViewDelegate - (void)closeGameAction{ - + self.isShowResults = NO; + [self quitGameActionWtihIsColse:YES]; } -(void)rematchGameAction{ - + self.isShowResults = NO; + if(self.coinModel.diamonds.integerValue < self.chooseGameModel.ticket.integerValue){ + TTAlertConfig * config = [[TTAlertConfig alloc] init]; + config.message = YMLocalizedString(@"XPTreasureFairyViewController5"); + config.confirmButtonConfig.title = YMLocalizedString(@"XPTreasureFairyViewController6"); + [TTPopup alertWithConfig:config confirmHandler:^{ + XPIAPRechargeViewController * rechargeVC = [[XPIAPRechargeViewController alloc] init]; + rechargeVC.delegate = self; + [self.navigationController pushViewController:rechargeVC animated:YES]; + } cancelHandler:^{ + + }]; + return; + } + [self.presenter startMatchGameWithroomId:@"" mgId:self.headView.roomGameModel.data.mgId gameMode:self.chooseGameModel.gameMode]; +} +-(void)startMatchGameSuccess{ + [self.presenter getRoomGameDetailWithRoomType:@"0"]; +} +#pragma mark -XPIAPRechargeViewControllerDelegate +-(void)paySuccess{ + [self getCoinNum]; } #pragma mark - MSRoomGameQuitGameViewDelegate - (void)quitGameAction{ + [self quitGameActionWtihIsColse:YES]; + +} +-(void)quitGameActionWtihIsColse:(BOOL)isColse{ + self.isShowResults = YES; + if(isColse == YES){ + [self.presenter closeRoomGameWithRoomId:self.roomId]; + } + [self.presenter exitNIMRoom:self.roomId]; + [self.roomGameView handleSelfInExitEvent]; + [self.roomGameView destroyMG]; [self dismissViewControllerAnimated:YES completion:nil]; } #pragma mark -MSRoomGameHeadViewDelegate - (void)clickQuitGameAction{ + MSRoomGameQuitGameView *quitGameView = [[MSRoomGameQuitGameView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)]; quitGameView.delegate = self; [TTPopup popupView:quitGameView style:TTPopupStyleAlert]; -// MSRoomGameVictoryView *victoryView = [[MSRoomGameVictoryView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)]; -// victoryView.delegate = self; -// [TTPopup popupView:victoryView style:TTPopupStyleAlert]; - - } #pragma mark - NIMChatManagerDelegate - (void)onRecvMessages:(NSArray *)messages { for (NIMMessage * message in messages) { - - // 非房间内消息不处理 if (message.session.sessionType != NIMSessionTypeChatroom) { continue; } - if(![message.session.sessionId isEqualToString:self.roomId]){ - continue; } if (message.messageType == NIMMessageTypeNotification) { @@ -146,16 +268,44 @@ if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) { AttachmentModel * attachment = (AttachmentModel *)obj.attachment; if(attachment.first == CustomMessageType_Chat_Room_Game && attachment.second == Custom_Message_Sub_Room_Game_Match_Success){ - [self.presenter exitNIMRoom:self.roomId]; MSRoomGameModel *model = [MSRoomGameModel modelWithJSON:attachment.data]; + [self.presenter exitNIMRoom:self.roomId]; self.roomId = model.roomId; self.headView.roomGameModel = model; - [self.presenter enterNIMRoom:model.roomId user:self.userinfo]; + [self.presenter enterNIMRoom:model.roomId user:self.userinfo]; + self.roomGameView.gameModel = model; + if(self.roomGameView.superview == nil){ + [self.bgImageView addSubview:self.roomGameView]; + [self.roomGameView mas_makeConstraints:^(MASConstraintMaker *make) { + make.edges.equalTo(self.bgImageView); + }]; + [self.roomGameView onRoomEntered]; + + } + + + }if(attachment.first == CustomMessageType_Chat_Room_Game && attachment.second == Custom_Message_Sub_Room_Game_Match_Fail){ + + MSRoomGameQuitGameView *quitGameView = [[MSRoomGameQuitGameView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)]; + quitGameView.delegate = self; + quitGameView.isNormalFail = YES; + [TTPopup popupView:quitGameView style:TTPopupStyleAlert]; + + }if(attachment.first == CustomMessageType_Chat_Room_Game && attachment.second == Custom_Message_Sub_Room_Game_Early_Exit){ + if(self.isShowResults == YES)return; + self.isShowResults = YES; + NSArray *list = [MSRoomGameResultsModel modelsWithArray:attachment.data[@"results"]]; + MSRoomGameVictoryView *victoryView = [[MSRoomGameVictoryView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)]; + victoryView.delegate = self; + victoryView.resultsList = list; + [TTPopup popupView:victoryView style:TTPopupStyleAlert]; [self.presenter exitNIMRoom:self.roomId]; - [self showErrorToast:YMLocalizedString(@"MSRoomGameVC0")]; - [self dismissViewControllerAnimated:YES completion:nil]; + [self.roomGameView handleSelfInExitEvent]; + [self.roomGameView destroyMG]; + self.roomGameView = nil; + [self.headView setDataInNull]; } } @@ -168,7 +318,7 @@ //发送消息成功回调 - (void)sendMessage:(NIMMessage *)message didCompleteWithError:(NSError *)error { // 非本房间不处理 - if([message.session.sessionId isEqualToString:self.roomId]){ + if(![message.session.sessionId isEqualToString:self.roomId]){ return;; } if (message.messageType == NIMMessageTypeText) { @@ -203,14 +353,16 @@ - (MSRoomGameSendMsgView *)sendMsgView{ if(!_sendMsgView){ _sendMsgView = [[MSRoomGameSendMsgView alloc]initWithFrame:CGRectZero]; + _sendMsgView.delegate = self; } return _sendMsgView; } -- (XPRoomLittleGameContainerView *)littleGameView { - if (!_littleGameView) { - _littleGameView = [[XPRoomLittleGameContainerView alloc] initWithDelegate:self]; - _littleGameView.delegate = self; +- (MSRoomGameView *)roomGameView{ + if(!_roomGameView){ + _roomGameView = [[MSRoomGameView alloc]initWithFrame:CGRectZero]; + _roomGameView.delegate = self; + } - return _littleGameView; + return _roomGameView; } @end diff --git a/YuMi/Modules/YMRoom/View/RoomGame/View/MSTabbarRoomGameVC.m b/YuMi/Modules/YMRoom/View/RoomGame/View/MSTabbarRoomGameVC.m index 766cbaa3..3564088c 100644 --- a/YuMi/Modules/YMRoom/View/RoomGame/View/MSTabbarRoomGameVC.m +++ b/YuMi/Modules/YMRoom/View/RoomGame/View/MSTabbarRoomGameVC.m @@ -15,6 +15,7 @@ #import "MSRoomGameProtocol.h" #import "XPIAPRechargeViewController.h" #import "XPWebViewController.h" +#import "XPRoomHalfWebView.h" @interface MSTabbarRoomGameVC () @property(nonatomic,strong) UIImageView *bgImageView; @property(nonatomic,strong) MSTabbarRoomGameHeadView *headView; @@ -40,6 +41,7 @@ [self installConstraints]; } + -(void)installUI{ [self.view addSubview:self.bgImageView]; [self.view addSubview:self.headView]; @@ -79,6 +81,12 @@ } [self.presenter startMatchGameWithroomId:@"" mgId:self.gameModel.mgId gameMode:model.gameMode]; } +///规则 +-(void)clickRuleActionWithModel:(MSTabbarRoomGameItemModel *)model{ + XPRoomHalfWebView * webView = [[XPRoomHalfWebView alloc] init]; + webView.url = model.ruleUrl; + [TTPopup popupView:webView style:TTPopupStyleActionSheet]; +} #pragma mark - MSTabbarRoomGameHeadViewDelegate - (void)clickPayAction{ XPIAPRechargeViewController *iapVC = [XPIAPRechargeViewController new]; @@ -101,12 +109,14 @@ } -(void)startMatchGameSuccess{ + [self.presenter getRoomGameConfig]; MSRoomGameVC *gameVC = [MSRoomGameVC new]; gameVC.chooseGameModel = self.chooseGameModel; gameVC.userinfo = self.headView.userModel; BaseNavigationController *nav = [[BaseNavigationController alloc]initWithRootViewController:gameVC]; nav.modalPresentationStyle = UIModalPresentationFullScreen; [self presentViewController:nav animated:YES completion:nil]; + } #pragma mark - XPIAPRechargeViewControllerDelegate - (void)paySuccess{ @@ -118,6 +128,7 @@ self.headView.coinModel= coinModel; self.gameView.gameModel = gameModel; self.gameModel = gameModel; + } #pragma mark - 懒加载 - (UIImageView *)bgImageView{ diff --git a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameHeadAvatarView.h b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameHeadAvatarView.h index db1e8dd7..61c6f48a 100644 --- a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameHeadAvatarView.h +++ b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameHeadAvatarView.h @@ -10,7 +10,7 @@ NS_ASSUME_NONNULL_BEGIN @interface MSRoomGameHeadAvatarView : UIView -@property(nonatomic,copy) NSString *imageUrl; +@property(nonatomic,copy) NSString *__nullable imageUrl; @end NS_ASSUME_NONNULL_END diff --git a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameHeadAvatarView.m b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameHeadAvatarView.m index ab2df97f..116f02fe 100644 --- a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameHeadAvatarView.m +++ b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameHeadAvatarView.m @@ -35,8 +35,12 @@ }]; } --(void)setImageUrl:(NSString *)imageUrl{ +-(void)setImageUrl:(NSString *__nullable)imageUrl{ _imageUrl = imageUrl; + if(_imageUrl == nil){ + _avatarView.imageUrl = nil; + return; + } _avatarView.imageUrl = imageUrl; } #pragma mark - 懒加载 diff --git a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameHeadView.h b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameHeadView.h index d0054f3a..fe8c8b51 100644 --- a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameHeadView.h +++ b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameHeadView.h @@ -8,6 +8,7 @@ #import #import "MSRoomGameModel.h" #import "MSTabbarRoomGameModel.h" +#import "UserInfoModel.h" NS_ASSUME_NONNULL_BEGIN @protocol MSRoomGameHeadViewDelegate @@ -15,9 +16,14 @@ NS_ASSUME_NONNULL_BEGIN @end @interface MSRoomGameHeadView : UIView +@property(nonatomic,copy) NSString *gainProfit; @property(nonatomic,weak) iddelegate; -@property(nonatomic,strong) MSRoomGameModel *roomGameModel; +@property(nonatomic,strong) MSRoomGameModel *__nullable roomGameModel; @property(nonatomic,strong) MSTabbarRoomGameItemModel *chooseGameModel; +@property(nonatomic,strong) HomePlayMicUserModel *mineModel; +@property(nonatomic,strong) HomePlayMicUserModel *rivalModel; +@property(nonatomic,strong) UserInfoModel *userInfo; +-(void)setDataInNull; @end NS_ASSUME_NONNULL_END diff --git a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameHeadView.m b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameHeadView.m index 7a86feb0..472e682b 100644 --- a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameHeadView.m +++ b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameHeadView.m @@ -100,6 +100,16 @@ make.centerY.equalTo(self.bgCoinView); }]; } +- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { + for (NSInteger i = (self.subviews.count - 1) ; i >= 0 ; i--) { + UIView * subView = [self.subviews safeObjectAtIndex1:i]; + CGPoint convertPoint = [subView convertPoint:point fromView:self]; + if (CGRectContainsPoint(subView.bounds, convertPoint)) { + return [subView hitTest:convertPoint withEvent:event]; + } + } + return nil; +} -(void)clickBackBtnAction{ if(self.delegate && [self.delegate respondsToSelector:@selector(clickQuitGameAction)]){ [self.delegate clickQuitGameAction]; @@ -110,19 +120,30 @@ id coin = _chooseGameModel.scores.firstObject; if(coin != nil){ self.coinNumView.text = [NSString stringWithFormat:@"%@",coin]; + NSMutableAttributedString *attText = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:YMLocalizedString(@"MSRoomGameHeadView2"),self.coinNumView.text] attributes:@{NSFontAttributeName:kFontMedium(14),NSForegroundColorAttributeName:[UIColor whiteColor]}]; + [attText addAttributes:@{NSForegroundColorAttributeName:UIColorFromRGB(0xFF6629)} range:[attText.string rangeOfString:[NSString stringWithFormat:YMLocalizedString(@"MSRoomGameHeadView3"),self.coinNumView.text]]]; + _hintView.attributedText = attText; } } -- (void)setRoomGameModel:(MSRoomGameModel *)roomGameModel{ +-(void)setDataInNull{ + self.titleView.text = YMLocalizedString(@"MSRoomGameHeadView0"); + self.rivalView.imageUrl = nil; +} +- (void)setRoomGameModel:(MSRoomGameModel *__nullable)roomGameModel{ _roomGameModel = roomGameModel; + + if(_roomGameModel == nil){ + + return; + } NSString *uid = [[AccountInfoStorage instance]getUid]; for (MSRoomGameMicModel *obj in _roomGameModel.roomMics) { - if([obj.micUser.uid isEqualToString:uid]){ - self.mineView.imageUrl = obj.micUser.avatar; - }else{ + if(![obj.micUser.uid isEqualToString:uid]){ + self.rivalModel = obj.micUser; self.rivalView.imageUrl = obj.micUser.avatar; } - } + MSRoomGameInfoModel *data = _roomGameModel.data; if(data != nil){ _topImageView.imageUrl = data.gameRoomIcon; @@ -133,6 +154,15 @@ } } } +- (void)setUserInfo:(UserInfoModel *)userInfo{ + _userInfo = userInfo; + HomePlayMicUserModel *mineModel = [HomePlayMicUserModel new]; + mineModel.uid = @(_userInfo.uid).stringValue; + mineModel.nick = _userInfo.nick; + mineModel.avatar = _userInfo.avatar; + self.mineView.imageUrl = mineModel.avatar; + self.mineModel = mineModel; +} #pragma mark - 懒加载 - (NetImageView *)topImageView{ if(!_topImageView){ @@ -177,9 +207,7 @@ - (UILabel *)hintView{ if(!_hintView){ _hintView = [UILabel new]; - NSMutableAttributedString *attText = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:YMLocalizedString(@"MSRoomGameHeadView0"),@"18"] attributes:@{NSFontAttributeName:kFontMedium(14),NSForegroundColorAttributeName:[UIColor whiteColor]}]; - [attText addAttributes:@{NSForegroundColorAttributeName:UIColorFromRGB(0xFF6629)} range:[attText.string rangeOfString:@"18金币"]]; - _hintView.attributedText = attText; + _hintView.numberOfLines = 0; _hintView.textAlignment = NSTextAlignmentCenter; } diff --git a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameQuitGameView.h b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameQuitGameView.h index e3f1aa91..c4e3fe15 100644 --- a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameQuitGameView.h +++ b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameQuitGameView.h @@ -8,12 +8,21 @@ #import NS_ASSUME_NONNULL_BEGIN +@class MSTabbarRoomGameItemModel; @protocol MSRoomGameQuitGameViewDelegate - +@optional +///退出游戏 - (void)quitGameAction; - +///继续游戏 +-(void)rematchGameAction; +///强杀app打开后,是否重新玩游戏 +-(void)replayTheGameWithModel:(MSTabbarRoomGameItemModel *)model; +///强杀app打开后,退出游戏 +- (void)closeGameActionWithModel:(MSTabbarRoomGameItemModel *)model; @end @interface MSRoomGameQuitGameView : UIView +@property(nonatomic,strong) MSTabbarRoomGameItemModel *chooseGameModel; +@property(nonatomic,assign) BOOL isNormalFail; @property(nonatomic,weak) iddelegate; @end diff --git a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameQuitGameView.m b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameQuitGameView.m index 7e7f2466..f5265e54 100644 --- a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameQuitGameView.m +++ b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameQuitGameView.m @@ -51,14 +51,41 @@ make.top.mas_equalTo(kGetScaleWidth(48)); }]; } +-(void)setChooseGameModel:(MSTabbarRoomGameItemModel *)chooseGameModel{ + _chooseGameModel = chooseGameModel; + + _titleView.text = YMLocalizedString(@"MSRoomGameQuitGameView4"); + +} +- (void)setIsNormalFail:(BOOL)isNormalFail{ + _isNormalFail = isNormalFail; + _titleView.text = YMLocalizedString(@"MSRoomGameQuitGameView3"); + [_resumeBtn setTitle:YMLocalizedString(@"MSRoomGameVictoryView0") forState:UIControlStateNormal]; +} -(void)qutiBtnAction{ [TTPopup dismiss]; + if(self.chooseGameModel != nil){ + if(self.delegate && [self.delegate respondsToSelector:@selector(closeGameActionWithModel:)]){ + [self.delegate closeGameActionWithModel:self.chooseGameModel]; + } + return; + } if(self.delegate && [self.delegate respondsToSelector:@selector(quitGameAction)]){ [self.delegate quitGameAction]; } } -(void)resumeBtnAction{ [TTPopup dismiss]; + if(self.chooseGameModel != nil){ + if(self.delegate && [self.delegate respondsToSelector:@selector(replayTheGameWithModel:)]){ + [self.delegate replayTheGameWithModel:self.chooseGameModel]; + } + return; + } + if(self.isNormalFail == NO)return; + if(self.delegate && [self.delegate respondsToSelector:@selector(rematchGameAction)]){ + [self.delegate rematchGameAction]; + } } #pragma mark - 懒加载 - (UIView *)bgView{ diff --git a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameSendMsgView.h b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameSendMsgView.h index 997a4c4a..8de80282 100644 --- a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameSendMsgView.h +++ b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameSendMsgView.h @@ -8,9 +8,13 @@ #import NS_ASSUME_NONNULL_BEGIN +@protocol MSRoomGameSendMsgViewDelegate +- (void)clickSendMsgAction; + +@end @interface MSRoomGameSendMsgView : UIView - +@property(nonatomic,weak) iddelegate; @end NS_ASSUME_NONNULL_END diff --git a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameSendMsgView.m b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameSendMsgView.m index fff97e36..f9b407c8 100644 --- a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameSendMsgView.m +++ b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameSendMsgView.m @@ -38,6 +38,11 @@ make.centerY.equalTo(self.sendBtn); }]; } +-(void)clickSendBtnAction{ + if(self.delegate && [self.delegate respondsToSelector:@selector(clickSendMsgAction)]){ + [self.delegate clickSendMsgAction]; + } +} #pragma mark - 懒加载 - (UIButton *)sendBtn{ if(!_sendBtn){ @@ -45,6 +50,7 @@ _sendBtn.backgroundColor = UIColorRGBAlpha(0x0B032D , 0.1); _sendBtn.layer.cornerRadius = kGetScaleWidth(28)/2; _sendBtn.layer.masksToBounds = YES; + [_sendBtn addTarget:self action:@selector(clickSendBtnAction) forControlEvents:UIControlEventTouchUpInside]; } return _sendBtn; } diff --git a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameSendTextView.h b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameSendTextView.h new file mode 100644 index 00000000..7107cd9d --- /dev/null +++ b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameSendTextView.h @@ -0,0 +1,19 @@ +// +// MSRoomGameSendTextView.h +// YuMi +// +// Created by duoban on 2024/5/30. +// + +#import +#import "UserInfoModel.h" +NS_ASSUME_NONNULL_BEGIN + +@interface MSRoomGameSendTextView : UIView +///输入框 +@property (nonatomic, strong, readonly) UITextField *editTextFiled; +-(void)showInputView:(NSString *)text; +- (instancetype)initWithRoomId:(NSString *)roomId userInfo:(UserInfoModel *)userInfo; +@end + +NS_ASSUME_NONNULL_END diff --git a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameSendTextView.m b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameSendTextView.m new file mode 100644 index 00000000..9b90dc61 --- /dev/null +++ b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameSendTextView.m @@ -0,0 +1,285 @@ +// +// MSRoomGameSendTextView.m +// YuMi +// +// Created by duoban on 2024/5/30. +// +#import +#import +#import "NSObject+MJExtension.h" +#import +///Tool +#import "ThemeColor+Room.h" +#import "UIImage+Utils.h" +#import "AccountInfoStorage.h" +///Model +#import "XPMessageRemoteExtModel.h" +#import "UserInfoModel.h" +#import "RoomInfoModel.h" +#import "ClientConfig.h" +#import "MSRoomGameSendTextView.h" +#import "MSRoomGameSendTextView.h" +//公屏限制最大字数 +#define MAX_STARWORDS_LENGTH 300 +@interface MSRoomGameSendTextView() +///输入框 +@property (nonatomic, strong) MSBaseTextField *editTextFiled; +@property (nonatomic, strong) UIView *bgEditTextFiled; +///发送按钮 +@property (nonatomic, strong) UIButton *sendButton; +///文本输入的内容 +@property (nonatomic,copy) NSString *inputMessage; +@property(nonatomic,strong) UserInfoModel * userInfo; +@property(nonatomic,copy) NSString *roomId; + +@end +@implementation MSRoomGameSendTextView +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + +- (instancetype)initWithRoomId:(NSString *)roomId userInfo:(UserInfoModel *)userInfo { + self = [super initWithFrame:CGRectMake(0, KScreenHeight - 60, KScreenWidth, 60)]; + if (self) { + self.roomId = roomId; + self.userInfo = userInfo; + [self addNotification]; + [self initSubViews]; + [self initSubViewConstraints]; + [IQKeyboardManager sharedManager].enable = NO; + [self.editTextFiled becomeFirstResponder]; + } + return self; +} + +#pragma mark - Response + +- (void)sendButtonDidClick:(UIButton *)sender { + UserInfoModel * userInfo = self.userInfo; + XPMessageRemoteExtModel *extModel = [[XPMessageRemoteExtModel alloc] init]; + extModel.defUser = userInfo.defUser; + extModel.erbanNo = userInfo.erbanNo; + extModel.carName = userInfo.carName; + extModel.inRoomNameplatePic = userInfo.nameplatePic; + extModel.inRoomNameplateWord = userInfo.nameplateWord; + extModel.isCustomWord = userInfo.isCustomWord; + extModel.charmUrl = userInfo.userLevelVo.charmUrl; + extModel.experLevelSeq = userInfo.userLevelVo.experLevelSeq; + extModel.experUrl = userInfo.userLevelVo.experUrl; + extModel.newUser = userInfo.newUser; + extModel.vipIcon = userInfo.userVipInfoVO.vipIcon; + extModel.androidBubbleUrl = userInfo.androidBubbleUrl; + extModel.iosBubbleUrl = userInfo.iosBubbleUrl; + extModel.fromSayHelloChannel = userInfo.fromSayHelloChannel; + + + + NIMMessage * message = [[NIMMessage alloc] init]; + message.text = self.inputMessage; + NSMutableDictionary *remoteExt = [NSMutableDictionary dictionaryWithObject:extModel.model2dictionary forKey:[AccountInfoStorage instance].getUid]; + message.remoteExt = remoteExt; + + ///网易易盾 拦截高风险 + NIMAntiSpamOption *option = [[NIMAntiSpamOption alloc]init]; + option.yidunEnabled = YES; + option.businessId = KeyWithType(keyType_YiDunBussinessId); + message.antiSpamOption = option; + NSString * sessionId = self.roomId; + //构造会话 + self.sendButton.enabled = NO; + NIMSession *session = [NIMSession session:sessionId type:NIMSessionTypeChatroom]; + [[NIMSDK sharedSDK].chatManager sendMessage:message toSession:session completion:^(NSError * _Nullable error) { + self.editTextFiled.text = @""; + [self.editTextFiled resignFirstResponder]; + self.inputMessage = nil; + }]; +} +-(void)showSendheadlineBtnAction{ + if(self.editTextFiled.text.length == 0){ + [XNDJTDDLoadingTool showErrorWithMessage:YMLocalizedString(@"MSSessionReleaseHeadlinesView0")]; + return; + } + if(self.editTextFiled.text.length > 100){ + [XNDJTDDLoadingTool showErrorWithMessage:YMLocalizedString(@"MSSessionReleaseHeadlinesView0")]; + return; + } + [self.editTextFiled resignFirstResponder]; + [[NSNotificationCenter defaultCenter]postNotificationName:@"kShowSendheadlineView" object:self.editTextFiled.text]; + self.editTextFiled.text = @""; +} +- (void)keyboardWillShow:(NSNotification *)notification { + [self.superview bringSubviewToFront:self]; + NSDictionary *info = [notification userInfo]; + NSValue *value = [info objectForKey:UIKeyboardFrameEndUserInfoKey]; + CGFloat keyBoardEndY = value.CGRectValue.origin.y; + NSNumber *curve = [info objectForKey:UIKeyboardAnimationCurveUserInfoKey]; + CGFloat duration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]; + CGRect endKeyboardRect = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; + CGFloat h = endKeyboardRect.size.height; + [UIView animateWithDuration:duration animations:^{ + if(self.superview){ + [self mas_remakeConstraints:^(MASConstraintMaker *make) { + make.leading.trailing.equalTo(self.superview); + make.height.equalTo(@60); + make.bottom.equalTo(self.superview).offset(-h); + }]; + } + [UIView setAnimationBeginsFromCurrentState:YES]; + [UIView setAnimationCurve:[curve intValue]]; + self.center = CGPointMake(self.center.x, keyBoardEndY - statusbarHeight - self.bounds.size.height/2.0); + }]; +} + +//键盘隐藏 +- (void)keyboardWillHidden:(NSNotification *)notification { + + NSDictionary *info = [notification userInfo]; + CGFloat duration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]; + [UIView animateWithDuration:duration animations:^{ + [self mas_remakeConstraints:^(MASConstraintMaker *make) { + make.bottom.leading.trailing.equalTo(self.superview); + make.height.equalTo(@60); + }]; + self.hidden = YES; + }]; +} + +-(void)textFieldEditChanged:(NSNotification *)notification{ + + UITextField *textField = (UITextField *)notification.object; + NSString *toBeString = textField.text; + NSString *lang = [textField.textInputMode primaryLanguage]; + if ([lang isEqualToString:@"zh-Hans"]){// 简体中文输入 + //获取高亮部分 + UITextRange *selectedRange = [textField markedTextRange]; + UITextPosition *position = [textField positionFromPosition:selectedRange.start offset:0]; + // 没有高亮选择的字,则对已输入的文字进行字数统计和限制 + if (!position){ + if (toBeString.length > MAX_STARWORDS_LENGTH){ + NSRange rangeIndex = [toBeString rangeOfComposedCharacterSequenceAtIndex:MAX_STARWORDS_LENGTH]; + if (rangeIndex.length == 1){ + + textField.text = [toBeString substringToIndex:MAX_STARWORDS_LENGTH]; + }else{ + NSRange rangeRange = [toBeString rangeOfComposedCharacterSequencesForRange:NSMakeRange(0, MAX_STARWORDS_LENGTH)]; + textField.text = [toBeString substringWithRange:rangeRange]; + } + } + } + }else{ // 中文输入法以外的直接对其统计限制即可,不考虑其他语种情况 + if (toBeString.length > MAX_STARWORDS_LENGTH){ + NSRange rangeIndex = [toBeString rangeOfComposedCharacterSequenceAtIndex:MAX_STARWORDS_LENGTH]; + if (rangeIndex.length == 1){ + + textField.text = [toBeString substringToIndex:MAX_STARWORDS_LENGTH]; + }else{ + + NSRange rangeRange = [toBeString rangeOfComposedCharacterSequencesForRange:NSMakeRange(0, MAX_STARWORDS_LENGTH)]; + textField.text = [toBeString substringWithRange:rangeRange]; + } + } + } + + self.inputMessage = textField.text; + + if (self.inputMessage.length > 0) { + self.sendButton.enabled = YES; + } else { + self.sendButton.enabled = NO; + } +} + + + +#pragma mark - Private Method +- (void)initSubViews { + self.backgroundColor = UIColorFromRGB(0x260159); + [self addSubview:self.bgEditTextFiled]; + [self.bgEditTextFiled addSubview:self.editTextFiled]; + [self addSubview:self.sendButton]; + +} + +- (void)initSubViewConstraints { + + + + + [self.bgEditTextFiled mas_makeConstraints:^(MASConstraintMaker *make) { + make.leading.mas_equalTo(6); + make.height.mas_equalTo(36); + make.top.mas_equalTo(12); + make.trailing.equalTo(self.sendButton.mas_leading).mas_offset(-8); + + }]; + [self.editTextFiled mas_makeConstraints:^(MASConstraintMaker *make) { + make.leading.mas_equalTo(20); + make.trailing.mas_equalTo(-kGetScaleWidth(20)); + make.top.bottom.mas_equalTo(0); + }]; + + + [self.sendButton mas_remakeConstraints:^(MASConstraintMaker *make) { + make.width.mas_equalTo(58); + make.height.mas_equalTo(29); + make.trailing.mas_equalTo(-15); + make.centerY.equalTo(self); + }]; + + +} + +- (void)addNotification { + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHidden:) name:UIKeyboardWillHideNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldEditChanged:) name:UITextFieldTextDidChangeNotification object:self.editTextFiled]; +} +-(void)showInputView:(NSString *)text{ + self.editTextFiled.text = text; + self.inputMessage = text; + if(text.length > 0){ + self.sendButton.enabled = YES; + } + +} +#pragma mark - Getters And Setters +- (MSBaseTextField *)editTextFiled{ + if (!_editTextFiled) { + _editTextFiled = [[MSBaseTextField alloc] init]; + NSAttributedString * attribute = [[NSAttributedString alloc] initWithString:YMLocalizedString(@"XPRoomSendTextView0") attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15], NSForegroundColorAttributeName : [UIColor colorWithWhite:1 alpha:0.5]}]; + _editTextFiled.attributedPlaceholder = attribute; + _editTextFiled.borderStyle = UITextBorderStyleNone; + _editTextFiled.textColor = [UIColor whiteColor]; + _editTextFiled.font = [UIFont systemFontOfSize:13 weight:UIFontWeightMedium]; + [_editTextFiled setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal]; + + } + return _editTextFiled; +} +- (UIButton *)sendButton{ + if (!_sendButton) { + _sendButton = [[UIButton alloc] init]; + [_sendButton setTitle:YMLocalizedString(@"XPRoomSendTextView1") forState:UIControlStateNormal]; + _sendButton.titleLabel.textColor = [UIColor whiteColor]; + _sendButton.titleLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium]; + [_sendButton setBackgroundImage:[UIImage imageWithColor:[DJDKMIMOMColor disableButtonColor] ]forState:UIControlStateDisabled]; + [_sendButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[UIColorFromRGB(0x7E5AFF), UIColorFromRGB(0x52CAD3)] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)] forState:UIControlStateNormal]; + _sendButton.enabled = NO; + _sendButton.layer.cornerRadius = 7.5; + _sendButton.layer.masksToBounds = YES; + [_sendButton addTarget:self action:@selector(sendButtonDidClick:) forControlEvents:UIControlEventTouchUpInside]; + _sendButton.tag = 101; + } + return _sendButton; +} + +- (UIView *)bgEditTextFiled{ + if(!_bgEditTextFiled){ + _bgEditTextFiled = [UIView new]; + _bgEditTextFiled.backgroundColor = UIColorFromRGB(0x361661); + _bgEditTextFiled.layer.cornerRadius = 18; + _bgEditTextFiled.layer.masksToBounds = YES; + } + return _bgEditTextFiled; +} +@end diff --git a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameVictoryView.h b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameVictoryView.h index 33743b90..d4051b16 100644 --- a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameVictoryView.h +++ b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameVictoryView.h @@ -14,6 +14,7 @@ NS_ASSUME_NONNULL_BEGIN -(void)rematchGameAction; @end @interface MSRoomGameVictoryView : UIView +@property(nonatomic,copy) NSArray *resultsList; @property(nonatomic,weak) iddelegate; @end diff --git a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameVictoryView.m b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameVictoryView.m index e71f26db..3be338a5 100644 --- a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameVictoryView.m +++ b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameVictoryView.m @@ -7,6 +7,7 @@ #import "MSRoomGameVictoryView.h" #import "MSRoomGameVictoryCell.h" +#import "MSRoomGameResultsModel.h" @interface MSRoomGameVictoryView() @property(nonatomic,strong) UIView *bgView; @property(nonatomic,strong) UIView *bgSubView; @@ -71,11 +72,11 @@ } #pragma mark- UITableViewDelegate,UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ - return 2; + return self.resultsList.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ MSRoomGameVictoryCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([MSRoomGameVictoryCell class]) forIndexPath:indexPath]; - + cell.resultsModel = [self.resultsList safeObjectAtIndex1:indexPath.row]; return cell; } -(void)closeBtnAction{ @@ -90,6 +91,13 @@ [self.delegate rematchGameAction]; } } +-(void)setResultsList:(NSArray *)resultsList{ + _resultsList = resultsList; + MSRoomGameResultsModel *resultsModel = _resultsList.firstObject; + NSString *uid = [AccountInfoStorage instance].getUid; + self.topView.image = [resultsModel.uid isEqualToString:[AccountInfoStorage instance].getUid] ? kImage(@"ms_room_game_victory_top_icon") : kImage(@"ms_room_game_victory_top_fail_icon"); + [_tableView reloadData]; +} #pragma mark - 懒加载 - (UIView *)bgView{ if(!_bgView){ diff --git a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameView.h b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameView.h index c6f1e354..ca840169 100644 --- a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameView.h +++ b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameView.h @@ -6,26 +6,25 @@ // #import -#import "RoomHostDelegate.h" -#import "RoomGuestDelegate.h" +#import "MSRoomGameModel.h" NS_ASSUME_NONNULL_BEGIN @protocol MSRoomGameViewDelegate -- (void)hiddenSudGamePostionView; +- (void)getGameRsultsWithList:(NSArray *)list; @end @interface MSRoomGameView : UIView -- (instancetype)initWithDelegate:(id)delegate; +@property(nonatomic,strong) MSRoomGameModel *gameModel; -///代理 -@property (nonatomic,weak) id delegate; +@property(nonatomic,weak) iddelegate; +- (void)onRoomEntered; ///销毁游戏的引擎 - (void)destroyMG; /// 退出游戏 - (void)handleSelfInExitEvent; - +- (void)handleNIMNotificationMessage:(NIMMessage *)message; //自己是否在游戏中 - (BOOL)isInSudGame; diff --git a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameView.m b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameView.m index 1d9e01e3..0657ac93 100644 --- a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameView.m +++ b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameView.m @@ -13,7 +13,7 @@ #import "AccountInfoStorage.h" - +#import "MSRoomGameResultsModel.h" #import "SudCommon.h" #import "SudGameConfig.h" ///Model @@ -31,838 +31,632 @@ #import #import #import "MSRoomGameView.h" -@interface MSRoomGameView() +@interface MSRoomGameView() ///当前小游戏ID @property (nonatomic, assign) int64_t currentmgId; ///小游戏code @property (nonatomic, copy) NSString *code; /// -@property(nonatomic,copy) NSString *mgId; + @property (nonatomic, strong) id fsmAPP2MG; -/// 你画我猜专用,游戏中选中的关键词,会回调出来,通过 DrawSomethingKeyWord 进行保存。 -@property (nonatomic, copy) NSString * DrawSomethingKeyWord; -/// 你画我猜,进入猜词环节,用来公屏识别关键字的状态标识 -@property (nonatomic, assign) BOOL keyWordHiting; ///游戏状态 @property (nonatomic, assign) LittleGamePlayStatus sudGameStatus; + +@property(nonatomic,strong) NSMutableArray *userList; @end @implementation MSRoomGameView -//- (instancetype)initWithmgId:(NSString *)mgId -//{ -// self = [super init]; -// if (self) { -// self.mgId = mgId; -// } -// return self; -//} -// -//#pragma mark - Private Method -//- (void)updateSudGame { -// -// -// if (self.currentmgId == 0) {//第一次加载游戏 -// self.currentmgId = roomInfo.mgId; -// if (self.currentmgId != 0) {//房间信息已加载 -// NSLog(@"initLittleGame---%lld", self.currentmgId); -// [self initLittleGame]; -// } -// } else { -// if (self.currentmgId != roomInfo.mgId) { -// //切换游戏玩法 -// self.currentmgId = roomInfo.mgId; -// NSLog(@"updateLittleGame---%lld", self.currentmgId); -// if (self.currentmgId != 0) { -// [self.fsmAPP2MG destroyMG]; -// [self updateMicInfoWithGameStatus:LittleGamePlayStatus_NoIn]; -// [self gameSetUp]; -// } -// } -// } -// -//} -// -//- (void)initLittleGame { -// [Api getSudGameCode:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { -// if (code == 200) { -// NSString * gameCode = data.data[@"code"]; -// self.code = gameCode; -// [self gameSetUp]; -// } else { -// [XNDJTDDLoadingTool showErrorWithMessage:msg]; -// } -// } uid:[AccountInfoStorage instance].getUid]; -//} -// -//- (void)gameSetUp { -// NSLog(@"小游戏的版本号是:%@", [SudMGP getVersion]); -// BOOL isTestEnv = NO; -//#ifdef DEBUG -// isTestEnv = YES; -//#else -// isTestEnv = NO; -//#endif -// if(isEnterprise == NO){ -// [[SudMGP getCfg]setBackgroundMode:NO]; -// } -// [SudMGP initSDK:KeyWithType(KeyType_SudGameAppID) appKey:KeyWithType(KeyType_SudGameAppKey) isTestEnv:isTestEnv listener:^(int retCode, const NSString *retMsg) { -// if (retCode == 0) { -// if (!self.currentmgId) { -// return; -// } -// NSString * userId = [AccountInfoStorage instance].getUid; -// NSString * roomId = [NSString stringWithFormat:@"%ld", self.hostDelegate.getRoomInfo.uid]; -// NSLog(@"用户ID:%@,房间ID:%@, 游戏ID:%lld, code:%@", userId, roomId, self.currentmgId, self.code); -//// -// -// NSString *language = [NSBundle getLanguageText]; -// if ([language hasPrefix:@"zh"]) { -// if ([language rangeOfString:@"Hans"].location != NSNotFound) { -// language = @"zh-CN"; // 简体中文 -// } else { -// language = @"zh-TW"; // 繁體中文 -// } -// }else{ -// language = @"en-US"; // 英文 -// } -// self.fsmAPP2MG = [SudMGP loadMG:userId roomId:roomId code:self.code mgId:self.currentmgId language:language fsmMG:self rootView:self]; -// } else { -// /// 初始化失败, 可根据业务重试 -// NSLog(@"ISudFSMMG:initGameSDKWithAppID:初始化sdk失败 :%@",retMsg); -// } -// }]; -//} -// -////判断是否在麦上 -//- (BOOL)isOnMicro:(NSInteger)uid{ -// NSArray *chatRoomMicSequences = [self.hostDelegate.getMicroQueue allValues] ; -// if (chatRoomMicSequences != nil && chatRoomMicSequences.count > 0) { -// for (int i = 0; i < chatRoomMicSequences.count; i ++) { -// MicroQueueModel *chatRoomMicSequence = chatRoomMicSequences[i]; -// if (chatRoomMicSequence.userInfo.uid == uid) { -// return YES; -// } -// } -// } -// return NO; -//} -// -//- (NSString *)findFreePosition{ -// NSMutableDictionary * micQueue = self.hostDelegate.getMicroQueue; -// if (micQueue != nil && micQueue.allKeys.count > 0) { -// NSArray *keys = [micQueue allKeys]; -// if (keys.count > 0) { -// ///重新排序,按照升序 -// NSArray *resultArr = [keys sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) { -// return [obj1 compare:obj2]; -// }]; -// for (NSString *key in resultArr) { -// UserInfoModel *userInfo = [[micQueue objectForKey:key] userInfo]; -// if ( !userInfo) { -// return key; -// } -// } -// } -// } -// return nil; -//} -// -////通过uid判断麦位 -//- (NSString *)findThePositionByUid:(NSInteger)uid{ -// if (uid > 0) { -// NSMutableDictionary * micQueue = self.hostDelegate.getMicroQueue; -// NSArray *keys = [micQueue allKeys]; -// if (keys.count > 0) { -// for (NSString *key in keys) { -// UserInfoModel *userInfo = [[micQueue objectForKey:key] userInfo]; -// if (userInfo.uid == uid) { -// return key; -// } -// } -// } -// } -// return nil; -//} -// -////上麦以加入游戏 -//- (void)upMicToJoinGame { -// NSString *position = [self findFreePosition]; -// if (position.length > 0) { -// NSString * userId = [AccountInfoStorage instance].getUid; -// UserInfoModel * userInfo = self.hostDelegate.getUserInfo; -// //清空该uid之前在队列中的信息 -// if ([self isOnMicro:userId.integerValue]) { -// if (position) { -// NSString *findOldPosition = [self findThePositionByUid:userInfo.uid]; -// NIMChatroomQueueRemoveRequest *request = [[NIMChatroomQueueRemoveRequest alloc]init]; -// request.key = findOldPosition; -// request.roomId = [NSString stringWithFormat:@"%ld", self.hostDelegate.getRoomInfo.roomId]; -// if (findOldPosition) { -// [[NIMSDK sharedSDK].chatroomManager removeChatroomQueueObject:request completion:^(NSError * _Nullable error, NSDictionary * _Nullable element) { -// if (error == nil) { -// NIMChatroomQueueUpdateRequest *request = [[NIMChatroomQueueUpdateRequest alloc]init]; -// request.key = position; -// request.value = [[self userInfoToQueueExt:userInfo] toJSONString]; -// request.roomId = [NSString stringWithFormat:@"%ld", self.hostDelegate.getRoomInfo.roomId]; -// request.transient = YES; -// [[NIMSDK sharedSDK].chatroomManager updateChatroomQueueObject:request completion:^(NSError * _Nullable error) { -// [self notifySelfInState:YES seatIndex:-1]; -// }]; -// } -// }]; -// } -// } -// }else{ -// NIMChatroomQueueUpdateRequest *request = [[NIMChatroomQueueUpdateRequest alloc]init]; -// request.key = position; -// request.value = [[self userInfoToQueueExt:userInfo] toJSONString]; -// request.roomId = [NSString stringWithFormat:@"%ld", self.hostDelegate.getRoomInfo.roomId]; -// request.transient = YES; -// [[NIMSDK sharedSDK].chatroomManager updateChatroomQueueObject:request completion:^(NSError * _Nullable error) { -// [self notifySelfInState:YES seatIndex:-1]; -// }]; -// } -// } -//} -// -//- (void)updateMicInfoWithGameStatus:(LittleGamePlayStatus)status { -// NSString * position = [self findThePositionByUid:[AccountInfoStorage instance].getUid.integerValue]; -// if (position != nil) { -// UserInfoModel * userInfo = self.hostDelegate.getUserInfo; -// userInfo.gameStatus = status; -// NIMChatroomQueueUpdateRequest *request = [[NIMChatroomQueueUpdateRequest alloc]init]; -// request.key = position; -// request.value = [[self userInfoToQueueExt:userInfo] toJSONString]; -// request.roomId = [NSString stringWithFormat:@"%ld", self.hostDelegate.getRoomInfo.roomId]; -// request.transient = YES; -// [[NIMSDK sharedSDK].chatroomManager updateChatroomQueueObject:request completion:^(NSError * _Nullable error) { -// -// }]; -// } -//} -// -///** -// * 麦位更新扩展字段。 -// */ -//- (NSDictionary *)userInfoToQueueExt:(UserInfoModel *)userInfo { -// MicroExtModel * extModel = [[MicroExtModel alloc] init]; -// extModel.gender = userInfo.gender; -// extModel.avatar = userInfo.avatar; -// extModel.uid = userInfo.uid; -// extModel.nick = userInfo.nick; -// extModel.gameStatus = userInfo.gameStatus; -// extModel.headWearUrl = userInfo.headwearEffect.length > 0 ? userInfo.headwearEffect : userInfo.headwearPic; -// extModel.preventKick = userInfo.userVipInfoVO.preventKick; -// extModel.enterHide = userInfo.userVipInfoVO.enterHide; -// return [extModel model2dictionary]; -//} -// -////自己是否在游戏中 -//- (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; -//} -// -////游戏状态 -//- (LittleGamePlayStatus)getCurrentUserSudGameStatus { -// LittleGamePlayStatus gameStatus = LittleGamePlayStatus_NoIn; -// 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) { -// gameStatus = micSequence.userInfo.gameStatus; -// break; -// } -// } -// return gameStatus; -//} -// -/////下麦 -//- (void)onDownMic:(NSInteger)uid { -// if (uid == [AccountInfoStorage instance].getUid.integerValue) {//自己下麦 -// [self notifyIsPlayingState:false]; -// [self nofityPlayerPlaying:NO]; -// [self notifySetReady:false]; -// /// 下游戏麦 -// [self notifySelfInState:false seatIndex:-1]; -// } -//} -// -//#pragma mark =======ISudFSMMG Delegate======= -///** -//* 游戏日志 -//*/ -//-(void)onGameLog:(NSString*)dataJson { -// NSLog(@"ISudFSMMG:onGameLog:%@", dataJson); -// NSDictionary * dic = [SudCommon turnStringToDictionary:dataJson]; -// NSString * msg_string = [dic objectForKey:@"msg"]; -// if (!msg_string) { -// return; -// } -//} -// -///** -//* 游戏开始 -//*/ -//-(void)onGameStarted { -// NSLog(@"ISudFSMMG:onGameStarted:游戏开始"); -//} -// -///** -// * 游戏销毁 -// */ -//-(void)onGameDestroyed { -// NSLog(@"ISudFSMMG:onGameDestroyed:游戏开始"); -//} -// -///** -// * Code过期 -// * @param dataJson {"code":"value"} -// */ -//-(void)onExpireCode:(id)handle dataJson:(NSString*)dataJson { -// NSLog(@"ISudFSMMG:onExpireCode:Code过期"); -// // 请求业务服务器刷新令牌 -// [Api getSudGameCode:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { -// if (code == 200) { -// NSString * gameCode = data.data[@"code"]; -// self.code = gameCode; -// [self.fsmAPP2MG updateCode:gameCode listener:^(int retCode, const NSString *retMsg, const NSString *dataJson) { -// NSLog(@"ISudFSMMG:updateGameCode retCode=%@ retMsg=%@ dataJson=%@", @(retCode), retMsg, dataJson); -// }]; -// // 回调结果 -// NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@(0), @"ret_code", @"return form APP onExpireCode", @"ret_msg", nil]; -// [handle success:[SudCommon dictionaryToJson:dict]]; -// } else { -// [XNDJTDDLoadingTool showErrorWithMessage:msg]; -// } -// } uid:[AccountInfoStorage instance].getUid]; -//} -// -///** -// * 获取游戏View信息 -// * @param handle 回调句柄 -// * @param dataJson {} -// */ -//-(void)onGetGameViewInfo:(id)handle dataJson:(NSString*)dataJson { -// CGRect rect = [[UIScreen mainScreen] bounds]; -// CGFloat scale = [[UIScreen mainScreen] nativeScale]; -// -// CGFloat top = (kNavigationHeight+105) * scale; -// CGFloat bottom; -// if (iPhoneXSeries) { -// bottom = (47+kSafeAreaBottomHeight+30 + 70) * scale; -// } else { -// bottom = (47+10+70 ) * scale; -// } -// CGFloat width = rect.size.width * scale; -// CGFloat height = rect.size.height * scale; -// NSDictionary *rectDict = [NSDictionary dictionaryWithObjectsAndKeys:@(top), @"top", @(0), @"left", @(bottom), @"bottom", @(0), @"right", nil]; -// NSDictionary *viewDict = [NSDictionary dictionaryWithObjectsAndKeys:@(width), @"width", @(height), @"height", nil]; -// NSDictionary *dataDict = [NSDictionary dictionaryWithObjectsAndKeys:@(0), @"ret_code", @"return form APP onGetGameViewInfo", @"ret_msg", viewDict, @"view_size", rectDict, @"view_game_rect", nil]; -// /// 回调 -// [handle success:[SudCommon dictionaryToJson:dataDict]]; -//} -// -///** -// * 获取游戏配置 -// * @param handle 回调句柄 -// * @param dataJson {} -// */ -//-(void)onGetGameCfg:(id)handle dataJson:(NSString*)dataJson { -// NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; -// dict[@"ret_code"] = @(0); -// dict[@"ret_msg"] = @"return form APP onGetGameCfg"; -// -// dict[@"ui"] = @{ -// @"join_btn" : @{@"custom": @(YES), @"hide": @(NO)},//加入游戏 -// @"start_btn" : @{@"custom": @(YES), @"hide": @(NO)},//开始游戏 -// @"lobby_players" : @{@"custom": @(YES), @"hide": @(NO)},//游戏中坑位点击 -// @"level" : @{@"custom": @(YES), @"hide" : @(YES)},//段位信息 -// }; -// NSString *dataJsonRet = @""; -// NSData *dataJsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil]; -// if (dataJsonData != nil) { -// dataJsonRet = [[NSString alloc]initWithData:dataJsonData encoding:NSUTF8StringEncoding]; -// } -// [handle success:dataJsonRet]; -//} -// -///** -// * 游戏状态变化 -// * @param handle 回调句柄 -// * @param state 游戏状态 -// * @param dataJson 回调json -// */ -//-(void)onGameStateChange:(id) handle state:(NSString*) state dataJson:(NSString*) dataJson { -// if ([state isEqualToString:MG_COMMON_PUBLIC_MESSAGE]) { -// NSLog(@"ISudFSMMG:onGameStateChange:游戏->APP:公屏消息"); -// } else if ([state isEqualToString:MG_COMMON_KEY_WORD_TO_HIT]) { -// NSDictionary *dic = [SudCommon turnStringToDictionary:dataJson]; -// NSString *word = [dic objectForKey:@"word"]; -// NSLog(@"ISudFSMMG:onGameStateChange:游戏->APP:你画我猜关键词获取:%@",word); -// /// 记录你画我猜关键字 -// self.DrawSomethingKeyWord = word; -// if (word == (id) [NSNull null] || [word isEqualToString:@""]) { -// /// 关闭公屏关键词hit状态 -// self.keyWordHiting = NO; -// } else { -// /// 开启公屏关键词hit状态 -// self.keyWordHiting = YES; -// } -// }else if ([state isEqualToString:MG_COMMON_SELF_CLICK_JOIN_BTN]) {//加入游戏按钮点击 -// NSDictionary *dic = [SudCommon turnStringToDictionary:dataJson]; -// int seatIndex = -1; -// if ([dic objectForKey:@"seatIndex"]) { -// seatIndex = [[dic objectForKey:@"seatIndex"] intValue]; -// } -// if (seatIndex == -1) { -// NSLog(@"来自加入按钮%d",seatIndex); -// }else { -// NSLog(@"来自麦位+入%d",seatIndex); -// } -// if ([self isOnMicro:[AccountInfoStorage instance].getUid.integerValue]) {//判断是否在麦上 -// [self notifySelfInState:YES seatIndex:seatIndex]; -// } else { -// //不在麦上 -// [self upMicToJoinGame]; -// } -// } else if([state isEqualToString:MG_COMMON_SELF_CLICK_START_BTN]) {//开始游戏按钮点击 -// [self notifyIsPlayingState:YES]; -// } else if ([state isEqualToString:MG_COMMON_SELF_CLICK_CANCEL_JOIN_BTN]) { -// /// 取消加入游戏(退出游戏按钮点击) -// [self handleSelfInExitEvent]; -// } else { -// /// 其他状态 -// NSLog(@"ISudFSMMG:onGameStateChange:游戏->APP:state:%@",MG_COMMON_PUBLIC_MESSAGE); -// } -//} -// -///** -// * 游戏玩家状态变化 -// * @param handle 回调句柄 -// * @param userId 用户id -// * @param state 玩家状态 -// * @param dataJson 回调JSON -// */ -//-(void)onPlayerStateChange:(nullable id) handle userId:(NSString*) userId state:(NSString*) state dataJson:(NSString*) dataJson { -// NSLog(@"ISudFSMMG:onPlayerStateChange:游戏->APP:游戏玩家状态变化:userId: %@ --state: %@ --dataJson: %@", userId, state, dataJson); -// /// 状态解析 -// NSString *dataStr = @""; -// if ([state isEqualToString:MG_COMMON_PLAYER_IN]) { -// dataStr = YMLocalizedString(@"XPRoomLittleGameContainerView0"); -// [self handleState_MG_COMMON_PLAYER_IN_WithUserId:userId dataJson:dataJson]; -// } else if ([state isEqualToString:MG_COMMON_PLAYER_READY]) { -// dataStr = YMLocalizedString(@"XPRoomLittleGameContainerView1"); -// [self handleState_MG_COMMON_PLAYER_READY_WithUserId:userId dataJson:dataJson]; -// } else if ([state isEqualToString:MG_COMMON_PLAYER_CAPTAIN]) { -// dataStr = YMLocalizedString(@"XPRoomLittleGameContainerView2"); -// [self handleState_MG_COMMON_PLAYER_CAPTAIN_WithUserId:userId dataJson:dataJson]; -// } else if ([state isEqualToString:MG_COMMON_PLAYER_PLAYING]) { -// dataStr = YMLocalizedString(@"XPRoomLittleGameContainerView3"); -// [self handleState_MG_COMMON_PLAYER_PLAYING_WithUserId:userId dataJson:dataJson]; -// } else if ([state isEqualToString:MG_DG_SELECTING]) { -// dataStr = YMLocalizedString(@"XPRoomLittleGameContainerView4"); -// [self handleState_MG_DG_SELECTING_WithUserId:userId dataJson:dataJson]; -// } else if ([state isEqualToString:MG_DG_PAINTING]) { -// dataStr = YMLocalizedString(@"XPRoomLittleGameContainerView5"); -// [self handleState_MG_DG_PAINTING_WithUserId:userId dataJson:dataJson]; -// } else if ([state isEqualToString:MG_DG_ERRORANSWER]) { -// dataStr = YMLocalizedString(@"XPRoomLittleGameContainerView6"); -// [self handleState_MG_DG_ERRORANSWER_WithUserId:userId dataJson:dataJson]; -// } else if ([state isEqualToString:MG_DG_TOTALSCORE]) { -// dataStr = YMLocalizedString(@"XPRoomLittleGameContainerView7"); -// [self handleState_MG_DG_TOTALSCORE_WithUserId:userId dataJson:dataJson]; -// } else if ([state isEqualToString:MG_DG_SCORE]) { -// dataStr = YMLocalizedString(@"XPRoomLittleGameContainerView8"); -// [self handleState_MG_DG_SCORE_WithUserId:userId dataJson:dataJson]; -// }else { -// NSLog(@"ISudFSMMG:onPlayerStateChange:未做解析状态:%@", MG_DG_SCORE); -// } -// NSLog(@"ISudFSMMG:onPlayerStateChange:dataStr:%@", dataStr); -// /// 回调 -// NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@(0), @"ret_code", @"return form APP onPlayerStateChange", @"ret_msg", nil]; -// [handle success:[SudCommon dictionaryToJson:dict]]; -//} -// -///// 退出游戏 -//- (void)handleSelfInExitEvent { -// if (self.hostDelegate.getRoomInfo.type != RoomType_MiniGame) { -// return; -// } -// /// 正在游戏中,只退出游戏 -// if ([self getCurrentUserSudGameStatus] == LittleGamePlayStatus_Plying) { -// [self notifyIsPlayingState:false]; -// [self nofityPlayerPlaying:NO]; -// [self notifySetReady:false]; -// [self updateMicInfoWithGameStatus:LittleGamePlayStatus_NoIn]; -// } else if ([self getCurrentUserSudGameStatus] == LittleGamePlayStatus_Ready) { /// 非游戏状态下 -// /// 如果已经准备先退出准备状态 -// [self notifySetReady:false]; -// [self updateMicInfoWithGameStatus:LittleGamePlayStatus_NoIn]; -// } else { -// [self updateMicInfoWithGameStatus:LittleGamePlayStatus_NoIn]; -// } -// /// 下游戏麦 -// [self notifySelfInState:false seatIndex:-1]; -//} -// -///// 准备游戏 -//- (void)handleSelfReadyEvent { -// [self notifySetReady:true]; -//} -// -///// 取消准备 -//- (void)handleSelfCancelReadyEvent { -// [self notifySetReady:false]; -//} -// -///// 开始游戏 -//- (void)handleGameStartEvent { -// [self notifyIsPlayingState:YES]; -//} -// -//#pragma mark =======APP->游戏状态处理======= -///// 状态通知(app to mg) -///// @param state 状态名称 -///// @param dataJson 需传递的json -//- (void)notifyStateChange:(NSString *) state dataJson:(NSString*) dataJson { -// [self.fsmAPP2MG notifyStateChange:state dataJson:dataJson listener:^(int retCode, const NSString *retMsg, const NSString *dataJson) { -// NSLog(@"ISudFSMMG:notifyStateChange:retCode=%@ retMsg=%@ dataJson=%@", @(retCode), retMsg, dataJson); -// RoomInfoModel * roomInfo = self.hostDelegate.getRoomInfo; -// if (retCode == 0 && [state isEqualToString:APP_COMMON_SELF_PLAYING]) {//开始游戏 -// //上报游戏开始 -// NSString *mgid = [NSString stringWithFormat:@"%lld", self.currentmgId]; -// if (mgid.length <= 0) { -// return; -// } -// [Api startGameCheck:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { -// if (code != 200) { -// [XNDJTDDLoadingTool showErrorWithMessage:msg]; -// } -// } roomUid:[NSString stringWithFormat:@"%ld", roomInfo.uid] mgId:mgid]; -// } else if (retCode == 0 && [state isEqualToString:APP_COMMON_SELF_END]) {//结束游戏 -// -// } -// }]; -//} -// -///// 加入,退出游戏 -///// @param isIn YES:加入 NO:退出 -//- (void)notifySelfInState:(BOOL)isIn uid:(NSInteger)uid { -// NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@(isIn), @"isIn", @(1), @"teamId", nil]; -// [self notifyStateChange:APP_COMMON_SELF_IN dataJson:[SudCommon dictionaryToJson:dic]]; -//} -// -///// 加入,退出游戏 -///// @param isIn YES:加入 NO:退出 -//- (void)notifySelfInState:(BOOL)isIn seatIndex:(int)seatIndex { -// NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@(seatIndex), @"seatIndex", @(isIn), @"isIn", @(1), @"teamId", nil]; -// [self notifyStateChange:APP_COMMON_SELF_IN dataJson:[SudCommon dictionaryToJson:dic]]; -//} -// -///// 踢出用户 -///// @param userId 踢出用户id -//- (void)notifyKickStateWithUserId:(NSString *)userId { -// NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:userId, @"kickedUID", nil]; -// [self notifyStateChange:APP_COMMON_SELF_KICK dataJson:[SudCommon dictionaryToJson:dic]]; -//} -// -///// 设置用户为队长 -///// @param userId 被设置用户id -//- (void)notifySetCaptainStateWithUserId:(NSString *)userId { -// NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:userId, @"curCaptainUID", nil]; -// [self notifyStateChange:APP_COMMON_SELF_CAPTAIN dataJson:[SudCommon dictionaryToJson:dic]]; -//} -// -///// 命中 关键词状态 (你画我猜) -//- (void)notifyChangeTextHitState:(NSString *)keyWord { -// if([keyWord isKindOfClass:[NSNull class]])return; -// if (keyWord.length && [keyWord containsString:self.DrawSomethingKeyWord]) { -// NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@(true), @"isHit", self.DrawSomethingKeyWord, @"keyWord", self.DrawSomethingKeyWord, @"text", nil]; -// [self notifyStateChange:APP_COMMON_SELF_TEXT_HIT dataJson:[SudCommon dictionaryToJson:dic]]; -// } -//} -// -///// 是否设置为准备状态 -//- (void)notifySetReady:(BOOL)isReady { -// NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@(isReady), @"isReady", nil]; -// [self notifyStateChange:APP_COMMON_SELF_READY dataJson:[SudCommon dictionaryToJson:dic]]; -//} -// -///// 停止游戏状态设置 -//- (void)notifySetEnd { -// [self notifyStateChange:APP_COMMON_SELF_END dataJson:[SudCommon dictionaryToJson:@{}]]; -//} -// -///// 游戏中状态设置 -//- (void)notifyIsPlayingState:(BOOL)isPlaying { -// NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@(isPlaying), @"isPlaying", nil]; -// [self notifyStateChange:APP_COMMON_SELF_PLAYING dataJson:[SudCommon dictionaryToJson:dic]]; -//} -// -/////游戏中退出游戏 -//- (void)nofityPlayerPlaying:(BOOL)isPlaying { -// NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@(isPlaying), @"isPlaying", nil]; -// [self notifyStateChange:MG_COMMON_PLAYER_PLAYING dataJson:[SudCommon dictionaryToJson:dic]]; -//} -// -//#pragma mark =======游戏->APP状态处理======= -//- (void)handleState_MG_COMMON_PLAYER_IN_WithUserId:(NSString *)userId dataJson:(NSString *)dataJson { -// NSDictionary * dic = [SudCommon turnStringToDictionary:dataJson]; -// /// 加入状态:YES加入,NO退出 -// BOOL isIn = NO; -// if (dic) { -// NSInteger retCode = [[dic objectForKey:@"retCode"] integerValue]; -// if (retCode != 0) { -// return; -// } -// isIn = [[dic objectForKey:@"isIn"] boolValue]; -// } -// if ([userId isEqualToString:[AccountInfoStorage instance].getUid]) {//是当前用户 -// if (isIn) {//加入了游戏 -// //判断是否在麦上 -// if ([self isOnMicro:[userId longLongValue]]) { -// [self updateMicInfoWithGameStatus:LittleGamePlayStatus_IsIn]; -// } else {//不在麦上 -// [self upMicToJoinGame]; -// } -// //判断是否为房主,房主需要设为队长 -// if (self.hostDelegate.getRoomInfo.uid == userId.integerValue) { -// [self notifySetCaptainStateWithUserId:userId]; -// } -// self.sudGameStatus = LittleGamePlayStatus_IsIn; -// }else {//退出了游戏 -// //判断是否在麦上 -// if ([self isOnMicro:[userId longLongValue]]) { -// [self updateMicInfoWithGameStatus:LittleGamePlayStatus_NoIn]; -// } -// self.sudGameStatus = LittleGamePlayStatus_NoIn; -// } -// } else {//退出游戏 -// if (self.sudGameStatus == LittleGamePlayStatus_Plying) {//游戏进行中,用户退出 -// ///自己是公会超管 -// BOOL meIsSuperAdmin = NO; -// for (GuildSuperAdminInfoModel *managerInfo in self.hostDelegate.getRoomSuperAdminList) { -// if ([managerInfo.uid isEqualToString:[AccountInfoStorage instance].getUid]) { -// meIsSuperAdmin = YES; -// break; -// } -// } -// NIMChatroomMembersByIdsRequest *request = [[NIMChatroomMembersByIdsRequest alloc]init]; -// request.roomId = [NSString stringWithFormat:@"%ld", self.hostDelegate.getRoomInfo.roomId]; -// request.userIds = @[[AccountInfoStorage instance].getUid]; -// [[NIMSDK sharedSDK].chatroomManager fetchChatroomMembersByIds:request completion:^(NSError * _Nullable error, NSArray * _Nullable members) { -// if (error == nil) { -// NIMChatroomMember *member = members.firstObject; -// if (member.type == NIMChatroomMemberTypeManager || member.type == NIMChatroomMemberTypeCreator || meIsSuperAdmin) { -// NIMChatroomMembersByIdsRequest *request = [[NIMChatroomMembersByIdsRequest alloc]init]; -// request.roomId = [NSString stringWithFormat:@"%ld", self.hostDelegate.getRoomInfo.roomId]; -// request.userIds = @[userId]; -// [[NIMSDK sharedSDK].chatroomManager fetchChatroomMembersByIds:request completion:^(NSError * _Nullable error, NSArray * _Nullable members) { -// if (error == nil) { -// NIMChatroomMember *member = members.firstObject; -// [XNDJTDDLoadingTool showErrorWithMessage:[NSString stringWithFormat:YMLocalizedString(@"XPRoomLittleGameContainerView9"), member.roomNickname]]; -// } -// }]; -// } -// } -// }]; -// -// } -// } -//} -// -//- (void)handleState_MG_COMMON_PLAYER_READY_WithUserId:(NSString *)userId dataJson:(NSString *)dataJson { -// /// 玩家是否准备,YES:已准备,NO:未准备 -// BOOL isReady = NO; -// NSDictionary * dic = [SudCommon turnStringToDictionary:dataJson]; -// if (dic) { -// NSInteger retCode = [[dic objectForKey:@"retCode"] integerValue]; -// if (retCode != 0) { -// return; -// } -// isReady = [[dic objectForKey:@"isReady"] boolValue]; -// } -// if ([userId isEqualToString:[AccountInfoStorage instance].getUid]) { -// if (isReady) { -// //判断是否在麦上 -// if ([self isOnMicro:[userId longLongValue]]) { -// [self updateMicInfoWithGameStatus:LittleGamePlayStatus_Ready]; -// } -// self.sudGameStatus = LittleGamePlayStatus_Ready; -// }else { -// if ([self isOnMicro:[userId longLongValue]]) { -// [self updateMicInfoWithGameStatus:LittleGamePlayStatus_IsIn]; -// } -// self.sudGameStatus = LittleGamePlayStatus_IsIn; -// } -// } -//} -// -//- (void)handleState_MG_COMMON_PLAYER_CAPTAIN_WithUserId:(NSString *)userId dataJson:(NSString *)dataJson { -// /// 是否是队长:YES:是队长 NO:不是队长 -// BOOL isCaptain = NO; -// NSDictionary * dic = [SudCommon turnStringToDictionary:dataJson]; -// if (dic) { -// /// 错误处理 -// NSInteger retCode = [[dic objectForKey:@"retCode"] integerValue]; -// if (retCode != 0) { -// return; -// } -// isCaptain = [[dic objectForKey:@"isCaptain"] boolValue]; -// } -//} -// -//- (void)handleState_MG_COMMON_PLAYER_PLAYING_WithUserId:(NSString *)userId dataJson:(NSString *)dataJson { -// /// 是否正在游戏中 -// BOOL isPlaying = NO; -// NSDictionary * dic = [SudCommon turnStringToDictionary:dataJson]; -// if (dic) { -// /// 错误处理 -// NSInteger retCode = [[dic objectForKey:@"retCode"] integerValue]; -// if (retCode != 0) { -// return; -// } -// isPlaying = [[dic objectForKey:@"isPlaying"] boolValue]; -// } -// if ([userId isEqualToString:[AccountInfoStorage instance].getUid]) { -// if (isPlaying) { -// //判断是否在麦上 -// if ([self isOnMicro:[userId longLongValue]]) { -// [self updateMicInfoWithGameStatus:LittleGamePlayStatus_Plying]; -// } -// if (self.delegate && [self.delegate respondsToSelector:@selector(hiddenSudGamePostionView)]) { -// [self.delegate hiddenSudGamePostionView]; -// } -// self.sudGameStatus = LittleGamePlayStatus_Plying; -// }else { -// if ([self isOnMicro:[userId longLongValue]]) { -// [self updateMicInfoWithGameStatus:LittleGamePlayStatus_IsIn]; -// } -// self.sudGameStatus = LittleGamePlayStatus_IsIn; -// } -// } -//} -// -//- (void)handleState_MG_DG_SELECTING_WithUserId:(NSString *)userId dataJson:(NSString *)dataJson { -// NSLog(@"handleState_MG_DG_SELECTING_WithUserId%@",dataJson); -//} -// -//- (void)handleState_MG_DG_PAINTING_WithUserId:(NSString *)userId dataJson:(NSString *)dataJson { -// NSLog(@"handleState_MG_DG_PAINTING_WithUserId%@",dataJson); -// /// 设置麦位状态为作画中 -// NSDictionary * dic = [SudCommon turnStringToDictionary:dataJson]; -// bool isPainting = NO; -// if (dic) { -// isPainting = [dic[@"isPainting"] boolValue]; -// } -//} -// -//- (void)handleState_MG_DG_ERRORANSWER_WithUserId:(NSString *)userId dataJson:(NSString *)dataJson { -// /// 错误答案 -// NSLog(@"handleState_MG_DG_ERRORANSWER_WithUserId%@",dataJson); -// -//} -// -//- (void)handleState_MG_DG_TOTALSCORE_WithUserId:(NSString *)userId dataJson:(NSString *)dataJson { -// /// 总积分 -// NSLog(@"handleState_MG_DG_TOTALSCORE_WithUserId%@",dataJson); -//} -// -//- (void)handleState_MG_DG_SCORE_WithUserId:(NSString *)userId dataJson:(NSString *)dataJson { -// /// 本次积分 -// NSLog(@"handleState_MG_DG_SCORE_WithUserId%@",dataJson); -//} -// -///// 销毁MG -//- (void)destroyMG { -// if (self.hostDelegate.getRoomInfo.type == RoomType_MiniGame) { -// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ -// [self.fsmAPP2MG destroyMG]; -// }); -// } -//} -// -//#pragma mark - RoomGuestDelegate -//- (void)onRoomEntered { -// if (self.hostDelegate.getRoomInfo.type != RoomType_MiniGame) { -// self.hidden = YES; -// return; -// } else { -// self.hidden = NO; -// } -// [self updateSudGame]; -//} -// -//- (void)onRoomUpdate { -// if (self.hostDelegate.getRoomInfo.type != RoomType_MiniGame) { -// self.hidden = YES; -// [self.fsmAPP2MG destroyMG]; -// } else { -// self.hidden = NO; -// } -// [self updateSudGame]; -//} -//#pragma mark - RoomGuestDelegate -//- (void)handleNIMCustomMessage:(NIMMessage *)message { -// if (self.hostDelegate.getRoomInfo.type != RoomType_MiniGame) { -// return; -// } -// NIMCustomObject *obj = (NIMCustomObject *)message.messageObject; -// if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) { -// AttachmentModel *attachment = (AttachmentModel *)obj.attachment; -// if (attachment.first == CustomMessageType_Kick_User) { -// XPKickUserModel * kickModel = [XPKickUserModel modelWithJSON:attachment.data]; -// [self onDownMic:kickModel.uid]; -// } else if(attachment.first == CustomMessageType_Queue && attachment.second == Custom_Message_Sub_Queue_Kick) { -// XPKickUserModel * kickModel = [XPKickUserModel modelWithJSON:attachment.data]; -// [self onDownMic:kickModel.uid]; -// } -// } -//} -// -//- (void)handleNIMNotificationMessage:(NIMMessage *)message { -// if (self.hostDelegate.getRoomInfo.type != RoomType_MiniGame) {return;} -// NIMNotificationObject *notiMsg = (NIMNotificationObject *)message.messageObject; -// NIMChatroomNotificationContent *content = (NIMChatroomNotificationContent *)notiMsg.content; -// switch (content.eventType) { -// case NIMChatroomEventTypeQueueChange: // 麦序上下麦 -// { -// NSDictionary* data = (NSDictionary *)content.ext; -// UserInfoModel* userInfo = [UserInfoModel modelWithJSON:[data objectForKey:NIMChatroomEventInfoQueueChangeItemValueKey]]; -// NSInteger changeType = [data[NIMChatroomEventInfoQueueChangeTypeKey] integerValue]; -// if (changeType != 1) { -// [self onDownMic:userInfo.uid]; -// } -// } -// break; -// default: -// break; -// } -//} -// -//- (void)handleNIMTextMessage:(NIMMessage *)message { -// if (self.hostDelegate.getRoomInfo.type != RoomType_MiniGame) {return;} -// if (message.from.integerValue == [AccountInfoStorage instance].getUid.integerValue && [self isInSudGame]) { -// [self notifyChangeTextHitState:message.text]; -// } -//} +#pragma mark - Private Method +- (void)updateSudGame { + if(self.currentmgId == self.gameModel.data.mgId.integerValue)return; + self.currentmgId = self.gameModel.data.mgId.integerValue; + [self initLittleGame]; +} + +- (void)initLittleGame { + [Api getSudGameCode:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { + if (code == 200) { + NSString * gameCode = data.data[@"code"]; + self.code = gameCode; + [self gameSetUp]; + } else { + [XNDJTDDLoadingTool showErrorWithMessage:msg]; + } + } uid:[AccountInfoStorage instance].getUid]; +} + +- (void)gameSetUp { + NSLog(@"小游戏的版本号是:%@", [SudMGP getVersion]); + BOOL isTestEnv = NO; +#ifdef DEBUG + isTestEnv = YES; +#else + isTestEnv = NO; +#endif + if(isEnterprise == NO){ + [[SudMGP getCfg]setBackgroundMode:NO]; + } + [SudMGP initSDK:KeyWithType(KeyType_SudGameAppID) appKey:KeyWithType(KeyType_SudGameAppKey) isTestEnv:isTestEnv listener:^(int retCode, const NSString *retMsg) { + if (retCode == 0) { + if (!self.currentmgId) { + return; + } + NSString * userId = [AccountInfoStorage instance].getUid; + NSString * roomId = self.gameModel.roomId; + NSLog(@"用户ID:%@,房间ID:%@, 游戏ID:%lld, code:%@", userId, roomId, self.currentmgId, self.code); +// + + NSString *language = [NSBundle getLanguageText]; + if ([language hasPrefix:@"zh"]) { + if ([language rangeOfString:@"Hans"].location != NSNotFound) { + language = @"zh-CN"; // 简体中文 + } else { + language = @"zh-TW"; // 繁體中文 + } + }else{ + language = @"en-US"; // 英文 + } + self.fsmAPP2MG = [SudMGP loadMG:userId roomId:roomId code:self.code mgId:self.currentmgId language:language fsmMG:self rootView:self]; + + + + + + } else { + /// 初始化失败, 可根据业务重试 + NSLog(@"ISudFSMMG:initGameSDKWithAppID:初始化sdk失败 :%@",retMsg); + } + }]; +} + +//判断是否在麦上 + + +//通过uid判断麦位 + + +//上麦以加入游戏 +- (void)upMicToJoinGame { + +} + +- (void)updateMicInfoWithGameStatus:(LittleGamePlayStatus)status { + +} + +/** + * 麦位更新扩展字段。 + */ +- (NSDictionary *)userInfoToQueueExt:(UserInfoModel *)userInfo { + MicroExtModel * extModel = [[MicroExtModel alloc] init]; + extModel.gender = userInfo.gender; + extModel.avatar = userInfo.avatar; + extModel.uid = userInfo.uid; + extModel.nick = userInfo.nick; + extModel.gameStatus = userInfo.gameStatus; + extModel.headWearUrl = userInfo.headwearEffect.length > 0 ? userInfo.headwearEffect : userInfo.headwearPic; + extModel.preventKick = userInfo.userVipInfoVO.preventKick; + extModel.enterHide = userInfo.userVipInfoVO.enterHide; + return [extModel model2dictionary]; +} + + + + +///下麦 +- (void)onDownMic:(NSInteger)uid { + if (uid == [AccountInfoStorage instance].getUid.integerValue) {//自己下麦 + [self notifyIsPlayingState:false]; + [self nofityPlayerPlaying:NO]; + [self notifySetReady:false]; + /// 下游戏麦 + [self notifySelfInState:false seatIndex:-1]; + } +} + +#pragma mark =======ISudFSMMG Delegate======= +/** +* 游戏日志 +*/ +-(void)onGameLog:(NSString*)dataJson { + NSLog(@"ISudFSMMG:onGameLog:%@", dataJson); + NSDictionary * dic = [SudCommon turnStringToDictionary:dataJson]; + NSString * msg_string = [dic objectForKey:@"msg"]; + if (!msg_string) { + return; + } +} + +/** +* 游戏开始 +*/ +-(void)onGameStarted { + NSLog(@"ISudFSMMG:onGameStarted:游戏开始"); + [self notifySelfInState:YES seatIndex:-1];///加入房间 + [self handleSelfReadyEvent];///准备游戏 + +} + +/** + * 游戏销毁 + */ +-(void)onGameDestroyed { + NSLog(@"ISudFSMMG:onGameDestroyed:游戏开始"); +} + +/** + * Code过期 + * @param dataJson {"code":"value"} + */ +-(void)onExpireCode:(id)handle dataJson:(NSString*)dataJson { + NSLog(@"ISudFSMMG:onExpireCode:Code过期"); + // 请求业务服务器刷新令牌 + [Api getSudGameCode:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { + if (code == 200) { + NSString * gameCode = data.data[@"code"]; + self.code = gameCode; + [self.fsmAPP2MG updateCode:gameCode listener:^(int retCode, const NSString *retMsg, const NSString *dataJson) { + NSLog(@"ISudFSMMG:updateGameCode retCode=%@ retMsg=%@ dataJson=%@", @(retCode), retMsg, dataJson); + }]; + // 回调结果 + NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@(0), @"ret_code", @"return form APP onExpireCode", @"ret_msg", nil]; + [handle success:[SudCommon dictionaryToJson:dict]]; + } else { + [XNDJTDDLoadingTool showErrorWithMessage:msg]; + } + } uid:[AccountInfoStorage instance].getUid]; +} + +/** + * 获取游戏View信息 + * @param handle 回调句柄 + * @param dataJson {} + */ +-(void)onGetGameViewInfo:(id)handle dataJson:(NSString*)dataJson { + CGRect rect = [[UIScreen mainScreen] bounds]; + CGFloat scale = [[UIScreen mainScreen] nativeScale]; + + CGFloat top = kGetScaleWidth(185) * scale; + CGFloat bottom = kGetScaleWidth(175) *scale; + + CGFloat width = rect.size.width * scale; + CGFloat height = rect.size.height * scale; + NSDictionary *rectDict = [NSDictionary dictionaryWithObjectsAndKeys:@(top), @"top", @(0), @"left", @(bottom), @"bottom", @(0), @"right", nil]; + NSDictionary *viewDict = [NSDictionary dictionaryWithObjectsAndKeys:@(width), @"width", @(height), @"height", nil]; + NSDictionary *dataDict = [NSDictionary dictionaryWithObjectsAndKeys:@(0), @"ret_code", @"return form APP onGetGameViewInfo", @"ret_msg", viewDict, @"view_size", rectDict, @"view_game_rect", nil]; + /// 回调 + [handle success:[SudCommon dictionaryToJson:dataDict]]; +} + +/** + * 获取游戏配置 + * @param handle 回调句柄 + * @param dataJson {} + */ +-(void)onGetGameCfg:(id)handle dataJson:(NSString*)dataJson { + NSString *configJson = self.gameModel.data.configJson; + if(configJson != nil){ + [handle success:configJson]; + return; + } + NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; + dict[@"ret_code"] = @(0); + dict[@"ret_msg"] = @"return form APP onGetGameCfg"; + + dict[@"ui"] = @{ + @"join_btn" : @{@"custom": @(YES), @"hide": @(YES)},//加入游戏 + @"start_btn" : @{@"custom": @(YES), @"hide": @(YES)},//开始游戏 + @"ready_btn" : @{@"custom": @(YES), @"hide": @(YES)},//准备游戏 + @"lobby_players" : @{@"custom": @(YES), @"hide": @(YES)},//游戏中坑位点击 + @"level" : @{@"custom": @(YES), @"hide" : @(YES)},//段位信息 + @"cancel_join" : @{@"custom": @(YES), @"hide" : @(YES)},//退出游戏 + }; + NSString *dataJsonRet = @""; + NSData *dataJsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil]; + if (dataJsonData != nil) { + dataJsonRet = [[NSString alloc]initWithData:dataJsonData encoding:NSUTF8StringEncoding]; + } + [handle success:dataJsonRet]; +} + +/** + * 游戏状态变化 + * @param handle 回调句柄 + * @param state 游戏状态 + * @param dataJson 回调json + */ +-(void)onGameStateChange:(id) handle state:(NSString*) state dataJson:(NSString*) dataJson { + + if([state isEqualToString:MG_COMMON_GAME_SETTLE]){ + NSDictionary *data = @{@"value0":self.gameModel.data.matchRoundId ?: @""}; + NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[data mj_JSONString] , @"reportGameInfoExtras",@"value0" , @"reportGameInfoKey" ,nil]; + [self notifyStateChange:MG_COMMON_GAME_SETTLE dataJson:[SudCommon dictionaryToJson:dic]]; + if([dataJson containsString:@"value0"]){ + return; + } + NSDictionary *results = [dataJson mj_JSONObject]; + NSArray *list = [MSRoomGameResultsModel modelsWithArray:results[@"results"]]; + if(self.delegate && [self.delegate respondsToSelector:@selector(getGameRsultsWithList:)]){ + [self.delegate getGameRsultsWithList:list]; + } + + + }else if ([state isEqualToString:MG_COMMON_PUBLIC_MESSAGE]) { + NSLog(@"ISudFSMMG:onGameStateChange:游戏->APP:公屏消息"); + } else if ([state isEqualToString:MG_COMMON_KEY_WORD_TO_HIT]) { + + }else if ([state isEqualToString:MG_COMMON_SELF_CLICK_JOIN_BTN]) {//加入游戏按钮点击 + NSDictionary *dic = [SudCommon turnStringToDictionary:dataJson]; + int seatIndex = -1; + if ([dic objectForKey:@"seatIndex"]) { + seatIndex = [[dic objectForKey:@"seatIndex"] intValue]; + } + if (seatIndex == -1) { + NSLog(@"来自加入按钮%d",seatIndex); + }else { + NSLog(@"来自麦位+入%d",seatIndex); + } + [self notifySelfInState:YES seatIndex:-1]; + } else if([state isEqualToString:MG_COMMON_SELF_CLICK_START_BTN]) {//开始游戏按钮点击 + [self notifyIsPlayingState:YES]; + } else if ([state isEqualToString:MG_COMMON_SELF_CLICK_CANCEL_JOIN_BTN]) { + /// 取消加入游戏(退出游戏按钮点击) + [self handleSelfInExitEvent]; + } else { + /// 其他状态 + NSLog(@"ISudFSMMG:onGameStateChange:游戏->APP:state:%@",MG_COMMON_PUBLIC_MESSAGE); + } +} + +/** + * 游戏玩家状态变化 + * @param handle 回调句柄 + * @param userId 用户id + * @param state 玩家状态 + * @param dataJson 回调JSON + */ +-(void)onPlayerStateChange:(nullable id) handle userId:(NSString*) userId state:(NSString*) state dataJson:(NSString*) dataJson { + NSLog(@"ISudFSMMG:onPlayerStateChange:游戏->APP:游戏玩家状态变化:userId: %@ --state: %@ --dataJson: %@", userId, state, dataJson); + /// 状态解析 + NSString *dataStr = @""; + if ([state isEqualToString:MG_COMMON_PLAYER_IN]) { + dataStr = YMLocalizedString(@"XPRoomLittleGameContainerView0"); + [self handleState_MG_COMMON_PLAYER_IN_WithUserId:userId dataJson:dataJson]; + } else if ([state isEqualToString:MG_COMMON_PLAYER_READY]) { + dataStr = YMLocalizedString(@"XPRoomLittleGameContainerView1"); + [self handleState_MG_COMMON_PLAYER_READY_WithUserId:userId dataJson:dataJson]; + if(userId != nil && ![self.userList containsObject:userId]){ + [self.userList addObject:userId]; + } + if(self.userList.count > 1 && self.sudGameStatus != LittleGamePlayStatus_Plying){ + [self handleGameStartEvent];///开始游戏 + [self.userList removeAllObjects]; + + self.sudGameStatus = LittleGamePlayStatus_Plying; + } + } else if ([state isEqualToString:MG_COMMON_PLAYER_CAPTAIN]) { + dataStr = YMLocalizedString(@"XPRoomLittleGameContainerView2"); + [self handleState_MG_COMMON_PLAYER_CAPTAIN_WithUserId:userId dataJson:dataJson]; + + } else if ([state isEqualToString:MG_COMMON_PLAYER_PLAYING]) { + dataStr = YMLocalizedString(@"XPRoomLittleGameContainerView3"); + [self handleState_MG_COMMON_PLAYER_PLAYING_WithUserId:userId dataJson:dataJson]; + } else if ([state isEqualToString:MG_DG_SELECTING]) { + dataStr = YMLocalizedString(@"XPRoomLittleGameContainerView4"); + [self handleState_MG_DG_SELECTING_WithUserId:userId dataJson:dataJson]; + } else if ([state isEqualToString:MG_DG_PAINTING]) { + dataStr = YMLocalizedString(@"XPRoomLittleGameContainerView5"); + [self handleState_MG_DG_PAINTING_WithUserId:userId dataJson:dataJson]; + } else if ([state isEqualToString:MG_DG_ERRORANSWER]) { + dataStr = YMLocalizedString(@"XPRoomLittleGameContainerView6"); + [self handleState_MG_DG_ERRORANSWER_WithUserId:userId dataJson:dataJson]; + } else if ([state isEqualToString:MG_DG_TOTALSCORE]) { + dataStr = YMLocalizedString(@"XPRoomLittleGameContainerView7"); + [self handleState_MG_DG_TOTALSCORE_WithUserId:userId dataJson:dataJson]; + } else if ([state isEqualToString:MG_DG_SCORE]) { + dataStr = YMLocalizedString(@"XPRoomLittleGameContainerView8"); + [self handleState_MG_DG_SCORE_WithUserId:userId dataJson:dataJson]; + }else { + NSLog(@"ISudFSMMG:onPlayerStateChange:未做解析状态:%@", MG_DG_SCORE); + } + NSLog(@"ISudFSMMG:onPlayerStateChange:dataStr:%@", dataStr); + /// 回调 + NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@(0), @"ret_code", @"return form APP onPlayerStateChange", @"ret_msg", nil]; + [handle success:[SudCommon dictionaryToJson:dict]]; +} + +/// 退出游戏 +- (void)handleSelfInExitEvent { + + + /// 下游戏麦 + [self notifyIsPlayingState:false]; + [self nofityPlayerPlaying:NO]; + [self notifySetReady:false]; + [self notifySetEnd]; + /// 下游戏麦 + [self notifySelfInState:false seatIndex:-1]; + self.sudGameStatus = LittleGamePlayStatus_NoIn; +} + +/// 准备游戏 +- (void)handleSelfReadyEvent { + [self notifySetReady:true]; +} + +/// 取消准备 +- (void)handleSelfCancelReadyEvent { + [self notifySetReady:false]; +} + +/// 开始游戏 +- (void)handleGameStartEvent { + [self notifyIsPlayingState:YES]; +} + +#pragma mark =======APP->游戏状态处理======= +/// 状态通知(app to mg) +/// @param state 状态名称 +/// @param dataJson 需传递的json +- (void)notifyStateChange:(NSString *) state dataJson:(NSString*) dataJson { + [self.fsmAPP2MG notifyStateChange:state dataJson:dataJson listener:^(int retCode, const NSString *retMsg, const NSString *dataJson) { + NSLog(@"ISudFSMMG:notifyStateChange:retCode=%@ retMsg=%@ dataJson=%@", @(retCode), retMsg, dataJson); + + if (retCode == 0 && [state isEqualToString:APP_COMMON_SELF_PLAYING]) {//开始游戏 + //上报游戏开始 + NSString *mgid = [NSString stringWithFormat:@"%lld", self.currentmgId]; + if (mgid.length <= 0) { + return; + } + + } else if (retCode == 0 && [state isEqualToString:APP_COMMON_SELF_END]) {//结束游戏 + + } + }]; +} + +/// 加入,退出游戏 +/// @param isIn YES:加入 NO:退出 +- (void)notifySelfInState:(BOOL)isIn uid:(NSInteger)uid { + NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@(isIn), @"isIn", @(1), @"teamId", nil]; + [self notifyStateChange:APP_COMMON_SELF_IN dataJson:[SudCommon dictionaryToJson:dic]]; +} + +/// 加入,退出游戏 +/// @param isIn YES:加入 NO:退出 +- (void)notifySelfInState:(BOOL)isIn seatIndex:(int)seatIndex { + NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@(seatIndex), @"seatIndex", @(isIn), @"isIn", @(1), @"teamId", nil]; + [self notifyStateChange:APP_COMMON_SELF_IN dataJson:[SudCommon dictionaryToJson:dic]]; +} + +/// 踢出用户 +/// @param userId 踢出用户id +- (void)notifyKickStateWithUserId:(NSString *)userId { + NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:userId, @"kickedUID", nil]; + [self notifyStateChange:APP_COMMON_SELF_KICK dataJson:[SudCommon dictionaryToJson:dic]]; +} + +/// 设置用户为队长 +/// @param userId 被设置用户id +- (void)notifySetCaptainStateWithUserId:(NSString *)userId { + NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:userId, @"curCaptainUID", nil]; + [self notifyStateChange:APP_COMMON_SELF_CAPTAIN dataJson:[SudCommon dictionaryToJson:dic]]; + +} + +/// 命中 关键词状态 (你画我猜) +- (void)notifyChangeTextHitState:(NSString *)keyWord { + +} + +/// 是否设置为准备状态 +- (void)notifySetReady:(BOOL)isReady { + NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@(isReady), @"isReady", nil]; + [self notifyStateChange:APP_COMMON_SELF_READY dataJson:[SudCommon dictionaryToJson:dic]]; +} + +/// 停止游戏状态设置 +- (void)notifySetEnd { + [self notifyStateChange:APP_COMMON_SELF_END dataJson:[SudCommon dictionaryToJson:@{}]]; +} + +/// 游戏中状态设置 +- (void)notifyIsPlayingState:(BOOL)isPlaying { + NSDictionary *data = @{@"value0":self.gameModel.data.matchRoundId ?: @""}; + NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@(isPlaying), @"isPlaying",[data mj_JSONString] , @"reportGameInfoExtras",@"value0", @"reportGameInfoKey" ,nil]; + [self notifyStateChange:APP_COMMON_SELF_PLAYING dataJson:[SudCommon dictionaryToJson:dic]]; +} + +///游戏中退出游戏 +- (void)nofityPlayerPlaying:(BOOL)isPlaying { + NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@(isPlaying), @"isPlaying", nil]; + [self notifyStateChange:MG_COMMON_PLAYER_PLAYING dataJson:[SudCommon dictionaryToJson:dic]]; +} + +#pragma mark =======游戏->APP状态处理======= +- (void)handleState_MG_COMMON_PLAYER_IN_WithUserId:(NSString *)userId dataJson:(NSString *)dataJson { + NSDictionary * dic = [SudCommon turnStringToDictionary:dataJson]; + /// 加入状态:YES加入,NO退出 + BOOL isIn = NO; + if (dic) { + NSInteger retCode = [[dic objectForKey:@"retCode"] integerValue]; + if (retCode != 0) { + return; + } + isIn = [[dic objectForKey:@"isIn"] boolValue]; + } + if ([userId isEqualToString:[AccountInfoStorage instance].getUid]) {//是当前用户 + if (isIn) {//加入了游戏 + //判断是否在麦上 + + //判断是否为房主,房主需要设为队长 + if (self.gameModel.roomId.integerValue == userId.integerValue) { + [self notifySetCaptainStateWithUserId:userId]; + } + + + + }else {//退出了游戏 + + + } + } else {//退出游戏 + if (self.sudGameStatus == LittleGamePlayStatus_Plying) {//游戏进行中,用户退出 + + + + } + } +} + +- (void)handleState_MG_COMMON_PLAYER_READY_WithUserId:(NSString *)userId dataJson:(NSString *)dataJson { + /// 玩家是否准备,YES:已准备,NO:未准备 + BOOL isReady = NO; + NSDictionary * dic = [SudCommon turnStringToDictionary:dataJson]; + if (dic) { + NSInteger retCode = [[dic objectForKey:@"retCode"] integerValue]; + if (retCode != 0) { + return; + } + isReady = [[dic objectForKey:@"isReady"] boolValue]; + } + if ([userId isEqualToString:[AccountInfoStorage instance].getUid]) { + if (isReady) { + //判断是否在麦上 + + + }else { + + + } + } +} + +- (void)handleState_MG_COMMON_PLAYER_CAPTAIN_WithUserId:(NSString *)userId dataJson:(NSString *)dataJson { + /// 是否是队长:YES:是队长 NO:不是队长 + BOOL isCaptain = NO; + NSDictionary * dic = [SudCommon turnStringToDictionary:dataJson]; + if (dic) { + /// 错误处理 + NSInteger retCode = [[dic objectForKey:@"retCode"] integerValue]; + if (retCode != 0) { + return; + } + isCaptain = [[dic objectForKey:@"isCaptain"] boolValue]; + } +} + +- (void)handleState_MG_COMMON_PLAYER_PLAYING_WithUserId:(NSString *)userId dataJson:(NSString *)dataJson { + /// 是否正在游戏中 + BOOL isPlaying = NO; + NSDictionary * dic = [SudCommon turnStringToDictionary:dataJson]; + if (dic) { + /// 错误处理 + NSInteger retCode = [[dic objectForKey:@"retCode"] integerValue]; + if (retCode != 0) { + return; + } + isPlaying = [[dic objectForKey:@"isPlaying"] boolValue]; + } + if ([userId isEqualToString:[AccountInfoStorage instance].getUid]) { + if (isPlaying) { + + + }else { + + + } + } +} + +- (void)handleState_MG_DG_SELECTING_WithUserId:(NSString *)userId dataJson:(NSString *)dataJson { + NSLog(@"handleState_MG_DG_SELECTING_WithUserId%@",dataJson); +} + +- (void)handleState_MG_DG_PAINTING_WithUserId:(NSString *)userId dataJson:(NSString *)dataJson { + NSLog(@"handleState_MG_DG_PAINTING_WithUserId%@",dataJson); + /// 设置麦位状态为作画中 + NSDictionary * dic = [SudCommon turnStringToDictionary:dataJson]; + bool isPainting = NO; + if (dic) { + isPainting = [dic[@"isPainting"] boolValue]; + } +} + +- (void)handleState_MG_DG_ERRORANSWER_WithUserId:(NSString *)userId dataJson:(NSString *)dataJson { + /// 错误答案 + NSLog(@"handleState_MG_DG_ERRORANSWER_WithUserId%@",dataJson); + +} + +- (void)handleState_MG_DG_TOTALSCORE_WithUserId:(NSString *)userId dataJson:(NSString *)dataJson { + /// 总积分 + NSLog(@"handleState_MG_DG_TOTALSCORE_WithUserId%@",dataJson); +} + +- (void)handleState_MG_DG_SCORE_WithUserId:(NSString *)userId dataJson:(NSString *)dataJson { + /// 本次积分 + NSLog(@"handleState_MG_DG_SCORE_WithUserId%@",dataJson); +} + +/// 销毁MG +- (void)destroyMG { + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [self.fsmAPP2MG destroyMG]; + }); + +} + +#pragma mark - RoomGuestDelegate +- (void)onRoomEntered { + + [self updateSudGame]; +} + +- (void)onRoomUpdate { + + [self.fsmAPP2MG destroyMG]; + + [self updateSudGame]; +} +#pragma mark - RoomGuestDelegate +- (void)handleNIMCustomMessage:(NIMMessage *)message { + +} + +- (void)handleNIMNotificationMessage:(NIMMessage *)message { + + NIMNotificationObject *notiMsg = (NIMNotificationObject *)message.messageObject; + NIMChatroomNotificationContent *content = (NIMChatroomNotificationContent *)notiMsg.content; + switch (content.eventType) { + case NIMChatroomEventTypeQueueChange: // 麦序上下麦 + { + NSDictionary* data = (NSDictionary *)content.ext; + UserInfoModel* userInfo = [UserInfoModel modelWithJSON:[data objectForKey:NIMChatroomEventInfoQueueChangeItemValueKey]]; + NSInteger changeType = [data[NIMChatroomEventInfoQueueChangeTypeKey] integerValue]; + if (changeType != 1) { + [self onDownMic:userInfo.uid]; + } + } + break; + default: + break; + } +} + +- (void)handleNIMTextMessage:(NIMMessage *)message { + if (message.from.integerValue == [AccountInfoStorage instance].getUid.integerValue && [self isInSudGame]) { + [self notifyChangeTextHitState:message.text]; + } +} + +- (NSMutableArray *)userList{ + if(!_userList){ + _userList = [NSMutableArray array]; + } + return _userList; +} @end diff --git a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSTabbarBeginGameView.h b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSTabbarBeginGameView.h index 345c5015..dd002add 100644 --- a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSTabbarBeginGameView.h +++ b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSTabbarBeginGameView.h @@ -11,7 +11,8 @@ NS_ASSUME_NONNULL_BEGIN @protocol MSTabbarBeginGameViewDelegate //开始游戏 -(void)startMatchGameActionWithModel:(MSTabbarRoomGameItemModel *)model; - +///规则 +-(void)clickRuleActionWithModel:(MSTabbarRoomGameItemModel *)model; @end @interface MSTabbarBeginGameView : UIView @property(nonatomic,weak) iddelegate; diff --git a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSTabbarBeginGameView.m b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSTabbarBeginGameView.m index ea627122..d8792958 100644 --- a/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSTabbarBeginGameView.m +++ b/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSTabbarBeginGameView.m @@ -98,7 +98,11 @@ _coinNumView.text = _itemModel.ticket; _titleView.text = _itemModel.modeName; } - +-(void)ruleBtnAction{ + if(self.delegate && [self.delegate respondsToSelector:@selector(clickRuleActionWithModel:)]){ + [self.delegate clickRuleActionWithModel:self.itemModel]; + } +} #pragma mark - 懒加载 - (UIImageView *)bgImageView{ if(!_bgImageView){ @@ -155,6 +159,7 @@ _ruleBtn = [UIButton new]; [_ruleBtn setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10]; [_ruleBtn setBackgroundImage:kImage(@"ms_room_game_begin_rule_icon") forState:UIControlStateNormal]; + [_ruleBtn addTarget:self action:@selector(ruleBtnAction) forControlEvents:UIControlEventTouchUpInside]; } return _ruleBtn; } diff --git a/YuMi/Modules/YMTabbar/View/TabbarViewController.m b/YuMi/Modules/YMTabbar/View/TabbarViewController.m index 6fc2f826..005016e9 100644 --- a/YuMi/Modules/YMTabbar/View/TabbarViewController.m +++ b/YuMi/Modules/YMTabbar/View/TabbarViewController.m @@ -34,7 +34,10 @@ #import "YYUtility.h" #import "XPWeakTimer.h" #import "PLTimeUtil.h" +#import "Api+MSRoomGameApi.h" + ///Model +#import "MSRoomGameModel.h" #import "AccountModel.h" #import "RoomInfoModel.h" #import "AttachmentModel.h" @@ -48,6 +51,7 @@ #import "XPRedPacketModel.h" #import "GiftReceiveInfoModel.h" #import "XPVersionUpdateModel.h" +#import "MSRoomGameQuitGameView.h" ///VC #import "TabbarViewController.h" #import "XPBlankViewController.h" @@ -66,6 +70,7 @@ #import "XPWebViewController.h" #import "XPMineUserInfoViewController.h" #import "MSTabbarRoomGameVC.h" +#import "MSRoomGameVC.h" #import "XPMonentsRecommendViewController.h" #import "XPMonentsViewController.h" @@ -82,7 +87,7 @@ #import #import "Api+Gift.h" #import "UploadFile.h" - +#import "XPTabBar.h" NSString * const kUserFirstLoginKey = @"kUserFirstLoginKey"; @@ -92,7 +97,7 @@ NSString * const kNetworkReachabilityKey = @"kNetworkReachabilityKey"; UIKIT_EXTERN NSString * kNewUserRechargeKey; UIKIT_EXTERN NSString *kTabShowAnchorCardKey; -@interface TabbarViewController () +@interface TabbarViewController () { NSTimer * timer; } @@ -136,7 +141,8 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey; - (void)viewDidLoad { [super viewDidLoad]; - +// XPTabBar *tabbar = [[XPTabBar alloc]initWithFrame:CGRectMake(0, KScreenHeight - kTabBarHeight, KScreenWidth, kTabBarHeight)]; +// [self setValue:tabbar forKey:@"tabBar"]; [self.presenter autoLogin]; [self configTheme]; [self initTabs:NO]; @@ -248,7 +254,41 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey; [[NSUserDefaults standardUserDefaults] synchronize]; } } +-(void)getRoomGameInfo{ + [Api getRoomGameDetails:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { + if(code == 200){ + MSRoomGameModel *model = [MSRoomGameModel modelWithJSON:data.data]; + if(model.data.matchStatus == 1 && model.data.roundStatus == 0){ + MSTabbarRoomGameItemModel *chooseGameModel = [MSTabbarRoomGameItemModel new]; + chooseGameModel.scores = model.data.scores; + chooseGameModel.roomId = model.roomId; + MSRoomGameQuitGameView *quitGameView = [[MSRoomGameQuitGameView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)]; + quitGameView.chooseGameModel = chooseGameModel; + quitGameView.delegate = self; + [TTPopup popupView:quitGameView style:TTPopupStyleAlert]; + + } + } + } roomType:@"0"]; +} +#pragma mark -MSRoomGameQuitGameViewDelegate +///退出游戏 +- (void)closeGameActionWithModel:(MSTabbarRoomGameItemModel *)model{ + [Api closeRoomGame:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { + + } roomId:model.roomId]; +} +///强杀app打开后,是否重新玩游戏 +-(void)replayTheGameWithModel:(MSTabbarRoomGameItemModel *)model{ + MSRoomGameVC *gameVC = [MSRoomGameVC new]; + + gameVC.chooseGameModel = model; + gameVC.userinfo = self.userInfo; + BaseNavigationController *nav = [[BaseNavigationController alloc]initWithRootViewController:gameVC]; + nav.modalPresentationStyle = UIModalPresentationFullScreen; + [self presentViewController:nav animated:YES completion:nil]; +} /// 获取用户信息后检查:1、是否绑定手机号;2、是否需要完善用户信息。 /// 该逻辑仅在刷新ticket后执行一次。 /// 当前服务端接口是有未完善信息的全局拦截的,在BaseMvpPresenter里会触发1415去完善用户信息。 @@ -261,6 +301,7 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey; return; } self.userInfo = userInfo; + [self getRoomGameInfo]; [AccountInfoStorage instance].name = self.userInfo.nick; if ((userInfo.nick == nil || userInfo.avatar == nil) && self.isFormLogin == NO) { @@ -726,7 +767,7 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey; } - (BaseNavigationController *)createTabBarItem:(UIViewController *)itemVc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage{ - itemVc.title = title; + itemVc.title = @"" ; itemVc.tabBarItem.image = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; itemVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; [itemVc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:UIColorFromRGB(0x1F1B4F)} forState:UIControlStateSelected]; @@ -760,7 +801,7 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey; if (model.total > 99) { badge = @"99+"; } - NSUInteger index = 1; + NSUInteger index = 2; UITabBarItem *item = self.tabBar.items.count > index ? self.tabBar.items[index] : nil; [item setBadgeValue:badge]; } @@ -773,7 +814,7 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey; unreadCount += obj.unreadCount; }]; if(unreadCount > 0){ - NSUInteger index = 2; + NSUInteger index = 3; UITabBarItem *item = self.tabBar.items.count > index ? self.tabBar.items[index] : nil; [item setBadgeValue:[NSString stringWithFormat:@"%ld",unreadCount]]; } diff --git a/YuMi/Modules/YMTabbar/View/XPTabBar.m b/YuMi/Modules/YMTabbar/View/XPTabBar.m index dd8499fb..266650cb 100644 --- a/YuMi/Modules/YMTabbar/View/XPTabBar.m +++ b/YuMi/Modules/YMTabbar/View/XPTabBar.m @@ -10,15 +10,14 @@ #import "YUMIMacroUitls.h" #import "DJDKMIMOMColor.h" -CGFloat tabBarHeight = 60.0; // TabBar高度 -CGFloat leftRightSpace = 8.0; // TabBar左右距离 + +CGFloat leftRightSpace = 20.0; // TabBar左右距离 CGFloat bottomSpace = 29.0; // TabBar离底部距离 -NSInteger itemCount = 4; // tabBarItem的数量 +NSInteger itemCount = 5; // tabBarItem的数量 @interface XPTabBar() -/// 背景 -@property (nonatomic, strong) UIView *bgView; + @end @@ -28,7 +27,7 @@ NSInteger itemCount = 4; // tabBarItem的数量 self = [super initWithFrame:frame]; if(self) { - [self addSubview:self.bgView]; + self.backgroundColor = [UIColor whiteColor]; // 去除顶部横线 [self setBackgroundImage:[UIImage new]]; [self setShadowImage:[UIImage new]]; @@ -57,7 +56,7 @@ NSInteger itemCount = 4; // tabBarItem的数量 - (void)layoutSubviews { [super layoutSubviews]; // 重设tabBar的位置 - self.frame = CGRectMake(0, KScreenHeight- tabBarHeight-bottomSpace, KScreenWidth, tabBarHeight); + self.frame = CGRectMake(0, KScreenHeight- kTabBarHeight, KScreenWidth, kTabBarHeight); // 设置其他tabbarbtn的frame CGFloat tabBarButtonW = (KScreenWidth-leftRightSpace*2)/itemCount; @@ -65,25 +64,13 @@ NSInteger itemCount = 4; // tabBarItem的数量 for (UIView *child in self.subviews) { Class class = NSClassFromString(@"UITabBarButton"); if ([child isKindOfClass:class]) { - CGRect frame = CGRectMake(tabBarButtonIndex * tabBarButtonW+leftRightSpace, (tabBarHeight-49)/2, tabBarButtonW, 49); + CGRect frame = CGRectMake(tabBarButtonIndex * tabBarButtonW+leftRightSpace, 17, 34, 34); child.frame = frame; tabBarButtonIndex ++; } } } -- (UIView *)bgView { - if (!_bgView) { - _bgView = [[UIView alloc] init]; - _bgView.backgroundColor = [[DJDKMIMOMColor tabbarViewColor] colorWithAlphaComponent:0.95]; - _bgView.frame = CGRectMake(leftRightSpace, 0, KScreenWidth-leftRightSpace*2, tabBarHeight); - _bgView.layer.cornerRadius = tabBarHeight/2.0; - _bgView.layer.shadowColor = [UIColor.blackColor colorWithAlphaComponent:0.5].CGColor; - _bgView.layer.shadowOffset = CGSizeMake(0, 0); - _bgView.layer.shadowOpacity = 0.2; - _bgView.layer.shadowRadius = 5; - } - return _bgView; -} + @end diff --git a/YuMi/Modules/YMWeb/XPWebViewController.h b/YuMi/Modules/YMWeb/XPWebViewController.h index 7e973917..d7683dfd 100644 --- a/YuMi/Modules/YMWeb/XPWebViewController.h +++ b/YuMi/Modules/YMWeb/XPWebViewController.h @@ -40,7 +40,7 @@ NS_ASSUME_NONNULL_BEGIN ///关闭webView 目前适用于半屏的情况下 @property (nonatomic,copy) void (^CloseWebViewBlock)(BOOL result); - (instancetype)initWithCustomizeNav:(BOOL)isCustom; - +- (instancetype)initWithGame; @end NS_ASSUME_NONNULL_END diff --git a/YuMi/zh-Hans.lproj/Localizable.strings b/YuMi/zh-Hans.lproj/Localizable.strings index 33453903..03510b2e 100644 --- a/YuMi/zh-Hans.lproj/Localizable.strings +++ b/YuMi/zh-Hans.lproj/Localizable.strings @@ -3269,13 +3269,17 @@ ///MSRoomGameVictoryView "MSRoomGameVictoryView0"="重新匹配"; ///MSRoomGameQuitGameView -"MSRoomGameQuitGameView0"="游戏已经开始,退出房间将默认 游戏失败,确认退出房间?"; +"MSRoomGameQuitGameView0"="游戏已经开始,退出房间将默认游戏失败,确认退出房间?"; "MSRoomGameQuitGameView1"="退出"; "MSRoomGameQuitGameView2"="继续游戏"; +"MSRoomGameQuitGameView3"="匹配失败,是否重新匹配?"; +"MSRoomGameQuitGameView4"="游戏进行中,是否返回房间?"; + //MSRoomGameHeadView "MSRoomGameHeadView0"="匹配中"; "MSRoomGameHeadView1"="匹配成功"; "MSRoomGameHeadView2"="获胜奖励%@金币"; - +"MSRoomGameHeadView3"="%@金币"; //MSRoomGameVC "MSRoomGameVC0"="匹配失败"; +"MSRoomGameVC1"="钱包"; diff --git a/YuMi/zh-Hant.lproj/Localizable.strings b/YuMi/zh-Hant.lproj/Localizable.strings index d1e3a300..e4d0a3bf 100644 --- a/YuMi/zh-Hant.lproj/Localizable.strings +++ b/YuMi/zh-Hant.lproj/Localizable.strings @@ -3258,3 +3258,22 @@ "MSRoomSetingBackdropCell0"="使用中"; "MSRoomSetingBackdropCell1"="確認選擇這張圖片作為房間主題嗎?"; +///MSTabbarBeginGameView +"MSTabbarBeginGameView0"="开始"; +///MSRoomGameVictoryView +"MSRoomGameVictoryView0"="重新匹配"; +///MSRoomGameQuitGameView +"MSRoomGameQuitGameView0"="游戏已经开始,退出房间将默认游戏失败,确认退出房间?"; +"MSRoomGameQuitGameView1"="退出"; +"MSRoomGameQuitGameView2"="继续游戏"; +"MSRoomGameQuitGameView3"="匹配失败,是否重新匹配?"; +"MSRoomGameQuitGameView4"="游戏进行中,是否返回房间?"; + +//MSRoomGameHeadView +"MSRoomGameHeadView0"="匹配中"; +"MSRoomGameHeadView1"="匹配成功"; +"MSRoomGameHeadView2"="获胜奖励%@金币"; +"MSRoomGameHeadView3"="%@金币"; +//MSRoomGameVC +"MSRoomGameVC0"="匹配失败"; +"MSRoomGameVC1"="钱包";