summaryrefslogtreecommitdiff
path: root/macosx/plugins/HIDInput/src/ControllerList.m
diff options
context:
space:
mode:
authorSND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2009-10-24 03:15:42 +0000
committerSND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2009-10-24 03:15:42 +0000
commit5408345d8b1cde19a19ddf324d3439ead6e80709 (patch)
treefd7934308384396b4ad92b547e8804a696c480e8 /macosx/plugins/HIDInput/src/ControllerList.m
parentf2f1033882e0643f05f3027f2c812f425f67a879 (diff)
downloadpcsxr-5408345d8b1cde19a19ddf324d3439ead6e80709.tar.gz
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@32699 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'macosx/plugins/HIDInput/src/ControllerList.m')
-rw-r--r--macosx/plugins/HIDInput/src/ControllerList.m245
1 files changed, 245 insertions, 0 deletions
diff --git a/macosx/plugins/HIDInput/src/ControllerList.m b/macosx/plugins/HIDInput/src/ControllerList.m
new file mode 100644
index 00000000..21fc9acf
--- /dev/null
+++ b/macosx/plugins/HIDInput/src/ControllerList.m
@@ -0,0 +1,245 @@
+/***************************************************************************
+ ControllerList.m
+ HIDInput
+
+ Created by Gil Pedersen on Mon May 03 2004.
+ Copyright (c) 2004 Gil Pedersen.
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. See also the license.txt file for *
+ * additional informations. *
+ * *
+ ***************************************************************************/
+
+#import "ControllerList.h"
+
+@implementation ControllerList
+
+- (id)initWithConfig:(KeyConfig *)keyconfig
+{
+ if (!(self = [super init]) || nil == keyconfig)
+ return nil;
+
+ config = keyconfig;
+
+ /* load keyinfo plist */
+ NSString *path = [[NSBundle bundleWithIdentifier:@"net.pcsx.HIDInputPlugin"] pathForResource:@"psxKeys" ofType:@"plist"];
+ NSData *plistData;
+ NSString *error;
+ int i;
+
+ plistData = [NSData dataWithContentsOfFile:path];
+ plist = [NSPropertyListSerialization propertyListFromData:plistData
+ mutabilityOption:NSPropertyListImmutable
+ format:nil
+ errorDescription:&error];
+ if(!plist)
+ {
+ NSLog(error);
+ [error release];
+ return nil;
+ }
+
+ [plist retain];
+ //[plistData retain];
+
+ /* build typelist */
+ NSMutableArray *tmpList = [NSMutableArray arrayWithCapacity:[plist count]];
+ for (i=0; i<[plist count]; i++) {
+ id name = [plist objectAtIndex:i];
+ if ([name isKindOfClass:[NSString class]]) {
+ [tmpList addObject:name];
+ }
+ }
+ typeList = [[NSArray alloc] initWithArray:tmpList];
+
+ return self;
+}
+
+- (void)dealloc
+{
+ [typeList release];
+
+ //[plistData release];
+ [plist release];
+ //[currentSet release];
+}
+
+
+
+/*
+- (NSString *)typeDefaultKey
+{
+ return [NSString stringWithFormat:@"TypeForPad%iSet%@", currentController, [[NSUserDefaults standardUserDefaults] stringForKey:@"CurrentPadSet"]];
+}
+
+- (void)setType:(NSString *)aType
+{
+ if (type)
+ [type release];
+ if (keys)
+ [keys release];
+
+ type = aType ? [aType retain] : [typeList objectAtIndex:0];
+ keys = [[plist objectForKey:type] objectForKey:@"Buttons"];
+ if (keys)
+ [keys retain];
+
+ [[NSUserDefaults standardUserDefaults] setObject:type forKey:[self typeDefaultKey]];
+}
+*/
+- (NSArray *)controllerTypes
+{
+ return typeList;
+}
+/*
+- (NSString *)controllerType
+{
+ return type;
+}*/
+
+- (NSDictionary *)dictForType:(NSString *)type
+{
+ int index = [plist indexOfObject:type];
+ if (NSNotFound == index)
+ return [NSDictionary dictionary];
+
+ id dict = [plist objectAtIndex:index+1];
+ if (![dict isKindOfClass:[NSDictionary class]])
+ return [NSDictionary dictionary];
+
+ return dict;
+}
+
+- (NSArray *)elementsForType:(NSString *)type
+{
+ return [[self dictForType:type] objectForKey:@"Elements"];
+}
+
+- (NSString *)elementNameAtIndex:(int)index type:(NSString *)type
+{
+ if (nil == type || index < 0)
+ return @"";
+
+ NSArray *list = [self elementsForType:type];
+ if (index*2 >= [list count])
+ return @"";
+
+ return [list objectAtIndex:index*2];
+}
+
+- (int)elementCountForType:(NSString *)type
+{
+ if (nil == type)
+ return 0;
+
+ return [[self elementsForType:type] count]/2;
+}
+
+- (int)controllerTypeIdForType:(NSString *)type
+{
+ if (nil == type)
+ return 0;
+
+ NSNumber *number = [[self dictForType:type] objectForKey:@"Type ID"];
+ if (nil == number)
+ return 0;
+
+ return [number intValue];
+}
+
+- (int)buttonIdAtIndex:(int)index type:(NSString *)type
+{
+ if (nil == type || index < 0)
+ return -1;
+
+ NSDictionary *dict = [[self elementsForType:type] objectAtIndex:index*2+1];
+ NSNumber *number = [dict objectForKey:@"Button"];
+ if (nil == number)
+ return -1;
+
+ return [number intValue];
+}
+
+- (int)axisIdAtIndex:(int)index type:(NSString *)type
+{
+ if (nil == type || index < 0)
+ return -1;
+
+ NSDictionary *dict = [[self elementsForType:type] objectAtIndex:index*2+1];
+ NSNumber *number = [dict objectForKey:@"Axis"];
+ if (nil == number)
+ return -1;
+
+ return [number intValue];
+}
+
+- (int)axisDirectionAtIndex:(int)index type:(NSString *)type
+{
+ if (nil == type || index < 0)
+ return -1;
+
+ NSDictionary *dict = [[self elementsForType:type] objectAtIndex:index*2+1];
+ NSNumber *number = [dict objectForKey:@"Axis-Positive"];
+ if (nil == number)
+ return 1;
+
+ return [number boolValue] ? 1 : -1;
+}
+
+- (NSArray *)defaultMappingsAtIndex:(int)index type:(NSString *)type
+{
+ if (nil == type || index < 0)
+ return -1;
+
+ NSDictionary *dict = [[self elementsForType:type] objectAtIndex:index*2+1];
+ return [dict objectForKey:@"Default Mappings"];
+}
+
+
+/* sets current controller data returned by data source */
+- (void)setCurrentController:(int)which
+{
+ currentController = which;
+}
+
+- (int)currentController
+{
+ return currentController;
+}
+
+/* NSDataSource */
+- (int)numberOfRowsInTableView:(NSTableView *)aTableView
+{
+ return [self elementCountForType:[config currentTypeForPlayer:currentController]];
+}
+
+- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn
+ row:(int)rowIndex
+{
+ NSString *type = [config currentTypeForPlayer:currentController];
+ if (type) {
+ NSString *name = [self elementNameAtIndex:rowIndex type:type];
+
+ if ([((NSString *)[aTableColumn identifier]) isEqualToString:@"key"])
+ return NSLocalizedString(name, @"");
+ else {
+ // actual keys
+ NSString *mappingName = [config mappingNamesForElement:name player:currentController];
+ if (nil == mappingName) {
+ return @"";
+ //return NSLocalizedString(@"Double-Click to Set", @"");
+ }
+ return mappingName;
+ }
+ }
+
+ return @"";
+}
+
+@end