(iOS) Some much needed code cleanup

This commit is contained in:
meancoot 2013-06-14 00:45:35 -04:00
parent c3f1af7890
commit 65fb256b90
15 changed files with 314 additions and 360 deletions

View File

@ -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 = "<group>"; };
96297A0E16C5AEA100E6DCE0 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
96297A2616C82FF100E6DCE0 /* overlays */ = {isa = PBXFileReference; lastKnownFileType = folder; name = overlays; path = ../../media/overlays; sourceTree = "<group>"; };
96337E81176AC6E5004685F3 /* utility.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = utility.m; sourceTree = "<group>"; };
96337E83176AD5D9004685F3 /* browser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = browser.m; sourceTree = "<group>"; };
96337E85176AD6B6004685F3 /* settings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = settings.m; sourceTree = "<group>"; };
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 = "<group>"; };
963F5AC516CC523B009BBD19 /* RAGameView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RAGameView.m; sourceTree = "<group>"; };
966B9CA916E41C07005B61E1 /* browser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = browser.h; sourceTree = "<group>"; };
966B9CAA16E41C07005B61E1 /* browser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = browser.m; sourceTree = "<group>"; };
966B9CAD16E41C07005B61E1 /* RAModuleList.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RAModuleList.m; sourceTree = "<group>"; };
966B9CB816E41E7A005B61E1 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = "<group>"; };
966B9CB916E41E7A005B61E1 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = "<group>"; };
966B9CBA16E41E7A005B61E1 /* Default@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default@2x.png"; sourceTree = "<group>"; };
@ -79,7 +78,6 @@
96C19C2616D455BE00FE8D5A /* rarch_wrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rarch_wrapper.h; sourceTree = "<group>"; };
96F9C28216FFA55F002455B3 /* RALogView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RALogView.m; sourceTree = "<group>"; };
D48581DD16F823F9004BEB17 /* griffin.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = griffin.c; path = ../griffin/griffin.c; sourceTree = "<group>"; };
D486CA87170D4EAF004DC638 /* settings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = settings.m; sourceTree = "<group>"; };
/* 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 = "<group>";
};
966B9CA816E41C07005B61E1 /* browser */ = {
isa = PBXGroup;
children = (
966B9CA916E41C07005B61E1 /* browser.h */,
966B9CAA16E41C07005B61E1 /* browser.m */,
966B9CAD16E41C07005B61E1 /* RAModuleList.m */,
);
path = browser;
sourceTree = "<group>";
};
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;
};

View File

@ -13,10 +13,13 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#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;

View File

@ -17,6 +17,8 @@
#include <stdio.h>
#include <pthread.h>
#import "views.h"
static NSMutableArray* g_messages;
static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER;

View File

@ -26,6 +26,3 @@
- (bool)supportsFileAtPath:(NSString*)path;
@end
@interface RAModuleInfoList : UITableViewController
- (id)initWithModuleInfo:(RAModuleInfo*)info;
@end

View File

@ -14,8 +14,12 @@
*/
#include <glob.h>
#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];

View File

@ -25,7 +25,8 @@
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <GLKit/GLKit.h>
#import <Foundation/Foundation.h>
#import "views.h"
#import "RetroArch_iOS.h"
#import <objc/runtime.h>
#endif

View File

@ -13,7 +13,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#import <UIKit/UIKit.h>
#import "RAModuleInfo.h"
@interface RetroArch_iOS : UINavigationController<UIApplicationDelegate, UINavigationControllerDelegate>
@ -35,4 +35,5 @@
@end
// utility.m
extern NSString* ios_get_value_from_config(config_file_t* config, NSString* name, NSString* defaultValue);

View File

@ -15,8 +15,12 @@
#include <dirent.h>
#include <sys/stat.h>
#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

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#import <objc/runtime.h>
#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

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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

View File

@ -13,29 +13,21 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#import <UIKit/UIKit.h>
#include "input/ios_input.h"
#include "input/keycode.h"
#include "input/BTStack/btpad.h"
#include "libretro.h"
#include <sys/stat.h>
#include <pthread.h>
#include <string.h>
#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;
}

View File

@ -13,12 +13,37 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#import <objc/runtime.h>
#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<UIAlertViewDelegate>
- (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

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<UIAlertViewDelegate>
- (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

60
ios/RetroArch/utility.m Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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

View File

@ -13,11 +13,9 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#import <UIKit/UIKit.h>
#import <GLKit/GLKit.h>
#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