248 NSString *command = [NSString stringWithFormat:@"console.setDisplayMessagesInClass(\"%@\", %@)", [msgClass escapedForJavaScriptLiteral], display ? @"true" : @"false"];
253- (IBAction)toggleThisLogMessageClassAction:sender
255 NSString *msgClass =
nil;
257 if ([sender respondsToSelector:
@selector(representedObject)])
259 msgClass = [sender representedObject];
265- (IBAction)otherLogMessageClassAction:sender
267 [NSApp runModalForWindow:logMessageClassPanel];
268 [logMessageClassPanel orderOut:self];
272- (IBAction)logMsgClassPanelEnableAction:sender
274 NSString *msgClass =
nil;
276 msgClass = [logMsgClassPanelTextField stringValue];
283- (IBAction)logMsgClassPanelDisableAction:sender
285 NSString *msgClass =
nil;
287 msgClass = [logMsgClassPanelTextField stringValue];
294- (IBAction)toggleThisDebugFlagAction:sender
296 NSUInteger tag, bits;
297 NSString *command =
nil;
305 command = [NSString stringWithFormat:@"console.debugFlags |= 0x%lX", tag];
310 command = [NSString stringWithFormat:@"console.debugFlags &= ~0x%.lX", tag];
317- (IBAction) setShaderModeToTag:(NSMenuItem *)sender
320 NSString *detailString = [OOStringFromGraphicsDetail(detail) escapedForJavaScriptLiteral];
321 NSString *command = [NSString stringWithFormat:@"console.detailLevel = \"%@\"", detailString];
327- (IBAction)showLogPreferencesAction:sender
329 [logShowFunctionCheckBox setState:OOLogShowFunction()];
330 [logShowFileAndLineCheckBox setState:OOLogShowFileAndLine()];
331 [logShowMessageClassCheckBox setState:OOLogShowMessageClass()];
332 [logShowTimeStampCheckBox setState:OOLogShowTime()];
334 [logPrefsWindow makeKeyAndOrderFront:self];
338- (IBAction)logSetShowFunctionAction:sender
344- (IBAction)logSetShowFileAndLineAction:sender
350- (IBAction)logSetShowMessageClassAction:sender
356- (IBAction) logSetShowTimeStampAction:sender
362- (IBAction)insertLogSeparatorAction:sender
368- (IBAction)createShipPanelOKAction:sender
370 NSString *shipRole =
nil;
372 shipRole = [createShipPanelTextField stringValue];
373 if ([shipRole length] != 0)
375 [
self performSelector:@selector(spawnShip:) withObject:shipRole afterDelay:0.1];
376 [[NSUserDefaults standardUserDefaults] setObject:shipRole forKey:@"debug-create-ship-panel-last-role"];
383- (void)spawnShip:(NSString *)shipRole
385 NSString *command =
nil;
387 if (shipRole ==
nil)
return;
391 command = [NSString stringWithFormat:@"this.T = system.addShips('%@', 1, player.ship.position, 10000); if (this.T) this.T = this.T[0]; else consoleMessage('command-error', 'Could not spawn \"%@\".');", [shipRole escapedForJavaScriptLiteral], [shipRole escapedForJavaScriptLiteral]];
396 [UNIVERSE addShipWithRole:shipRole nearRouteOneAt:1.0];
401- (IBAction)modalPanelCancelAction:sender
409- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
412 NSString *msgClass =
nil;
413 NSUInteger tag, bits;
416 action = [menuItem action];
418 if (action ==
@selector(toggleThisLogMessageClassAction:))
420 msgClass = [menuItem representedObject];
421 [menuItem setState:OOLogWillDisplayMessagesInClass(msgClass)];
424 if (action ==
@selector(toggleThisDebugFlagAction:))
426 tag = [menuItem tag];
428 if (bits == 0) state = NSOffState;
429 else if (bits == tag) state = NSOnState;
430 else state = NSMixedState;
432 [menuItem setState:state];
435 if (action ==
@selector(toggleWireframeModeAction:))
437 [menuItem setState:!![UNIVERSE wireframeGraphics]];
440 if (action ==
@selector(inspectTarget:))
444 if (action ==
@selector(hideShowHUD:))
447 [menuItem setTitle:hidden ? @"Show HUD" : @"Hide HUD"];
450 if (action ==
@selector(setShaderModeToTag:))
454 menuItem.state = (
UNIVERSE.detailLevel == itemLevel);
458 return [
self respondsToSelector:action];
464 NSMenuItem *item =
nil;
467 [menu setTitle:@"Debug"];
468 item = [[NSMenuItem alloc] initWithTitle:@"Debug" action:NULL keyEquivalent:@""];
469 [item setSubmenu:menu];
470 [[NSApp mainMenu] addItem:item];
473 if (![[NSUserDefaults standardUserDefaults] boolForKey:
@"debug-show-extra-menu-items"])
480 index = [menu indexOfItemWithTag:-42];
483 [menu removeItemAtIndex:index];
484 index = [menu indexOfItemWithTag:-42];
492 NSArray *definitions =
nil;
493 NSUInteger i,
count, inserted = 0;
494 NSString *title =
nil, *key =
nil;
495 NSMenuItem *item =
nil;
498 count = [definitions count] / 2;
500 for (i = 0; i !=
count; ++i)
502 title = [definitions oo_stringAtIndex:i * 2];
503 key = [definitions oo_stringAtIndex:i * 2 + 1];
504 if (title ==
nil || key ==
nil)
continue;
506 item = [[NSMenuItem alloc] initWithTitle:title
507 action:@selector(toggleThisLogMessageClassAction:)
509 [item setTarget:self];
510 [item setRepresentedObject:key];
512 [logMessageClassSubMenu insertItem:item atIndex:inserted++];
520@implementation OODebugController (Singleton)
527+ (id)allocWithZone:(NSZone *)inZone