mirror of
https://github.com/CTCaer/RetroArch.git
synced 2024-12-28 21:55:27 +00:00
(iOS) Handle general options on settings menu better
This commit is contained in:
parent
e058034a24
commit
9914dff82a
@ -26,7 +26,7 @@ static NSString* get_value_from_config(RAConfig* config, NSString* name, NSStrin
|
||||
|
||||
static RASettingData* boolean_setting(RAConfig* config, NSString* name, NSString* label, NSString* defaultValue)
|
||||
{
|
||||
RASettingData* result = [[RASettingData alloc] init];
|
||||
RASettingData* result = [RASettingData new];
|
||||
result.type = BooleanSetting;
|
||||
result.label = label;
|
||||
result.name = name;
|
||||
@ -36,7 +36,7 @@ static RASettingData* boolean_setting(RAConfig* config, NSString* name, NSString
|
||||
|
||||
static RASettingData* button_setting(RAConfig* config, NSString* name, NSString* label, NSString* defaultValue)
|
||||
{
|
||||
RASettingData* result = [[RASettingData alloc] init];
|
||||
RASettingData* result = [RASettingData new];
|
||||
result.type = ButtonSetting;
|
||||
result.label = label;
|
||||
result.name = name;
|
||||
@ -49,7 +49,7 @@ static RASettingData* button_setting(RAConfig* config, NSString* name, NSString*
|
||||
|
||||
static RASettingData* group_setting(NSString* label, NSArray* settings)
|
||||
{
|
||||
RASettingData* result = [[RASettingData alloc] init];
|
||||
RASettingData* result = [RASettingData new];
|
||||
result.type = GroupSetting;
|
||||
result.label = label;
|
||||
result.subValues = settings;
|
||||
@ -58,7 +58,7 @@ static RASettingData* group_setting(NSString* label, NSArray* settings)
|
||||
|
||||
static RASettingData* enumeration_setting(RAConfig* config, NSString* name, NSString* label, NSString* defaultValue, NSArray* values)
|
||||
{
|
||||
RASettingData* result = [[RASettingData alloc] init];
|
||||
RASettingData* result = [RASettingData new];
|
||||
result.type = EnumerationSetting;
|
||||
result.label = label;
|
||||
result.name = name;
|
||||
@ -75,7 +75,7 @@ static RASettingData* subpath_setting(RAConfig* config, NSString* name, NSString
|
||||
NSArray* values = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:path error:nil];
|
||||
values = [values pathsMatchingExtensions:[NSArray arrayWithObject:extension]];
|
||||
|
||||
RASettingData* result = [[RASettingData alloc] init];
|
||||
RASettingData* result = [RASettingData new];
|
||||
result.type = FileListSetting;
|
||||
result.label = label;
|
||||
result.name = name;
|
||||
@ -85,6 +85,14 @@ static RASettingData* subpath_setting(RAConfig* config, NSString* name, NSString
|
||||
return result;
|
||||
}
|
||||
|
||||
static RASettingData* custom_action(NSString* action)
|
||||
{
|
||||
RASettingData* result = [RASettingData new];
|
||||
result.type = CustomAction;
|
||||
result.label = action;
|
||||
return result;
|
||||
}
|
||||
|
||||
@implementation RASettingsList
|
||||
+ (void)refreshConfigFile
|
||||
{
|
||||
@ -99,6 +107,13 @@ static RASettingData* subpath_setting(RAConfig* config, NSString* name, NSString
|
||||
NSString* shader_path = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/shaders/"];
|
||||
|
||||
NSArray* settings = [NSArray arrayWithObjects:
|
||||
[NSArray arrayWithObjects:@"General",
|
||||
custom_action(@"Module Info"),
|
||||
#ifdef WIIMOTE
|
||||
custom_action(@"Connect WiiMotes");
|
||||
#endif
|
||||
nil],
|
||||
|
||||
[NSArray arrayWithObjects:@"Video",
|
||||
boolean_setting(config, @"video_smooth", @"Smooth Video", @"true"),
|
||||
boolean_setting(config, @"video_crop_overscan", @"Crop Overscan", @"true"),
|
||||
@ -171,6 +186,15 @@ static RASettingData* subpath_setting(RAConfig* config, NSString* name, NSString
|
||||
[self writeToDisk];
|
||||
}
|
||||
|
||||
- (void)handleCustomAction:(NSString*)action
|
||||
{
|
||||
if ([@"Module Info" isEqualToString:action])
|
||||
[[RetroArch_iOS get] pushViewController:[[RAModuleInfoList alloc] initWithModuleInfo:[RetroArch_iOS get].moduleInfo] isGame:NO];
|
||||
else if([@"Connect WiiMotes" isEqualToString:action])
|
||||
[[RetroArch_iOS get] showWiiRemoteConfig];
|
||||
}
|
||||
|
||||
|
||||
- (void)writeToDisk
|
||||
{
|
||||
RAConfig* config = [[RAConfig alloc] initWithPath:[RetroArch_iOS get].moduleInfo.configPath];
|
||||
@ -181,57 +205,4 @@ static RASettingData* subpath_setting(RAConfig* config, NSString* name, NSString
|
||||
[config writeToFile:[RetroArch_iOS get].moduleInfo.configPath];
|
||||
}
|
||||
|
||||
// Override tableView methods to add General section at top.
|
||||
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
if (indexPath.section == 0)
|
||||
{
|
||||
if (indexPath.row == 0)
|
||||
[[RetroArch_iOS get] pushViewController:[[RAModuleInfoList alloc] initWithModuleInfo:[RetroArch_iOS get].moduleInfo] isGame:NO];
|
||||
else if(indexPath.row == 1)
|
||||
[[RetroArch_iOS get] showWiiRemoteConfig];
|
||||
}
|
||||
else
|
||||
[super tableView:tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section - 1]];
|
||||
}
|
||||
|
||||
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
if (indexPath.section == 0)
|
||||
{
|
||||
UITableViewCell* cell = [self.tableView dequeueReusableCellWithIdentifier:@"general"];
|
||||
cell = cell ? cell : [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"general"];
|
||||
|
||||
cell.textLabel.text = (indexPath.row == 0) ? @"Module Info" : @"Connect WiiMotes";
|
||||
return cell;
|
||||
}
|
||||
else
|
||||
return [super tableView:tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section - 1]];
|
||||
}
|
||||
|
||||
- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView
|
||||
{
|
||||
return [super numberOfSectionsInTableView:tableView] + 1;
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
|
||||
{
|
||||
if (section == 0)
|
||||
#ifdef WIIMOTE
|
||||
return 2;
|
||||
#else
|
||||
return 1;
|
||||
#endif
|
||||
|
||||
return [super tableView:tableView numberOfRowsInSection:section - 1] ;
|
||||
}
|
||||
|
||||
- (NSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section
|
||||
{
|
||||
if (section == 0)
|
||||
return @"General";
|
||||
|
||||
return [super tableView:tableView titleForHeaderInSection:section - 1];
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -32,6 +32,11 @@ static const char* const SETTINGID = "SETTING";
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleCustomAction:(NSString*)action
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
- (void)writeSettings:(NSArray*)settingList toConfig:(RAConfig*)config
|
||||
{
|
||||
NSArray* list = settingList ? settingList : settings;
|
||||
@ -45,7 +50,7 @@ static const char* const SETTINGID = "SETTING";
|
||||
RASettingData* setting = [group objectAtIndex:j];
|
||||
|
||||
switch (setting.type)
|
||||
{
|
||||
{
|
||||
case GroupSetting:
|
||||
[self writeSettings:setting.subValues toConfig:config];
|
||||
break;
|
||||
@ -64,6 +69,9 @@ static const char* const SETTINGID = "SETTING";
|
||||
[config putStringNamed:[setting.name stringByAppendingString:@"_btn"] value:setting.msubValues[1]];
|
||||
break;
|
||||
|
||||
case CustomAction:
|
||||
break;
|
||||
|
||||
default:
|
||||
[config putStringNamed:setting.name value:setting.value];
|
||||
break;
|
||||
@ -91,12 +99,16 @@ static const char* const SETTINGID = "SETTING";
|
||||
[[RetroArch_iOS get] pushViewController:[[RASettingsSubList alloc] initWithSettings:setting.subValues title:setting.label] isGame:NO];
|
||||
break;
|
||||
|
||||
case CustomAction:
|
||||
[self handleCustomAction:setting.label];
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)handle_boolean_switch:(UISwitch*)swt
|
||||
- (void)handleBooleanSwitch:(UISwitch*)swt
|
||||
{
|
||||
RASettingData* setting = objc_getAssociatedObject(swt, SETTINGID);
|
||||
setting.value = (swt.on ? @"true" : @"false");
|
||||
@ -119,7 +131,7 @@ static const char* const SETTINGID = "SETTING";
|
||||
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"boolean"];
|
||||
|
||||
UISwitch* accessory = [[UISwitch alloc] init];
|
||||
[accessory addTarget:self action:@selector(handle_boolean_switch:) forControlEvents:UIControlEventValueChanged];
|
||||
[accessory addTarget:self action:@selector(handleBooleanSwitch:) forControlEvents:UIControlEventValueChanged];
|
||||
cell.accessoryView = accessory;
|
||||
|
||||
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
|
||||
@ -134,6 +146,7 @@ static const char* const SETTINGID = "SETTING";
|
||||
case EnumerationSetting:
|
||||
case FileListSetting:
|
||||
case ButtonSetting:
|
||||
case CustomAction:
|
||||
{
|
||||
cell = [self.tableView dequeueReusableCellWithIdentifier:@"enumeration"];
|
||||
cell = cell ? cell : [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"enumeration"];
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
enum SettingTypes
|
||||
{
|
||||
BooleanSetting, ButtonSetting, EnumerationSetting, FileListSetting, GroupSetting
|
||||
BooleanSetting, ButtonSetting, EnumerationSetting, FileListSetting, GroupSetting, CustomAction
|
||||
};
|
||||
|
||||
@interface RASettingData : NSObject
|
||||
@ -40,6 +40,7 @@ enum SettingTypes
|
||||
|
||||
@interface RASettingsSubList : UITableViewController
|
||||
- (id)initWithSettings:(NSArray*)values title:(NSString*)title;
|
||||
- (void)handleCustomAction:(NSString*)action;
|
||||
- (void)writeSettings:(NSArray*)settingList toConfig:(RAConfig*)config;
|
||||
@end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user