From 72543d13107b0fb34d3611ca02f3ed8845e24d38 Mon Sep 17 00:00:00 2001 From: meancoot Date: Sat, 9 Feb 2013 21:24:09 -0500 Subject: [PATCH] ios: Add support for enumeration and file based settings. --- ios/RetroArch/RetroArch_iOS.h | 1 + ios/RetroArch/RetroArch_iOS.m | 2 + ios/RetroArch/settings_list.m | 117 ++++++++++++++++++++++++++++++++-- 3 files changed, 114 insertions(+), 6 deletions(-) diff --git a/ios/RetroArch/RetroArch_iOS.h b/ios/RetroArch/RetroArch_iOS.h index 8d137eab63..37391de73a 100644 --- a/ios/RetroArch/RetroArch_iOS.h +++ b/ios/RetroArch/RetroArch_iOS.h @@ -13,6 +13,7 @@ @property (strong, nonatomic) UIWindow *window; @property (strong, nonatomic) NSString *module_path; +@property (strong, nonatomic) NSString *overlay_path; @property (strong, nonatomic) UINavigationController *navigator; @property (strong, nonatomic) UIImage* file_icon; @property (strong, nonatomic) UIImage* folder_icon; diff --git a/ios/RetroArch/RetroArch_iOS.m b/ios/RetroArch/RetroArch_iOS.m index f5bb8e984f..39eff8bb2c 100644 --- a/ios/RetroArch/RetroArch_iOS.m +++ b/ios/RetroArch/RetroArch_iOS.m @@ -31,6 +31,8 @@ extern uint32_t ios_current_touch_count ; self.system_directory = "/var/mobile/Library/RetroArch/"; mkdir(self.system_directory, 0755); + self.overlay_path = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/overlays"]; + // Load icons self.file_icon = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"ic_file" ofType:@"png"]]; self.folder_icon = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"ic_dir" ofType:@"png"]]; diff --git a/ios/RetroArch/settings_list.m b/ios/RetroArch/settings_list.m index 41d3475ffe..79344e80b5 100644 --- a/ios/RetroArch/settings_list.m +++ b/ios/RetroArch/settings_list.m @@ -6,9 +6,9 @@ // Copyright (c) 2013 RetroArch. All rights reserved. // -static NSDictionary* boolean_setting(NSString* name, NSString* label, NSString* value) +static NSMutableDictionary* boolean_setting(NSString* name, NSString* label, NSString* value) { - return [[NSDictionary alloc] initWithObjectsAndKeys: + return [[NSMutableDictionary alloc] initWithObjectsAndKeys: @"B", @"TYPE", name, @"NAME", label, @"LABEL", @@ -16,6 +16,81 @@ static NSDictionary* boolean_setting(NSString* name, NSString* label, NSString* nil]; } +static NSMutableDictionary* enumeration_setting(NSString* name, NSString* label, NSString* value, NSArray* values) +{ + return [[NSMutableDictionary alloc] initWithObjectsAndKeys: + @"E", @"TYPE", + name, @"NAME", + label, @"LABEL", + value, @"VALUE", + values, @"VALUES", + nil]; +} + +static NSMutableDictionary* subpath_setting(NSString* name, NSString* label, NSString* value, NSString* path, NSString* extension) +{ + NSArray* values = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:[RetroArch_iOS get].overlay_path error:nil]; + values = [values pathsMatchingExtensions:[NSArray arrayWithObject:extension]]; + + return [[NSMutableDictionary alloc] initWithObjectsAndKeys: + @"F", @"TYPE", + name, @"NAME", + label, @"LABEL", + value, @"VALUE", + values, @"VALUES", + path, @"PATH", + nil]; +} + +@interface enumeration_list : UITableViewController +@end + +@implementation enumeration_list +{ + NSMutableDictionary* value; + UITableView* view; +}; + +- (id)initWithSetting:(NSMutableDictionary*)setting fromTable:(UITableView*)table +{ + self = [super initWithStyle:UITableViewStyleGrouped]; + + value = setting; + view = table; + [self setTitle: [value objectForKey:@"LABEL"]]; + return self; +} + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return [[value objectForKey:@"VALUES"] count]; +} + +- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + UITableViewCell* cell = [self.tableView dequeueReusableCellWithIdentifier:@"option"]; + cell = cell ? cell : [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"option"]; + + cell.textLabel.text = [[value objectForKey:@"VALUES"] objectAtIndex:indexPath.row]; + + return cell; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + [value setObject:[[value objectForKey:@"VALUES"] objectAtIndex:indexPath.row] forKey:@"VALUE"]; + + [view reloadData]; + [[RetroArch_iOS get].navigator popViewControllerAnimated:YES]; +} + +@end + @implementation settings_list { NSArray* settings; @@ -25,6 +100,7 @@ static NSDictionary* boolean_setting(NSString* name, NSString* label, NSString* { self = [super initWithStyle:UITableViewStyleGrouped]; + settings = [NSArray arrayWithObjects: [NSArray arrayWithObjects:@"Video", boolean_setting(@"video_smooth", @"Smooth Video", @"true"), @@ -36,6 +112,10 @@ static NSDictionary* boolean_setting(NSString* name, NSString* label, NSString* boolean_setting(@"audio_sync", @"Sync on Audio Stream", @"true"), boolean_setting(@"audio_rate_control", @"Adjust for Better Sync", @"true"), nil], + + [NSArray arrayWithObjects:@"Input", + subpath_setting(@"input_overlay", @"Input Overlay", @"", [RetroArch_iOS get].overlay_path, @"cfg"), + nil], [NSArray arrayWithObjects:@"Save States", boolean_setting(@"rewind_enable", @"Enable Rewinding", @"false"), @@ -65,9 +145,12 @@ static NSDictionary* boolean_setting(NSString* name, NSString* label, NSString* for (int j = 1; j < [group count]; j ++) { - NSDictionary* setting = [group objectAtIndex:j]; + NSMutableDictionary* setting = [group objectAtIndex:j]; - fprintf(output, "%s = %s\n", [[setting objectForKey:@"NAME"] UTF8String], [[setting objectForKey:@"VALUE"] UTF8String]); + if ([[setting objectForKey:@"TYPE"] isEqualToString:@"F"]) + fprintf(output, "%s = \"%s/%s\"\n", [[setting objectForKey:@"NAME"] UTF8String], [[setting objectForKey:@"PATH"] UTF8String], [[setting objectForKey:@"VALUE"] UTF8String]); + else + fprintf(output, "%s = %s\n", [[setting objectForKey:@"NAME"] UTF8String], [[setting objectForKey:@"VALUE"] UTF8String]); } } @@ -76,10 +159,20 @@ static NSDictionary* boolean_setting(NSString* name, NSString* label, NSString* - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + NSMutableDictionary* setting = [[settings objectAtIndex:indexPath.section] objectAtIndex:indexPath.row + 1]; + NSString* type = [setting valueForKey:@"TYPE"]; + + if ([type isEqualToString:@"E"] || [type isEqualToString:@"F"]) + { + [[RetroArch_iOS get].navigator + pushViewController:[[enumeration_list alloc] initWithSetting:setting fromTable:(UITableView*)self.view] + animated:YES]; + } } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + [self write_to_file]; return [settings count]; } @@ -95,10 +188,12 @@ static NSDictionary* boolean_setting(NSString* name, NSString* label, NSString* - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - NSDictionary* setting = [[settings objectAtIndex:indexPath.section] objectAtIndex:indexPath.row + 1]; + NSMutableDictionary* setting = [[settings objectAtIndex:indexPath.section] objectAtIndex:indexPath.row + 1]; UITableViewCell* cell = nil; - if ([[setting valueForKey:@"TYPE"] isEqualToString:@"B"]) + NSString* type = [setting valueForKey:@"TYPE"]; + + if ([type isEqualToString:@"B"]) { cell = [self.tableView dequeueReusableCellWithIdentifier:@"boolean"]; @@ -112,8 +207,18 @@ static NSDictionary* boolean_setting(NSString* name, NSString* label, NSString* UISwitch* swt = (UISwitch*)cell.accessoryView; swt.on = [[setting valueForKey:@"VALUE"] isEqualToString:@"true"]; } + else if ([type isEqualToString:@"E"] || [type isEqualToString:@"F"]) + { + cell = [self.tableView dequeueReusableCellWithIdentifier:@"enumeration"]; + + if (cell == nil) + { + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"enumeration"]; + } + } cell.textLabel.text = [setting valueForKey:@"LABEL"]; + cell.detailTextLabel.text = [setting valueForKey:@"VALUE"]; return cell; }