5 // Created by Sam McCall on 5/05/09.
8 @implementation TargetController
11 [radioButtons setState: 1 atRow: 1 column: 0 ];
14 -(IBAction)radioChanged:(id)sender {
15 [[[NSApplication sharedApplication] mainWindow] makeFirstResponder: sender];
18 -(IBAction)mbtnChanged:(id)sender {
19 [radioButtons setState: 1 atRow: 5 column: 0];
20 [[[NSApplication sharedApplication] mainWindow] makeFirstResponder: sender];
26 switch([radioButtons selectedRow]) {
30 if([keyInput hasKey]) {
31 TargetKeyboard* k = [[TargetKeyboard alloc] init];
32 [k setVk: [keyInput vk]];
33 [k setDescr: [keyInput descr]];
39 TargetConfig* c = [[TargetConfig alloc] init];
40 [c setConfig: [[configsController configs] objectAtIndex: [configPopup indexOfSelectedItem]]];
45 TargetMouseMove *mm = [[TargetMouseMove alloc] init];
51 TargetMouseMove *mm = [[TargetMouseMove alloc] init];
57 TargetMouseBtn *mb = [[TargetMouseBtn alloc] init];
58 if ([mouseBtnSelect selectedSegment] == 0) {
59 [mb setWhich: kCGMouseButtonLeft];
62 [mb setWhich: kCGMouseButtonRight];
70 -(void)configChosen:(id)sender {
71 [radioButtons setState: 1 atRow: 2 column: 0];
76 id action = [joystickController selectedAction];
78 Target* target = [self state];
79 [[configsController currentConfig] setTarget: target forAction: action];
85 [radioButtons setState: 1 atRow: 0 column: 0];
86 [mouseBtnSelect setSelectedSegment: 0];
87 [self refreshConfigsPreservingSelection: NO];
90 -(void) setEnabled: (BOOL) enabled {
91 [radioButtons setEnabled: enabled];
92 [keyInput setEnabled: enabled];
93 [configPopup setEnabled: enabled];
94 [mouseBtnSelect setEnabled: enabled];
97 return [radioButtons isEnabled];
101 id jsaction = [joystickController selectedAction];
102 currentJsaction = jsaction;
104 [self setEnabled: NO];
105 [title setStringValue: @""];
108 [self setEnabled: YES];
110 Target* target = [[configsController currentConfig] getTargetForAction: jsaction];
113 NSString* actFullName = [act name];
116 actFullName = [[NSString alloc] initWithFormat: @"%@ > %@", [act name], actFullName];
118 [title setStringValue: [[NSString alloc] initWithFormat: @"%@ > %@", [[configsController currentConfig] name], actFullName]];
122 } else if([target isKindOfClass: [TargetKeyboard class]]) {
123 [radioButtons setState:1 atRow: 1 column: 0];
124 [keyInput setVk: [(TargetKeyboard*)target vk]];
125 } else if([target isKindOfClass: [TargetConfig class]]) {
126 [radioButtons setState:1 atRow: 2 column: 0];
127 [configPopup selectItemAtIndex: [[configsController configs] indexOfObject: [(TargetConfig*)target config]]];
129 else if ([target isKindOfClass: [TargetMouseMove class]]) {
130 if ([(TargetMouseMove *)target dir] == 0)
131 [radioButtons setState:1 atRow: 3 column: 0];
133 [radioButtons setState:1 atRow: 4 column: 0];
135 else if ([target isKindOfClass: [TargetMouseBtn class]]) {
136 [radioButtons setState: 1 atRow: 5 column: 0];
137 if ([(TargetMouseBtn *)target which] == kCGMouseButtonLeft)
138 [mouseBtnSelect setSelectedSegment: 0];
140 [mouseBtnSelect setSelectedSegment: 1];
142 [NSException raise:@"Unknown target subclass" format:@"Unknown target subclass"];
147 [[[NSApplication sharedApplication] mainWindow] makeFirstResponder: keyInput];
150 -(void) refreshConfigsPreservingSelection: (BOOL) preserve {
151 int initialIndex = [configPopup indexOfSelectedItem];
153 NSArray* configs = [configsController configs];
154 [configPopup removeAllItems];
155 for(int i=0; i<[configs count]; i++) {
156 [configPopup addItemWithTitle: [[configs objectAtIndex:i]name]];
159 [configPopup selectItemAtIndex:initialIndex];