(iOS) Add an enumeration type setting and use it for selecting screen orientations and bluetooth mode

This commit is contained in:
meancoot 2013-12-03 19:46:30 -05:00
parent 8882d07f3f
commit 96c9357273
4 changed files with 84 additions and 45 deletions

View File

@ -84,6 +84,14 @@
/*********************************************/
@interface RAMenuItemPathSetting : RAMenuItemGeneralSetting<RAMenuItemBase> @end
/*********************************************/
/* RAMenuItemEnumSetting */
/* A menu item that displays and allows */
/* a setting to be set from a list of */
/* allowed choices. */
/*********************************************/
@interface RAMenuItemEnumSetting : RAMenuItemGeneralSetting<RAMenuItemBase> @end
/*********************************************/
/* RAMenuItemBindSetting */
/* A menu item that displays and allows */

View File

@ -136,6 +136,9 @@
default: break;
}
if (setting->type == ST_STRING && setting->values)
return [[RAMenuItemEnumSetting alloc] initWithSetting:setting];
RAMenuItemGeneralSetting* item = [[RAMenuItemGeneralSetting alloc] initWithSetting:setting];
if (item.setting->type == ST_INT || item.setting->type == ST_UINT || item.setting->type == ST_FLOAT)
@ -286,6 +289,51 @@
@end
/*********************************************/
/* RAMenuItemEnumSetting */
/* A menu item that displays and allows */
/* a setting to be set from a list of */
/* allowed choices. */
/*********************************************/
@interface RAMenuItemEnumSetting() <UIActionSheetDelegate>
@property (nonatomic) UIActionSheet* actionSheet;
@end
@implementation RAMenuItemEnumSetting
- (void)wasSelectedOnTableView:(UITableView*)tableView ofController:(UIViewController*)controller
{
struct string_list* options = string_split(self.setting->values, "|");
self.actionSheet = [UIActionSheet new];
self.actionSheet.title = @(self.setting->short_description);
self.actionSheet.delegate = self;
for (int i = 0; i < options->size; i ++)
{
[self.actionSheet addButtonWithTitle:@(options->elems[i].data)];
}
self.actionSheet.cancelButtonIndex = [self.actionSheet addButtonWithTitle:@"Cancel"];
[self.actionSheet showInView:self.parentTable];
string_list_free(options);
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex != actionSheet.cancelButtonIndex)
{
setting_data_set_with_string_representation(self.setting, [actionSheet buttonTitleAtIndex:buttonIndex].UTF8String);
[self.parentTable reloadData];
}
self.actionSheet = nil;
}
@end
/*********************************************/
/* RAMenuItemBindSetting */
/* A menu item that displays and allows */
@ -604,6 +652,8 @@ static const void* const associated_core_key = &associated_core_key;
if ((self = [super initWithGroup:frontend_setting_data]))
{
[[RetroArch_iOS get] refreshSystemConfig];
RAFrontendSettingsMenu* __weak weakSelf = self;
self.title = @"Frontend Settings";

View File

@ -22,22 +22,18 @@
typedef struct
{
bool portrait;
bool portrait_upside_down;
bool landscape_left;
bool landscape_right;
char orientations[32];
bool logging_enabled;
bool logging_enabled;
char bluetooth_mode[64];
char bluetooth_mode[64];
struct
{
int stdout;
int stderr;
struct
{
int stdout;
int stderr;
FILE* file;
} logging;
FILE* file;
} logging;
} apple_frontend_settings_t;
extern apple_frontend_settings_t apple_frontend_settings;

View File

@ -57,33 +57,24 @@ void ios_set_bluetooth_mode(NSString* mode)
const void* apple_get_frontend_settings(void)
{
static rarch_setting_t settings[16];
static rarch_setting_t settings[8];
if (settings[0].type == ST_NONE)
{
settings[0] = setting_data_group_setting(ST_GROUP, "Frontend Settings");
settings[1] = setting_data_group_setting(ST_SUB_GROUP, "Frontend");
settings[2] = setting_data_bool_setting("ios_use_file_log", "Enable File Logging",
settings[0] = setting_data_group_setting(ST_GROUP, "Frontend Settings");
settings[1] = setting_data_group_setting(ST_SUB_GROUP, "Frontend");
settings[2] = setting_data_bool_setting("ios_use_file_log", "Enable File Logging",
&apple_frontend_settings.logging_enabled, false);
settings[3] = setting_data_bool_setting("ios_tv_mode", "TV Mode", &apple_use_tv_mode, false);
settings[4] = setting_data_group_setting(ST_END_SUB_GROUP, 0);
settings[5] = setting_data_group_setting(ST_SUB_GROUP, "Bluetooth");
settings[6] = setting_data_string_setting(ST_STRING, "ios_btmode", "Mode", apple_frontend_settings.bluetooth_mode,
settings[3] = setting_data_bool_setting("ios_tv_mode", "TV Mode", &apple_use_tv_mode, false);
settings[4] = setting_data_string_setting(ST_STRING, "ios_btmode", "Bluetooth Input Type", apple_frontend_settings.bluetooth_mode,
sizeof(apple_frontend_settings.bluetooth_mode), "keyboard");
settings[7] = setting_data_group_setting(ST_END_SUB_GROUP, 0);
settings[4].values = "icade|keyboard|btstack";
settings[5] = setting_data_string_setting(ST_STRING, "ios_orientations", "Screen Orientations", apple_frontend_settings.orientations,
sizeof(apple_frontend_settings.orientations), "both");
settings[5].values = "both|landscape|portrait";
settings[6] = setting_data_group_setting(ST_END_SUB_GROUP, 0);
settings[8] = setting_data_group_setting(ST_SUB_GROUP, "Orientations");
settings[9] = setting_data_bool_setting("ios_allow_portrait", "Portrait",
&apple_frontend_settings.portrait, true);
settings[10] = setting_data_bool_setting("ios_allow_portrait_upside_down", "Portrait Upside Down",
&apple_frontend_settings.portrait_upside_down, true);
settings[11] = setting_data_bool_setting("ios_allow_landscape_left", "Landscape Left",
&apple_frontend_settings.landscape_left, true);
settings[12] = setting_data_bool_setting("ios_allow_landscape_right", "Landscape Right",
&apple_frontend_settings.landscape_right, true);
settings[13] = setting_data_group_setting(ST_END_SUB_GROUP, 0);
settings[14] = setting_data_group_setting(ST_END_GROUP, 0);
settings[7] = setting_data_group_setting(ST_END_GROUP, 0);
}
return settings;
@ -339,18 +330,12 @@ static void handle_touch_event(NSArray* touches)
setting_data_load_config_path(frontend_settings, self.systemConfigPath.UTF8String);
// Get enabled orientations
static const struct { const bool* value; uint32_t orientation; } orientationSettings[4] =
{
{ &apple_frontend_settings.portrait, UIInterfaceOrientationMaskPortrait },
{ &apple_frontend_settings.portrait_upside_down, UIInterfaceOrientationMaskPortraitUpsideDown },
{ &apple_frontend_settings.landscape_left, UIInterfaceOrientationMaskLandscapeLeft },
{ &apple_frontend_settings.landscape_right, UIInterfaceOrientationMaskLandscapeRight }
};
_enabledOrientations = UIInterfaceOrientationMaskAll;
_enabledOrientations = 0;
for (int i = 0; i < 4; i ++)
_enabledOrientations |= (*orientationSettings[i].value) ? orientationSettings[i].orientation : 0;
if (strcmp(apple_frontend_settings.orientations, "landscape") == 0)
_enabledOrientations = UIInterfaceOrientationMaskLandscape;
else if (strcmp(apple_frontend_settings.orientations, "portrait") == 0)
_enabledOrientations = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
// Set bluetooth mode
ios_set_bluetooth_mode(@(apple_frontend_settings.bluetooth_mode));