X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=NJOutputController.m;h=f3eca24b79c50a6857e45e0f60214bf8a5b10196;hp=f05c615ddc7dd0b10f17e69c766507208e824e74;hb=48186896d41ccb345e4678c53ab1480059c12d3d;hpb=dcedf147ddcb6c21768cea94a2f06b93007d2a82 diff --git a/NJOutputController.m b/NJOutputController.m index f05c615..f3eca24 100644 --- a/NJOutputController.m +++ b/NJOutputController.m @@ -10,7 +10,8 @@ #import "NJMappingsController.h" #import "NJMapping.h" #import "NJInput.h" -#import "NJInputController.h" +#import "NJEvents.h" +#import "NJDeviceController.h" #import "NJKeyInputField.h" #import "NJOutputMapping.h" #import "NJOutputController.h" @@ -22,11 +23,26 @@ @implementation NJOutputController +- (id)init { + if ((self = [super init])) { + [NSNotificationCenter.defaultCenter + addObserver:self + selector:@selector(mappingListDidChange:) + name:NJEventMappingListChanged + object:nil]; + } + return self; +} + +- (void)dealloc { + [NSNotificationCenter.defaultCenter removeObserver:self]; +} + - (void)cleanUpInterface { NSInteger row = radioButtons.selectedRow; if (row != 1) { - keyInput.keyCode = -1; + keyInput.keyCode = NJKeyInputFieldEmpty; [keyInput resignIfFirstResponder]; } @@ -38,9 +54,14 @@ if (row != 3) { mouseDirSelect.selectedSegment = -1; + mouseSpeedSlider.floatValue = mouseSpeedSlider.minValue; [mouseDirSelect resignIfFirstResponder]; - } else if (mouseDirSelect.selectedSegment == -1) - mouseDirSelect.selectedSegment = 0; + } else { + if (mouseDirSelect.selectedSegment == -1) + mouseDirSelect.selectedSegment = 0; + if (!mouseSpeedSlider.floatValue) + mouseSpeedSlider.floatValue = 4; + } if (row != 4) { mouseBtnSelect.selectedSegment = -1; @@ -50,9 +71,19 @@ if (row != 5) { scrollDirSelect.selectedSegment = -1; + scrollSpeedSlider.floatValue = scrollSpeedSlider.minValue; [scrollDirSelect resignIfFirstResponder]; - } else if (scrollDirSelect.selectedSegment == -1) - scrollDirSelect.selectedSegment = 0; + } else { + if (scrollDirSelect.selectedSegment == -1) + scrollDirSelect.selectedSegment = 0; + if (scrollDirSelect.selectedSegment < 2 + && !scrollSpeedSlider.floatValue) + scrollSpeedSlider.floatValue = 15.f; + else if (scrollDirSelect.selectedSegment >= 2 + && scrollSpeedSlider.floatValue) + scrollSpeedSlider.floatValue = scrollSpeedSlider.minValue; + } + } - (IBAction)radioChanged:(NSView *)sender { @@ -85,6 +116,12 @@ [self commit]; } +- (void)mouseSpeedChanged:(NSSlider *)sender { + [radioButtons selectCellAtRow:3 column:0]; + [sender.window makeFirstResponder:sender]; + [self commit]; +} + - (void)mbtnChanged:(NSView *)sender { [radioButtons selectCellAtRow:4 column:0]; [sender.window makeFirstResponder:sender]; @@ -97,6 +134,16 @@ [self commit]; } +- (void)scrollSpeedChanged:(NSSlider *)sender { + [radioButtons selectCellAtRow:5 column:0]; + [sender.window makeFirstResponder:sender]; + if (!sender.floatValue && scrollDirSelect.selectedSegment < 2) + scrollDirSelect.selectedSegment += 2; + else if (sender.floatValue && scrollDirSelect.selectedSegment >= 2) + scrollDirSelect.selectedSegment -= 2; + [self commit]; +} + - (NJOutput *)currentOutput { return mappingsController.currentMapping[inputController.selectedInput]; } @@ -116,12 +163,13 @@ break; case 2: { NJOutputMapping *c = [[NJOutputMapping alloc] init]; - c.mapping = mappingsController.mappings[mappingPopup.indexOfSelectedItem]; + c.mapping = mappingsController[mappingPopup.indexOfSelectedItem]; return c; } case 3: { NJOutputMouseMove *mm = [[NJOutputMouseMove alloc] init]; mm.axis = mouseDirSelect.selectedSegment; + mm.speed = mouseSpeedSlider.floatValue; return mm; } case 4: { @@ -131,7 +179,10 @@ } case 5: { NJOutputMouseScroll *ms = [[NJOutputMouseScroll alloc] init]; - ms.amount = scrollDirSelect.selectedSegment ? 1 : -1; + ms.direction = (scrollDirSelect.selectedSegment & 1) ? 1 : -1; + ms.speed = scrollDirSelect.selectedSegment < 2 + ? scrollSpeedSlider.floatValue + : 0.f; return ms; } case 6: { @@ -158,6 +209,7 @@ [keyInput setEnabled:enabled]; [mappingPopup setEnabled:enabled]; [mouseDirSelect setEnabled:enabled]; + [mouseSpeedSlider setEnabled:enabled]; [mouseBtnSelect setEnabled:enabled]; [scrollDirSelect setEnabled:enabled]; } @@ -172,7 +224,7 @@ for (id cur = input.base; cur; cur = cur.base) { inpFullName = [[NSString alloc] initWithFormat:@"%@ > %@", cur.name, inpFullName]; } - title.stringValue = [[NSString alloc] initWithFormat:@"%@ > %@", mappingsController.currentMapping.name, inpFullName]; + title.stringValue = inpFullName; } if ([output isKindOfClass:NJOutputKeyPress.class]) { @@ -180,17 +232,15 @@ keyInput.keyCode = [(NJOutputKeyPress*)output vk]; } else if ([output isKindOfClass:NJOutputMapping.class]) { [radioButtons selectCellAtRow:2 column:0]; - NSUInteger idx = [mappingsController.mappings - indexOfObject:[(NJOutputMapping *)output mapping]]; - if (idx == NSNotFound) { + NSMenuItem *item = [mappingPopup itemWithRepresentedObject:[(NJOutputMapping *)output mapping]]; + [mappingPopup selectItem:item]; + if (!item) [radioButtons selectCellAtRow:self.enabled ? 0 : -1 column:0]; - [mappingPopup selectItemAtIndex:-1]; - } else - [mappingPopup selectItemAtIndex:idx]; } else if ([output isKindOfClass:NJOutputMouseMove.class]) { [radioButtons selectCellAtRow:3 column:0]; - [mouseDirSelect setSelectedSegment:[(NJOutputMouseMove *)output axis]]; + mouseDirSelect.selectedSegment = [(NJOutputMouseMove *)output axis]; + mouseSpeedSlider.floatValue = [(NJOutputMouseMove *)output speed]; } else if ([output isKindOfClass:NJOutputMouseButton.class]) { [radioButtons selectCellAtRow:4 column:0]; @@ -198,7 +248,10 @@ } else if ([output isKindOfClass:NJOutputMouseScroll.class]) { [radioButtons selectCellAtRow:5 column:0]; - scrollDirSelect.selectedSegment = [(NJOutputMouseScroll *)output amount] > 0; + int direction = [(NJOutputMouseScroll *)output direction]; + float speed = [(NJOutputMouseScroll *)output speed]; + scrollDirSelect.selectedSegment = (direction > 0) + !speed * 2; + scrollSpeedSlider.floatValue = speed; } else if ([output isKindOfClass:NJOutputSwitchMouseMode.class]) { [radioButtons selectCellAtRow:6 column:0]; @@ -219,17 +272,19 @@ [keyInput resignIfFirstResponder]; } -- (void)refreshMappings { - NSInteger initialIndex = mappingPopup.indexOfSelectedItem; +- (void)mappingListDidChange:(NSNotification *)note { + NSArray *mappings = note.object; + NJMapping *current = mappingPopup.selectedItem.representedObject; [mappingPopup.menu removeAllItems]; - for (NJMapping *mapping in mappingsController.mappings) { + for (NJMapping *mapping in mappings) { NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:mapping.name action:@selector(mappingChosen:) keyEquivalent:@""]; item.target = self; + item.representedObject = mapping; [mappingPopup.menu addItem:item]; } - [mappingPopup selectItemAtIndex:initialIndex]; + [mappingPopup selectItemWithRepresentedObject:current]; } @end