Cocoa Port:

- Fix a crashing bug that can sometimes occur when removing an input mapping.
- Make command names and input setting strings localizable.
- Do some minor code cleanup.
This commit is contained in:
rogerman 2013-03-12 21:14:34 +00:00
parent 5cd1cdef80
commit a18082d29b
5 changed files with 49 additions and 287 deletions

View File

@ -101,6 +101,17 @@
#define NSSTRING_DISPLAYMODE_TOUCH NSLocalizedString(@"Touch", nil) #define NSSTRING_DISPLAYMODE_TOUCH NSLocalizedString(@"Touch", nil)
#define NSSTRING_DISPLAYMODE_COMBO NSLocalizedString(@"Combo", nil) #define NSSTRING_DISPLAYMODE_COMBO NSLocalizedString(@"Combo", nil)
#define NSSTRING_INPUTPREF_NUM_INPUTS_MAPPED NSLocalizedString(@"%ld Input Mapped", nil)
#define NSSTRING_INPUTPREF_NUM_INPUTS_MAPPED_PLURAL NSLocalizedString(@"%ld Inputs Mapped", nil)
#define NSSTRING_INPUTPREF_USE_DEVICE_COORDINATES NSLocalizedString(@"Use Device Coordinates", nil)
#define NSSTRING_INPUTPREF_MIC_NONE NSLocalizedString(@"None", nil)
#define NSSTRING_INPUTPREF_MIC_INTERNAL_NOISE NSLocalizedString(@"Internal Noise Samples", nil)
#define NSSTRING_INPUTPREF_MIC_WHITE_NOISE NSLocalizedString(@"White Noise", nil)
#define NSSTRING_INPUTPREF_SPEED_SCALAR NSLocalizedString(@"%1.2fx Speed", nil)
#define NSSTRING_INPUTPREF_GPU_STATE_ALL_MAIN NSLocalizedString(@"Main GPU - All Layers", nil)
#define NSSTRING_INPUTPREF_GPU_STATE_ALL_SUB NSLocalizedString(@"Sub GPU - All Layers", nil)
// LEGACY STRINGS // LEGACY STRINGS
#define NSSTRING_TITLE_OPEN_ROM_PANEL_LEGACY NSLocalizedString(@"Open ROM...", nil) #define NSSTRING_TITLE_OPEN_ROM_PANEL_LEGACY NSLocalizedString(@"Open ROM...", nil)
#define NSSTRING_TITLE_OPEN_STATE_FILE_PANEL_LEGACY NSLocalizedString(@"Load State From...", nil) #define NSSTRING_TITLE_OPEN_STATE_FILE_PANEL_LEGACY NSLocalizedString(@"Load State From...", nil)
@ -452,35 +463,3 @@ enum
MICMODE_WHITE_NOISE, MICMODE_WHITE_NOISE,
MICMODE_PHYSICAL MICMODE_PHYSICAL
}; };
/*
CONTROL TAGS FOR PREFERENCE WINDOW INPUT CONFIG BUTTONS
*/
enum
{
PREF_INPUT_BUTTON_UP = 1000,
PREF_INPUT_BUTTON_DOWN,
PREF_INPUT_BUTTON_LEFT,
PREF_INPUT_BUTTON_RIGHT,
PREF_INPUT_BUTTON_A,
PREF_INPUT_BUTTON_B,
PREF_INPUT_BUTTON_X,
PREF_INPUT_BUTTON_Y,
PREF_INPUT_BUTTON_L,
PREF_INPUT_BUTTON_R,
PREF_INPUT_BUTTON_START,
PREF_INPUT_BUTTON_SELECT,
PREF_INPUT_BUTTON_SIM_MIC = 2000,
PREF_INPUT_BUTTON_LID = 3000,
PREF_INPUT_BUTTON_DEBUG,
PREF_INPUT_BUTTON_SPEED_HALF,
PREF_INPUT_BUTTON_SPEED_DOUBLE,
PREF_INPUT_BUTTON_TOGGLE_HUD,
PREF_INPUT_BUTTON_EXECUTE,
PREF_INPUT_BUTTON_PAUSE,
PREF_INPUT_BUTTON_RESET,
PREF_INPUT_BUTTON_TOUCH = 4000
};

File diff suppressed because it is too large Load Diff

View File

@ -144,7 +144,6 @@ void HandleDeviceRemovalCallback(void *inContext, IOReturn inResult, void *inSen
@interface InputManager : NSObject @interface InputManager : NSObject
{ {
EmuControllerDelegate *emuControl; EmuControllerDelegate *emuControl;
NSOutlineView *inputPrefsOutlineView;
id<InputHIDManagerTarget> hidInputTarget; id<InputHIDManagerTarget> hidInputTarget;
InputHIDManager *hidManager; InputHIDManager *hidManager;
NSMutableDictionary *inputMappings; NSMutableDictionary *inputMappings;
@ -155,7 +154,6 @@ void HandleDeviceRemovalCallback(void *inContext, IOReturn inResult, void *inSen
} }
@property (readonly) IBOutlet EmuControllerDelegate *emuControl; @property (readonly) IBOutlet EmuControllerDelegate *emuControl;
@property (readonly) IBOutlet NSOutlineView *inputPrefsOutlineView;
@property (retain) id<InputHIDManagerTarget> hidInputTarget; @property (retain) id<InputHIDManagerTarget> hidInputTarget;
@property (retain) NSMutableDictionary *inputMappings; @property (retain) NSMutableDictionary *inputMappings;

View File

@ -795,7 +795,6 @@ void HandleDeviceRemovalCallback(void *inContext, IOReturn inResult, void *inSen
@implementation InputManager @implementation InputManager
@synthesize emuControl; @synthesize emuControl;
@synthesize inputPrefsOutlineView;
@dynamic hidInputTarget; @dynamic hidInputTarget;
@synthesize inputMappings; @synthesize inputMappings;
@ -1146,9 +1145,9 @@ static std::tr1::unordered_map<unsigned short, std::string> keyboardNameTable; /
commandMap.erase(it); commandMap.erase(it);
} }
for (NSString *inputCommandTag in [self inputMappings]) for (NSString *inputCommandTag in inputMappings)
{ {
NSMutableArray *inputList = (NSMutableArray *)[[self inputMappings] valueForKey:inputCommandTag]; NSMutableArray *inputList = (NSMutableArray *)[inputMappings valueForKey:inputCommandTag];
NSMutableArray *inputRemovalList = [NSMutableArray arrayWithCapacity:1]; NSMutableArray *inputRemovalList = [NSMutableArray arrayWithCapacity:1];
for (NSDictionary *inputDeviceInfo in inputList) for (NSDictionary *inputDeviceInfo in inputList)
@ -1164,10 +1163,7 @@ static std::tr1::unordered_map<unsigned short, std::string> keyboardNameTable; /
} }
} }
for (NSDictionary *inputDeviceInfoToRemove in inputRemovalList) [inputList removeObjectsInArray:inputRemovalList];
{
[inputList removeObject:inputDeviceInfoToRemove];
}
} }
} }
@ -1304,7 +1300,7 @@ static std::tr1::unordered_map<unsigned short, std::string> keyboardNameTable; /
const BOOL useInputForIntCoord = [(NSNumber *)[deviceInfo valueForKey:@"useInputForIntCoord"] boolValue]; const BOOL useInputForIntCoord = [(NSNumber *)[deviceInfo valueForKey:@"useInputForIntCoord"] boolValue];
if (useInputForIntCoord) if (useInputForIntCoord)
{ {
inputSummary = @"Use Device Coordinates"; inputSummary = NSSTRING_INPUTPREF_USE_DEVICE_COORDINATES;
} }
else else
{ {
@ -1319,11 +1315,11 @@ static std::tr1::unordered_map<unsigned short, std::string> keyboardNameTable; /
switch (micMode) switch (micMode)
{ {
case MICMODE_NONE: case MICMODE_NONE:
inputSummary = @"None"; inputSummary = NSSTRING_INPUTPREF_MIC_NONE;
break; break;
case MICMODE_INTERNAL_NOISE: case MICMODE_INTERNAL_NOISE:
inputSummary = @"Internal Noise Samples"; inputSummary = NSSTRING_INPUTPREF_MIC_INTERNAL_NOISE;
break; break;
case MICMODE_SOUND_FILE: case MICMODE_SOUND_FILE:
@ -1331,7 +1327,7 @@ static std::tr1::unordered_map<unsigned short, std::string> keyboardNameTable; /
break; break;
case MICMODE_WHITE_NOISE: case MICMODE_WHITE_NOISE:
inputSummary = @"White Noise"; inputSummary = NSSTRING_INPUTPREF_MIC_WHITE_NOISE;
break; break;
case MICMODE_PHYSICAL: case MICMODE_PHYSICAL:
@ -1355,7 +1351,7 @@ static std::tr1::unordered_map<unsigned short, std::string> keyboardNameTable; /
else if (strncmp(commandTag, "Set Speed", INPUT_HANDLER_STRING_LENGTH) == 0) else if (strncmp(commandTag, "Set Speed", INPUT_HANDLER_STRING_LENGTH) == 0)
{ {
const float speedScalar = [(NSNumber *)[deviceInfo valueForKey:@"floatValue0"] floatValue]; const float speedScalar = [(NSNumber *)[deviceInfo valueForKey:@"floatValue0"] floatValue];
inputSummary = [NSString stringWithFormat:@"%1.2fx Speed", speedScalar]; inputSummary = [NSString stringWithFormat:NSSTRING_INPUTPREF_SPEED_SCALAR, speedScalar];
} }
else if (strncmp(commandTag, "Enable/Disable GPU State", INPUT_HANDLER_STRING_LENGTH) == 0) else if (strncmp(commandTag, "Enable/Disable GPU State", INPUT_HANDLER_STRING_LENGTH) == 0)
{ {
@ -1363,7 +1359,7 @@ static std::tr1::unordered_map<unsigned short, std::string> keyboardNameTable; /
switch (gpuStateID) switch (gpuStateID)
{ {
case 0: case 0:
inputSummary = @"Main GPU - All Layers"; inputSummary = NSSTRING_INPUTPREF_GPU_STATE_ALL_MAIN;
break; break;
case 1: case 1:
@ -1387,7 +1383,7 @@ static std::tr1::unordered_map<unsigned short, std::string> keyboardNameTable; /
break; break;
case 6: case 6:
inputSummary = @"Sub GPU - All Layers"; inputSummary = NSSTRING_INPUTPREF_GPU_STATE_ALL_SUB;
break; break;
case 7: case 7:

View File

@ -372,7 +372,7 @@
buttonImage = (NSImage *)[inputPrefProperties valueForKey:@"UNKNOWN COMMAND"]; buttonImage = (NSImage *)[inputPrefProperties valueForKey:@"UNKNOWN COMMAND"];
} }
[outCell setTitle:commandTag]; [outCell setTitle:NSLocalizedString(commandTag, nil)];
[outCell setImage:buttonImage]; [outCell setImage:buttonImage];
} }
else else
@ -483,7 +483,7 @@
if ([item isKindOfClass:[NSArray class]]) if ([item isKindOfClass:[NSArray class]])
{ {
const unsigned long inputCount = (unsigned long)[(NSArray *)item count]; const unsigned long inputCount = (unsigned long)[(NSArray *)item count];
return [NSString stringWithFormat:(inputCount != 1) ? @"%ld Inputs Mapped" : @"%ld Input Mapped", inputCount]; return [NSString stringWithFormat:(inputCount != 1) ? NSSTRING_INPUTPREF_NUM_INPUTS_MAPPED_PLURAL : NSSTRING_INPUTPREF_NUM_INPUTS_MAPPED, inputCount];
} }
else if ([item isKindOfClass:[NSDictionary class]]) else if ([item isKindOfClass:[NSDictionary class]])
{ {
@ -626,13 +626,12 @@
const NSInteger rowNumber = [outlineView clickedRow]; const NSInteger rowNumber = [outlineView clickedRow];
NSDictionary *deviceInfo = (NSDictionary *)[outlineView itemAtRow:rowNumber]; NSDictionary *deviceInfo = (NSDictionary *)[outlineView itemAtRow:rowNumber];
[inputManager removeMappingUsingDeviceCode:[(NSString *)[deviceInfo valueForKey:@"deviceCode"] cStringUsingEncoding:NSUTF8StringEncoding] elementCode:[(NSString *)[deviceInfo valueForKey:@"elementCode"] cStringUsingEncoding:NSUTF8StringEncoding]];
NSMutableArray *inputList = (NSMutableArray *)[outlineView parentForItem:deviceInfo]; NSMutableArray *inputList = (NSMutableArray *)[outlineView parentForItem:deviceInfo];
[inputList removeObject:deviceInfo];
[inputManager removeMappingUsingDeviceCode:[(NSString *)[deviceInfo valueForKey:@"deviceCode"] cStringUsingEncoding:NSUTF8StringEncoding] elementCode:[(NSString *)[deviceInfo valueForKey:@"elementCode"] cStringUsingEncoding:NSUTF8StringEncoding]];
[inputManager writeDefaultsInputMappings];
[outlineView reloadItem:inputList reloadChildren:YES]; [outlineView reloadItem:inputList reloadChildren:YES];
[inputManager writeDefaultsInputMappings];
} }
- (IBAction) changeSpeed:(id)sender - (IBAction) changeSpeed:(id)sender