From 65fb256b90c56aa2f51daadb4b2599fd48f1aee9 Mon Sep 17 00:00:00 2001 From: meancoot Date: Fri, 14 Jun 2013 00:45:35 -0400 Subject: [PATCH] (iOS) Some much needed code cleanup --- ios/RetroArch.xcodeproj/project.pbxproj | 44 +++------ ios/RetroArch/RAGameView.m | 5 +- ios/RetroArch/RALogView.m | 2 + ios/RetroArch/RAModuleInfo.h | 3 - ios/RetroArch/RAModuleInfo.m | 66 +++++++------ ios/RetroArch/RetroArch-Prefix.pch | 5 +- ios/RetroArch/RetroArch_iOS.h | 3 +- ios/RetroArch/{browser => }/browser.m | 119 +++++++++++++++++++----- ios/RetroArch/browser/RAModuleList.m | 116 ----------------------- ios/RetroArch/browser/browser.h | 26 ------ ios/RetroArch/main.m | 36 ++----- ios/RetroArch/{settings => }/settings.m | 77 +++++++++------ ios/RetroArch/settings/settings.h | 63 ------------- ios/RetroArch/utility.m | 60 ++++++++++++ ios/RetroArch/views.h | 49 +++++++++- 15 files changed, 314 insertions(+), 360 deletions(-) rename ios/RetroArch/{browser => }/browser.m (57%) delete mode 100644 ios/RetroArch/browser/RAModuleList.m delete mode 100644 ios/RetroArch/browser/browser.h rename ios/RetroArch/{settings => }/settings.m (95%) delete mode 100644 ios/RetroArch/settings/settings.h create mode 100644 ios/RetroArch/utility.m diff --git a/ios/RetroArch.xcodeproj/project.pbxproj b/ios/RetroArch.xcodeproj/project.pbxproj index bc8ecdac38..c68dec0853 100644 --- a/ios/RetroArch.xcodeproj/project.pbxproj +++ b/ios/RetroArch.xcodeproj/project.pbxproj @@ -12,11 +12,12 @@ 962979F716C43B9500E6DCE0 /* ic_file.png in Resources */ = {isa = PBXBuildFile; fileRef = 962979F516C43B9500E6DCE0 /* ic_file.png */; }; 96297A0F16C5AEA100E6DCE0 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 96297A0E16C5AEA100E6DCE0 /* main.m */; }; 96297A2716C82FF100E6DCE0 /* overlays in Resources */ = {isa = PBXBuildFile; fileRef = 96297A2616C82FF100E6DCE0 /* overlays */; }; + 96337E82176AC6E5004685F3 /* utility.m in Sources */ = {isa = PBXBuildFile; fileRef = 96337E81176AC6E5004685F3 /* utility.m */; }; + 96337E84176AD5D9004685F3 /* browser.m in Sources */ = {isa = PBXBuildFile; fileRef = 96337E83176AD5D9004685F3 /* browser.m */; }; + 96337E86176AD6B6004685F3 /* settings.m in Sources */ = {isa = PBXBuildFile; fileRef = 96337E85176AD6B6004685F3 /* settings.m */; }; 96366C5516C9AC3300D64A22 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96366C5416C9AC3300D64A22 /* CoreAudio.framework */; }; 96366C5916C9ACF500D64A22 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96366C5816C9ACF500D64A22 /* AudioToolbox.framework */; }; 963F5AC816CC523B009BBD19 /* RAGameView.m in Sources */ = {isa = PBXBuildFile; fileRef = 963F5AC516CC523B009BBD19 /* RAGameView.m */; }; - 966B9CAE16E41C07005B61E1 /* browser.m in Sources */ = {isa = PBXBuildFile; fileRef = 966B9CAA16E41C07005B61E1 /* browser.m */; }; - 966B9CB416E41C07005B61E1 /* RAModuleList.m in Sources */ = {isa = PBXBuildFile; fileRef = 966B9CAD16E41C07005B61E1 /* RAModuleList.m */; }; 966B9CBD16E41E7A005B61E1 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 966B9CB816E41E7A005B61E1 /* Default-568h@2x.png */; }; 966B9CBF16E41E7A005B61E1 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 966B9CB916E41E7A005B61E1 /* Default.png */; }; 966B9CC116E41E7A005B61E1 /* Default@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 966B9CBA16E41E7A005B61E1 /* Default@2x.png */; }; @@ -34,7 +35,6 @@ 96AFAE3816C1D4EA009DE44C /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 96AFAE3616C1D4EA009DE44C /* InfoPlist.strings */; }; 96F9C28316FFA55F002455B3 /* RALogView.m in Sources */ = {isa = PBXBuildFile; fileRef = 96F9C28216FFA55F002455B3 /* RALogView.m */; }; D48581DE16F823F9004BEB17 /* griffin.c in Sources */ = {isa = PBXBuildFile; fileRef = D48581DD16F823F9004BEB17 /* griffin.c */; }; - D486CA88170D4EAF004DC638 /* settings.m in Sources */ = {isa = PBXBuildFile; fileRef = D486CA87170D4EAF004DC638 /* settings.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -47,13 +47,12 @@ 96297A0D16C5ADDA00E6DCE0 /* views.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = views.h; sourceTree = ""; }; 96297A0E16C5AEA100E6DCE0 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 96297A2616C82FF100E6DCE0 /* overlays */ = {isa = PBXFileReference; lastKnownFileType = folder; name = overlays; path = ../../media/overlays; sourceTree = ""; }; + 96337E81176AC6E5004685F3 /* utility.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = utility.m; sourceTree = ""; }; + 96337E83176AD5D9004685F3 /* browser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = browser.m; sourceTree = ""; }; + 96337E85176AD6B6004685F3 /* settings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = settings.m; sourceTree = ""; }; 96366C5416C9AC3300D64A22 /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = System/Library/Frameworks/CoreAudio.framework; sourceTree = SDKROOT; }; 96366C5816C9ACF500D64A22 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; - 96366C7216CAF62200D64A22 /* settings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = settings.h; sourceTree = ""; }; 963F5AC516CC523B009BBD19 /* RAGameView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RAGameView.m; sourceTree = ""; }; - 966B9CA916E41C07005B61E1 /* browser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = browser.h; sourceTree = ""; }; - 966B9CAA16E41C07005B61E1 /* browser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = browser.m; sourceTree = ""; }; - 966B9CAD16E41C07005B61E1 /* RAModuleList.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RAModuleList.m; sourceTree = ""; }; 966B9CB816E41E7A005B61E1 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; }; 966B9CB916E41E7A005B61E1 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = ""; }; 966B9CBA16E41E7A005B61E1 /* Default@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default@2x.png"; sourceTree = ""; }; @@ -79,7 +78,6 @@ 96C19C2616D455BE00FE8D5A /* rarch_wrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rarch_wrapper.h; sourceTree = ""; }; 96F9C28216FFA55F002455B3 /* RALogView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RALogView.m; sourceTree = ""; }; D48581DD16F823F9004BEB17 /* griffin.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = griffin.c; path = ../griffin/griffin.c; sourceTree = ""; }; - D486CA87170D4EAF004DC638 /* settings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = settings.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -100,25 +98,6 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 96366C6F16CAF62200D64A22 /* settings */ = { - isa = PBXGroup; - children = ( - D486CA87170D4EAF004DC638 /* settings.m */, - 96366C7216CAF62200D64A22 /* settings.h */, - ); - path = settings; - sourceTree = ""; - }; - 966B9CA816E41C07005B61E1 /* browser */ = { - isa = PBXGroup; - children = ( - 966B9CA916E41C07005B61E1 /* browser.h */, - 966B9CAA16E41C07005B61E1 /* browser.m */, - 966B9CAD16E41C07005B61E1 /* RAModuleList.m */, - ); - path = browser; - sourceTree = ""; - }; 966B9CB716E41E7A005B61E1 /* Assets */ = { isa = PBXGroup; children = ( @@ -175,8 +154,7 @@ 96AFAE3316C1D4EA009DE44C /* RetroArch */ = { isa = PBXGroup; children = ( - 966B9CA816E41C07005B61E1 /* browser */, - 96366C6F16CAF62200D64A22 /* settings */, + 96337E83176AD5D9004685F3 /* browser.m */, 96297A0E16C5AEA100E6DCE0 /* main.m */, 963F5AC516CC523B009BBD19 /* RAGameView.m */, 96F9C28216FFA55F002455B3 /* RALogView.m */, @@ -184,6 +162,8 @@ 9605EA99170288EA001D47B0 /* RAModuleInfo.h */, 96C19C2616D455BE00FE8D5A /* rarch_wrapper.h */, 96297A0A16C5AD8D00E6DCE0 /* RetroArch_iOS.h */, + 96337E85176AD6B6004685F3 /* settings.m */, + 96337E81176AC6E5004685F3 /* utility.m */, 96297A0D16C5ADDA00E6DCE0 /* views.h */, ); path = RetroArch; @@ -323,12 +303,12 @@ files = ( 96297A0F16C5AEA100E6DCE0 /* main.m in Sources */, 963F5AC816CC523B009BBD19 /* RAGameView.m in Sources */, - 966B9CAE16E41C07005B61E1 /* browser.m in Sources */, - 966B9CB416E41C07005B61E1 /* RAModuleList.m in Sources */, D48581DE16F823F9004BEB17 /* griffin.c in Sources */, 96F9C28316FFA55F002455B3 /* RALogView.m in Sources */, 9605EA9B170288EA001D47B0 /* RAModuleInfo.m in Sources */, - D486CA88170D4EAF004DC638 /* settings.m in Sources */, + 96337E82176AC6E5004685F3 /* utility.m in Sources */, + 96337E84176AD5D9004685F3 /* browser.m in Sources */, + 96337E86176AD6B6004685F3 /* settings.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/ios/RetroArch/RAGameView.m b/ios/RetroArch/RAGameView.m index 48402ba7bd..13329491ed 100644 --- a/ios/RetroArch/RAGameView.m +++ b/ios/RetroArch/RAGameView.m @@ -13,10 +13,13 @@ * If not, see . */ -#include "general.h" +#import "RetroArch_iOS.h" +#import "views.h" #include "rarch_wrapper.h" #include "input/ios_input.h" +#include "general.h" + static const float ALMOST_INVISIBLE = .021f; static float g_screen_scale; static int g_fast_forward_skips; diff --git a/ios/RetroArch/RALogView.m b/ios/RetroArch/RALogView.m index 22482a555d..61e4e41fbc 100644 --- a/ios/RetroArch/RALogView.m +++ b/ios/RetroArch/RALogView.m @@ -17,6 +17,8 @@ #include #include +#import "views.h" + static NSMutableArray* g_messages; static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; diff --git a/ios/RetroArch/RAModuleInfo.h b/ios/RetroArch/RAModuleInfo.h index 5f18be5f6e..466e2a52e0 100644 --- a/ios/RetroArch/RAModuleInfo.h +++ b/ios/RetroArch/RAModuleInfo.h @@ -26,6 +26,3 @@ - (bool)supportsFileAtPath:(NSString*)path; @end -@interface RAModuleInfoList : UITableViewController -- (id)initWithModuleInfo:(RAModuleInfo*)info; -@end diff --git a/ios/RetroArch/RAModuleInfo.m b/ios/RetroArch/RAModuleInfo.m index 292edabe1f..197fe80cec 100644 --- a/ios/RetroArch/RAModuleInfo.m +++ b/ios/RetroArch/RAModuleInfo.m @@ -14,8 +14,12 @@ */ #include + +#import "RetroArch_iOS.h" #import "RAModuleInfo.h" -#import "browser/browser.h" +#import "views.h" + +#include "file.h" static NSMutableArray* moduleList; @@ -84,10 +88,17 @@ static NSMutableArray* moduleList; @end +// Build a string with a second associated string +static NSString* build_string_pair(NSString* stringA, NSString* stringB) +{ + NSString* string_pair = [NSString stringWithString:stringA]; + objc_setAssociatedObject(string_pair, "OTHER", stringB, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + return string_pair; +} + @implementation RAModuleInfoList { RAModuleInfo* _data; - NSMutableArray* _sections; uint32_t _firmwareSectionIndex; } @@ -97,15 +108,13 @@ static NSMutableArray* moduleList; _data = info; - _sections = [NSMutableArray array]; - - [_sections addObject: [NSArray arrayWithObjects:@"Core", - @"Core Name", ios_get_value_from_config(_data.data, @"corename", @"Unspecified"), + [self.sections addObject: [NSArray arrayWithObjects:@"Core", + build_string_pair(@"Core Name", ios_get_value_from_config(_data.data, @"corename", @"Unspecified")), nil]]; - [_sections addObject: [NSArray arrayWithObjects:@"Hardware/Software", - @"Developer", ios_get_value_from_config(_data.data, @"manufacturer", @"Unspecified"), - @"Name", ios_get_value_from_config(_data.data, @"systemname", @"Unspecified"), + [self.sections addObject: [NSArray arrayWithObjects:@"Hardware/Software", + build_string_pair(@"Developer", ios_get_value_from_config(_data.data, @"manufacturer", @"Unspecified")), + build_string_pair(@"Name", ios_get_value_from_config(_data.data, @"systemname", @"Unspecified")), nil]]; // Firmware @@ -117,39 +126,25 @@ static NSMutableArray* moduleList; for (int i = 0; i < firmwareCount; i ++) { - [firmwareSection addObject:ios_get_value_from_config(_data.data, [NSString stringWithFormat:@"firmware%d_desc", i + 1], @"Unspecified")]; - NSString* path = ios_get_value_from_config(_data.data, [NSString stringWithFormat:@"firmware%d_path", i + 1], @"Unspecified"); - path = [path stringByReplacingOccurrencesOfString:@"%sysdir%" withString:RetroArch_iOS.get.systemDirectory]; - [firmwareSection addObject:path]; + path = [path stringByReplacingOccurrencesOfString:@"%sysdir%" withString:RetroArch_iOS.get.systemDirectory]; + [firmwareSection addObject:build_string_pair(ios_get_value_from_config(_data.data, [NSString stringWithFormat:@"firmware%d_desc", i + 1], @"Unspecified"), path)]; } - _firmwareSectionIndex = _sections.count; - [_sections addObject:firmwareSection]; + _firmwareSectionIndex = self.sections.count; + [self.sections addObject:firmwareSection]; } return self; } -- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView -{ - return _sections.count; -} - -- (NSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section -{ - return _sections[section][0]; -} - -- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section -{ - return ([_sections[section] count] - 1) / 2; -} - - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == _firmwareSectionIndex) - [RetroArch_iOS displayErrorMessage:_sections[indexPath.section][indexPath.row * 2 + 2] withTitle:_sections[indexPath.section][indexPath.row * 2 + 1]]; + { + NSString* item = (NSString*)[self itemForIndexPath:indexPath]; + [RetroArch_iOS displayErrorMessage:objc_getAssociatedObject(item, "OTHER") withTitle:item]; + } } - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath @@ -163,11 +158,14 @@ static NSMutableArray* moduleList; cell.detailTextLabel.adjustsFontSizeToFitWidth = YES; } - cell.textLabel.text = _sections[indexPath.section][indexPath.row * 2 + 1]; - cell.detailTextLabel.text = _sections[indexPath.section][indexPath.row * 2 + 2]; + NSString* item = (NSString*)[self itemForIndexPath:indexPath]; + NSString* value = (NSString*)objc_getAssociatedObject(item, "OTHER"); + + cell.textLabel.text = item; + cell.detailTextLabel.text = value; if (indexPath.section == _firmwareSectionIndex) - cell.backgroundColor = path_file_exists(((NSString*)_sections[indexPath.section][indexPath.row * 2 + 2]).UTF8String) ? [UIColor blueColor] : [UIColor redColor]; + cell.backgroundColor = path_file_exists(value.UTF8String) ? [UIColor blueColor] : [UIColor redColor]; else cell.backgroundColor = [UIColor whiteColor]; diff --git a/ios/RetroArch/RetroArch-Prefix.pch b/ios/RetroArch/RetroArch-Prefix.pch index ca2c72fb32..fedf841223 100644 --- a/ios/RetroArch/RetroArch-Prefix.pch +++ b/ios/RetroArch/RetroArch-Prefix.pch @@ -25,7 +25,8 @@ #ifdef __OBJC__ #import + #import #import - #import "views.h" - #import "RetroArch_iOS.h" + + #import #endif diff --git a/ios/RetroArch/RetroArch_iOS.h b/ios/RetroArch/RetroArch_iOS.h index 97efa78cc7..6295c5fe64 100644 --- a/ios/RetroArch/RetroArch_iOS.h +++ b/ios/RetroArch/RetroArch_iOS.h @@ -13,7 +13,7 @@ * If not, see . */ -#import +#import "RAModuleInfo.h" @interface RetroArch_iOS : UINavigationController @@ -35,4 +35,5 @@ @end +// utility.m extern NSString* ios_get_value_from_config(config_file_t* config, NSString* name, NSString* defaultValue); diff --git a/ios/RetroArch/browser/browser.m b/ios/RetroArch/browser.m similarity index 57% rename from ios/RetroArch/browser/browser.m rename to ios/RetroArch/browser.m index 82f415e600..29dcbd3426 100644 --- a/ios/RetroArch/browser/browser.m +++ b/ios/RetroArch/browser.m @@ -15,8 +15,12 @@ #include #include -#import "browser.h" + +#import "RetroArch_iOS.h" +#import "views.h" + #include "conf/config_file.h" +#include "file.h" @interface RADirectoryItem : NSObject @property (strong) NSString* path; @@ -28,8 +32,8 @@ @implementation RADirectoryList { - NSMutableArray* _list; NSString* _path; + NSMutableArray* _sectionNames; } + (id)directoryListAtBrowseRoot @@ -57,7 +61,8 @@ _path = path; self = [super initWithStyle:UITableViewStylePlain]; - [self setTitle: [path lastPathComponent]]; + self.title = path.lastPathComponent; + self.hidesHeaders = YES; [self refresh]; return self; @@ -65,10 +70,14 @@ - (void)refresh { + static const char sectionNames[28] = { '/', '#', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', + 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' }; + static const uint32_t sectionCount = sizeof(sectionNames) / sizeof(sectionNames[0]); + // Need one array per section - _list = [NSMutableArray arrayWithCapacity:28]; - for (int i = 0; i < 28; i ++) - [_list addObject:[NSMutableArray array]]; + NSMutableArray* sectionLists[sectionCount]; + for (int i = 0; i != sectionCount; i ++) + sectionLists[i] = [NSMutableArray arrayWithObject:[NSString stringWithFormat:@"%c", sectionNames[i]]]; // List contents struct string_list* contents = dir_list_new(_path.UTF8String, 0, true); @@ -86,14 +95,22 @@ uint32_t section = isalpha(basename[0]) ? (toupper(basename[0]) - 'A') + 2 : 1; section = contents->elems[i].attr.b ? 0 : section; - + RADirectoryItem* item = RADirectoryItem.new; item.path = [NSString stringWithUTF8String:contents->elems[i].data]; item.isDirectory = contents->elems[i].attr.b; - [_list[section] addObject:item]; + [sectionLists[section] addObject:item]; } dir_list_free(contents); + + // Add the sections + _sectionNames = [NSMutableArray array]; + for (int i = 0; i != sectionCount; i ++) + { + [self.sections addObject:sectionLists[i]]; + [_sectionNames addObject:sectionLists[i][0]]; + } } else [RetroArch_iOS displayErrorMessage:[NSString stringWithFormat:@"Browsed path is not a directory: %@", _path]]; @@ -103,7 +120,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - RADirectoryItem* path = _list[indexPath.section][indexPath.row]; + RADirectoryItem* path = (RADirectoryItem*)[self itemForIndexPath:indexPath]; if(path.isDirectory) [[RetroArch_iOS get] pushViewController:[RADirectoryList directoryListForPath:path.path] animated:YES]; @@ -117,19 +134,9 @@ } } -- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView -{ - return _list.count; -} - -- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section -{ - return [_list[section] count]; -} - - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - RADirectoryItem* path = _list[indexPath.section][indexPath.row]; + RADirectoryItem* path = (RADirectoryItem*)[self itemForIndexPath:indexPath]; UITableViewCell* cell = [self.tableView dequeueReusableCellWithIdentifier:@"path"]; cell = (cell != nil) ? cell : [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"path"]; @@ -141,8 +148,76 @@ - (NSArray*)sectionIndexTitlesForTableView:(UITableView*)tableView { - return [NSArray arrayWithObjects:@"/", @"#", @"A", @"B", @"C", @"D", @"E", @"F", @"G", @"H", @"I", @"J", @"K", @"L", @"M", - @"N", @"O", @"P", @"Q", @"R", @"S", @"T", @"U", @"V", @"W", @"X", @"Y", @"Z", nil]; + return _sectionNames; +} + +@end + +@implementation RAModuleList +{ + NSString* _game; +} + +- (id)initWithGame:(NSString*)path +{ + self = [super initWithStyle:UITableViewStyleGrouped]; + [self setTitle:[path lastPathComponent]]; + + _game = path; + + // Load the modules with their data + NSArray* moduleList = [RAModuleInfo getModules]; + + NSMutableArray* supported = [NSMutableArray arrayWithObject:@"Suggested Cores"]; + NSMutableArray* other = [NSMutableArray arrayWithObject:@"Other Cores"]; + + for (RAModuleInfo* i in moduleList) + { + if ([i supportsFileAtPath:_game]) [supported addObject:i]; + else [other addObject:i]; + } + + if (supported.count > 1) + [self.sections addObject:supported]; + + if (other.count > 1) + [self.sections addObject:other]; + + return self; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + [RetroArch_iOS.get runGame:_game withModule:(RAModuleInfo*)[self itemForIndexPath:indexPath]]; +} + +- (void)infoButtonTapped:(id)sender +{ + RAModuleInfo* info = objc_getAssociatedObject(sender, "MODULE"); + if (info && info.data) + [RetroArch_iOS.get pushViewController:[[RAModuleInfoList alloc] initWithModuleInfo:info] animated:YES]; + else + [RetroArch_iOS displayErrorMessage:@"No information available."]; +} + +- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + UITableViewCell* cell = [self.tableView dequeueReusableCellWithIdentifier:@"module"]; + + if (!cell) + { + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"module"]; + + UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoDark]; + [infoButton addTarget:self action:@selector(infoButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; + cell.accessoryView = infoButton; + } + + RAModuleInfo* info = (RAModuleInfo*)[self itemForIndexPath:indexPath]; + cell.textLabel.text = info.displayName; + objc_setAssociatedObject(cell.accessoryView, "MODULE", info, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + + return cell; } @end diff --git a/ios/RetroArch/browser/RAModuleList.m b/ios/RetroArch/browser/RAModuleList.m deleted file mode 100644 index ea18dac26d..0000000000 --- a/ios/RetroArch/browser/RAModuleList.m +++ /dev/null @@ -1,116 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2013 - Jason Fetters - * - * RetroArch is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with RetroArch. - * If not, see . - */ - -#import -#import "RAModuleInfo.h" -#import "browser.h" -#import "settings.h" - -@implementation RAModuleList -{ - NSMutableArray* _supported; - NSMutableArray* _other; - - NSString* _game; -} - -- (id)initWithGame:(NSString*)path -{ - self = [super initWithStyle:UITableViewStyleGrouped]; - [self setTitle:[path lastPathComponent]]; - - _game = path; - - // - NSArray* moduleList = [RAModuleInfo getModules]; - - if (moduleList.count == 0) - [RetroArch_iOS displayErrorMessage:@"No libretro cores were found."]; - - // Load the modules with their data - _supported = [NSMutableArray array]; - _other = [NSMutableArray array]; - - for (RAModuleInfo* i in moduleList) - { - NSMutableArray* target = [i supportsFileAtPath:_game] ? _supported : _other; - [target addObject:i]; - } - - // No sort, [RAModuleInfo getModules] is already sorted by display name - - return self; -} - -- (RAModuleInfo*)moduleInfoForIndexPath:(NSIndexPath*)path -{ - NSMutableArray* sectionData = (_supported.count && path.section == 0) ? _supported : _other; - return (RAModuleInfo*)sectionData[path.row]; -} - -- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView -{ - return _supported.count ? 2 : 1; -} - -- (NSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section -{ - if (_supported.count) - return (section == 0) ? @"Suggested Cores" : @"Other Cores"; - - return @"All Cores"; -} - -- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section -{ - NSMutableArray* sectionData = (_supported.count && section == 0) ? _supported : _other; - return sectionData.count; -} - -- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath -{ - [RetroArch_iOS.get runGame:_game withModule:[self moduleInfoForIndexPath:indexPath]]; -} - -- (void)infoButtonTapped:(id)sender -{ - RAModuleInfo* info = objc_getAssociatedObject(sender, "MODULE"); - if (info && info.data) - [RetroArch_iOS.get pushViewController:[[RAModuleInfoList alloc] initWithModuleInfo:info] animated:YES]; - else - [RetroArch_iOS displayErrorMessage:@"No information available."]; -} - -- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath -{ - UITableViewCell* cell = [self.tableView dequeueReusableCellWithIdentifier:@"module"]; - - if (!cell) - { - cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"module"]; - - UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoDark]; - [infoButton addTarget:self action:@selector(infoButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; - cell.accessoryView = infoButton; - } - - RAModuleInfo* info = [self moduleInfoForIndexPath:indexPath]; - cell.textLabel.text = info.displayName; - objc_setAssociatedObject(cell.accessoryView, "MODULE", info, OBJC_ASSOCIATION_RETAIN_NONATOMIC); - - return cell; -} - -@end diff --git a/ios/RetroArch/browser/browser.h b/ios/RetroArch/browser/browser.h deleted file mode 100644 index 2275554e81..0000000000 --- a/ios/RetroArch/browser/browser.h +++ /dev/null @@ -1,26 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2013 - Jason Fetters - * - * RetroArch is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with RetroArch. - * If not, see . - */ - -#include "file.h" - -@interface RADirectoryList : UITableViewController -+ (id)directoryListAtBrowseRoot; -+ (id)directoryListForPath:(NSString*)path; -- (id)initWithPath:(NSString*)path; -@end - -@interface RAModuleList : UITableViewController -- (id)initWithGame:(NSString*)path; -@end diff --git a/ios/RetroArch/main.m b/ios/RetroArch/main.m index d7bd6b4060..bd32bfc029 100644 --- a/ios/RetroArch/main.m +++ b/ios/RetroArch/main.m @@ -13,29 +13,21 @@ * If not, see . */ -#import -#include "input/ios_input.h" -#include "input/keycode.h" -#include "input/BTStack/btpad.h" -#include "libretro.h" - #include #include #include +#import "RetroArch_iOS.h" +#import "views.h" #include "rarch_wrapper.h" -#include "general.h" -#include "file.h" -#include "frontend/menu/rmenu.h" - -#import "browser/browser.h" -#import "settings/settings.h" +#include "input/ios_input.h" +#include "input/keycode.h" +#include "input/BTStack/btpad.h" #include "input/BTStack/btdynamic.h" #include "input/BTStack/btpad.h" -#define GSEVENT_TYPE_KEYDOWN 10 -#define GSEVENT_TYPE_KEYUP 11 +#include "file.h" //#define HAVE_DEBUG_FILELOG @@ -119,6 +111,9 @@ static void handle_icade_event(unsigned keycode) @implementation RApplication +#define GSEVENT_TYPE_KEYDOWN 10 +#define GSEVENT_TYPE_KEYUP 11 + - (void)sendEvent:(UIEvent *)event { [super sendEvent:event]; @@ -560,16 +555,3 @@ char* ios_get_rarch_system_directory() { return strdup([RetroArch_iOS.get.systemDirectory UTF8String]); } - - -NSString* ios_get_value_from_config(config_file_t* config, NSString* name, NSString* defaultValue) -{ - char* data = 0; - if (config) - config_get_string(config, [name UTF8String], &data); - - NSString* result = data ? [NSString stringWithUTF8String:data] : defaultValue; - free(data); - return result; -} - diff --git a/ios/RetroArch/settings/settings.m b/ios/RetroArch/settings.m similarity index 95% rename from ios/RetroArch/settings/settings.m rename to ios/RetroArch/settings.m index 2073a54f98..dccedb164d 100644 --- a/ios/RetroArch/settings/settings.m +++ b/ios/RetroArch/settings.m @@ -13,12 +13,37 @@ * If not, see . */ -#import -#import "settings.h" +#import "RetroArch_iOS.h" +#import "views.h" -#include "../input/ios_input.h" -#include "../input/keycode.h" -#include "../input/BTStack/btpad.h" +#include "input/ios_input.h" +#include "input/keycode.h" +#include "input/BTStack/btpad.h" + +enum SettingTypes +{ + BooleanSetting, ButtonSetting, EnumerationSetting, FileListSetting, + GroupSetting, AspectSetting, RangeSetting, CustomAction +}; + +@interface RASettingData : NSObject +@property enum SettingTypes type; + +@property (strong) NSString* label; +@property (strong) NSString* name; +@property (strong) NSString* value; + +@property (strong) NSString* path; +@property (strong) NSArray* subValues; +@property (strong) NSMutableArray* msubValues; + +@property double rangeMin; +@property double rangeMax; + +@property bool haveNoneOption; + +- (id)initWithType:(enum SettingTypes)aType label:(NSString*)aLabel name:(NSString*)aName; +@end @implementation RASettingData - (id)initWithType:(enum SettingTypes)aType label:(NSString*)aLabel name:(NSString*)aName @@ -30,6 +55,16 @@ } @end +// Helper view definitions +@interface RAButtonGetter : NSObject +- (id)initWithSetting:(RASettingData*)setting fromTable:(UITableView*)table; +@end + +@interface RASettingEnumerationList : UITableViewController +- (id)initWithSetting:(RASettingData*)setting fromTable:(UITableView*)table; +@end + + static RASettingData* boolean_setting(config_file_t* config, NSString* name, NSString* label, NSString* defaultValue) { RASettingData* result = [[RASettingData alloc] initWithType:BooleanSetting label:label name:name]; @@ -338,16 +373,12 @@ static RASettingData* custom_action(NSString* action, id data) @end @implementation RASettingsSubList -{ - NSArray* settings; -}; - -- (id)initWithSettings:(NSArray*)values title:(NSString*)title +- (id)initWithSettings:(NSMutableArray*)values title:(NSString*)title { self = [super initWithStyle:UITableViewStyleGrouped]; - settings = values; - [self setTitle:title]; + + self.sections = values; return self; } @@ -366,6 +397,7 @@ static RASettingData* custom_action(NSString* action, id data) if (!config) return; +#if 0 NSArray* list = settingList ? settingList : settings; for (int i = 0; i < [list count]; i++) @@ -417,11 +449,12 @@ static RASettingData* custom_action(NSString* action, id data) } } } +#endif } - (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - RASettingData* setting = [[settings objectAtIndex:indexPath.section] objectAtIndex:indexPath.row + 1]; + RASettingData* setting = (RASettingData*)[self itemForIndexPath:indexPath]; switch (setting.type) { @@ -464,7 +497,7 @@ static RASettingData* custom_action(NSString* action, id data) - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - RASettingData* setting = [[settings objectAtIndex:indexPath.section] objectAtIndex:indexPath.row + 1]; + RASettingData* setting = (RASettingData*)[self itemForIndexPath:indexPath]; UITableViewCell* cell = nil; @@ -553,22 +586,6 @@ static RASettingData* custom_action(NSString* action, id data) return cell; } -// UITableView item counts -- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView -{ - return [settings count]; -} - -- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section -{ - return [[settings objectAtIndex:section] count] -1; -} - -- (NSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section -{ - return [[settings objectAtIndex:section] objectAtIndex:0]; -} - @end @implementation RASettingEnumerationList diff --git a/ios/RetroArch/settings/settings.h b/ios/RetroArch/settings/settings.h deleted file mode 100644 index fdbaf1ba9c..0000000000 --- a/ios/RetroArch/settings/settings.h +++ /dev/null @@ -1,63 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2013 - Jason Fetters - * - * RetroArch is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with RetroArch. - * If not, see . - */ - -enum SettingTypes -{ - BooleanSetting, ButtonSetting, EnumerationSetting, FileListSetting, - GroupSetting, AspectSetting, RangeSetting, CustomAction -}; - -@interface RASettingData : NSObject -@property enum SettingTypes type; - -@property (strong) NSString* label; -@property (strong) NSString* name; -@property (strong) NSString* value; - -@property (strong) NSString* path; -@property (strong) NSArray* subValues; -@property (strong) NSMutableArray* msubValues; - -@property double rangeMin; -@property double rangeMax; - -@property bool haveNoneOption; - -- (id)initWithType:(enum SettingTypes)aType label:(NSString*)aLabel name:(NSString*)aName; -@end - -@interface RAButtonGetter : NSObject -- (id)initWithSetting:(RASettingData*)setting fromTable:(UITableView*)table; -@end - -@interface RASettingEnumerationList : UITableViewController -- (id)initWithSetting:(RASettingData*)setting fromTable:(UITableView*)table; -@end - -@interface RASettingsSubList : UITableViewController -- (id)initWithSettings:(NSArray*)values title:(NSString*)title; -- (void)handleCustomAction:(RASettingData*)setting; -- (void)writeSettings:(NSArray*)settingList toConfig:(config_file_t*)config; - -- (bool)isSettingsView; -@end - -@interface RASettingsList : RASettingsSubList -+ (void)refreshModuleConfig:(RAModuleInfo*)module; -- (id)initWithModule:(RAModuleInfo*)module; -@end - -@interface RASystemSettingsList : RASettingsSubList -@end \ No newline at end of file diff --git a/ios/RetroArch/utility.m b/ios/RetroArch/utility.m new file mode 100644 index 0000000000..8d51a5d33b --- /dev/null +++ b/ios/RetroArch/utility.m @@ -0,0 +1,60 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2013 - Jason Fetters + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#import "views.h" + +// Fetch a value from a config file, returning defaultValue if the value is not present +NSString* ios_get_value_from_config(config_file_t* config, NSString* name, NSString* defaultValue) +{ + char* data = 0; + if (config) + config_get_string(config, [name UTF8String], &data); + + NSString* result = data ? [NSString stringWithUTF8String:data] : defaultValue; + free(data); + return result; +} + +// Simple class to reduce code duplication for fixed table views +@implementation RATableViewController + +- (id)initWithStyle:(UITableViewStyle)style +{ + self = [super initWithStyle:style]; + self.sections = [NSMutableArray array]; + return self; +} + +- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView +{ + return self.sections.count; +} + +- (NSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section +{ + return self.hidesHeaders ? nil : self.sections[section][0]; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return [self.sections[section] count] - 1; +} + +- (id)itemForIndexPath:(NSIndexPath*)indexPath +{ + return self.sections[indexPath.section][indexPath.row + 1]; +} + +@end diff --git a/ios/RetroArch/views.h b/ios/RetroArch/views.h index 13a819eaf8..7cdc1a755c 100644 --- a/ios/RetroArch/views.h +++ b/ios/RetroArch/views.h @@ -13,11 +13,9 @@ * If not, see . */ -#import -#import - #import "RAModuleInfo.h" +// RAGameView.m @interface RAGameView : UIViewController + (RAGameView*)get; - (void)openPauseMenu; @@ -27,5 +25,50 @@ - (void)resume; @end +// RALogView.m @interface RALogView : UITableViewController @end + +// utility.m +@interface RATableViewController : UITableViewController +@property NSMutableArray* sections; +@property BOOL hidesHeaders; + +- (id)initWithStyle:(UITableViewStyle)style; +- (id)itemForIndexPath:(NSIndexPath*)indexPath; +@end + +// browser.m +@interface RADirectoryList : RATableViewController ++ (id)directoryListAtBrowseRoot; ++ (id)directoryListForPath:(NSString*)path; +- (id)initWithPath:(NSString*)path; +@end + +// browser.m +@interface RAModuleList : RATableViewController +- (id)initWithGame:(NSString*)path; +@end + +// RAModuleInfo.m +@interface RAModuleInfoList : RATableViewController +- (id)initWithModuleInfo:(RAModuleInfo*)info; +@end + +// settings.m +@interface RASettingsSubList : RATableViewController +- (id)initWithSettings:(NSArray*)values title:(NSString*)title; +- (void)writeSettings:(NSArray*)settingList toConfig:(config_file_t*)config; + +- (bool)isSettingsView; +@end + +// settings.m +@interface RASettingsList : RASettingsSubList ++ (void)refreshModuleConfig:(RAModuleInfo*)module; +- (id)initWithModule:(RAModuleInfo*)module; +@end + +// settings.m +@interface RASystemSettingsList : RASettingsSubList +@end