diff --git a/Natives/CMakeLists.txt b/Natives/CMakeLists.txt index 9b0324db..dcfcc676 100644 --- a/Natives/CMakeLists.txt +++ b/Natives/CMakeLists.txt @@ -131,6 +131,7 @@ add_executable(PojavLauncher LauncherPrefGameDirViewController.m LauncherSplitViewController.m MinecraftResourceUtils.m + PickTextField.m SceneDelegate.m SceneExternalDelegate.m SurfaceViewController.m diff --git a/Natives/JavaLauncher.m b/Natives/JavaLauncher.m index 75a067e2..e47f87c9 100644 --- a/Natives/JavaLauncher.m +++ b/Natives/JavaLauncher.m @@ -11,8 +11,6 @@ #include "utils.h" -#import - #import "ios_uikit_bridge.h" #import "JavaLauncher.h" #import "LauncherPreferences.h" @@ -277,23 +275,6 @@ int launchJVM(NSString *username, id launchTarget, int width, int height, int mi margv[++margc] = [launchTarget UTF8String]; } margv[++margc] = [NSString stringWithFormat:@"%dx%d", width, height].UTF8String; - - NSError *sessionError = nil; - AVAudioSessionCategory category; - AVAudioSessionCategoryOptions options; - if([getPreference(@"silence_with_switch") boolValue]) { - category = AVAudioSessionCategorySoloAmbient; - } else { - category = AVAudioSessionCategoryPlayback; - } - if([getPreference(@"silence_other_audio") boolValue]) { - options = 0; - } else { - options = AVAudioSessionCategoryOptionMixWithOthers; - } - [[AVAudioSession sharedInstance] setCategory:category withOptions:options error:&sessionError]; - [[AVAudioSession sharedInstance] setActive:YES error:&sessionError]; - pJLI_Launch = (JLI_Launch_func *)dlsym(libjli, "JLI_Launch"); diff --git a/Natives/LauncherNavigationController.m b/Natives/LauncherNavigationController.m index c13576d9..d46681af 100644 --- a/Natives/LauncherNavigationController.m +++ b/Natives/LauncherNavigationController.m @@ -6,6 +6,7 @@ #import "LauncherNavigationController.h" #import "LauncherPreferences.h" #import "MinecraftResourceUtils.h" +#import "PickTextField.h" #import "ios_uikit_bridge.h" #import "UIKit+hook.h" @@ -38,7 +39,7 @@ [self setNeedsUpdateOfScreenEdgesDeferringSystemGestures]; } - self.versionTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 4, self.toolbar.frame.size.width * 0.8, self.toolbar.frame.size.height - 8)]; + self.versionTextField = [[PickTextField alloc] initWithFrame:CGRectMake(0, 4, self.toolbar.frame.size.width * 0.8, self.toolbar.frame.size.height - 8)]; [self.versionTextField addTarget:self.versionTextField action:@selector(resignFirstResponder) forControlEvents:UIControlEventEditingDidEndOnExit]; self.versionTextField.autoresizingMask = AUTORESIZE_MASKS; self.versionTextField.placeholder = @"Specify version..."; diff --git a/Natives/LauncherPrefContCfgViewController.m b/Natives/LauncherPrefContCfgViewController.m index 526dab10..d6f7af46 100644 --- a/Natives/LauncherPrefContCfgViewController.m +++ b/Natives/LauncherPrefContCfgViewController.m @@ -7,6 +7,7 @@ #import "LauncherNavigationController.h" #import "LauncherPreferences.h" #import "LauncherPrefContCfgViewController.h" +#import "PickTextField.h" #import "TOInsetGroupedTableView.h" #import "ios_uikit_bridge.h" #import "utils.h" @@ -19,14 +20,14 @@ typedef void(^CreateView)(UITableViewCell *, NSString *, NSDictionary *); @interface LauncherPrefContCfgViewController () @property(nonatomic) NSString *currentFileName; -@property(nonatomic) NSMutableDictionary *allMappings; +@property(nonatomic) NSMutableDictionary *currentMappings; @property(nonatomic) NSDictionary *keycodePlist; +@property(nonatomic) UIPickerView *editPickMapping; +@property(nonatomic) UIToolbar *editPickToolbar; @property(nonatomic) UITextField *activeTextField; @property(nonatomic) NSArray* prefSections; @property(nonatomic) NSMutableArray* prefSectionsVisibility; -@property(nonatomic) NSArray*>* prefContents; -@property(nonatomic) NSArray* prefMappings, *prefMappingsTrimmed; -@property(nonatomic) NSArray* prefConfigFiles, *prefControllerTypes; +@property(nonatomic) NSArray *prefControllerTypes; @property(nonatomic) NSMutableArray *keyCodeMap, *keyValueMap; @end @@ -48,81 +49,31 @@ typedef void(^CreateView)(UITableViewCell *, NSString *, NSDictionary *); self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive; self.tableView.sectionFooterHeight = 50; - self.prefMappings = [self loadGamepadConfigurationFile:YES shouldSkipImmutables:NO]; - self.prefMappingsTrimmed = [self loadGamepadConfigurationFile:NO shouldSkipImmutables:YES]; - self.prefConfigFiles = [self loadGamepadControlFolder]; - self.prefControllerTypes = [self loadControllerTypeOptions]; + [self loadGamepadConfigurationFile]; + self.prefControllerTypes = @[@{@"name": @"xbox"}, @{@"name": @"playstation"}]; self.prefSections = @[@"config_files", @"game_mappings", @"menu_mappings", @"controller_style"]; - self.prefContents = @[self.prefConfigFiles, self.prefMappingsTrimmed[0], self.prefMappingsTrimmed[1], self.prefControllerTypes]; self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:localize(@"Save", nil) style:UIBarButtonItemStyleDone target:self action:@selector(actionMenuSave)]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:localize(@"Exit", nil) style:UIBarButtonItemStyleDone target:self action:@selector(exitButtonSelector)]; + self.editPickMapping = [[UIPickerView alloc] init]; + self.editPickMapping.delegate = self; + self.editPickMapping.dataSource = self; + self.editPickToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, 44.0)]; + UIBarButtonItem *btnFlexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; + UIBarButtonItem *editDoneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(closeTextField:)]; + self.editPickToolbar.items = @[btnFlexibleSpace, editDoneButton]; } -- (NSArray*>*) loadGamepadConfigurationFile:(BOOL)isUpdated shouldSkipImmutables:(BOOL)isSkipped { - if(isUpdated) { - NSString *gamepadPath = [NSString stringWithFormat:@"%s/controlmap/gamepads/%@", getenv("POJAV_HOME"), getPreference(@"default_gamepad_ctrl")]; - self.allMappings = parseJSONFromFile(gamepadPath); - } - +- (void)loadGamepadConfigurationFile { + NSString *gamepadPath = [NSString stringWithFormat:@"%s/controlmap/gamepads/%@", getenv("POJAV_HOME"), getPreference(@"default_gamepad_ctrl")]; + self.currentMappings = parseJSONFromFile(gamepadPath); self.currentFileName = [getPreference(@"default_ctrl") stringByDeletingPathExtension]; - - NSMutableArray* tempGameMap = [[NSMutableArray alloc] init]; - NSMutableArray* tempMenuMap = [[NSMutableArray alloc] init]; - - __block NSArray *immutables = @[@"mouse_primary", @"mouse_middle", @"mouse_secondary"]; - __block NSArray *maps = @[@"mGameMappingList", @"mMenuMappingList"]; - - for(NSString *mapName in maps) { - for(NSDictionary* mapping in self.allMappings[mapName]) { - __block BOOL isImmutable = NO; - __block int isThird = 0; - for(NSString* name in immutables) { - if([name isEqualToString:mapping[@"name"]]) { if(isSkipped) { isImmutable = YES; } } - if(isThird == 2 && !isImmutable) { - if([mapName isEqualToString:maps[0]]) { - [tempGameMap addObject:mapping]; - } else if([mapName isEqualToString:maps[1]]) { - [tempMenuMap addObject:mapping]; - } - } - isThird++; - } - } - } - - return @[[tempGameMap copy], [tempMenuMap copy]]; -} - -- (NSArray*) loadGamepadControlFolder { - NSArray* gamepadCtrl = @[getPreference(@"default_gamepad_ctrl")]; - NSMutableArray* finalArray = [[NSMutableArray alloc] init]; - NSMutableDictionary *holder = [[NSMutableDictionary alloc] init]; - holder[@"name"] = gamepadCtrl; - [finalArray addObject:holder]; - - return [finalArray copy]; -} - - -- (NSArray*) loadControllerTypeOptions { - NSArray* types = @[@"xbox", @"playstation"]; - NSMutableArray* finalArray = [[NSMutableArray alloc] init]; - for(NSString *type in types) { - NSMutableDictionary *controllerDict = [[NSMutableDictionary alloc] init]; - controllerDict[@"name"] = type; - [finalArray addObject:controllerDict]; - } - - return [finalArray copy]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; - NSMutableArray *indexPaths = [[NSMutableArray alloc] init]; - [self.tableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone]; } #pragma mark External UITableView functions @@ -131,154 +82,91 @@ typedef void(^CreateView)(UITableViewCell *, NSString *, NSDictionary *); return self.prefSections.count; } +- (NSArray *)prefContentForIndex:(NSInteger)index { + switch (index) { + case 0: return nil; // one single cell is defined in cellForRowAtIndexPath + case 1: return self.currentMappings[@"mGameMappingList"]; + case 2: return self.currentMappings[@"mMenuMappingList"]; + case 3: return self.prefControllerTypes; + default: return nil; + } +} + - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return self.prefContents[section].count; + if (section == 0) { + return 1; + } else { + return [self prefContentForIndex:section].count; + } } - (UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - __weak LauncherPrefContCfgViewController *weakSelf = self; - - NSDictionary *item = self.prefContents[indexPath.section][indexPath.row]; - NSString *cellID = @"cellValue1"; + NSMutableDictionary *item = [self prefContentForIndex:indexPath.section][indexPath.row]; + NSString *cellID = [NSString stringWithFormat:@"cellValue%ld", indexPath.section]; UITableViewCellStyle cellStyle = UITableViewCellStyleValue1; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:cellStyle reuseIdentifier:cellID]; cell.detailTextLabel.numberOfLines = 0; cell.detailTextLabel.lineBreakMode = NSLineBreakByWordWrapping; + cell.selectionStyle = UITableViewCellSelectionStyleGray; } - - // Reset cell properties, as it could be reused - cell.accessoryType = UITableViewCellAccessoryNone; - cell.accessoryView = nil; - cell.selectionStyle = UITableViewCellSelectionStyleNone; - cell.textLabel.textColor = nil; - cell.detailTextLabel.text = nil; - NSString *name = nil; - NSString *value = nil; - NSNumber *keycode = 0; - if(indexPath.section == 0) { - name = item[@"name"]; - value = getPreference(@"default_gamepad_ctrl"); cell.textLabel.text = localize(@"controller_configurator.title.current", nil); cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; - cell.detailTextLabel.text = value; + cell.detailTextLabel.text = getPreference(@"default_gamepad_ctrl"); } else if(indexPath.section == 1 || indexPath.section == 2) { - name = item[@"name"]; NSNumber *keycode = (NSNumber *)item[@"keycode"]; - value = [self.keyCodeMap objectAtIndex:[self.keyValueMap indexOfObject:keycode]]; - cell.textLabel.text = localize(([NSString stringWithFormat:@"controller_configurator.%@.title.%@", getPreference(@"controller_type"), name]), nil); - - CGFloat shortest = MIN(self.view.frame.size.width, self.view.frame.size.height); - CGFloat tempW = MIN(self.view.frame.size.width * 0.75, shortest); - CGFloat tempH = MIN(self.view.frame.size.height * 0.6, shortest); - - UITextField *view = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, cell.bounds.size.width / 2.1, cell.bounds.size.height)]; - [view addTarget:view action:@selector(resignFirstResponder) forControlEvents:UIControlEventEditingDidEndOnExit]; - view.autocorrectionType = UITextAutocorrectionTypeNo; - view.autocapitalizationType = UITextAutocapitalizationTypeNone; - view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin; - view.delegate = weakSelf; - view.returnKeyType = UIReturnKeyDone; - view.text = value; - view.tag = indexPath.section; - view.textAlignment = NSTextAlignmentRight; - view.tintColor = UIColor.clearColor; - view.adjustsFontSizeToFitWidth = YES; - - UIPickerView *pickerMapping = [[UIPickerView alloc] init]; - pickerMapping.delegate = self; - pickerMapping.dataSource = self; - [pickerMapping reloadAllComponents]; - [pickerMapping selectRow:[self.keyValueMap indexOfObject:keycode] inComponent:0 animated:NO]; - [self pickerView:pickerMapping didSelectRow:0 inComponent:0]; - - - UIBlurEffectStyle blurStyle; - UIVisualEffectView *blurView; - if (@available(iOS 13.0, *)) { - blurStyle = UIBlurEffectStyleSystemMaterial; - } else { - blurStyle = UIBlurEffectStyleExtraLight; + cell.textLabel.text = localize(([NSString stringWithFormat:@"controller_configurator.%@.title.%@", getPreference(@"controller_type"), item[@"name"]]), nil); + UITextField *view = (id)cell.accessoryView; + if (view == nil) { + view = [[PickTextField alloc] initWithFrame:CGRectMake(0, 0, cell.bounds.size.width / 2.1, cell.bounds.size.height)]; + [view addTarget:view action:@selector(resignFirstResponder) forControlEvents:UIControlEventEditingDidEndOnExit]; + view.autocorrectionType = UITextAutocorrectionTypeNo; + view.autocapitalizationType = UITextAutocapitalizationTypeNone; + view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin; + view.delegate = self; + view.returnKeyType = UIReturnKeyDone; + view.tag = indexPath.section; + view.textAlignment = NSTextAlignmentRight; + view.tintColor = UIColor.clearColor; + view.adjustsFontSizeToFitWidth = YES; + view.inputAccessoryView = self.editPickToolbar; + view.inputView = self.editPickMapping; + cell.accessoryView = view; } - blurView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:blurStyle]]; - blurView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin; - blurView.frame = CGRectMake( - (self.view.frame.size.width - MAX(tempW, tempH))/2, - (self.view.frame.size.height - MIN(tempW, tempH))/2, - MAX(tempW, tempH), MIN(tempW, tempH)); - blurView.layer.cornerRadius = 10.0; - blurView.clipsToBounds = YES; - - UIToolbar *editPickToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0, 0.0, blurView.frame.size.width, 44.0)]; - UIBarButtonItem *btnFlexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; - - UIBarButtonItem *editDoneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(closeTextField:)]; - editPickToolbar.items = @[btnFlexibleSpace, editDoneButton]; - - view.inputAccessoryView = editPickToolbar; - view.inputView = pickerMapping; - - cell.accessoryView = view; + view.text = self.keyCodeMap[[self.keyValueMap indexOfObject:keycode]]; + objc_setAssociatedObject(view, @"gamepad_button", item[@"name"], OBJC_ASSOCIATION_ASSIGN); + objc_setAssociatedObject(view, @"item", item, OBJC_ASSOCIATION_ASSIGN); } else if(indexPath.section == 3) { - name = item[@"name"]; - value = getPreference(@"default_gamepad_ctrl"); - cell.textLabel.text = localize([NSString stringWithFormat:@"controller_configurator.title.type.%@", name], nil); - if ([getPreference(@"controller_type") isEqualToString:name]) { + cell.textLabel.text = localize([NSString stringWithFormat:@"controller_configurator.title.type.%@", item[@"name"]], nil); + if ([getPreference(@"controller_type") isEqualToString:item[@"name"]]) { cell.accessoryType = UITableViewCellAccessoryCheckmark; } else { cell.accessoryType = UITableViewCellAccessoryNone; } } - cell.selectionStyle = UITableViewCellSelectionStyleGray; - - if (cell.accessoryView) { - objc_setAssociatedObject(cell.accessoryView, @"gamepad_button", name, OBJC_ASSOCIATION_ASSIGN); - objc_setAssociatedObject(cell.accessoryView, @"item", item, OBJC_ASSOCIATION_ASSIGN); - } - - [(id)cell.accessoryView setEnabled:YES]; - return cell; } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { - NSString *header = NSLocalizedStringWithDefaultValue(([NSString stringWithFormat:@"controller_configurator.section.%@", self.prefSections[section]]), @"Localizable", NSBundle.mainBundle, @" ", nil); - if ([header isEqualToString:@" "]) { - return nil; - } - return header; + return localize([NSString stringWithFormat:@"controller_configurator.section.%@", self.prefSections[section]], nil); } - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section { - NSString *footer = NSLocalizedStringWithDefaultValue(([NSString stringWithFormat:@"controller_configurator.section.footer.%@", self.prefSections[section]]), @"Localizable", NSBundle.mainBundle, @" ", nil); - if ([footer isEqualToString:@" "]) { - return nil; - } - return footer; + NSString *key = [NSString stringWithFormat:@"controller_configurator.section.footer.%@", self.prefSections[section]]; + NSString *footer = localize(key, nil); + return [footer isEqualToString:key] ? nil : footer; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:NO]; - NSDictionary *item = self.prefContents[indexPath.section][indexPath.row]; - - if (indexPath.section == 0 || indexPath.section == 3) { - [self tableView:tableView invokeActionAtIndexPath:indexPath]; - return; - } - // 1 and 2 handle themselves with picker views. - - return; -} - -- (void)tableView:(UITableView *)tableView invokeActionAtIndexPath:(NSIndexPath *)indexPath { + NSDictionary *item = [self prefContentForIndex:indexPath.section][indexPath.row]; UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; if(indexPath.section == 0) { [self actionMenuLoad]; - [self.tableView reloadData]; } else if(indexPath.section == 3) { if(indexPath.row == 0) { setPreference(@"controller_type", @"xbox"); @@ -288,6 +176,7 @@ typedef void(^CreateView)(UITableViewCell *, NSString *, NSDictionary *); NSIndexSet *section = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, 3)]; [self.tableView reloadSections:section withRowAnimation:UITableViewRowAnimationNone]; } + // 1 and 2 handle themselves with picker views. } #pragma mark UITextField + UIPickerView @@ -325,11 +214,27 @@ typedef void(^CreateView)(UITableViewCell *, NSString *, NSDictionary *); - (void)textFieldDidBeginEditing:(UITextField *)textField { self.activeTextField = textField; + [self.editPickMapping selectRow:[self.keyCodeMap indexOfObject:textField.text] inComponent:0 animated:NO]; } - (void)textFieldDidEndEditing:(UITextField *)textField { UITableViewCell *cell = (UITableViewCell *)textField.superview; - __block NSDictionary *item = objc_getAssociatedObject(cell.accessoryView, @"item"); + NSMutableDictionary *item = objc_getAssociatedObject(cell.accessoryView, @"item"); +/* + if(textField.tag == 1) { + arrayToSave = self.prefMappings[0]; + index = @"mGameMappingList"; + } else if(textField.tag == 2) { + arrayToSave = self.prefMappings[1]; + index = @"mMenuMappingList"; + } +*/ + if(![textField.text hasPrefix:@"SPECIALBTN"]) { + item[@"keycode"] = self.keycodePlist[[@"GLFW_KEY_" stringByAppendingString:textField.text]]; + } else { + item[@"keycode"] = self.keycodePlist[textField.text]; + } +/* __block NSString *fullString = @""; __block NSArray *arrayToSave = nil; __block NSUInteger btnIndex = 0; @@ -356,8 +261,8 @@ typedef void(^CreateView)(UITableViewCell *, NSString *, NSDictionary *); fullString = textField.text; } - self.allMappings[index][btnIndex][@"keycode"] = [self.keycodePlist objectForKey:fullString]; - + self.currentMappings[index][btnIndex][@"keycode"] = [self.keycodePlist objectForKey:fullString]; +*/ self.activeTextField = nil; } @@ -391,8 +296,7 @@ typedef void(^CreateView)(UITableViewCell *, NSString *, NSDictionary *); NSString *currentFile = [NSString stringWithFormat:@"%@.json", getPreference(@"default_gamepad_ctrl")]; if(![currentFile isEqualToString:name]) { setPreference(@"default_gamepad_ctrl", [NSString stringWithFormat:@"%@.json", name]); - self.prefMappings = [self loadGamepadConfigurationFile:YES shouldSkipImmutables:NO]; - self.prefMappingsTrimmed = [self loadGamepadConfigurationFile:NO shouldSkipImmutables:YES]; + [self loadGamepadConfigurationFile]; [self.tableView reloadData]; } }]; @@ -412,7 +316,7 @@ typedef void(^CreateView)(UITableViewCell *, NSString *, NSDictionary *); NSArray *textFields = controller.textFields; UITextField *field = textFields[0]; NSError *error; - NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self.allMappings options:NSJSONWritingPrettyPrinted error:&error]; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self.currentMappings options:NSJSONWritingPrettyPrinted error:&error]; if (jsonData == nil) { showDialog(self, localize(@"custom_controls.control_menu.save.error.json", nil), error.localizedDescription); return; @@ -444,7 +348,7 @@ typedef void(^CreateView)(UITableViewCell *, NSString *, NSDictionary *); - (void)exitButtonSelector { NSString *gamepadPath = [NSString stringWithFormat:@"%s/controlmap/gamepads/%@", getenv("POJAV_HOME"), getPreference(@"default_gamepad_ctrl")]; - if([self.allMappings isEqualToDictionary:parseJSONFromFile(gamepadPath)]) { + if([self.currentMappings isEqualToDictionary:parseJSONFromFile(gamepadPath)]) { [self dismissModalViewController]; } else { [self actionMenuSaveWithExit:YES]; diff --git a/Natives/LauncherPreferencesViewController.m b/Natives/LauncherPreferencesViewController.m index 9f5dd276..e5ddfdda 100644 --- a/Natives/LauncherPreferencesViewController.m +++ b/Natives/LauncherPreferencesViewController.m @@ -240,14 +240,12 @@ typedef void(^CreateView)(UITableViewCell *, NSString *, NSDictionary *); @{@"key": @"silence_other_audio", @"hasDetail": @YES, @"icon": @"speaker.slash", - @"type": self.typeSwitch, - @"enableCondition": whenNotInGame + @"type": self.typeSwitch }, @{@"key": @"silence_with_switch", @"hasDetail": @YES, @"icon": @"speaker.zzz", - @"type": self.typeSwitch, - @"enableCondition": whenNotInGame + @"type": self.typeSwitch }, ], @[ // Control settings diff --git a/Natives/PickTextField.h b/Natives/PickTextField.h new file mode 100644 index 00000000..3f5434cf --- /dev/null +++ b/Natives/PickTextField.h @@ -0,0 +1,5 @@ +#import + +@interface PickTextField : UITextField + +@end diff --git a/Natives/PickTextField.m b/Natives/PickTextField.m new file mode 100644 index 00000000..b1115640 --- /dev/null +++ b/Natives/PickTextField.m @@ -0,0 +1,20 @@ +#import "PickTextField.h" + +@interface PickTextField() +@end + +@implementation PickTextField + +- (BOOL)canPerformAction:(SEL)action withSender:(id)sender { + return NO; +} + +- (CGRect)caretRectForPosition:(UITextPosition*) position { + return CGRectNull; +} + +- (NSArray *)selectionRectsForRange:(UITextRange *)range { + return nil; +} + +@end diff --git a/Natives/SurfaceViewController.m b/Natives/SurfaceViewController.m index 50675e61..66be1c23 100644 --- a/Natives/SurfaceViewController.m +++ b/Natives/SurfaceViewController.m @@ -1,3 +1,4 @@ +#import #import #import @@ -299,6 +300,24 @@ BOOL slideableHotbar; } } +- (void)updateAudioSettings { + NSError *sessionError = nil; + AVAudioSessionCategory category; + AVAudioSessionCategoryOptions options; + if([getPreference(@"silence_with_switch") boolValue]) { + category = AVAudioSessionCategorySoloAmbient; + } else { + category = AVAudioSessionCategoryPlayback; + } + if([getPreference(@"silence_other_audio") boolValue]) { + options = 0; + } else { + options = AVAudioSessionCategoryOptionMixWithOthers; + } + [[AVAudioSession sharedInstance] setCategory:category withOptions:options error:&sessionError]; + [[AVAudioSession sharedInstance] setActive:YES error:&sessionError]; +} + - (void)updateJetsamControl { if (!getEntitlementValue(@"com.apple.private.memorystatus")) { return; @@ -347,6 +366,8 @@ BOOL slideableHotbar; self.doubleTapGesture.enabled = self.enableHotbarGestures; self.longPressGesture.minimumPressDuration = [getPreference(@"press_duration") floatValue] / 1000.0; + // Update audio settings + [self updateAudioSettings]; // Update resolution [self updateSavedResolution]; } diff --git a/Natives/customcontrols/CustomControlsUtils.m b/Natives/customcontrols/CustomControlsUtils.m index 65cb9974..49b838db 100644 --- a/Natives/customcontrols/CustomControlsUtils.m +++ b/Natives/customcontrols/CustomControlsUtils.m @@ -321,10 +321,6 @@ void generateAndSaveDefaultControlForGamepad() { dict[@"mGameMappingList"] = [[NSMutableArray alloc] init]; - [dict[@"mGameMappingList"] addObject:createGamepadButton(@"mouse_primary", SPECIALBTN_MOUSEPRI, SPECIALBTN_MOUSEPRI)]; - [dict[@"mGameMappingList"] addObject:createGamepadButton(@"mouse_middle", SPECIALBTN_MOUSEMID, SPECIALBTN_MOUSEMID)]; - [dict[@"mGameMappingList"] addObject:createGamepadButton(@"mouse_secondary", SPECIALBTN_MOUSESEC, SPECIALBTN_MOUSESEC)]; - [dict[@"mGameMappingList"] addObject:createGamepadButton(@"bumper_left", GLFW_GAMEPAD_BUTTON_LEFT_BUMPER, SPECIALBTN_SCROLLUP)]; [dict[@"mGameMappingList"] addObject:createGamepadButton(@"bumper_right", GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER, SPECIALBTN_SCROLLDOWN)];