From 1e7bfe94ff902b42e91030c2a5462f89bb130477 Mon Sep 17 00:00:00 2001 From: Duy Tran Khanh Date: Tue, 9 Feb 2021 18:49:06 +0700 Subject: [PATCH] [WIP] Login UI --- Natives/CMakeLists.txt | 3 +- Natives/LoginViewController.h | 5 ++ Natives/LoginViewController.m | 100 +++++++++++++++++++++++++++++++--- Natives/aminimake.sh | 2 +- Natives/login_bridge.h | 3 + Natives/login_bridge.m | 3 + Natives/utils.h | 4 +- 7 files changed, 108 insertions(+), 12 deletions(-) create mode 100644 Natives/login_bridge.h create mode 100644 Natives/login_bridge.m diff --git a/Natives/CMakeLists.txt b/Natives/CMakeLists.txt index 27d967a9..51c8c87c 100644 --- a/Natives/CMakeLists.txt +++ b/Natives/CMakeLists.txt @@ -13,9 +13,10 @@ set_target_properties(PojavLauncher PROPERTIES MACOSX_FRAMEWORK_IDENTIFIER org.cmake.ExecutableTarget MACOSX_BUNDLE_INFO_PLIST "../Info.plist") -add_library(pojavexec SHARED log.m AppDelegate.m SceneDelegate.m UILauncher.m LauncherViewController.m LoginViewController.m SurfaceViewController.m egl_bridge_ios.m ios_uikit_bridge.m egl_bridge.c input_bridge_v3.c utils.c) +add_library(pojavexec SHARED log.m AppDelegate.m SceneDelegate.m UILauncher.m LauncherViewController.m LoginViewController.m SurfaceViewController.m egl_bridge_ios.m ios_uikit_bridge.m login_bridge.m egl_bridge.c input_bridge_v3.c utils.c) target_link_libraries(pojavexec "-Fresources/Frameworks" "-framework UIKit" "-framework MetalANGLE" + "-framework CoreGraphics" ) diff --git a/Natives/LoginViewController.h b/Natives/LoginViewController.h index baf6c5c5..dca5c0ab 100644 --- a/Natives/LoginViewController.h +++ b/Natives/LoginViewController.h @@ -3,3 +3,8 @@ @interface LoginViewController : UIViewController @end + +@interface LoginListViewController : UIViewController + +@end + diff --git a/Natives/LoginViewController.m b/Natives/LoginViewController.m index e764e2e0..335fd93e 100644 --- a/Natives/LoginViewController.m +++ b/Natives/LoginViewController.m @@ -6,8 +6,6 @@ @interface LoginViewController () { } -// - (void)method - @end @implementation LoginViewController @@ -17,7 +15,7 @@ [self setTitle:@"PojavLauncher"]; - UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil]; + UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil]; [self.navigationItem setBackBarButtonItem:backItem]; CGRect screenBounds = [[UIScreen mainScreen] bounds]; @@ -25,8 +23,9 @@ int width = (int) roundf(screenBounds.size.width); int height = (int) roundf(screenBounds.size.height) - self.navigationController.navigationBar.frame.size.height; - UIScrollView *scrollView = self.view = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, width, height)]; + UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame]; scrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; + [self.view addSubview:scrollView]; // Update color mode once if(@available(iOS 13.0, *)) { @@ -39,7 +38,7 @@ UIButton *button_login_mojang = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button_login_mojang setTitle:@"Mojang login" forState:UIControlStateNormal]; - button_login_mojang.frame = CGRectMake(widthSplit, (height - 50.0) / 2.0 - 4.0 - 50.0, width - widthSplit * 2.0, 50.0); + button_login_mojang.frame = CGRectMake(widthSplit, (height - 50.0) / 2.0 - 4.0 - 50.0, (width - widthSplit * 2.0) / 2 - 2.0, 50.0); button_login_mojang.backgroundColor = [UIColor colorWithRed:54/255.0 green:176/255.0 blue:48/255.0 alpha:1.0]; button_login_mojang.layer.cornerRadius = 5; [button_login_mojang setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; @@ -48,7 +47,7 @@ UIButton *button_login_microsoft = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button_login_microsoft setTitle:@"Microsoft login" forState:UIControlStateNormal]; - button_login_microsoft.frame = CGRectMake(widthSplit, (height - 50.0) / 2.0, width - widthSplit * 2.0, 50.0); + button_login_microsoft.frame = CGRectMake(widthSplit + (width - widthSplit * 2.0) / 2.0 + 2.0, (height - 50.0) / 2.0 - 4.0 - 50.0, (width - widthSplit * 2.0) / 2 - 2.0, 50.0); button_login_microsoft.backgroundColor = [UIColor colorWithRed:54/255.0 green:176/255.0 blue:48/255.0 alpha:1.0]; button_login_microsoft.layer.cornerRadius = 5; [button_login_microsoft setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; @@ -57,12 +56,21 @@ UIButton *button_login_offline = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button_login_offline setTitle:@"Offline login" forState:UIControlStateNormal]; - button_login_offline.frame = CGRectMake(widthSplit, (height - 50.0) / 2.0 + 4.0 + 50.0, width - widthSplit * 2.0, 50.0); + button_login_offline.frame = CGRectMake(widthSplit, (height - 50.0) / 2.0, width - widthSplit * 2.0, 50.0); button_login_offline.backgroundColor = [UIColor colorWithRed:54/255.0 green:176/255.0 blue:48/255.0 alpha:1.0]; button_login_offline.layer.cornerRadius = 5; [button_login_offline setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [button_login_offline addTarget:self action:@selector(loginOffline) forControlEvents:UIControlEventTouchUpInside]; [scrollView addSubview:button_login_offline]; + + UIButton *button_login_account = [UIButton buttonWithType:UIButtonTypeRoundedRect]; + [button_login_account setTitle:@"Select account" forState:UIControlStateNormal]; + button_login_account.frame = CGRectMake(widthSplit, (height - 50.0) / 2.0 + 4.0 + 50.0, width - widthSplit * 2.0, 50.0); + button_login_account.backgroundColor = [UIColor colorWithRed:54/255.0 green:176/255.0 blue:48/255.0 alpha:1.0]; + button_login_account.layer.cornerRadius = 5; + [button_login_account setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; + [button_login_account addTarget:self action:@selector(loginAccount) forControlEvents:UIControlEventTouchUpInside]; + [scrollView addSubview:button_login_account]; } -(void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection API_AVAILABLE(ios(13.0)) { @@ -85,9 +93,87 @@ [self enterLauncher]; } +- (void)loginAccount { +/* + UIViewController *controller = [[UIViewController alloc] init]; + UITableView *alertTableView; +alertTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 300, 300)]; + alertTableView.delegate = self; + alertTableView.dataSource = self; + alertTableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero]; + [alertTableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine]; + [controller.view addSubview:alertTableView]; + [controller.view bringSubviewToFront:alertTableView]; + [controller.view setUserInteractionEnabled:YES]; + [alertTableView setUserInteractionEnabled:YES]; + [alertTableView setAllowsSelection:YES]; +*/ + + LoginListViewController *controller = [[LoginListViewController alloc] init]; + [self presentViewController:controller animated:YES completion:nil]; +} + - (void)enterLauncher { LauncherViewController *vc = [[LauncherViewController alloc] init]; [self.navigationController pushViewController:vc animated:YES]; } @end + +@interface LoginListViewController () { +} + +@end + +@implementation LoginListViewController + +NSMutableArray *accountList; + +- (void)viewDidLoad { + [super viewDidLoad]; + + if (accountList == nil) { + accountList = [NSMutableArray array]; + } else { + [accountList removeAllObjects]; + } + + [accountList addObject:@"mojangacc1"]; + [accountList addObject:@"themsacc"]; + [accountList addObject:@"offlineme"]; + + CGRect screenBounds = [[UIScreen mainScreen] bounds]; + + int width = (int) roundf(screenBounds.size.width); + int height = (int) roundf(screenBounds.size.height) - self.navigationController.navigationBar.frame.size.height; + + self.view.frame = CGRectMake(width / 6, height / 6, width - width / 3, height); + + UITableView *tableView = [[UITableView alloc]initWithFrame:self.view.frame]; + tableView.delegate = self; + tableView.dataSource = self; + tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero]; + [tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine]; + [self.view addSubview:tableView]; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return [accountList count]; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + NSString *simpleTableIdentifier = @"SimpleTableCell"; + + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; + + if (cell == nil) { + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; + } + + cell.textLabel.text = [accountList objectAtIndex:indexPath.row]; + return cell; +} + +@end diff --git a/Natives/aminimake.sh b/Natives/aminimake.sh index 80ec7431..3ae1e2c6 100644 --- a/Natives/aminimake.sh +++ b/Natives/aminimake.sh @@ -5,7 +5,7 @@ set -e CFLAGS="-fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -Wno-trigraphs -fpascal-strings -O3 -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-return-type -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wno-float-conversion -Wno-non-literal-null-conversion -Wno-objc-literal-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof" -clang -Wl,-rpath,/Applications/PojavLauncher.app/Frameworks -fobjc-arc -x objective-c -Fresources/Frameworks -framework UIKit -framework MetalANGLE -Iresources/Frameworks/MetalANGLE.framework/Headers -dynamiclib -isysroot /var/mobile/theos/sdks/iPhoneOS13.4.sdk $CFLAGS -o libpojavexec.dylib log.m AppDelegate.m SceneDelegate.m UILauncher.m LauncherViewController.m LoginViewController.m SurfaceViewController.m egl_bridge_ios.m ios_uikit_bridge.m egl_bridge.c input_bridge_v3.c utils.c -DGLES_TESTZ -DUSE_EGLZ +clang -Wl,-rpath,/Applications/PojavLauncher.app/Frameworks -fobjc-arc -x objective-c -Fresources/Frameworks -framework UIKit -framework MetalANGLE -framework CoreGraphics -Iresources/Frameworks/MetalANGLE.framework/Headers -dynamiclib -isysroot /var/mobile/theos/sdks/iPhoneOS13.4.sdk $CFLAGS -o libpojavexec.dylib log.m AppDelegate.m SceneDelegate.m UILauncher.m LauncherViewController.m LoginViewController.m SurfaceViewController.m egl_bridge_ios.m ios_uikit_bridge.m login_bridge.m egl_bridge.c input_bridge_v3.c utils.c -DGLES_TESTZ -DUSE_EGLZ ldid -S../entitlements.xml libpojavexec.dylib diff --git a/Natives/login_bridge.h b/Natives/login_bridge.h new file mode 100644 index 00000000..45dcbb04 --- /dev/null +++ b/Natives/login_bridge.h @@ -0,0 +1,3 @@ +#pragma once + + diff --git a/Natives/login_bridge.m b/Natives/login_bridge.m new file mode 100644 index 00000000..a056a376 --- /dev/null +++ b/Natives/login_bridge.m @@ -0,0 +1,3 @@ +#include "login_bridge.h" + + diff --git a/Natives/utils.h b/Natives/utils.h index f4880389..c2836781 100644 --- a/Natives/utils.h +++ b/Natives/utils.h @@ -1,5 +1,4 @@ -#ifndef _BINARY_UTILS_H_ -#define _BINARY_UTILS_H_ +#pragma once #include #include "jni.h" @@ -60,5 +59,4 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendScreenSize(J JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendScroll(JNIEnv* env, jclass clazz, jdouble xoffset, jdouble yoffset); JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendWindowPos(JNIEnv* env, jclass clazz, jint x, jint y); -#endif // _BINARY_UTILS_H_