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];
21 switch([radioButtons selectedRow]) {
25 if([keyInput hasKey]) {
26 TargetKeyboard* k = [[TargetKeyboard alloc] init];
27 [k setVk: [keyInput vk]];
28 [k setDescr: [keyInput descr]];
34 TargetConfig* c = [[TargetConfig alloc] init];
35 [c setConfig: [[configsController configs] objectAtIndex: [configPopup indexOfSelectedItem]]];
40 TargetMouseMove *mm = [[TargetMouseMove alloc] init];
46 TargetMouseMove *mm = [[TargetMouseMove alloc] init];
52 TargetMouseBtn *mb = [[TargetMouseBtn alloc] init];
53 [mb setWhich: [mouseBtnRadio selectedCol]];
60 -(void)configChosen:(id)sender {
61 [radioButtons setState: 1 atRow: 2 column: 0];
66 id action = [joystickController selectedAction];
68 Target* target = [self state];
69 [[configsController currentConfig] setTarget: target forAction: action];
75 [radioButtons setState: 1 atRow: 0 column: 0];
76 [self refreshConfigsPreservingSelection: NO];
79 -(void) setEnabled: (BOOL) enabled {
80 [radioButtons setEnabled: enabled];
81 [keyInput setEnabled: enabled];
82 [configPopup setEnabled: enabled];
85 return [radioButtons isEnabled];
89 id jsaction = [joystickController selectedAction];
90 currentJsaction = jsaction;
92 [self setEnabled: NO];
93 [title setStringValue: @""];
96 [self setEnabled: YES];
98 Target* target = [[configsController currentConfig] getTargetForAction: jsaction];
101 NSString* actFullName = [act name];
104 actFullName = [[NSString alloc] initWithFormat: @"%@ > %@", [act name], actFullName];
106 [title setStringValue: [[NSString alloc] initWithFormat: @"%@ > %@", [[configsController currentConfig] name], actFullName]];
110 } else if([target isKindOfClass: [TargetKeyboard class]]) {
111 [radioButtons setState:1 atRow: 1 column: 0];
112 [keyInput setVk: [(TargetKeyboard*)target vk]];
113 } else if([target isKindOfClass: [TargetConfig class]]) {
114 [radioButtons setState:1 atRow: 2 column: 0];
115 [configPopup selectItemAtIndex: [[configsController configs] indexOfObject: [(TargetConfig*)target config]]];
116 } else if ([target isKindOfClass: [TargetMouseMove class]]) {
117 if ([(TargetMouseMove *)target dir] == 0)
118 [radioButtons setState:1 atRow: 3 column: 0];
120 [radioButtons setState:1 atRow: 4 column: 0];
122 [NSException raise:@"Unknown target subclass" format:@"Unknown target subclass"];
127 [[[NSApplication sharedApplication] mainWindow] makeFirstResponder: keyInput];
130 -(void) refreshConfigsPreservingSelection: (BOOL) preserve {
131 int initialIndex = [configPopup indexOfSelectedItem];
133 NSArray* configs = [configsController configs];
134 [configPopup removeAllItems];
135 for(int i=0; i<[configs count]; i++) {
136 [configPopup addItemWithTitle: [[configs objectAtIndex:i]name]];
139 [configPopup selectItemAtIndex:initialIndex];