|
|
|
@@ -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 ()<UITextFieldDelegate, UIPopoverPresentationControllerDelegate, UIPickerViewDataSource, UIPickerViewDelegate>
|
|
|
|
|
@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<NSString*>* prefSections;
|
|
|
|
|
@property(nonatomic) NSMutableArray<NSNumber*>* prefSectionsVisibility;
|
|
|
|
|
@property(nonatomic) NSArray<NSArray<NSDictionary*>*>* prefContents;
|
|
|
|
|
@property(nonatomic) NSArray<NSArray*>* prefMappings, *prefMappingsTrimmed;
|
|
|
|
|
@property(nonatomic) NSArray<NSDictionary*>* prefConfigFiles, *prefControllerTypes;
|
|
|
|
|
@property(nonatomic) NSArray<NSDictionary*> *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<NSArray<NSDictionary*>*>*) 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<NSDictionary*>* tempGameMap = [[NSMutableArray<NSDictionary*> alloc] init];
|
|
|
|
|
NSMutableArray<NSDictionary*>* tempMenuMap = [[NSMutableArray<NSDictionary*> 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<NSDictionary*>*) loadGamepadControlFolder {
|
|
|
|
|
NSArray<NSString*>* gamepadCtrl = @[getPreference(@"default_gamepad_ctrl")];
|
|
|
|
|
NSMutableArray<NSDictionary*>* finalArray = [[NSMutableArray alloc] init];
|
|
|
|
|
NSMutableDictionary *holder = [[NSMutableDictionary alloc] init];
|
|
|
|
|
holder[@"name"] = gamepadCtrl;
|
|
|
|
|
[finalArray addObject:holder];
|
|
|
|
|
|
|
|
|
|
return [finalArray copy];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (NSArray<NSDictionary*>*) loadControllerTypeOptions {
|
|
|
|
|
NSArray<NSString*>* types = @[@"xbox", @"playstation"];
|
|
|
|
|
NSMutableArray<NSDictionary*>* 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];
|
|
|
|
|