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)mdirChanged:(id)sender {
19 [radioButtons setState: 1 atRow: 3 column: 0];
20 [[[NSApplication sharedApplication] mainWindow] makeFirstResponder: sender];
23 -(IBAction)mbtnChanged:(id)sender {
24 [radioButtons setState: 1 atRow: 4 column: 0];
25 [[[NSApplication sharedApplication] mainWindow] makeFirstResponder: sender];
28 -(IBAction)sdirChanged:(id)sender {
29 [radioButtons setState: 1 atRow: 5 column: 0];
30 [[[NSApplication sharedApplication] mainWindow] makeFirstResponder: sender];
36 switch([radioButtons selectedRow]) {
40 if([keyInput hasKey]) {
41 TargetKeyboard* k = [[TargetKeyboard alloc] init];
42 [k setVk: [keyInput vk]];
43 [k setDescr: [keyInput descr]];
49 TargetConfig* c = [[TargetConfig alloc] init];
50 [c setConfig: [[configsController configs] objectAtIndex: [configPopup indexOfSelectedItem]]];
55 TargetMouseMove *mm = [[TargetMouseMove alloc] init];
56 [mm setDir: [mouseDirSelect selectedSegment]];
61 TargetMouseBtn *mb = [[TargetMouseBtn alloc] init];
62 if ([mouseBtnSelect selectedSegment] == 0) {
63 [mb setWhich: kCGMouseButtonLeft];
66 [mb setWhich: kCGMouseButtonRight];
72 TargetMouseScroll *ms = [[TargetMouseScroll alloc] init];
73 if ([scrollDirSelect selectedSegment] == 0) {
83 TargetToggleMouseScope *tms = [[TargetToggleMouseScope alloc] init];
90 -(void)configChosen:(id)sender {
91 [radioButtons setState: 1 atRow: 2 column: 0];
96 id action = [joystickController selectedAction];
98 Target* target = [self state];
99 [[configsController currentConfig] setTarget: target forAction: action];
105 [radioButtons setState: 1 atRow: 0 column: 0];
106 [mouseDirSelect setSelectedSegment: 0];
107 [mouseBtnSelect setSelectedSegment: 0];
108 [scrollDirSelect setSelectedSegment: 0];
109 [self refreshConfigsPreservingSelection: NO];
112 -(void) setEnabled: (BOOL) enabled {
113 [radioButtons setEnabled: enabled];
114 [keyInput setEnabled: enabled];
115 [configPopup setEnabled: enabled];
116 [mouseDirSelect setEnabled: enabled];
117 [mouseBtnSelect setEnabled: enabled];
118 [scrollDirSelect setEnabled: enabled];
121 return [radioButtons isEnabled];
125 id jsaction = [joystickController selectedAction];
126 currentJsaction = jsaction;
128 [self setEnabled: NO];
129 [title setStringValue: @""];
132 [self setEnabled: YES];
134 Target* target = [[configsController currentConfig] getTargetForAction: jsaction];
137 NSString* actFullName = [act name];
140 actFullName = [[NSString alloc] initWithFormat: @"%@ > %@", [act name], actFullName];
142 [title setStringValue: [[NSString alloc] initWithFormat: @"%@ > %@", [[configsController currentConfig] name], actFullName]];
146 } else if([target isKindOfClass: [TargetKeyboard class]]) {
147 [radioButtons setState:1 atRow: 1 column: 0];
148 [keyInput setVk: [(TargetKeyboard*)target vk]];
149 } else if([target isKindOfClass: [TargetConfig class]]) {
150 [radioButtons setState:1 atRow: 2 column: 0];
151 [configPopup selectItemAtIndex: [[configsController configs] indexOfObject: [(TargetConfig*)target config]]];
153 else if ([target isKindOfClass: [TargetMouseMove class]]) {
154 [radioButtons setState:1 atRow: 3 column: 0];
155 [mouseDirSelect setSelectedSegment: [(TargetMouseMove *)target dir]];
157 else if ([target isKindOfClass: [TargetMouseBtn class]]) {
158 [radioButtons setState: 1 atRow: 4 column: 0];
159 if ([(TargetMouseBtn *)target which] == kCGMouseButtonLeft)
160 [mouseBtnSelect setSelectedSegment: 0];
162 [mouseBtnSelect setSelectedSegment: 1];
164 else if ([target isKindOfClass: [TargetMouseScroll class]]) {
165 [radioButtons setState: 1 atRow: 5 column: 0];
166 if ([(TargetMouseScroll *)target howMuch] < 0)
167 [scrollDirSelect setSelectedSegment: 0];
169 [scrollDirSelect setSelectedSegment: 1];
171 else if ([target isKindOfClass: [TargetToggleMouseScope class]]) {
172 [radioButtons setState: 1 atRow: 6 column: 0];
174 [NSException raise:@"Unknown target subclass" format:@"Unknown target subclass"];
179 [[[NSApplication sharedApplication] mainWindow] makeFirstResponder: keyInput];
182 -(void) refreshConfigsPreservingSelection: (BOOL) preserve {
183 int initialIndex = [configPopup indexOfSelectedItem];
185 NSArray* configs = [configsController configs];
186 [configPopup removeAllItems];
187 for(int i=0; i<[configs count]; i++) {
188 [configPopup addItemWithTitle: [[configs objectAtIndex:i]name]];
191 [configPopup selectItemAtIndex:initialIndex];