X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=TargetController.m;h=1da2c99a6e7157f038ac8d13a5eb6fa8a6cacab3;hp=9aad491d17eb41a936d21e08f37e4eda7ef781fe;hb=e2a4d830dd9817f6a515a3b1b6aa152d3bb98c2b;hpb=62aa5b73be6ec1e499e6b155cd0e7687c338cbaa diff --git a/TargetController.m b/TargetController.m index 9aad491..1da2c99 100644 --- a/TargetController.m +++ b/TargetController.m @@ -7,11 +7,11 @@ #import "TargetController.h" -#import "ConfigsController.h" -#import "Config.h" -#import "JSAction.h" -#import "JoystickController.h" -#import "KeyInputTextView.h" +#import "NJMappingsController.h" +#import "NJMapping.h" +#import "NJInput.h" +#import "NJInputController.h" +#import "NJKeyInputField.h" #import "TargetConfig.h" #import "TargetController.h" #import "TargetKeyboard.h" @@ -26,15 +26,15 @@ NSInteger row = radioButtons.selectedRow; if (row != 1) { - keyInput.vk = -1; + keyInput.keyCode = -1; [keyInput resignIfFirstResponder]; } if (row != 2) { - [configPopup selectItemAtIndex:-1]; - [configPopup resignIfFirstResponder]; - } else if (!configPopup.selectedItem) - [configPopup selectItemAtIndex:0]; + [mappingPopup selectItemAtIndex:-1]; + [mappingPopup resignIfFirstResponder]; + } else if (!mappingPopup.selectedItem) + [mappingPopup selectItemAtIndex:0]; if (row != 3) { mouseDirSelect.selectedSegment = -1; @@ -62,15 +62,20 @@ [self commit]; } -- (void)keyChanged { +- (void)keyInputField:(NJKeyInputField *)keyInput didChangeKey:(CGKeyCode)keyCode { [radioButtons selectCellAtRow:1 column:0]; [radioButtons.window makeFirstResponder:radioButtons]; [self commit]; } -- (void)configChosen:(id)sender { +- (void)keyInputFieldDidClear:(NJKeyInputField *)keyInput { + [radioButtons selectCellAtRow:0 column:0]; + [self commit]; +} + +- (void)mappingChosen:(id)sender { [radioButtons selectCellAtRow:2 column:0]; - [configPopup.window makeFirstResponder:configPopup]; + [mappingPopup.window makeFirstResponder:mappingPopup]; [self commit]; } @@ -93,7 +98,7 @@ } - (Target *)currentTarget { - return configsController.currentConfig[joystickController.selectedAction]; + return mappingsController.currentMapping[joystickController.selectedInput]; } - (Target *)makeTarget { @@ -101,9 +106,9 @@ case 0: return nil; case 1: - if (keyInput.hasKey) { + if (keyInput.hasKeyCode) { TargetKeyboard *k = [[TargetKeyboard alloc] init]; - k.vk = keyInput.vk; + k.vk = keyInput.keyCode; return k; } else { return nil; @@ -111,7 +116,7 @@ break; case 2: { TargetConfig *c = [[TargetConfig alloc] init]; - c.config = configsController.configs[configPopup.indexOfSelectedItem]; + c.mapping = mappingsController.mappings[mappingPopup.indexOfSelectedItem]; return c; } case 3: { @@ -140,8 +145,8 @@ - (void)commit { [self cleanUpInterface]; - configsController.currentConfig[joystickController.selectedAction] = [self makeTarget]; - [configsController save]; + mappingsController.currentMapping[joystickController.selectedInput] = [self makeTarget]; + [mappingsController save]; } - (BOOL)enabled { @@ -151,46 +156,51 @@ - (void)setEnabled:(BOOL)enabled { [radioButtons setEnabled:enabled]; [keyInput setEnabled:enabled]; - [configPopup setEnabled:enabled]; + [mappingPopup setEnabled:enabled]; [mouseDirSelect setEnabled:enabled]; [mouseBtnSelect setEnabled:enabled]; [scrollDirSelect setEnabled:enabled]; } -- (void)loadTarget:(Target *)target forAction:(JSAction *)action { - if (!action) { +- (void)loadTarget:(Target *)target forInput:(NJInput *)input { + if (!input) { self.enabled = NO; title.stringValue = @""; } else { self.enabled = YES; - NSString *actFullName = action.name; - for (JSAction *cur = action.base; cur; cur = cur.base) { - actFullName = [[NSString alloc] initWithFormat:@"%@ > %@", cur.name, actFullName]; + NSString *inpFullName = input.name; + for (id cur = input.base; cur; cur = cur.base) { + inpFullName = [[NSString alloc] initWithFormat:@"%@ > %@", cur.name, inpFullName]; } - title.stringValue = [[NSString alloc] initWithFormat:@"%@ > %@", configsController.currentConfig.name, actFullName]; + title.stringValue = [[NSString alloc] initWithFormat:@"%@ > %@", mappingsController.currentMapping.name, inpFullName]; } - if ([target isKindOfClass:[TargetKeyboard class]]) { + if ([target isKindOfClass:TargetKeyboard.class]) { [radioButtons selectCellAtRow:1 column:0]; - keyInput.vk = [(TargetKeyboard*)target vk]; - } else if ([target isKindOfClass:[TargetConfig class]]) { + keyInput.keyCode = [(TargetKeyboard*)target vk]; + } else if ([target isKindOfClass:TargetConfig.class]) { [radioButtons selectCellAtRow:2 column:0]; - [configPopup selectItemAtIndex:[configsController.configs - indexOfObject:[(TargetConfig *)target config]]]; + NSUInteger idx = [mappingsController.mappings + indexOfObject:[(TargetConfig *)target mapping]]; + if (idx == NSNotFound) { + [radioButtons selectCellAtRow:self.enabled ? 0 : -1 column:0]; + [mappingPopup selectItemAtIndex:-1]; + } else + [mappingPopup selectItemAtIndex:idx]; } - else if ([target isKindOfClass:[TargetMouseMove class]]) { + else if ([target isKindOfClass:TargetMouseMove.class]) { [radioButtons selectCellAtRow:3 column:0]; [mouseDirSelect setSelectedSegment:[(TargetMouseMove *)target axis]]; } - else if ([target isKindOfClass:[TargetMouseBtn class]]) { + else if ([target isKindOfClass:TargetMouseBtn.class]) { [radioButtons selectCellAtRow:4 column:0]; mouseBtnSelect.selectedSegment = [(TargetMouseBtn *)target button] == kCGMouseButtonLeft ? 0 : 1; } - else if ([target isKindOfClass:[TargetMouseScroll class]]) { + else if ([target isKindOfClass:TargetMouseScroll.class]) { [radioButtons selectCellAtRow:5 column:0]; scrollDirSelect.selectedSegment = [(TargetMouseScroll *)target amount] > 0; } - else if ([target isKindOfClass:[TargetToggleMouseScope class]]) { + else if ([target isKindOfClass:TargetToggleMouseScope.class]) { [radioButtons selectCellAtRow:6 column:0]; } else { [radioButtons selectCellAtRow:self.enabled ? 0 : -1 column:0]; @@ -199,7 +209,7 @@ } - (void)loadCurrent { - [self loadTarget:[self currentTarget] forAction:joystickController.selectedAction]; + [self loadTarget:self.currentTarget forInput:joystickController.selectedInput]; } - (void)focusKey { @@ -209,13 +219,17 @@ [keyInput resignIfFirstResponder]; } -- (void)refreshConfigs { - // TODO: This doesn't work when removing configs. - NSInteger initialIndex = configPopup.indexOfSelectedItem; - [configPopup removeAllItems]; - for (Config *config in configsController.configs) - [configPopup addItemWithTitle:config.name]; - [configPopup selectItemAtIndex:initialIndex]; +- (void)refreshMappings { + NSInteger initialIndex = mappingPopup.indexOfSelectedItem; + [mappingPopup.menu removeAllItems]; + for (NJMapping *mapping in mappingsController.mappings) { + NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:mapping.name + action:@selector(mappingChosen:) + keyEquivalent:@""]; + item.target = self; + [mappingPopup.menu addItem:item]; + } + [mappingPopup selectItemAtIndex:initialIndex]; } @end