新增游戏

This commit is contained in:
liyuhua
2024-04-30 19:30:11 +08:00
parent adabc08d07
commit 3be0f8bc74
46 changed files with 761 additions and 83 deletions

View File

@@ -6,6 +6,10 @@
//
#import "MSRoomGameWebVC.h"
#import "LittleGameInfoModel.h"
#import "RoomInfoModel.h"
#import "XPIAPRechargeViewController.h"
@interface MSWeakWebViewScriptMessageDelegate : NSObject<WKScriptMessageHandler>
//WKScriptMessageHandler JavaScriptOC
@@ -46,11 +50,24 @@ NSString * const kMSGameLoaded = @"gameLoaded";
@property (strong, nonatomic) WKWebView *webview;
@property (strong, nonatomic) UIProgressView *progressView;
@property (nonatomic, strong) WKUserContentController *ms_userContentController;
@property (nonatomic,weak) id<RoomHostDelegate> hostDelegate;
@property(nonatomic,strong) ActivityInfoModel *gameModel;
@end
@implementation MSRoomGameWebVC
- (instancetype)initWithDelegate:(id<RoomHostDelegate>)delegate gameModel:(ActivityInfoModel *)gameModel
{
self = [super init];
if (self) {
self.hostDelegate = delegate;
self.gameModel = gameModel;
}
return self;
}
- (BOOL)isHiddenNavBar {
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self installUI];
@@ -80,11 +97,7 @@ NSString * const kMSGameLoaded = @"gameLoaded";
//
int ScreenHeight = [[UIScreen mainScreen] bounds].size.height;
int ScreenWidth = [[UIScreen mainScreen] bounds].size.width;
//
CGRect statusBarRect = [[UIApplication sharedApplication]
statusBarFrame];
int statusBarHeight = statusBarRect.size.height;
self.webview = [[WKWebView alloc] initWithFrame:CGRectMake(0,0,
ScreenWidth, ScreenHeight) configuration:config];
[self.webview.scrollView setBackgroundColor:[UIColor clearColor]];
@@ -98,6 +111,11 @@ NSString * const kMSGameLoaded = @"gameLoaded";
UIScrollViewContentInsetAdjustmentNever;
}
[self.view addSubview:self.webview];
NSString *h5Url = self.gameModel.skipContent;
NSURL *url = [NSURL URLWithString:h5Url];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
[self.webview loadRequest:request];
}
- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler{
@@ -106,8 +124,6 @@ NSString * const kMSGameLoaded = @"gameLoaded";
NSURLCredential *card = [[NSURLCredential alloc]initWithTrust:challenge.protectionSpace.serverTrust];
completionHandler(NSURLSessionAuthChallengeUseCredential,card);
});
}
}
@@ -171,32 +187,58 @@ NSString * const kMSGameLoaded = @"gameLoaded";
//
- (void) getConfig:(NSDictionary*)args
{
NSLog(@"BSGAME %s","游戏调⽤getConfig");
NSString* method = [args objectForKey:@"jsCallback"];
RoomInfoModel *roomInfo = self.hostDelegate.getRoomInfo;
ActivityInfoItemModel *gameModel = self.gameModel.gameModel;
NSString *appChannel = gameModel.appChannel ?: @"";
int64_t appId = gameModel.appId;
NSString *userId = [AccountInfoStorage instance].getUid;
NSString *code = gameModel.code ?: @"";
NSString *roomId = [NSString stringWithFormat:@"%ld",roomInfo.uid];
NSString *gameMode = gameModel.gameMode ?: @"";
NSString *language = gameModel.language ?: @"";
NSDictionary *gameConfig = gameModel.gameConfig ?: @{};
int gsp = gameModel.gsp;
// APP
NSObject* configData = @{
@"appChannel":@"mesh",
@"appId":@88888888,
@"userId":@"534206265",
@"code":@"j10NQCb16b6E1oCnAx4o3hHdEaDzm6RLZjyyyEcn34tiJcPXNbkZh5g8Q6Zd",
@"roomId":@"20230901",
@"gameMode":@"3",
@"language":@"2",
@"gameConfig":@{
@"sceneMode":@0,
@"currencyIcon":@"https://bsyx-store.s3.ap-southeast-.amazonaws.com/game-icons/20230906-163004.png",
},
@"gsp":@101,
@"appChannel":appChannel,
@"appId":@(appId),
@"userId":userId,
@"code":code,
@"roomId":roomId,
@"gameMode":gameMode,
@"language":[self getlanguage],
@"gameConfig":gameConfig,
@"gsp":@(gsp),
};
[self callJs:method withJavaScriptValue:configData];
}
-(NSString *)getlanguage{
NSString *language = [NSBundle getLanguageText];
if ([language hasPrefix:@"zh"]) {
if ([language rangeOfString:@"Hans"].location != NSNotFound) {
language = @"0"; //
} else {
language = @"1"; //
}
}else if([language hasPrefix:@"ar"]){///
language = @"7";
}else{///
language = @"2";
}
return language;
}
//
- (void) destroy:(NSDictionary*)args
{
NSLog(@"BSGAME %s","游戏调⽤destroy");
// TODO
[self willMoveToParentViewController:nil]; //1
[self.view removeFromSuperview]; //2
[self removeFromParentViewController]; //3
}
//
@@ -204,6 +246,16 @@ NSString * const kMSGameLoaded = @"gameLoaded";
{
NSLog(@"BSGAME %s","游戏调⽤gameRecharge");
// TODO
TTAlertConfig *config = [[TTAlertConfig alloc]init];
config.message = YMLocalizedString(@"XPNobleCenterViewController3");
config.actionStyle = TTAlertActionBothStyle;
[TTPopup alertWithConfig:config showBorder:NO confirmHandler:^{
XPIAPRechargeViewController * webVC =[[XPIAPRechargeViewController alloc] init];
webVC.type = @"4";
[self.navigationController pushViewController:webVC animated:YES];
} cancelHandler:^{
}];
}
//