Oolite
Loading...
Searching...
No Matches
PlayerEntityControls.m
Go to the documentation of this file.
1/*
2
3PlayerEntityControls.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
31#import "PlayerEntitySound.h"
34
35#import "AI.h"
36#import "DockEntity.h"
37#import "GameController.h"
38#import "HeadUpDisplay.h"
39#import "MyOpenGLView.h"
41#import "OOConstToJSString.h"
42#import "OOConstToString.h"
43#import "OODebugFlags.h"
44#import "OOLoggingExtended.h"
45#import "OOMusicController.h"
46#import "OOOXZManager.h"
47#import "OOPlanetEntity.h"
48#import "OOSound.h"
49#import "OOStringExpander.h"
50#import "OOStringParsing.h"
51#import "OOSunEntity.h"
52#import "OOTexture.h"
53#import "ResourceManager.h"
54#import "ShipEntityAI.h"
55#import "StationEntity.h"
56#import "Universe.h"
57
58#import "OOJoystickManager.h"
60
61#import "OOEquipmentType.h"
62#import "OOJSGuiScreenKeyDefinition.h"
63#import "OOJSScript.h"
64
65#import "OODebugMonitor.h"
66#import "OODebugSupport.h"
67
68#define CUSTOM_VIEW_ROTATE_SPEED 1.0
69#define CUSTOM_VIEW_ZOOM_SPEED 5.0
70#define CUSTOM_VIEW_SPEED_REDUCTION_FACTOR 0.3
71
72static BOOL jump_pressed;
75static BOOL pause_pressed;
89static BOOL ident_pressed;
90static BOOL safety_pressed;
95#ifdef OO_DEBUG_MONITOR_ENABLED
96static BOOL dump_target_state_pressed;
97static BOOL dump_entity_list_pressed;
98#endif
99static BOOL taking_snapshot;
101static BOOL f_key_pressed;
102static BOOL m_key_pressed;
103static BOOL pling_pressed;
104static BOOL cursor_moving;
106static BOOL f9_key_pressed;
107#if OO_RESOLUTION_OPTION
109#endif
110#if OOLITE_SPEECH_SYNTH
111static BOOL speech_settings_pressed;
112#if OOLITE_ESPEAK
113static BOOL speechVoiceSelectKeyPressed;
114static BOOL speechGenderSelectKeyPressed;
115#endif
116#endif
117static BOOL wait_for_key_up;
124#if OOLITE_WINDOWS
125static BOOL hdrMaxBrightnessControlPressed;
126static BOOL hdrPaperWhiteControlPressed;
127#endif
130static BOOL selectPressed;
131static BOOL queryPressed;
132static BOOL spacePressed;
136// static BOOL switching_market_screens;
139static BOOL zoom_pressed;
145static BOOL mouse_left_down;
153static NSPoint mouse_click_position;
155
156static NSUInteger searchStringLength;
157static double timeLastKeyPress;
158// static OOGUIRow oldSelection;
160static double saved_script_time;
163static int pressedArrow = 0;
164static BOOL mouse_x_axis_map_to_yaw = NO;
165static NSTimeInterval time_last_frame;
166
167@interface PlayerEntity (OOControlsPrivate)
168
169- (void)pollFlightControls:(double)delta_t;
170- (void)pollFlightArrowKeyControls:(double)delta_t;
171- (void)pollGuiArrowKeyControls:(double)delta_t;
178- (void)pollViewControls;
180- (void)pollGuiScreenControlsWithFKeyAlias:(BOOL)fKeyAlias;
182- (void)handleUndockControl;
183- (void)pollGameOverControls:(double)delta_t;
184- (void)pollAutopilotControls:(double)delta_t;
185- (void)pollDockedControls:(double)delta_t;
186- (void)pollDemoControls:(double)delta_t;
190- (void)switchToThisView:(OOViewID)viewDirection;
191- (void)switchToThisView:(OOViewID)viewDirection andProcessWeaponFacing:(BOOL)processWeaponFacing;
192- (void)switchToThisView:(OOViewID)viewDirection fromView:(OOViewID)oldViewDirection andProcessWeaponFacing:(BOOL)processWeaponFacing justNotify:(BOOL)justNotify;
193
194- (void)handleAutopilotOn:(BOOL)fastDocking;
195
196// Handlers for individual controls
197- (void)handleButtonIdent;
199@end
200
201@implementation PlayerEntity (Controls)
202
204{
205 [keyCodeLookups release];
206 // all entries in this dict must be in lowercase
207 keyCodeLookups = [[NSDictionary alloc] initWithObjectsAndKeys:
208 [NSNumber numberWithUnsignedShort:gvArrowKeyLeft], @"arrowleft",
209 [NSNumber numberWithUnsignedShort:gvArrowKeyLeft], @"leftarrow",
210 [NSNumber numberWithUnsignedShort:gvArrowKeyLeft], @"left",
211 [NSNumber numberWithUnsignedShort:gvArrowKeyRight], @"arrowright",
212 [NSNumber numberWithUnsignedShort:gvArrowKeyRight], @"rightarrow",
213 [NSNumber numberWithUnsignedShort:gvArrowKeyRight], @"right",
214 [NSNumber numberWithUnsignedShort:gvArrowKeyUp], @"arrowup",
215 [NSNumber numberWithUnsignedShort:gvArrowKeyUp], @"uparrow",
216 [NSNumber numberWithUnsignedShort:gvArrowKeyUp], @"up",
217 [NSNumber numberWithUnsignedShort:gvArrowKeyDown], @"arrowdown",
218 [NSNumber numberWithUnsignedShort:gvArrowKeyDown], @"downarrow",
219 [NSNumber numberWithUnsignedShort:gvArrowKeyDown], @"down",
220 [NSNumber numberWithUnsignedShort:gvPageUpKey], @"pageup",
221 [NSNumber numberWithUnsignedShort:gvPageDownKey], @"pagedown",
222 [NSNumber numberWithUnsignedShort:13], @"enter",
223 [NSNumber numberWithUnsignedShort:13], @"return",
224 [NSNumber numberWithUnsignedShort:27], @"escape",
225 [NSNumber numberWithUnsignedShort:27], @"esc",
226 [NSNumber numberWithUnsignedShort:9], @"tab",
227 [NSNumber numberWithUnsignedShort:32], @"space",
228 [NSNumber numberWithUnsignedShort:32], @"spc",
229 [NSNumber numberWithUnsignedShort:gvHomeKey], @"home",
230 [NSNumber numberWithUnsignedShort:gvEndKey], @"end",
231 [NSNumber numberWithUnsignedShort:gvDeleteKey], @"delete",
232 [NSNumber numberWithUnsignedShort:gvDeleteKey], @"del",
233 [NSNumber numberWithUnsignedShort:gvBackspaceKey], @"backspace",
234 [NSNumber numberWithUnsignedShort:gvBackspaceKey], @"backspc",
235 [NSNumber numberWithUnsignedShort:gvBackspaceKey], @"bkspace",
236 [NSNumber numberWithUnsignedShort:gvBackspaceKey], @"bkspc",
237 [NSNumber numberWithUnsignedShort:gvInsertKey], @"insert",
238 [NSNumber numberWithUnsignedShort:gvInsertKey], @"ins",
239 [NSNumber numberWithUnsignedShort:gvFunctionKey1], @"f1",
240 [NSNumber numberWithUnsignedShort:gvFunctionKey2], @"f2",
241 [NSNumber numberWithUnsignedShort:gvFunctionKey3], @"f3",
242 [NSNumber numberWithUnsignedShort:gvFunctionKey4], @"f4",
243 [NSNumber numberWithUnsignedShort:gvFunctionKey5], @"f5",
244 [NSNumber numberWithUnsignedShort:gvFunctionKey6], @"f6",
245 [NSNumber numberWithUnsignedShort:gvFunctionKey7], @"f7",
246 [NSNumber numberWithUnsignedShort:gvFunctionKey8], @"f8",
247 [NSNumber numberWithUnsignedShort:gvFunctionKey9], @"f9",
248 [NSNumber numberWithUnsignedShort:gvFunctionKey10], @"f10",
249 [NSNumber numberWithUnsignedShort:gvFunctionKey11], @"f11",
250 [NSNumber numberWithUnsignedShort:gvPauseKey], @"pause",
251 [NSNumber numberWithUnsignedShort:gvPrintScreenKey], @"printscreen",
252 [NSNumber numberWithUnsignedShort:gvPrintScreenKey], @"prtscrn",
253 [NSNumber numberWithUnsignedShort:gvPrintScreenKey], @"prntscrn",
254 [NSNumber numberWithUnsignedShort:gvPrintScreenKey], @"prtscn",
255 [NSNumber numberWithUnsignedShort:gvNumberPadKey0], @"numpad0",
256 [NSNumber numberWithUnsignedShort:gvNumberPadKey1], @"numpad1",
257 [NSNumber numberWithUnsignedShort:gvNumberPadKey2], @"numpad2",
258 [NSNumber numberWithUnsignedShort:gvNumberPadKey3], @"numpad3",
259 [NSNumber numberWithUnsignedShort:gvNumberPadKey4], @"numpad4",
260 [NSNumber numberWithUnsignedShort:gvNumberPadKey5], @"numpad5",
261 [NSNumber numberWithUnsignedShort:gvNumberPadKey6], @"numpad6",
262 [NSNumber numberWithUnsignedShort:gvNumberPadKey7], @"numpad7",
263 [NSNumber numberWithUnsignedShort:gvNumberPadKey8], @"numpad8",
264 [NSNumber numberWithUnsignedShort:gvNumberPadKey9], @"numpad9",
265 [NSNumber numberWithUnsignedShort:gvNumberPadKeyDivide], @"numpad/",
266 [NSNumber numberWithUnsignedShort:gvNumberPadKeyDivide], @"numpaddivide",
267 [NSNumber numberWithUnsignedShort:gvNumberPadKeyMultiply], @"numpad*",
268 [NSNumber numberWithUnsignedShort:gvNumberPadKeyMultiply], @"numpadmultiply",
269 [NSNumber numberWithUnsignedShort:gvNumberPadKeyMinus], @"numpad-",
270 [NSNumber numberWithUnsignedShort:gvNumberPadKeyMinus], @"numpadminus",
271 [NSNumber numberWithUnsignedShort:gvNumberPadKeyPlus], @"numpad+",
272 [NSNumber numberWithUnsignedShort:gvNumberPadKeyPlus], @"numpadplus",
273 [NSNumber numberWithUnsignedShort:gvNumberPadKeyPeriod], @"numpad.",
274 [NSNumber numberWithUnsignedShort:gvNumberPadKeyPeriod], @"numpadperiod",
275 [NSNumber numberWithUnsignedShort:gvNumberPadKeyEquals], @"numpad=",
276 [NSNumber numberWithUnsignedShort:gvNumberPadKeyEquals], @"numpadequals",
277 [NSNumber numberWithUnsignedShort:gvNumberPadKeyEnter], @"numpadenter", nil];
278
279 keyShiftText = [DESC(@"oolite-keyconfig-shift") retain];
280 keyMod1Text = [DESC(@"oolite-keyconfig-mod1") retain];
281#if OOLITE_MAC_COCOA_UI
282 keyMod2Text = [DESC(@"oolite-keyconfig-mod2-mac") retain];
283#else
284 keyMod2Text = [DESC(@"oolite-keyconfig-mod2-pc") retain];
285#endif
286
288
289 // Enable polling
290 pollControls = YES;
291}
292
294{
295 NSMutableDictionary* kdicmaster = [NSMutableDictionary dictionaryWithDictionary:[ResourceManager dictionaryFromFilesNamed:@"keyconfig2.plist" inFolder:@"Config" mergeMode:MERGE_BASIC cache:NO]];
296 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
297 NSString* kbd = [defaults oo_stringForKey:@"keyboard-code" defaultValue:@"default"];
298 NSMutableDictionary* kdic2 = [NSMutableDictionary dictionaryWithDictionary:[kdicmaster objectForKey:kbd]];
299
300 unsigned i;
301 NSArray* keys = nil;
302 id key = nil;
303 NSArray* def_list = nil;
304
305 keys = [kdic2 allKeys];
306 for (i = 0; i < [keys count]; i++) {
307 key = [keys objectAtIndex:i];
308 if ([[kdic2 objectForKey:key] isKindOfClass:[NSArray class]]) {
309 def_list = (NSArray*)[kdic2 objectForKey:key];
310 [kdic2 setObject:[self processKeyCode:def_list] forKey:key];
311 }
312 }
313
314 // load custom equipment keys/buttons
315 [customEquipActivation release];
316 if ([defaults objectForKey:KEYCONFIG_CUSTOMEQUIP]) {
317 NSArray* temp = [defaults arrayForKey:KEYCONFIG_CUSTOMEQUIP];
318 customEquipActivation = [[NSMutableArray arrayWithArray:temp] retain];
319 } else {
320 customEquipActivation = [[NSMutableArray alloc] init];
321 }
322 [customActivatePressed release];
323 [customModePressed release];
324 customActivatePressed = [[NSMutableArray alloc] init];
325 customModePressed = [[NSMutableArray alloc] init];
326 for (i = 0; i < [customEquipActivation count]; i++) {
327 [customActivatePressed addObject:[NSNumber numberWithBool:NO]];
328 [customModePressed addObject:[NSNumber numberWithBool:NO]];
329 }
330
331 NSMutableArray* keyDef = nil;
332 NSString* lookup = nil;
333 NSArray* curr = nil;
334 NSDictionary* key1 = nil;
335 NSDictionary* key2 = nil;
336
337 // update with overrides from defaults file
338 NSDictionary* dict = [defaults objectForKey:KEYCONFIG_OVERRIDES];
339
340 keys = [dict allKeys];
341 for (i = 0; i < [keys count]; i++) {
342 key = [keys objectAtIndex:i];
343 [kdic2 setObject:[dict objectForKey:key] forKey:key];
344 }
345
346// by default none of the standard key functions require more than 2 entries, so our macro will limit itself to 2
347// also, none of the standard key functions utilise "Alt" (mod2), so we're defaulting that setting
348#define LOAD_KEY_SETTING2(name, default_1, shift_1, mod1_1, default_2, shift_2, mod1_2) \
349 lookup = [@ #name substringFromIndex:2]; \
350 curr = (NSArray*)[[kdic2 objectForKey:lookup] copy]; \
351 key1 = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithUnsignedShort:default_1], @"key", [NSNumber numberWithBool:shift_1], @"shift", [NSNumber numberWithBool:mod1_1], @"mod1", [NSNumber numberWithBool:NO], @"mod2", nil]; \
352 [keyDef addObject:key1]; \
353 if (default_2 > 0) { \
354 key2 = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithUnsignedShort:default_2], @"key", [NSNumber numberWithBool:shift_2], @"shift", [NSNumber numberWithBool:mod1_2], @"mod1", [NSNumber numberWithBool:NO], @"mod2", nil]; \
355 [keyDef addObject:key2]; \
356 } \
357 name = curr ?: keyDef; \
358 [kdic2 setObject:curr ?: keyDef forKey:lookup]; \
359 [keyDef release];
360
361 LOAD_KEY_SETTING2(n_key_roll_left, gvArrowKeyLeft, NO, NO, 0, NO, NO);
362 LOAD_KEY_SETTING2(n_key_roll_right, gvArrowKeyRight, NO, NO, 0, NO, NO);
363 LOAD_KEY_SETTING2(n_key_pitch_forward, gvArrowKeyUp, NO, NO, 0, NO, NO);
364 LOAD_KEY_SETTING2(n_key_pitch_back, gvArrowKeyDown, NO, NO, 0, NO, NO);
365 LOAD_KEY_SETTING2(n_key_yaw_left, ',', NO, NO, 0, NO, NO);
366 LOAD_KEY_SETTING2(n_key_yaw_right, '.', NO, NO, 0, NO, NO);
367
368 LOAD_KEY_SETTING2(n_key_view_forward, '1', NO, NO, gvFunctionKey1, NO, NO);
369 LOAD_KEY_SETTING2(n_key_view_aft, '2', NO, NO, gvFunctionKey2, NO, NO);
370 LOAD_KEY_SETTING2(n_key_view_port, '3', NO, NO, gvFunctionKey3, NO, NO);
371 LOAD_KEY_SETTING2(n_key_view_starboard, '4', NO, NO, gvFunctionKey4, NO, NO);
372
373 LOAD_KEY_SETTING2(n_key_launch_ship, '1', NO, NO, gvFunctionKey1, NO, NO);
374 LOAD_KEY_SETTING2(n_key_gui_screen_options, '2', NO, NO, gvFunctionKey2, NO, NO);
375 LOAD_KEY_SETTING2(n_key_gui_screen_equipship, '3', NO, NO, gvFunctionKey3, NO, NO);
376 LOAD_KEY_SETTING2(n_key_gui_screen_interfaces, '4', NO, NO, gvFunctionKey4, NO, NO);
377 LOAD_KEY_SETTING2(n_key_gui_screen_status, '5', NO, NO, gvFunctionKey5, NO, NO);
378 LOAD_KEY_SETTING2(n_key_gui_chart_screens, '6', NO, NO, gvFunctionKey6, NO, NO);
379 LOAD_KEY_SETTING2(n_key_gui_system_data, '7', NO, NO, gvFunctionKey7, NO, NO);
380 LOAD_KEY_SETTING2(n_key_gui_market, '8', NO, NO, gvFunctionKey8, NO, NO);
381
382 LOAD_KEY_SETTING2(n_key_gui_arrow_left, gvArrowKeyLeft, NO, NO, 0, NO, NO);
383 LOAD_KEY_SETTING2(n_key_gui_arrow_right, gvArrowKeyRight, NO, NO, 0, NO, NO);
384 LOAD_KEY_SETTING2(n_key_gui_arrow_up, gvArrowKeyUp, NO, NO, 0, NO, NO);
385 LOAD_KEY_SETTING2(n_key_gui_arrow_down, gvArrowKeyDown, NO, NO, 0, NO, NO);
386 LOAD_KEY_SETTING2(n_key_gui_page_up, gvPageUpKey, NO, NO, 0, NO, NO);
387 LOAD_KEY_SETTING2(n_key_gui_page_down, gvPageDownKey, NO, NO, 0, NO, NO);
388 LOAD_KEY_SETTING2(n_key_gui_select, 13, NO, NO, gvNumberPadKeyEnter, NO, NO);
389
390 LOAD_KEY_SETTING2(n_key_increase_speed, 'w', NO, NO, 0, NO, NO);
391 LOAD_KEY_SETTING2(n_key_decrease_speed, 's', NO, NO, 0, NO, NO);
392 LOAD_KEY_SETTING2(n_key_inject_fuel, 'i', NO, NO, 0, NO, NO);
393
394 LOAD_KEY_SETTING2(n_key_fire_lasers, 'a', NO, NO, 0, NO, NO);
395 LOAD_KEY_SETTING2(n_key_weapons_online_toggle, '_', YES, NO, 0, NO, NO);
396 LOAD_KEY_SETTING2(n_key_launch_missile, 'm', NO, NO, 0, NO, NO);
397 LOAD_KEY_SETTING2(n_key_next_missile, 'y', NO, NO, 0, NO, NO);
398 LOAD_KEY_SETTING2(n_key_ecm, 'e', NO, NO, 0, NO, NO);
399
400 LOAD_KEY_SETTING2(n_key_prime_next_equipment, 'N', YES, NO, 0, NO, NO);
401 LOAD_KEY_SETTING2(n_key_prime_previous_equipment, 'N', YES, YES, 0, NO, NO);
402 LOAD_KEY_SETTING2(n_key_activate_equipment, 'n', NO, NO, 0, NO, NO);
403 LOAD_KEY_SETTING2(n_key_mode_equipment, 'b', NO, NO, 0, NO, NO);
404 LOAD_KEY_SETTING2(n_key_fastactivate_equipment_a, '0', NO, NO, 0, NO, NO);
405 LOAD_KEY_SETTING2(n_key_fastactivate_equipment_b, 9, NO, NO, 0, NO, NO);
406
407 LOAD_KEY_SETTING2(n_key_target_missile, 't', NO, NO, 0, NO, NO);
408 LOAD_KEY_SETTING2(n_key_untarget_missile, 'u', NO, NO, 0, NO, NO);
409 LOAD_KEY_SETTING2(n_key_target_incoming_missile, 'T', YES, NO, 0, NO, NO);
410 LOAD_KEY_SETTING2(n_key_ident_system, 'r', NO, NO, 0, NO, NO);
411
412 LOAD_KEY_SETTING2(n_key_scanner_zoom, 'z', NO, NO, 0, NO, NO);
413 LOAD_KEY_SETTING2(n_key_scanner_unzoom, 'Z', YES, NO, 0, NO, NO);
414
415 LOAD_KEY_SETTING2(n_key_launch_escapepod, 27, NO, NO, 0, NO, NO);
416
417 LOAD_KEY_SETTING2(n_key_galactic_hyperspace, 'g', NO, NO, 0, NO, NO);
418 LOAD_KEY_SETTING2(n_key_hyperspace, 'h', NO, NO, 0, NO, NO);
419 LOAD_KEY_SETTING2(n_key_jumpdrive, 'j', NO, NO, 0, NO, NO);
420
421 LOAD_KEY_SETTING2(n_key_dump_cargo, 'D', YES, NO, 0, NO, NO);
422 LOAD_KEY_SETTING2(n_key_rotate_cargo, 'R', YES, NO, 0, NO, NO);
423
424 LOAD_KEY_SETTING2(n_key_autopilot, 'c', NO, NO, 0, NO, NO);
425 LOAD_KEY_SETTING2(n_key_autodock, 'C', YES, NO, 0, NO, NO);
426 LOAD_KEY_SETTING2(n_key_docking_clearance_request, 'L', YES, NO, 0, NO, NO);
427
428 LOAD_KEY_SETTING2(n_key_snapshot, '*', YES, NO, gvNumberPadKeyMultiply, NO, NO);
429 LOAD_KEY_SETTING2(n_key_docking_music, 's', NO, NO, 0, NO, NO);
430
431 LOAD_KEY_SETTING2(n_key_advanced_nav_array_next, '^', YES, NO, 0, NO, NO);
432 LOAD_KEY_SETTING2(n_key_advanced_nav_array_previous, '^', YES, YES, 0, NO, NO);
433 LOAD_KEY_SETTING2(n_key_map_home, gvHomeKey, NO, NO, 0, NO, NO);
434 LOAD_KEY_SETTING2(n_key_map_end, gvEndKey, NO, NO, 0, NO, NO);
435 LOAD_KEY_SETTING2(n_key_map_next_system, gvArrowKeyRight, NO, NO, gvArrowKeyDown, NO, NO);
436 LOAD_KEY_SETTING2(n_key_map_previous_system, gvArrowKeyLeft, NO, NO, gvArrowKeyUp, NO, NO);
437 LOAD_KEY_SETTING2(n_key_map_zoom_in, gvPageDownKey, NO, NO, 0, NO, NO);
438 LOAD_KEY_SETTING2(n_key_map_zoom_out, gvPageUpKey, NO, NO, 0, NO, NO);
439 LOAD_KEY_SETTING2(n_key_map_info, 'i', NO, NO, 0, NO, NO);
440 LOAD_KEY_SETTING2(n_key_chart_highlight, '?', YES, NO, 0, NO, NO);
441
442 LOAD_KEY_SETTING2(n_key_system_home, gvHomeKey, NO, NO, 0, NO, NO);
443 LOAD_KEY_SETTING2(n_key_system_end, gvEndKey, NO, NO, 0, NO, NO);
444 LOAD_KEY_SETTING2(n_key_system_next_system, gvArrowKeyRight, NO, NO, gvArrowKeyDown, NO, NO);
445 LOAD_KEY_SETTING2(n_key_system_previous_system, gvArrowKeyLeft, NO, NO, gvArrowKeyUp, NO, NO);
446
447 LOAD_KEY_SETTING2(n_key_pausebutton, 'p', NO, NO, 0, NO, NO);
448 LOAD_KEY_SETTING2(n_key_show_fps, 'F', YES, NO, 0, NO, NO);
449 LOAD_KEY_SETTING2(n_key_bloom_toggle, gvFunctionKey9, YES, NO, 0, NO, NO);
450 LOAD_KEY_SETTING2(n_key_mouse_control_roll, 'M', YES, NO, 0, NO, NO);
451 LOAD_KEY_SETTING2(n_key_mouse_control_yaw, 'M', YES, YES, 0, NO, NO);
452 LOAD_KEY_SETTING2(n_key_hud_toggle, 'o', NO, NO, 0, NO, NO);
453
454 LOAD_KEY_SETTING2(n_key_comms_log, '`', YES, NO, 0, NO, NO);
455 LOAD_KEY_SETTING2(n_key_prev_compass_mode, '|', YES, NO, 0, NO, NO);
456 LOAD_KEY_SETTING2(n_key_next_compass_mode, '\\', NO, NO, 0, NO, NO);
457
458 LOAD_KEY_SETTING2(n_key_market_filter_cycle, '?', YES, NO, 0, NO, NO);
459 LOAD_KEY_SETTING2(n_key_market_sorter_cycle, '/', NO, NO, gvNumberPadKeyDivide, NO, NO);
460 LOAD_KEY_SETTING2(n_key_market_buy_one, gvArrowKeyRight, NO, NO, 0, NO, NO);
461 LOAD_KEY_SETTING2(n_key_market_sell_one, gvArrowKeyLeft, NO, NO, 0, NO, NO);
462 LOAD_KEY_SETTING2(n_key_market_buy_max, gvArrowKeyRight, YES, NO, 0, NO, NO);
463 LOAD_KEY_SETTING2(n_key_market_sell_max, gvArrowKeyLeft, YES, NO, 0, NO, NO);
464
465 LOAD_KEY_SETTING2(n_key_cycle_next_mfd, ';', NO, NO, 0, NO, NO);
466 LOAD_KEY_SETTING2(n_key_cycle_previous_mfd, ';', NO, YES, 0, NO, NO);
467 LOAD_KEY_SETTING2(n_key_switch_next_mfd, ':', YES, NO, 0, NO, NO);
468 LOAD_KEY_SETTING2(n_key_switch_previous_mfd, ':', YES, YES, 0, NO, NO);
469
470 LOAD_KEY_SETTING2(n_key_next_target, '+', YES, NO, gvNumberPadKeyPlus, NO, NO);
471 LOAD_KEY_SETTING2(n_key_previous_target, '-', NO, NO, gvNumberPadKeyMinus, NO, NO);
472
473 LOAD_KEY_SETTING2(n_key_custom_view, 'v', NO, NO, 0, NO, NO);
474 LOAD_KEY_SETTING2(n_key_custom_view_zoom_out, gvPageDownKey, NO, NO, 0, NO, NO);
475 LOAD_KEY_SETTING2(n_key_custom_view_zoom_in, gvPageUpKey, NO, NO, 0, NO, NO);
476 LOAD_KEY_SETTING2(n_key_custom_view_roll_left, gvArrowKeyLeft, NO, NO, 0, NO, NO);
477 LOAD_KEY_SETTING2(n_key_custom_view_pan_left, gvArrowKeyLeft, YES, NO, 0, NO, NO);
478 LOAD_KEY_SETTING2(n_key_custom_view_roll_right, gvArrowKeyRight, NO, NO, 0, NO, NO);
479 LOAD_KEY_SETTING2(n_key_custom_view_pan_right, gvArrowKeyRight, YES, NO, 0, NO, NO);
480 LOAD_KEY_SETTING2(n_key_custom_view_rotate_up, gvArrowKeyUp, NO, NO, 0, NO, NO);
481 LOAD_KEY_SETTING2(n_key_custom_view_pan_up, gvArrowKeyUp, YES, NO, 0, NO, NO);
482 LOAD_KEY_SETTING2(n_key_custom_view_rotate_down, gvArrowKeyDown, NO, NO, 0, NO, NO);
483 LOAD_KEY_SETTING2(n_key_custom_view_pan_down, gvArrowKeyDown, YES, NO, 0, NO, NO);
484 LOAD_KEY_SETTING2(n_key_custom_view_rotate_left, ',', NO, NO, 0, NO, NO);
485 LOAD_KEY_SETTING2(n_key_custom_view_rotate_right, '.', NO, NO, 0, NO, NO);
486
487 LOAD_KEY_SETTING2(n_key_oxzmanager_setfilter, 'f', NO, NO, 0, NO, NO);
488 LOAD_KEY_SETTING2(n_key_oxzmanager_showinfo, 'i', NO, NO, 0, NO, NO);
489 LOAD_KEY_SETTING2(n_key_oxzmanager_copyurl, 'c', NO, NO, 0, NO, NO);
490 LOAD_KEY_SETTING2(n_key_oxzmanager_extract, 'x', NO, NO, 0, NO, NO);
491
492#if OO_FOV_INFLIGHT_CONTROL_ENABLED
493 LOAD_KEY_SETTING2(n_key_inc_field_of_view, 'l', NO, NO, 0, NO, NO);
494 LOAD_KEY_SETTING2(n_key_dec_field_of_view, 'k', NO, NO, 0, NO, NO);
495#endif
496
497#ifdef OO_DEBUG_MONITOR_ENABLED
498 LOAD_KEY_SETTING2(n_key_dump_target_state, 'H', YES, NO, 0, NO, NO);
499 LOAD_KEY_SETTING2(n_key_dump_entity_list, '0', NO, NO, 0, NO, NO);
500 LOAD_KEY_SETTING2(n_key_debug_full, 'd', NO, NO, 0, NO, NO);
501 LOAD_KEY_SETTING2(n_key_debug_collision, 'b', NO, NO, 0, NO, NO);
502 LOAD_KEY_SETTING2(n_key_debug_console_connect, 'c', NO, NO, 0, NO, NO);
503 LOAD_KEY_SETTING2(n_key_debug_bounding_boxes, 'x', NO, NO, 0, NO, NO);
504 LOAD_KEY_SETTING2(n_key_debug_shaders, 's', NO, NO, 0, NO, NO);
505 LOAD_KEY_SETTING2(n_key_debug_off, 'n', NO, NO, 0, NO, NO);
506#endif
507
508 [keyconfig2_settings release];
509 keyconfig2_settings = [[NSDictionary alloc] initWithDictionary:kdic2 copyItems:YES];
510}
511
512- (NSArray*)processKeyCode:(NSArray*)key_def
513{
514 int i;
515 id key = nil, value = nil;
516 int iValue;
517 unsigned char keychar;
518 NSString* keystring = nil;
519 NSDictionary* def = nil;
520 NSMutableArray* newList = [[NSMutableArray alloc] init];
521
522 for (i = 0; i < [key_def count]; i++) {
523 def = [key_def objectAtIndex:i];
524 if ([def count] == 0)
525 continue; // skip this if the definition is empty
526 value = [def objectForKey:@"key"];
527 iValue = [value intValue];
528
529 // we're going to fully expand all the shift/mod1/mod2 properties for all the key setting with defaults
530 // to avoid the need to check for the presence of a property during game loops
531 NSMutableDictionary* defNew = [[NSMutableDictionary alloc] init];
532 if ([def objectForKey:@"shift"])
533 [defNew setObject:[def objectForKey:@"shift"] forKey:@"shift"];
534 else
535 [defNew setObject:[NSNumber numberWithBool:NO] forKey:@"shift"];
536 if ([def objectForKey:@"mod1"])
537 [defNew setObject:[def objectForKey:@"mod1"] forKey:@"mod1"];
538 else
539 [defNew setObject:[NSNumber numberWithBool:NO] forKey:@"mod1"];
540 if ([def objectForKey:@"mod2"])
541 [defNew setObject:[def objectForKey:@"mod2"] forKey:@"mod2"];
542 else
543 [defNew setObject:[NSNumber numberWithBool:NO] forKey:@"mod2"];
544
545 // for '0' '1' '2' '3' '4' '5' '6' '7' '8' '9' - we want to interpret those as strings - not numbers
546 // alphabetical characters and symbols will return an intValue of 0.
547
548 if ([value isKindOfClass:[NSString class]] && (iValue < 10)) {
549 keystring = value;
550
551 // check for a named lookup
552 if ([keystring length] != 0) {
553 int checkVal;
554 checkVal = [[keyCodeLookups objectForKey:[keystring lowercaseString]] intValue];
555 if (checkVal > 0) {
556 iValue = checkVal;
557
558 [defNew setObject:[NSNumber numberWithUnsignedShort:iValue] forKey:@"key"];
559 [newList addObject:defNew];
560 [defNew release];
561 continue;
562 }
563 }
564
565 if ([keystring length] == 1 || (iValue == 0 && [keystring length] != 0)) {
566 keychar = [keystring characterAtIndex:0] & 0x00ff; // uses lower byte of unichar
567 } else if (iValue <= 0xFF)
568 keychar = iValue;
569 else {
570 OOLogWARN(@"testing", @"continue hit for key %@.", key);
571 [defNew setObject:[def objectForKey:@"key"] forKey:@"key"];
572 [newList addObject:defNew];
573 [defNew release];
574 continue;
575 }
576
577 [defNew setObject:[NSNumber numberWithUnsignedShort:keychar] forKey:@"key"];
578 [newList addObject:defNew];
579 [defNew release];
580 } else {
581 [defNew setObject:[def objectForKey:@"key"] forKey:@"key"];
582 [newList addObject:defNew];
583 [defNew release];
584 }
585 }
586
587 return newList;
588}
589
590// special case for navigation keys - these keys cannot use mod keys, so they can't be impacted by multiple keypresses
591- (BOOL)checkNavKeyPress:(NSArray*)key_def
592{
593 MyOpenGLView* gameView = [UNIVERSE gameView];
594 int i;
595 for (i = 0; i < [key_def count]; i++) {
596 NSDictionary* def = [key_def objectAtIndex:i];
597 if ([gameView isDown:[[def objectForKey:@"key"] intValue]])
598 return YES;
599 }
600 return NO;
601}
602
603- (BOOL)checkKeyPress:(NSArray*)key_def
604{
605 return [self checkKeyPress:key_def fKey_only:NO ignore_ctrl:NO];
606}
607
608- (BOOL)checkKeyPress:(NSArray*)key_def fKey_only:(BOOL)fKey_only
609{
610 return [self checkKeyPress:key_def fKey_only:fKey_only ignore_ctrl:NO];
611}
612
613- (BOOL)checkKeyPress:(NSArray*)key_def ignore_ctrl:(BOOL)ignore_ctrl
614{
615 return [self checkKeyPress:key_def fKey_only:NO ignore_ctrl:ignore_ctrl];
616}
617
618- (BOOL)checkKeyPress:(NSArray*)key_def fKey_only:(BOOL)fKey_only ignore_ctrl:(BOOL)ignore_ctrl
619{
620 MyOpenGLView* gameView = [UNIVERSE gameView];
621 int i;
622 for (i = 0; i < [key_def count]; i++) {
623 NSDictionary* def = [key_def objectAtIndex:i];
624 int keycode = [[def objectForKey:@"key"] intValue];
625 // skip normal keys if the fKey_only flag is set
626 // note: if the player has remapped the gui screen keys to not include function keys, they will not be able to
627 // switch screens directly (they would need to finish the task - ie press enter, or use the escape key to cancel the function)
628 // note: the logic below now means that the state of the modifiers must match the requirements for the key binding, including
629 // when all settings are off. This means, if the player presses two functions at once, one that requires a modifier and
630 // one that doesn't, the one that doesn't will not be triggered.
631 if (fKey_only == YES && (keycode < gvFunctionKey1 || keycode > gvFunctionKey11))
632 continue;
633 if ([gameView isDown:keycode]
634 && ([[def objectForKey:@"shift"] boolValue] == [gameView isShiftDown])
635 && (ignore_ctrl || ([[def objectForKey:@"mod1"] boolValue] == [gameView isCtrlDown]))
636 && ([[def objectForKey:@"mod2"] boolValue] == [gameView isOptDown]))
637 return YES;
638 }
639 return NO;
640}
641
642- (int)getFirstKeyCode:(NSArray*)key_def
643{
644 NSDictionary* def = [key_def objectAtIndex:0];
645 return [[def objectForKey:@"key"] intValue];
646}
647
648- (void)pollControls:(double)delta_t
649{
650 MyOpenGLView* gameView = [UNIVERSE gameView];
651 NSString* exceptionContext = @"setup";
652
653 @try {
654 if (gameView) {
655 // poll the gameView keyboard things
656 exceptionContext = @"pollApplicationControls";
657 [self pollApplicationControls]; // quit command-f etc.
658 switch ([self status]) {
659 case STATUS_WITCHSPACE_COUNTDOWN:
660 case STATUS_IN_FLIGHT:
661 exceptionContext = @"pollFlightControls";
662 [self pollFlightControls:delta_t];
663 break;
664
665 case STATUS_DEAD:
666 exceptionContext = @"pollGameOverControls";
667 [self pollGameOverControls:delta_t];
668 break;
669
670 case STATUS_AUTOPILOT_ENGAGED:
671 exceptionContext = @"pollAutopilotControls";
672 [self pollAutopilotControls:delta_t];
673 break;
674
675 case STATUS_DOCKED:
676 exceptionContext = @"pollDockedControls";
677 [self pollDockedControls:delta_t];
678 break;
679
680 case STATUS_START_GAME:
681 exceptionContext = @"pollDemoControls";
682 [self pollDemoControls:delta_t];
683 break;
684
685 default:
686 // don't poll extra controls at any other times.
687 break;
688 }
689 }
690 }
691 @catch (NSException* exception) {
692 OOLog(kOOLogException, @"***** Exception checking controls [%@]: %@ : %@", exceptionContext, [exception name], [exception reason]);
693 }
694}
695
696// DJS + aegidian: Moved from the big switch/case block in pollGuiArrowKeyControls
698{
699 MyOpenGLView* gameView = [UNIVERSE gameView];
700 GuiDisplayGen* gui = [UNIVERSE gui];
701 const BOOL* joyButtonState = [[OOJoystickManager sharedStickHandler] getAllButtonStates];
702
703 BOOL result = NO;
704 BOOL arrow_up = [self checkKeyPress:n_key_gui_arrow_up] || joyButtonState[BUTTON_GUIUP];
705 BOOL arrow_down = [self checkKeyPress:n_key_gui_arrow_down] || joyButtonState[BUTTON_GUIDOWN];
706 BOOL mouse_click = [gameView isDown:gvMouseLeftButton];
707 BOOL mouse_dbl_click = [gameView isDown:gvMouseDoubleClick];
708
709 if (arrow_down) {
710 if ((!upDownKeyPressed) || (script_time > timeLastKeyPress + KEY_REPEAT_INTERVAL)) {
711 if ([gui setNextRow:+1]) {
712 result = YES;
713 } else {
714 if ([gui setFirstSelectableRow])
715 result = YES;
716 }
717
718 if (result && [gui selectableRange].length > 1)
720 else
722
723 timeLastKeyPress = script_time;
724 }
725 }
726
727 if (arrow_up) {
728 if ((!upDownKeyPressed) || (script_time > timeLastKeyPress + KEY_REPEAT_INTERVAL)) {
729 if ([gui setNextRow:-1]) {
730 result = YES;
731 } else {
732 if ([gui setLastSelectableRow])
733 result = YES;
734 }
735
736 if (result && [gui selectableRange].length > 1)
738 else
740
741 timeLastKeyPress = script_time;
742 }
743 }
744
745 if (mouse_click) {
746 if (!upDownKeyPressed) {
747 int click_row = 0;
748 if (UNIVERSE)
749 click_row = UNIVERSE->cursor_row;
750 if ([gui setSelectedRow:click_row]) {
751 result = YES;
752 }
753 }
754 }
755 if (mouse_dbl_click) {
756 int click_row = 0;
757 if (UNIVERSE)
758 click_row = UNIVERSE->cursor_row;
759 if ([gui setSelectedRow:click_row]) {
760 result = YES;
761 } else {
762 // if double-clicked on an unselectable row, clear the
763 // state so it doesn't activate whatever was last
764 // selected
766 }
767 }
768
769 upDownKeyPressed = (arrow_up || arrow_down || mouse_click);
770
771 return result;
772}
773
774- (void)targetNewSystem:(int)direction whileTyping:(BOOL)whileTyping
775{
776 target_system_id = [[UNIVERSE gui] targetNextFoundSystem:direction];
777 [self setInfoSystemID:target_system_id moveChart:YES];
778 cursor_coordinates = [[UNIVERSE systemManager] getCoordinatesForSystem:target_system_id inGalaxy:galaxy_number];
779
780 found_system_id = target_system_id;
781 if (!whileTyping) {
783 }
784 cursor_moving = YES;
785}
786
788{
789 [[UNIVERSE gameView] resetTypedString];
790 if (planetSearchString)
791 [planetSearchString release];
792 planetSearchString = nil;
793}
794
795- (void)targetNewSystem:(int)direction
796{
797 [self targetNewSystem:direction whileTyping:NO];
798}
799
801{
802 OOGUIScreenID oldScreen = gui_screen;
803 gui_screen = GUI_SCREEN_MAIN;
804 if (showDemoShips) {
805 [self setShowDemoShips:NO];
806 [UNIVERSE removeDemoShips];
807 }
808 [(MyOpenGLView*)[UNIVERSE gameView] allowStringInput:NO];
809 if ([self isMouseControlOn])
810 [[UNIVERSE gameView] resetMouse];
811 [UNIVERSE enterGUIViewModeWithMouseInteraction:NO];
812 [self noteGUIDidChangeFrom:oldScreen to:gui_screen];
813}
814
815- (void)noteSwitchToView:(OOViewID)toView fromView:(OOViewID)fromView
816{
817 [self switchToThisView:toView fromView:fromView andProcessWeaponFacing:NO justNotify:YES]; // no extra processing needed!
818}
819
820- (void)beginWitchspaceCountdown:(int)spin_time
821{
822 if ([self hasHyperspaceMotor]) {
823 if (spin_time == 0) {
824 witchspaceCountdown = hyperspaceMotorSpinTime;
825 } else {
826#ifndef OO_DUMP_PLANETINFO
827 if (spin_time < 5) {
828 witchspaceCountdown = 5;
829 } else
830#endif
831 {
832 witchspaceCountdown = spin_time;
833 }
834 }
835 [self setStatus:STATUS_WITCHSPACE_COUNTDOWN];
837 // say it!
838 [UNIVERSE clearPreviousMessage];
839 int seconds = round(witchspaceCountdown);
840 NSString* destination = [UNIVERSE getSystemName:[self nextHopTargetSystemID]];
841 [UNIVERSE displayCountdownMessage:OOExpandKey(@"witch-to-x-in-y-seconds", seconds, destination) forCount:1.0];
842 [self doScriptEvent:OOJSID("playerStartedJumpCountdown")
843 withArguments:[NSArray arrayWithObjects:@"standard", [NSNumber numberWithFloat:witchspaceCountdown], nil]];
844 [UNIVERSE preloadPlanetTexturesForSystem:target_system_id];
845 }
846}
847
849{
850 if ([self hasHyperspaceMotor]) {
851 [self beginWitchspaceCountdown:hyperspaceMotorSpinTime];
852 }
853}
854
856{
857 if ([self status] == STATUS_WITCHSPACE_COUNTDOWN) {
858 [self setStatus:STATUS_IN_FLIGHT];
860 }
861 // say it!
862 [UNIVERSE clearPreviousMessage];
863 [self doScriptEvent:OOJSID("playerCancelledJumpCountdown")];
864}
865
866@end
867
868@implementation PlayerEntity (OOControlsPrivate)
869
871{
872 if (!pollControls)
873 return;
874
875 NSString* exceptionContext = @"setup";
876
877 // does fullscreen / quit / snapshot
878 MyOpenGLView* gameView = [UNIVERSE gameView];
879 GameController* gameController = [UNIVERSE gameController];
880
881 BOOL onTextEntryScreen = (gui_screen == GUI_SCREEN_LONG_RANGE_CHART) || (gui_screen == GUI_SCREEN_MISSION) || (gui_screen == GUI_SCREEN_SAVE) || (gui_screen == GUI_SCREEN_OXZMANAGER || (gui_screen == GUI_SCREEN_KEYBOARD_ENTRY));
882
883 @try {
884// command-key controls
885#if !OOLITE_MAC_OS_X || !OOLITE_64_BIT // On 64-bit Macs, these are handled by normal menu shortcuts.
886 if ([gameController inFullScreenMode]) {
887 exceptionContext = @"command key controls";
888 if ([gameView isCommandFDown]) {
891 if (mouse_control_on) {
892 [UNIVERSE addMessage:DESC(@"mouse-off") forCount:3.0];
893 mouse_control_on = NO;
894 }
895 }
896
897 if ([gameView isCommandQDown]) {
898 [gameController pauseFullScreenModeToPerform:@selector(exitAppCommandQ) onTarget:gameController];
899 }
900 }
901#endif
902
903 // handle pressing Q or [esc] in error-handling mode
904 if ([self status] == STATUS_HANDLING_ERROR) {
905 exceptionContext = @"error handling mode";
906 if ([gameView isDown:113] || [gameView isDown:81] || [gameView isDown:27]) // 'q' | 'Q' | esc
907 {
908 [gameController exitAppWithContext:@"Q or escape pressed in error handling mode"];
909 }
910 }
911
912 if ([gameController isGamePaused]) {
913 // What's the status?
914 switch ([self status]) {
915 case STATUS_WITCHSPACE_COUNTDOWN:
916 case STATUS_IN_FLIGHT:
917 case STATUS_AUTOPILOT_ENGAGED:
918 case STATUS_DOCKED:
919 // Pause is handled inside their pollControls, no need to unpause.
920 break;
921
922 default: {
923 // In all other cases we can't handle pause. Unpause immediately.
924 script_time = saved_script_time;
926 if ([UNIVERSE pauseMessageVisible]) {
927 [UNIVERSE clearPreviousMessage]; // remove the 'paused' message.
928 }
930 } break;
931 }
932 }
933
934 // snapshot
935 const BOOL* joyButtonState = [[OOJoystickManager sharedStickHandler] getAllButtonStates];
936
937 if (([self checkKeyPress:n_key_snapshot] || joyButtonState[BUTTON_SNAPSHOT]) && ([gameView allowingStringInput] <= gvStringInputAlpha) && // not while entering text on the keyboard config screens
938 ![[OOOXZManager sharedManager] isAcceptingTextInput]) // '*' key but not while filtering inside OXZ Manager
939 {
940 exceptionContext = @"snapshot";
941 if (!taking_snapshot) {
942 taking_snapshot = YES;
943 [gameView snapShot:nil]; // nil filename so that the program auto-names the snapshot
944 }
945 } else {
946 taking_snapshot = NO;
947 }
948
949 // FPS display
950 if (!onTextEntryScreen && [self checkKeyPress:n_key_show_fps]) // 'F' key
951 {
952 exceptionContext = @"toggle FPS";
953 if (!f_key_pressed)
954 [UNIVERSE setDisplayFPS:![UNIVERSE displayFPS]];
955 f_key_pressed = YES;
956 } else {
957 f_key_pressed = NO;
958 }
959
960 // bloom toggle
961 if ([self checkKeyPress:n_key_bloom_toggle]) {
962 if (!f9_key_pressed) {
963 BOOL oldBloom = [UNIVERSE bloom];
964 [UNIVERSE setBloom:!oldBloom];
965 }
966 f9_key_pressed = YES;
967 } else {
968 f9_key_pressed = NO;
969 }
970
971 // Mouse control
972 BOOL allowMouseControl;
973#if OO_DEBUG
974 allowMouseControl = YES;
975#else
976 allowMouseControl = [gameController inFullScreenMode] ||
977 [[NSUserDefaults standardUserDefaults] boolForKey:@"mouse-control-in-windowed-mode"];
978#endif
979
980 if (allowMouseControl) {
981 exceptionContext = @"mouse control";
982 if (!onTextEntryScreen && ([self checkKeyPress:n_key_mouse_control_roll] || [self checkKeyPress:n_key_mouse_control_yaw])) // 'M' key
983 {
984 if (!m_key_pressed) {
985 mouse_control_on = !mouse_control_on;
986 if (mouse_control_on) {
987 [UNIVERSE addMessage:DESC(@"mouse-on") forCount:3.0];
988 /* Ensure the keyboard pitch override (intended to lock
989 out the joystick if the player runs to the keyboard)
990 is reset */
992 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"grab-mouse-on-mouse-control"]) {
994 }
995 mouse_x_axis_map_to_yaw = [self checkKeyPress:n_key_mouse_control_yaw];
996 keyboardRollOverride = mouse_x_axis_map_to_yaw; // Getafix: set keyboardRollOverride to TRUE only if yaw is mapped to mouse x-axis
997 keyboardPitchOverride = NO;
998 keyboardYawOverride = !keyboardRollOverride;
999 } else {
1000 [UNIVERSE addMessage:DESC(@"mouse-off") forCount:3.0];
1002 }
1003 }
1004 if (OOMouseInteractionModeIsFlightMode([gameController mouseInteractionMode])) {
1006 }
1007 m_key_pressed = YES;
1008 } else {
1009 m_key_pressed = NO;
1010 }
1011 } else {
1012 if (mouse_control_on) {
1013 mouse_control_on = NO;
1014 [UNIVERSE addMessage:DESC(@"mouse-off") forCount:3.0];
1016
1017 if (OOMouseInteractionModeIsFlightMode([gameController mouseInteractionMode])) {
1019 }
1020 }
1021 }
1022
1023 // HUD toggle
1024 if (([self checkKeyPress:n_key_hud_toggle] || joyButtonState[BUTTON_TOGGLEHUD]) && [gameController isGamePaused] && !onTextEntryScreen) // 'o' key while paused
1025 {
1026 exceptionContext = @"toggle HUD";
1027 if (!hide_hud_pressed) {
1028 HeadUpDisplay* theHUD = [self hud];
1030 if (gui_screen == GUI_SCREEN_STATUS) {
1031 // ensure refresh of status page screen if looking at it
1032 [self setGuiToStatusScreen];
1033 }
1034 }
1035 hide_hud_pressed = YES;
1036 } else {
1037 hide_hud_pressed = NO;
1038 }
1039 }
1040 @catch (NSException* exception) {
1041 OOLog(kOOLogException, @"***** Exception in pollApplicationControls [%@]: %@ : %@", exceptionContext, [exception name], [exception reason]);
1042 }
1043}
1044
1045- (void)pollFlightControls:(double)delta_t
1046{
1047 MyOpenGLView* gameView = [UNIVERSE gameView];
1049 NSString* exceptionContext = @"setup";
1050
1051 @try {
1052 exceptionContext = @"joystick handling";
1053 const BOOL* joyButtonState = [[OOJoystickManager sharedStickHandler] getAllButtonStates];
1054
1055 BOOL paused = [[UNIVERSE gameController] isGamePaused];
1056 double speed_delta = SHIP_THRUST_FACTOR * thrust;
1057
1058 if (!paused && gui_screen == GUI_SCREEN_MISSION) {
1059 exceptionContext = @"mission screen";
1060 OOViewID view = VIEW_NONE;
1061
1062 NSPoint virtualView = NSZeroPoint;
1063 double view_threshold = 0.5;
1064
1065 if ([stickHandler joystickCount]) {
1066 virtualView = [stickHandler viewAxis];
1067 if (virtualView.y == STICK_AXISUNASSIGNED)
1068 virtualView.y = 0.0;
1069 if (virtualView.x == STICK_AXISUNASSIGNED)
1070 virtualView.x = 0.0;
1071 if (fabs(virtualView.y) >= fabs(virtualView.x))
1072 virtualView.x = 0.0; // forward/aft takes precedence
1073 else
1074 virtualView.y = 0.0;
1075 }
1076
1077 if ([self checkKeyPress:n_key_view_forward] || (virtualView.y < -view_threshold) || joyButtonState[BUTTON_VIEWFORWARD]) {
1078 view = VIEW_FORWARD;
1079 }
1080 if ([self checkKeyPress:n_key_view_aft] | (virtualView.y > view_threshold) || joyButtonState[BUTTON_VIEWAFT]) {
1081 view = VIEW_AFT;
1082 }
1083 if ([self checkKeyPress:n_key_view_port] || (virtualView.x < -view_threshold) || joyButtonState[BUTTON_VIEWPORT]) {
1084 view = VIEW_PORT;
1085 }
1086 if ([self checkKeyPress:n_key_view_starboard] || (virtualView.x > view_threshold) || joyButtonState[BUTTON_VIEWSTARBOARD]) {
1087 view = VIEW_STARBOARD;
1088 }
1089 if (view == VIEW_NONE) {
1090 // still in mission screen, process the input.
1091 [self pollDemoControls:delta_t];
1092 } else {
1093 [[UNIVERSE gui] clearBackground];
1094 [self switchToThisView:view];
1095 if (_missionWithCallback) {
1096 [self doMissionCallback];
1097 }
1098 // notify older scripts, but do not trigger missionScreenOpportunity.
1099 [self doWorldEventUntilMissionScreen:OOJSID("missionScreenEnded")];
1100 }
1101 } else if (!paused) {
1102 exceptionContext = @"arrow keys";
1103 // arrow keys
1104 if ([UNIVERSE displayGUI])
1105 [self pollGuiArrowKeyControls:delta_t];
1106 else
1107 [self pollFlightArrowKeyControls:delta_t];
1108
1109 // view keys
1110 [self pollViewControls];
1111
1112 if (OOMouseInteractionModeIsFlightMode([[UNIVERSE gameController] mouseInteractionMode])) {
1113 exceptionContext = @"afterburner";
1114 if ((joyButtonState[BUTTON_FUELINJECT] || [self checkKeyPress:n_key_inject_fuel]) &&
1115 [self hasFuelInjection] && !hyperspeed_engaged) {
1116 if (fuel > 0 && !afterburner_engaged) {
1117 [UNIVERSE addMessage:DESC(@"fuel-inject-on") forCount:1.5];
1118 afterburner_engaged = YES;
1119 [self startAfterburnerSound];
1120 } else {
1121 if (fuel <= 0.0)
1122 [UNIVERSE addMessage:DESC(@"fuel-out") forCount:1.5];
1123 }
1124 afterburner_engaged = (fuel > 0);
1125 } else
1126 afterburner_engaged = NO;
1127
1128 if ((!afterburner_engaged) && (afterburnerSoundLooping))
1129 [self stopAfterburnerSound];
1130
1131 exceptionContext = @"thrust";
1132 // DJS: Thrust can be an axis or a button. Axis takes precidence.
1133 double reqSpeed = [stickHandler getAxisState:AXIS_THRUST];
1134 float mouseWheelDeltaFactor = mouse_control_on ? fabs([gameView mouseWheelDelta]) : 1.0f;
1135 if (mouseWheelDeltaFactor == 0.0f)
1136 mouseWheelDeltaFactor = 1.0f;
1137 // Updated DJS original code to fix BUG #17482 - (Getafix 2010/09/13)
1138 if (([self checkKeyPress:n_key_increase_speed] || joyButtonState[BUTTON_INCTHRUST] || ((mouse_control_on) && ([gameView mouseWheelState] == gvMouseWheelUp) && ([UNIVERSE viewDirection] <= VIEW_STARBOARD || ![gameView isCapsLockOn])))
1139 && (flightSpeed < maxFlightSpeed) && (!afterburner_engaged)) {
1140 flightSpeed += speed_delta * delta_t * mouseWheelDeltaFactor;
1141 }
1142
1143 if (([self checkKeyPress:n_key_decrease_speed] || joyButtonState[BUTTON_DECTHRUST] || ((mouse_control_on) && ([gameView mouseWheelState] == gvMouseWheelDown) && ([UNIVERSE viewDirection] <= VIEW_STARBOARD || ![gameView isCapsLockOn])))
1144 && (!afterburner_engaged)) {
1145 flightSpeed -= speed_delta * delta_t * mouseWheelDeltaFactor;
1146 // ** tgape ** - decrease obviously means no hyperspeed
1147 hyperspeed_engaged = NO;
1148 }
1149
1150 NSDictionary* functionForThrustAxis = [[stickHandler axisFunctions] oo_dictionaryForKey:[[NSNumber numberWithInt:AXIS_THRUST] stringValue]];
1151 if ([stickHandler joystickCount] != 0 && functionForThrustAxis != nil) {
1152 if (flightSpeed < maxFlightSpeed * reqSpeed) {
1153 flightSpeed += speed_delta * delta_t;
1154 }
1155 if (flightSpeed > maxFlightSpeed * reqSpeed) {
1156 flightSpeed -= speed_delta * delta_t;
1157 }
1158 } // DJS: end joystick thrust axis (Getafix - End code update for fixing BUG #17482)
1159
1160 if (!afterburner_engaged && ![self atHyperspeed] && !hyperspeed_engaged) {
1161 flightSpeed = OOClamp_0_max_f(flightSpeed, maxFlightSpeed);
1162 }
1163
1164 exceptionContext = @"hyperspeed";
1165 // hyperspeed controls
1166 if ([self checkKeyPress:n_key_jumpdrive] || joyButtonState[BUTTON_HYPERSPEED]) // 'j'
1167 {
1168 if (!jump_pressed) {
1169 if (!hyperspeed_engaged) {
1170 hyperspeed_locked = [self massLocked];
1171 hyperspeed_engaged = !hyperspeed_locked;
1172 if (hyperspeed_locked) {
1173 [self playJumpMassLocked];
1174 [UNIVERSE addMessage:DESC(@"jump-mass-locked") forCount:1.5];
1175 }
1176 } else {
1177 hyperspeed_engaged = NO;
1178 }
1179 }
1180 jump_pressed = YES;
1181 } else {
1182 jump_pressed = NO;
1183 }
1184
1185 exceptionContext = @"shoot";
1186 // shoot 'a'
1187 if ((([self checkNavKeyPress:n_key_fire_lasers]) || ((mouse_control_on) && ([gameView isDown:gvMouseLeftButton]) && ([UNIVERSE viewDirection] <= VIEW_STARBOARD || ![gameView isCapsLockOn])) || joyButtonState[BUTTON_FIRE]) && (shot_time > weapon_recharge_rate)) {
1188 if ([self fireMainWeapon]) {
1189 [self playLaserHit:([self shipHitByLaser] != nil) offset:[[self currentLaserOffset] oo_vectorAtIndex:0] weaponIdentifier:[[self currentWeapon] identifier]];
1190 }
1191 }
1192
1193 exceptionContext = @"weapons online toggle";
1194 // weapons online / offline toggle '_'
1195 if (([self checkKeyPress:n_key_weapons_online_toggle] || joyButtonState[BUTTON_WEAPONSONLINETOGGLE])) {
1197 NSString* weaponsOnlineToggleMsg;
1198
1199 [self setWeaponsOnline:![self weaponsOnline]];
1200 weaponsOnlineToggleMsg = [self weaponsOnline] ? DESC(@"weapons-systems-online") : DESC(@"weapons-systems-offline");
1201 if ([self weaponsOnline]) {
1202 [self playWeaponsOnline];
1203 } else {
1204 [self playWeaponsOffline];
1205 }
1206 [UNIVERSE addMessage:weaponsOnlineToggleMsg forCount:2.0];
1207 [self doScriptEvent:OOJSID("weaponsSystemsToggled") withArgument:[NSNumber numberWithBool:[self weaponsOnline]]];
1209 }
1210 } else
1212
1213 exceptionContext = @"missile fire";
1214 // shoot 'm' // launch missile
1215 if ([self checkKeyPress:n_key_launch_missile] || joyButtonState[BUTTON_LAUNCHMISSILE]) {
1216 // launch here
1217 if (!fire_missile_pressed) {
1218 [self fireMissile];
1220 }
1221 } else
1223
1224 exceptionContext = @"next missile";
1225 // shoot 'y' // next missile
1226 if ([self checkKeyPress:n_key_next_missile] || joyButtonState[BUTTON_CYCLEMISSILE]) {
1227 if (!ident_engaged && !next_missile_pressed && [self weaponsOnline]) {
1229 [self selectNextMissile];
1230 }
1232 } else
1234
1235 exceptionContext = @"next target";
1236 // '+' // next target
1237 if ([self checkKeyPress:n_key_next_target] || joyButtonState[BUTTON_NEXTTARGET]) {
1238 if ((!next_target_pressed) && ([self hasEquipmentItemProviding:@"EQ_TARGET_MEMORY"])) {
1239 [self moveTargetMemoryBy:+1];
1240 }
1241 next_target_pressed = YES;
1242 } else
1244
1245 exceptionContext = @"previous target";
1246 // '-' // previous target
1247 if ([self checkKeyPress:n_key_previous_target] || joyButtonState[BUTTON_PREVTARGET]) {
1248 if ((!previous_target_pressed) && ([self hasEquipmentItemProviding:@"EQ_TARGET_MEMORY"])) {
1249 [self moveTargetMemoryBy:-1];
1250 }
1252 } else
1254
1255 exceptionContext = @"ident R";
1256 // shoot 'r' // switch on ident system
1257 if ([self checkKeyPress:n_key_ident_system] || joyButtonState[BUTTON_ID]) {
1258 // ident 'on' here
1259 if (!ident_pressed) {
1260 [self handleButtonIdent];
1261 }
1262 ident_pressed = YES;
1263 } else
1264 ident_pressed = NO;
1265
1266 exceptionContext = @"prime equipment";
1267 // prime equipment 'N' - selects equipment to use with keypress
1268 if ([self checkKeyPress:n_key_prime_next_equipment] || [self checkKeyPress:n_key_prime_previous_equipment] || joyButtonState[BUTTON_PRIMEEQUIPMENT] || joyButtonState[BUTTON_PRIMEEQUIPMENT_PREV]) {
1269
1271
1272 // cycle through all the relevant equipment.
1273 NSUInteger c = [eqScripts count];
1274
1275 // if Ctrl is held down at the same time as the prime equipment key,
1276 // cycle relevant equipment in reverse
1277 // if (![gameView isCtrlDown])
1278 if (![self checkKeyPress:n_key_prime_previous_equipment] || joyButtonState[BUTTON_PRIMEEQUIPMENT_PREV]) {
1279 primedEquipment++;
1280 if (primedEquipment > c)
1281 primedEquipment = 0;
1282 } else {
1283 if (primedEquipment > 0)
1284 primedEquipment--;
1285 else
1286 primedEquipment = c;
1287 }
1288
1289 NSString* eqKey = @"";
1290
1291 if (primedEquipment == c) {
1292 if (c > 0) {
1294 [UNIVERSE addMessage:DESC(@"equipment-primed-none") forCount:2.0];
1295 } else
1296 [UNIVERSE addMessage:DESC(@"equipment-primed-none-available") forCount:2.0];
1297 } else {
1299 NSString* equipmentName = [[OOEquipmentType equipmentTypeWithIdentifier:[[eqScripts oo_arrayAtIndex:primedEquipment] oo_stringAtIndex:0]] name];
1300 eqKey = [[eqScripts oo_arrayAtIndex:primedEquipment] oo_stringAtIndex:0];
1301 [UNIVERSE addMessage:OOExpandKey(@"equipment-primed", equipmentName) forCount:2.0];
1302 }
1303 [self doScriptEvent:OOJSID("playerChangedPrimedEquipment") withArgument:eqKey];
1304 }
1306
1307 } else
1309
1310 exceptionContext = @"activate equipment";
1311 // activate equipment 'n' - runs the activated() function inside the equipment's script.
1312 if ([self checkKeyPress:n_key_activate_equipment] || joyButtonState[BUTTON_ACTIVATEEQUIPMENT]) {
1314 [self activatePrimableEquipment:primedEquipment withMode:OOPRIMEDEQUIP_ACTIVATED];
1315 }
1317 } else
1319
1320 exceptionContext = @"mode equipment";
1321 // mode equipment 'b' - runs the mode() function inside the equipment's script.
1322 if ([self checkKeyPress:n_key_mode_equipment] || joyButtonState[BUTTON_MODEEQUIPMENT]) {
1324 [self activatePrimableEquipment:primedEquipment withMode:OOPRIMEDEQUIP_MODE];
1325 }
1327 } else
1329
1330 exceptionContext = @"fast equipment A";
1331 if ([self checkKeyPress:n_key_fastactivate_equipment_a] || joyButtonState[BUTTON_CLOAK]) {
1333 [self activatePrimableEquipment:[self eqScriptIndexForKey:[self fastEquipmentA]] withMode:OOPRIMEDEQUIP_ACTIVATED];
1334 }
1336 } else
1338
1339 exceptionContext = @"fast equipment B";
1340 if ([self checkKeyPress:n_key_fastactivate_equipment_b] || joyButtonState[BUTTON_ENERGYBOMB]) {
1342 [self activatePrimableEquipment:[self eqScriptIndexForKey:[self fastEquipmentB]] withMode:OOPRIMEDEQUIP_ACTIVATED];
1343 }
1345 } else
1347
1348 exceptionContext = @"custom equipment";
1349 // loop through all the objects in the customEquipActivation array
1350 NSDictionary* item;
1351 NSUInteger i;
1352 for (i = 0; i < [customEquipActivation count]; i++) {
1353 item = [customEquipActivation objectAtIndex:i];
1354 // check if the player has the equip item installed
1355 if ([self hasOneEquipmentItem:[item oo_stringForKey:CUSTOMEQUIP_EQUIPKEY] includeWeapons:NO whileLoading:NO]) {
1356 NSArray* key_act = [item oo_arrayForKey:CUSTOMEQUIP_KEYACTIVATE];
1357 NSArray* key_mod = [item oo_arrayForKey:CUSTOMEQUIP_KEYMODE];
1358 NSDictionary* but_act = [item oo_dictionaryForKey:CUSTOMEQUIP_BUTTONACTIVATE];
1359 NSDictionary* but_mod = [item oo_dictionaryForKey:CUSTOMEQUIP_BUTTONMODE];
1360 // if so,
1361 // check to see if the key or button was pressed for activate
1362 if ((key_act && [self checkKeyPress:key_act]) || (but_act && [[OOJoystickManager sharedStickHandler] isButtonDown:[but_act oo_intForKey:STICK_AXBUT] stick:[but_act oo_intForKey:STICK_NUMBER]])) {
1363 if (![[customActivatePressed objectAtIndex:i] boolValue]) {
1364 // initate the activate JS code
1365 [self activatePrimableEquipment:[self eqScriptIndexForKey:[item oo_stringForKey:CUSTOMEQUIP_EQUIPKEY]] withMode:OOPRIMEDEQUIP_ACTIVATED];
1366 }
1367 [customActivatePressed replaceObjectAtIndex:i withObject:[NSNumber numberWithBool:YES]];
1368 } else
1369 [customActivatePressed replaceObjectAtIndex:i withObject:[NSNumber numberWithBool:NO]];
1370
1371 // check to see if the key or button was pressed for mode
1372 if ((key_mod && [self checkKeyPress:key_mod]) || (but_mod && [[OOJoystickManager sharedStickHandler] isButtonDown:[but_mod oo_intForKey:STICK_AXBUT] stick:[but_mod oo_intForKey:STICK_NUMBER]])) {
1373 if (![[customModePressed objectAtIndex:i] boolValue]) {
1374 // initiate the activate JS code
1375 [self activatePrimableEquipment:[self eqScriptIndexForKey:[item oo_stringForKey:CUSTOMEQUIP_EQUIPKEY]] withMode:OOPRIMEDEQUIP_MODE];
1376 }
1377 [customModePressed replaceObjectAtIndex:i withObject:[NSNumber numberWithBool:YES]];
1378 } else
1379 [customModePressed replaceObjectAtIndex:i withObject:[NSNumber numberWithBool:NO]];
1380 }
1381 }
1382
1383 exceptionContext = @"incoming missile T";
1384 // target nearest incoming missile 'T' - useful for quickly giving a missile target to turrets
1385 if ([self checkKeyPress:n_key_target_incoming_missile] || joyButtonState[BUTTON_TARGETINCOMINGMISSILE]) {
1388 }
1390 } else
1392
1393 exceptionContext = @"missile T";
1394 // shoot 't' // switch on missile targeting
1395 if (([self checkKeyPress:n_key_target_missile] || joyButtonState[BUTTON_ARMMISSILE]) && (missile_entity[activeMissile])) {
1396 // targeting 'on' here
1399 }
1401 } else
1403
1404 exceptionContext = @"missile U";
1405 // shoot 'u' // disarm missile targeting
1406 if ([self checkKeyPress:n_key_untarget_missile] || joyButtonState[BUTTON_UNARM]) {
1407 if (!safety_pressed) {
1408 // targeting off in both cases!
1409 if ([self primaryTarget] != nil)
1410 [self noteLostTarget];
1411 DESTROY(_primaryTarget);
1412 [self safeAllMissiles];
1413 if (!ident_engaged && [self weaponsOnline]) {
1414 [UNIVERSE addMessage:DESC(@"missile-safe") forCount:2.0];
1415 [self playMissileSafe];
1416 } else {
1417 [UNIVERSE addMessage:DESC(@"ident-off") forCount:2.0];
1418 [self playIdentOff];
1419 }
1420 ident_engaged = NO;
1421 }
1422 safety_pressed = YES;
1423 } else
1424 safety_pressed = NO;
1425
1426 exceptionContext = @"ECM";
1427 // shoot 'e' // ECM
1428 if (([self checkKeyPress:n_key_ecm] || joyButtonState[BUTTON_ECM]) && [self hasECM]) {
1429 if (!ecm_in_operation) {
1430 if ([self weaponsOnline] && [self fireECM]) {
1431 [self playFiredECMSound];
1432 [UNIVERSE addMessage:DESC(@"ecm-on") forCount:3.0];
1433 }
1434 }
1435 }
1436
1437 exceptionContext = @"escape pod";
1438 // shoot 'escape' // Escape pod launch - NOTE: Allowed at all times, but requires double press within a specific time interval.
1439 // Double press not available in strict mode or when the "escape-pod-activation-immediate" override is in the
1440 // user defaults file.
1441 if (([self checkKeyPress:n_key_launch_escapepod] || joyButtonState[BUTTON_ESCAPE]) && [self hasEscapePod]) {
1442 BOOL goodToLaunch = [[NSUserDefaults standardUserDefaults] boolForKey:@"escape-pod-activation-immediate"];
1443 static OOTimeDelta escapePodKeyResetTime;
1444
1445 if (!goodToLaunch) {
1446 if (!escapePodKey_pressed) {
1448 // first keypress will unregister in KEY_REPEAT_INTERVAL seconds
1449 escapePodKeyResetTime = [NSDate timeIntervalSinceReferenceDate] + KEY_REPEAT_INTERVAL;
1450 //[gameView clearKey:key_launch_escapepod];
1451 [gameView clearKey:[self getFirstKeyCode:n_key_launch_escapepod]];
1452 if ([stickHandler joystickCount]) {
1453 [stickHandler clearStickButtonState:BUTTON_ESCAPE];
1454 }
1455 } else {
1456 OOTimeDelta timeNow = [NSDate timeIntervalSinceReferenceDate];
1458 if (timeNow < escapePodKeyResetTime)
1459 goodToLaunch = YES;
1460 }
1461 }
1462 if (goodToLaunch) {
1463 [self launchEscapeCapsule];
1464 }
1465 }
1466
1467 exceptionContext = @"dump cargo";
1468 // shoot 'd' // Dump Cargo
1469 if (([self checkKeyPress:n_key_dump_cargo] || joyButtonState[BUTTON_JETTISON]) && [cargo count] > 0) {
1470 [self dumpCargo];
1471 }
1472
1473 exceptionContext = @"rotate cargo";
1474 // shoot 'R' // Rotate Cargo
1475 if ([self checkKeyPress:n_key_rotate_cargo] || joyButtonState[BUTTON_ROTATECARGO]) {
1476 if ((!rotateCargo_pressed) && ([cargo count] > 0))
1477 [self rotateCargo];
1478 rotateCargo_pressed = YES;
1479 } else
1481
1482 exceptionContext = @"autopilot C";
1483 // autopilot 'c'
1484 if ([self checkKeyPress:n_key_autopilot] || joyButtonState[BUTTON_DOCKCPU]) // look for the 'c' key
1485 {
1486 if ([self hasDockingComputer] && (!autopilot_key_pressed)) {
1487 [self handleAutopilotOn:false];
1488 }
1490 } else
1492
1493 exceptionContext = @"autopilot shift-C";
1494 // autopilot 'C' - fast-autopilot
1495 if ([self checkKeyPress:n_key_autodock] || joyButtonState[BUTTON_DOCKCPUFAST]) // look for the 'C' key
1496 {
1497 if ([self hasDockingComputer] && (!fast_autopilot_key_pressed)) {
1498 [self handleAutopilotOn:true];
1499 }
1501 } else {
1503 }
1504
1505 exceptionContext = @"docking clearance request";
1506
1507 if ([self checkKeyPress:n_key_docking_clearance_request] || joyButtonState[BUTTON_DOCKINGCLEARANCE]) {
1509 Entity* primeTarget = [self primaryTarget];
1510 [self performDockingRequest:(StationEntity*)primeTarget];
1511 }
1513 } else {
1515 }
1516
1517 exceptionContext = @"hyperspace";
1518 // hyperspace 'h'
1519 if (([self checkKeyPress:n_key_hyperspace] || joyButtonState[BUTTON_HYPERDRIVE]) &&
1520 [self hasHyperspaceMotor]) // look for the 'h' key
1521 {
1522 if (!hyperspace_pressed) {
1523 if ([self status] == STATUS_WITCHSPACE_COUNTDOWN) {
1525 if (galactic_witchjump) {
1526 galactic_witchjump = NO;
1527 [UNIVERSE addMessage:DESC(@"witch-user-galactic-abort") forCount:3.0];
1528 } else {
1529 [UNIVERSE addMessage:DESC(@"witch-user-abort") forCount:3.0];
1530 }
1531 } else if ([self witchJumpChecklist:false]) {
1532 [self beginWitchspaceCountdown:hyperspaceMotorSpinTime];
1533 }
1534 }
1535 hyperspace_pressed = YES;
1536 } else
1537 hyperspace_pressed = NO;
1538
1539 exceptionContext = @"galactic hyperspace";
1540 // Galactic hyperspace 'g'
1541 if (([self checkKeyPress:n_key_galactic_hyperspace] || joyButtonState[BUTTON_GALACTICDRIVE]) && ([self hasEquipmentItemProviding:@"EQ_GAL_DRIVE"])) // look for the 'g' key
1542 {
1543 if (!galhyperspace_pressed) {
1544 if ([self status] == STATUS_WITCHSPACE_COUNTDOWN) {
1546 if (galactic_witchjump) {
1547 galactic_witchjump = NO;
1548 [UNIVERSE addMessage:DESC(@"witch-user-galactic-abort") forCount:3.0];
1549 } else {
1550 [UNIVERSE addMessage:DESC(@"witch-user-abort") forCount:3.0];
1551 }
1552 } else {
1553 galactic_witchjump = YES;
1554
1555 // even if we don't have a witchspace motor, we can still do a default galactic jump (!)
1556 if (EXPECT([self hasHyperspaceMotor]))
1557 witchspaceCountdown = hyperspaceMotorSpinTime;
1558 else
1559 witchspaceCountdown = DEFAULT_HYPERSPACE_SPIN_TIME;
1560
1561 [self setStatus:STATUS_WITCHSPACE_COUNTDOWN];
1563 // say it!
1564 [UNIVERSE addMessage:[NSString stringWithFormat:DESC(@"witch-galactic-in-f-seconds"), witchspaceCountdown] forCount:1.0];
1565 // FIXME: how to preload target system for hyperspace jump?
1566
1567 [self doScriptEvent:OOJSID("playerStartedJumpCountdown")
1568 withArguments:[NSArray arrayWithObjects:@"galactic", [NSNumber numberWithFloat:witchspaceCountdown], nil]];
1569 }
1570 }
1572 } else
1574 }
1575
1576#if OO_FOV_INFLIGHT_CONTROL_ENABLED
1577 // Field of view controls
1578 if (![UNIVERSE displayGUI]) {
1579 if (([self checkKeyPress:n_key_inc_field_of_view] || joyButtonState[BUTTON_INC_FIELD_OF_VIEW]) && (fieldOfView < MAX_FOV)) {
1580 fieldOfView *= pow(fov_delta, delta_t);
1581 if (fieldOfView > MAX_FOV)
1582 fieldOfView = MAX_FOV;
1583 }
1584
1585 if (([self checkKeyPress:n_key_dec_field_of_view] || joyButtonState[BUTTON_DEC_FIELD_OF_VIEW]) && (fieldOfView > MIN_FOV)) {
1586 fieldOfView /= pow(fov_delta, delta_t);
1587 if (fieldOfView < MIN_FOV)
1588 fieldOfView = MIN_FOV;
1589 }
1590
1591 NSDictionary* functionForFovAxis = [[stickHandler axisFunctions] oo_dictionaryForKey:[[NSNumber numberWithInt:AXIS_FIELD_OF_VIEW] stringValue]];
1592 if ([stickHandler joystickCount] != 0 && functionForFovAxis != nil) {
1593 // TODO think reqFov through
1594 double reqFov = [stickHandler getAxisState:AXIS_FIELD_OF_VIEW];
1595 if (fieldOfView < maxFieldOfView * reqFov) {
1596 fieldOfView *= pow(fov_delta, delta_t);
1597 if (fieldOfView > MAX_FOV)
1598 fieldOfView = MAX_FOV;
1599 }
1600 if (fieldOfView > maxFieldOfView * reqFov) {
1601 fieldOfView /= pow(fov_delta, delta_t);
1602 if (fieldOfView < MIN_FOV)
1603 fieldOfView = MIN_FOV;
1604 }
1605 }
1606 }
1607#endif
1608
1609#ifdef OO_DEBUG_MONITOR_ENABLED
1610 exceptionContext = @"dump target state";
1611 if ([self checkKeyPress:n_key_dump_target_state]) {
1612 if (!dump_target_state_pressed) {
1613 dump_target_state_pressed = YES;
1614 id target = [self primaryTarget];
1615 if (target == nil)
1616 target = self;
1617 [target dumpState];
1618 }
1619 } else
1620 dump_target_state_pressed = NO;
1621#endif
1622
1623 // text displays
1624 exceptionContext = @"pollGuiScreenControls";
1625 [self pollGuiScreenControls];
1626 } else {
1627 // game is paused
1628 // check options menu request
1629 exceptionContext = @"options menu";
1630 if (([self checkKeyPress:n_key_gui_screen_options]) && (gui_screen != GUI_SCREEN_OPTIONS) && ![gameView allowingStringInput]) {
1633 }
1634
1635#if (ALLOW_CUSTOM_VIEWS_WHILE_PAUSED)
1636 [self pollCustomViewControls]; // allow custom views during pause
1637#endif
1638
1639 if (gui_screen == GUI_SCREEN_OPTIONS || gui_screen == GUI_SCREEN_GAMEOPTIONS || gui_screen == GUI_SCREEN_STICKMAPPER || gui_screen == GUI_SCREEN_STICKPROFILE || gui_screen == GUI_SCREEN_KEYBOARD || gui_screen == GUI_SCREEN_KEYBOARD_CONFIRMCLEAR || gui_screen == GUI_SCREEN_KEYBOARD_CONFIG || gui_screen == GUI_SCREEN_KEYBOARD_ENTRY || gui_screen == GUI_SCREEN_KEYBOARD_LAYOUT) {
1640 if ([UNIVERSE pauseMessageVisible])
1641 [[UNIVERSE messageGUI] leaveLastLine];
1642 else
1643 [[UNIVERSE messageGUI] clear];
1644 NSTimeInterval time_this_frame = [NSDate timeIntervalSinceReferenceDate];
1645 OOTimeDelta time_delta;
1646 if (![[GameController sharedController] isGamePaused]) {
1647 time_delta = time_this_frame - time_last_frame;
1648 time_last_frame = time_this_frame;
1649 time_delta = OOClamp_0_max_d(time_delta, MINIMUM_GAME_TICK);
1650 } else {
1651 time_delta = 0.0;
1652 }
1653
1654 script_time += time_delta;
1655 [self pollGuiArrowKeyControls:time_delta];
1656 }
1657
1658 exceptionContext = @"debug keys";
1659#ifdef OO_DEBUG_MONITOR_ENABLED
1660 // look for debugging keys
1661 if ([self checkKeyPress:n_key_dump_entity_list] && ![gameView allowingStringInput]) // look for the '0' key
1662 {
1663 if (!dump_entity_list_pressed) {
1664 [UNIVERSE debugDumpEntities];
1665 gDebugFlags = 0;
1666 [UNIVERSE addMessage:@"Entity List dumped. Debugging OFF" forCount:3];
1667 }
1668 dump_entity_list_pressed = YES;
1669 } else
1670 dump_entity_list_pressed = NO;
1671
1672 // look for debugging keys
1673 if ([self checkKeyPress:n_key_debug_full] && ![gameView allowingStringInput]) // look for the 'd' key
1674 {
1676 [UNIVERSE addMessage:@"Full debug ON" forCount:3];
1677 }
1678
1679 if ([self checkKeyPress:n_key_debug_collision] && ![gameView allowingStringInput]) // look for the 'b' key
1680 {
1682 [UNIVERSE addMessage:@"Collision debug ON" forCount:3];
1683 }
1684
1685 if ([self checkKeyPress:n_key_debug_console_connect] && ![[OODebugMonitor sharedDebugMonitor] usingPlugInController] && ![gameView allowingStringInput]) // look for the 'c' key
1686 {
1687 // This code is executed only if we're not using the integrated plugin controller
1688 if (!autopilot_key_pressed) {
1689 if (![[OODebugMonitor sharedDebugMonitor] debuggerConnected]) {
1691 if ([[OODebugMonitor sharedDebugMonitor] debuggerConnected])
1692 [UNIVERSE addMessage:@"Connected to debug console." forCount:3];
1693 } else {
1695 [UNIVERSE addMessage:@"Disconnected from debug console." forCount:3];
1696 }
1697 }
1699 } else
1701
1702 if ([self checkKeyPress:n_key_debug_bounding_boxes] && ![gameView allowingStringInput]) // look for the 'x' key
1703 {
1705 [UNIVERSE addMessage:@"Bounding box debug ON" forCount:3];
1706 }
1707
1708 if ([self checkKeyPress:n_key_debug_shaders] && ![gameView allowingStringInput]) // look for the 's' key
1709 {
1710 OOLogSetDisplayMessagesInClass(@"$shaderDebugOn", YES);
1711 [UNIVERSE addMessage:@"Shader debug ON" forCount:3];
1712 }
1713
1714 if (([self checkKeyPress:n_key_gui_arrow_left] || [self checkKeyPress:n_key_gui_arrow_right]) && gui_screen != GUI_SCREEN_GAMEOPTIONS && [UNIVERSE displayFPS] && ![gameView allowingStringInput]) {
1715 if (!leftRightKeyPressed) {
1716 float newTimeAccelerationFactor = [self checkKeyPress:n_key_gui_arrow_left] ? fmax([UNIVERSE timeAccelerationFactor] / 2.0f, TIME_ACCELERATION_FACTOR_MIN) : fmin([UNIVERSE timeAccelerationFactor] * 2.0f, TIME_ACCELERATION_FACTOR_MAX);
1717 [UNIVERSE setTimeAccelerationFactor:newTimeAccelerationFactor];
1718 }
1719 leftRightKeyPressed = YES;
1720 } else
1722
1723 if ([self checkKeyPress:n_key_debug_off] && ![gameView allowingStringInput]) // look for the 'n' key
1724 {
1725 gDebugFlags = 0;
1726 [UNIVERSE addMessage:@"All debug flags OFF" forCount:3];
1727 OOLogSetDisplayMessagesInClass(@"$shaderDebugOn", NO);
1728 }
1729#endif
1730 }
1731
1732 exceptionContext = @"pause";
1733 // Pause game 'p'
1734 if (([self checkKeyPress:n_key_pausebutton] || joyButtonState[BUTTON_PAUSE]) && gui_screen != GUI_SCREEN_LONG_RANGE_CHART && gui_screen != GUI_SCREEN_MISSION && ![gameView allowingStringInput]) // look for the 'p' key
1735 {
1736 if (!pause_pressed) {
1737 if (paused) {
1738 script_time = saved_script_time;
1739 // Reset to correct GUI screen, if we are unpausing from one.
1740 // Don't set gui_screen here, use setGuis - they also switch backgrounds.
1741 // No gui switching events will be triggered while still paused.
1742 switch (saved_gui_screen) {
1743 case GUI_SCREEN_STATUS:
1744 [self setGuiToStatusScreen];
1745 break;
1746 case GUI_SCREEN_LONG_RANGE_CHART:
1748 break;
1749 case GUI_SCREEN_SHORT_RANGE_CHART:
1751 break;
1752 case GUI_SCREEN_MANIFEST:
1754 break;
1755 case GUI_SCREEN_MARKET:
1756 [self setGuiToMarketScreen];
1757 break;
1758 case GUI_SCREEN_MARKETINFO:
1760 break;
1761 case GUI_SCREEN_SYSTEM_DATA:
1762 // Do not reset planet rotation if we are already in the system info screen!
1763 if (gui_screen != GUI_SCREEN_SYSTEM_DATA)
1765 break;
1766 default:
1767 gui_screen = saved_gui_screen; // make sure we're back to the right screen
1768 break;
1769 }
1771 [UNIVERSE clearPreviousMessage];
1772 [UNIVERSE setViewDirection:saved_view_direction];
1773 currentWeaponFacing = saved_weapon_facing;
1774 // make sure the light comes from the right direction after resuming from pause!
1775 if (saved_gui_screen == GUI_SCREEN_SYSTEM_DATA)
1776 [UNIVERSE setMainLightPosition:_sysInfoLight];
1777 [[UNIVERSE gui] setForegroundTextureKey:@"overlay"];
1778 [[UNIVERSE gameController] setGamePaused:NO];
1779 } else {
1780 saved_view_direction = [UNIVERSE viewDirection];
1781 saved_script_time = script_time;
1782 saved_gui_screen = gui_screen;
1783 saved_weapon_facing = currentWeaponFacing;
1784 [UNIVERSE pauseGame]; // pause handler
1785 }
1786 }
1787 pause_pressed = YES;
1788 } else {
1789 pause_pressed = NO;
1790 }
1791 }
1792 @catch (NSException* exception) {
1793 OOLog(kOOLogException, @"***** Exception in pollFlightControls [%@]: %@ : %@", exceptionContext, [exception name], [exception reason]);
1794 }
1795}
1796
1797- (void)pollGuiArrowKeyControls:(double)delta_t
1798{
1799 MyOpenGLView* gameView = [UNIVERSE gameView];
1800 const BOOL* joyButtonState = [[OOJoystickManager sharedStickHandler] getAllButtonStates];
1801 BOOL moving = NO;
1802 BOOL dragging = NO;
1803 double cursor_speed = ([gameView isCtrlDown] ? 20.0 : 10.0) * chart_zoom;
1804 GameController* controller = [UNIVERSE gameController];
1805 GuiDisplayGen* gui = [UNIVERSE gui];
1806 GUI_ROW_INIT(gui);
1807
1808 // deal with string inputs as necessary
1809 if (gui_screen == GUI_SCREEN_LONG_RANGE_CHART) {
1810 [gameView setStringInput:gvStringInputAlpha];
1811 } else if (gui_screen == GUI_SCREEN_SAVE) {
1812 [gameView setStringInput:gvStringInputLoadSave];
1813 } else if (gui_screen == GUI_SCREEN_MISSION && _missionTextEntry) {
1814 [gameView setStringInput:gvStringInputAll];
1815 } else if (gui_screen == GUI_SCREEN_KEYBOARD_ENTRY) {
1816 [gameView setStringInput:gvStringInputAll];
1817 }
1818#if 0
1819 // at the moment this function is never called for GUI_SCREEN_OXZMANAGER
1820 // but putting this here in case we do later
1821 else if (gui_screen == GUI_SCREEN_OXZMANAGER && [[OOOXZManager sharedManager] isAcceptingTextInput])
1822 {
1823 [gameView setStringInput: gvStringInputAll];
1824 }
1825#endif
1826 else {
1828 // If we have entered this screen with the injectors key pressed, make sure
1829 // that injectors switch off when we release it - Nikos.
1830 if (afterburner_engaged && ![self checkKeyPress:n_key_inject_fuel]) {
1831 afterburner_engaged = NO;
1832 }
1833 }
1834
1835 switch (gui_screen) {
1836 case GUI_SCREEN_LONG_RANGE_CHART:
1837
1838 if ([self status] != STATUS_WITCHSPACE_COUNTDOWN) {
1839 if ([[gameView typedString] length] > 0) {
1840 planetSearchString = [[[gameView typedString] lowercaseString] retain];
1841 NSPoint search_coords = [UNIVERSE findSystemCoordinatesWithPrefix:planetSearchString];
1842 if ((search_coords.x >= 0.0) && (search_coords.y >= 0.0)) {
1843 // always reset the found system index at the beginning of a new search
1844 if ([planetSearchString length] == 1)
1845 [[UNIVERSE gui] targetNextFoundSystem:0];
1846
1847 // Always select the right one out of 2 overlapping systems.
1848 [self targetNewSystem:0 whileTyping:YES];
1849 } else {
1850 found_system_id = -1;
1852 }
1853 } else {
1854 if ([gameView isDown:gvDeleteKey]) // did we just delete the string ?
1855 {
1856 found_system_id = -1;
1857 [UNIVERSE findSystemCoordinatesWithPrefix:@""];
1858 }
1859 if (planetSearchString)
1860 [planetSearchString release];
1861 planetSearchString = nil;
1862 }
1863
1864 moving |= (searchStringLength != [[gameView typedString] length]);
1866 }
1867
1868 case GUI_SCREEN_SHORT_RANGE_CHART:
1869
1870 if ([self checkKeyPress:n_key_chart_highlight]) {
1871 if (!queryPressed) {
1873 if (mode != OOLRC_MODE_TECHLEVEL) {
1874 [self setLongRangeChartMode:mode + 1];
1875 } else {
1876 [self setLongRangeChartMode:OOLRC_MODE_SUNCOLOR];
1877 }
1878 [self doScriptEvent:OOJSID("chartHighlightModeChanged") withArgument:OOStringFromLongRangeChartMode([self longRangeChartMode])];
1879 }
1880 queryPressed = YES;
1881 } else {
1882 queryPressed = NO;
1883 }
1884
1885 if ([self checkKeyPress:n_key_map_info] && chart_zoom <= CHART_ZOOM_SHOW_LABELS) {
1886 if (!chartInfoPressed) {
1887 show_info_flag = !show_info_flag;
1888 chartInfoPressed = YES;
1889 }
1890 } else {
1891 chartInfoPressed = NO;
1892 }
1893
1894 if ([self status] != STATUS_WITCHSPACE_COUNTDOWN) {
1895 if ([self hasEquipmentItemProviding:@"EQ_ADVANCED_NAVIGATIONAL_ARRAY"]) {
1896 if ([self checkKeyPress:n_key_advanced_nav_array_next] || [self checkKeyPress:n_key_advanced_nav_array_previous]) {
1897 if (!pling_pressed) {
1898 if ([self checkKeyPress:n_key_advanced_nav_array_previous]) {
1899 switch (ANA_mode) {
1900 case OPTIMIZED_BY_NONE:
1901 ANA_mode = OPTIMIZED_BY_TIME;
1902 break;
1903 case OPTIMIZED_BY_TIME:
1904 ANA_mode = OPTIMIZED_BY_JUMPS;
1905 break;
1906 default:
1907 ANA_mode = OPTIMIZED_BY_NONE;
1908 break;
1909 }
1910 } else {
1911 switch (ANA_mode) {
1912 case OPTIMIZED_BY_NONE:
1913 ANA_mode = OPTIMIZED_BY_JUMPS;
1914 break;
1915 case OPTIMIZED_BY_JUMPS:
1916 ANA_mode = OPTIMIZED_BY_TIME;
1917 break;
1918 default:
1919 ANA_mode = OPTIMIZED_BY_NONE;
1920 break;
1921 }
1922 }
1923 if (ANA_mode == OPTIMIZED_BY_NONE || ![self infoSystemOnRoute]) {
1924 [self setInfoSystemID:target_system_id moveChart:NO];
1925 }
1926 }
1927 pling_pressed = YES;
1928 } else {
1929 pling_pressed = NO;
1930 }
1931 } else {
1932 ANA_mode = OPTIMIZED_BY_NONE;
1933 }
1934
1935 if ([gameView isDown:gvMouseDoubleClick]) {
1937 mouse_left_down = NO;
1938 [self noteGUIWillChangeTo:GUI_SCREEN_SYSTEM_DATA];
1939 showingLongRangeChart = (gui_screen == GUI_SCREEN_LONG_RANGE_CHART);
1941 break;
1942 }
1943 if ([gameView isDown:gvMouseLeftButton]) {
1944 NSPoint maus = [gameView virtualJoystickPosition];
1945 double vadjust = MAIN_GUI_PIXEL_HEIGHT / 2.0 - CHART_SCREEN_VERTICAL_CENTRE;
1946 double hscale = MAIN_GUI_PIXEL_WIDTH / (64.0 * chart_zoom);
1947 double vscale = MAIN_GUI_PIXEL_HEIGHT / (128.0 * chart_zoom);
1948 if (mouse_left_down == NO) {
1949 NSPoint centre = [self adjusted_chart_centre];
1950 centre_at_mouse_click = chart_centre_coordinates;
1951 mouse_click_position = maus;
1952 chart_focus_coordinates.x = OOClamp_0_max_f(centre.x + (maus.x * MAIN_GUI_PIXEL_WIDTH) / hscale, 256.0);
1953 chart_focus_coordinates.y = OOClamp_0_max_f(centre.y + (maus.y * MAIN_GUI_PIXEL_HEIGHT + vadjust) / vscale, 256.0);
1954 target_chart_focus = chart_focus_coordinates;
1955 }
1956 if (fabs(maus.x - mouse_click_position.x) * MAIN_GUI_PIXEL_WIDTH > 2 || fabs(maus.y - mouse_click_position.y) * MAIN_GUI_PIXEL_HEIGHT > 2) {
1957 chart_centre_coordinates.x = OOClamp_0_max_f(centre_at_mouse_click.x - (maus.x - mouse_click_position.x) * MAIN_GUI_PIXEL_WIDTH / hscale, 256.0);
1958 chart_centre_coordinates.y = OOClamp_0_max_f(centre_at_mouse_click.y - (maus.y - mouse_click_position.y) * MAIN_GUI_PIXEL_HEIGHT / vscale, 256.0);
1959 target_chart_centre = chart_centre_coordinates;
1960 dragging = YES;
1961 }
1962 if (gui_screen == GUI_SCREEN_LONG_RANGE_CHART)
1964 mouse_left_down = YES;
1965 } else if (mouse_left_down == YES) {
1966 NSPoint maus = [gameView virtualJoystickPosition];
1967 if (fabs(maus.x - mouse_click_position.x) * MAIN_GUI_PIXEL_WIDTH <= 2 && fabs(maus.y - mouse_click_position.y) * MAIN_GUI_PIXEL_HEIGHT <= 2) {
1968 cursor_coordinates = chart_focus_coordinates;
1969 moving = YES;
1970 } else {
1971 dragging = YES;
1972 }
1973 mouse_left_down = NO;
1974 }
1975 if ([self checkKeyPress:n_key_map_home]) {
1976 if ([gameView isOptDown]) {
1977 [self homeInfoSystem];
1978 target_chart_focus = galaxy_coordinates;
1979 } else {
1981 cursor_coordinates = galaxy_coordinates;
1982 target_chart_focus = cursor_coordinates;
1983 target_chart_centre = galaxy_coordinates;
1984 found_system_id = -1;
1985 [UNIVERSE findSystemCoordinatesWithPrefix:@""];
1986 moving = YES;
1987 }
1988 }
1989 if ([self checkKeyPress:n_key_map_end]) {
1990 [self targetInfoSystem];
1991 target_chart_focus = cursor_coordinates;
1992 }
1993 if ([self checkKeyPress:n_key_map_zoom_in] || [gameView mouseWheelState] == gvMouseWheelDown) {
1994 target_chart_zoom *= CHART_ZOOM_SPEED_FACTOR;
1995 if (target_chart_zoom > CHART_MAX_ZOOM)
1996 target_chart_zoom = CHART_MAX_ZOOM;
1997 saved_chart_zoom = target_chart_zoom;
1998 }
1999 if ([self checkKeyPress:n_key_map_zoom_out] || [gameView mouseWheelState] == gvMouseWheelUp) {
2000 if (gui_screen == GUI_SCREEN_LONG_RANGE_CHART) {
2001 target_chart_zoom = CHART_MAX_ZOOM;
2003 }
2004 target_chart_zoom /= CHART_ZOOM_SPEED_FACTOR;
2005 if (target_chart_zoom < 1.0)
2006 target_chart_zoom = 1.0;
2007 saved_chart_zoom = target_chart_zoom;
2008 // target_chart_centre = cursor_coordinates;
2009 target_chart_focus = target_chart_centre;
2010 }
2011
2012 BOOL nextSystem = [gameView isShiftDown];
2013 BOOL nextSystemOnRoute = [gameView isOptDown];
2014
2015 if ([self checkNavKeyPress:n_key_gui_arrow_left]) {
2016 if ((nextSystem || nextSystemOnRoute) && pressedArrow != 1) {
2017 if (nextSystem) {
2018 [self targetNewSystem:-1];
2019 target_chart_focus = cursor_coordinates;
2020 } else {
2022 [self previousInfoSystem];
2023 target_chart_focus = [[UNIVERSE systemManager] getCoordinatesForSystem:info_system_id inGalaxy:galaxy_number];
2024 }
2025 pressedArrow = 1;
2026 } else if (!nextSystem && !nextSystemOnRoute) {
2028 cursor_coordinates.x -= cursor_speed * delta_t;
2029 if (cursor_coordinates.x < 0.0)
2030 cursor_coordinates.x = 0.0;
2031 moving = YES;
2032 target_chart_focus = cursor_coordinates;
2033 }
2034 } else
2036
2037 if ([self checkNavKeyPress:n_key_gui_arrow_right]) {
2038 if ((nextSystem || nextSystemOnRoute) && pressedArrow != 2) {
2039 if (nextSystem) {
2040 [self targetNewSystem:+1];
2041 target_chart_focus = cursor_coordinates;
2042 } else {
2044 [self nextInfoSystem];
2045 target_chart_focus = [[UNIVERSE systemManager] getCoordinatesForSystem:info_system_id inGalaxy:galaxy_number];
2046 }
2047 pressedArrow = 2;
2048 } else if (!nextSystem && !nextSystemOnRoute) {
2050 cursor_coordinates.x += cursor_speed * delta_t;
2051 if (cursor_coordinates.x > 256.0)
2052 cursor_coordinates.x = 256.0;
2053 moving = YES;
2054 target_chart_focus = cursor_coordinates;
2055 }
2056 } else
2058
2059 if ([self checkNavKeyPress:n_key_gui_arrow_down]) {
2060 if (nextSystem && pressedArrow != 3) {
2061 [self targetNewSystem:+1];
2062 pressedArrow = 3;
2063 } else if (!nextSystem) {
2065 cursor_coordinates.y += cursor_speed * delta_t * 2.0;
2066 if (cursor_coordinates.y > 256.0)
2067 cursor_coordinates.y = 256.0;
2068 moving = YES;
2069 }
2070 target_chart_focus = cursor_coordinates;
2071 } else
2073
2074 if ([self checkNavKeyPress:n_key_gui_arrow_up]) {
2075 if (nextSystem && pressedArrow != 4) {
2076 [self targetNewSystem:-1];
2077 pressedArrow = 4;
2078 } else if (!nextSystem) {
2080 cursor_coordinates.y -= cursor_speed * delta_t * 2.0;
2081 if (cursor_coordinates.y < 0.0)
2082 cursor_coordinates.y = 0.0;
2083 moving = YES;
2084 }
2085 target_chart_focus = cursor_coordinates;
2086 } else
2088 if ((cursor_moving) && (!moving)) {
2089 if (found_system_id == -1) {
2090 target_system_id = [UNIVERSE findSystemNumberAtCoords:cursor_coordinates withGalaxy:galaxy_number includingHidden:NO];
2091 [self setInfoSystemID:target_system_id moveChart:YES];
2092 } else {
2093 // if found with a search string, don't recalculate! Required for overlapping systems, like Divees & Tezabi in galaxy 5
2094 NSPoint fpos = [[UNIVERSE systemManager] getCoordinatesForSystem:found_system_id inGalaxy:galaxy_number];
2095 if (fpos.x != cursor_coordinates.x && fpos.y != cursor_coordinates.y) {
2096 target_system_id = [UNIVERSE findSystemNumberAtCoords:cursor_coordinates withGalaxy:galaxy_number includingHidden:NO];
2097 [self setInfoSystemID:target_system_id moveChart:YES];
2098 }
2099 }
2100 cursor_coordinates = [[UNIVERSE systemManager] getCoordinatesForSystem:target_system_id inGalaxy:galaxy_number];
2101 }
2102 if (chart_focus_coordinates.x - target_chart_centre.x <= -CHART_SCROLL_AT_X * chart_zoom) {
2103 target_chart_centre.x = chart_focus_coordinates.x + CHART_SCROLL_AT_X * chart_zoom;
2104 } else if (chart_focus_coordinates.x - target_chart_centre.x >= CHART_SCROLL_AT_X * chart_zoom) {
2105 target_chart_centre.x = chart_focus_coordinates.x - CHART_SCROLL_AT_X * chart_zoom;
2106 }
2107 if (chart_focus_coordinates.y - target_chart_centre.y <= -CHART_SCROLL_AT_Y * chart_zoom) {
2108 target_chart_centre.y = chart_focus_coordinates.y + CHART_SCROLL_AT_Y * chart_zoom;
2109 } else if (chart_focus_coordinates.y - target_chart_centre.y >= CHART_SCROLL_AT_Y * chart_zoom) {
2110 target_chart_centre.y = chart_focus_coordinates.y - CHART_SCROLL_AT_Y * chart_zoom;
2111 }
2112 chart_centre_coordinates.x = (3.0 * chart_centre_coordinates.x + target_chart_centre.x) / 4.0;
2113 chart_centre_coordinates.y = (3.0 * chart_centre_coordinates.y + target_chart_centre.y) / 4.0;
2114 chart_zoom = (3.0 * chart_zoom + target_chart_zoom) / 4.0;
2115 chart_focus_coordinates.x = (3.0 * chart_focus_coordinates.x + target_chart_focus.x) / 4.0;
2116 chart_focus_coordinates.y = (3.0 * chart_focus_coordinates.y + target_chart_focus.y) / 4.0;
2117 if (cursor_moving || dragging)
2118 [self setGuiToChartScreenFrom:gui_screen]; // update graphics
2119 cursor_moving = moving;
2120 }
2121 break;
2122
2123 case GUI_SCREEN_SYSTEM_DATA:
2124 if ([self checkKeyPress:n_key_system_next_system]) {
2126 [self nextInfoSystem];
2128 }
2129 } else {
2131 }
2132 if ([self checkKeyPress:n_key_system_previous_system]) {
2134 [self previousInfoSystem];
2136 }
2137 } else {
2139 }
2140 if ([self checkKeyPress:n_key_system_home]) {
2141 if (!home_info_pressed) {
2142 [self homeInfoSystem];
2143 home_info_pressed = YES;
2144 }
2145 } else {
2146 home_info_pressed = NO;
2147 }
2148 if ([self checkKeyPress:n_key_system_end]) {
2149 if (!target_info_pressed) {
2150 [self targetInfoSystem];
2151 target_info_pressed = YES;
2152 }
2153 } else {
2155 }
2156 break;
2157
2158 // DJS: Farm off load/save screen options to LoadSave.m
2159 case GUI_SCREEN_LOAD: {
2160 NSString* commanderFile = [self commanderSelector];
2161 if (commanderFile) {
2162 // also release the demo ship here (see showShipyardModel and noteGUIDidChangeFrom)
2163 [demoShip release];
2164 demoShip = nil;
2165
2166 [self loadPlayerFromFile:commanderFile asNew:NO];
2167 }
2168 break;
2169 }
2170
2171 case GUI_SCREEN_SAVE:
2173 /* Only F1 works for launch on this screen, not '1' or
2174 * whatever it has been bound to */
2175 if ([self checkKeyPress:n_key_launch_ship fKey_only:YES])
2176 [self handleUndockControl];
2177 if (gui_screen == GUI_SCREEN_SAVE) {
2179 } else
2180 pollControls = YES;
2181 break;
2182
2183 case GUI_SCREEN_SAVE_OVERWRITE:
2185 break;
2186
2187 case GUI_SCREEN_STICKMAPPER:
2189 break;
2190
2191 case GUI_SCREEN_STICKPROFILE:
2192 [self stickProfileInputHandler:gui view:gameView];
2193 break;
2194
2195 case GUI_SCREEN_GAMEOPTIONS:
2197 break;
2198
2199 case GUI_SCREEN_KEYBOARD:
2201 // if ([gameView isDown:' '])
2202 //{
2203 // [self setGuiToGameOptionsScreen];
2204 // }
2205 break;
2206
2207 case GUI_SCREEN_KEYBOARD_CONFIRMCLEAR:
2208 [self handleKeyMapperConfirmClearKeys:gui view:gameView];
2209 break;
2210
2211 case GUI_SCREEN_KEYBOARD_CONFIG:
2212 [self handleKeyConfigKeys:gui view:gameView];
2213 break;
2214
2215 case GUI_SCREEN_KEYBOARD_ENTRY:
2216 [self handleKeyConfigEntryKeys:gui view:gameView];
2217 break;
2218
2219 case GUI_SCREEN_KEYBOARD_LAYOUT:
2221 break;
2222
2223 case GUI_SCREEN_SHIPLIBRARY:
2224 if ([gameView isDown:' ']) // '<space>'
2225 {
2226 // viewed in game, return to interfaces as that's where it's accessed from
2227 [self setGuiToInterfacesScreen:0];
2228 }
2229 if ([self checkKeyPress:n_key_gui_arrow_up] || joyButtonState[BUTTON_GUIUP]) // '<--'
2230 {
2231 if (!upDownKeyPressed)
2232 [UNIVERSE selectIntro2Previous];
2233 }
2234 if ([self checkKeyPress:n_key_gui_arrow_down] || joyButtonState[BUTTON_GUIDOWN]) // '-->'
2235 {
2236 if (!upDownKeyPressed)
2237 [UNIVERSE selectIntro2Next];
2238 }
2239 upDownKeyPressed = (([self checkKeyPress:n_key_gui_arrow_up] || joyButtonState[BUTTON_GUIUP]) || ([self checkKeyPress:n_key_gui_arrow_down] || joyButtonState[BUTTON_GUIDOWN]));
2240
2241 if ([self checkKeyPress:n_key_gui_arrow_left] || joyButtonState[BUTTON_GUILEFT]) // '<--'
2242 {
2244 [UNIVERSE selectIntro2PreviousCategory];
2245 }
2246 if ([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]) // '-->'
2247 {
2249 [UNIVERSE selectIntro2NextCategory];
2250 }
2251 leftRightKeyPressed = (([self checkKeyPress:n_key_gui_arrow_left] || joyButtonState[BUTTON_GUILEFT]) || ([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]));
2252
2253 break;
2254 case GUI_SCREEN_OPTIONS:
2256 OOGUIRow guiSelectedRow = [gui selectedRow];
2257 BOOL selectKeyPress = ([self checkKeyPress:n_key_gui_select] || [gameView isDown:gvMouseDoubleClick] || joyButtonState[BUTTON_GUISELECT]);
2258
2259 if (selectKeyPress) // 'enter'
2260 {
2261 if ((guiSelectedRow == GUI_ROW(, QUICKSAVE)) && (!disc_operation_in_progress)) {
2262 @try {
2264 [self quicksavePlayer];
2265 }
2266 @catch (NSException* exception) {
2267 OOLog(kOOLogException, @"\n\n***** Handling exception: %@ : %@ *****\n\n", [exception name], [exception reason]);
2268 if ([[exception name] isEqual:@"GameNotSavedException"]) // try saving game instead
2269 {
2270 OOLog(kOOLogException, @"%@", @"\n\n***** Trying a normal save instead *****\n\n");
2271 if ([controller inFullScreenMode])
2272 [controller pauseFullScreenModeToPerform:@selector(savePlayer) onTarget:self];
2273 else
2274 [self savePlayer];
2275 } else {
2276 @throw exception;
2277 }
2278 }
2279 }
2280 if ((guiSelectedRow == GUI_ROW(, SAVE)) && (!disc_operation_in_progress)) {
2282 [self savePlayer];
2283 }
2284 if ((guiSelectedRow == GUI_ROW(, LOAD)) && (!disc_operation_in_progress)) {
2286 if (![self loadPlayer]) {
2288 [self setGuiToStatusScreen];
2289 }
2290 }
2291
2292 if ((guiSelectedRow == GUI_ROW(, BEGIN_NEW)) && (!disc_operation_in_progress)) {
2294 [UNIVERSE setUseAddOns:SCENARIO_OXP_DEFINITION_ALL fromSaveGame:NO forceReinit:YES]; // calls reinitAndShowDemo
2295 }
2296
2297 if ([gameView isDown:gvMouseDoubleClick])
2299 } else {
2301 }
2302
2303#if OOLITE_SDL
2304 // quit only appears in GNUstep as users aren't
2305 // used to Cmd-Q equivs. Same goes for window
2306 // vs fullscreen.
2307 if ((guiSelectedRow == GUI_ROW(, QUIT)) && selectKeyPress) {
2308 [[UNIVERSE gameController] exitAppWithContext:@"Exit Game selected on options screen"];
2309 }
2310#endif
2311
2312 if ((guiSelectedRow == GUI_ROW(, GAMEOPTIONS)) && selectKeyPress) {
2315 }
2316
2317 break;
2318
2319 case GUI_SCREEN_EQUIP_SHIP:
2320 if ([self handleGUIUpDownArrowKeys]) {
2321 NSString* itemText = [gui selectedRowText];
2322 OOWeaponType weaponType = nil;
2323
2324 if ([itemText isEqual:FORWARD_FACING_STRING])
2325 weaponType = forward_weapon_type;
2326 if ([itemText isEqual:AFT_FACING_STRING])
2327 weaponType = aft_weapon_type;
2328 if ([itemText isEqual:PORT_FACING_STRING])
2329 weaponType = port_weapon_type;
2330 if ([itemText isEqual:STARBOARD_FACING_STRING])
2331 weaponType = starboard_weapon_type;
2332
2333 if (weaponType != nil) {
2334 BOOL sameAs = OOWeaponTypeFromEquipmentIdentifierSloppy([gui selectedRowKey]) == weaponType;
2335 // override showInformation _completely_ with itemText
2336 if ([[weaponType identifier] isEqualToString:@"EQ_WEAPON_NONE"])
2337 itemText = DESC(@"no-weapon-enter-to-install");
2338 else {
2339 NSString* weaponName = [[OOEquipmentType equipmentTypeWithIdentifier:OOEquipmentIdentifierFromWeaponType(weaponType)] name];
2340 if (sameAs)
2341 itemText = [NSString stringWithFormat:DESC(@"weapon-installed-@"), weaponName];
2342 else
2343 itemText = [NSString stringWithFormat:DESC(@"weapon-@-enter-to-replace"), weaponName];
2344 }
2345
2347 } else
2349 }
2350
2351 if ([self checkKeyPress:n_key_gui_arrow_left] || [self checkKeyPress:n_key_gui_page_up] || joyButtonState[BUTTON_GUILEFT] || joyButtonState[BUTTON_GUIPAGEUP]) {
2352 if ((!leftRightKeyPressed) || (script_time > timeLastKeyPress + KEY_REPEAT_INTERVAL)) {
2353 if ([[gui keyForRow:GUI_ROW_EQUIPMENT_START] hasPrefix:@"More:"]) {
2354 [self playMenuPagePrevious];
2355 [gui setSelectedRow:GUI_ROW_EQUIPMENT_START];
2356 [self buySelectedItem];
2357 }
2358 timeLastKeyPress = script_time;
2359 }
2360 }
2361 if ([self checkKeyPress:n_key_gui_arrow_right] || [self checkKeyPress:n_key_gui_page_down] || joyButtonState[BUTTON_GUIRIGHT] || joyButtonState[BUTTON_GUIPAGEDOWN]) {
2362 if ((!leftRightKeyPressed) || (script_time > timeLastKeyPress + KEY_REPEAT_INTERVAL)) {
2363 if ([[gui keyForRow:GUI_ROW_EQUIPMENT_START + GUI_MAX_ROWS_EQUIPMENT - 1] hasPrefix:@"More:"]) {
2364 [self playMenuPageNext];
2365 [gui setSelectedRow:GUI_ROW_EQUIPMENT_START + GUI_MAX_ROWS_EQUIPMENT - 1];
2366 [self buySelectedItem];
2367 }
2368 timeLastKeyPress = script_time;
2369 }
2370 }
2371 leftRightKeyPressed = [self checkKeyPress:n_key_gui_arrow_right] | [self checkKeyPress:n_key_gui_arrow_left] | [self checkKeyPress:n_key_gui_page_down] | [self checkKeyPress:n_key_gui_page_up] | joyButtonState[BUTTON_GUILEFT] | joyButtonState[BUTTON_GUIRIGHT] | joyButtonState[BUTTON_GUIPAGEUP] | joyButtonState[BUTTON_GUIPAGEDOWN];
2372
2373 if ([self checkKeyPress:n_key_gui_select] || [gameView isDown:gvMouseDoubleClick] || joyButtonState[BUTTON_GUISELECT]) {
2374 if ([gameView isDown:gvMouseDoubleClick]) {
2375 selectPressed = NO;
2377 }
2378 if ((!selectPressed) && ([gui selectedRow] > -1)) {
2379 [self buySelectedItem];
2380 selectPressed = YES;
2381 }
2382 } else {
2383 selectPressed = NO;
2384 }
2385 break;
2386
2387 case GUI_SCREEN_INTERFACES:
2388 if ([self handleGUIUpDownArrowKeys]) {
2390 }
2391 if ([self checkKeyPress:n_key_gui_arrow_left] || [self checkKeyPress:n_key_gui_page_up] || joyButtonState[BUTTON_GUILEFT] || joyButtonState[BUTTON_GUIPAGEUP]) {
2392 if ((!leftRightKeyPressed) || (script_time > timeLastKeyPress + KEY_REPEAT_INTERVAL)) {
2393 if ([[gui keyForRow:GUI_ROW_INTERFACES_START] hasPrefix:@"More:"]) {
2394 [self playMenuPagePrevious];
2395 [gui setSelectedRow:GUI_ROW_INTERFACES_START];
2397 }
2398 timeLastKeyPress = script_time;
2399 }
2400 }
2401 if ([self checkKeyPress:n_key_gui_arrow_right] || [self checkKeyPress:n_key_gui_page_down] || joyButtonState[BUTTON_GUIRIGHT] || joyButtonState[BUTTON_GUIPAGEDOWN]) {
2402 if ((!leftRightKeyPressed) || (script_time > timeLastKeyPress + KEY_REPEAT_INTERVAL)) {
2403 if ([[gui keyForRow:GUI_ROW_INTERFACES_START + GUI_MAX_ROWS_INTERFACES - 1] hasPrefix:@"More:"]) {
2404 [self playMenuPageNext];
2405 [gui setSelectedRow:GUI_ROW_INTERFACES_START + GUI_MAX_ROWS_INTERFACES - 1];
2407 }
2408 timeLastKeyPress = script_time;
2409 }
2410 }
2411 leftRightKeyPressed = [self checkKeyPress:n_key_gui_arrow_right] | [self checkKeyPress:n_key_gui_arrow_left] | [self checkKeyPress:n_key_gui_page_down] | [self checkKeyPress:n_key_gui_page_up] | joyButtonState[BUTTON_GUILEFT] | joyButtonState[BUTTON_GUIRIGHT] | joyButtonState[BUTTON_GUIPAGEUP] | joyButtonState[BUTTON_GUIPAGEDOWN];
2412 if ([self checkKeyPress:n_key_gui_select] || [gameView isDown:gvMouseDoubleClick] || joyButtonState[BUTTON_GUISELECT]) // 'enter'
2413 {
2414 if ([gameView isDown:gvMouseDoubleClick]) {
2415 selectPressed = NO;
2417 }
2418 if ((!selectPressed) && ([gui selectedRow] > -1)) {
2420 selectPressed = YES;
2421 }
2422 } else {
2423 selectPressed = NO;
2424 }
2425 break;
2426
2427 case GUI_SCREEN_MARKETINFO:
2429 break;
2430
2431 case GUI_SCREEN_MARKET:
2433
2434 if ([self checkKeyPress:n_key_market_filter_cycle] || [self checkKeyPress:n_key_market_sorter_cycle]) {
2435 if (!queryPressed) {
2436 queryPressed = YES;
2437 if ([self checkKeyPress:n_key_market_filter_cycle]) {
2438 if (marketFilterMode >= MARKET_FILTER_MODE_MAX) {
2439 marketFilterMode = MARKET_FILTER_MODE_OFF;
2440 } else {
2441 marketFilterMode++;
2442 }
2443 } else {
2444 if (marketSorterMode >= MARKET_SORTER_MODE_MAX) {
2445 marketSorterMode = MARKET_SORTER_MODE_OFF;
2446 } else {
2447 marketSorterMode++;
2448 }
2449 }
2450 [self playChangedOption];
2451 [self setGuiToMarketScreen];
2452 }
2453 } else {
2454 queryPressed = NO;
2455 }
2456
2457 break;
2458
2459 case GUI_SCREEN_REPORT:
2460 if ([gameView isDown:32]) // spacebar
2461 {
2462 if (!spacePressed) {
2463 BOOL reportEnded = ([dockingReport length] == 0);
2465 if (reportEnded) {
2466 [self setGuiToStatusScreen];
2467 [self doScriptEvent:OOJSID("reportScreenEnded")]; // last report given. Screen is now free for missionscreens.
2468 [self doWorldEventUntilMissionScreen:OOJSID("missionScreenOpportunity")];
2469 } else {
2471 }
2472 }
2473 spacePressed = YES;
2474 } else
2475 spacePressed = NO;
2476 break;
2477 case GUI_SCREEN_STATUS:
2479 if ([self checkKeyPress:n_key_gui_arrow_left] || [self checkKeyPress:n_key_gui_page_up] || joyButtonState[BUTTON_GUILEFT] || joyButtonState[BUTTON_GUIPAGEUP]) {
2480
2481 if ((!leftRightKeyPressed) || (script_time > timeLastKeyPress + KEY_REPEAT_INTERVAL)) {
2482 if ([[gui keyForRow:STATUS_EQUIPMENT_FIRST_ROW] isEqual:GUI_KEY_OK]) {
2483 [gui setSelectedRow:STATUS_EQUIPMENT_FIRST_ROW];
2484 [self playMenuPagePrevious];
2485 [gui setStatusPage:-1];
2486 [self setGuiToStatusScreen];
2487 }
2488 timeLastKeyPress = script_time;
2489 }
2490 }
2491 if ([self checkKeyPress:n_key_gui_arrow_right] || [self checkKeyPress:n_key_gui_page_down] || joyButtonState[BUTTON_GUIRIGHT] || joyButtonState[BUTTON_GUIPAGEDOWN]) {
2492
2493 if ((!leftRightKeyPressed) || (script_time > timeLastKeyPress + KEY_REPEAT_INTERVAL)) {
2495 if ([[gui keyForRow:STATUS_EQUIPMENT_FIRST_ROW + maxRows] isEqual:GUI_KEY_OK]) {
2496 [gui setSelectedRow:STATUS_EQUIPMENT_FIRST_ROW + maxRows];
2497 [self playMenuPageNext];
2498 [gui setStatusPage:+1];
2499 [self setGuiToStatusScreen];
2500 }
2501 timeLastKeyPress = script_time;
2502 }
2503 }
2504 leftRightKeyPressed = [self checkKeyPress:n_key_gui_arrow_right] | [self checkKeyPress:n_key_gui_arrow_left] | [self checkKeyPress:n_key_gui_page_down] | [self checkKeyPress:n_key_gui_page_up] | joyButtonState[BUTTON_GUILEFT] | joyButtonState[BUTTON_GUIRIGHT] | joyButtonState[BUTTON_GUIPAGEUP] | joyButtonState[BUTTON_GUIPAGEDOWN];
2505
2506 if ([self checkKeyPress:n_key_gui_select] || [gameView isDown:gvMouseDoubleClick] || joyButtonState[BUTTON_GUISELECT]) {
2507 if ([gameView isDown:gvMouseDoubleClick]) {
2508 selectPressed = NO;
2510 }
2511 if ((!selectPressed) && ([gui selectedRow] > -1)) {
2512 [gui setStatusPage:([gui selectedRow] == STATUS_EQUIPMENT_FIRST_ROW ? -1 : +1)];
2513 [self setGuiToStatusScreen];
2514
2515 selectPressed = YES;
2516 }
2517 } else {
2518 selectPressed = NO;
2519 }
2520
2521 break;
2522 case GUI_SCREEN_MANIFEST:
2524 if ([self checkKeyPress:n_key_gui_arrow_left] || [self checkKeyPress:n_key_gui_page_up] || joyButtonState[BUTTON_GUILEFT] || joyButtonState[BUTTON_GUIPAGEUP]) {
2525
2526 if ((!leftRightKeyPressed) || (script_time > timeLastKeyPress + KEY_REPEAT_INTERVAL)) {
2527 if ([[gui keyForRow:MANIFEST_SCREEN_ROW_BACK] isEqual:GUI_KEY_OK]) {
2528 [gui setSelectedRow:MANIFEST_SCREEN_ROW_BACK];
2529 [self playMenuPagePrevious];
2530 [gui setStatusPage:-1];
2532 }
2533 timeLastKeyPress = script_time;
2534 }
2535 }
2536 if ([self checkKeyPress:n_key_gui_arrow_right] || [self checkKeyPress:n_key_gui_page_down] || joyButtonState[BUTTON_GUIRIGHT] || joyButtonState[BUTTON_GUIPAGEDOWN]) {
2538 if ([[self hud] isHidden] || [[self hud] allowBigGui]) {
2539 nextRow += 7;
2540 }
2541 if ((!leftRightKeyPressed) || (script_time > timeLastKeyPress + KEY_REPEAT_INTERVAL)) {
2542 if ([[gui keyForRow:nextRow] isEqual:GUI_KEY_OK]) {
2543 [gui setSelectedRow:nextRow];
2544 [self playMenuPageNext];
2545 [gui setStatusPage:+1];
2547 }
2548 timeLastKeyPress = script_time;
2549 }
2550 }
2551 leftRightKeyPressed = [self checkKeyPress:n_key_gui_arrow_right] | [self checkKeyPress:n_key_gui_arrow_left] | [self checkKeyPress:n_key_gui_page_down] | [self checkKeyPress:n_key_gui_page_up] | joyButtonState[BUTTON_GUILEFT] | joyButtonState[BUTTON_GUIRIGHT] | joyButtonState[BUTTON_GUIPAGEUP] | joyButtonState[BUTTON_GUIPAGEDOWN];
2552
2553 if ([self checkKeyPress:n_key_gui_select] || [gameView isDown:gvMouseDoubleClick] || joyButtonState[BUTTON_GUISELECT]) {
2554 if ([gameView isDown:gvMouseDoubleClick]) {
2555 selectPressed = NO;
2557 }
2558 if ((!selectPressed) && ([gui selectedRow] > -1)) {
2559 [gui setStatusPage:([gui selectedRow] == MANIFEST_SCREEN_ROW_BACK ? -1 : +1)];
2561
2562 selectPressed = YES;
2563 }
2564 } else {
2565 selectPressed = NO;
2566 }
2567
2568 break;
2569
2570 case GUI_SCREEN_SHIPYARD:
2571 if ([self handleGUIUpDownArrowKeys]) {
2573 }
2574
2575 if ([self checkKeyPress:n_key_gui_arrow_left] || [self checkKeyPress:n_key_gui_page_up] || joyButtonState[BUTTON_GUILEFT] || joyButtonState[BUTTON_GUIPAGEUP]) {
2576 if ((!leftRightKeyPressed) || (script_time > timeLastKeyPress + KEY_REPEAT_INTERVAL)) {
2577 if ([[gui keyForRow:GUI_ROW_SHIPYARD_START] hasPrefix:@"More:"]) {
2578 [self playMenuPagePrevious];
2579 [gui setSelectedRow:GUI_ROW_SHIPYARD_START];
2580 [self buySelectedShip];
2581 }
2582 timeLastKeyPress = script_time;
2583 }
2584 }
2585 if ([self checkKeyPress:n_key_gui_arrow_right] || [self checkKeyPress:n_key_gui_page_down] || joyButtonState[BUTTON_GUIRIGHT] || joyButtonState[BUTTON_GUIPAGEDOWN]) {
2586 if ((!leftRightKeyPressed) || (script_time > timeLastKeyPress + KEY_REPEAT_INTERVAL)) {
2587 if ([[gui keyForRow:GUI_ROW_SHIPYARD_START + MAX_ROWS_SHIPS_FOR_SALE - 1] hasPrefix:@"More:"]) {
2588 [self playMenuPageNext];
2589 [gui setSelectedRow:GUI_ROW_SHIPYARD_START + MAX_ROWS_SHIPS_FOR_SALE - 1];
2590 [self buySelectedShip];
2591 }
2592 timeLastKeyPress = script_time;
2593 }
2594 }
2595 leftRightKeyPressed = [self checkKeyPress:n_key_gui_arrow_right] | [self checkKeyPress:n_key_gui_arrow_left] | [self checkKeyPress:n_key_gui_page_down] | [self checkKeyPress:n_key_gui_page_up] | joyButtonState[BUTTON_GUILEFT] | joyButtonState[BUTTON_GUIRIGHT] | joyButtonState[BUTTON_GUIPAGEUP] | joyButtonState[BUTTON_GUIPAGEDOWN];
2596
2597 if ([self checkKeyPress:n_key_gui_select] || joyButtonState[BUTTON_GUISELECT]) // 'enter' NOT double-click
2598 {
2599 if (!selectPressed) {
2600 // try to buy the ship!
2601 NSString* key = [gui keyForRow:[gui selectedRow]];
2602 OOCreditsQuantity shipprice = 0;
2603 if (![key hasPrefix:@"More:"]) {
2604 shipprice = [self priceForShipKey:key];
2605 }
2606
2607 if ([self buySelectedShip]) {
2608 if (![key hasPrefix:@"More:"]) // don't do anything if we clicked/selected a "More:" line
2609 {
2610 [UNIVERSE removeDemoShips];
2611 [self setGuiToStatusScreen];
2612 [self playBuyShip];
2613 [self doScriptEvent:OOJSID("playerBoughtNewShip") withArgument:self andArgument:[NSNumber numberWithUnsignedLongLong:shipprice]]; // some equipment.oxp might want to know everything has changed.
2614 }
2615 } else {
2616 [self playCantBuyShip];
2617 }
2618 }
2619 selectPressed = YES;
2620 } else {
2621 selectPressed = NO;
2622 }
2623 if ([gameView isDown:gvMouseDoubleClick]) {
2624 if (([gui selectedRow] == GUI_ROW_SHIPYARD_START + MAX_ROWS_SHIPS_FOR_SALE - 1) && [[gui keyForRow:GUI_ROW_SHIPYARD_START + MAX_ROWS_SHIPS_FOR_SALE - 1] hasPrefix:@"More:"]) {
2625 [self playMenuPageNext];
2626 [gui setSelectedRow:GUI_ROW_SHIPYARD_START + MAX_ROWS_SHIPS_FOR_SALE - 1];
2627 [self buySelectedShip];
2628 } else if (([gui selectedRow] == GUI_ROW_SHIPYARD_START) && [[gui keyForRow:GUI_ROW_SHIPYARD_START] hasPrefix:@"More:"]) {
2629 [self playMenuPagePrevious];
2630 [gui setSelectedRow:GUI_ROW_SHIPYARD_START];
2631 [self buySelectedShip];
2632 }
2634 }
2635
2636 break;
2637
2638 default:
2639 break;
2640 }
2641
2642 // check for any extra keys added by scripting
2643 NSArray* keys = [extraGuiScreenKeys objectForKey:[NSString stringWithFormat:@"%d", gui_screen]];
2644 if (keys) {
2645 NSInteger kc = [keys count];
2646 OOJSGuiScreenKeyDefinition* definition = nil;
2647 NSDictionary* keydefs = nil;
2648 NSString* key = nil;
2649 while (kc--) {
2650 definition = [keys objectAtIndex:kc];
2651 keydefs = [definition registerKeys];
2652 foreach (key, [keydefs allKeys]) {
2653 if ([self checkKeyPress:[keydefs objectForKey:key]]) {
2654 if (!extra_gui_key_pressed) {
2655 // do callback
2656 if (definition) {
2657 [[UNIVERSE gameView] clearKeys];
2658 [definition runCallback:key];
2659 } else {
2660 OOLog(@"interface.missingCallback", @"Unable to find callback definition for %@ using key %@", [definition name], key);
2661 }
2662 }
2664 } else
2666 }
2667 }
2668 }
2669
2670 // damp any rotations we entered with
2671 if (flightRoll > 0.0) {
2672 if (flightRoll > delta_t)
2673 [self decrease_flight_roll:delta_t];
2674 else
2675 flightRoll = 0.0;
2676 }
2677 if (flightRoll < 0.0) {
2678 if (flightRoll < -delta_t)
2679 [self increase_flight_roll:delta_t];
2680 else
2681 flightRoll = 0.0;
2682 }
2683 if (flightPitch > 0.0) {
2684 if (flightPitch > delta_t)
2685 [self decrease_flight_pitch:delta_t];
2686 else
2687 flightPitch = 0.0;
2688 }
2689 if (flightPitch < 0.0) {
2690 if (flightPitch < -delta_t)
2691 [self increase_flight_pitch:delta_t];
2692 else
2693 flightPitch = 0.0;
2694 }
2695 if (flightYaw > 0.0) {
2696 if (flightYaw > delta_t)
2697 [self decrease_flight_yaw:delta_t];
2698 else
2699 flightYaw = 0.0;
2700 }
2701 if (flightYaw < 0.0) {
2702 if (flightYaw < -delta_t)
2703 [self increase_flight_yaw:delta_t];
2704 else
2705 flightYaw = 0.0;
2706 }
2707}
2708
2710{
2711 MyOpenGLView* gameView = [UNIVERSE gameView];
2712 GuiDisplayGen* gui = [UNIVERSE gui];
2713 const BOOL* joyButtonState = [[OOJoystickManager sharedStickHandler] getAllButtonStates];
2714
2715 if (gui_screen == GUI_SCREEN_MARKET) {
2717 DESTROY(marketSelectedCommodity);
2718 marketSelectedCommodity = [[gui selectedRowKey] retain];
2719
2720 BOOL page_up = [self checkKeyPress:n_key_gui_page_up] || joyButtonState[BUTTON_GUIPAGEUP];
2721 BOOL page_down = [self checkKeyPress:n_key_gui_page_down] || joyButtonState[BUTTON_GUIPAGEDOWN];
2722 if (page_up || page_down) {
2723 if ((!pageUpDownKeyPressed) || (script_time > timeLastKeyPress + KEY_REPEAT_INTERVAL)) {
2724 OOCommodityMarket* localMarket = [self localMarket];
2725 NSArray* goods = [self applyMarketSorter:[self applyMarketFilter:[localMarket goods] onMarket:localMarket] onMarket:localMarket];
2726 if ([goods count] > 0) {
2727 NSInteger goodsIndex = [goods indexOfObject:marketSelectedCommodity];
2728 NSInteger offset1 = 0;
2729 NSInteger offset2 = 0;
2730 if ([[gui keyForRow:GUI_ROW_MARKET_START] isEqualToString:@"<<<"] == true)
2731 offset1 += 1;
2732 if ([[gui keyForRow:GUI_ROW_MARKET_LAST] isEqualToString:@">>>"] == true)
2733 offset2 += 1;
2734 if (page_up) {
2735 [self playMenuPagePrevious];
2736 // some edge cases
2737 if (goodsIndex - 16 <= 0) {
2738 offset1 = 0;
2739 offset2 = 0;
2740 }
2741 if (offset1 == 1 && offset2 == 0 && goodsIndex < (NSInteger)[goods count] - 1 && goodsIndex - 15 > 0)
2742 offset2 = 1;
2743 goodsIndex -= (16 - (offset1 + offset2));
2744 if (goodsIndex < 0)
2745 goodsIndex = 0;
2746 if ([goods count] <= 17)
2747 goodsIndex = 0;
2748 }
2749 if (page_down) {
2750 [self playMenuPageNext];
2751 // some edge cases
2752 if (offset1 == 0 && offset2 == 1 && goodsIndex > 1)
2753 offset1 = 1;
2754 if (offset2 == 1 && goodsIndex + 15 == (NSInteger)[goods count] - 1)
2755 offset2 = 0;
2756 goodsIndex += (16 - (offset1 + offset2));
2757 if (goodsIndex > ((NSInteger)[goods count] - 1) || [goods count] <= 17)
2758 goodsIndex = (NSInteger)[goods count] - 1;
2759 }
2760 DESTROY(marketSelectedCommodity);
2761 marketSelectedCommodity = [[goods oo_stringAtIndex:goodsIndex] retain];
2762 [self setGuiToMarketScreen];
2763 }
2764 }
2766 timeLastKeyPress = script_time;
2767 } else {
2769 }
2770 } else {
2771 // handle up and down slightly differently
2772 BOOL arrow_up = [self checkKeyPress:n_key_gui_arrow_up] || joyButtonState[BUTTON_GUIUP];
2773 BOOL arrow_down = [self checkKeyPress:n_key_gui_arrow_down] || joyButtonState[BUTTON_GUIDOWN];
2774 if (arrow_up || arrow_down) {
2775 if ((!upDownKeyPressed) || (script_time > timeLastKeyPress + KEY_REPEAT_INTERVAL)) {
2776 OOCommodityMarket* localMarket = [self localMarket];
2777 NSArray* goods = [self applyMarketSorter:[self applyMarketFilter:[localMarket goods] onMarket:localMarket] onMarket:localMarket];
2778 if ([goods count] > 0) {
2779 NSInteger goodsIndex = [goods indexOfObject:marketSelectedCommodity];
2780 if (arrow_down) {
2781 ++goodsIndex;
2782 } else {
2783 --goodsIndex;
2784 }
2785 if (goodsIndex < 0) {
2786 goodsIndex = [goods count] - 1;
2787 } else if (goodsIndex >= (NSInteger)[goods count]) {
2788 goodsIndex = 0;
2789 }
2790 DESTROY(marketSelectedCommodity);
2791 marketSelectedCommodity = [[goods oo_stringAtIndex:goodsIndex] retain];
2793 }
2794 }
2795 upDownKeyPressed = YES;
2796 timeLastKeyPress = script_time;
2797 } else {
2798 upDownKeyPressed = NO;
2799 }
2800 }
2801
2802 BOOL isdocked = [self isDocked];
2803
2804 if (([self checkNavKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]) || ([self checkNavKeyPress:n_key_gui_arrow_left] || joyButtonState[BUTTON_GUILEFT]) || ([self checkKeyPress:n_key_gui_select] || [gameView isDown:gvMouseDoubleClick] || joyButtonState[BUTTON_GUISELECT])) {
2805 if ([self checkNavKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]) // -->
2806 {
2807 if (!wait_for_key_up) {
2808 if (isdocked && [self tryBuyingCommodity:marketSelectedCommodity all:[gameView isShiftDown]]) {
2809 [self playBuyCommodity];
2810 if (gui_screen == GUI_SCREEN_MARKET) {
2811 [self setGuiToMarketScreen];
2812 } else {
2814 }
2815 } else {
2816 if ([[gui selectedRowKey] isEqualToString:@">>>"]) {
2818 [self setGuiToMarketScreen];
2819 } else if ([[gui selectedRowKey] isEqualToString:@"<<<"]) {
2820 [self playMenuNavigationUp];
2821 [self setGuiToMarketScreen];
2822 } else {
2823 [self playCantBuyCommodity];
2824 }
2825 }
2826 wait_for_key_up = YES;
2827 }
2828 }
2829 if ([self checkNavKeyPress:n_key_gui_arrow_left] || joyButtonState[BUTTON_GUILEFT]) // <--
2830 {
2831 if (!wait_for_key_up) {
2832 if (isdocked && [self trySellingCommodity:marketSelectedCommodity all:[gameView isShiftDown]]) {
2833 [self playSellCommodity];
2834 if (gui_screen == GUI_SCREEN_MARKET) {
2835 [self setGuiToMarketScreen];
2836 } else {
2838 }
2839 } else {
2840 if ([[gui selectedRowKey] isEqualToString:@">>>"]) {
2842 [self setGuiToMarketScreen];
2843 } else if ([[gui selectedRowKey] isEqualToString:@"<<<"]) {
2844 [self playMenuNavigationUp];
2845 [self setGuiToMarketScreen];
2846 } else {
2847 [self playCantSellCommodity];
2848 }
2849 }
2850 wait_for_key_up = YES;
2851 }
2852 }
2853 if ((gui_screen == GUI_SCREEN_MARKET && [gameView isDown:gvMouseDoubleClick]) || ([self checkKeyPress:n_key_gui_select] || joyButtonState[BUTTON_GUISELECT])) // 'enter'
2854 {
2855 if ([gameView isDown:gvMouseDoubleClick]) {
2856 wait_for_key_up = NO;
2858 }
2859 if (!wait_for_key_up) {
2860 OOCommodityType item = marketSelectedCommodity;
2861 OOCargoQuantity yours = [shipCommodityData quantityForGood:item];
2862 if ([item isEqualToString:@">>>"]) {
2863 [self tryBuyingCommodity:item all:YES];
2864 [self setGuiToMarketScreen];
2865 } else if ([item isEqualToString:@"<<<"]) {
2866 [self trySellingCommodity:item all:YES];
2867 [self setGuiToMarketScreen];
2868 } else if (isdocked && [gameView isShiftDown] && [self tryBuyingCommodity:item all:YES]) // buy as much as possible (with Shift)
2869 {
2870 [self playBuyCommodity];
2871 if (gui_screen == GUI_SCREEN_MARKET) {
2872 [self setGuiToMarketScreen];
2873 } else {
2875 }
2876 } else if (isdocked && (yours > 0) && [self trySellingCommodity:item all:YES]) // sell all you can
2877 {
2878 [self playSellCommodity];
2879 if (gui_screen == GUI_SCREEN_MARKET) {
2880 [self setGuiToMarketScreen];
2881 } else {
2883 }
2884 } else if (isdocked && [self tryBuyingCommodity:item all:YES]) // buy as much as possible
2885 {
2886 [self playBuyCommodity];
2887 if (gui_screen == GUI_SCREEN_MARKET) {
2888 [self setGuiToMarketScreen];
2889 } else {
2891 }
2892 } else if (isdocked) {
2893 [self playCantBuyCommodity];
2894 }
2895 wait_for_key_up = YES;
2896 }
2897 }
2898 } else {
2899 wait_for_key_up = NO;
2900 }
2901}
2902
2904{
2905 MyOpenGLView* gameView = [UNIVERSE gameView];
2906 GuiDisplayGen* gui = [UNIVERSE gui];
2907 GUI_ROW_INIT(gui);
2908 const BOOL* joyButtonState = [[OOJoystickManager sharedStickHandler] getAllButtonStates];
2909
2911 OOGUIRow guiSelectedRow = [gui selectedRow];
2912 BOOL selectKeyPress = ([self checkKeyPress:n_key_gui_select] || [gameView isDown:gvMouseDoubleClick] || joyButtonState[BUTTON_GUISELECT]);
2913 if ([gameView isDown:gvMouseDoubleClick])
2915
2916 if ((guiSelectedRow == GUI_ROW(GAME, STICKMAPPER)) && selectKeyPress) {
2917 selFunctionIdx = 0;
2918 [self resetStickFunctions]; // reset the list of stick functions, so changes in oxp equipment are reflected
2921 }
2922 if ((guiSelectedRow == GUI_ROW(GAME, KEYMAPPER)) && selectKeyPress) {
2923 selFunctionIdx = 0;
2924 [self resetKeyFunctions]; // reset the list of key functions, so changes in oxp equipment are reflected
2927 }
2928
2929#if OOLITE_WINDOWS
2930 if ([gameView hdrOutput]) {
2931 if ((guiSelectedRow == GUI_ROW(GAME, HDRMAXBRIGHTNESS)) && (([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]) || ([self checkKeyPress:n_key_gui_arrow_left] || joyButtonState[BUTTON_GUILEFT]))) {
2932 if (!hdrMaxBrightnessControlPressed) {
2933 int direction = ([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]) ? 1 : -1;
2934 NSArray* brightnesses = [[UNIVERSE descriptions] oo_arrayForKey:@"hdr_maxBrightness_array"];
2935 int brightnessIdx = [brightnesses indexOfObject:[NSString stringWithFormat:@"%d", (int)[gameView hdrMaxBrightness]]];
2936
2937 if (brightnessIdx == NSNotFound) {
2938 OOLogWARN(@"hdr.maxBrightness.notFound", @"%@", @"couldn't find current max brightness setting, switching to lowest.");
2939 brightnessIdx = 0;
2940 }
2941
2942 brightnessIdx += direction;
2943 int count = [brightnesses count];
2944 if (brightnessIdx < 0)
2945 brightnessIdx = count - 1;
2946 if (brightnessIdx >= count)
2947 brightnessIdx = 0;
2948
2949 int brightnessValue = [brightnesses oo_intAtIndex:brightnessIdx];
2950
2951 // warp if the value we got is out of expected limits; can be the case if user has
2952 // manually modified the hdr_maxBrightness_array in descriptions.plist
2953 if (brightnessValue < MIN_HDR_MAXBRIGHTNESS)
2954 brightnessValue = direction == -1 ? MAX_HDR_MAXBRIGHTNESS : MIN_HDR_MAXBRIGHTNESS;
2955 if (brightnessValue > MAX_HDR_MAXBRIGHTNESS)
2956 brightnessValue = direction == 1 ? MIN_HDR_MAXBRIGHTNESS : MAX_HDR_MAXBRIGHTNESS;
2957
2958 [gameView setHDRMaxBrightness:(float)brightnessValue];
2959 NSString* maxBrightnessString = OOExpandKey(@"gameoptions-hdr-maxbrightness", brightnessValue);
2960
2961 [gui setText:maxBrightnessString forRow:GUI_ROW(GAME, HDRMAXBRIGHTNESS) align:GUI_ALIGN_CENTER];
2962
2963 hdrMaxBrightnessControlPressed = YES;
2964 }
2965 } else
2966 hdrMaxBrightnessControlPressed = NO;
2967 }
2968#endif
2969
2970#if OO_RESOLUTION_OPTION
2971 if (!switching_resolution && guiSelectedRow == GUI_ROW(GAME, DISPLAY) && ([self checkKeyPress:n_key_gui_arrow_right] || [self checkKeyPress:n_key_gui_arrow_left] || joyButtonState[BUTTON_GUIRIGHT] || joyButtonState[BUTTON_GUILEFT])) {
2972 GameController* controller = [UNIVERSE gameController];
2973 int direction = ([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]) ? 1 : -1;
2974 NSInteger displayModeIndex = [controller indexOfCurrentDisplayMode];
2975 NSArray* modes = [controller displayModes];
2976
2977 if (displayModeIndex == (NSInteger)NSNotFound) {
2978 OOLogWARN(@"graphics.mode.notFound", @"%@", @"couldn't find current fullscreen setting, switching to default.");
2979 displayModeIndex = 0;
2980 }
2981
2982 displayModeIndex = displayModeIndex + direction;
2983 int count = [modes count];
2984 if (displayModeIndex < 0)
2985 displayModeIndex = count - 1;
2986 if (displayModeIndex >= count)
2987 displayModeIndex = 0;
2988
2989 NSDictionary* mode = [modes objectAtIndex:displayModeIndex];
2990 int modeWidth = [mode oo_intForKey:kOODisplayWidth];
2991 int modeHeight = [mode oo_intForKey:kOODisplayHeight];
2992 int modeRefresh = [mode oo_intForKey:kOODisplayRefreshRate];
2993 [controller setDisplayWidth:modeWidth Height:modeHeight Refresh:modeRefresh];
2994
2995 NSString* displayModeString = [self screenModeStringForWidth:modeWidth height:modeHeight refreshRate:modeRefresh];
2996
2997 [self playChangedOption];
2998 [gui setText:displayModeString forRow:GUI_ROW(GAME, DISPLAY) align:GUI_ALIGN_CENTER];
3000
3001#if OOLITE_SDL
3002 /* TODO: The gameView for the SDL game currently holds and
3003 sets the actual screen resolution (controller just stores
3004 it). This probably ought to change. */
3005 [gameView setScreenSize:displayModeIndex]; // changes fullscreen mode immediately
3006#endif
3007 }
3008 if (switching_resolution && ![self checkKeyPress:n_key_gui_arrow_right] && ![self checkKeyPress:n_key_gui_arrow_left] && !selectKeyPress && !joyButtonState[BUTTON_GUIRIGHT] && !joyButtonState[BUTTON_GUILEFT]) {
3010 }
3011#endif // OO_RESOLUTION_OPTION
3012
3013#if OOLITE_SPEECH_SYNTH
3014
3015 if ((guiSelectedRow == GUI_ROW(GAME, SPEECH)) && (([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]) || ([self checkKeyPress:n_key_gui_arrow_left] || joyButtonState[BUTTON_GUILEFT]))) {
3016 if (!speech_settings_pressed) {
3017 if (([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]) && isSpeechOn < OOSPEECHSETTINGS_ALL) {
3018 ++isSpeechOn;
3019 [self playChangedOption];
3020 speech_settings_pressed = YES;
3021 } else if (([self checkKeyPress:n_key_gui_arrow_left] || joyButtonState[BUTTON_GUILEFT]) && isSpeechOn > OOSPEECHSETTINGS_OFF) {
3022 speech_settings_pressed = YES;
3023 --isSpeechOn;
3024 [self playChangedOption];
3025 }
3026 if (speech_settings_pressed) {
3027 NSString* message = nil;
3028 switch (isSpeechOn) {
3030 message = DESC(@"gameoptions-spoken-messages-no");
3031 break;
3033 message = DESC(@"gameoptions-spoken-messages-comms");
3034 break;
3036 message = DESC(@"gameoptions-spoken-messages-yes");
3037 break;
3038 }
3039 [gui setText:message forRow:GUI_ROW(GAME, SPEECH) align:GUI_ALIGN_CENTER];
3040
3041 if (isSpeechOn == OOSPEECHSETTINGS_ALL) {
3042 [UNIVERSE stopSpeaking];
3043 [UNIVERSE startSpeakingString:message];
3044 }
3045 }
3046 }
3047 } else {
3048 speech_settings_pressed = NO;
3049 }
3050#if OOLITE_ESPEAK
3051 if (guiSelectedRow == GUI_ROW(GAME, SPEECH_LANGUAGE)) {
3052 if ([self checkKeyPress:n_key_gui_arrow_right] || [self checkKeyPress:n_key_gui_arrow_left] || joyButtonState[BUTTON_GUIRIGHT] || joyButtonState[BUTTON_GUILEFT]) {
3053 if (!speechVoiceSelectKeyPressed || script_time > timeLastKeyPress + KEY_REPEAT_INTERVAL) {
3054 [self playChangedOption];
3055 if ([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT])
3056 voice_no = [UNIVERSE nextVoice:voice_no];
3057 else
3058 voice_no = [UNIVERSE prevVoice:voice_no];
3059 [UNIVERSE setVoice:voice_no withGenderM:voice_gender_m];
3060 NSString* voiceName = [UNIVERSE voiceName:voice_no];
3061 NSString* message = OOExpandKey(@"gameoptions-voice-name", voiceName);
3062 [gui setText:message forRow:GUI_ROW(GAME, SPEECH_LANGUAGE) align:GUI_ALIGN_CENTER];
3063 if (isSpeechOn == OOSPEECHSETTINGS_ALL) {
3064 [UNIVERSE stopSpeaking];
3065 [UNIVERSE startSpeakingString:[UNIVERSE voiceName:voice_no]];
3066 }
3067 timeLastKeyPress = script_time;
3068 }
3069 speechVoiceSelectKeyPressed = YES;
3070 } else
3071 speechVoiceSelectKeyPressed = NO;
3072 }
3073
3074 if (guiSelectedRow == GUI_ROW(GAME, SPEECH_GENDER)) {
3075 if ([self checkKeyPress:n_key_gui_arrow_right] || [self checkKeyPress:n_key_gui_arrow_left] || joyButtonState[BUTTON_GUIRIGHT] || joyButtonState[BUTTON_GUILEFT]) {
3076 if (!speechGenderSelectKeyPressed) {
3077 [self playChangedOption];
3078 BOOL m = [self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT];
3079 if (m != voice_gender_m) {
3080 voice_gender_m = m;
3081 [UNIVERSE setVoice:voice_no withGenderM:voice_gender_m];
3082 NSString* message = [NSString stringWithFormat:@"%@", DESC(voice_gender_m ? @"gameoptions-voice-M" : @"gameoptions-voice-F")];
3083 [gui setText:message forRow:GUI_ROW(GAME, SPEECH_GENDER) align:GUI_ALIGN_CENTER];
3084 if (isSpeechOn == OOSPEECHSETTINGS_ALL) {
3085 [UNIVERSE stopSpeaking];
3086 [UNIVERSE startSpeakingString:[UNIVERSE voiceName:voice_no]];
3087 }
3088 }
3089 }
3090 speechGenderSelectKeyPressed = YES;
3091 } else
3092 speechGenderSelectKeyPressed = NO;
3093 }
3094#endif
3095#endif
3096
3097 if ((guiSelectedRow == GUI_ROW(GAME, MUSIC)) && (([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]) || ([self checkKeyPress:n_key_gui_arrow_left] || joyButtonState[BUTTON_GUILEFT]))) {
3098 if (!musicModeKeyPressed) {
3100 int initialMode = [musicController mode];
3101 int mode = initialMode;
3102
3103 if ([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT])
3104 mode++;
3105 if ([self checkKeyPress:n_key_gui_arrow_left] || joyButtonState[BUTTON_GUILEFT])
3106 mode--;
3107
3108 [musicController setMode:MAX(mode, 0)];
3109
3110 if ((int)[musicController mode] != initialMode) {
3111 [self playChangedOption];
3112 NSString* musicMode = [UNIVERSE descriptionForArrayKey:@"music-mode" index:[[OOMusicController sharedController] mode]];
3113 NSString* message = OOExpandKey(@"gameoptions-music-mode", musicMode);
3114 [gui setText:message forRow:GUI_ROW(GAME, MUSIC) align:GUI_ALIGN_CENTER];
3115 }
3116 }
3117 musicModeKeyPressed = YES;
3118 } else
3120
3121 if ((guiSelectedRow == GUI_ROW(GAME, AUTOSAVE)) && (([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]) || ([self checkKeyPress:n_key_gui_arrow_left] || joyButtonState[BUTTON_GUILEFT]))) {
3122 if (([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]) != [UNIVERSE autoSave])
3123 [self playChangedOption];
3124 [UNIVERSE setAutoSave:([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT])];
3125 if ([UNIVERSE autoSave]) {
3126 // if just enabled, we want to autosave immediately
3127 [UNIVERSE setAutoSaveNow:YES];
3128 [gui setText:DESC(@"gameoptions-autosave-yes") forRow:GUI_ROW(GAME, AUTOSAVE) align:GUI_ALIGN_CENTER];
3129 } else {
3130 [UNIVERSE setAutoSaveNow:NO];
3131 [gui setText:DESC(@"gameoptions-autosave-no") forRow:GUI_ROW(GAME, AUTOSAVE) align:GUI_ALIGN_CENTER];
3132 }
3133 }
3134
3135 if ((guiSelectedRow == GUI_ROW(GAME, VOLUME))
3136 && (([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]) || ([self checkKeyPress:n_key_gui_arrow_left] || joyButtonState[BUTTON_GUILEFT]))
3137 && [OOSound respondsToSelector:@selector(masterVolume)]) {
3138 if ((!volumeControlPressed) || (script_time > timeLastKeyPress + KEY_REPEAT_INTERVAL)) {
3139 BOOL rightKeyDown = ([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]);
3140 BOOL leftKeyDown = ([self checkKeyPress:n_key_gui_arrow_left] || joyButtonState[BUTTON_GUILEFT]);
3141 double volume = 100.0 * [OOSound masterVolume];
3142 int vol = (volume / 5.0 + 0.5);
3143 if (rightKeyDown)
3144 vol++;
3145 if (leftKeyDown)
3146 vol--;
3147 vol = (int)OOClampInteger(vol, 0, 20);
3148 [OOSound setMasterVolume:0.05 * vol];
3149 [self playChangedOption];
3150#if OOLITE_ESPEAK
3151 espeak_SetParameter(espeakVOLUME, vol * 5, 0);
3152#endif
3153 if (vol > 0) {
3154 NSString* soundVolumeWordDesc = DESC(@"gameoptions-sound-volume");
3155 NSString* v1_string = @"|||||||||||||||||||||||||";
3156 NSString* v0_string = @".........................";
3157 v1_string = [v1_string substringToIndex:vol];
3158 v0_string = [v0_string substringToIndex:20 - vol];
3159 [gui setText:[NSString stringWithFormat:@"%@%@%@ ", soundVolumeWordDesc, v1_string, v0_string]
3160 forRow:GUI_ROW(GAME, VOLUME)
3161 align:GUI_ALIGN_CENTER];
3162 } else
3163 [gui setText:DESC(@"gameoptions-sound-volume-mute") forRow:GUI_ROW(GAME, VOLUME) align:GUI_ALIGN_CENTER];
3164 timeLastKeyPress = script_time;
3165 }
3167 } else
3169
3170 if ((guiSelectedRow == GUI_ROW(GAME, FOV))
3171 && (([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]) || ([self checkKeyPress:n_key_gui_arrow_left] || joyButtonState[BUTTON_GUILEFT]))) {
3172 if (!fovControlPressed || (script_time > timeLastKeyPress + KEY_REPEAT_INTERVAL)) {
3173 BOOL rightKeyDown = ([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]);
3174 BOOL leftKeyDown = ([self checkKeyPress:n_key_gui_arrow_left] || joyButtonState[BUTTON_GUILEFT]);
3175 float fov = [gameView fov:NO];
3176 float fovStep = (MAX_FOV_DEG - MIN_FOV_DEG) / 20.0f;
3177 fov += (((rightKeyDown && (fov < MAX_FOV_DEG)) ? fovStep : 0.0f) - ((leftKeyDown && (fov > MIN_FOV_DEG)) ? fovStep : 0.0f));
3178 if (fov > MAX_FOV_DEG)
3179 fov = MAX_FOV_DEG;
3180 if (fov < MIN_FOV_DEG)
3181 fov = MIN_FOV_DEG;
3182 [gameView setFov:fov fromFraction:NO];
3183 fieldOfView = [gameView fov:YES];
3184 int fovTicks = (int)((fov - MIN_FOV_DEG) / fovStep);
3185 NSString* fovWordDesc = DESC(@"gameoptions-fov-value");
3186 NSString* v1_string = @"|||||||||||||||||||||||||";
3187 NSString* v0_string = @".........................";
3188 v1_string = [v1_string substringToIndex:fovTicks];
3189 v0_string = [v0_string substringToIndex:20 - fovTicks];
3190 [gui setText:[NSString stringWithFormat:@"%@%@%@ (%d%c) ", fovWordDesc, v1_string, v0_string, (int)fov, 176 /*176 is the degrees symbol ASCII code*/] forRow:GUI_ROW(GAME, FOV) align:GUI_ALIGN_CENTER];
3191 [[NSUserDefaults standardUserDefaults] setFloat:[gameView fov:NO] forKey:@"fov-value"];
3192 timeLastKeyPress = script_time;
3193 }
3194 fovControlPressed = YES;
3195 } else
3196 fovControlPressed = NO;
3197
3198 // color blind mode
3199 if ((guiSelectedRow == GUI_ROW(GAME, COLORBLINDMODE)) && (([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]) || ([self checkKeyPress:n_key_gui_arrow_left] || joyButtonState[BUTTON_GUILEFT]))) {
3201 int colorblindMode = [UNIVERSE colorblindMode];
3202 if ([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]) {
3203 [UNIVERSE setCurrentPostFX:[UNIVERSE nextColorblindMode:colorblindMode]];
3204 } else {
3205 [UNIVERSE setCurrentPostFX:[UNIVERSE prevColorblindMode:colorblindMode]];
3206 }
3207 colorblindMode = [UNIVERSE colorblindMode]; // get the updated value
3208 NSString* colorblindModeDesc = [[[UNIVERSE descriptions] oo_arrayForKey:@"colorblind_mode"] oo_stringAtIndex:[UNIVERSE useShaders] ? colorblindMode : 0];
3209 NSString* colorblindModeMsg = OOExpandKey(@"gameoptions-colorblind-mode", colorblindModeDesc);
3210 [gui setText:colorblindModeMsg forRow:GUI_ROW(GAME, COLORBLINDMODE) align:GUI_ALIGN_CENTER];
3211 }
3213 } else
3215
3216 if (![gameView hdrOutput]) {
3217 if ((guiSelectedRow == GUI_ROW(GAME, WIREFRAMEGRAPHICS)) && (([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]) || ([self checkKeyPress:n_key_gui_arrow_left] || joyButtonState[BUTTON_GUILEFT]))) {
3218 if (([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]) != [UNIVERSE wireframeGraphics])
3219 [self playChangedOption];
3220 [UNIVERSE setWireframeGraphics:([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT])];
3221 if ([UNIVERSE wireframeGraphics])
3222 [gui setText:DESC(@"gameoptions-wireframe-graphics-yes") forRow:GUI_ROW(GAME, WIREFRAMEGRAPHICS) align:GUI_ALIGN_CENTER];
3223 else
3224 [gui setText:DESC(@"gameoptions-wireframe-graphics-no") forRow:GUI_ROW(GAME, WIREFRAMEGRAPHICS) align:GUI_ALIGN_CENTER];
3225 }
3226 }
3227#if OOLITE_WINDOWS
3228 else {
3229 if ((guiSelectedRow == GUI_ROW(GAME, HDRPAPERWHITE))
3230 && (([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]) || ([self checkKeyPress:n_key_gui_arrow_left] || joyButtonState[BUTTON_GUILEFT]))) {
3231 if (!hdrPaperWhiteControlPressed) {
3232 BOOL rightKeyDown = [self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT];
3233 BOOL leftKeyDown = [self checkKeyPress:n_key_gui_arrow_left] || joyButtonState[BUTTON_GUILEFT];
3234 float paperWhite = [gameView hdrPaperWhiteBrightness];
3235 paperWhite += (((rightKeyDown && (paperWhite < MAX_HDR_PAPERWHITE)) ? 10.0f : 0.0f) - ((leftKeyDown && (paperWhite > MIN_HDR_PAPERWHITE)) ? 10.0f : 0.0f));
3236 if (paperWhite > MAX_HDR_PAPERWHITE)
3237 paperWhite = MAX_HDR_PAPERWHITE;
3238 if (paperWhite < MIN_HDR_PAPERWHITE)
3239 paperWhite = MIN_HDR_PAPERWHITE;
3240 [gameView setHDRPaperWhiteBrightness:paperWhite];
3241 int paperWhiteNorm = (int)((paperWhite - MIN_HDR_PAPERWHITE) * 20 / (MAX_HDR_PAPERWHITE - MIN_HDR_PAPERWHITE));
3242 NSString* paperWhiteWordDesc = DESC(@"gameoptions-hdr-paperwhite");
3243 NSString* v1_string = @"|||||||||||||||||||||||||";
3244 NSString* v0_string = @".........................";
3245 v1_string = [v1_string substringToIndex:paperWhiteNorm];
3246 v0_string = [v0_string substringToIndex:20 - paperWhiteNorm];
3247 [gui setText:[NSString stringWithFormat:@"%@%@%@ (%d) ", paperWhiteWordDesc, v1_string, v0_string, (int)paperWhite] forRow:GUI_ROW(GAME, HDRPAPERWHITE) align:GUI_ALIGN_CENTER];
3248 }
3249 hdrPaperWhiteControlPressed = YES;
3250 } else
3251 hdrPaperWhiteControlPressed = NO;
3252 }
3253#endif
3254
3255#if !NEW_PLANETS
3256 if ((guiSelectedRow == GUI_ROW(GAME, PROCEDURALLYTEXTUREDPLANETS)) && (([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]) || ([self checkKeyPress:n_key_gui_arrow_left] || joyButtonState[BUTTON_GUILEFT]))) {
3257 if (([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]) != [UNIVERSE doProcedurallyTexturedPlanets]) {
3258 [UNIVERSE setDoProcedurallyTexturedPlanets:([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT])];
3259 [self playChangedOption];
3260 if ([UNIVERSE planet]) {
3261 [UNIVERSE setUpPlanet];
3262 }
3263 }
3264 if ([UNIVERSE doProcedurallyTexturedPlanets])
3265 [gui setText:DESC(@"gameoptions-procedurally-textured-planets-yes") forRow:GUI_ROW(GAME, PROCEDURALLYTEXTUREDPLANETS) align:GUI_ALIGN_CENTER];
3266 else
3267 [gui setText:DESC(@"gameoptions-procedurally-textured-planets-no") forRow:GUI_ROW(GAME, PROCEDURALLYTEXTUREDPLANETS) align:GUI_ALIGN_CENTER];
3268 }
3269#endif
3270
3271 if (guiSelectedRow == GUI_ROW(GAME, SHADEREFFECTS) && ([self checkKeyPress:n_key_gui_arrow_right] || [self checkKeyPress:n_key_gui_arrow_left] || joyButtonState[BUTTON_GUIRIGHT] || joyButtonState[BUTTON_GUILEFT])) {
3273 int direction = ([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]) ? 1 : -1;
3274
3275 /* (Getafix - 2015/05/07)
3276 Fix bug coincidentally resulting in Graphics Detail value cycling
3277 when left arrow is pressed.
3278
3279 OOGraphicsDetail is an enum type and as such it will never go
3280 negative. The following code adjusts "direction" to avoid illegal
3281 detailLevel values.
3282
3283 Perhaps a more elegant solution could be set in place, restructuring
3284 in Universe.m the logic behing setDetailLevelDirectly and
3285 setDetailLevel, not forgetting to consider Graphic Detail assigned
3286 from various sources (i.e. menu, user prefs file, javascript, etc.).
3287 This is postponed in order not to risk the recently announced
3288 plans for v1.82 release.
3289
3290 Generally we should decide whether the menu values should cycle or
3291 not and apply it for all menu entries.
3292 */
3293 if ((([UNIVERSE detailLevel] == DETAIL_LEVEL_MINIMUM) && (direction == -1)) || (([UNIVERSE detailLevel] == DETAIL_LEVEL_MAXIMUM) && (direction == 1)))
3294 direction = 0;
3295
3296 OOGraphicsDetail detailLevel = [UNIVERSE detailLevel] + direction;
3297 [UNIVERSE setDetailLevel:detailLevel];
3298 detailLevel = [UNIVERSE detailLevel];
3299
3300 NSString* shaderEffectsOptionsString = OOExpand(@"gameoptions-detaillevel-[detailLevel]", detailLevel);
3301 [gui setText:OOExpandKey(shaderEffectsOptionsString) forRow:GUI_ROW(GAME, SHADEREFFECTS) align:GUI_ALIGN_CENTER];
3302 [gui setKey:GUI_KEY_OK forRow:GUI_ROW(GAME, SHADEREFFECTS)];
3303
3304 timeLastKeyPress = script_time;
3305
3306 // changing detail level may result in changes to other settings too
3307 // (e.g. colorblind mode status), so refresh the page
3309 [gui setSelectedRow:GUI_ROW(GAME, SHADEREFFECTS)];
3310 }
3312 } else
3314
3315#if OOLITE_SDL
3316 if ((guiSelectedRow == GUI_ROW(GAME, DISPLAYSTYLE)) && selectKeyPress) {
3318 // redraw GUI
3320 }
3321#endif
3322
3323 if ((guiSelectedRow == GUI_ROW(GAME, DOCKINGCLEARANCE)) && (([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]) || ([self checkKeyPress:n_key_gui_arrow_left] || joyButtonState[BUTTON_GUILEFT]))) {
3324 if (([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]) != [UNIVERSE dockingClearanceProtocolActive])
3325 [self playChangedOption];
3326 [UNIVERSE setDockingClearanceProtocolActive:([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT])];
3327 if ([UNIVERSE dockingClearanceProtocolActive])
3328 [gui setText:DESC(@"gameoptions-docking-clearance-yes") forRow:GUI_ROW(GAME, DOCKINGCLEARANCE) align:GUI_ALIGN_CENTER];
3329 else
3330 [gui setText:DESC(@"gameoptions-docking-clearance-no") forRow:GUI_ROW(GAME, DOCKINGCLEARANCE) align:GUI_ALIGN_CENTER];
3331 }
3332
3333 if ((guiSelectedRow == GUI_ROW(GAME, BACK)) && selectKeyPress) {
3336 }
3337}
3338
3340{
3341 MyOpenGLView* gameView = [UNIVERSE gameView];
3342 GuiDisplayGen* gui = [UNIVERSE gui];
3343 const BOOL* joyButtonState = [[OOJoystickManager sharedStickHandler] getAllButtonStates];
3344
3345 [self keyMapperInputHandler:gui view:gameView];
3346 leftRightKeyPressed = [self checkKeyPress:n_key_gui_arrow_right] || [self checkKeyPress:n_key_gui_arrow_left] || [self checkKeyPress:n_key_gui_page_up] || [self checkKeyPress:n_key_gui_page_down] ||
3347 joyButtonState[BUTTON_GUIRIGHT] || joyButtonState[BUTTON_GUILEFT] || joyButtonState[BUTTON_GUIPAGEUP] || joyButtonState[BUTTON_GUIPAGEDOWN];
3348 if (leftRightKeyPressed) {
3349 NSString* key = [gui keyForRow:[gui selectedRow]];
3350 if ([self checkKeyPress:n_key_gui_arrow_right] || [self checkKeyPress:n_key_gui_page_down] || joyButtonState[BUTTON_GUIRIGHT] || joyButtonState[BUTTON_GUIPAGEDOWN]) {
3351 key = [gui keyForRow:GUI_ROW_KC_FUNCEND];
3352 }
3353 if ([self checkKeyPress:n_key_gui_arrow_left] || [self checkKeyPress:n_key_gui_page_up] || joyButtonState[BUTTON_GUILEFT] || joyButtonState[BUTTON_GUIPAGEUP]) {
3354 key = [gui keyForRow:GUI_ROW_KC_FUNCSTART];
3355 }
3356 int from_function = 0;
3357 NSArray* keyComponents = [key componentsSeparatedByString:@":"];
3358 if ([keyComponents count] > 1) {
3359 from_function = [keyComponents oo_intAtIndex:1];
3360 if (from_function < 0)
3361 from_function = 0;
3362
3363 [self setGuiToKeyMapperScreen:from_function resetCurrentRow:YES];
3364 if ([[UNIVERSE gui] selectedRow] < GUI_ROW_KC_FUNCSTART) {
3365 [[UNIVERSE gui] setSelectedRow:GUI_ROW_KC_FUNCSTART];
3366 }
3367 if (from_function == 0) {
3368 [[UNIVERSE gui] setSelectedRow:GUI_ROW_KC_FUNCSTART + MAX_ROWS_KC_FUNCTIONS - 1];
3369 }
3370 }
3371 }
3373}
3374
3376{
3377 MyOpenGLView* gameView = [UNIVERSE gameView];
3378 GuiDisplayGen* gui = [UNIVERSE gui];
3379 const BOOL* joyButtonState = [[OOJoystickManager sharedStickHandler] getAllButtonStates];
3380
3381 [self handleKeyboardLayoutEntryKeys:gui view:gameView];
3382 leftRightKeyPressed = [self checkKeyPress:n_key_gui_arrow_right] || [self checkKeyPress:n_key_gui_arrow_left] || [self checkKeyPress:n_key_gui_page_up] || [self checkKeyPress:n_key_gui_page_down]
3383 || joyButtonState[BUTTON_GUILEFT] || joyButtonState[BUTTON_GUIRIGHT] || joyButtonState[BUTTON_GUIPAGEUP] || joyButtonState[BUTTON_GUIPAGEDOWN];
3384 if (leftRightKeyPressed) {
3385 NSString* key = [gui keyForRow:[gui selectedRow]];
3386 if ([self checkKeyPress:n_key_gui_arrow_right] || [self checkKeyPress:n_key_gui_page_down]) {
3387 key = [gui keyForRow:GUI_ROW_KC_FUNCEND];
3388 }
3389 if ([self checkKeyPress:n_key_gui_arrow_left] || [self checkKeyPress:n_key_gui_page_up]) {
3390 key = [gui keyForRow:GUI_ROW_KC_FUNCSTART];
3391 }
3392 int from_function = 0;
3393 NSArray* keyComponents = [key componentsSeparatedByString:@":"];
3394 if ([keyComponents count] > 1) {
3395 from_function = [keyComponents oo_intAtIndex:1];
3396 if (from_function < 0)
3397 from_function = 0;
3398
3399 [self setGuiToKeyboardLayoutScreen:from_function resetCurrentRow:YES];
3400 if ([[UNIVERSE gui] selectedRow] < GUI_ROW_KC_FUNCSTART) {
3401 [[UNIVERSE gui] setSelectedRow:GUI_ROW_KC_FUNCSTART];
3402 }
3403 if (from_function == 0) {
3404 [[UNIVERSE gui] setSelectedRow:GUI_ROW_KC_FUNCSTART + MAX_ROWS_KC_FUNCTIONS - 1];
3405 }
3406 }
3407 }
3409}
3410
3412{
3413 MyOpenGLView* gameView = [UNIVERSE gameView];
3414 GuiDisplayGen* gui = [UNIVERSE gui];
3415 const BOOL* joyButtonState = [[OOJoystickManager sharedStickHandler] getAllButtonStates];
3416
3417 [self stickMapperInputHandler:gui view:gameView];
3418 leftRightKeyPressed = [self checkKeyPress:n_key_gui_arrow_right] || [self checkKeyPress:n_key_gui_arrow_left] || [self checkKeyPress:n_key_gui_page_up] || [self checkKeyPress:n_key_gui_page_down] ||
3419 joyButtonState[BUTTON_GUIRIGHT] || joyButtonState[BUTTON_GUILEFT] || joyButtonState[BUTTON_GUIPAGEUP] || joyButtonState[BUTTON_GUIPAGEDOWN];
3420 if (leftRightKeyPressed) {
3421 NSString* key = [gui keyForRow:[gui selectedRow]];
3422 if ([self checkKeyPress:n_key_gui_arrow_right] || [self checkKeyPress:n_key_gui_page_down] || joyButtonState[BUTTON_GUIRIGHT] || joyButtonState[BUTTON_GUIPAGEDOWN]) {
3423 key = [gui keyForRow:GUI_ROW_FUNCEND];
3424 }
3425 if ([self checkKeyPress:n_key_gui_arrow_left] || [self checkKeyPress:n_key_gui_page_up] || joyButtonState[BUTTON_GUILEFT] || joyButtonState[BUTTON_GUIPAGEUP]) {
3426 key = [gui keyForRow:GUI_ROW_FUNCSTART];
3427 }
3428 int from_function = 0;
3429 NSArray* keyComponents = [key componentsSeparatedByString:@":"];
3430 if ([keyComponents count] > 1) {
3431 from_function = [keyComponents oo_intAtIndex:1];
3432 if (from_function < 0)
3433 from_function = 0;
3434
3435 [self setGuiToStickMapperScreen:from_function resetCurrentRow:YES];
3436 if ([[UNIVERSE gui] selectedRow] < GUI_ROW_FUNCSTART) {
3437 [[UNIVERSE gui] setSelectedRow:GUI_ROW_FUNCSTART];
3438 }
3439 if (from_function == 0) {
3440 [[UNIVERSE gui] setSelectedRow:GUI_ROW_FUNCSTART + MAX_ROWS_FUNCTIONS - 1];
3441 }
3442 }
3443 }
3445 if ([gameView isDown:' '])
3447}
3448
3450{
3451 static Quaternion viewQuaternion;
3452 static Vector viewOffset;
3453 static Vector rotationCenter;
3454 static Vector up;
3455 static Vector right;
3456 static BOOL mouse_clicked = NO;
3457 static NSPoint mouse_clicked_position;
3458 static BOOL shift_down;
3459 static BOOL caps_on = NO;
3460 static NSTimeInterval last_time = 0.0;
3461 MyOpenGLView* gameView = [UNIVERSE gameView];
3462 const BOOL* joyButtonState = [[OOJoystickManager sharedStickHandler] getAllButtonStates];
3463
3464 if ([self checkKeyPress:n_key_custom_view] || joyButtonState[BUTTON_EXTVIEWCYCLE]) {
3465 if (!customView_pressed && [_customViews count] != 0 && gui_screen != GUI_SCREEN_LONG_RANGE_CHART && ![gameView allowingStringInput]) {
3466 if ([UNIVERSE viewDirection] == VIEW_CUSTOM) // already in custom view mode
3467 {
3468 // rotate the custom views
3469 _customViewIndex = (_customViewIndex + 1) % [_customViews count];
3470 }
3471
3472 [self setCustomViewDataFromDictionary:[_customViews oo_dictionaryAtIndex:_customViewIndex] withScaling:YES];
3473
3474 [self switchToThisView:VIEW_CUSTOM andProcessWeaponFacing:NO]; // weapon facing must not change, we just want an external view
3475 }
3476 customView_pressed = YES;
3477 } else
3478 customView_pressed = NO;
3479 NSTimeInterval this_time = [NSDate timeIntervalSinceReferenceDate];
3480 if ([UNIVERSE viewDirection] > VIEW_STARBOARD && [gameView isCapsLockOn]) {
3481 BOOL ctrl_down = [gameView isCtrlDown];
3482 float customViewZoomSpeed = ctrl_down ? CUSTOM_VIEW_ZOOM_SPEED * CUSTOM_VIEW_SPEED_REDUCTION_FACTOR : CUSTOM_VIEW_ZOOM_SPEED;
3483 float customViewRotateSpeed = ctrl_down ? CUSTOM_VIEW_ROTATE_SPEED * CUSTOM_VIEW_SPEED_REDUCTION_FACTOR : CUSTOM_VIEW_ROTATE_SPEED;
3484
3485 if (!caps_on)
3486 caps_on = YES;
3487
3488 OOTimeDelta delta_t = this_time - last_time;
3489 if (([self checkKeyPress:n_key_custom_view_zoom_out ignore_ctrl:YES] && ![self checkKeyPress:n_key_custom_view_zoom_in ignore_ctrl:YES]) || [gameView mouseWheelState] == gvMouseWheelDown) {
3490 [self customViewZoomOut:pow(customViewZoomSpeed, delta_t)];
3491 }
3492 if (([self checkKeyPress:n_key_custom_view_zoom_in ignore_ctrl:YES] && ![self checkKeyPress:n_key_custom_view_zoom_out ignore_ctrl:YES]) || [gameView mouseWheelState] == gvMouseWheelUp) {
3493 [self customViewZoomIn:pow(customViewZoomSpeed, delta_t)];
3494 }
3495 if ([self checkKeyPress:n_key_custom_view_roll_left ignore_ctrl:YES] && ![self checkKeyPress:n_key_custom_view_roll_right ignore_ctrl:YES]) {
3496 [self customViewRollLeft:customViewRotateSpeed * delta_t];
3497 }
3498 if ([self checkKeyPress:n_key_custom_view_pan_left ignore_ctrl:YES] && ![self checkKeyPress:n_key_custom_view_pan_right ignore_ctrl:YES]) {
3499 [self customViewPanLeft:customViewRotateSpeed * delta_t];
3500 }
3501 if ([self checkKeyPress:n_key_custom_view_roll_right ignore_ctrl:YES] && ![self checkKeyPress:n_key_custom_view_roll_left ignore_ctrl:YES]) {
3502 [self customViewRollRight:customViewRotateSpeed * delta_t];
3503 }
3504 if ([self checkKeyPress:n_key_custom_view_pan_right ignore_ctrl:YES] && ![self checkKeyPress:n_key_custom_view_pan_left ignore_ctrl:YES]) {
3505 [self customViewPanRight:customViewRotateSpeed * delta_t];
3506 }
3507 if ([self checkKeyPress:n_key_custom_view_rotate_up ignore_ctrl:YES] && ![self checkKeyPress:n_key_custom_view_rotate_down ignore_ctrl:YES]) {
3508 [self customViewRotateUp:customViewRotateSpeed * delta_t];
3509 }
3510 if ([self checkKeyPress:n_key_custom_view_pan_down ignore_ctrl:YES] && ![self checkKeyPress:n_key_custom_view_pan_up ignore_ctrl:YES]) {
3511 [self customViewPanDown:customViewRotateSpeed * delta_t];
3512 }
3513 if ([self checkKeyPress:n_key_custom_view_rotate_down ignore_ctrl:YES] && ![self checkKeyPress:n_key_custom_view_rotate_up ignore_ctrl:YES]) {
3514 [self customViewRotateDown:customViewRotateSpeed * delta_t];
3515 }
3516 if ([self checkKeyPress:n_key_custom_view_pan_up ignore_ctrl:YES] && ![self checkKeyPress:n_key_custom_view_pan_down ignore_ctrl:YES]) {
3517 [self customViewPanUp:customViewRotateSpeed * delta_t];
3518 }
3519 if ([self checkKeyPress:n_key_custom_view_rotate_left ignore_ctrl:YES] && ![self checkKeyPress:n_key_custom_view_rotate_right ignore_ctrl:YES]) {
3520 [self customViewRotateLeft:customViewRotateSpeed * delta_t];
3521 }
3522 if ([self checkKeyPress:n_key_custom_view_rotate_right ignore_ctrl:YES] && ![self checkKeyPress:n_key_custom_view_rotate_left ignore_ctrl:YES]) {
3523 [self customViewRotateRight:customViewRotateSpeed * delta_t];
3524 }
3525 if ([gameView isDown:gvMouseLeftButton]) {
3526 if (!mouse_clicked || shift_down != [gameView isShiftDown]) {
3527 mouse_clicked = YES;
3528 viewQuaternion = [PLAYER customViewQuaternion];
3529 viewOffset = [PLAYER customViewOffset];
3530 rotationCenter = [PLAYER customViewRotationCenter];
3531 up = [PLAYER customViewUpVector];
3532 right = [PLAYER customViewRightVector];
3533 mouse_clicked_position = [gameView virtualJoystickPosition];
3534 shift_down = [gameView isShiftDown];
3535 }
3536 NSPoint mouse_position = [gameView virtualJoystickPosition];
3537 Vector axis = vector_add(vector_multiply_scalar(up, mouse_position.x - mouse_clicked_position.x),
3538 vector_multiply_scalar(right, mouse_position.y - mouse_clicked_position.y));
3539 float angle = magnitude(axis);
3540 axis = vector_normal(axis);
3541 Quaternion newViewQuaternion = viewQuaternion;
3542 if ([gameView isShiftDown]) {
3543 quaternion_rotate_about_axis(&newViewQuaternion, axis, angle);
3544 [PLAYER setCustomViewQuaternion:newViewQuaternion];
3545 [PLAYER setCustomViewRotationCenter:vector_subtract(viewOffset,
3546 vector_multiply_scalar([PLAYER customViewForwardVector],
3547 dot_product([PLAYER customViewForwardVector], viewOffset)))];
3548 } else {
3549 quaternion_rotate_about_axis(&newViewQuaternion, axis, -angle);
3550 OOScalar m = magnitude(vector_subtract(viewOffset, rotationCenter));
3551 [PLAYER setCustomViewQuaternion:newViewQuaternion];
3552 Vector offset = vector_flip([PLAYER customViewForwardVector]);
3554 [PLAYER setCustomViewOffset:vector_add(offset, rotationCenter)];
3555 }
3556 } else {
3557 mouse_clicked = NO;
3558 }
3559 } else {
3560 mouse_clicked = NO;
3561 if (caps_on) {
3562 caps_on = NO;
3563 if ([self isMouseControlOn])
3565 }
3566 }
3567 last_time = this_time;
3568}
3569
3571{
3572 if (!pollControls)
3573 return;
3574
3575 MyOpenGLView* gameView = [UNIVERSE gameView];
3577
3578 NSPoint virtualView = NSZeroPoint;
3579 double view_threshold = 0.5;
3580
3581 if ([stickHandler joystickCount]) {
3582 virtualView = [stickHandler viewAxis];
3583 if (virtualView.y == STICK_AXISUNASSIGNED)
3584 virtualView.y = 0.0;
3585 if (virtualView.x == STICK_AXISUNASSIGNED)
3586 virtualView.x = 0.0;
3587 if (fabs(virtualView.y) >= fabs(virtualView.x))
3588 virtualView.x = 0.0; // forward/aft takes precedence
3589 else
3590 virtualView.y = 0.0;
3591 }
3592
3593 const BOOL* joyButtonState = [stickHandler getAllButtonStates];
3594
3595 // view keys
3596 if (([self checkKeyPress:n_key_view_forward]) || (virtualView.y < -view_threshold) || joyButtonState[BUTTON_VIEWFORWARD] || ((([self checkKeyPress:n_key_hyperspace] && gui_screen != GUI_SCREEN_LONG_RANGE_CHART) || joyButtonState[BUTTON_HYPERDRIVE]) && [UNIVERSE displayGUI])) {
3597 [self switchToThisView:VIEW_FORWARD];
3598 }
3599 if (([self checkKeyPress:n_key_view_aft]) || (virtualView.y > view_threshold) || joyButtonState[BUTTON_VIEWAFT]) {
3600 [self switchToThisView:VIEW_AFT];
3601 }
3602 if (([self checkKeyPress:n_key_view_port]) || (virtualView.x < -view_threshold) || joyButtonState[BUTTON_VIEWPORT]) {
3603 [self switchToThisView:VIEW_PORT];
3604 }
3605 if (([self checkKeyPress:n_key_view_starboard]) || (virtualView.x > view_threshold) || joyButtonState[BUTTON_VIEWSTARBOARD]) {
3606 [self switchToThisView:VIEW_STARBOARD];
3607 }
3608
3610
3611 // Zoom scanner 'z'
3612 if (([self checkKeyPress:n_key_scanner_zoom] && ([gameView allowingStringInput] == gvStringInputNo)) || joyButtonState[BUTTON_SCANNERZOOM]) // look for the 'z' key
3613 {
3614 if (!scanner_zoom_rate) {
3615 if ([hud scannerZoom] < 5.0) {
3616 if (([hud scannerZoom] > 1.0) || (!zoom_pressed))
3617 scanner_zoom_rate = SCANNER_ZOOM_RATE_UP;
3618 } else {
3619 if (!zoom_pressed) // must release and re-press zoom to zoom back down..
3620 scanner_zoom_rate = SCANNER_ZOOM_RATE_DOWN;
3621 }
3622 }
3623 zoom_pressed = YES;
3624 } else
3625 zoom_pressed = NO;
3626
3627 // Unzoom scanner 'Z'
3628 if (([self checkKeyPress:n_key_scanner_unzoom] && ([gameView allowingStringInput] == gvStringInputNo)) || joyButtonState[BUTTON_SCANNERUNZOOM]) // look for the 'Z' key
3629 {
3630 if ((!scanner_zoom_rate) && ([hud scannerZoom] > 1.0))
3631 scanner_zoom_rate = SCANNER_ZOOM_RATE_DOWN;
3632 }
3633
3634 if (EXPECT([[self hud] isCompassActive])) // only switch compass modes if there is a compass
3635 {
3636 // Compass mode '|'
3637 if ([self checkKeyPress:n_key_prev_compass_mode] || joyButtonState[BUTTON_COMPASSMODE_PREV]) // look for the '|' key
3638 {
3639 if ((!prev_compass_mode_pressed) && (compassMode != COMPASS_MODE_BASIC))
3640 [self setPrevCompassMode];
3642 } else {
3644 }
3645 // Compass mode '\'
3646 if ([self checkKeyPress:n_key_next_compass_mode] || joyButtonState[BUTTON_COMPASSMODE]) // look for the '\' key
3647 {
3648 if ((!next_compass_mode_pressed) && (compassMode != COMPASS_MODE_BASIC))
3649 [self setNextCompassMode];
3651 } else {
3653 }
3654 }
3655
3656 // ';' // Cycle active MFD
3657 if ([self checkKeyPress:n_key_cycle_next_mfd] || [self checkKeyPress:n_key_cycle_previous_mfd] || joyButtonState[BUTTON_MFDCYCLENEXT] || joyButtonState[BUTTON_MFDCYCLEPREV]) {
3658 if (!cycleMFD_pressed) {
3659 // if (![gameView isCtrlDown])
3660 if (![self checkKeyPress:n_key_cycle_previous_mfd] || joyButtonState[BUTTON_MFDCYCLEPREV]) {
3661 [self cycleNextMultiFunctionDisplay:activeMFD];
3662 } else {
3663 [self cyclePreviousMultiFunctionDisplay:activeMFD];
3664 }
3665 }
3666 cycleMFD_pressed = YES;
3667 } else {
3668 cycleMFD_pressed = NO;
3669 }
3670
3671 // ':' // Select next MFD
3672 if ([self checkKeyPress:n_key_switch_next_mfd] || [self checkKeyPress:n_key_switch_previous_mfd] || joyButtonState[BUTTON_MFDSELECTNEXT] || joyButtonState[BUTTON_MFDSELECTPREV]) {
3673 if ([[self hud] mfdCount] > 1) {
3674 if (!switchMFD_pressed) {
3675 // if (![gameView isCtrlDown])
3676 if (![self checkKeyPress:n_key_switch_previous_mfd] || joyButtonState[BUTTON_MFDSELECTPREV]) {
3678 } else {
3680 }
3681 }
3682 }
3683 switchMFD_pressed = YES;
3684 } else {
3685 switchMFD_pressed = NO;
3686 }
3687
3688 // show comms log '`'
3689 if ([self checkKeyPress:n_key_comms_log]) {
3690 [UNIVERSE showCommsLog:1.5];
3691 [hud refreshLastTransmitter];
3692 }
3693}
3694
3695- (void)pollFlightArrowKeyControls:(double)delta_t
3696{
3697 MyOpenGLView* gameView = [UNIVERSE gameView];
3699 NSUInteger numSticks = [stickHandler joystickCount];
3700 NSPoint virtualStick = NSZeroPoint;
3701 double reqYaw = 0.0;
3702
3703 /* DJS: Handle inputs on the joy roll/pitch axis.
3704 Mouse control on takes precedence over joysticks.
3705 We have to assume the player has a reason for switching mouse
3706 control on if they have a joystick - let them do it. */
3707 if (mouse_control_on) {
3708 virtualStick = [gameView virtualJoystickPosition];
3709 double sensitivity = 2.0;
3710 virtualStick.x *= sensitivity;
3711 virtualStick.y *= sensitivity;
3712 reqYaw = virtualStick.x;
3713 } else if (numSticks > 0) {
3714 virtualStick = [stickHandler rollPitchAxis];
3715 // handle roll separately (fix for BUG #17490)
3716 if (virtualStick.x == STICK_AXISUNASSIGNED) {
3717 // Not assigned - set to zero.
3718 virtualStick.x = 0;
3719 } else if (virtualStick.x != 0) {
3720 // cancel keyboard override, stick has been waggled
3721 keyboardRollOverride = NO;
3722 }
3723 // handle pitch separately (fix for BUG #17490)
3724 if (virtualStick.y == STICK_AXISUNASSIGNED) {
3725 // Not assigned - set to zero.
3726 virtualStick.y = 0;
3727 } else if (virtualStick.y != 0) {
3728 // cancel keyboard override, stick has been waggled
3729 keyboardPitchOverride = NO;
3730 }
3731 // handle yaw separately from pitch/roll
3732 reqYaw = [stickHandler getAxisState:AXIS_YAW];
3733 if (reqYaw == STICK_AXISUNASSIGNED) {
3734 // Not assigned or deadzoned - set to zero.
3735 reqYaw = 0;
3736 } else if (reqYaw != 0) {
3737 // cancel keyboard override, stick has been waggled
3738 keyboardYawOverride = NO;
3739 }
3740 }
3741
3742 double roll_dampner = ROLL_DAMPING_FACTOR * delta_t;
3743 double pitch_dampner = PITCH_DAMPING_FACTOR * delta_t;
3744 double yaw_dampner = YAW_DAMPING_FACTOR * delta_t;
3745 BOOL capsLockCustomView = [UNIVERSE viewDirection] == VIEW_CUSTOM && [gameView isCapsLockOn];
3746
3747 BOOL isCtrlDown = [gameView isCtrlDown];
3748
3749 double flightArrowKeyPrecisionFactor = [[NSUserDefaults standardUserDefaults] oo_doubleForKey:@"flight-arrow-key-precision-factor" defaultValue:0.5];
3750 if (flightArrowKeyPrecisionFactor < 0.05)
3751 flightArrowKeyPrecisionFactor = 0.05;
3752 if (flightArrowKeyPrecisionFactor > 1.0)
3753 flightArrowKeyPrecisionFactor = 1.0;
3754
3755 rolling = NO;
3756 // if we have yaw on the mouse x-axis, then allow using the keyboard roll keys
3757 if (!mouse_control_on || (mouse_control_on && mouse_x_axis_map_to_yaw)) {
3758 if ([self checkNavKeyPress:n_key_roll_left] && [self checkNavKeyPress:n_key_roll_right]) {
3759 keyboardRollOverride = YES;
3760 flightRoll = 0.0;
3761 } else if ([self checkNavKeyPress:n_key_roll_left] && !capsLockCustomView) {
3762 keyboardRollOverride = YES;
3763 if (flightRoll > 0.0)
3764 flightRoll = 0.0;
3765 [self decrease_flight_roll:isCtrlDown ? flightArrowKeyPrecisionFactor * roll_dampner * roll_delta : delta_t * roll_delta];
3766 rolling = YES;
3767 } else if ([self checkNavKeyPress:n_key_roll_right] && !capsLockCustomView) {
3768 keyboardRollOverride = YES;
3769 if (flightRoll < 0.0)
3770 flightRoll = 0.0;
3771 [self increase_flight_roll:isCtrlDown ? flightArrowKeyPrecisionFactor * roll_dampner * roll_delta : delta_t * roll_delta];
3772 rolling = YES;
3773 }
3774 }
3775 if (((mouse_control_on && !mouse_x_axis_map_to_yaw) || numSticks) && !keyboardRollOverride && !capsLockCustomView) {
3776 stick_roll = max_flight_roll * virtualStick.x;
3777 if (flightRoll < stick_roll) {
3778 [self increase_flight_roll:delta_t * roll_delta];
3779 if (flightRoll > stick_roll)
3780 flightRoll = stick_roll;
3781 }
3782 if (flightRoll > stick_roll) {
3783 [self decrease_flight_roll:delta_t * roll_delta];
3784 if (flightRoll < stick_roll)
3785 flightRoll = stick_roll;
3786 }
3787 rolling = (fabs(virtualStick.x) > 0.0);
3788 }
3789 if (!rolling) {
3790 if (flightRoll > 0.0) {
3791 if (flightRoll > roll_dampner)
3792 [self decrease_flight_roll:roll_dampner];
3793 else
3794 flightRoll = 0.0;
3795 }
3796 if (flightRoll < 0.0) {
3797 if (flightRoll < -roll_dampner)
3798 [self increase_flight_roll:roll_dampner];
3799 else
3800 flightRoll = 0.0;
3801 }
3802 }
3803
3804 pitching = NO;
3805 // we don't care about pitch keyboard overrides when mouse control is on, only when using joystick
3806 if (!mouse_control_on) {
3807 if ([self checkNavKeyPress:n_key_pitch_back] && [self checkNavKeyPress:n_key_pitch_forward]) {
3808 keyboardPitchOverride = YES;
3809 flightPitch = 0.0;
3810 } else if ([self checkNavKeyPress:n_key_pitch_back] && !capsLockCustomView) {
3811 keyboardPitchOverride = YES;
3812 if (flightPitch < 0.0)
3813 flightPitch = 0.0;
3814 [self increase_flight_pitch:isCtrlDown ? flightArrowKeyPrecisionFactor * pitch_dampner * pitch_delta : delta_t * pitch_delta];
3815 pitching = YES;
3816 } else if ([self checkNavKeyPress:n_key_pitch_forward] && !capsLockCustomView) {
3817 keyboardPitchOverride = YES;
3818 if (flightPitch > 0.0)
3819 flightPitch = 0.0;
3820 [self decrease_flight_pitch:isCtrlDown ? flightArrowKeyPrecisionFactor * pitch_dampner * pitch_delta : delta_t * pitch_delta];
3821 pitching = YES;
3822 }
3823 }
3824 if ((mouse_control_on || (numSticks && !keyboardPitchOverride)) && !capsLockCustomView) {
3825 stick_pitch = max_flight_pitch * virtualStick.y;
3826 if (flightPitch < stick_pitch) {
3827 [self increase_flight_pitch:delta_t * pitch_delta];
3828 if (flightPitch > stick_pitch)
3829 flightPitch = stick_pitch;
3830 }
3831 if (flightPitch > stick_pitch) {
3832 [self decrease_flight_pitch:delta_t * pitch_delta];
3833 if (flightPitch < stick_pitch)
3834 flightPitch = stick_pitch;
3835 }
3836 pitching = (fabs(virtualStick.y) > 0.0);
3837 }
3838 if (!pitching) {
3839 if (flightPitch > 0.0) {
3840 if (flightPitch > pitch_dampner)
3841 [self decrease_flight_pitch:pitch_dampner];
3842 else
3843 flightPitch = 0.0;
3844 }
3845 if (flightPitch < 0.0) {
3846 if (flightPitch < -pitch_dampner)
3847 [self increase_flight_pitch:pitch_dampner];
3848 else
3849 flightPitch = 0.0;
3850 }
3851 }
3852
3853 yawing = NO;
3854 // if we have roll on the mouse x-axis, then allow using the keyboard yaw keys
3855 if (!mouse_control_on || (mouse_control_on && !mouse_x_axis_map_to_yaw)) {
3856 if ([self checkNavKeyPress:n_key_yaw_left] && [self checkNavKeyPress:n_key_yaw_right]) {
3857 keyboardYawOverride = YES;
3858 flightYaw = 0.0;
3859 } else if ([self checkNavKeyPress:n_key_yaw_left] && !capsLockCustomView) {
3860 keyboardYawOverride = YES;
3861 if (flightYaw < 0.0)
3862 flightYaw = 0.0;
3863 [self increase_flight_yaw:isCtrlDown ? flightArrowKeyPrecisionFactor * yaw_dampner * yaw_delta : delta_t * yaw_delta];
3864 yawing = YES;
3865 } else if ([self checkNavKeyPress:n_key_yaw_right] && !capsLockCustomView) {
3866 keyboardYawOverride = YES;
3867 if (flightYaw > 0.0)
3868 flightYaw = 0.0;
3869 [self decrease_flight_yaw:isCtrlDown ? flightArrowKeyPrecisionFactor * yaw_dampner * yaw_delta : delta_t * yaw_delta];
3870 yawing = YES;
3871 }
3872 }
3873 if (((mouse_control_on && mouse_x_axis_map_to_yaw) || numSticks) && !keyboardYawOverride && !capsLockCustomView) {
3874 // I think yaw is handled backwards in the code,
3875 // which is why the negative sign is here.
3876 stick_yaw = max_flight_yaw * (-reqYaw);
3877 if (flightYaw < stick_yaw) {
3878 [self increase_flight_yaw:delta_t * yaw_delta];
3879 if (flightYaw > stick_yaw)
3880 flightYaw = stick_yaw;
3881 }
3882 if (flightYaw > stick_yaw) {
3883 [self decrease_flight_yaw:delta_t * yaw_delta];
3884 if (flightYaw < stick_yaw)
3885 flightYaw = stick_yaw;
3886 }
3887 yawing = (fabs(reqYaw) > 0.0);
3888 }
3889 if (!yawing) {
3890 if (flightYaw > 0.0) {
3891 if (flightYaw > yaw_dampner)
3892 [self decrease_flight_yaw:yaw_dampner];
3893 else
3894 flightYaw = 0.0;
3895 }
3896 if (flightYaw < 0.0) {
3897 if (flightYaw < -yaw_dampner)
3898 [self increase_flight_yaw:yaw_dampner];
3899 else
3900 flightYaw = 0.0;
3901 }
3902 }
3903}
3904
3909
3910- (void)pollGuiScreenControlsWithFKeyAlias:(BOOL)fKeyAlias
3911{
3912 if (!pollControls && fKeyAlias) // Still OK to run, if we don't use number keys.
3913 return;
3914
3915 GuiDisplayGen* gui = [UNIVERSE gui];
3916 MyOpenGLView* gameView = [UNIVERSE gameView];
3917 BOOL docked_okay = ([self status] == STATUS_DOCKED);
3918
3919 // text displays
3920 if ([self checkKeyPress:n_key_gui_screen_status fKey_only:!fKeyAlias]) {
3923 if (gui_screen == GUI_SCREEN_STATUS) {
3924 [self noteGUIWillChangeTo:GUI_SCREEN_MANIFEST];
3926 } else
3927 [self setGuiToStatusScreen];
3928 [self checkScript];
3929 }
3930 } else {
3932 }
3933
3934 if ([self checkKeyPress:n_key_gui_chart_screens fKey_only:!fKeyAlias]) {
3935 mouse_left_down = NO;
3939 // handles http://aegidian.org/bb/viewtopic.php?p=233189#p233189
3940 if (EXPECT_NOT([self status] == STATUS_WITCHSPACE_COUNTDOWN && gui_screen == GUI_SCREEN_SHORT_RANGE_CHART)) {
3941 // don't switch to LRC if countdown in progress
3943 } else if (gui_screen == GUI_SCREEN_SHORT_RANGE_CHART || (gui_screen == GUI_SCREEN_SYSTEM_DATA && showingLongRangeChart)) {
3944 if (target_chart_zoom != CHART_MAX_ZOOM) {
3945 saved_chart_zoom = target_chart_zoom;
3946 }
3947 target_chart_zoom = CHART_MAX_ZOOM;
3948 [self noteGUIWillChangeTo:GUI_SCREEN_LONG_RANGE_CHART];
3950 } else {
3951 if (target_chart_zoom == CHART_MAX_ZOOM) {
3952 target_chart_zoom = saved_chart_zoom;
3953 }
3954 // target_chart_centre = cursor_coordinates = [[UNIVERSE systemManager] getCoordinatesForSystem:target_system_id inGalaxy:galaxy_number];
3955 [self noteGUIWillChangeTo:GUI_SCREEN_SHORT_RANGE_CHART];
3957 }
3958 }
3959 } else {
3961 }
3962
3963 if ([self checkKeyPress:n_key_gui_system_data fKey_only:!fKeyAlias]) {
3964 if (gui_screen != GUI_SCREEN_SYSTEM_DATA) {
3965 showingLongRangeChart = (gui_screen == GUI_SCREEN_LONG_RANGE_CHART);
3966 [self noteGUIWillChangeTo:GUI_SCREEN_SYSTEM_DATA];
3968 }
3969 }
3970
3971 if ([self checkKeyPress:n_key_gui_market fKey_only:!fKeyAlias]) {
3972 if (gui_screen != GUI_SCREEN_MARKET) {
3975 [self noteGUIWillChangeTo:GUI_SCREEN_MARKET];
3976 [self setGuiToMarketScreen];
3977 } else {
3980 [self noteGUIWillChangeTo:GUI_SCREEN_MARKETINFO];
3982 }
3983 }
3984
3985 if (docked_okay) {
3986 if (([self checkKeyPress:n_key_gui_screen_options fKey_only:!fKeyAlias]) && (gui_screen != GUI_SCREEN_OPTIONS)) {
3989 }
3990
3991 if ([self checkKeyPress:n_key_gui_screen_equipship fKey_only:!fKeyAlias]) {
3993 if ([self dockedStation] == nil)
3995 OOGUIScreenID oldScreen = gui_screen;
3996
3997 if ((gui_screen == GUI_SCREEN_EQUIP_SHIP) && [[self dockedStation] hasShipyard]) {
3999 [self noteGUIWillChangeTo:GUI_SCREEN_SHIPYARD];
4001 [self setGuiToShipyardScreen:0];
4002 [gui setSelectedRow:GUI_ROW_SHIPYARD_START];
4004 } else {
4006 [self noteGUIWillChangeTo:GUI_SCREEN_EQUIP_SHIP];
4008 [self setGuiToEquipShipScreen:0];
4009 [gui setSelectedRow:GUI_ROW_EQUIPMENT_START];
4010 }
4011
4012 [self noteGUIDidChangeFrom:oldScreen to:gui_screen];
4013 }
4015 } else {
4017 }
4018
4019 if ([self checkKeyPress:n_key_gui_screen_interfaces fKey_only:!fKeyAlias]) {
4022 [self setGuiToInterfacesScreen:0];
4023 [gui setSelectedRow:GUI_ROW_INTERFACES_START];
4024 }
4026 } else {
4028 }
4029 }
4030}
4031
4032- (void)pollGameOverControls:(double)delta_t
4033{
4034 MyOpenGLView* gameView = [UNIVERSE gameView];
4035 if ([gameView isDown:32]) // look for the spacebar
4036 {
4037 if (!spacePressed) {
4038 [UNIVERSE displayMessage:@"" forCount:1.0];
4039 shot_time = INITIAL_SHOT_TIME; // forces immediate restart
4040 }
4041 spacePressed = YES;
4042 } else
4043 spacePressed = NO;
4044}
4045
4046static BOOL toggling_music;
4047static BOOL playing_music;
4049
4050- (void)pollAutopilotControls:(double)delta_t
4051{
4052 // don't do anything if we're configuring the keyboard
4053 if (gui_screen == GUI_SCREEN_KEYBOARD_ENTRY || gui_screen == GUI_SCREEN_KEYBOARD_CONFIG || gui_screen == GUI_SCREEN_KEYBOARD_LAYOUT || gui_screen == GUI_SCREEN_KEYBOARD || gui_screen == GUI_SCREEN_KEYBOARD_CONFIRMCLEAR)
4054 return;
4055
4056 const BOOL* joyButtonState = [[OOJoystickManager sharedStickHandler] getAllButtonStates];
4057
4058 // controls polled while the autopilot is active
4059 if (![[UNIVERSE gameController] isGamePaused]) {
4060 // view keys
4061 [self pollViewControls];
4062
4063 // text displays
4064 [self pollGuiScreenControls];
4065
4066 if ([UNIVERSE displayGUI])
4067 [self pollGuiArrowKeyControls:delta_t];
4068
4069 if ([self checkKeyPress:n_key_autopilot] || joyButtonState[BUTTON_DOCKCPU]
4070 || [self checkKeyPress:n_key_autodock] || joyButtonState[BUTTON_DOCKCPUFAST]) // look for the 'c' and 'C' key
4071 {
4072 if ([self hasDockingComputer] && !autopilot_key_pressed && !fast_autopilot_key_pressed) {
4073 [self disengageAutopilot];
4074 [UNIVERSE addMessage:DESC(@"autopilot-off") forCount:4.5];
4075 }
4077 if ([self checkKeyPress:n_key_autodock] || joyButtonState[BUTTON_DOCKCPUFAST]) {
4079 }
4080 } else {
4083 }
4084
4085 if (([self checkKeyPress:n_key_docking_music] || joyButtonState[BUTTON_DOCKINGMUSIC])) // look for the 's' key
4086 {
4087 if (!toggling_music) {
4089 }
4090 toggling_music = YES;
4091 } else {
4092 toggling_music = NO;
4093 }
4094 // look for the pause game, 'p' key
4095 if (([self checkKeyPress:n_key_pausebutton] || joyButtonState[BUTTON_PAUSE]) && gui_screen != GUI_SCREEN_SHORT_RANGE_CHART && gui_screen != GUI_SCREEN_MISSION && gui_screen != GUI_SCREEN_KEYBOARD_ENTRY) {
4096 if (!autopilot_pause) {
4098 if (playing_music)
4100 // normal flight controls can handle the rest.
4101 pause_pressed = NO; // pause button flag must be NO for pollflightControls to react!
4102 [self pollFlightControls:delta_t];
4103 }
4104 autopilot_pause = YES;
4105 } else {
4106 autopilot_pause = NO;
4107 }
4108 } else {
4109 // paused
4110 if ([self checkKeyPress:n_key_pausebutton] || joyButtonState[BUTTON_PAUSE]) {
4111 if (!autopilot_pause) {
4112 if (playing_music)
4114 }
4115 autopilot_pause = YES;
4116 } else {
4117 autopilot_pause = NO;
4118 }
4119 // let the normal flight controls handle paused commands.
4120 [self pollFlightControls:delta_t];
4121 }
4122}
4123
4124- (void)pollDockedControls:(double)delta_t
4125{
4126 MyOpenGLView* gameView = [UNIVERSE gameView];
4127 GameController* gameController = [UNIVERSE gameController];
4128 const BOOL* joyButtonState = [[OOJoystickManager sharedStickHandler] getAllButtonStates];
4129 NSString* exceptionContext = @"setup";
4130
4131 @try {
4132 // Pause game, 'p' key
4133 exceptionContext = @"pause key";
4134 if (([self checkKeyPress:n_key_pausebutton] || joyButtonState[BUTTON_PAUSE]) && (gui_screen != GUI_SCREEN_LONG_RANGE_CHART && gui_screen != GUI_SCREEN_REPORT && gui_screen != GUI_SCREEN_SAVE && gui_screen != GUI_SCREEN_KEYBOARD_ENTRY)) {
4135 BOOL isMissionScreenWithTextEntry = gui_screen == GUI_SCREEN_MISSION && _missionTextEntry;
4136 if (!pause_pressed) {
4137 if ([gameController isGamePaused]) {
4138 script_time = saved_script_time;
4140 if ([UNIVERSE pauseMessageVisible]) {
4141 [UNIVERSE clearPreviousMessage]; // remove the 'paused' message.
4142 }
4143 [[UNIVERSE gui] setForegroundTextureKey:@"docked_overlay"];
4145 } else {
4146 if (!isMissionScreenWithTextEntry) {
4147 saved_script_time = script_time;
4148 [[UNIVERSE messageGUI] clear];
4149
4150 [UNIVERSE pauseGame]; // 'paused' handler
4151 }
4152 }
4153 }
4154 if (!isMissionScreenWithTextEntry) {
4155 pause_pressed = YES;
4156 }
4157 } else {
4158 pause_pressed = NO;
4159 }
4160
4161 if ([gameController isGamePaused])
4162 return;
4163
4164 if (pollControls) {
4165 exceptionContext = @"undock";
4166 if ([self checkKeyPress:n_key_launch_ship]) {
4167 if (EXPECT((gui_screen != GUI_SCREEN_MISSION || _missionAllowInterrupt) && gui_screen != GUI_SCREEN_KEYBOARD_ENTRY)) {
4168 [self handleUndockControl];
4169 }
4170 }
4171 }
4172
4173 // text displays
4174 // mission screens
4175 exceptionContext = @"GUI keys";
4176 if (gui_screen == GUI_SCREEN_MISSION || gui_screen == GUI_SCREEN_KEYBOARD_ENTRY) {
4177 [self pollDemoControls:delta_t]; // don't switch away from mission screens
4178 } else {
4179 if (gui_screen != GUI_SCREEN_REPORT)
4180 [self pollGuiScreenControls]; // don't switch away from report screens
4181 }
4182
4183 [self pollGuiArrowKeyControls:delta_t];
4184 }
4185 @catch (NSException* exception) {
4186 OOLog(kOOLogException, @"***** Exception in pollDockedControls [%@]: %@ : %@", exceptionContext, [exception name], [exception reason]);
4187 }
4188}
4189
4191{
4192 // FIXME: should this not be in leaveDock:? (Note: leaveDock: is also called from script method launchFromStation and -[StationEntity becomeExplosion]) -- Ahruman 20080308
4193 [UNIVERSE setUpUniverseFromStation]; // player pre-launch
4194 if ([self dockedStation] == nil)
4196
4197 StationEntity* dockedStation = [self dockedStation];
4198 if (dockedStation == [UNIVERSE station] && [UNIVERSE autoSaveNow] && !([[UNIVERSE sun] goneNova] || [[UNIVERSE sun] willGoNova])) {
4199 [self autosavePlayer];
4200 }
4201 [self launchFromStation];
4202}
4203
4204- (void)pollDemoControls:(double)delta_t
4205{
4206 MyOpenGLView* gameView = [UNIVERSE gameView];
4207 GuiDisplayGen* gui = [UNIVERSE gui];
4208 NSUInteger end_row = 21;
4209 OOOXZManager* oxzmanager = [OOOXZManager sharedManager];
4210 const BOOL* joyButtonState = [[OOJoystickManager sharedStickHandler] getAllButtonStates];
4211
4212 switch (gui_screen) {
4213 case GUI_SCREEN_INTRO1:
4215
4216 int row_zero = 21;
4217 if (!selectPressed) {
4219 if (([gameView isDown:gvMouseDoubleClick] || [self checkKeyPress:n_key_gui_select] || joyButtonState[BUTTON_GUISELECT]) && [gui selectedRow] == 2 + row_zero) {
4221 [UNIVERSE removeDemoShips];
4223 if (![self loadPlayer]) {
4224 [self setGuiToIntroFirstGo:YES];
4225 }
4226 break;
4227 }
4228 }
4229 if (([gameView isDown:gvMouseDoubleClick] || [self checkKeyPress:n_key_gui_select] || joyButtonState[BUTTON_GUISELECT]) && [gui selectedRow] == 1 + row_zero) {
4230 missionTextRow = 0;
4231 [self setGuiToScenarioScreen:0];
4232 } else if (([gameView isDown:gvMouseDoubleClick] || [self checkKeyPress:n_key_gui_select] || joyButtonState[BUTTON_GUISELECT]) && [gui selectedRow] == 3 + row_zero) {
4233 [self setGuiToIntroFirstGo:NO];
4234 } else if (([gameView isDown:gvMouseDoubleClick] || [self checkKeyPress:n_key_gui_select] || joyButtonState[BUTTON_GUISELECT]) && [gui selectedRow] == 4 + row_zero) {
4236 } else if (([gameView isDown:gvMouseDoubleClick] || [self checkKeyPress:n_key_gui_select] || joyButtonState[BUTTON_GUISELECT]) && [gui selectedRow] == 5 + row_zero) {
4237 [self setGuiToOXZManager];
4238 } else if (([gameView isDown:gvMouseDoubleClick] || [self checkKeyPress:n_key_gui_select] || joyButtonState[BUTTON_GUISELECT]) && [gui selectedRow] == 6 + row_zero) {
4239 [[UNIVERSE gameController] exitAppWithContext:@"Exit Game selected on start screen"];
4240 } else {
4242 }
4243 }
4244 selectPressed = [self checkKeyPress:n_key_gui_select];
4245 if ([gameView isDown:gvMouseDoubleClick]) {
4247 }
4249 break;
4250
4251 case GUI_SCREEN_GAMEOPTIONS:
4253 break;
4254
4255 case GUI_SCREEN_KEYBOARD:
4256 // if ([gameView isDown:' ']) // '<space>'
4257 //{
4258 // [self setGuiToIntroFirstGo:YES];
4259 // }
4261 break;
4262
4263 case GUI_SCREEN_KEYBOARD_CONFIRMCLEAR:
4264 [self handleKeyMapperConfirmClearKeys:gui view:gameView];
4265 break;
4266
4267 case GUI_SCREEN_KEYBOARD_CONFIG:
4268 [self handleKeyConfigKeys:gui view:gameView];
4269 break;
4270
4271 case GUI_SCREEN_KEYBOARD_ENTRY:
4272 [self handleKeyConfigEntryKeys:gui view:gameView];
4273 break;
4274
4275 case GUI_SCREEN_KEYBOARD_LAYOUT:
4277 break;
4278
4279 case GUI_SCREEN_STICKMAPPER:
4281 break;
4282
4283 case GUI_SCREEN_STICKPROFILE:
4284 [self stickProfileInputHandler:gui view:gameView];
4285 break;
4286
4287 case GUI_SCREEN_SHIPLIBRARY:
4288 if ([gameView isDown:' ']) // '<space>'
4289 {
4290 // viewed from start screen, return to it
4291 [self setGuiToIntroFirstGo:YES];
4292 }
4293 if ([self checkKeyPress:n_key_gui_arrow_up] || joyButtonState[BUTTON_GUIUP]) // '<--'
4294 {
4295 if (!upDownKeyPressed)
4296 [UNIVERSE selectIntro2Previous];
4297 }
4298 if ([self checkKeyPress:n_key_gui_arrow_down] || joyButtonState[BUTTON_GUIDOWN]) // '-->'
4299 {
4300 if (!upDownKeyPressed)
4301 [UNIVERSE selectIntro2Next];
4302 }
4303 upDownKeyPressed = (([self checkKeyPress:n_key_gui_arrow_up] || joyButtonState[BUTTON_GUIUP]) || ([self checkKeyPress:n_key_gui_arrow_down] || joyButtonState[BUTTON_GUIDOWN]));
4304
4305 if ([self checkKeyPress:n_key_gui_arrow_left] || joyButtonState[BUTTON_GUILEFT]) // '<--'
4306 {
4308 [UNIVERSE selectIntro2PreviousCategory];
4309 }
4310 if ([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]) // '-->'
4311 {
4313 [UNIVERSE selectIntro2NextCategory];
4314 }
4315 leftRightKeyPressed = (([self checkKeyPress:n_key_gui_arrow_left] || joyButtonState[BUTTON_GUILEFT]) || ([self checkKeyPress:n_key_gui_arrow_right] || joyButtonState[BUTTON_GUIRIGHT]));
4316
4317 break;
4318
4319 case GUI_SCREEN_NEWGAME:
4320 if ([self handleGUIUpDownArrowKeys]) {
4321 [self showScenarioDetails];
4322 }
4323
4324 if (!pageUpDownKeyPressed) {
4325 if ([self checkKeyPress:n_key_gui_page_up] || joyButtonState[BUTTON_GUIPAGEUP]) {
4326 // find the Back <<< line, select it and press it
4327 if ([[gui keyForRow:GUI_ROW_SCENARIOS_START - 1] hasPrefix:@"__page"]) {
4328 if ([gui setSelectedRow:GUI_ROW_SCENARIOS_START - 1]) {
4329 [self startScenario];
4330 }
4331 }
4332
4333 } else if ([self checkKeyPress:n_key_gui_page_down] || joyButtonState[BUTTON_GUIPAGEDOWN]) {
4334 // find the Next >>> line, select it and press it
4335 if ([[gui keyForRow:GUI_ROW_SCENARIOS_START + GUI_MAX_ROWS_SCENARIOS] hasPrefix:@"__page"]) {
4336 if ([gui setSelectedRow:GUI_ROW_SCENARIOS_START + GUI_MAX_ROWS_SCENARIOS]) {
4337 [self startScenario];
4338 }
4339 }
4340 }
4341 }
4342 pageUpDownKeyPressed = [self checkKeyPress:n_key_gui_page_down] | [self checkKeyPress:n_key_gui_page_up] | joyButtonState[BUTTON_GUIPAGEUP] | joyButtonState[BUTTON_GUIPAGEDOWN];
4343
4344 if (!selectPressed) {
4345 if ([self checkKeyPress:n_key_gui_select] || [gameView isDown:gvMouseDoubleClick] || joyButtonState[BUTTON_GUISELECT]) // enter
4346 {
4347 if (![self startScenario]) {
4348 [UNIVERSE removeDemoShips];
4349 [self setGuiToIntroFirstGo:YES];
4350 }
4351 }
4352 }
4353 selectPressed = [self checkKeyPress:n_key_gui_select] || joyButtonState[BUTTON_GUISELECT];
4354 if ([gameView isDown:gvMouseDoubleClick] || [gameView isDown:gvMouseLeftButton]) {
4356 }
4357 break;
4358
4359 case GUI_SCREEN_OXZMANAGER:
4360 // release locks on music on this screen
4362 if (EXPECT(![oxzmanager isRestarting])) {
4363 if ([oxzmanager isAcceptingGUIInput]) {
4364 if ([oxzmanager isAcceptingTextInput]) {
4365 [gameView setStringInput:gvStringInputAll];
4367 } else {
4369 }
4370 if ([self handleGUIUpDownArrowKeys]) {
4371 // only has an effect on install/remove selection screens
4373 }
4374 if ([self checkKeyPress:n_key_gui_arrow_left] || [self checkKeyPress:n_key_gui_page_up] || joyButtonState[BUTTON_GUILEFT] || joyButtonState[BUTTON_GUIPAGEUP]) {
4375 if ((!leftRightKeyPressed)) {
4377 }
4378 } else if ([self checkKeyPress:n_key_gui_arrow_right] || [self checkKeyPress:n_key_gui_page_down] || joyButtonState[BUTTON_GUIRIGHT] || joyButtonState[BUTTON_GUIPAGEDOWN]) {
4379 if ((!leftRightKeyPressed)) {
4381 }
4382 }
4383 leftRightKeyPressed = [self checkKeyPress:n_key_gui_arrow_right] | [self checkKeyPress:n_key_gui_arrow_left] | [self checkKeyPress:n_key_gui_page_down] | [self checkKeyPress:n_key_gui_page_up] | joyButtonState[BUTTON_GUIRIGHT] | joyButtonState[BUTTON_GUILEFT] | joyButtonState[BUTTON_GUIPAGEUP] | joyButtonState[BUTTON_GUIPAGEDOWN];
4384
4385 if (!selectPressed) {
4386 if ([self checkKeyPress:n_key_gui_select] || [gameView isDown:gvMouseDoubleClick] || joyButtonState[BUTTON_GUISELECT]) // enter
4387 {
4388 if ([oxzmanager isAcceptingTextInput]) {
4390 } else {
4392 }
4393 }
4394 }
4395 selectPressed = [self checkKeyPress:n_key_gui_select] || joyButtonState[BUTTON_GUISELECT];
4396 if ([gameView isDown:gvMouseDoubleClick] || [gameView isDown:gvMouseLeftButton]) {
4398 }
4399 } // endif isAcceptingGUIInput
4400 if ([self checkKeyPress:n_key_oxzmanager_setfilter] ||
4401 [self checkKeyPress:n_key_oxzmanager_showinfo] ||
4402 [self checkKeyPress:n_key_oxzmanager_copyurl] ||
4403 [self checkKeyPress:n_key_oxzmanager_extract]) {
4404 if (!oxz_manager_pressed) {
4405 oxz_manager_pressed = YES;
4406 if ([self checkKeyPress:n_key_oxzmanager_setfilter]) {
4408 } else if ([self checkKeyPress:n_key_oxzmanager_showinfo]) {
4410 } else if ([self checkKeyPress:n_key_oxzmanager_copyurl]) {
4412 } else if ([self checkKeyPress:n_key_oxzmanager_extract]) {
4414 }
4415 }
4416 } else {
4418 }
4419 }
4420 break;
4421
4422 case GUI_SCREEN_MISSION:
4423 if ([[self hud] allowBigGui]) {
4424 end_row = 27;
4425 }
4426 if (_missionTextEntry) {
4428 if ([self checkKeyPress:n_key_gui_select] || [gameView isDown:gvMouseDoubleClick] || joyButtonState[BUTTON_GUISELECT]) // '<enter/return>' or double click
4429 {
4433
4434 [self handleMissionCallback];
4435
4436 [self checkScript];
4437 selectPressed = YES;
4438 pollControls = YES;
4439 } else {
4440 pollControls = NO;
4441 selectPressed = NO;
4443 }
4444 } else if ([[gui keyForRow:end_row] isEqual:@"spacebar"]) {
4445 if ([gameView isDown:32]) // '<space>'
4446 {
4447 if (!spacePressed) {
4449 [self handleMissionCallback];
4450 }
4451 spacePressed = YES;
4452 } else {
4453 spacePressed = NO;
4455 }
4456 } else {
4458 NSString* extraKey = @"";
4459 if (extraMissionKeys) {
4460 NSString* key = nil;
4461 foreach (key, [extraMissionKeys allKeys]) {
4462 if ([self checkKeyPress:[extraMissionKeys oo_arrayForKey:key]]) {
4463 if (!extra_key_pressed) {
4464 extraKey = [key copy];
4465 }
4466 extra_key_pressed = YES;
4467 } else
4468 extra_key_pressed = NO;
4469 }
4470 }
4471 if ([self checkKeyPress:n_key_gui_select] || [gameView isDown:gvMouseDoubleClick] || joyButtonState[BUTTON_GUISELECT] || [extraKey length] > 0) // '<enter/return>' or double click
4472 {
4473 if ([gameView isDown:gvMouseDoubleClick]) {
4474 selectPressed = NO;
4476 }
4477 if (!selectPressed) {
4478 if ([extraKey length] == 0)
4479 extraKey = @"enter";
4480 [self setMissionChoice:[gui selectedRowKey] keyPress:extraKey];
4483
4484 [self handleMissionCallback];
4485
4486 [self checkScript];
4487 }
4488 selectPressed = YES;
4489 } else {
4490 selectPressed = NO;
4492 }
4493 [extraKey release];
4494 }
4495 break;
4496
4497 // DJS: Farm off load/save screen options to LoadSave.m
4498 case GUI_SCREEN_LOAD: {
4499 NSString* commanderFile = [self commanderSelector];
4500 if (commanderFile) {
4501 // also release the demo ship here (see showShipyardModel and noteGUIDidChangeFrom)
4502 [demoShip release];
4503 demoShip = nil;
4504
4505 [self loadPlayerFromFile:commanderFile asNew:NO];
4506 }
4507 break;
4508 }
4509
4510 default:
4511 break;
4512 }
4513}
4514
4516{
4517 if (_missionAllowInterrupt) {
4518 if (gui_screen == GUI_SCREEN_MISSION && _missionTextEntry) {
4520 } else {
4521 [self pollGuiScreenControls];
4522 }
4523 if (gui_screen != GUI_SCREEN_MISSION) {
4524 if (gui_screen != GUI_SCREEN_SYSTEM_DATA) {
4525 [UNIVERSE removeDemoShips];
4526 }
4528 }
4529 }
4530}
4531
4533{
4534 [UNIVERSE removeDemoShips];
4535 [[UNIVERSE gui] clearBackground];
4536
4537 [self setGuiToMissionEndScreen]; // need this to find out if we call a new mission screen inside callback.
4538
4539 if ([self status] != STATUS_DOCKED)
4540 [self switchToThisView:VIEW_FORWARD];
4541
4542 if (_missionWithCallback) {
4543 [self doMissionCallback];
4544 }
4545
4546 if ([self status] != STATUS_DOCKED) // did we launch inside callback? / are we in flight?
4547 {
4548 // TODO: This is no longer doing anything because of an 'isDocked' check inside the function. ***** Probably remove it for 1.76
4549 [self doWorldEventUntilMissionScreen:OOJSID("missionScreenEnded")]; // no opportunity events.
4550 } else {
4551 if (gui_screen != GUI_SCREEN_MISSION) // did we call a new mission screen inside callback?
4552 {
4553 // note that this might not be the same end screen as last time...
4554 [self setGuiToMissionEndScreen]; // if not, update status screen with callback changes, if any.
4555 [self endMissionScreenAndNoteOpportunity]; // missionScreenEnded, plus opportunity events.
4556 }
4557 }
4558}
4559
4561{
4562 MyOpenGLView* gameView = [UNIVERSE gameView];
4564 if ([self status] != STATUS_DOCKED) {
4565 // this setting is only applied when not docked
4566 [self setGuiToStatusScreen];
4567 return;
4568 }
4569 switch (_missionExitScreen) {
4570 case GUI_SCREEN_MANIFEST:
4571 [self noteGUIWillChangeTo:GUI_SCREEN_MANIFEST];
4573 break;
4574 case GUI_SCREEN_EQUIP_SHIP:
4575 [self noteGUIWillChangeTo:GUI_SCREEN_EQUIP_SHIP];
4576 [self setGuiToEquipShipScreen:0];
4577 break;
4578 case GUI_SCREEN_SHIPYARD:
4579 if ([[self dockedStation] hasShipyard]) {
4580 [self noteGUIWillChangeTo:GUI_SCREEN_SHIPYARD];
4581 [self setGuiToShipyardScreen:0];
4582 [[UNIVERSE gui] setSelectedRow:GUI_ROW_SHIPYARD_START];
4584 } else {
4585 // that doesn't work here
4586 [self setGuiToStatusScreen];
4587 }
4588 break;
4589 case GUI_SCREEN_LONG_RANGE_CHART:
4591 break;
4592 case GUI_SCREEN_SHORT_RANGE_CHART:
4594 break;
4595 case GUI_SCREEN_SYSTEM_DATA:
4596 [self noteGUIWillChangeTo:GUI_SCREEN_SYSTEM_DATA];
4598 break;
4599 case GUI_SCREEN_MARKET:
4600 [self noteGUIWillChangeTo:GUI_SCREEN_MARKET];
4601 [self setGuiToMarketScreen];
4602 break;
4603 case GUI_SCREEN_MARKETINFO:
4604 [self noteGUIWillChangeTo:GUI_SCREEN_MARKETINFO];
4606 break;
4607 case GUI_SCREEN_INTERFACES:
4608 [self setGuiToInterfacesScreen:0];
4609 break;
4610 case GUI_SCREEN_STATUS:
4611 default: // invalid screen specifications
4612 [self setGuiToStatusScreen];
4613 }
4614}
4615
4616- (void)switchToThisView:(OOViewID)viewDirection
4617{
4618 [self switchToThisView:viewDirection andProcessWeaponFacing:YES];
4619}
4620
4621- (void)switchToThisView:(OOViewID)viewDirection andProcessWeaponFacing:(BOOL)processWeaponFacing
4622{
4623 [self switchToThisView:viewDirection fromView:[UNIVERSE viewDirection] andProcessWeaponFacing:processWeaponFacing justNotify:NO];
4624}
4625
4626- (void)switchToThisView:(OOViewID)viewDirection fromView:(OOViewID)oldViewDirection andProcessWeaponFacing:(BOOL)processWeaponFacing justNotify:(BOOL)justNotify
4627{
4628 if (!justNotify) {
4629 if ([UNIVERSE displayGUI])
4630 [self switchToMainView];
4631 [UNIVERSE setViewDirection:viewDirection];
4632 }
4633 if (processWeaponFacing) {
4635 switch (viewDirection) {
4636 case VIEW_FORWARD:
4637 facing = WEAPON_FACING_FORWARD;
4638 break;
4639
4640 case VIEW_AFT:
4641 facing = WEAPON_FACING_AFT;
4642 break;
4643
4644 case VIEW_PORT:
4645 facing = WEAPON_FACING_PORT;
4646 break;
4647
4648 case VIEW_STARBOARD:
4649 facing = WEAPON_FACING_STARBOARD;
4650 break;
4651
4652 default:
4653 break;
4654 }
4655
4656 if (facing != WEAPON_FACING_NONE) {
4657 currentWeaponFacing = facing;
4658 [self currentWeaponStats];
4659 } else {
4660 OOLogERR(kOOLogParameterError, @"%s called with processWeaponFacing=YES for non-main view %i.", __FUNCTION__, viewDirection);
4661 }
4662 }
4663 if ((oldViewDirection != viewDirection || viewDirection == VIEW_CUSTOM) && ![[UNIVERSE gameController] isGamePaused]) {
4664 JSContext* context = OOJSAcquireContext();
4665 ShipScriptEvent(context, self, "viewDirectionChanged", OOJSValueFromViewID(context, viewDirection), OOJSValueFromViewID(context, oldViewDirection));
4666 OOJSRelinquishContext(context);
4667 }
4668}
4669
4670// Called on c or Shift-C
4671- (void)handleAutopilotOn:(BOOL)fastDocking
4672{
4673 NSString* message = nil;
4674
4675 // Check alert condition - on red alert, abort
4676 // -- but only for fast docking
4677 if (fastDocking && ([self alertCondition] == ALERT_CONDITION_RED)) {
4679 message = OOExpandKey(@"autopilot-red-alert");
4680 goto abort;
4681 }
4682
4683 Entity* target = [self primaryTarget];
4684 // If target isn't dockable, check for nearby stations
4685 if (![target isStation]) {
4686 Universe* uni = UNIVERSE;
4687 Entity** entities = uni->sortedEntities; // grab the public sorted list
4688 int nStations = 0;
4689 unsigned i;
4690
4691 for (i = 0; i < uni->n_entities && nStations < 2; i++) {
4692 if (entities[i]->isStation && [entities[i] isKindOfClass:[StationEntity class]] && entities[i]->zero_distance <= SCANNER_MAX_RANGE2) {
4693 nStations++;
4694 target = entities[i];
4695 }
4696 }
4697 // If inside the Aegis, dock with the main station.
4698 // If we found one target, dock with it.
4699 // If outside the Aegis and we found multiple targets, abort.
4700
4701 if ([self withinStationAegis] && legalStatus <= 50) {
4702 target = [UNIVERSE station];
4703 } else if (nStations != 1) {
4704 if (nStations == 0) {
4706 message = OOExpandKey(@"autopilot-out-of-range");
4707 } else {
4709 message = OOExpandKey(@"autopilot-multiple-targets");
4710 }
4711 goto abort;
4712 }
4713 }
4714
4715 // We found a dockable, check whether we can dock with it
4716 // NSAssert([target isKindOfClass:[StationEntity class]], @"Expected entity with isStation flag set to be a station."); // no need for asserts. Tested enough already.
4717 StationEntity* ts = (StationEntity*)target;
4718 NSString* stationName = [ts displayName];
4719
4720 // If station is not transmitting docking instructions, we cannot use autopilot.
4721 if (![ts allowsAutoDocking]) {
4723 message = OOExpandKey(@"autopilot-station-does-not-allow-autodocking", stationName);
4724 }
4725 // Deny if station is hostile or player is a fugitive trying to dock at the main station.
4726 else if ((legalStatus > 50 && ts == [UNIVERSE station]) || [ts isHostileTo:self]) {
4728 message = OOExpandKey((ts == [UNIVERSE station]) ? @"autopilot-denied" : @"autopilot-target-docking-instructions-denied", stationName);
4729 }
4730 // If we're fast-docking, perform the docking logic
4731 else if (fastDocking && [ts allowsFastDocking]) {
4732 // check whether there are docks that do not accept docking - even one such dock will result in rejection
4733 NSEnumerator* subEnum = nil;
4734 DockEntity* sub = nil;
4735 for (subEnum = [ts dockSubEntityEnumerator]; (sub = [subEnum nextObject]);) {
4736 // TOO_BIG_TO_DOCK issued when docks are scripted to reject docking
4737 if ([[sub canAcceptShipForDocking:self] isEqualToString:@"TOO_BIG_TO_DOCK"]) {
4738 message = OOExpandKey((ts == [UNIVERSE station]) ? @"autopilot-denied" : @"autopilot-target-docking-instructions-denied", stationName);
4739 goto abort;
4740 }
4741 }
4742
4743 if (legalStatus > 0) {
4744 // there's a slight chance you'll be fined for your past offences when autodocking
4745 int fine_chance = ranrot_rand() & 0x03ff; // 0..1023
4746 int government = 1 + [[UNIVERSE currentSystemData] oo_intForKey:KEY_GOVERNMENT]; // 1..8
4747 if ([UNIVERSE inInterstellarSpace])
4748 government = 2; // equivalent to Feudal. I'm assuming any station in interstellar space is military. -- Ahruman 2008-05-29
4749 fine_chance /= government;
4750 if (fine_chance < legalStatus) {
4751 [self markForFines];
4752 }
4753 }
4754
4755 [self setDockingClearanceStatus:DOCKING_CLEARANCE_STATUS_GRANTED];
4756
4757 [UNIVERSE forceWitchspaceEntries];
4758 ship_clock_adjust += 1200.0; // 20 minutes penalty to enter dock
4759 ident_engaged = NO;
4760 [self safeAllMissiles];
4761 [UNIVERSE setViewDirection:VIEW_FORWARD];
4762 [self enterDock:ts];
4763 } else {
4764 // Standard docking - engage autopilot
4765 [self engageAutopilotToStation:ts];
4766 message = OOExpandKey(@"autopilot-on");
4767 }
4768
4769abort:
4770 // Clean-up code
4771 if (message != nil)
4772 [UNIVERSE addMessage:message forCount:4.5];
4773 return;
4774}
4775
4777{
4778 // Clear current target if we're already in Ident mode
4779 if (ident_engaged)
4780 [self noteLostTarget];
4781
4782 [self safeAllMissiles];
4783 ident_engaged = YES;
4784 if ([self primaryTarget] == nil) {
4785 [self playIdentOn];
4786 [UNIVERSE addMessage:OOExpandKey(@"ident-on") forCount:2.0];
4787 } else {
4788 [self playIdentLockedOn];
4790 }
4791}
4792
4794{
4795 if (![self weaponsOnline]) {
4796 [self handleButtonIdent];
4797 return;
4798 }
4799
4800 // Clear current target if we're already in Missile Targeting mode
4801 if (missile_status != MISSILE_STATUS_SAFE) {
4802 [self noteLostTarget];
4803 }
4804
4805 // Arm missile and check for missile lock
4806 missile_status = MISSILE_STATUS_ARMED;
4807 if ([missile_entity[activeMissile] isMissile]) {
4808 if ([[self primaryTarget] isShip]) {
4809 missile_status = MISSILE_STATUS_TARGET_LOCKED;
4810 [missile_entity[activeMissile] addTarget:[self primaryTarget]];
4812 [self playMissileLockedOn];
4813 } else {
4814 // if it's nil, that means it was lost earlier
4815 if ([self primaryTarget] != nil) {
4816 [self noteLostTarget];
4817 }
4818 [missile_entity[activeMissile] noteLostTarget];
4819 NSString* weaponName = [missile_entity[activeMissile] name];
4820 [UNIVERSE addMessage:OOExpandKey(@"missile-armed", weaponName) forCount:2.0];
4821 [self playMissileArmed];
4822 }
4823 } else if ([missile_entity[activeMissile] isMine]) {
4824 NSString* weaponName = [missile_entity[activeMissile] name];
4825 [UNIVERSE addMessage:OOExpandKey(@"mine-armed", weaponName) forCount:2.0];
4826 [self playMineArmed];
4827 }
4828 ident_engaged = NO;
4829}
4830
4831@end
#define SCANNER_MAX_RANGE2
Definition Entity.h:54
#define MINIMUM_GAME_TICK
#define GUI_KEY_OK
#define MAIN_GUI_PIXEL_WIDTH
#define MAIN_GUI_PIXEL_HEIGHT
NSInteger OOGUIRow
@ gvMouseWheelDown
@ gvMouseWheelUp
@ gvNumberPadKeyDivide
@ gvNumberPadKeyMultiply
@ gvMouseLeftButton
@ gvFunctionKey2
@ gvNumberPadKeyPlus
@ gvFunctionKey5
@ gvDeleteKey
@ gvArrowKeyDown
@ gvFunctionKey9
@ gvFunctionKey4
@ gvEndKey
@ gvMouseDoubleClick
@ gvHomeKey
@ gvNumberPadKeyEnter
@ gvNumberPadKeyMinus
@ gvFunctionKey11
@ gvFunctionKey8
@ gvPageDownKey
@ gvFunctionKey3
@ gvArrowKeyUp
@ gvArrowKeyRight
@ gvFunctionKey6
@ gvArrowKeyLeft
@ gvFunctionKey7
@ gvPageUpKey
@ gvFunctionKey1
#define MAX_FOV
#define MIN_FOV
#define MIN_HDR_MAXBRIGHTNESS
#define MIN_HDR_PAPERWHITE
#define MIN_FOV_DEG
#define MAX_HDR_MAXBRIGHTNESS
#define MAX_FOV_DEG
#define MAX_HDR_PAPERWHITE
@ gvStringInputAlpha
@ gvStringInputNo
OOINLINE long long OOClampInteger(long long value, long long minValue, long long maxValue) ALWAYS_INLINE_FUNC
OOINLINE jsval OOJSValueFromViewID(JSContext *context, OOViewID value)
#define gDebugFlags
#define DEBUG_ALL
@ DEBUG_COLLISIONS
Definition OODebugFlags.h:6
@ DEBUG_BOUNDING_BOXES
#define OOInitDebugSupport()
OOINLINE double OOClamp_0_max_d(double value, double max) INLINE_CONST_FUNC
OOINLINE float OOClamp_0_max_f(float value, float max) INLINE_CONST_FUNC
#define DESTROY(x)
#define EXPECT_NOT(x)
#define EXPECT(x)
OOINLINE JSContext * OOJSAcquireContext(void)
OOINLINE void OOJSRelinquishContext(JSContext *context)
#define STICK_AXISUNASSIGNED
@ BUTTON_MFDSELECTNEXT
@ BUTTON_GUILEFT
@ BUTTON_DOCKINGCLEARANCE
@ BUTTON_LAUNCHMISSILE
@ BUTTON_GUISELECT
@ BUTTON_DOCKINGMUSIC
@ BUTTON_FUELINJECT
@ BUTTON_GUIRIGHT
@ BUTTON_ENERGYBOMB
@ BUTTON_TARGETINCOMINGMISSILE
@ BUTTON_PRIMEEQUIPMENT
@ BUTTON_COMPASSMODE
@ BUTTON_ROTATECARGO
@ BUTTON_GUIPAGEDOWN
@ BUTTON_VIEWSTARBOARD
@ BUTTON_VIEWAFT
@ BUTTON_GALACTICDRIVE
@ BUTTON_MFDCYCLENEXT
@ BUTTON_MFDCYCLEPREV
@ BUTTON_ARMMISSILE
@ BUTTON_HYPERDRIVE
@ BUTTON_ACTIVATEEQUIPMENT
@ BUTTON_CLOAK
@ BUTTON_NEXTTARGET
@ BUTTON_GUIDOWN
@ BUTTON_FIRE
@ BUTTON_UNARM
@ BUTTON_CYCLEMISSILE
@ BUTTON_VIEWPORT
@ BUTTON_SNAPSHOT
@ BUTTON_DOCKCPU
@ BUTTON_HYPERSPEED
@ BUTTON_ESCAPE
@ BUTTON_JETTISON
@ BUTTON_SCANNERUNZOOM
@ BUTTON_MODEEQUIPMENT
@ BUTTON_VIEWFORWARD
@ BUTTON_WEAPONSONLINETOGGLE
@ BUTTON_EXTVIEWCYCLE
@ BUTTON_INCTHRUST
@ BUTTON_SCANNERZOOM
@ BUTTON_GUIUP
@ BUTTON_ID
@ BUTTON_ECM
@ BUTTON_COMPASSMODE_PREV
@ BUTTON_TOGGLEHUD
@ BUTTON_DOCKCPUFAST
@ BUTTON_PREVTARGET
@ BUTTON_DECTHRUST
@ BUTTON_PRIMEEQUIPMENT_PREV
@ BUTTON_PAUSE
@ BUTTON_GUIPAGEUP
@ BUTTON_MFDSELECTPREV
#define STICK_NUMBER
#define STICK_AXBUT
#define OOLogWARN(class, format,...)
Definition OOLogging.h:126
#define OOLogERR(class, format,...)
Definition OOLogging.h:125
NSString *const kOOLogException
Definition OOLogging.m:600
#define OOLog(class, format,...)
Definition OOLogging.h:84
NSString *const kOOLogParameterError
Definition OOLogging.m:596
void OOLogSetDisplayMessagesInClass(NSString *inClass, BOOL inFlag)
Definition OOLogging.m:172
GLfloat OOScalar
Definition OOMaths.h:49
BOOL OOMouseInteractionModeIsFlightMode(OOMouseInteractionMode mode)
unsigned count
return nil
void quaternion_rotate_about_axis(Quaternion *quat, Vector axis, OOScalar angle) NONNULL_FUNC
#define OOExpandKey(key,...)
#define OOExpand(string,...)
OOLongRangeChartMode
Definition OOTypes.h:45
NSString * OOCommodityType
Definition OOTypes.h:97
@ OPTIMIZED_BY_NONE
Definition OOTypes.h:32
@ OPTIMIZED_BY_JUMPS
Definition OOTypes.h:33
@ OPTIMIZED_BY_TIME
Definition OOTypes.h:34
OOGraphicsDetail
Definition OOTypes.h:208
@ DETAIL_LEVEL_MAXIMUM
Definition OOTypes.h:214
@ DETAIL_LEVEL_MINIMUM
Definition OOTypes.h:209
OOViewID
Definition OOTypes.h:39
uint64_t OOCreditsQuantity
Definition OOTypes.h:160
uint32_t OOCargoQuantity
Definition OOTypes.h:155
double OOTimeDelta
Definition OOTypes.h:193
OOWeaponFacing
Definition OOTypes.h:195
@ WEAPON_FACING_FORWARD
Definition OOTypes.h:196
@ WEAPON_FACING_NONE
Definition OOTypes.h:201
@ WEAPON_FACING_AFT
Definition OOTypes.h:197
@ WEAPON_FACING_PORT
Definition OOTypes.h:198
@ WEAPON_FACING_STARBOARD
Definition OOTypes.h:199
OOINLINE Vector vector_flip(Vector v) INLINE_CONST_FUNC
Definition OOVector.h:227
OOINLINE Vector vector_add(Vector a, Vector b) INLINE_CONST_FUNC
Definition OOVector.h:195
OOINLINE Vector vector_subtract(Vector a, Vector b) INLINE_CONST_FUNC
Definition OOVector.h:218
OOINLINE OOScalar magnitude(Vector vec) INLINE_CONST_FUNC
Definition OOVector.h:242
OOINLINE void scale_vector(Vector *outVector, OOScalar factor) ALWAYS_INLINE_FUNC NONNULL_FUNC
Definition OOVector.h:166
OOINLINE Vector vector_multiply_scalar(Vector v, OOScalar s) INLINE_CONST_FUNC
Definition OOVector.h:180
OOINLINE Vector vector_normal(Vector vec) INLINE_CONST_FUNC
Definition OOVector.h:270
#define MAX_ROWS_SHIPS_FOR_SALE
#define GUI_ROW_SHIPYARD_START
static BOOL musicModeKeyPressed
static BOOL cycleMFD_pressed
static BOOL extra_gui_key_pressed
static BOOL selectPressed
static NSPoint centre_at_mouse_click
static BOOL shaderSelectKeyPressed
static BOOL prime_equipment_pressed
static BOOL pageUpDownKeyPressed
static BOOL zoom_pressed
static BOOL ident_pressed
static BOOL switching_interface_screens
static BOOL chartInfoPressed
static BOOL next_target_pressed
static BOOL rotateCargo_pressed
static BOOL taking_snapshot
static BOOL switching_chart_screens
static BOOL upDownKeyPressed
static BOOL previous_target_pressed
static BOOL next_planet_info_pressed
static BOOL m_key_pressed
static NSTimeInterval time_last_frame
static OOWeaponFacing saved_weapon_facing
static BOOL mode_equipment_pressed
static BOOL jump_pressed
#define CUSTOM_VIEW_SPEED_REDUCTION_FACTOR
static BOOL fire_missile_pressed
static BOOL autopilot_pause
static int pressedArrow
static BOOL safety_pressed
static BOOL target_incoming_missile_pressed
static BOOL switching_equipship_screens
static BOOL galhyperspace_pressed
static int saved_gui_screen
static BOOL target_info_pressed
static BOOL wait_for_key_up
static BOOL next_missile_pressed
static BOOL weaponsOnlineToggle_pressed
static BOOL home_info_pressed
static BOOL switching_status_screens
static BOOL f_key_pressed
static BOOL hyperspace_pressed
static BOOL volumeControlPressed
static BOOL fast_autopilot_key_pressed
#define CUSTOM_VIEW_ZOOM_SPEED
static BOOL leftRightKeyPressed
static BOOL fastactivate_a_pressed
static BOOL fovControlPressed
static BOOL spacePressed
static BOOL previous_planet_info_pressed
static BOOL switchMFD_pressed
static BOOL extra_key_pressed
static BOOL hide_hud_pressed
static int saved_view_direction
static BOOL mouse_left_down
static BOOL queryPressed
static BOOL pause_pressed
#define LOAD_KEY_SETTING2(name, default_1, shift_1, mod1_1, default_2, shift_2, mod1_2)
static BOOL escapePodKey_pressed
static BOOL next_compass_mode_pressed
static BOOL activate_equipment_pressed
static BOOL disc_operation_in_progress
static BOOL oxz_manager_pressed
static BOOL pling_pressed
#define CUSTOM_VIEW_ROTATE_SPEED
static BOOL prev_compass_mode_pressed
static BOOL customView_pressed
static BOOL f9_key_pressed
static NSUInteger searchStringLength
static double saved_script_time
static BOOL colorblindModeControlPressed
static BOOL toggling_music
static NSPoint mouse_click_position
static BOOL playing_music
static BOOL fastactivate_b_pressed
static BOOL target_missile_pressed
static BOOL cursor_moving
static BOOL mouse_x_axis_map_to_yaw
static BOOL autopilot_key_pressed
static BOOL docking_clearance_request_key_pressed
static BOOL switching_resolution
static double timeLastKeyPress
#define GUI_ROW_KC_FUNCSTART
#define GUI_ROW_FUNCSTART
#define CHART_SCREEN_VERTICAL_CENTRE
#define PORT_FACING_STRING
@ MARKET_FILTER_MODE_MAX
@ MARKET_FILTER_MODE_OFF
@ OOSPEECHSETTINGS_ALL
@ OOSPEECHSETTINGS_OFF
@ OOSPEECHSETTINGS_COMMS
#define CHART_ZOOM_SHOW_LABELS
#define YAW_DAMPING_FACTOR
#define CHART_MAX_ZOOM
#define ROLL_DAMPING_FACTOR
#define MANIFEST_SCREEN_ROW_BACK
#define SCANNER_ZOOM_RATE_DOWN
#define FORWARD_FACING_STRING
#define AFT_FACING_STRING
#define KEY_REPEAT_INTERVAL
OOGUIScreenID
#define CHART_ZOOM_SPEED_FACTOR
#define MANIFEST_SCREEN_ROW_NEXT
#define GUI_ROW_INIT(GUI)
#define SCANNER_ZOOM_RATE_UP
#define GUI_ROW(GROUP, ITEM)
@ STATUS_EQUIPMENT_FIRST_ROW
@ GUI_ROW_SCENARIOS_START
@ STATUS_EQUIPMENT_MAX_ROWS
@ GUI_MAX_ROWS_SCENARIOS
@ GUI_MAX_ROWS_EQUIPMENT
@ GUI_ROW_EQUIPMENT_START
@ GUI_ROW_MARKET_START
@ GUI_ROW_MARKET_LAST
@ STATUS_EQUIPMENT_BIGGUI_EXTRA_ROWS
@ GUI_ROW_INTERFACES_START
@ GUI_MAX_ROWS_INTERFACES
#define STARBOARD_FACING_STRING
#define CUSTOMEQUIP_EQUIPKEY
#define CHART_SCROLL_AT_Y
#define PLAYER
#define CHART_SCROLL_AT_X
@ MISSILE_STATUS_TARGET_LOCKED
@ MISSILE_STATUS_ARMED
@ MISSILE_STATUS_SAFE
@ MARKET_SORTER_MODE_OFF
@ MARKET_SORTER_MODE_MAX
#define KEYCONFIG_CUSTOMEQUIP
#define PITCH_DAMPING_FACTOR
#define INITIAL_SHOT_TIME
Definition ShipEntity.h:102
OOEquipmentType * OOWeaponType
Definition ShipEntity.h:164
@ ALERT_CONDITION_RED
Definition ShipEntity.h:172
#define DEFAULT_HYPERSPACE_SPIN_TIME
Definition ShipEntity.h:72
OOWeaponType OOWeaponTypeFromEquipmentIdentifierSloppy(NSString *string) PURE_FUNC
#define SHIP_THRUST_FACTOR
Definition ShipEntity.h:46
#define ShipScriptEvent(context, ship, event,...)
#define UNIVERSE
Definition Universe.h:827
#define DESC(key)
Definition Universe.h:832
#define TIME_ACCELERATION_FACTOR_MAX
Definition Universe.h:158
#define TIME_ACCELERATION_FACTOR_MIN
Definition Universe.h:156
void setGuiToIntroFirstGo:(BOOL justCobra)
OOEntityStatus status()
Definition Entity.m:733
NSArray * displayModes()
void setGamePaused:(BOOL value)
void exitAppWithContext:(NSString *context)
void exitFullScreenMode()
void setMouseInteractionModeForFlight()
NSUInteger indexOfCurrentDisplayMode()
void pauseFullScreenModeToPerform:onTarget:(SEL selector,[onTarget] id target)
BOOL setDisplayWidth:Height:Refresh:(unsigned int d_width,[Height] unsigned int d_height,[Refresh] unsigned int d_refresh)
BOOL inFullScreenMode()
BOOL setSelectedRow:(OOGUIRow row)
void setStatusPage:(NSInteger pageNum)
NSString * selectedRowText()
void setText:forRow:align:(NSString *str,[forRow] OOGUIRow row,[align] OOGUIAlignment alignment)
OOGUIRow selectedRow
NSString * selectedRowKey()
NSString * keyForRow:(OOGUIRow row)
void setKey:forRow:(NSString *str,[forRow] OOGUIRow row)
void setHidden:(BOOL newValue)
BOOL isDown:(int key)
void grabMouseInsideGameWindow:(BOOL value)
void setFov:fromFraction:(float value,[fromFraction] BOOL fromFraction)
void toggleScreenMode()
NSMutableString * typedString
void setScreenSize:(int sizeIndex)
NSPoint virtualJoystickPosition
float fov:(BOOL inFraction)
void clearKey:(int theKey)
BOOL snapShot:(NSString *filename)
void setStringInput:(enum StringInput value)
void allowStringInput:(BOOL value)
BOOL setDebugger:(id< OODebuggerInterface > debugger)
OODebugMonitor * sharedDebugMonitor()
OOEquipmentType * equipmentTypeWithIdentifier:(NSString *identifier)
NSString * identifier()
NSDictionary * axisFunctions()
const BOOL * getAllButtonStates()
double getAxisState:(int function)
void clearStickButtonState:(int stickButton)
OOMusicController * sharedController()
void setMode:(OOMusicMode mode)
void processOptionsNext()
void processCopyUrlKey()
void processFilterKey()
void processSelection()
void showOptionsUpdate()
void processTextInput:(NSString *input)
void processOptionsPrev()
void processExtractKey()
OOOXZManager * sharedManager()
void refreshTextInput:(NSString *input)
void processShowInfoKey()
void setMasterVolume:(float fraction)
Definition OOALSound.m:61
float masterVolume()
Definition OOALSound.m:75
void setGuiToSystemDataScreen()
OOWeaponType currentWeapon()
void cycleNextMultiFunctionDisplay:(NSUInteger index)
void pollGuiArrowKeyControls:(double delta_t)
void overwriteCommanderInputHandler()
void customViewPanRight:(OOScalar angle)
void playNextEquipmentSelected()
void setNextCompassMode()
void setGuiToLongRangeChartScreen()
void setGuiToScenarioScreen:(int page)
BOOL engageAutopilotToStation:(StationEntity *stationForDocking)
void setGuiToLoadSaveScreen()
void pollAutopilotControls:(double delta_t)
void cyclePreviousMultiFunctionDisplay:(NSUInteger index)
ShipEntity * launchEscapeCapsule()
void setGuiToChartScreenFrom:(OOGUIScreenID oldScreen)
void activateSelectedInterface()
void setGuiToMarketScreen()
void setGuiToGameOptionsScreen()
void customViewRotateDown:(OOScalar angle)
BOOL checkKeyPress:(NSArray *key_def)
void setGuiToInterfacesScreen:(int skip)
void handleAutopilotOn:(BOOL fastDocking)
void pollGuiScreenControlsWithFKeyAlias:(BOOL fKeyAlias)
void setPrevCompassMode()
void pollFlightControls:(double delta_t)
NSString * screenModeStringForWidth:height:refreshRate:(unsigned inWidth,[height] unsigned inHeight,[refreshRate] float inRate)
void setGuiToStatusScreen()
void customViewPanUp:(OOScalar angle)
void customViewZoomOut:(OOScalar rate)
void activatePrimableEquipment:withMode:(NSUInteger index,[withMode] OOPrimedEquipmentMode mode)
BOOL loadPlayerFromFile:asNew:(NSString *fileToOpen,[asNew] BOOL asNew)
void setGuiToMarketInfoScreen()
OOLongRangeChartMode longRangeChartMode
void setGuiToShipyardScreen:(NSUInteger skip)
BOOL trySellingCommodity:all:(OOCommodityType type,[all] BOOL all)
StationEntity * dockedStation()
void setShowDemoShips:(BOOL value)
void targetInfoSystem()
void customViewRotateUp:(OOScalar angle)
BOOL doWorldEventUntilMissionScreen:(OOJSPropID message)
void setWeaponsOnline:(BOOL newValue)
void targetNewSystem:(int direction)
void stickMapperInputHandler:view:(GuiDisplayGen *gui,[view] MyOpenGLView *gameView)
void setDockingClearanceStatus:(OODockingClearanceStatus newValue)
void beginWitchspaceCountdown:(int spin_time)
NSUInteger eqScriptIndexForKey:(NSString *eq_key)
NSArray * applyMarketFilter:onMarket:(NSArray *goods,[onMarket] OOCommodityMarket *market)
void nextInfoSystem()
OOCreditsQuantity priceForShipKey:(NSString *key)
void setGuiToKeyboardLayoutScreen:resetCurrentRow:(unsigned skip,[resetCurrentRow] BOOL resetCurrentRow)
void customViewRollLeft:(OOScalar angle)
void pollFlightArrowKeyControls:(double delta_t)
void setInfoSystemID:moveChart:(OOSystemID sid,[moveChart] BOOL moveChart)
void noteGUIWillChangeTo:(OOGUIScreenID toScreen)
void customViewRotateRight:(OOScalar angle)
void showInformationForSelectedInterface()
int getFirstKeyCode:(NSArray *key_def)
NSString * fastEquipmentA()
void stickProfileInputHandler:view:(GuiDisplayGen *gui,[view] MyOpenGLView *gameView)
void setMissionChoice:keyPress:(NSString *newChoice,[keyPress] NSString *keyPress)
OOCommodityType dumpCargo()
void handleKeyMapperConfirmClearKeys:view:(GuiDisplayGen *gui,[view] MyOpenGLView *gameView)
NSString * commanderSelector()
void keyMapperInputHandler:view:(GuiDisplayGen *gui,[view] MyOpenGLView *gameView)
void previousInfoSystem()
void handleKeyConfigEntryKeys:view:(GuiDisplayGen *gui,[view] MyOpenGLView *gameView)
void showInformationForSelectedUpgradeWithFormatString:(NSString *extraString)
void customViewRotateLeft:(OOScalar angle)
void handleKeyboardLayoutEntryKeys:view:(GuiDisplayGen *gui,[view] MyOpenGLView *gameView)
void customViewZoomIn:(OOScalar rate)
void pollGameOverControls:(double delta_t)
void handleKeyConfigKeys:view:(GuiDisplayGen *gui,[view] MyOpenGLView *gameView)
HeadUpDisplay * hud
ShipEntity * fireMissile()
void targetNewSystem:whileTyping:(int direction, [whileTyping] BOOL whileTyping)
void setLongRangeChartMode:(OOLongRangeChartMode mode)
void selectNextMissile()
void setDockedAtMainStation()
void selectPreviousMultiFunctionDisplay()
void setGuiToShortRangeChartScreen()
NSString * fastEquipmentB()
NSPoint adjusted_chart_centre()
void playAutopilotCannotDockWithTarget()
void setGuiToStickMapperScreen:resetCurrentRow:(unsigned skip,[resetCurrentRow] BOOL resetCurrentRow)
void playDismissedMissionScreen()
void switchToThisView:fromView:andProcessWeaponFacing:justNotify:(OOViewID viewDirection,[fromView] OOViewID oldViewDirection,[andProcessWeaponFacing] BOOL processWeaponFacing,[justNotify] BOOL justNotify)
void currentWeaponStats()
void setGuiToOXZManager()
void performDockingRequest:(StationEntity *stationForDocking)
void pollDockedControls:(double delta_t)
void homeInfoSystem()
void disengageAutopilot()
void playLaserHit:offset:weaponIdentifier:(BOOL hit,[offset] Vector weaponOffset,[weaponIdentifier] NSString *weaponIdentifier)
BOOL checkKeyPress:fKey_only:ignore_ctrl:(NSArray *key_def,[fKey_only] BOOL fKey_only,[ignore_ctrl] BOOL ignore_ctrl)
void printIdentLockedOnForMissile:(BOOL missile)
void playDismissedReportScreen()
void switchToThisView:(OOViewID viewDirection)
void customViewPanDown:(OOScalar angle)
void noteGUIDidChangeFrom:to:(OOGUIScreenID fromScreen,[to] OOGUIScreenID toScreen)
void enterDock:(StationEntity *station)
void pollDemoControls:(double delta_t)
void setCustomViewDataFromDictionary:withScaling:(NSDictionary *viewDict,[withScaling] BOOL withScaling)
OOSystemID nextHopTargetSystemID()
BOOL tryBuyingCommodity:all:(OOCommodityType type,[all] BOOL all)
void customViewPanLeft:(OOScalar angle)
NSArray * applyMarketSorter:onMarket:(NSArray *goods,[onMarket] OOCommodityMarket *market)
void setGuiToKeyMapperScreen:resetCurrentRow:(unsigned skip,[resetCurrentRow] BOOL resetCurrentRow)
void showInformationForSelectedUpgrade()
void selectNextMultiFunctionDisplay()
void setGuiToEquipShipScreen:(int skip)
void customViewRollRight:(OOScalar angle)
OOCommodityMarket * localMarket()
NSArray * processKeyCode:(NSArray *key_def)
BOOL moveTargetMemoryBy:(NSInteger delta)
NSArray * currentLaserOffset()
void switchToThisView:andProcessWeaponFacing:(OOViewID viewDirection,[andProcessWeaponFacing] BOOL processWeaponFacing)
NSDictionary * dictionaryFromFilesNamed:inFolder:mergeMode:cache:(NSString *fileName,[inFolder] NSString *folderName,[mergeMode] OOResourceMergeMode mergeMode,[cache] BOOL useCache)
void doScriptEvent:(OOJSPropID message)
void noteLostTarget()
BOOL markForFines()
void decrease_flight_roll:(double delta)
void doScriptEvent:withArguments:(OOJSPropID message,[withArguments] NSArray *arguments)
void setStatus:(OOEntityStatus stat)
void decrease_flight_yaw:(double delta)
void doScriptEvent:withArgument:andArgument:(OOJSPropID message,[withArgument] id argument1,[andArgument] id argument2)
ShipEntity * shipHitByLaser()
void doScriptEvent:withArgument:(OOJSPropID message,[withArgument] id argument)
void increase_flight_yaw:(double delta)
void decrease_flight_pitch:(double delta)
void increase_flight_pitch:(double delta)
void increase_flight_roll:(double delta)
NSString * displayName
unsigned n_entities
Definition Universe.h:181
Entity * sortedEntities[UNIVERSE_MAX_ENTITIES+1]
Definition Universe.h:180
voidpf uLong offset
Definition ioapi.h:132
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
const char int mode
Definition ioapi.h:125
#define ranrot_rand()
OOScalar x
Definition OOVector.h:32
OOScalar y
Definition OOVector.h:33