268 lines
9.5 KiB
Objective-C
268 lines
9.5 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 "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 MSRoomMenuTypeGame:
|
|
[self getGameData];
|
|
break;
|
|
case MSRoomMenuTypeLittleGame:
|
|
[self getLittleGameList];
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
-(void)getGameData{
|
|
NSMutableArray *resourceList = [self.hostDelegate getPlayList];
|
|
if(resourceList.count > 0){
|
|
_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);
|
|
NSArray <ActivityInfoModel *>* array = [ActivityInfoModel modelsWithArray:data.data];
|
|
self.gameView.playList = [[NSMutableArray alloc]initWithArray:array];
|
|
}
|
|
} roomId:roomId];
|
|
}
|
|
|
|
- (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)ms_didSelectItemAtIndexPath:(ActivityInfoModel *)model {
|
|
self.gameView.hidden = YES;
|
|
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];
|
|
}
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
|
}
|
|
-(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
|