From bc1b1e6cf4b594fff9f10b2facedce7de3bb8320 Mon Sep 17 00:00:00 2001 From: doregon Date: Wed, 4 Aug 2021 15:15:36 -0400 Subject: [PATCH] Add java arguments to the preferences window, also minor linting --- Natives/LauncherPreferencesViewController.m | 42 +++++++++++++++------ Natives/LauncherViewController.m | 4 +- Natives/LoginViewController.m | 2 +- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/Natives/LauncherPreferencesViewController.m b/Natives/LauncherPreferencesViewController.m index d5cfa201..9715cc4b 100644 --- a/Natives/LauncherPreferencesViewController.m +++ b/Natives/LauncherPreferencesViewController.m @@ -13,16 +13,14 @@ @implementation LauncherPreferencesViewController +UITextField* jargsTextField; UITextField* versionTextField; - (void)viewDidLoad { [super viewDidLoad]; - [self setNeedsUpdateOfScreenEdgesDeferringSystemGestures]; - [self setNeedsUpdateOfHomeIndicatorAutoHidden]; - - [self setTitle:@"Launcher preferences"]; + [self setTitle:@"Preferences"]; CGRect screenBounds = [[UIScreen mainScreen] bounds]; CGFloat screenScale = [[UIScreen mainScreen] scale]; @@ -62,9 +60,37 @@ UITextField* versionTextField; buttonSizeSlider.value = ((NSNumber *) getPreference(@"button_scale")).floatValue; [scrollView addSubview:buttonSizeSlider]; + UILabel *jargsTextView = [[UILabel alloc] initWithFrame:CGRectMake(4.0, 54.0, 0.0, 0.0)]; + jargsTextView.text = @"Java arguments "; + jargsTextView.numberOfLines = 0; + [jargsTextView sizeToFit]; + [scrollView addSubview:jargsTextView]; + + jargsTextField = [[UITextField alloc] initWithFrame:CGRectMake(jargsTextView.bounds.size.width + 4.0, 54.0, width - jargsTextView.bounds.size.width - 8.0, height - 58.0)]; + [jargsTextField addTarget:versionTextField action:@selector(resignFirstResponder) forControlEvents:UIControlEventEditingDidEndOnExit]; + jargsTextField.tag = 100; + jargsTextField.delegate = self; + jargsTextField.placeholder = @"Specify arguments..."; + jargsTextField.text = (NSString *) getPreference(@"java_args"); + jargsTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentTop; + jargsTextField.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; + [scrollView addSubview:jargsTextField]; + scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, scrollView.frame.size.height + 200); } +- (void)textFieldDidEndEditing:(UITextField *)textField +{ + if (textField.tag == 100) { + setPreference(@"java_args", jargsTextField.text); + UIAlertController *fullAlert = [UIAlertController alertControllerWithTitle:@"Restart the launcher" message:@"Changing Java arguments requires a restart of the launcher to take effect."preferredStyle:UIAlertControllerStyleAlert]; + UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil]; + [self presentViewController:fullAlert animated:YES completion:nil]; + [fullAlert addAction:ok]; + } +} + + - (void)sliderMoved:(DBNumberedSlider *)sender { switch (sender.tag) { case 1: @@ -76,14 +102,6 @@ UITextField* versionTextField; } } -- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures { - return UIRectEdgeBottom; -} - -- (BOOL)prefersHomeIndicatorAutoHidden { - return NO; -} - -(void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection { if(@available(iOS 13.0, *)) { if (UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) { diff --git a/Natives/LauncherViewController.m b/Natives/LauncherViewController.m index 11c57ecd..95303d8d 100644 --- a/Natives/LauncherViewController.m +++ b/Natives/LauncherViewController.m @@ -81,7 +81,7 @@ int versionSelectedAt = 0; handler:^(__kindof UIAction * _Nonnull action) {[self enterModInstaller];}]; UIAction *option2 = [UIAction actionWithTitle:@"Custom controls" image:nil identifier:nil handler:^(__kindof UIAction * _Nonnull action) {[self enterCustomControls];}]; - UIAction *option3 = [UIAction actionWithTitle:@"Settings" image:nil identifier:nil + UIAction *option3 = [UIAction actionWithTitle:@"Preferences" image:nil identifier:nil handler:^(__kindof UIAction * _Nonnull action) {[self enterPreferences];}]; UIMenu *menu = [UIMenu menuWithTitle:@"Options" image:nil identifier:nil options:UIMenuOptionsDisplayInline children:@[option1, option2, option3]]; @@ -204,7 +204,7 @@ int versionSelectedAt = 0; handler:^(UIAlertAction * _Nonnull action) {[self enterModInstaller];}]; UIAlertAction *option2 = [UIAlertAction actionWithTitle:@"Custom controls" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self enterCustomControls];}]; - UIAlertAction *option3 = [UIAlertAction actionWithTitle:@"Settings" style:UIAlertActionStyleDefault + UIAlertAction *option3 = [UIAlertAction actionWithTitle:@"Preferences" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self enterPreferences];}]; fullAlert.popoverPresentationController.barButtonItem = sender; [self presentViewController:fullAlert animated:YES completion:nil]; diff --git a/Natives/LoginViewController.m b/Natives/LoginViewController.m index 24ab5c58..7e8c3254 100644 --- a/Natives/LoginViewController.m +++ b/Natives/LoginViewController.m @@ -137,7 +137,7 @@ void loginAccountInput(UINavigationController *controller, int type, const char* } - (void)accountType:(UIButton *)sender { - UIAlertController *fullAlert = [UIAlertController alertControllerWithTitle:@"Let's get you signed in." message:@"What account do you use to log into Minecraft?"preferredStyle:UIAlertControllerStyleActionSheet]; + UIAlertController *fullAlert = [UIAlertController alertControllerWithTitle:@"Let's get you signed in." message:@"What account do you use to log into Minecraft?"preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertAction *mojang = [UIAlertAction actionWithTitle:@"Mojang account" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self loginUsername:TYPE_MOJANG];}]; UIAlertAction *microsoft = [UIAlertAction actionWithTitle:@"Microsoft account" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self loginMicrosoft];}]; UIAlertAction *offline = [UIAlertAction actionWithTitle:@"Local account" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self loginOffline:sender];}];