356 lines
14 KiB
Objective-C
356 lines
14 KiB
Objective-C
//
|
|
// MSRoomMenuGameVC.m
|
|
// YuMi
|
|
//
|
|
// Created by duoban on 2024/4/29.
|
|
//
|
|
#import "Api+Room.h"
|
|
#import "MSRoomMenuGameVC.h"
|
|
#import "MSRoomMenuGameView.h"
|
|
#import "XPTreasureFairyViewController.h"
|
|
#import "XPRoomHalfWebView.h"
|
|
#import "XPWebViewController.h"
|
|
#import "XPCandyTreeViewController.h"
|
|
#import "XPSailingViewController.h"
|
|
#import "XPRoomViewController.h"
|
|
#import "MSRoomGameWebVC.h"
|
|
#import "XPRoomAnimationView.h"
|
|
#import "XPRoomMoreItemModel.h"
|
|
#import "GuildSuperAdminInfoModel.h"
|
|
#import "XPRoomPKViewController.h"
|
|
#import "XPAcrossRoomPKViewController.h"
|
|
|
|
#import <NIMSDK/NIMSDK.h>
|
|
#import "Api+LittleGame.h"
|
|
#import "Api+RoomSetting.h"
|
|
|
|
@interface MSRoomMenuGameVC ()<MSRoomMenuGameViewDelegate>
|
|
@property(nonatomic,strong) MSRoomMenuGameView *gameView;
|
|
@property(nonatomic, assign) MSRoomMenuType type;
|
|
///host 代理
|
|
@property (nonatomic,weak) id<RoomHostDelegate>hostDelegate;
|
|
@end
|
|
|
|
@implementation MSRoomMenuGameVC
|
|
-(void)dealloc{
|
|
|
|
}
|
|
|
|
- (instancetype)initWithDelegate:(id<RoomHostDelegate>)delegate{
|
|
self = [super init];
|
|
if(self){
|
|
self.hostDelegate = delegate;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (instancetype)initWithDelegate:(id<RoomHostDelegate>)delegate
|
|
roomMenuType:(MSRoomMenuType)type {
|
|
self = [super init];
|
|
if(self){
|
|
self.type = type;
|
|
self.hostDelegate = delegate;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (BOOL)isHiddenNavBar {
|
|
return YES;
|
|
}
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self installUI];
|
|
[self installConstraints];
|
|
[self loadMenuData];
|
|
}
|
|
|
|
- (void)loadMenuData {
|
|
switch (self.type) {
|
|
case MSRoomMenuTypePK:
|
|
[self updateGamePlayList:@[]];
|
|
break;
|
|
case MSRoomMenuTypeGame:
|
|
[self getGameData];
|
|
break;
|
|
case MSRoomMenuTypeLittleGame:
|
|
[self getLittleGameList];
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
-(void)getGameData{
|
|
NSMutableArray *resourceList = [self.hostDelegate getPlayList];
|
|
if(resourceList.count > 0){
|
|
self.gameView.playList = resourceList;
|
|
return;
|
|
}
|
|
|
|
NSString * roomId = [NSString stringWithFormat:@"%ld", self.hostDelegate.getRoomInfo.roomId];
|
|
@kWeakify(self);
|
|
[Api getPlayList:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
|
if (code == 200) {
|
|
@kStrongify(self);
|
|
self.gameView.playList = [[ActivityInfoModel modelsWithArray:data.data] mutableCopy];
|
|
}
|
|
} roomId:roomId];
|
|
}
|
|
|
|
- (void)updateGamePlayList:(NSArray *)array {
|
|
RoomInfoModel *roomInfo = self.hostDelegate.getRoomInfo;
|
|
NSMutableArray *tempArray = [[NSMutableArray alloc] initWithArray:@[
|
|
[self createRoomPKModel:roomInfo],
|
|
[self createCrossRoomPKModel:roomInfo]
|
|
]];
|
|
self.gameView.playList = tempArray;
|
|
}
|
|
|
|
- (XPRoomMoreItemModel *)createRoomPKModel:(RoomInfoModel *)roomInfo {
|
|
XPRoomMoreItemModel * roomPK = [[XPRoomMoreItemModel alloc] init];
|
|
roomPK.imageName= @"room_pk_menu_icon";
|
|
roomPK.type = (roomInfo.roomModeType == RoomModeType_Open_PK_Mode) ?
|
|
RoomMoreMenuType_Room_PK_Close :
|
|
RoomMoreMenuType_Room_PK_Open;
|
|
return roomPK;
|
|
}
|
|
|
|
- (XPRoomMoreItemModel *)createCrossRoomPKModel:(RoomInfoModel *)roomInfo {
|
|
XPRoomMoreItemModel * acrossRoomPK = [[XPRoomMoreItemModel alloc] init];
|
|
acrossRoomPK.imageName = @"crossroom_pk_menu_icon";
|
|
acrossRoomPK.type = (roomInfo.roomModeType == RoomModeType_Open_AcrossRoomPK_mode) ?
|
|
RoomMoreMenuType_Room_Across_PK_Close :
|
|
RoomMoreMenuType_Room_Across_PK_Open;
|
|
return acrossRoomPK;
|
|
}
|
|
|
|
- (void)getLittleGameList {
|
|
NSMutableArray *resourceList = [self.hostDelegate getLittleGameList];
|
|
if(resourceList.count > 0){
|
|
_gameView.littleGameList = resourceList;
|
|
return;
|
|
}
|
|
|
|
@kWeakify(self);
|
|
[Api getLittleGameList:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
|
if (code == 200) {
|
|
@kStrongify(self);
|
|
NSArray * array = [LittleGameInfoModel modelsWithArray:data.data];
|
|
self.gameView.littleGameList = array.mutableCopy;
|
|
}
|
|
}
|
|
roomUid:@""];
|
|
}
|
|
|
|
-(void)installUI{
|
|
self.view.backgroundColor = [UIColor clearColor];
|
|
[self.view addSubview:self.gameView];
|
|
}
|
|
-(void)installConstraints{
|
|
[self.gameView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.equalTo(self.view);
|
|
}];
|
|
}
|
|
|
|
#pragma mark- MSRoomMenuGameViewDelegate
|
|
- (void)didClickBackBtnAction{
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
|
}
|
|
|
|
-(void)ms_didSelectLittleGameItemAtIndexPath:(LittleGameInfoModel *)model {
|
|
if (self.hostDelegate.isManagerOrOwner) {
|
|
@kWeakify(self);
|
|
[TTPopup alertWithMessage:YMLocalizedString(@"MSRoomMenuGameVC0") confirmHandler:^{
|
|
@kStrongify(self);
|
|
[self startLittleGameWith:model];
|
|
} cancelHandler:^{}];
|
|
} else {
|
|
[XNDJTDDLoadingTool showErrorWithMessage:YMLocalizedString(@"MSRoomMenuGameVC1")];
|
|
}
|
|
}
|
|
|
|
- (void)startLittleGameWith:(LittleGameInfoModel *)model {
|
|
RoomInfoModel * roomInfo = self.hostDelegate.getRoomInfo;
|
|
NSMutableDictionary * params = [NSMutableDictionary dictionary];
|
|
NSString * ticket = [AccountInfoStorage instance].getTicket;
|
|
[params setObject:ticket forKey:@"ticket"];
|
|
[params setObject:@(roomInfo.uid).stringValue forKey:@"uid"];
|
|
[params setObject:[NSString stringWithFormat:@"%ld", roomInfo.uid] forKey:@"roomUid"];
|
|
if (roomInfo.title.length > 0) {
|
|
[params setObject:roomInfo.title forKey:@"title"];
|
|
}
|
|
|
|
if (roomInfo.roomPwd.length > 0) {
|
|
[params setObject:roomInfo.roomPwd forKey:@"roomPwd"];
|
|
} else{
|
|
[params setObject:@"" forKey:@"roomPwd"];
|
|
}
|
|
|
|
if (roomInfo.tagId > 0) {
|
|
[params setObject:[NSString stringWithFormat:@"%ld", roomInfo.tagId] forKey:@"tagId"];
|
|
}
|
|
if ([model.mgId isEqualToString:@"0"]) {
|
|
[params setObject:@(RoomType_Game) forKey:@"type"];
|
|
[params setObject:@"0" forKey:@"mgId"];
|
|
} else {
|
|
[params setObject:@(RoomType_MiniGame) forKey:@"type"];
|
|
[params setObject:model.mgId forKey:@"mgId"];
|
|
}
|
|
[params setObject:@(roomInfo.hasAnimationEffect) forKey:@"hasAnimationEffect"];
|
|
|
|
@kWeakify(self);
|
|
[Api ownerUpdateRoomInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
|
@kStrongify(self);
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
|
if (code == 200) {
|
|
|
|
} else {
|
|
[XNDJTDDLoadingTool showErrorWithMessage:msg];
|
|
}
|
|
} params:params];
|
|
}
|
|
|
|
- (void)handleMoreItem:(XPRoomMoreItemModel *)model {
|
|
RoomInfoModel *roomInfo = self.hostDelegate.getRoomInfo;
|
|
switch (model.type) {
|
|
case RoomMoreMenuType_Room_PK_Close: {
|
|
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventroom_more_tool_click
|
|
eventAttributes:@{@"roomMoreMenuType" : @"closeRoomPk"}];
|
|
XPRoomPKViewController * roomPKVC = [[XPRoomPKViewController alloc] initWithDelegate:self.hostDelegate];
|
|
[self.hostDelegate.getCurrentNav pushViewController:roomPKVC animated:YES];
|
|
}
|
|
break;
|
|
case RoomMoreMenuType_Room_PK_Open: {
|
|
if (roomInfo.roomModeType == RoomModeType_Open_Blind) {
|
|
[self showErrorToast:YMLocalizedString(@"XPRoomMoreMenuViewController20")];
|
|
} else if (roomInfo.roomModeType == RoomModeType_Open_AcrossRoomPK_mode) {
|
|
[self showErrorToast:YMLocalizedString(@"XPRoomMoreMenuViewController21")];
|
|
} else {
|
|
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventroom_more_tool_click
|
|
eventAttributes:@{@"roomMoreMenuType" : @"openRoomPk"}];
|
|
XPRoomPKViewController * roomPKVC = [[XPRoomPKViewController alloc] initWithDelegate:self.hostDelegate];
|
|
[self.hostDelegate.getCurrentNav pushViewController:roomPKVC animated:YES];
|
|
}
|
|
}
|
|
break;
|
|
case RoomMoreMenuType_Room_Across_PK_Close: {
|
|
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventroom_more_tool_click eventAttributes:@{@"roomMoreMenuType" : @"closeAcrossPk"}];
|
|
[self showErrorToast:YMLocalizedString(@"XPRoomMoreMenuViewController15")];
|
|
}
|
|
break;
|
|
case RoomMoreMenuType_Room_Across_PK_Open:{
|
|
if (roomInfo.roomModeType == RoomModeType_Open_Blind) {
|
|
[self showErrorToast:YMLocalizedString(@"XPRoomMoreMenuViewController13")];
|
|
} else if (roomInfo.roomModeType == RoomModeType_Open_PK_Mode) {
|
|
[self showErrorToast:YMLocalizedString(@"XPRoomMoreMenuViewController14")];
|
|
} else {
|
|
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventroom_more_tool_click eventAttributes:@{@"roomMoreMenuType" : @"openAcrossPk"}];
|
|
XPAcrossRoomPKViewController *acrossRoomPKVC = [[XPAcrossRoomPKViewController alloc] initWithRoomUid:[NSString stringWithFormat:@"%ld", roomInfo.uid]];
|
|
[self.hostDelegate.getCurrentNav presentViewController:acrossRoomPKVC animated:YES completion:nil];
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
- (void)handleActivityInfo:(ActivityInfoModel *)model {
|
|
if ([model.code isEqualToString:@"FIND_LOVE"]) {
|
|
[self lookLoveTapRecognizer];
|
|
} else if([model.code isEqualToString:@"NAUTICAL_ADVENTURE"]) {
|
|
[self sailTapRecognizer];
|
|
}else if([model.code isEqualToString:@"BAISHUN"]){
|
|
[self clickGameVC:model];
|
|
}else if([model.code isEqualToString:@"SEIZE_TREASURE"]){
|
|
if ([self.hostDelegate isKindOfClass:[XPRoomViewController class]]){
|
|
XPRoomViewController *vc = (XPRoomViewController *)self.hostDelegate;
|
|
XPTreasureFairyViewController * fairyVC = [[XPTreasureFairyViewController alloc] initWithdelegate:self.hostDelegate];
|
|
fairyVC.roomUid =[NSString stringWithFormat:@"%ld", self.hostDelegate.getRoomInfo.uid];
|
|
fairyVC.view.frame = CGRectMake(0, KScreenHeight, KScreenWidth, KScreenHeight);
|
|
[vc addChildViewController:fairyVC];
|
|
[fairyVC.navigationController setNavigationBarHidden:YES animated:NO];
|
|
[vc.view addSubview:fairyVC.view];
|
|
[UIView animateWithDuration:0.2 animations:^{
|
|
fairyVC.view.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
|
|
}completion:^(BOOL finished) {
|
|
|
|
}];
|
|
}
|
|
} else if(model.skipType == ActivitySkipType_Web) {
|
|
if(model.showType == ActivityShowType_Half){
|
|
XPRoomHalfWebView * webView = [[XPRoomHalfWebView alloc] init];
|
|
webView.isPlayView = YES;
|
|
webView.roomUid = [NSString stringWithFormat:@"%ld", self.hostDelegate.getRoomInfo.uid];
|
|
webView.url = model.skipContent;
|
|
[TTPopup popupView:webView style:TTPopupStyleActionSheet];
|
|
return;
|
|
}
|
|
|
|
XPWebViewController * webVC = [[XPWebViewController alloc] init];
|
|
webVC.roomUid = [NSString stringWithFormat:@"%ld", self.hostDelegate.getRoomInfo.uid];
|
|
webVC.url = model.skipContent;
|
|
[self.hostDelegate.getCurrentNav pushViewController:webVC animated:YES];
|
|
}
|
|
}
|
|
|
|
-(void)ms_didSelectItemAtIndexPath:(id)model {
|
|
self.gameView.hidden = YES;
|
|
[self dismissViewControllerAnimated:YES completion:^{
|
|
if ([model isKindOfClass:[XPRoomMoreItemModel class]]) {
|
|
[self handleMoreItem:(XPRoomMoreItemModel *)model];
|
|
} else if ([model isKindOfClass:[ActivityInfoModel class]]) {
|
|
[self handleActivityInfo:(ActivityInfoModel *)model];
|
|
}
|
|
}];
|
|
}
|
|
-(void)clickGameVC:(ActivityInfoModel *)model{
|
|
if ([self.hostDelegate isKindOfClass:[XPRoomViewController class]]){
|
|
MSRoomGameWebVC *vc = [[MSRoomGameWebVC alloc]initWithDelegate:self.hostDelegate gameModel:model];
|
|
vc.view.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
|
|
XPRoomViewController *roomVC = (XPRoomViewController *)self.hostDelegate;
|
|
[roomVC addChildViewController:vc];
|
|
XPRoomAnimationView *animationView;
|
|
for (id obj in self.hostDelegate.getSuperView.subviews) {
|
|
if ([obj isKindOfClass:[XPRoomAnimationView class]]){
|
|
animationView = obj;
|
|
break;
|
|
}
|
|
}
|
|
[self.hostDelegate.getSuperView addSubview:vc.view];
|
|
[self.hostDelegate.getSuperView bringSubviewToFront:animationView];
|
|
}
|
|
}
|
|
|
|
- (void)lookLoveTapRecognizer {
|
|
if ([self.hostDelegate isKindOfClass:[XPRoomViewController class]]){
|
|
XPCandyTreeViewController * candyTreeVC = [[XPCandyTreeViewController alloc] initWithDelegate:self.hostDelegate];
|
|
candyTreeVC.view.frame = CGRectMake(0, KScreenHeight, KScreenWidth, KScreenHeight);
|
|
[self.hostDelegate.getSuperView addSubview:candyTreeVC.view];
|
|
XPRoomViewController *vc = (XPRoomViewController *)self.hostDelegate;
|
|
[vc addChildViewController:candyTreeVC];
|
|
[candyTreeVC.navigationController setNavigationBarHidden:YES animated:NO];
|
|
[UIView animateWithDuration:0.1 animations:^{
|
|
candyTreeVC.view.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
|
|
}completion:^(BOOL finished) {
|
|
|
|
}];
|
|
}
|
|
}
|
|
|
|
- (void)sailTapRecognizer {
|
|
NSString * roomUid = [NSString stringWithFormat:@"%ld", self.hostDelegate.getRoomInfo.uid];
|
|
XPSailingViewController * sailingVC = [[XPSailingViewController alloc] initWithRoomUid:roomUid];
|
|
[self.hostDelegate.getCurrentNav presentViewController:sailingVC animated:YES completion:nil];
|
|
}
|
|
|
|
#pragma mark - 懒加载
|
|
- (MSRoomMenuGameView *)gameView{
|
|
if(!_gameView){
|
|
_gameView = [[MSRoomMenuGameView alloc]initWithFrame:CGRectZero];
|
|
_gameView.delegate = self;
|
|
}
|
|
return _gameView;
|
|
}
|
|
@end
|