mirror of
https://github.com/libretro/RetroArch
synced 2025-02-21 18:40:09 +00:00
(iOS) Simplify RAMenu item creation
This commit is contained in:
parent
fae4b05440
commit
dd45169063
@ -60,7 +60,6 @@
|
|||||||
@property (nonatomic) rarch_setting_t* setting;
|
@property (nonatomic) rarch_setting_t* setting;
|
||||||
@property (copy) void (^action)();
|
@property (copy) void (^action)();
|
||||||
@property (nonatomic, weak) UITableView* parentTable;
|
@property (nonatomic, weak) UITableView* parentTable;
|
||||||
+ (id)itemForSetting:(rarch_setting_t*)setting action:(void (^)())action;
|
|
||||||
- (id)initWithSetting:(rarch_setting_t*)setting action:(void (^)())action;
|
- (id)initWithSetting:(rarch_setting_t*)setting action:(void (^)())action;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@ -135,45 +134,45 @@
|
|||||||
@implementation RANumberFormatter
|
@implementation RANumberFormatter
|
||||||
- (id)initWithSetting:(const rarch_setting_t*)setting
|
- (id)initWithSetting:(const rarch_setting_t*)setting
|
||||||
{
|
{
|
||||||
if ((self = [super init]))
|
if ((self = [super init]))
|
||||||
{
|
{
|
||||||
[self setAllowsFloats:(setting->type == ST_FLOAT)];
|
[self setAllowsFloats:(setting->type == ST_FLOAT)];
|
||||||
|
|
||||||
if (setting->flags & SD_FLAG_HAS_RANGE)
|
if (setting->flags & SD_FLAG_HAS_RANGE)
|
||||||
{
|
{
|
||||||
[self setMinimum:BOXFLOAT(setting->min)];
|
[self setMinimum:BOXFLOAT(setting->min)];
|
||||||
[self setMaximum:BOXFLOAT(setting->max)];
|
[self setMaximum:BOXFLOAT(setting->max)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)isPartialStringValid:(NSString*)partialString newEditingString:(NSString**)newString errorDescription:(NSString**)error
|
- (BOOL)isPartialStringValid:(NSString*)partialString newEditingString:(NSString**)newString errorDescription:(NSString**)error
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
bool hasDot = false;
|
bool hasDot = false;
|
||||||
|
|
||||||
if (partialString.length)
|
if (partialString.length)
|
||||||
for (i = 0; i < partialString.length; i ++)
|
for (i = 0; i < partialString.length; i ++)
|
||||||
{
|
{
|
||||||
unichar ch = [partialString characterAtIndex:i];
|
unichar ch = [partialString characterAtIndex:i];
|
||||||
|
|
||||||
if (i == 0 && (!self.minimum || self.minimum.intValue < 0) && ch == '-')
|
if (i == 0 && (!self.minimum || self.minimum.intValue < 0) && ch == '-')
|
||||||
continue;
|
continue;
|
||||||
else if (self.allowsFloats && !hasDot && ch == '.')
|
else if (self.allowsFloats && !hasDot && ch == '.')
|
||||||
hasDot = true;
|
hasDot = true;
|
||||||
else if (!isdigit(ch))
|
else if (!isdigit(ch))
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
|
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
|
||||||
{
|
{
|
||||||
NSString* text = (NSString*)[[textField text] stringByReplacingCharactersInRange:range withString:string];
|
NSString* text = (NSString*)[[textField text] stringByReplacingCharactersInRange:range withString:string];
|
||||||
return [self isPartialStringValid:text newEditingString:nil errorDescription:nil];
|
return [self isPartialStringValid:text newEditingString:nil errorDescription:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@ -214,16 +213,17 @@ static void RunActionSheet(const char* title, const struct string_list* items, U
|
|||||||
size_t i;
|
size_t i;
|
||||||
RARunActionSheetDelegate* delegate = [[RARunActionSheetDelegate alloc] initWithCallbackBlock:callback];
|
RARunActionSheetDelegate* delegate = [[RARunActionSheetDelegate alloc] initWithCallbackBlock:callback];
|
||||||
UIActionSheet* actionSheet = [UIActionSheet new];
|
UIActionSheet* actionSheet = [UIActionSheet new];
|
||||||
actionSheet.title = BOXSTRING(title);
|
|
||||||
actionSheet.delegate = delegate;
|
|
||||||
|
|
||||||
|
actionSheet.title = BOXSTRING(title);
|
||||||
|
actionSheet.delegate = delegate;
|
||||||
|
|
||||||
for (i = 0; i < items->size; i ++)
|
for (i = 0; i < items->size; i ++)
|
||||||
[actionSheet addButtonWithTitle:BOXSTRING(items->elems[i].data)];
|
[actionSheet addButtonWithTitle:BOXSTRING(items->elems[i].data)];
|
||||||
|
|
||||||
actionSheet.cancelButtonIndex = [actionSheet addButtonWithTitle:BOXSTRING("Cancel")];
|
actionSheet.cancelButtonIndex = [actionSheet addButtonWithTitle:BOXSTRING("Cancel")];
|
||||||
|
|
||||||
objc_setAssociatedObject(actionSheet, associated_delegate_key, delegate, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
objc_setAssociatedObject(actionSheet, associated_delegate_key, delegate, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||||
|
|
||||||
[actionSheet showInView:parent];
|
[actionSheet showInView:parent];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,7 +250,7 @@ static void RunActionSheet(const char* title, const struct string_list* items, U
|
|||||||
- (NSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section
|
- (NSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section
|
||||||
{
|
{
|
||||||
if (self.hidesHeaders)
|
if (self.hidesHeaders)
|
||||||
return nil;
|
return nil;
|
||||||
return self.sections[section][0];
|
return self.sections[section][0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,7 +276,7 @@ static void RunActionSheet(const char* title, const struct string_list* items, U
|
|||||||
|
|
||||||
- (void)willReloadData
|
- (void)willReloadData
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)reloadData
|
- (void)reloadData
|
||||||
@ -312,23 +312,23 @@ static void RunActionSheet(const char* title, const struct string_list* items, U
|
|||||||
+ (RAMenuItemBasic*)itemWithDescription:(NSString*)description association:(id)userdata action:(void (^)())action detail:(NSString* (^)())detail
|
+ (RAMenuItemBasic*)itemWithDescription:(NSString*)description association:(id)userdata action:(void (^)())action detail:(NSString* (^)())detail
|
||||||
{
|
{
|
||||||
RAMenuItemBasic* item = [RAMenuItemBasic new];
|
RAMenuItemBasic* item = [RAMenuItemBasic new];
|
||||||
item.description = description;
|
item.description = description;
|
||||||
item.userdata = userdata;
|
item.userdata = userdata;
|
||||||
item.action = action;
|
item.action = action;
|
||||||
item.detail = detail;
|
item.detail = detail;
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (UITableViewCell*)cellForTableView:(UITableView*)tableView
|
- (UITableViewCell*)cellForTableView:(UITableView*)tableView
|
||||||
{
|
{
|
||||||
static NSString* const cell_id = @"text";
|
static NSString* const cell_id = @"text";
|
||||||
|
|
||||||
UITableViewCell* result = [tableView dequeueReusableCellWithIdentifier:cell_id];
|
UITableViewCell* result = [tableView dequeueReusableCellWithIdentifier:cell_id];
|
||||||
if (!result)
|
if (!result)
|
||||||
result = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cell_id];
|
result = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cell_id];
|
||||||
|
|
||||||
result.selectionStyle = UITableViewCellSelectionStyleNone;
|
result.selectionStyle = UITableViewCellSelectionStyleNone;
|
||||||
result.textLabel.text = self.description;
|
result.textLabel.text = self.description;
|
||||||
result.detailTextLabel.text = self.detail ? self.detail(self.userdata) : nil;
|
result.detailTextLabel.text = self.detail ? self.detail(self.userdata) : nil;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -341,27 +341,6 @@ static void RunActionSheet(const char* title, const struct string_list* items, U
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
MENU_ITEM_BASIC = 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct ios_menu_item
|
|
||||||
{
|
|
||||||
char description[PATH_MAX_LENGTH];
|
|
||||||
} ios_menu_item_t;
|
|
||||||
|
|
||||||
static void *menu_item_init(ios_menu_item_t *item, unsigned type)
|
|
||||||
{
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case MENU_ITEM_BASIC:
|
|
||||||
return (__bridge void*)[RAMenuItemBasic itemWithDescription:BOXSTRING(item->description) action:^{}];
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*********************************************/
|
/*********************************************/
|
||||||
/* RAMenuItemGeneralSetting */
|
/* RAMenuItemGeneralSetting */
|
||||||
/* A simple menu item that displays the */
|
/* A simple menu item that displays the */
|
||||||
@ -374,58 +353,13 @@ static void *menu_item_init(ios_menu_item_t *item, unsigned type)
|
|||||||
|
|
||||||
@implementation RAMenuItemGeneralSetting
|
@implementation RAMenuItemGeneralSetting
|
||||||
|
|
||||||
+ (id)itemForSetting:(rarch_setting_t*)setting action:(void (^)())action
|
|
||||||
{
|
|
||||||
ios_menu_item_t menu_item;
|
|
||||||
|
|
||||||
switch (setting->type)
|
|
||||||
{
|
|
||||||
case ST_NONE:
|
|
||||||
case ST_ACTION:
|
|
||||||
strlcpy(menu_item.description, "Shouldn't be called with ST_NONE or ST_ACTION", sizeof(menu_item.description));
|
|
||||||
return (__bridge RAMenuItemBasic*)menu_item_init(&menu_item, MENU_ITEM_BASIC);
|
|
||||||
case ST_BOOL:
|
|
||||||
return [[RAMenuItemBooleanSetting alloc] initWithSetting:setting action:action];
|
|
||||||
case ST_INT:
|
|
||||||
case ST_UINT:
|
|
||||||
case ST_FLOAT:
|
|
||||||
break;
|
|
||||||
case ST_PATH:
|
|
||||||
case ST_DIR:
|
|
||||||
return [[RAMenuItemPathSetting alloc] initWithSetting:setting action:action];
|
|
||||||
case ST_STRING:
|
|
||||||
case ST_HEX:
|
|
||||||
break;
|
|
||||||
case ST_BIND:
|
|
||||||
return [[RAMenuItemBindSetting alloc] initWithSetting:setting action:action];
|
|
||||||
case ST_GROUP:
|
|
||||||
case ST_SUB_GROUP:
|
|
||||||
case ST_END_GROUP:
|
|
||||||
case ST_END_SUB_GROUP:
|
|
||||||
default:
|
|
||||||
strlcpy(menu_item.description, "Shouldn't be called with ST_GROUP", sizeof(menu_item.description));
|
|
||||||
return (__bridge RAMenuItemBasic*)menu_item_init(&menu_item, MENU_ITEM_BASIC);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setting_is_of_enum_type(setting))
|
|
||||||
return [[RAMenuItemEnumSetting alloc] initWithSetting:setting action:action];
|
|
||||||
|
|
||||||
RAMenuItemGeneralSetting* item = [[RAMenuItemGeneralSetting alloc] initWithSetting:setting action:action];
|
|
||||||
|
|
||||||
if (setting_is_of_numeric_type(item.setting))
|
|
||||||
item.formatter = [[RANumberFormatter alloc] initWithSetting:item.setting];
|
|
||||||
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id)initWithSetting:(rarch_setting_t*)setting action:(void (^)())action
|
- (id)initWithSetting:(rarch_setting_t*)setting action:(void (^)())action
|
||||||
{
|
{
|
||||||
if ((self = [super init]))
|
if ((self = [super init])) {
|
||||||
{
|
_setting = setting;
|
||||||
_setting = setting;
|
_action = action;
|
||||||
_action = action;
|
}
|
||||||
}
|
return self;
|
||||||
return self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (UITableViewCell*)cellForTableView:(UITableView*)tableView
|
- (UITableViewCell*)cellForTableView:(UITableView*)tableView
|
||||||
@ -433,7 +367,6 @@ static void *menu_item_init(ios_menu_item_t *item, unsigned type)
|
|||||||
char buffer[PATH_MAX_LENGTH];
|
char buffer[PATH_MAX_LENGTH];
|
||||||
UITableViewCell* result;
|
UITableViewCell* result;
|
||||||
static NSString* const cell_id = @"string_setting";
|
static NSString* const cell_id = @"string_setting";
|
||||||
rarch_setting_t *setting = self.setting;
|
|
||||||
|
|
||||||
self.parentTable = tableView;
|
self.parentTable = tableView;
|
||||||
|
|
||||||
@ -443,23 +376,23 @@ static void *menu_item_init(ios_menu_item_t *item, unsigned type)
|
|||||||
result = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cell_id];
|
result = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cell_id];
|
||||||
result.selectionStyle = UITableViewCellSelectionStyleNone;
|
result.selectionStyle = UITableViewCellSelectionStyleNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
[self attachDefaultingGestureTo:result];
|
[self attachDefaultingGestureTo:result];
|
||||||
|
|
||||||
result.textLabel.text = BOXSTRING("<Uninitialized>");
|
result.textLabel.text = BOXSTRING("<Uninitialized>");
|
||||||
|
|
||||||
if (setting)
|
if (self.setting)
|
||||||
{
|
{
|
||||||
if (setting->short_description)
|
if (self.setting->short_description)
|
||||||
result.textLabel.text = BOXSTRING(setting->short_description);
|
result.textLabel.text = BOXSTRING(self.setting->short_description);
|
||||||
|
|
||||||
setting_get_string_representation(setting, buffer, sizeof(buffer));
|
setting_get_string_representation(self.setting, buffer, sizeof(buffer));
|
||||||
if (buffer[0] == '\0')
|
if (buffer[0] == '\0')
|
||||||
strlcpy(buffer, "<default>", sizeof(buffer));
|
strlcpy(buffer, "<default>", sizeof(buffer));
|
||||||
|
|
||||||
result.detailTextLabel.text = BOXSTRING(buffer);
|
result.detailTextLabel.text = BOXSTRING(buffer);
|
||||||
|
|
||||||
if (setting->type == ST_PATH)
|
if (self.setting->type == ST_PATH)
|
||||||
result.detailTextLabel.text = [result.detailTextLabel.text lastPathComponent];
|
result.detailTextLabel.text = [result.detailTextLabel.text lastPathComponent];
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@ -471,19 +404,18 @@ static void *menu_item_init(ios_menu_item_t *item, unsigned type)
|
|||||||
NSString *desc = BOXSTRING("N/A");
|
NSString *desc = BOXSTRING("N/A");
|
||||||
UIAlertView *alertView;
|
UIAlertView *alertView;
|
||||||
UITextField *field;
|
UITextField *field;
|
||||||
rarch_setting_t *setting = self.setting;
|
|
||||||
|
if (self.setting && self.setting->short_description)
|
||||||
if (setting && setting->short_description)
|
desc = BOXSTRING(self.setting->short_description);
|
||||||
desc = BOXSTRING(setting->short_description);
|
|
||||||
|
|
||||||
alertView = [[UIAlertView alloc] initWithTitle:BOXSTRING("Enter new value") message:desc delegate:self cancelButtonTitle:BOXSTRING("Cancel") otherButtonTitles:BOXSTRING("OK"), nil];
|
alertView = [[UIAlertView alloc] initWithTitle:BOXSTRING("Enter new value") message:desc delegate:self cancelButtonTitle:BOXSTRING("Cancel") otherButtonTitles:BOXSTRING("OK"), nil];
|
||||||
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
|
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
|
||||||
|
|
||||||
field = [alertView textFieldAtIndex:0];
|
field = [alertView textFieldAtIndex:0];
|
||||||
|
|
||||||
field.delegate = self.formatter;
|
field.delegate = self.formatter;
|
||||||
|
|
||||||
setting_get_string_representation(setting, buffer, sizeof(buffer));
|
setting_get_string_representation(self.setting, buffer, sizeof(buffer));
|
||||||
if (buffer[0] == '\0')
|
if (buffer[0] == '\0')
|
||||||
strlcpy(buffer, "N/A", sizeof(buffer));
|
strlcpy(buffer, "N/A", sizeof(buffer));
|
||||||
|
|
||||||
@ -495,15 +427,14 @@ static void *menu_item_init(ios_menu_item_t *item, unsigned type)
|
|||||||
- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
|
- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
|
||||||
{
|
{
|
||||||
NSString* text = (NSString*)[alertView textFieldAtIndex:0].text;
|
NSString* text = (NSString*)[alertView textFieldAtIndex:0].text;
|
||||||
rarch_setting_t *setting = self.setting;
|
|
||||||
|
|
||||||
if (buttonIndex != alertView.firstOtherButtonIndex)
|
if (buttonIndex != alertView.firstOtherButtonIndex)
|
||||||
return;
|
return;
|
||||||
if (!text.length)
|
if (!text.length)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
setting_set_with_string_representation(setting, [text UTF8String]);
|
setting_set_with_string_representation(self.setting, [text UTF8String]);
|
||||||
[self.parentTable reloadData];
|
[self.parentTable reloadData];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)attachDefaultingGestureTo:(UIView*)view
|
- (void)attachDefaultingGestureTo:(UIView*)view
|
||||||
@ -511,25 +442,28 @@ static void *menu_item_init(ios_menu_item_t *item, unsigned type)
|
|||||||
for (UIGestureRecognizer* i in view.gestureRecognizers)
|
for (UIGestureRecognizer* i in view.gestureRecognizers)
|
||||||
[view removeGestureRecognizer:i];
|
[view removeGestureRecognizer:i];
|
||||||
[view addGestureRecognizer:[[UILongPressGestureRecognizer alloc] initWithTarget:self
|
[view addGestureRecognizer:[[UILongPressGestureRecognizer alloc] initWithTarget:self
|
||||||
action:@selector(resetValue:)]];
|
action:@selector(resetValue:)]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)resetValue:(UIGestureRecognizer*)gesture
|
- (void)resetValue:(UIGestureRecognizer*)gesture
|
||||||
{
|
{
|
||||||
RAMenuItemGeneralSetting __weak* weakSelf = self;
|
struct string_list* items;
|
||||||
struct string_list *items = string_split("OK", "|");
|
RAMenuItemGeneralSetting __weak* weakSelf;
|
||||||
|
|
||||||
if (gesture.state != UIGestureRecognizerStateBegan)
|
if (gesture.state != UIGestureRecognizerStateBegan)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
weakSelf = self;
|
||||||
|
items = (struct string_list*)string_split("OK", "|");
|
||||||
|
|
||||||
RunActionSheet("Really Reset Value?", items, self.parentTable,
|
RunActionSheet("Really Reset Value?", items, self.parentTable,
|
||||||
^(UIActionSheet* actionSheet, NSInteger buttonIndex)
|
^(UIActionSheet* actionSheet, NSInteger buttonIndex)
|
||||||
{
|
{
|
||||||
if (buttonIndex != actionSheet.cancelButtonIndex)
|
if (buttonIndex != actionSheet.cancelButtonIndex)
|
||||||
setting_reset_setting(self.setting);
|
setting_reset_setting(self.setting);
|
||||||
[weakSelf.parentTable reloadData];
|
[weakSelf.parentTable reloadData];
|
||||||
});
|
});
|
||||||
|
|
||||||
string_list_free(items);
|
string_list_free(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -545,44 +479,42 @@ static void *menu_item_init(ios_menu_item_t *item, unsigned type)
|
|||||||
|
|
||||||
- (id)initWithSetting:(rarch_setting_t*)setting action:(void (^)())action
|
- (id)initWithSetting:(rarch_setting_t*)setting action:(void (^)())action
|
||||||
{
|
{
|
||||||
if ((self = [super init]))
|
if ((self = [super init]))
|
||||||
{
|
{
|
||||||
_setting = setting;
|
_setting = setting;
|
||||||
_action = action;
|
_action = action;
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (UITableViewCell*)cellForTableView:(UITableView*)tableView
|
- (UITableViewCell*)cellForTableView:(UITableView*)tableView
|
||||||
{
|
{
|
||||||
static NSString* const cell_id = @"boolean_setting";
|
static NSString* const cell_id = @"boolean_setting";
|
||||||
|
|
||||||
UITableViewCell* result = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:cell_id];
|
UITableViewCell* result = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:cell_id];
|
||||||
rarch_setting_t *setting = self.setting;
|
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
result = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cell_id];
|
result = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cell_id];
|
||||||
result.selectionStyle = UITableViewCellSelectionStyleNone;
|
result.selectionStyle = UITableViewCellSelectionStyleNone;
|
||||||
result.accessoryView = [UISwitch new];
|
result.accessoryView = [UISwitch new];
|
||||||
}
|
}
|
||||||
|
|
||||||
result.textLabel.text = BOXSTRING(setting->short_description);
|
result.textLabel.text = BOXSTRING(self.setting->short_description);
|
||||||
[(id)result.accessoryView removeTarget:nil action:NULL forControlEvents:UIControlEventValueChanged];
|
[(id)result.accessoryView removeTarget:nil action:NULL forControlEvents:UIControlEventValueChanged];
|
||||||
[(id)result.accessoryView addTarget:self action:@selector(handleBooleanSwitch:) forControlEvents:UIControlEventValueChanged];
|
[(id)result.accessoryView addTarget:self action:@selector(handleBooleanSwitch:) forControlEvents:UIControlEventValueChanged];
|
||||||
|
|
||||||
if (setting)
|
if (self.setting)
|
||||||
[(id)result.accessoryView setOn:*setting->value.boolean];
|
[(id)result.accessoryView setOn:*self.setting->value.boolean];
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)handleBooleanSwitch:(UISwitch*)swt
|
- (void)handleBooleanSwitch:(UISwitch*)swt
|
||||||
{
|
{
|
||||||
rarch_setting_t *setting = self.setting;
|
if (self.setting)
|
||||||
if (setting)
|
*self.setting->value.boolean = swt.on ? true : false;
|
||||||
*setting->value.boolean = swt.on ? true : false;
|
if (self.action)
|
||||||
if (self.action)
|
self.action();
|
||||||
self.action();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)wasSelectedOnTableView:(UITableView*)tableView ofController:(UIViewController*)controller
|
- (void)wasSelectedOnTableView:(UITableView*)tableView ofController:(UIViewController*)controller
|
||||||
@ -604,44 +536,46 @@ static void *menu_item_init(ios_menu_item_t *item, unsigned type)
|
|||||||
NSString *path;
|
NSString *path;
|
||||||
RADirectoryList* list;
|
RADirectoryList* list;
|
||||||
RAMenuItemPathSetting __weak* weakSelf = self;
|
RAMenuItemPathSetting __weak* weakSelf = self;
|
||||||
rarch_setting_t *setting = self.setting;
|
|
||||||
|
|
||||||
if (setting_is_of_path_type(setting))
|
if (self.setting && self.setting->type == ST_ACTION &&
|
||||||
setting->action_toggle( setting, MENU_ACTION_RIGHT, false);
|
self.setting->flags & SD_FLAG_BROWSER_ACTION &&
|
||||||
|
self.setting->action_toggle &&
|
||||||
|
self.setting->change_handler )
|
||||||
|
self.setting->action_toggle( self.setting, MENU_ACTION_RIGHT, false);
|
||||||
|
|
||||||
path = BOXSTRING(setting->value.string);
|
path = BOXSTRING(self.setting->value.string);
|
||||||
|
|
||||||
if (setting->type == ST_PATH )
|
if ( self.setting->type == ST_PATH )
|
||||||
path = [path stringByDeletingLastPathComponent];
|
path = [path stringByDeletingLastPathComponent];
|
||||||
|
|
||||||
list = [[RADirectoryList alloc] initWithPath:path extensions:setting->values action:
|
list = [[RADirectoryList alloc] initWithPath:path extensions:self.setting->values action:
|
||||||
^(RADirectoryList* list, RADirectoryItem* item)
|
^(RADirectoryList* list, RADirectoryItem* item)
|
||||||
{
|
{
|
||||||
const char *newval = "";
|
const char *newval = "";
|
||||||
if (item)
|
if (item)
|
||||||
{
|
{
|
||||||
if (list.forDirectory && !item.isDirectory)
|
if (list.forDirectory && !item.isDirectory)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
newval = [item.path UTF8String];
|
newval = [item.path UTF8String];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!list.allowBlank)
|
if (!list.allowBlank)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setting_set_with_string_representation(weakSelf.setting, newval);
|
setting_set_with_string_representation(weakSelf.setting, newval);
|
||||||
[[list navigationController] popViewControllerAnimated:YES];
|
[[list navigationController] popViewControllerAnimated:YES];
|
||||||
|
|
||||||
weakSelf.action();
|
weakSelf.action();
|
||||||
|
|
||||||
[weakSelf.parentTable reloadData];
|
[weakSelf.parentTable reloadData];
|
||||||
}];
|
}];
|
||||||
|
|
||||||
list.allowBlank = (setting->flags & SD_FLAG_ALLOW_EMPTY);
|
list.allowBlank = (self.setting->flags & SD_FLAG_ALLOW_EMPTY);
|
||||||
list.forDirectory = (setting->flags & SD_FLAG_PATH_DIR);
|
list.forDirectory = (self.setting->flags & SD_FLAG_PATH_DIR);
|
||||||
|
|
||||||
[controller.navigationController pushViewController:list animated:YES];
|
[controller.navigationController pushViewController:list animated:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -657,19 +591,19 @@ static void *menu_item_init(ios_menu_item_t *item, unsigned type)
|
|||||||
|
|
||||||
- (void)wasSelectedOnTableView:(UITableView*)tableView ofController:(UIViewController*)controller
|
- (void)wasSelectedOnTableView:(UITableView*)tableView ofController:(UIViewController*)controller
|
||||||
{
|
{
|
||||||
|
struct string_list* items;
|
||||||
RAMenuItemEnumSetting __weak* weakSelf = self;
|
RAMenuItemEnumSetting __weak* weakSelf = self;
|
||||||
rarch_setting_t *setting = self.setting;
|
|
||||||
struct string_list *items = string_split(setting->values, "|");
|
items = (struct string_list*)string_split(self.setting->values, "|");
|
||||||
|
RunActionSheet(self.setting->short_description, items, self.parentTable,
|
||||||
RunActionSheet(setting->short_description, items, self.parentTable,
|
^(UIActionSheet* actionSheet, NSInteger buttonIndex)
|
||||||
^(UIActionSheet* actionSheet, NSInteger buttonIndex)
|
{
|
||||||
{
|
|
||||||
if (buttonIndex == actionSheet.cancelButtonIndex)
|
if (buttonIndex == actionSheet.cancelButtonIndex)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
setting_set_with_string_representation(setting, [[actionSheet buttonTitleAtIndex:buttonIndex] UTF8String]);
|
setting_set_with_string_representation(self.setting, [[actionSheet buttonTitleAtIndex:buttonIndex] UTF8String]);
|
||||||
[weakSelf.parentTable reloadData];
|
[weakSelf.parentTable reloadData];
|
||||||
});
|
});
|
||||||
string_list_free(items);
|
string_list_free(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -691,17 +625,17 @@ static void *menu_item_init(ios_menu_item_t *item, unsigned type)
|
|||||||
- (void)wasSelectedOnTableView:(UITableView *)tableView ofController:(UIViewController *)controller
|
- (void)wasSelectedOnTableView:(UITableView *)tableView ofController:(UIViewController *)controller
|
||||||
{
|
{
|
||||||
self.alert = [[UIAlertView alloc] initWithTitle:BOXSTRING("RetroArch")
|
self.alert = [[UIAlertView alloc] initWithTitle:BOXSTRING("RetroArch")
|
||||||
message:BOXSTRING(self.setting->short_description)
|
message:BOXSTRING(self.setting->short_description)
|
||||||
delegate:self
|
delegate:self
|
||||||
cancelButtonTitle:BOXSTRING("Cancel")
|
cancelButtonTitle:BOXSTRING("Cancel")
|
||||||
otherButtonTitles:BOXSTRING("Clear Keyboard"), BOXSTRING("Clear Joystick"), BOXSTRING("Clear Axis"), nil];
|
otherButtonTitles:BOXSTRING("Clear Keyboard"), BOXSTRING("Clear Joystick"), BOXSTRING("Clear Axis"), nil];
|
||||||
|
|
||||||
[self.alert show];
|
[self.alert show];
|
||||||
|
|
||||||
[self.parentTable reloadData];
|
[self.parentTable reloadData];
|
||||||
|
|
||||||
self.bindTimer = [NSTimer scheduledTimerWithTimeInterval:.1f target:self selector:@selector(checkBind:)
|
self.bindTimer = [NSTimer scheduledTimerWithTimeInterval:.1f target:self selector:@selector(checkBind:)
|
||||||
userInfo:nil repeats:YES];
|
userInfo:nil repeats:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)finishWithClickedButton:(bool)clicked
|
- (void)finishWithClickedButton:(bool)clicked
|
||||||
@ -714,20 +648,19 @@ static void *menu_item_init(ios_menu_item_t *item, unsigned type)
|
|||||||
|
|
||||||
[self.bindTimer invalidate];
|
[self.bindTimer invalidate];
|
||||||
self.bindTimer = nil;
|
self.bindTimer = nil;
|
||||||
|
|
||||||
cocoa_input_reset_icade_buttons();
|
cocoa_input_reset_icade_buttons();
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
|
- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
|
||||||
{
|
{
|
||||||
rarch_setting_t *setting = self.setting;
|
|
||||||
if (buttonIndex == alertView.firstOtherButtonIndex)
|
if (buttonIndex == alertView.firstOtherButtonIndex)
|
||||||
BINDFOR(*setting).key = RETROK_UNKNOWN;
|
BINDFOR(*self.setting).key = RETROK_UNKNOWN;
|
||||||
else if(buttonIndex == alertView.firstOtherButtonIndex + 1)
|
else if(buttonIndex == alertView.firstOtherButtonIndex + 1)
|
||||||
BINDFOR(*setting).joykey = NO_BTN;
|
BINDFOR(*self.setting).joykey = NO_BTN;
|
||||||
else if(buttonIndex == alertView.firstOtherButtonIndex + 2)
|
else if(buttonIndex == alertView.firstOtherButtonIndex + 2)
|
||||||
BINDFOR(*setting).joyaxis = AXIS_NONE;
|
BINDFOR(*self.setting).joyaxis = AXIS_NONE;
|
||||||
|
|
||||||
[self finishWithClickedButton:true];
|
[self finishWithClickedButton:true];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -735,17 +668,16 @@ static void *menu_item_init(ios_menu_item_t *item, unsigned type)
|
|||||||
{
|
{
|
||||||
int32_t value = 0;
|
int32_t value = 0;
|
||||||
int32_t idx = 0;
|
int32_t idx = 0;
|
||||||
rarch_setting_t *setting = self.setting;
|
|
||||||
|
|
||||||
if (setting->index)
|
if (self.setting->index)
|
||||||
idx = setting->index - 1;
|
idx = self.setting->index - 1;
|
||||||
|
|
||||||
if ((value = cocoa_input_find_any_key()))
|
if ((value = cocoa_input_find_any_key()))
|
||||||
BINDFOR(*setting).key = input_keymaps_translate_keysym_to_rk(value);
|
BINDFOR(*self.setting).key = input_keymaps_translate_keysym_to_rk(value);
|
||||||
else if ((value = cocoa_input_find_any_button(idx)) >= 0)
|
else if ((value = cocoa_input_find_any_button(idx)) >= 0)
|
||||||
BINDFOR(*setting).joykey = value;
|
BINDFOR(*self.setting).joykey = value;
|
||||||
else if ((value = cocoa_input_find_any_axis(idx)))
|
else if ((value = cocoa_input_find_any_axis(idx)))
|
||||||
BINDFOR(*setting).joyaxis = (value > 0) ? AXIS_POS(value - 1) : AXIS_NEG(abs(value) - 1);
|
BINDFOR(*self.setting).joyaxis = (value > 0) ? AXIS_POS(value - 1) : AXIS_NEG(abs(value) - 1);
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -868,64 +800,69 @@ void get_core_title(char *title_msg, size_t title_msg_len)
|
|||||||
|
|
||||||
menu_list_get_at_offset(menu->menu_list->selection_buf, i, &path,
|
menu_list_get_at_offset(menu->menu_list->selection_buf, i, &path,
|
||||||
&entry_label, &type);
|
&entry_label, &type);
|
||||||
|
|
||||||
|
// JM: Ideally, this would be simpler because RA would provide a
|
||||||
|
// function that takes "i" and returns either Path, DirPath, Bool,
|
||||||
|
// Bind, Enum, Number, String, Action. [Sub-menus would be action,
|
||||||
|
// because it causes an effect]
|
||||||
|
|
||||||
setting =
|
setting =
|
||||||
(rarch_setting_t*)setting_find_setting
|
(rarch_setting_t*)setting_find_setting
|
||||||
(menu->list_settings,
|
(menu->list_settings,
|
||||||
menu->menu_list->selection_buf->list[i].label);
|
menu->menu_list->selection_buf->list[i].label);
|
||||||
|
|
||||||
cbs = (menu_file_list_cbs_t*)
|
|
||||||
menu_list_get_actiondata_at_offset(menu->menu_list->selection_buf, i);
|
|
||||||
|
|
||||||
if (cbs && cbs->action_get_representation) {
|
|
||||||
cbs->action_get_representation
|
|
||||||
(menu->menu_list->selection_buf,
|
|
||||||
&w, type, i, label,
|
|
||||||
type_str, sizeof(type_str),
|
|
||||||
entry_label, path,
|
|
||||||
path_buf, sizeof(path_buf));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setting && setting->type == ST_ACTION &&
|
if (setting && setting->type == ST_ACTION &&
|
||||||
setting->flags & SD_FLAG_BROWSER_ACTION &&
|
setting->flags & SD_FLAG_BROWSER_ACTION &&
|
||||||
setting->action_toggle &&
|
setting->action_toggle &&
|
||||||
setting->change_handler )
|
setting->change_handler) {
|
||||||
{
|
return [[RAMenuItemPathSetting alloc]
|
||||||
return [[RAMenuItemPathSetting alloc]
|
|
||||||
initWithSetting:setting
|
initWithSetting:setting
|
||||||
action:^{}];
|
action:^{}];
|
||||||
|
} else if (setting && setting->type == ST_BOOL ) {
|
||||||
|
return [[RAMenuItemBooleanSetting alloc]
|
||||||
|
initWithSetting:setting
|
||||||
|
action:^{[weakSelf menuSelect: i];}];
|
||||||
|
} else if (setting && ST_PATH <= setting->type && setting->type <= ST_DIR) {
|
||||||
|
return [[RAMenuItemPathSetting alloc]
|
||||||
|
initWithSetting:setting
|
||||||
|
action:^{[weakSelf menuSelect: i];}];
|
||||||
|
} else if (setting && setting->type == ST_BIND ) {
|
||||||
|
return [[RAMenuItemBindSetting alloc]
|
||||||
|
initWithSetting:setting
|
||||||
|
action:^{[weakSelf menuSelect: i];}];
|
||||||
|
} else if (setting && setting->type == ST_STRING && setting->values ) {
|
||||||
|
return [[RAMenuItemEnumSetting alloc]
|
||||||
|
initWithSetting:setting
|
||||||
|
action:^{[weakSelf menuSelect: i];}];
|
||||||
|
} else if (setting && ST_INT <= setting->type && setting->type <= ST_HEX) {
|
||||||
|
RAMenuItemGeneralSetting* item =
|
||||||
|
[[RAMenuItemGeneralSetting alloc]
|
||||||
|
initWithSetting:setting
|
||||||
|
action:^{[weakSelf menuSelect: i];}];
|
||||||
|
|
||||||
|
if (setting->type == ST_INT ||
|
||||||
|
setting->type == ST_UINT ||
|
||||||
|
setting->type == ST_FLOAT)
|
||||||
|
item.formatter = [[RANumberFormatter alloc] initWithSetting:item.setting];
|
||||||
|
|
||||||
|
return item;
|
||||||
|
} else { // This is for ST_GROUP/etc
|
||||||
|
cbs = (menu_file_list_cbs_t*)
|
||||||
|
menu_list_get_actiondata_at_offset(menu->menu_list->selection_buf, i);
|
||||||
|
|
||||||
|
if (cbs && cbs->action_get_representation) {
|
||||||
|
cbs->action_get_representation
|
||||||
|
(menu->menu_list->selection_buf,
|
||||||
|
&w, type, i, label,
|
||||||
|
type_str, sizeof(type_str),
|
||||||
|
entry_label, path,
|
||||||
|
path_buf, sizeof(path_buf));
|
||||||
}
|
}
|
||||||
else if (setting && ST_ACTION < setting->type && setting->type < ST_GROUP)
|
|
||||||
{
|
return [RAMenuItemBasic
|
||||||
return [RAMenuItemGeneralSetting
|
|
||||||
itemForSetting:setting
|
|
||||||
action:^{
|
|
||||||
menu->navigation.selection_ptr = i;
|
|
||||||
if (cbs && cbs->action_ok)
|
|
||||||
cbs->action_ok(path, entry_label, type, i);
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return [RAMenuItemBasic
|
|
||||||
itemWithDescription:BOXSTRING(path_buf)
|
itemWithDescription:BOXSTRING(path_buf)
|
||||||
action:^{
|
action:^{[weakSelf menuSelect: i];}];
|
||||||
menu->navigation.selection_ptr = i;
|
}
|
||||||
if (cbs && cbs->action_ok)
|
|
||||||
cbs->action_ok(path, entry_label, type, i);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (cbs && cbs->action_start)
|
|
||||||
cbs->action_start(type, entry_label, MENU_ACTION_START);
|
|
||||||
if (cbs && cbs->action_toggle)
|
|
||||||
cbs->action_toggle(type, entry_label, MENU_ACTION_RIGHT, true);
|
|
||||||
menu_list_push_stack(menu->menu_list, "",
|
|
||||||
"info_screen", 0, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
[weakSelf menuRefresh];
|
|
||||||
[weakSelf reloadData];
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)menuSelect: (uint) i
|
- (void)menuSelect: (uint) i
|
||||||
@ -989,13 +926,15 @@ uint menu_select_entry(uint i) {
|
|||||||
|
|
||||||
- (void)menuRefresh
|
- (void)menuRefresh
|
||||||
{
|
{
|
||||||
menu_handle_t *menu = menu_driver_get_ptr();
|
menu_handle_t *menu = menu_driver_get_ptr();
|
||||||
if (!menu || !menu->need_refresh)
|
if (!menu)
|
||||||
return;
|
return;
|
||||||
|
if (!menu->need_refresh)
|
||||||
menu_entries_deferred_push(menu->menu_list->selection_buf,
|
return;
|
||||||
menu->menu_list->menu_stack);
|
|
||||||
menu->need_refresh = false;
|
menu_entries_deferred_push(menu->menu_list->selection_buf,
|
||||||
|
menu->menu_list->menu_stack);
|
||||||
|
menu->need_refresh = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)menuBack
|
- (void)menuBack
|
||||||
@ -1003,11 +942,11 @@ uint menu_select_entry(uint i) {
|
|||||||
menu_handle_t *menu = menu_driver_get_ptr();
|
menu_handle_t *menu = menu_driver_get_ptr();
|
||||||
if (!menu)
|
if (!menu)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
menu_apply_deferred_settings();
|
menu_apply_deferred_settings();
|
||||||
menu_list_pop_stack(menu->menu_list);
|
menu_list_pop_stack(menu->menu_list);
|
||||||
[self menuRefresh];
|
[self menuRefresh];
|
||||||
[self reloadData];
|
[self reloadData];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user