diff options
Diffstat (limited to 'macosx/plugins/DFInput/macsrc')
| -rwxr-xr-x | macosx/plugins/DFInput/macsrc/ControllerList.h | 3 | ||||
| -rwxr-xr-x | macosx/plugins/DFInput/macsrc/ControllerList.m | 111 | ||||
| -rwxr-xr-x | macosx/plugins/DFInput/macsrc/MappingCell.m | 6 | ||||
| -rwxr-xr-x | macosx/plugins/DFInput/macsrc/PadController.h | 6 | ||||
| -rwxr-xr-x | macosx/plugins/DFInput/macsrc/PadController.m | 4 | ||||
| -rwxr-xr-x | macosx/plugins/DFInput/macsrc/PadView.h | 4 | ||||
| -rwxr-xr-x | macosx/plugins/DFInput/macsrc/PadView.m | 42 | ||||
| -rwxr-xr-x | macosx/plugins/DFInput/macsrc/cfg.c | 23 | ||||
| -rwxr-xr-x | macosx/plugins/DFInput/macsrc/cfg.h | 2 | ||||
| -rw-r--r-- | macosx/plugins/DFInput/macsrc/cfgHelper.m | 12 |
10 files changed, 152 insertions, 61 deletions
diff --git a/macosx/plugins/DFInput/macsrc/ControllerList.h b/macosx/plugins/DFInput/macsrc/ControllerList.h index aae13954..e212ab66 100755 --- a/macosx/plugins/DFInput/macsrc/ControllerList.h +++ b/macosx/plugins/DFInput/macsrc/ControllerList.h @@ -25,14 +25,13 @@ #include "cfg.h" @interface ControllerList : NSObject <NSTableViewDataSource> +@property (getter = isUsingSDL2) BOOL usingSDL2; - (id)initWithConfig; + (void)setCurrentController:(int)which; + (int)currentController; + (int)buttonOfRow:(NSInteger)row; -- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView; -- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex; - (void)deleteRow:(NSInteger)which; @end diff --git a/macosx/plugins/DFInput/macsrc/ControllerList.m b/macosx/plugins/DFInput/macsrc/ControllerList.m index 583c0ad3..172bc534 100755 --- a/macosx/plugins/DFInput/macsrc/ControllerList.m +++ b/macosx/plugins/DFInput/macsrc/ControllerList.m @@ -25,43 +25,83 @@ static int currentController; static NSArray *labelText; +static NSArray *GameControllerText; @implementation ControllerList +- (BOOL)isUsingSDL2 +{ + return g.cfg.PadDef[currentController].UseSDL2; +} + +- (void)setUsingSDL2:(BOOL)_usingSDL2 +{ + g.cfg.PadDef[currentController].UseSDL2 = _usingSDL2; +} + - (id)initWithConfig { if (self = [super init]) { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - NSBundle *plugBundle = [NSBundle bundleForClass:[ControllerList class]]; - labelText = @[[plugBundle localizedStringForKey:@"D-Pad Up" value:@"" table:nil], - [plugBundle localizedStringForKey:@"D-Pad Down" value:@"" table:nil], - [plugBundle localizedStringForKey:@"D-Pad Left" value:@"" table:nil], - [plugBundle localizedStringForKey:@"D-Pad Right" value:@"" table:nil], - [plugBundle localizedStringForKey:@"Cross" value:@"" table:nil], - [plugBundle localizedStringForKey:@"Circle" value:@"" table:nil], - [plugBundle localizedStringForKey:@"Square" value:@"" table:nil], - [plugBundle localizedStringForKey:@"Triangle" value:@"" table:nil], - [plugBundle localizedStringForKey:@"L1" value:@"" table:nil], - [plugBundle localizedStringForKey:@"R1" value:@"" table:nil], - [plugBundle localizedStringForKey:@"L2" value:@"" table:nil], - [plugBundle localizedStringForKey:@"R2" value:@"" table:nil], - [plugBundle localizedStringForKey:@"Select" value:@"" table:nil], - [plugBundle localizedStringForKey:@"Start" value:@"" table:nil], - - [plugBundle localizedStringForKey:@"L3" value:@"" table:nil], - [plugBundle localizedStringForKey:@"R3" value:@"" table:nil], - [plugBundle localizedStringForKey:@"Analog" value:@"" table:nil], - - [plugBundle localizedStringForKey:@"L-Stick Right" value:@"" table:nil], - [plugBundle localizedStringForKey:@"L-Stick Left" value:@"" table:nil], - [plugBundle localizedStringForKey:@"L-Stick Down" value:@"" table:nil], - [plugBundle localizedStringForKey:@"L-Stick Up" value:@"" table:nil], - - [plugBundle localizedStringForKey:@"R-Stick Right" value:@"" table:nil], - [plugBundle localizedStringForKey:@"R-Stick Left" value:@"" table:nil], - [plugBundle localizedStringForKey:@"R-Stick Down" value:@"" table:nil], - [plugBundle localizedStringForKey:@"R-Stick Up" value:@"" table:nil]]; + NSBundle *plugBundle = [NSBundle bundleForClass:[self class]]; + labelText = @[NSLocalizedStringFromTableInBundle(@"D-Pad Up", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"D-Pad Down", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"D-Pad Left", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"D-Pad Right", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"Cross", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"Circle", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"Square", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"Triangle", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"L1", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"R1", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"L2", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"R2", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"Select", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"Start", nil, plugBundle, @""), + + NSLocalizedStringFromTableInBundle(@"L3", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"R3", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"Analog", nil, plugBundle, @""), + + NSLocalizedStringFromTableInBundle(@"L-Stick Right", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"L-Stick Left", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"L-Stick Down", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"L-Stick Up", nil, plugBundle, @""), + + NSLocalizedStringFromTableInBundle(@"R-Stick Right", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"R-Stick Left", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"R-Stick Down", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"R-Stick Up", nil, plugBundle, @"")]; + + GameControllerText = @[NSLocalizedStringFromTableInBundle(@"D-Pad Up", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"D-Pad Down", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"D-Pad Left", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"D-Pad Right", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"Cross", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"Circle", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"Square", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"Triangle", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"Left Bumper", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"Right Bumper", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"Left Trigger", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"Right Trigger", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"Back", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"Start", nil, plugBundle, @""), + + NSLocalizedStringFromTableInBundle(@"L3", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"R3", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"Guide", nil, plugBundle, @""), + + NSLocalizedStringFromTableInBundle(@"L-Stick Right", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"L-Stick Left", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"L-Stick Down", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"L-Stick Up", nil, plugBundle, @""), + + NSLocalizedStringFromTableInBundle(@"R-Stick Right", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"R-Stick Left", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"R-Stick Down", nil, plugBundle, @""), + NSLocalizedStringFromTableInBundle(@"R-Stick Up", nil, plugBundle, @"")]; }); } return self; @@ -117,6 +157,18 @@ static const int DPad[DKEY_TOTAL] = { } else { char buf[256] = {0}; + if ([self isUsingSDL2]) { + NSString *keyBoardString, *gamePadStr = GameControllerText[rowIndex]; + if (rowIndex < DKEY_TOTAL) { + GetKeyboardKeyDescription(buf, currentController, DPad[rowIndex]); + } else { + NSInteger tmpRowIndex = rowIndex - DKEY_TOTAL; + GetKeyboardAnalogDescription(buf, currentController, (int)(tmpRowIndex / 4), tmpRowIndex % 4); + } + keyBoardString = @(buf); + + return [keyBoardString isEqualToString:@""] ? gamePadStr : [gamePadStr stringByAppendingFormat:@" / %@", keyBoardString]; + } else { // actual keys if (rowIndex < DKEY_TOTAL) { GetKeyDescription(buf, currentController, DPad[rowIndex]); @@ -126,6 +178,7 @@ static const int DPad[DKEY_TOTAL] = { } return @(buf); + } } } diff --git a/macosx/plugins/DFInput/macsrc/MappingCell.m b/macosx/plugins/DFInput/macsrc/MappingCell.m index a61e9087..164f8db3 100755 --- a/macosx/plugins/DFInput/macsrc/MappingCell.m +++ b/macosx/plugins/DFInput/macsrc/MappingCell.m @@ -26,8 +26,10 @@ @implementation MappingCell - (id)initTextCell:(NSString *)aString { - self = [super initTextCell:aString]; - [self setEditable:NO]; + if (self = [super initTextCell:aString]) { + [self setEditable:NO]; + } + return self; } diff --git a/macosx/plugins/DFInput/macsrc/PadController.h b/macosx/plugins/DFInput/macsrc/PadController.h index 6257b849..2f3a348c 100755 --- a/macosx/plugins/DFInput/macsrc/PadController.h +++ b/macosx/plugins/DFInput/macsrc/PadController.h @@ -35,6 +35,6 @@ - (IBAction)ok:(id)sender; @end -extern NSDictionary *DefaultPadArray(int padnum); -extern void LoadPadArray(int padnum, NSDictionary *nsPrefs); -extern NSDictionary *SavePadArray(int padnum); +__private_extern__ NSDictionary *DefaultPadArray(int padnum); +__private_extern__ void LoadPadArray(int padnum, NSDictionary *nsPrefs); +__private_extern__ NSDictionary *SavePadArray(int padnum); diff --git a/macosx/plugins/DFInput/macsrc/PadController.m b/macosx/plugins/DFInput/macsrc/PadController.m index 3ec7d14b..fbc03619 100755 --- a/macosx/plugins/DFInput/macsrc/PadController.m +++ b/macosx/plugins/DFInput/macsrc/PadController.m @@ -145,8 +145,8 @@ void LoadPADConfig() [usrDefaults registerDefaults: @{PrefsKey: @{kDFPad1: DefaultPadArray(0), - kDFPad2: DefaultPadArray(1), - kDFThreading: @YES}}]; + kDFPad2: DefaultPadArray(1), + kDFThreading: @YES}}]; //Load the old preferences if present and we don't have new ones. NSFileManager *fm = [NSFileManager defaultManager]; diff --git a/macosx/plugins/DFInput/macsrc/PadView.h b/macosx/plugins/DFInput/macsrc/PadView.h index c8694796..8ab20ab5 100755 --- a/macosx/plugins/DFInput/macsrc/PadView.h +++ b/macosx/plugins/DFInput/macsrc/PadView.h @@ -32,9 +32,11 @@ ControllerList *controller; } +@property (weak) IBOutlet NSButton *useSDL2Check; + - (IBAction)setType:(id)sender; - (IBAction)setDevice:(id)sender; +- (IBAction)toggleSDL2:(id)sender; - (void)setController:(int)which; - @end diff --git a/macosx/plugins/DFInput/macsrc/PadView.m b/macosx/plugins/DFInput/macsrc/PadView.m index f8936888..befb5df3 100755 --- a/macosx/plugins/DFInput/macsrc/PadView.m +++ b/macosx/plugins/DFInput/macsrc/PadView.m @@ -26,7 +26,7 @@ - (id)initWithFrame:(NSRect)frameRect { - if ((self = [super initWithFrame:frameRect]) != nil) { + if (self = [super initWithFrame:frameRect]) { controller = [[ControllerList alloc] initWithConfig]; [self setController:0]; } @@ -35,13 +35,14 @@ - (void)drawRect:(NSRect)rect { + } - (IBAction)setType:(id)sender { g.cfg.PadDef[[ControllerList currentController]].Type = ([sender indexOfSelectedItem] > 0 ? PSE_PAD_TYPE_ANALOGPAD : PSE_PAD_TYPE_STANDARD); - + [tableView reloadData]; } @@ -50,36 +51,49 @@ g.cfg.PadDef[[ControllerList currentController]].DevNum = (int)[sender indexOfSelectedItem] - 1; } +- (IBAction)toggleSDL2:(id)sender +{ + controller.usingSDL2 = !controller.usingSDL2; + + [tableView reloadData]; +} + - (void)setController:(int)which { int i; - + [ControllerList setCurrentController:which]; [tableView setDataSource:controller]; - + [deviceMenu removeAllItems]; [deviceMenu addItemWithTitle:[[NSBundle bundleForClass:[self class]] localizedStringForKey:@"(Keyboard only)" value:@"" table:nil]]; - + for (i = 0; i < SDL_NumJoysticks(); i++) { - NSMenuItem *joystickItem = nil; + NSMenuItem *joystickItem; #if SDL_VERSION_ATLEAST(2, 0, 0) - SDL_Joystick *tmpJoy = SDL_JoystickOpen(i); - joystickItem = [[NSMenuItem alloc] initWithTitle:@(SDL_JoystickName(tmpJoy)) action:NULL keyEquivalent:@""]; - SDL_JoystickClose(tmpJoy); + NSString *tmpString; + if (SDL_IsGameController(i)) { + tmpString = @(SDL_GameControllerNameForIndex(i)); + } else { + tmpString = @(SDL_JoystickNameForIndex(i)); + } + joystickItem = [[NSMenuItem alloc] initWithTitle:tmpString action:NULL keyEquivalent:@""]; #else joystickItem = [[NSMenuItem alloc] initWithTitle:@(SDL_JoystickName(i)) action:NULL keyEquivalent:@""]; #endif [joystickItem setTag:i + 1]; [[deviceMenu menu] addItem:joystickItem]; } - + if (g.cfg.PadDef[which].DevNum >= SDL_NumJoysticks()) { g.cfg.PadDef[which].DevNum = -1; } - + [deviceMenu selectItemAtIndex:g.cfg.PadDef[which].DevNum + 1]; [typeMenu selectItemAtIndex:(g.cfg.PadDef[which].Type == PSE_PAD_TYPE_ANALOGPAD ? 1 : 0)]; - + + [self.useSDL2Check setState:g.cfg.PadDef[which].UseSDL2 ? NSOnState : NSOffState]; + [tableView reloadData]; } @@ -92,7 +106,7 @@ - (void)keyDown:(NSEvent *)theEvent { unsigned short key = [theEvent keyCode]; - + if ([[theEvent window] firstResponder] == tableView) { if (key == 51 || key == 117) { // delete keys - remove the mappings for the selected item @@ -105,7 +119,7 @@ return; } } - + [super keyDown:theEvent]; } diff --git a/macosx/plugins/DFInput/macsrc/cfg.c b/macosx/plugins/DFInput/macsrc/cfg.c index 703a001a..3e4cfa06 100755 --- a/macosx/plugins/DFInput/macsrc/cfg.c +++ b/macosx/plugins/DFInput/macsrc/cfg.c @@ -25,7 +25,8 @@ long DoConfiguration(); void DoAbout(); long PADconfigure(void) { - if (SDL_WasInit(SDL_INIT_JOYSTICK)) return PSE_ERR_FATAL; // cannot change settings on the fly + if (SDL_WasInit(SDL_INIT_JOYSTICK)) + return PSE_ERR_FATAL; // cannot change settings on the fly DoConfiguration(); //LoadPADConfig(); @@ -152,7 +153,7 @@ static const char *XKeysymToString(uint16_t key) { i++; } - sprintf(buf, "0x%.2X", key); + snprintf(buf, sizeof(buf), "0x%.2X", key); return buf; } @@ -194,6 +195,24 @@ void GetKeyDescription(char *buf, int joynum, int key) } } +void GetKeyboardKeyDescription(char *buf, int joynum, int key) +{ + if (g.cfg.PadDef[joynum].KeyDef[key].Key != 0) { + sprintf(buf, _("Keyboard: %s"), XKeysymToString(g.cfg.PadDef[joynum].KeyDef[key].Key)); + } else { + buf[0] = '\0'; + } +} + +void GetKeyboardAnalogDescription(char *buf, int joynum, int analognum, int dir) +{ + if (g.cfg.PadDef[joynum].AnalogDef[analognum][dir].Key != 0) { + sprintf(buf, _("Keyboard: %s"), XKeysymToString(g.cfg.PadDef[joynum].AnalogDef[analognum][dir].Key)); + } else { + buf[0] = '\0'; + } +} + void GetAnalogDescription(char *buf, int joynum, int analognum, int dir) { switch (g.cfg.PadDef[joynum].AnalogDef[analognum][dir].JoyEvType) { diff --git a/macosx/plugins/DFInput/macsrc/cfg.h b/macosx/plugins/DFInput/macsrc/cfg.h index cceb6f3e..4f772d47 100755 --- a/macosx/plugins/DFInput/macsrc/cfg.h +++ b/macosx/plugins/DFInput/macsrc/cfg.h @@ -23,6 +23,8 @@ void GetKeyDescription(char *buf, int joynum, int key); void GetAnalogDescription(char *buf, int joynum, int analognum, int dir); +void GetKeyboardKeyDescription(char *buf, int joynum, int key); +void GetKeyboardAnalogDescription(char *buf, int joynum, int analognum, int dir); void InitAxisPos(int padnum); int ReadDKeyEvent(int padnum, int key); int ReadAnalogEvent(int padnum, int analognum, int analogdir); diff --git a/macosx/plugins/DFInput/macsrc/cfgHelper.m b/macosx/plugins/DFInput/macsrc/cfgHelper.m index bb856824..8bdce079 100644 --- a/macosx/plugins/DFInput/macsrc/cfgHelper.m +++ b/macosx/plugins/DFInput/macsrc/cfgHelper.m @@ -43,6 +43,7 @@ #define dRightAnalogYM @"RightAnalogYM" #define VibrateOn @"Visual Vibration" +#define UseSDL2Mapping @"SDL2 Mapping" NSDictionary *DefaultPadArray(int padnum) { @@ -63,7 +64,8 @@ NSDictionary *DefaultPadArray(int padnum) dTriangle: [NSMutableDictionary dictionaryWithObjectsAndKeys:@0, joyVal, @(BUTTON), joyType, nil], dCircle: [NSMutableDictionary dictionaryWithObjectsAndKeys:@1, joyVal, @(BUTTON), joyType, nil], dCross: [NSMutableDictionary dictionaryWithObjectsAndKeys:@2, joyVal, @(BUTTON), joyType, nil], - dSquare: [NSMutableDictionary dictionaryWithObjectsAndKeys:@3, joyVal, @(BUTTON), joyType, nil]}]; + dSquare: [NSMutableDictionary dictionaryWithObjectsAndKeys:@3, joyVal, @(BUTTON), joyType, nil], + UseSDL2Mapping: @YES}]; if (padnum == 0) { mutArray[dSelect][dfKey] = @9; mutArray[dStart][dfKey] = @10; @@ -154,6 +156,7 @@ void LoadPadArray(int padnum, NSDictionary *nsPrefs) curDef->DevNum = [nsPrefs[deviceNumber] charValue]; curDef->Type = [nsPrefs[padType] unsignedShortValue]; curDef->VisualVibration = [nsPrefs[VibrateOn] boolValue]; //Not implemented on OS X right now. + curDef->UseSDL2 = [nsPrefs[UseSDL2Mapping] boolValue]; //Analog buttons SetKeyFromDictionary(nsPrefs[dL3], &curDef->KeyDef[DKEY_L3]); @@ -192,7 +195,7 @@ void LoadPadArray(int padnum, NSDictionary *nsPrefs) NSDictionary *SavePadArray(int padnum) { - NSMutableDictionary *mutArray = [NSMutableDictionary dictionary]; + NSMutableDictionary *mutArray = [[NSMutableDictionary alloc] init]; PADDEF *curDef = &g.cfg.PadDef[padnum]; mutArray[deviceNumber] = @(curDef->DevNum); mutArray[padType] = @(curDef->Type); @@ -200,7 +203,6 @@ NSDictionary *SavePadArray(int padnum) switch (curDef->Type) { case PSE_PAD_TYPE_ANALOGPAD: - { mutArray[dL3] = DictionaryFromButtonDef(curDef->KeyDef[DKEY_L3]); mutArray[dR3] = DictionaryFromButtonDef(curDef->KeyDef[DKEY_R3]); mutArray[dAnalog] = DictionaryFromButtonDef(curDef->KeyDef[DKEY_ANALOG]); @@ -214,11 +216,9 @@ NSDictionary *SavePadArray(int padnum) mutArray[dRightAnalogXM] = DictionaryFromButtonDef(curDef->AnalogDef[ANALOG_RIGHT][ANALOG_XM]); mutArray[dRightAnalogYP] = DictionaryFromButtonDef(curDef->AnalogDef[ANALOG_RIGHT][ANALOG_YP]); mutArray[dRightAnalogYM] = DictionaryFromButtonDef(curDef->AnalogDef[ANALOG_RIGHT][ANALOG_YM]); - } //Fall through case PSE_PAD_TYPE_STANDARD: - { mutArray[dL1] = DictionaryFromButtonDef(curDef->KeyDef[DKEY_L1]); mutArray[dL2] = DictionaryFromButtonDef(curDef->KeyDef[DKEY_L2]); mutArray[dR1] = DictionaryFromButtonDef(curDef->KeyDef[DKEY_R1]); @@ -234,7 +234,7 @@ NSDictionary *SavePadArray(int padnum) mutArray[dCircle] = DictionaryFromButtonDef(curDef->KeyDef[DKEY_CIRCLE]); mutArray[dCross] = DictionaryFromButtonDef(curDef->KeyDef[DKEY_CROSS]); mutArray[dSquare] = DictionaryFromButtonDef(curDef->KeyDef[DKEY_SQUARE]); - } + mutArray[UseSDL2Mapping] = @((BOOL)curDef->UseSDL2); break; default: |
