From 207aa876db988d0fd49785a97de1de35dc10a890 Mon Sep 17 00:00:00 2001 From: meancoot Date: Sun, 5 May 2013 11:47:53 -0400 Subject: [PATCH] (iOS) Refactor setting handling --- ios/RetroArch/browser/RAModuleList.m | 2 +- ios/RetroArch/main.m | 53 ++++++++++++---------------- ios/RetroArch/settings/settings.m | 9 +++-- 3 files changed, 30 insertions(+), 34 deletions(-) diff --git a/ios/RetroArch/browser/RAModuleList.m b/ios/RetroArch/browser/RAModuleList.m index 20766a9c4e..dfa104e720 100644 --- a/ios/RetroArch/browser/RAModuleList.m +++ b/ios/RetroArch/browser/RAModuleList.m @@ -85,7 +85,7 @@ - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { - [RetroArch_iOS.get pushViewController:[[RASettingsList alloc] initWithModule:[self moduleInfoForIndexPath:indexPath]] animated:YES]; + [RetroArch_iOS.get pushViewController:[[RAModuleInfoList alloc] initWithModuleInfo:[self moduleInfoForIndexPath:indexPath]] animated:YES]; } - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath diff --git a/ios/RetroArch/main.m b/ios/RetroArch/main.m index 57042e0798..06bf809fb0 100644 --- a/ios/RetroArch/main.m +++ b/ios/RetroArch/main.m @@ -42,6 +42,7 @@ static ios_input_data_t g_input_data; +static bool enable_btstack; static bool use_icade; static uint32_t icade_buttons; @@ -223,7 +224,7 @@ static void event_reload_config(void* userdata) self.system_directory = [NSString stringWithFormat:@"%@/.RetroArch", kDOCSFOLDER]; self.systemConfigPath = [NSString stringWithFormat:@"%@/.RetroArch/frontend.cfg", kDOCSFOLDER]; mkdir([self.system_directory UTF8String], 0755); - + // Setup window self.delegate = self; [self pushViewController:[RADirectoryList directoryListOrGridWithPath:kDOCSFOLDER] animated:YES]; @@ -231,6 +232,8 @@ static void event_reload_config(void* userdata) _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; _window.rootViewController = self; [_window makeKeyAndVisible]; + + [self refreshSystemConfig]; } - (void)applicationWillEnterForeground:(UIApplication *)application @@ -250,7 +253,7 @@ static void event_reload_config(void* userdata) [[UIApplication sharedApplication] setStatusBarHidden:_isGameTop withAnimation:UIStatusBarAnimationNone]; self.navigationBarHidden = _isGameTop; - self.topViewController.navigationItem.rightBarButtonItem = [self createBluetoothButton]; + self.topViewController.navigationItem.rightBarButtonItem = [self createSettingsButton]; } // UINavigationController: Never animate when pushing onto, or popping, an RAGameView @@ -308,9 +311,6 @@ static void event_reload_config(void* userdata) if (_isRunning) { _isRunning = false; - - // Stop bluetooth (might be annoying but forgetting could eat battery of device AND wiimote) - [self stopBluetooth]; // [self popToViewController:[RAGameView get] animated:NO]; @@ -335,20 +335,32 @@ static void event_reload_config(void* userdata) - (void)refreshSystemConfig { // Read load time settings - // TODO: Do this better config_file_t* conf = config_file_new([self.systemConfigPath UTF8String]); - bool autoStartBluetooth = false; - if (conf && config_get_bool(conf, "ios_auto_bluetooth", &autoStartBluetooth) && autoStartBluetooth) - [self startBluetooth]; - if (conf) + { config_get_bool(conf, "ios_use_icade", &use_icade); + config_get_bool(conf, "ios_use_btstack", &enable_btstack); + + if (enable_btstack) + [self startBluetooth]; + else + [self stopBluetooth]; + } config_file_free(conf); } #pragma mark PAUSE MENU +- (UIBarButtonItem*)createSettingsButton +{ + return [[UIBarButtonItem alloc] + initWithTitle:@"Settings" + style:UIBarButtonItemStyleBordered + target:[RetroArch_iOS get] + action:@selector(showSystemSettings)]; +} + - (IBAction)showPauseMenu:(id)sender { if (_isRunning && !_isPaused && _isGameTop) @@ -412,37 +424,16 @@ static void event_reload_config(void* userdata) } #pragma mark Bluetooth Helpers -- (UIBarButtonItem*)createBluetoothButton -{ - if (btstack_is_loaded()) - { - const bool isBTOn = btstack_is_running(); - return [[UIBarButtonItem alloc] - initWithTitle:isBTOn ? @"Stop Bluetooth" : @"Start Bluetooth" - style:UIBarButtonItemStyleBordered - target:[RetroArch_iOS get] - action:isBTOn ? @selector(stopBluetooth) : @selector(startBluetooth)]; - } - else - return nil; -} - - (IBAction)startBluetooth { if (btstack_is_loaded() && !btstack_is_running()) - { btstack_start(); - [self.topViewController.navigationItem setRightBarButtonItem:[self createBluetoothButton] animated:YES]; - } } - (IBAction)stopBluetooth { if (btstack_is_loaded()) - { btstack_stop(); - [self.topViewController.navigationItem setRightBarButtonItem:[self createBluetoothButton] animated:YES]; - } } @end diff --git a/ios/RetroArch/settings/settings.m b/ios/RetroArch/settings/settings.m index 532d0e3284..c58eeef8b6 100644 --- a/ios/RetroArch/settings/settings.m +++ b/ios/RetroArch/settings/settings.m @@ -292,8 +292,10 @@ static RASettingData* custom_action(NSString* action, id data) custom_action(@"Diagnostic Log", nil), nil], [NSArray arrayWithObjects:@"Bluetooth", + // TODO: Note that with this turned off the native bluetooth is expected to be a real keyboard boolean_setting(config, @"ios_use_icade", @"Native BT is iCade", @"false"), - boolean_setting(config, @"ios_auto_bluetooth", @"Auto Enable BTstack", @"false"), + // TODO: Make this option only if BTstack is available + boolean_setting(config, @"ios_use_btstack", @"Enable BTstack", @"false"), nil], modules, nil @@ -324,7 +326,10 @@ static RASettingData* custom_action(NSString* action, id data) if ([@"Diagnostic Log" isEqualToString:action]) [[RetroArch_iOS get] pushViewController:[RALogView new] animated:YES]; else if (data) - [[RetroArch_iOS get] pushViewController:[[RASettingsList alloc] initWithModule:(RAModuleInfo*)data] animated:YES]; + { + [RetroArch_iOS.get refreshSystemConfig]; + [RetroArch_iOS.get pushViewController:[[RASettingsList alloc] initWithModule:(RAModuleInfo*)data] animated:YES]; + } } @end