From c875a3566e340e366553beb2dcd6b2bcf4d5ab18 Mon Sep 17 00:00:00 2001 From: "SND\\MaddTheSane_cp" Date: Tue, 8 Apr 2014 02:33:19 +0000 Subject: DFInput: Implement SDL2 GameController support. This change allows the user to use SDL2’s GameController API instead of the Joystick API. The Game Controller API maps the buttons similar to an Xbox 360 controller, so some tricky mapping needed to be done. Note that it currently only supports OS X. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@89828 e17a0e51-4ae3-4d35-97c3-1a29b211df97 --- .../Base.lproj/NetPcsxrHIDInputPluginMain.xib | 73 ++++++++------ .../DFInput/English.lproj/Localizable.strings | 55 ---------- .../plugins/DFInput/en.lproj/Localizable.strings | 61 +++++++++++ .../en.lproj/NetPcsxrHIDInputPluginMain.strings | 6 ++ .../plugins/DFInput/fr.lproj/Localizable.strings | 13 ++- .../fr.lproj/NetPcsxrHIDInputPluginMain.strings | 6 ++ .../plugins/DFInput/hu.lproj/Localizable.strings | 10 +- .../hu.lproj/NetPcsxrHIDInputPluginMain.strings | 6 ++ macosx/plugins/DFInput/macsrc/ControllerList.h | 3 +- macosx/plugins/DFInput/macsrc/ControllerList.m | 111 +++++++++++++++------ macosx/plugins/DFInput/macsrc/MappingCell.m | 6 +- macosx/plugins/DFInput/macsrc/PadController.h | 6 +- macosx/plugins/DFInput/macsrc/PadController.m | 4 +- macosx/plugins/DFInput/macsrc/PadView.h | 4 +- macosx/plugins/DFInput/macsrc/PadView.m | 42 +++++--- macosx/plugins/DFInput/macsrc/cfg.c | 23 ++++- macosx/plugins/DFInput/macsrc/cfg.h | 2 + macosx/plugins/DFInput/macsrc/cfgHelper.m | 12 +-- .../DFInput/zh-Hans.lproj/Localizable.strings | 10 +- .../NetPcsxrHIDInputPluginMain.strings | 6 ++ 20 files changed, 308 insertions(+), 151 deletions(-) delete mode 100644 macosx/plugins/DFInput/English.lproj/Localizable.strings create mode 100644 macosx/plugins/DFInput/en.lproj/Localizable.strings (limited to 'macosx/plugins') diff --git a/macosx/plugins/DFInput/Base.lproj/NetPcsxrHIDInputPluginMain.xib b/macosx/plugins/DFInput/Base.lproj/NetPcsxrHIDInputPluginMain.xib index 1f2f45c5..e124c32a 100644 --- a/macosx/plugins/DFInput/Base.lproj/NetPcsxrHIDInputPluginMain.xib +++ b/macosx/plugins/DFInput/Base.lproj/NetPcsxrHIDInputPluginMain.xib @@ -1,8 +1,8 @@ - + - + @@ -15,31 +15,29 @@ - + - - + - - + - + - + - + - + @@ -55,15 +53,15 @@ - + - + - + @@ -82,7 +80,7 @@ - + + + @@ -279,7 +291,8 @@ Gw + - \ No newline at end of file + diff --git a/macosx/plugins/DFInput/English.lproj/Localizable.strings b/macosx/plugins/DFInput/English.lproj/Localizable.strings deleted file mode 100644 index f599d32c..00000000 --- a/macosx/plugins/DFInput/English.lproj/Localizable.strings +++ /dev/null @@ -1,55 +0,0 @@ -/* - Localizable.strings - DFInput - - Created by C.W. Betts on 11/16/11. - Copyright 2011 __MyCompanyName__. All rights reserved. - */ - -"Gamepad/Keyboard/Mouse Input" = "Gamepad/Keyboard/Mouse Input"; -"Joystick: Button %d" = "Joystick: Button %d"; -"Joystick: Axis %d%c" = "Joystick: Axis %d%c"; -"Joystick: Hat %d %s" = "Joystick: Hat %d %s"; -"Keyboard: %s" = "Keyboard: %s"; - -"(Keyboard only)" = "(Keyboard only)"; -"(Not Set)" = "(Not Set)"; - -"D-Pad Up" = "D-Pad Up"; -"D-Pad Down" = "D-Pad Down"; -"D-Pad Left" = "D-Pad Left"; -"D-Pad Right" = "D-Pad Right"; -"Cross" = "Cross"; -"Circle" = "Circle"; -"Square" = "Square"; -"Triangle" = "Triangle"; -"L1" = "L1"; -"R1" = "R1"; -"L2" = "L2"; -"R2" = "R2"; -"Select" = "Select"; -"Start" = "Start"; -"L3" = "L3"; -"R3" = "R3"; -"Analog" = "Analog"; -"L-Stick Right" = "L-Stick Right"; -"L-Stick Left" = "L-Stick Left"; -"L-Stick Down" = "L-Stick Down"; -"L-Stick Up" = "L-Stick Up"; -"R-Stick Right" = "R-Stick Right"; -"R-Stick Left" = "R-Stick Left"; -"R-Stick Down" = "R-Stick Down"; -"R-Stick Up" = "R-Stick Up"; - -//Unused right now -"Centered" = "Centered"; -"Up" = "Up"; -"Right" = "Right"; -"Rightup" = "Right-up"; -"Down" = "Down"; -"Rightdown" = "Right-down"; -"Left" = "Left"; -"Leftup" = "Left-up"; -"Leftdown" = "Left-down"; - - diff --git a/macosx/plugins/DFInput/en.lproj/Localizable.strings b/macosx/plugins/DFInput/en.lproj/Localizable.strings new file mode 100644 index 00000000..f35e8d8c --- /dev/null +++ b/macosx/plugins/DFInput/en.lproj/Localizable.strings @@ -0,0 +1,61 @@ +/* + Localizable.strings + DFInput + + Created by C.W. Betts on 11/16/11. + Copyright 2011 __MyCompanyName__. All rights reserved. + */ + +"Gamepad/Keyboard/Mouse Input" = "Gamepad/Keyboard/Mouse Input"; +"Joystick: Button %d" = "Joystick: Button %d"; +"Joystick: Axis %d%c" = "Joystick: Axis %d%c"; +"Joystick: Hat %d %s" = "Joystick: Hat %d %s"; +"Keyboard: %s" = "Keyboard: %s"; + +"(Keyboard only)" = "(Keyboard only)"; +"(Not Set)" = "(Not Set)"; + +"D-Pad Up" = "D-Pad Up"; +"D-Pad Down" = "D-Pad Down"; +"D-Pad Left" = "D-Pad Left"; +"D-Pad Right" = "D-Pad Right"; +"Cross" = "Cross"; +"Circle" = "Circle"; +"Square" = "Square"; +"Triangle" = "Triangle"; +"L1" = "L1"; +"R1" = "R1"; +"L2" = "L2"; +"R2" = "R2"; +"Select" = "Select"; +"Start" = "Start"; +"L3" = "L3"; +"R3" = "R3"; +"Analog" = "Analog"; +"L-Stick Right" = "L-Stick Right"; +"L-Stick Left" = "L-Stick Left"; +"L-Stick Down" = "L-Stick Down"; +"L-Stick Up" = "L-Stick Up"; +"R-Stick Right" = "R-Stick Right"; +"R-Stick Left" = "R-Stick Left"; +"R-Stick Down" = "R-Stick Down"; +"R-Stick Up" = "R-Stick Up"; + +// Game Controller names +"Left Bumper" = "Left Bumper"; +"Right Bumper" = "Right Bumper"; +"Left Trigger" = "Left Trigger"; +"Right Trigger" = "Right Trigger"; +"Guide" = "Guide"; +"Back" = "Back"; + +// Unused right now +"Centered" = "Centered"; +"Up" = "Up"; +"Right" = "Right"; +"Rightup" = "Right-up"; +"Down" = "Down"; +"Rightdown" = "Right-down"; +"Left" = "Left"; +"Leftup" = "Left-up"; +"Leftdown" = "Left-down"; diff --git a/macosx/plugins/DFInput/en.lproj/NetPcsxrHIDInputPluginMain.strings b/macosx/plugins/DFInput/en.lproj/NetPcsxrHIDInputPluginMain.strings index 7cb2ea27..d4225513 100644 --- a/macosx/plugins/DFInput/en.lproj/NetPcsxrHIDInputPluginMain.strings +++ b/macosx/plugins/DFInput/en.lproj/NetPcsxrHIDInputPluginMain.strings @@ -46,3 +46,9 @@ /* Class = "NSButtonCell"; title = "Cancel"; ObjectID = "262"; */ "262.title" = "Cancel"; + +/* Class = "NSButtonCell"; title = "Use Game Controller API"; ObjectID = "XyD-IN-gbq"; */ +"XyD-IN-gbq.title" = "Use Game Controller API"; + +/* Class = "NSButton"; ibShadowedToolTip = "Uses the SDL2 Game Controller API to automatically map buttons"; ObjectID = "e1h-QZ-6Ge"; */ +"e1h-QZ-6Ge.ibShadowedToolTip" = "Uses the SDL2 Game Controller API to automatically map buttons"; diff --git a/macosx/plugins/DFInput/fr.lproj/Localizable.strings b/macosx/plugins/DFInput/fr.lproj/Localizable.strings index 8370e0c2..3a7003d7 100644 --- a/macosx/plugins/DFInput/fr.lproj/Localizable.strings +++ b/macosx/plugins/DFInput/fr.lproj/Localizable.strings @@ -15,7 +15,6 @@ "(Keyboard only)" = "(Keyboard only)"; "(Not Set)" = "(Non défini)"; - "D-Pad Up" = "Pavé directionnel Haut"; "D-Pad Down" = "Pavé directionnel Bas"; "D-Pad Left" = "Pavé directionnel Gauche"; @@ -32,7 +31,7 @@ "Start" = "Start"; "L3" = "L3"; "R3" = "R3"; -//"Analog" = "Analog"; //Not translated +//"Analog" = "Analog"; // Not translated "L-Stick Right" = "L-Stick Droite"; "L-Stick Left" = "L-Stick Gauche"; "L-Stick Down" = "L-Stick Bas"; @@ -42,7 +41,15 @@ "R-Stick Down" = "R-Stick Bas"; "R-Stick Up" = "R-Stick Haut"; -//Unused right now +// Game Controller names +//"Left Bumper" = "Left Bumper"; +//"Right Bumper" = "Right Bumper"; +//"Left Trigger" = "Left Trigger"; +//"Right Trigger" = "Right Trigger"; +//"Guide" = "Guide"; +//"Back" = "Back"; + +// Unused right now "Centered" = "Centré"; "Up" = "Haut"; "Right" = "Droite"; diff --git a/macosx/plugins/DFInput/fr.lproj/NetPcsxrHIDInputPluginMain.strings b/macosx/plugins/DFInput/fr.lproj/NetPcsxrHIDInputPluginMain.strings index 7cb2ea27..bbcd4cda 100644 --- a/macosx/plugins/DFInput/fr.lproj/NetPcsxrHIDInputPluginMain.strings +++ b/macosx/plugins/DFInput/fr.lproj/NetPcsxrHIDInputPluginMain.strings @@ -46,3 +46,9 @@ /* Class = "NSButtonCell"; title = "Cancel"; ObjectID = "262"; */ "262.title" = "Cancel"; + +/* Class = "NSButtonCell"; title = "Use Game Controller API"; ObjectID = "XyD-IN-gbq"; */ +//"XyD-IN-gbq.title" = "Use Game Controller API"; + +/* Class = "NSButton"; ibShadowedToolTip = "Uses the SDL2 Game Controller API to automatically map buttons"; ObjectID = "e1h-QZ-6Ge"; */ +//"e1h-QZ-6Ge.ibShadowedToolTip" = "Uses the SDL2 Game Controller API to automatically map buttons"; diff --git a/macosx/plugins/DFInput/hu.lproj/Localizable.strings b/macosx/plugins/DFInput/hu.lproj/Localizable.strings index 1b90d583..a1da569d 100644 --- a/macosx/plugins/DFInput/hu.lproj/Localizable.strings +++ b/macosx/plugins/DFInput/hu.lproj/Localizable.strings @@ -41,7 +41,15 @@ "R-Stick Down" = "Jobb kar le"; "R-Stick Up" = "Jobb kar fel"; -//Unused right now +// Game Controller names +//"Left Bumper" = "Left Bumper"; +//"Right Bumper" = "Right Bumper"; +//"Left Trigger" = "Left Trigger"; +//"Right Trigger" = "Right Trigger"; +//"Guide" = "Guide"; +//"Back" = "Back"; + +// Unused right now "Centered" = "Középen"; "Up" = "Fel"; "Right" = "Jobbra"; diff --git a/macosx/plugins/DFInput/hu.lproj/NetPcsxrHIDInputPluginMain.strings b/macosx/plugins/DFInput/hu.lproj/NetPcsxrHIDInputPluginMain.strings index 7cb2ea27..bbcd4cda 100644 --- a/macosx/plugins/DFInput/hu.lproj/NetPcsxrHIDInputPluginMain.strings +++ b/macosx/plugins/DFInput/hu.lproj/NetPcsxrHIDInputPluginMain.strings @@ -46,3 +46,9 @@ /* Class = "NSButtonCell"; title = "Cancel"; ObjectID = "262"; */ "262.title" = "Cancel"; + +/* Class = "NSButtonCell"; title = "Use Game Controller API"; ObjectID = "XyD-IN-gbq"; */ +//"XyD-IN-gbq.title" = "Use Game Controller API"; + +/* Class = "NSButton"; ibShadowedToolTip = "Uses the SDL2 Game Controller API to automatically map buttons"; ObjectID = "e1h-QZ-6Ge"; */ +//"e1h-QZ-6Ge.ibShadowedToolTip" = "Uses the SDL2 Game Controller API to automatically map buttons"; 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 +@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: diff --git a/macosx/plugins/DFInput/zh-Hans.lproj/Localizable.strings b/macosx/plugins/DFInput/zh-Hans.lproj/Localizable.strings index 4771519a..6752dc00 100644 --- a/macosx/plugins/DFInput/zh-Hans.lproj/Localizable.strings +++ b/macosx/plugins/DFInput/zh-Hans.lproj/Localizable.strings @@ -41,7 +41,15 @@ "R-Stick Down" = "R-摇杆 ↓ / 下"; "R-Stick Up" = "R-摇杆 ↑ / 上"; -//Unused right now +// Game Controller names +//"Left Bumper" = "Left Bumper"; +//"Right Bumper" = "Right Bumper"; +//"Left Trigger" = "Left Trigger"; +//"Right Trigger" = "Right Trigger"; +//"Guide" = "Guide"; +//"Back" = "Back"; + +// Unused right now "Centered" = "中间键"; "Up" = "↑ / 上"; "Right" = "→ / 右"; diff --git a/macosx/plugins/DFInput/zh-Hans.lproj/NetPcsxrHIDInputPluginMain.strings b/macosx/plugins/DFInput/zh-Hans.lproj/NetPcsxrHIDInputPluginMain.strings index ed862535..1eab959d 100644 --- a/macosx/plugins/DFInput/zh-Hans.lproj/NetPcsxrHIDInputPluginMain.strings +++ b/macosx/plugins/DFInput/zh-Hans.lproj/NetPcsxrHIDInputPluginMain.strings @@ -46,3 +46,9 @@ /* Class = "NSButtonCell"; title = "取消"; ObjectID = "262"; */ "262.title" = "取消"; + +/* Class = "NSButtonCell"; title = "Use Game Controller API"; ObjectID = "XyD-IN-gbq"; */ +//"XyD-IN-gbq.title" = "Use Game Controller API"; + +/* Class = "NSButton"; ibShadowedToolTip = "Uses the SDL2 Game Controller API to automatically map buttons"; ObjectID = "e1h-QZ-6Ge"; */ +//"e1h-QZ-6Ge.ibShadowedToolTip" = "Uses the SDL2 Game Controller API to automatically map buttons"; -- cgit v1.2.3