Oolite
Loading...
Searching...
No Matches
PlayerEntityStickMapper.m
Go to the documentation of this file.
1/*
2
3PlayerEntityStickMapper.m
4
5Oolite
6Copyright (C) 2004-2019 Giles C Williams and contributors
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21MA 02110-1301, USA.
22
23*/
24
26#import "HeadUpDisplay.h"
28#import "OOJoystickManager.h"
29#import "OOTexture.h"
32
33@interface PlayerEntity (StickMapperInternal)
34
36- (void)checkCustomEquipButtons:(NSDictionary*)stickFn ignore:(int)idx;
37- (void)removeFunction:(int)selFunctionIdx;
38- (NSArray*)stickFunctionList;
39- (void)displayFunctionList:(GuiDisplayGen*)gui
40 skip:(NSUInteger)skip;
41- (NSString*)describeStickDict:(NSDictionary*)stickDict;
42- (NSString*)hwToString:(int)hwFlags;
43
44@end
45
46@implementation PlayerEntity (StickMapper)
47
49{
50 [stickFunctions release];
51 stickFunctions = nil;
52}
53
54- (void)setGuiToStickMapperScreen:(unsigned)skip
55{
57}
58
59- (void)setGuiToStickMapperScreen:(unsigned)skip resetCurrentRow:(BOOL)resetCurrentRow
60{
61 GuiDisplayGen* gui = [UNIVERSE gui];
63 NSArray* stickList = [stickHandler listSticks];
64 unsigned stickCount = [stickList count];
65 unsigned i;
66
67 OOGUITabStop tabStop[GUI_MAX_COLUMNS];
68 tabStop[0] = 10;
69 tabStop[1] = 290;
70 tabStop[2] = 400;
71 [gui setTabStops:tabStop];
72
73 gui_screen = GUI_SCREEN_STICKMAPPER;
74 [gui clear];
75 [gui setTitle:[NSString stringWithFormat:@"%@", DESC(@"stickmapper-header")]];
76
77 for (i = 0; i < stickCount; i++) {
78 NSString* stickNameForThisRow = [NSString stringWithFormat:@"%@ %d %@", DESC(@"stickmapper-stick"), i + 1, [stickList objectAtIndex:i]];
79 // for more than 2 sticks, the stick name rows are populated by more than one name if needed
80 NSString* stickNameAdditional = nil;
81 if (stickCount > 2 && OOStringWidthInEm(stickNameForThisRow) > 18.0) {
82 // string is too long, truncate it until its length gets below threshold
83 do {
84 stickNameForThisRow = [[stickNameForThisRow substringToIndex:[stickNameForThisRow length] - 5]
85 stringByAppendingString:@"..."];
86 } while (OOStringWidthInEm(stickNameForThisRow) > 18.0);
87 }
88 unsigned j = i + 2;
89 if (j < stickCount) {
90 stickNameAdditional = [NSString stringWithFormat:@"%@ %d %@", DESC(@"stickmapper-stick"), j + 1, [stickList objectAtIndex:j]];
91 if (OOStringWidthInEm(stickNameAdditional) > 11.0) {
92 // string is too long, truncate it until its length gets below threshold
93 do {
94 stickNameAdditional = [[stickNameAdditional substringToIndex:[stickNameAdditional length] - 5]
95 stringByAppendingString:@"..."];
96 } while (OOStringWidthInEm(stickNameAdditional) > 11.0);
97 }
98 }
99 [gui setArray:[NSArray arrayWithObjects:
100 stickNameForThisRow,
101 @"", // skip one column
102 stickNameAdditional,
103 nil]
104 forRow:i + GUI_ROW_STICKNAME];
105 }
106
107 [gui setArray:[NSArray arrayWithObjects:DESC(@"stickmapper-profile"), nil] forRow:GUI_ROW_STICKPROFILE];
108 [gui setKey:GUI_KEY_OK forRow:GUI_ROW_STICKPROFILE];
109 [self displayFunctionList:gui skip:skip];
110
111 [gui setArray:[NSArray arrayWithObject:DESC(@"stickmapper-help-text-1")]
112 forRow:GUI_ROW_INSTRUCT];
113
114 [gui setText:DESC(@"stickmapper-help-text-2") forRow:GUI_ROW_INSTRUCT + 1 align:GUI_ALIGN_CENTER];
115
116 if (resetCurrentRow) {
117 [gui setSelectedRow:GUI_ROW_STICKPROFILE];
118 }
119 [[UNIVERSE gameView] suppressKeysUntilKeyUp];
120 [gui setForegroundTextureKey:[self status] == STATUS_DOCKED ? @"docked_overlay" : @"paused_overlay"];
121 [gui setBackgroundTextureKey:@"settings"];
122}
123
124- (void)stickMapperInputHandler:(GuiDisplayGen*)gui
125 view:(MyOpenGLView*)gameView
126{
128 // Don't do anything if the user is supposed to be selecting
129 // a function - other than look for Escape.
130 if (waitingForStickCallback) {
131 if ([gameView isDown:27]) {
133 [gui setArray:[NSArray arrayWithObjects:
134 DESC(@"stickmapper-set-aborted"), nil]
135 forRow:GUI_ROW_INSTRUCT];
136 waitingForStickCallback = NO;
137 }
138
139 // Break out now.
140 return;
141 }
142 const BOOL* joyButtonState = [stickHandler getAllButtonStates];
144 BOOL selectKeyPress = ([self checkKeyPress:n_key_gui_select] || joyButtonState[BUTTON_GUISELECT] || [gameView isDown:gvMouseDoubleClick]);
145
146 if ([gui selectedRow] == GUI_ROW_STICKPROFILE && selectKeyPress) {
148 return;
149 }
150
151 NSString* key = [gui keyForRow:[gui selectedRow]];
152 if ([key hasPrefix:@"Index:"])
153 selFunctionIdx = [[[key componentsSeparatedByString:@":"] objectAtIndex:1] intValue];
154 else
155 selFunctionIdx = -1;
156
157 if (selectKeyPress) {
158 if ([key hasPrefix:@"More:"]) {
159 int from_function = [[[key componentsSeparatedByString:@":"] objectAtIndex:1] intValue];
160 if (from_function < 0)
161 from_function = 0;
162
163 [self setGuiToStickMapperScreen:from_function];
164 if ([[UNIVERSE gui] selectedRow] < 0)
165 [[UNIVERSE gui] setSelectedRow:GUI_ROW_FUNCSTART];
166 if (from_function == 0)
167 [[UNIVERSE gui] setSelectedRow:GUI_ROW_FUNCSTART + MAX_ROWS_FUNCTIONS - 1];
168 return;
169 }
170
171 NSDictionary* entry = [stickFunctions objectAtIndex:selFunctionIdx];
172 int hw = [(NSNumber*)[entry objectForKey:KEY_ALLOWABLE] intValue];
174 object:self
175 hardware:hw];
176
177 // Print instructions
178 NSString* instructions;
179 switch (hw) {
180 case HW_AXIS:
181 instructions = DESC(@"stickmapper-set-help-text-axis");
182 break;
183 case HW_BUTTON:
184 instructions = DESC(@"stickmapper-set-help-text-button");
185 break;
186 default:
187 instructions = DESC(@"stickmapper-set-help-text-either");
188 }
189 [gui setArray:[NSArray arrayWithObjects:instructions, nil] forRow:GUI_ROW_INSTRUCT];
190 waitingForStickCallback = YES;
191 }
192
193 if ([gameView isDown:'u']) {
194 if (selFunctionIdx >= 0)
195 [self removeFunction:selFunctionIdx];
196 }
197}
198
199// Callback function, called by JoystickHandler when the callback
200// is set. The dictionary contains the thing that was pressed/moved.
201- (void)updateFunction:(NSDictionary*)hwDict
202{
204 waitingForStickCallback = NO;
205
206 // Right time and the right place?
207 if (gui_screen != GUI_SCREEN_STICKMAPPER) {
208 OOLog(@"joystick.configure.error", @"%s called when not on stick mapper screen.", __PRETTY_FUNCTION__);
209 return;
210 }
211 // What moved?
212 int function;
213 NSDictionary* entry = [stickFunctions objectAtIndex:selFunctionIdx];
214 if ([hwDict oo_boolForKey:STICK_ISAXIS]) {
215 function = [entry oo_intForKey:KEY_AXISFN];
216 if (function == AXIS_THRUST) {
217 [stickHandler unsetButtonFunction:BUTTON_INCTHRUST];
218 [stickHandler unsetButtonFunction:BUTTON_DECTHRUST];
219 }
220#if OO_FOV_INFLIGHT_CONTROL_ENABLED
221 if (function == AXIS_FIELD_OF_VIEW) {
222 [stickHandler unsetButtonFunction:BUTTON_INC_FIELD_OF_VIEW];
223 [stickHandler unsetButtonFunction:BUTTON_DEC_FIELD_OF_VIEW];
224 }
225#endif
226 if (function == AXIS_VIEWX) {
227 [stickHandler unsetButtonFunction:BUTTON_VIEWPORT];
228 [stickHandler unsetButtonFunction:BUTTON_VIEWSTARBOARD];
229 }
230 if (function == AXIS_VIEWY) {
231 [stickHandler unsetButtonFunction:BUTTON_VIEWFORWARD];
232 [stickHandler unsetButtonFunction:BUTTON_VIEWAFT];
233 }
234 } else {
235 function = [entry oo_intForKey:KEY_BUTTONFN];
236 if (function == BUTTON_INCTHRUST || function == BUTTON_DECTHRUST) {
237 [stickHandler unsetAxisFunction:AXIS_THRUST];
238 }
239#if OO_FOV_INFLIGHT_CONTROL_ENABLED
240 if (function == BUTTON_INC_FIELD_OF_VIEW || function == BUTTON_DEC_FIELD_OF_VIEW) {
241 [stickHandler unsetAxisFunction:AXIS_FIELD_OF_VIEW];
242 }
243#endif
244 if (function == BUTTON_VIEWPORT || function == BUTTON_VIEWSTARBOARD) {
245 [stickHandler unsetAxisFunction:AXIS_VIEWX];
246 }
247 if (function == BUTTON_VIEWFORWARD || function == BUTTON_VIEWAFT) {
248 [stickHandler unsetAxisFunction:AXIS_VIEWY];
249 }
250 }
251 // special case for OXP equipment buttons
252 if (function >= 10000) {
253 NSString* key = CUSTOMEQUIP_BUTTONACTIVATE;
254 function -= 10000;
255 if (function >= 10000) {
256 function -= 10000;
258 }
259 NSMutableDictionary* custEquip = [[customEquipActivation objectAtIndex:function] mutableCopy];
260 [custEquip setObject:hwDict forKey:key];
261 [customEquipActivation replaceObjectAtIndex:function withObject:custEquip];
262 [custEquip release];
263 [self checkCustomEquipButtons:hwDict ignore:function];
264 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
265 [defaults setObject:customEquipActivation forKey:KEYCONFIG_CUSTOMEQUIP];
266 } else {
267 if (function >= BUTTON_GUILEFT && function <= BUTTON_GUISELECT) {
268 [stickHandler setFunction:function withDict:hwDict];
269 } else {
270 [stickHandler setFunction:function withDict:hwDict];
271 [self checkCustomEquipButtons:hwDict ignore:-1];
272 }
274 }
275
276 // Update the GUI (this will refresh the function list).
277 unsigned skip;
278 if (selFunctionIdx < MAX_ROWS_FUNCTIONS - 1) {
279 skip = 0;
280 } else {
281 skip = ((selFunctionIdx - 1) / (MAX_ROWS_FUNCTIONS - 2)) * (MAX_ROWS_FUNCTIONS - 2) + 1;
282 }
283
284 [self setGuiToStickMapperScreen:skip];
285}
286
287- (void)checkCustomEquipButtons:(NSDictionary*)stickFn ignore:(int)idx
288{
289 int i;
290 for (i = 0; i < [customEquipActivation count]; i++) {
291 if (i != idx) {
292 NSMutableDictionary* custEquip = [[customEquipActivation objectAtIndex:i] mutableCopy];
293 NSDictionary* bf = [[customEquipActivation objectAtIndex:i] objectForKey:CUSTOMEQUIP_BUTTONACTIVATE];
294 if ([bf oo_integerForKey:STICK_NUMBER] == [stickFn oo_integerForKey:STICK_NUMBER] &&
295 [bf oo_integerForKey:STICK_AXBUT] == [stickFn oo_integerForKey:STICK_AXBUT] &&
296 [custEquip objectForKey:CUSTOMEQUIP_BUTTONACTIVATE]) {
297 [custEquip removeObjectForKey:CUSTOMEQUIP_BUTTONACTIVATE];
298 }
299 bf = [[customEquipActivation objectAtIndex:i] objectForKey:CUSTOMEQUIP_BUTTONMODE];
300 if ([bf oo_integerForKey:STICK_NUMBER] == [stickFn oo_integerForKey:STICK_NUMBER] &&
301 [bf oo_integerForKey:STICK_AXBUT] == [stickFn oo_integerForKey:STICK_AXBUT] &&
302 [custEquip objectForKey:CUSTOMEQUIP_BUTTONMODE]) {
303 [custEquip removeObjectForKey:CUSTOMEQUIP_BUTTONMODE];
304 }
305 [customEquipActivation replaceObjectAtIndex:i withObject:custEquip];
306 [custEquip release];
307 }
308 }
309}
310
311- (void)removeFunction:(int)idx
312{
314 NSDictionary* entry = [stickFunctions objectAtIndex:idx];
315 NSNumber* butfunc = [entry objectForKey:KEY_BUTTONFN];
316 NSNumber* axfunc = [entry objectForKey:KEY_AXISFN];
317 BOOL custom = NO;
318 selFunctionIdx = idx;
319
320 // Some things can have either axis or buttons - make sure we clear
321 // both!
322 if (butfunc) {
323 // special case for OXP equipment buttons
324 if ([butfunc intValue] >= 10000) {
325 int bf = [butfunc intValue];
326 custom = YES;
327 NSString* key = CUSTOMEQUIP_BUTTONACTIVATE;
328 bf -= 10000;
329 if (bf >= 10000) {
330 bf -= 10000;
332 }
333 NSMutableDictionary* custEquip = [[customEquipActivation objectAtIndex:bf] mutableCopy];
334 if ([key isEqualToString:CUSTOMEQUIP_BUTTONACTIVATE] && [custEquip objectForKey:CUSTOMEQUIP_BUTTONACTIVATE])
335 [custEquip removeObjectForKey:key];
336 if ([key isEqualToString:CUSTOMEQUIP_BUTTONMODE] && [custEquip objectForKey:CUSTOMEQUIP_BUTTONMODE])
337 [custEquip removeObjectForKey:key];
338 [customEquipActivation replaceObjectAtIndex:bf withObject:custEquip];
339 [custEquip release];
340 } else {
342 }
343 }
344 if (axfunc) {
346 }
347 if (!custom) {
349 } else {
350 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
351 [defaults setObject:customEquipActivation forKey:KEYCONFIG_CUSTOMEQUIP];
352 }
353
354 unsigned skip;
355 if (selFunctionIdx < MAX_ROWS_FUNCTIONS - 1)
356 skip = 0;
357 else
358 skip = ((selFunctionIdx - 1) / (MAX_ROWS_FUNCTIONS - 2)) * (MAX_ROWS_FUNCTIONS - 2) + 1;
359 [self setGuiToStickMapperScreen:skip];
360}
361
362- (void)displayFunctionList:(GuiDisplayGen*)gui
363 skip:(NSUInteger)skip
364{
366
367 [gui setColor:[OOColor greenColor] forRow:GUI_ROW_HEADING];
368 [gui setArray:[NSArray arrayWithObjects:
369 DESC(@"stickmapper-column-function"), DESC(@"stickmapper-column-assigned-to"), DESC(@"stickmapper-column-type"), nil]
370 forRow:GUI_ROW_HEADING];
371
372 if (!stickFunctions) {
373 stickFunctions = [[self stickFunctionList] retain];
374 }
375 NSDictionary* assignedAxes = [stickHandler axisFunctions];
376 NSDictionary* assignedButs = [stickHandler buttonFunctions];
377 NSDictionary* assignedGuiButs = [stickHandler guiButtonFunctions];
378
379 NSUInteger i, n_functions = [stickFunctions count];
380 NSInteger n_rows, start_row, previous = 0;
381
382 if (skip >= n_functions)
383 skip = n_functions - 1;
384
385 if (n_functions < MAX_ROWS_FUNCTIONS) {
386 skip = 0;
387 previous = 0;
388 n_rows = MAX_ROWS_FUNCTIONS;
389 start_row = GUI_ROW_FUNCSTART;
390 } else {
391 n_rows = MAX_ROWS_FUNCTIONS - 1;
392 start_row = GUI_ROW_FUNCSTART;
393 if (skip > 0) {
394 n_rows -= 1;
395 start_row += 1;
396 if (skip > MAX_ROWS_FUNCTIONS)
397 previous = skip - (MAX_ROWS_FUNCTIONS - 2);
398 else
399 previous = 0;
400 }
401 }
402
403 if (n_functions > 0) {
404 if (skip > 0) {
405 [gui setColor:[OOColor greenColor] forRow:GUI_ROW_FUNCSTART];
406 [gui setArray:[NSArray arrayWithObjects:DESC(@"gui-back"), @" <-- ", nil] forRow:GUI_ROW_FUNCSTART];
407 [gui setKey:[NSString stringWithFormat:@"More:%zd", previous] forRow:GUI_ROW_FUNCSTART];
408 }
409
410 for (i = 0; i < (n_functions - skip) && (int)i < n_rows; i++) {
411 NSDictionary* entry = [stickFunctions objectAtIndex:i + skip];
412 if ([entry objectForKey:KEY_HEADER]) {
413 NSString* header = [entry objectForKey:KEY_HEADER];
414 [gui setArray:[NSArray arrayWithObjects:header, @"", @"", nil] forRow:i + start_row];
415 [gui setColor:[OOColor cyanColor] forRow:i + start_row];
416 } else {
417 NSString* allowedThings;
418 NSString* assignment;
419 NSString* axFuncKey = [entry oo_stringForKey:KEY_AXISFN];
420 NSString* butFuncKey = [entry oo_stringForKey:KEY_BUTTONFN];
421 int allowable = [entry oo_intForKey:KEY_ALLOWABLE];
422 switch (allowable) {
423 case HW_AXIS:
424 allowedThings = DESC(@"stickmapper-allowed-axis");
425 assignment = [self describeStickDict:
426 [assignedAxes objectForKey:axFuncKey]];
427 break;
428 case HW_BUTTON:
429 allowedThings = DESC(@"stickmapper-allowed-button");
430 int bf = [butFuncKey integerValue];
431 if (bf < 10000) {
432 if (bf >= BUTTON_GUILEFT && bf <= BUTTON_GUISELECT) {
433 assignment = [self describeStickDict:
434 [assignedGuiButs objectForKey:butFuncKey]];
435 } else {
436 assignment = [self describeStickDict:
437 [assignedButs objectForKey:butFuncKey]];
438 }
439 } else {
440 NSString* key = CUSTOMEQUIP_BUTTONACTIVATE;
441 bf -= 10000;
442 if (bf >= 10000) {
443 bf -= 10000;
445 }
446 assignment = [self describeStickDict:
447 [[customEquipActivation objectAtIndex:bf] objectForKey:key]];
448 }
449 break;
450 default:
451 allowedThings = DESC(@"stickmapper-allowed-both");
452
453 // axis has priority
454 assignment = [self describeStickDict:
455 [assignedAxes objectForKey:axFuncKey]];
456 if (!assignment) {
457 int bf = [butFuncKey integerValue];
458 if (bf >= BUTTON_GUILEFT && bf <= BUTTON_GUISELECT) {
459 assignment = [self describeStickDict:
460 [assignedGuiButs objectForKey:butFuncKey]];
461 } else {
462 assignment = [self describeStickDict:
463 [assignedButs objectForKey:butFuncKey]];
464 }
465 }
466 }
467
468 // Find out what's assigned for this function currently.
469 if (assignment == nil) {
470 assignment = @" - ";
471 }
472
473 [gui setArray:[NSArray arrayWithObjects:
474 [entry objectForKey:KEY_GUIDESC], assignment, allowedThings, nil]
475 forRow:i + start_row];
476 //[gui setKey: GUI_KEY_OK forRow: i + start_row];
477 [gui setKey:[NSString stringWithFormat:@"Index:%zu", i + skip] forRow:i + start_row];
478 }
479 }
480 if (i < n_functions - skip) {
481 [gui setColor:[OOColor greenColor] forRow:start_row + i];
482 [gui setArray:[NSArray arrayWithObjects:DESC(@"gui-more"), @" --> ", nil] forRow:start_row + i];
483 [gui setKey:[NSString stringWithFormat:@"More:%zu", n_rows + skip] forRow:start_row + i];
484 i++;
485 }
486
487 [gui setSelectableRange:NSMakeRange(GUI_ROW_STICKPROFILE, i + start_row - GUI_ROW_STICKPROFILE)];
488 }
489}
490
491- (NSString*)describeStickDict:(NSDictionary*)stickDict
492{
493 NSString* desc = nil;
494 if (stickDict) {
495 int thingNumber = [(NSNumber*)[stickDict objectForKey:STICK_AXBUT]
496 intValue];
497 int stickNumber = [(NSNumber*)[stickDict objectForKey:STICK_NUMBER]
498 intValue];
499 // Button or axis?
500 if ([(NSNumber*)[stickDict objectForKey:STICK_ISAXIS] boolValue]) {
501 desc = [NSString stringWithFormat:@"%@ %d %@ %d",
502 DESC(@"stickmapper-stick"), stickNumber + 1, DESC(@"stickmapper-axis"), thingNumber + 1];
503 } else if (thingNumber >= MAX_REAL_BUTTONS) {
504 NSString* dir[] = { DESC(@"stickmapper-hat-up"), DESC(@"stickmapper-hat-right"), DESC(@"stickmapper-hat-down"), DESC(@"stickmapper-hat-left") };
505 desc = [NSString stringWithFormat:@"%@ %d %@ %d %@",
506 DESC(@"stickmapper-stick"), stickNumber + 1, DESC(@"stickmapper-hat"), (thingNumber - MAX_REAL_BUTTONS) / 4 + 1,
507 dir[thingNumber & 3]];
508 } else {
509 desc = [NSString stringWithFormat:@"%@ %d %@ %d",
510 DESC(@"stickmapper-stick"), stickNumber + 1, DESC(@"stickmapper-button"), thingNumber + 1];
511 }
512 }
513 return desc;
514}
515
516- (NSString*)hwToString:(int)hwFlags
517{
518 NSString* hwString;
519 switch (hwFlags) {
520 case HW_AXIS:
521 hwString = DESC(@"stickmapper-axis");
522 break;
523 case HW_BUTTON:
524 hwString = DESC(@"stickmapper-button");
525 break;
526 default:
527 hwString = DESC(@"stickmapper-axis-button");
528 }
529 return hwString;
530}
531
532// TODO: This data could be put into a plist (i18n or just modifiable by
533// the user). It is otherwise an ugly method, but it'll do for testing.
535{
536 NSMutableArray* funcList = [NSMutableArray array];
537
538 // propulsion
539 [funcList addObject:[self makeStickGuiDictHeader:DESC(@"stickmapper-header-propulsion")]];
540 [funcList addObject:
541 [self makeStickGuiDict:DESC(@"stickmapper-roll")
542 allowable:HW_AXIS
543 axisfn:AXIS_ROLL
544 butfn:STICK_NOFUNCTION]];
545 [funcList addObject:
546 [self makeStickGuiDict:DESC(@"stickmapper-pitch")
547 allowable:HW_AXIS
548 axisfn:AXIS_PITCH
549 butfn:STICK_NOFUNCTION]];
550 [funcList addObject:
551 [self makeStickGuiDict:DESC(@"stickmapper-yaw")
552 allowable:HW_AXIS
553 axisfn:AXIS_YAW
554 butfn:STICK_NOFUNCTION]];
555 [funcList addObject:
556 [self makeStickGuiDict:DESC(@"stickmapper-increase-thrust")
557 allowable:HW_AXIS | HW_BUTTON
558 axisfn:AXIS_THRUST
559 butfn:BUTTON_INCTHRUST]];
560 [funcList addObject:
561 [self makeStickGuiDict:DESC(@"stickmapper-decrease-thrust")
562 allowable:HW_AXIS | HW_BUTTON
563 axisfn:AXIS_THRUST
564 butfn:BUTTON_DECTHRUST]];
565 [funcList addObject:
566 [self makeStickGuiDict:DESC(@"stickmapper-fuel-injection")
567 allowable:HW_BUTTON
568 axisfn:STICK_NOFUNCTION
569 butfn:BUTTON_FUELINJECT]];
570 [funcList addObject:
571 [self makeStickGuiDict:DESC(@"stickmapper-hyperspeed")
572 allowable:HW_BUTTON
573 axisfn:STICK_NOFUNCTION
574 butfn:BUTTON_HYPERSPEED]];
575 [funcList addObject:
576 [self makeStickGuiDict:DESC(@"stickmapper-hyperdrive")
577 allowable:HW_BUTTON
578 axisfn:STICK_NOFUNCTION
579 butfn:BUTTON_HYPERDRIVE]];
580 [funcList addObject:
581 [self makeStickGuiDict:DESC(@"stickmapper-gal-hyperdrive")
582 allowable:HW_BUTTON
583 axisfn:STICK_NOFUNCTION
584 butfn:BUTTON_GALACTICDRIVE]];
585
586 [funcList addObject:
587 [self makeStickGuiDict:DESC(@"stickmapper-roll/pitch-precision-toggle")
588 allowable:HW_BUTTON
589 axisfn:STICK_NOFUNCTION
590 butfn:BUTTON_PRECISION]];
591
592 // navigation
593 [funcList addObject:[self makeStickGuiDictHeader:DESC(@"stickmapper-header-navigation")]];
594 [funcList addObject:
595 [self makeStickGuiDict:DESC(@"stickmapper-compass-mode-next")
596 allowable:HW_BUTTON
597 axisfn:STICK_NOFUNCTION
598 butfn:BUTTON_COMPASSMODE]];
599 [funcList addObject:
600 [self makeStickGuiDict:DESC(@"stickmapper-compass-mode-prev")
601 allowable:HW_BUTTON
602 axisfn:STICK_NOFUNCTION
603 butfn:BUTTON_COMPASSMODE_PREV]];
604 [funcList addObject:
605 [self makeStickGuiDict:DESC(@"stickmapper-scanner-zoom")
606 allowable:HW_BUTTON
607 axisfn:STICK_NOFUNCTION
608 butfn:BUTTON_SCANNERZOOM]];
609 [funcList addObject:
610 [self makeStickGuiDict:DESC(@"stickmapper-scanner-unzoom")
611 allowable:HW_BUTTON
612 axisfn:STICK_NOFUNCTION
613 butfn:BUTTON_SCANNERUNZOOM]];
614 [funcList addObject:
615 [self makeStickGuiDict:DESC(@"stickmapper-view-forward")
616 allowable:HW_AXIS | HW_BUTTON
617 axisfn:AXIS_VIEWY
618 butfn:BUTTON_VIEWFORWARD]];
619 [funcList addObject:
620 [self makeStickGuiDict:DESC(@"stickmapper-view-aft")
621 allowable:HW_AXIS | HW_BUTTON
622 axisfn:AXIS_VIEWY
623 butfn:BUTTON_VIEWAFT]];
624 [funcList addObject:
625 [self makeStickGuiDict:DESC(@"stickmapper-view-port")
626 allowable:HW_AXIS | HW_BUTTON
627 axisfn:AXIS_VIEWX
628 butfn:BUTTON_VIEWPORT]];
629 [funcList addObject:
630 [self makeStickGuiDict:DESC(@"stickmapper-view-starboard")
631 allowable:HW_AXIS | HW_BUTTON
632 axisfn:AXIS_VIEWX
633 butfn:BUTTON_VIEWSTARBOARD]];
634 [funcList addObject:
635 [self makeStickGuiDict:DESC(@"stickmapper-ext-view-cycle")
636 allowable:HW_BUTTON
637 axisfn:STICK_NOFUNCTION
638 butfn:BUTTON_EXTVIEWCYCLE]];
639 [funcList addObject:
640 [self makeStickGuiDict:DESC(@"stickmapper-toggle-ID")
641 allowable:HW_BUTTON
642 axisfn:STICK_NOFUNCTION
643 butfn:BUTTON_ID]];
644 [funcList addObject:
645 [self makeStickGuiDict:DESC(@"stickmapper-docking-clearance")
646 allowable:HW_BUTTON
647 axisfn:STICK_NOFUNCTION
648 butfn:BUTTON_DOCKINGCLEARANCE]];
649 [funcList addObject:
650 [self makeStickGuiDict:DESC(@"stickmapper-dockcpu")
651 allowable:HW_BUTTON
652 axisfn:STICK_NOFUNCTION
653 butfn:BUTTON_DOCKCPU]];
654 [funcList addObject:
655 [self makeStickGuiDict:DESC(@"stickmapper-dockcpufast")
656 allowable:HW_BUTTON
657 axisfn:STICK_NOFUNCTION
658 butfn:BUTTON_DOCKCPUFAST]];
659 [funcList addObject:
660 [self makeStickGuiDict:DESC(@"stickmapper-docking-music")
661 allowable:HW_BUTTON
662 axisfn:STICK_NOFUNCTION
663 butfn:BUTTON_DOCKINGMUSIC]];
664
665 // offensive
666 [funcList addObject:[self makeStickGuiDictHeader:DESC(@"stickmapper-header-offensive")]];
667 [funcList addObject:
668 [self makeStickGuiDict:DESC(@"stickmapper-weapons-online-toggle")
669 allowable:HW_BUTTON
670 axisfn:STICK_NOFUNCTION
671 butfn:BUTTON_WEAPONSONLINETOGGLE]];
672 [funcList addObject:
673 [self makeStickGuiDict:DESC(@"stickmapper-primary-weapon")
674 allowable:HW_BUTTON
675 axisfn:STICK_NOFUNCTION
676 butfn:BUTTON_FIRE]];
677 [funcList addObject:
678 [self makeStickGuiDict:DESC(@"stickmapper-secondary-weapon")
679 allowable:HW_BUTTON
680 axisfn:STICK_NOFUNCTION
681 butfn:BUTTON_LAUNCHMISSILE]];
682 [funcList addObject:
683 [self makeStickGuiDict:DESC(@"stickmapper-arm-secondary")
684 allowable:HW_BUTTON
685 axisfn:STICK_NOFUNCTION
686 butfn:BUTTON_ARMMISSILE]];
687 [funcList addObject:
688 [self makeStickGuiDict:DESC(@"stickmapper-disarm-secondary")
689 allowable:HW_BUTTON
690 axisfn:STICK_NOFUNCTION
691 butfn:BUTTON_UNARM]];
692 [funcList addObject:
693 [self makeStickGuiDict:DESC(@"stickmapper-target-nearest-incoming-missile")
694 allowable:HW_BUTTON
695 axisfn:STICK_NOFUNCTION
696 butfn:BUTTON_TARGETINCOMINGMISSILE]];
697 [funcList addObject:
698 [self makeStickGuiDict:DESC(@"stickmapper-cycle-secondary")
699 allowable:HW_BUTTON
700 axisfn:STICK_NOFUNCTION
701 butfn:BUTTON_CYCLEMISSILE]];
702 [funcList addObject:
703 [self makeStickGuiDict:DESC(@"stickmapper-next-target")
704 allowable:HW_BUTTON
705 axisfn:STICK_NOFUNCTION
706 butfn:BUTTON_NEXTTARGET]];
707 [funcList addObject:
708 [self makeStickGuiDict:DESC(@"stickmapper-previous-target")
709 allowable:HW_BUTTON
710 axisfn:STICK_NOFUNCTION
711 butfn:BUTTON_PREVTARGET]];
712
713 // defensive
714 [funcList addObject:[self makeStickGuiDictHeader:DESC(@"stickmapper-header-defensive")]];
715 [funcList addObject:
716 [self makeStickGuiDict:DESC(@"stickmapper-ECM")
717 allowable:HW_BUTTON
718 axisfn:STICK_NOFUNCTION
719 butfn:BUTTON_ECM]];
720 [funcList addObject:
721 [self makeStickGuiDict:DESC(@"stickmapper-jettison")
722 allowable:HW_BUTTON
723 axisfn:STICK_NOFUNCTION
724 butfn:BUTTON_JETTISON]];
725 [funcList addObject:
726 [self makeStickGuiDict:DESC(@"stickmapper-rotate-cargo")
727 allowable:HW_BUTTON
728 axisfn:STICK_NOFUNCTION
729 butfn:BUTTON_ROTATECARGO]];
730 [funcList addObject:
731 [self makeStickGuiDict:DESC(@"stickmapper-escape-pod")
732 allowable:HW_BUTTON
733 axisfn:STICK_NOFUNCTION
734 butfn:BUTTON_ESCAPE]];
735
736 // oxp special equip
737 [funcList addObject:[self makeStickGuiDictHeader:DESC(@"stickmapper-header-special-equip")]];
738 [funcList addObject:
739 [self makeStickGuiDict:DESC(@"stickmapper-mfd-select-next")
740 allowable:HW_BUTTON
741 axisfn:STICK_NOFUNCTION
742 butfn:BUTTON_MFDSELECTNEXT]];
743 [funcList addObject:
744 [self makeStickGuiDict:DESC(@"stickmapper-mfd-select-prev")
745 allowable:HW_BUTTON
746 axisfn:STICK_NOFUNCTION
747 butfn:BUTTON_MFDSELECTPREV]];
748 [funcList addObject:
749 [self makeStickGuiDict:DESC(@"stickmapper-mfd-cycle-next")
750 allowable:HW_BUTTON
751 axisfn:STICK_NOFUNCTION
752 butfn:BUTTON_MFDCYCLENEXT]];
753 [funcList addObject:
754 [self makeStickGuiDict:DESC(@"stickmapper-mfd-cycle-prev")
755 allowable:HW_BUTTON
756 axisfn:STICK_NOFUNCTION
757 butfn:BUTTON_MFDCYCLEPREV]];
758 [funcList addObject:
759 [self makeStickGuiDict:DESC(@"stickmapper-prime-equipment")
760 allowable:HW_BUTTON
761 axisfn:STICK_NOFUNCTION
762 butfn:BUTTON_PRIMEEQUIPMENT]];
763 [funcList addObject:
764 [self makeStickGuiDict:DESC(@"stickmapper-prime-prev-equipment")
765 allowable:HW_BUTTON
766 axisfn:STICK_NOFUNCTION
767 butfn:BUTTON_PRIMEEQUIPMENT]];
768 [funcList addObject:
769 [self makeStickGuiDict:DESC(@"stickmapper-activate-equipment")
770 allowable:HW_BUTTON
771 axisfn:STICK_NOFUNCTION
772 butfn:BUTTON_ACTIVATEEQUIPMENT]];
773 [funcList addObject:
774 [self makeStickGuiDict:DESC(@"stickmapper-mode-equipment")
775 allowable:HW_BUTTON
776 axisfn:STICK_NOFUNCTION
777 butfn:BUTTON_MODEEQUIPMENT]];
778 [funcList addObject:
779 [self makeStickGuiDict:DESC(@"stickmapper-fastactivate-a")
780 allowable:HW_BUTTON
781 axisfn:STICK_NOFUNCTION
782 butfn:BUTTON_CLOAK]];
783 [funcList addObject:
784 [self makeStickGuiDict:DESC(@"stickmapper-fastactivate-b")
785 allowable:HW_BUTTON
786 axisfn:STICK_NOFUNCTION
787 butfn:BUTTON_ENERGYBOMB]];
788
789 [funcList addObject:[self makeStickGuiDictHeader:DESC(@"stickmapper-header-gui")]];
790 [funcList addObject:
791 [self makeStickGuiDict:DESC(@"stickmapper-gui-left")
792 allowable:HW_BUTTON
793 axisfn:STICK_NOFUNCTION
794 butfn:BUTTON_GUILEFT]];
795 [funcList addObject:
796 [self makeStickGuiDict:DESC(@"stickmapper-gui-right")
797 allowable:HW_BUTTON
798 axisfn:STICK_NOFUNCTION
799 butfn:BUTTON_GUIRIGHT]];
800 [funcList addObject:
801 [self makeStickGuiDict:DESC(@"stickmapper-gui-up")
802 allowable:HW_BUTTON
803 axisfn:STICK_NOFUNCTION
804 butfn:BUTTON_GUIUP]];
805 [funcList addObject:
806 [self makeStickGuiDict:DESC(@"stickmapper-gui-down")
807 allowable:HW_BUTTON
808 axisfn:STICK_NOFUNCTION
809 butfn:BUTTON_GUIDOWN]];
810 [funcList addObject:
811 [self makeStickGuiDict:DESC(@"stickmapper-gui-page-up")
812 allowable:HW_BUTTON
813 axisfn:STICK_NOFUNCTION
814 butfn:BUTTON_GUIPAGEUP]];
815 [funcList addObject:
816 [self makeStickGuiDict:DESC(@"stickmapper-gui-page-down")
817 allowable:HW_BUTTON
818 axisfn:STICK_NOFUNCTION
819 butfn:BUTTON_GUIPAGEDOWN]];
820 [funcList addObject:
821 [self makeStickGuiDict:DESC(@"stickmapper-gui-select")
822 allowable:HW_BUTTON
823 axisfn:STICK_NOFUNCTION
824 butfn:BUTTON_GUISELECT]];
825
826 // misc
827 [funcList addObject:[self makeStickGuiDictHeader:DESC(@"stickmapper-header-misc")]];
828 [funcList addObject:
829 [self makeStickGuiDict:DESC(@"stickmapper-snapshot")
830 allowable:HW_BUTTON
831 axisfn:STICK_NOFUNCTION
832 butfn:BUTTON_SNAPSHOT]];
833 [funcList addObject:
834 [self makeStickGuiDict:DESC(@"stickmapper-pause")
835 allowable:HW_BUTTON
836 axisfn:STICK_NOFUNCTION
837 butfn:BUTTON_PAUSE]];
838 [funcList addObject:
839 [self makeStickGuiDict:DESC(@"stickmapper-toggle-hud")
840 allowable:HW_BUTTON
841 axisfn:STICK_NOFUNCTION
842 butfn:BUTTON_TOGGLEHUD]];
843 [funcList addObject:
844 [self makeStickGuiDict:DESC(@"stickmapper-comms-log")
845 allowable:HW_BUTTON
846 axisfn:STICK_NOFUNCTION
847 butfn:BUTTON_COMMSLOG]];
848#if OO_FOV_INFLIGHT_CONTROL_ENABLED
849 [funcList addObject:
850 [self makeStickGuiDict:DESC(@"stickmapper-increase-field-of-view")
851 allowable:HW_AXIS | HW_BUTTON
852 axisfn:AXIS_FIELD_OF_VIEW
853 butfn:BUTTON_INC_FIELD_OF_VIEW]];
854 [funcList addObject:
855 [self makeStickGuiDict:DESC(@"stickmapper-decrease-field-of-view")
856 allowable:HW_AXIS | HW_BUTTON
857 axisfn:AXIS_FIELD_OF_VIEW
858 butfn:BUTTON_DEC_FIELD_OF_VIEW]];
859#endif
860 if ([customEquipActivation count] > 0) {
861 [funcList addObject:[self makeStickGuiDictHeader:DESC(@"stickmapper-header-oxp-equip")]];
862 int i;
863 for (i = 0; i < [customEquipActivation count]; i++) {
864 [funcList addObject:
865 [self makeStickGuiDict:[NSString stringWithFormat:@"%@ '%@'", DESC(@"stickmapper-cust-activate"), [[customEquipActivation objectAtIndex:i] oo_stringForKey:CUSTOMEQUIP_EQUIPNAME]]
866 allowable:HW_BUTTON
867 axisfn:STICK_NOFUNCTION
868 butfn:(i + 10000)]];
869 [funcList addObject:
870 [self makeStickGuiDict:[NSString stringWithFormat:@"%@ '%@'", DESC(@"stickmapper-cust-mode"), [[customEquipActivation objectAtIndex:i] oo_stringForKey:CUSTOMEQUIP_EQUIPNAME]]
871 allowable:HW_BUTTON
872 axisfn:STICK_NOFUNCTION
873 butfn:(i + 20000)]];
874 }
875 }
876 return funcList;
877}
878
879- (NSDictionary*)makeStickGuiDict:(NSString*)what
880 allowable:(int)allowable
881 axisfn:(int)axisfn
882 butfn:(int)butfn
883{
884 NSMutableDictionary* guiDict = [NSMutableDictionary dictionary];
885
886 if ([what length] > 50)
887 what = [[what substringToIndex:28] stringByAppendingString:@"..."];
888 [guiDict setObject:what forKey:KEY_GUIDESC];
889 [guiDict setObject:[NSNumber numberWithInt:allowable]
890 forKey:KEY_ALLOWABLE];
891 if (axisfn >= 0)
892 [guiDict setObject:[NSNumber numberWithInt:axisfn]
893 forKey:KEY_AXISFN];
894 if (butfn >= 0)
895 [guiDict setObject:[NSNumber numberWithInt:butfn]
896 forKey:KEY_BUTTONFN];
897 return guiDict;
898}
899
900- (NSDictionary*)makeStickGuiDictHeader:(NSString*)header
901{
902 NSMutableDictionary* guiDict = [NSMutableDictionary dictionary];
903 [guiDict setObject:header forKey:KEY_HEADER];
904 [guiDict setObject:@"" forKey:KEY_ALLOWABLE];
905 [guiDict setObject:@"" forKey:KEY_AXISFN];
906 [guiDict setObject:@"" forKey:KEY_BUTTONFN];
907 return guiDict;
908}
909
910@end
NSInteger OOGUITabStop
CGFloat OOStringWidthInEm(NSString *text)
#define STICK_ISAXIS
#define MAX_REAL_BUTTONS
#define HW_BUTTON
@ AXIS_VIEWX
@ AXIS_THRUST
@ AXIS_VIEWY
#define HW_AXIS
@ BUTTON_GUILEFT
@ BUTTON_GUISELECT
@ BUTTON_VIEWSTARBOARD
@ BUTTON_VIEWAFT
@ BUTTON_VIEWPORT
@ BUTTON_VIEWFORWARD
@ BUTTON_INCTHRUST
@ BUTTON_DECTHRUST
#define STICK_NUMBER
#define STICK_AXBUT
#define OOLog(class, format,...)
Definition OOLogging.h:84
unsigned count
return nil
#define KEY_HEADER
#define GUI_ROW_STICKPROFILE
#define MAX_ROWS_FUNCTIONS
#define GUI_ROW_FUNCSTART
#define CUSTOMEQUIP_BUTTONACTIVATE
#define CUSTOMEQUIP_BUTTONMODE
#define UNIVERSE
Definition Universe.h:827
#define DESC(key)
Definition Universe.h:832
OOEntityStatus status()
Definition Entity.m:733
BOOL setBackgroundTextureKey:(NSString *key)
BOOL setSelectedRow:(OOGUIRow row)
BOOL setForegroundTextureKey:(NSString *key)
void setText:forRow:align:(NSString *str,[forRow] OOGUIRow row,[align] OOGUIAlignment alignment)
OOGUIRow selectedRow
void setSelectableRange:(NSRange range)
void setColor:forRow:(OOColor *color,[forRow] OOGUIRow row)
void setTitle:(NSString *str)
void setTabStops:(OOGUITabSettings stops)
NSString * keyForRow:(OOGUIRow row)
void setArray:forRow:(NSArray *arr,[forRow] OOGUIRow row)
void setKey:forRow:(NSString *str,[forRow] OOGUIRow row)
BOOL isDown:(int key)
OOColor * cyanColor()
Definition OOColor.m:274
OOColor * greenColor()
Definition OOColor.m:264
NSDictionary * guiButtonFunctions()
NSDictionary * buttonFunctions()
void unsetButtonFunction:(int function)
void setFunction:withDict:(int function,[withDict] NSDictionary *stickFn)
NSDictionary * axisFunctions()
void unsetAxisFunction:(int function)
const BOOL * getAllButtonStates()
void setCallback:object:hardware:(SEL selector,[object] id obj,[hardware] char hwflags)
void displayFunctionList:skip:(GuiDisplayGen *gui, [skip] NSUInteger skip)
BOOL checkKeyPress:(NSArray *key_def)
void checkCustomEquipButtons:ignore:(NSDictionary *stickFn, [ignore] int idx)
void removeFunction:(int idx)
NSDictionary * makeStickGuiDictHeader:(NSString *header)
void setGuiToStickMapperScreen:(unsigned skip)
NSDictionary * makeStickGuiDict:allowable:axisfn:butfn:(NSString *what,[allowable] int allowable,[axisfn] int axisfn,[butfn] int butfn)
NSString * describeStickDict:(NSDictionary *stickDict)
void setGuiToStickMapperScreen:resetCurrentRow:(unsigned skip,[resetCurrentRow] BOOL resetCurrentRow)
void setGuiToStickProfileScreen:(GuiDisplayGen *gui)
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque