X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=Classes%2FNJInputHat.m;h=b4506d4b44126f758dee872be2dc932b19c20791;hp=e0e127fec646b6d4b15e51b144cede49ede7c0b2;hb=HEAD;hpb=0064c1fbff36795885a9724081af2a17d83c20a3 diff --git a/Classes/NJInputHat.m b/Classes/NJInputHat.m index e0e127f..b4506d4 100644 --- a/Classes/NJInputHat.m +++ b/Classes/NJInputHat.m @@ -27,22 +27,38 @@ static BOOL active_fourway[20] = { NO, NO, YES, NO , // W }; -@implementation NJInputHat +@implementation NJInputHat { + CFIndex _max; +} -- (id)initWithIndex:(int)index { - if ((self = [super init])) { - self.children = @[[[NJInput alloc] initWithName:@"Up" base:self], - [[NJInput alloc] initWithName:@"Down" base:self], - [[NJInput alloc] initWithName:@"Left" base:self], - [[NJInput alloc] initWithName:@"Right" base:self]]; - self.name = [NSString stringWithFormat:@"Hat Switch %d", index]; +- (id)initWithElement:(IOHIDElementRef)element + index:(int)index + parent:(NJInputPathElement *)parent +{ + if ((self = [super initWithName:NJINPUT_NAME(NSLocalizedString(@"hat switch %d", @"hat switch name"), index) + eid:NJINPUT_EID("Hat Switch", index) + element:element + parent:parent])) { + self.children = @[[[NJInput alloc] initWithName:NSLocalizedString(@"hat up", @"hat switch up state") + eid:@"Up" + parent:self], + [[NJInput alloc] initWithName:NSLocalizedString(@"hat down", @"hat switch down state") + eid:@"Down" + parent:self], + [[NJInput alloc] initWithName:NSLocalizedString(@"hat left", @"hat switch left state") + eid:@"Left" + parent:self], + [[NJInput alloc] initWithName:NSLocalizedString(@"hat right", @"hat switch right state") + eid:@"Right" + parent:self]]; + _max = IOHIDElementGetLogicalMax(element); } return self; } - (id)findSubInputForValue:(IOHIDValueRef)value { long parsed = IOHIDValueGetIntegerValue(value); - switch (IOHIDElementGetLogicalMax(IOHIDValueGetElement(value))) { + switch (_max) { case 7: // 8-way switch, 0-7. switch (parsed) { case 0: return self.children[0]; @@ -82,7 +98,7 @@ static BOOL active_fourway[20] = { - (void)notifyEvent:(IOHIDValueRef)value { long parsed = IOHIDValueGetIntegerValue(value); - long size = IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)); + long size = _max; // Skip first row in table if 0 is not neutral. if (size & 1) { parsed++;