Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
StickProfileScreen Class Reference

#include <PlayerEntityStickProfile.h>

+ Inheritance diagram for StickProfileScreen:
+ Collaboration diagram for StickProfileScreen:

Instance Methods

(id) - init
 
(void) - dealloc
 
(void) - startGui:
 
(void) - mouseDown:
 
(void) - mouseUp
 
(void) - deleteSelected
 
(void) - showScreen [implementation]
 
(void) - nextAxis [implementation]
 
(NSString *) - currentAxis [implementation]
 
(void) - previousAxis [implementation]
 
(void) - increaseDeadzone [implementation]
 
(void) - decreaseDeadzone [implementation]
 
(void) - nextProfileType [implementation]
 
(void) - previousProfileType [implementation]
 
(void) - IncreasePower [implementation]
 
(BOOL) - currentProfileIsSpline [implementation]
 
(void) - DecreasePower [implementation]
 
(void) - IncreaseParam [implementation]
 
(void) - DecreaseParam [implementation]
 
(void) - saveSettings [implementation]
 
(void) - graphProfile:at:size: [implementation]
 
(void) - startEdit [implementation]
 
(NSString *) - profileType [implementation]
 

Private Attributes

OOJoystickManagerstickHandler
 
NSUInteger current_axis
 
OOJoystickAxisProfileprofiles [3][2]
 
GuiDisplayGengui
 
NSRect graphRect
 
NSInteger selected_control_point
 
NSInteger dragged_control_point
 
NSInteger double_click_control_point
 

Detailed Description

Definition at line 41 of file PlayerEntityStickProfile.h.

Method Documentation

◆ currentAxis

- (NSString *) currentAxis
implementation

Provided by category StickProfileScreen(StickProfileInternal).

Definition at line 43 of file PlayerEntityStickProfile.m.

360{
361 switch (current_axis)
362 {
363 case AXIS_ROLL:
364 return DESC(@"stickmapper-roll");
365
366 case AXIS_PITCH:
367 return DESC(@"stickmapper-pitch");
368
369 case AXIS_YAW:
370 return DESC(@"stickmapper-yaw");
371 }
372 return @"";
373}
@ AXIS_PITCH
@ AXIS_YAW
@ AXIS_ROLL
#define DESC(key)
Definition Universe.h:839

◆ currentProfileIsSpline

- (BOOL) currentProfileIsSpline
implementation

Provided by category StickProfileScreen(StickProfileInternal).

Definition at line 43 of file PlayerEntityStickProfile.m.

442{
443 if ([[stickHandler getProfileForAxis: current_axis] isKindOfClass: [OOJoystickSplineAxisProfile class]])
444 {
445 return YES;
446 }
447 return NO;
448}

◆ dealloc

- (void) dealloc

Definition at line 43 of file PlayerEntityStickProfile.m.

256{
257 int i, j;
258 for (i = 0; i < 3; i++)
259 {
260 for (j = 0; j < 2; j++)
261 {
262 [profiles[i][j] release];
263 }
264 }
265 [super dealloc];
266}

◆ decreaseDeadzone

- (void) decreaseDeadzone
implementation

Provided by category StickProfileScreen(StickProfileInternal).

Definition at line 43 of file PlayerEntityStickProfile.m.

387{
388 OOJoystickAxisProfile *profile = [stickHandler getProfileForAxis: current_axis];
389 if (profile)
390 {
391 [profile setDeadzone: [profile deadzone] - STICK_MAX_DEADZONE / 20];
392 }
393 [self showScreen];
394 return;
395}
void setDeadzone:(double newValue)

◆ DecreaseParam

- (void) DecreaseParam
implementation

Provided by category StickProfileScreen(StickProfileInternal).

Definition at line 43 of file PlayerEntityStickProfile.m.

496{
497 OOJoystickAxisProfile *profile = [stickHandler getProfileForAxis: current_axis];
498 OOJoystickStandardAxisProfile *standard_profile;
499
500 if (profile && [profile isKindOfClass: [OOJoystickStandardAxisProfile class]])
501 {
502 standard_profile = (OOJoystickStandardAxisProfile *) profile;
503 [standard_profile setParameter: [standard_profile parameter] - 0.05];
504 [stickHandler saveStickSettings];
505 }
506 [self showScreen];
507 return;
508}
void setParameter:(double newValue)

◆ DecreasePower

- (void) DecreasePower
implementation

Provided by category StickProfileScreen(StickProfileInternal).

Definition at line 43 of file PlayerEntityStickProfile.m.

466{
467 OOJoystickAxisProfile *profile = [stickHandler getProfileForAxis: current_axis];
468 OOJoystickStandardAxisProfile *standard_profile;
469
470 if (profile && [profile isKindOfClass: [OOJoystickStandardAxisProfile class]])
471 {
472 standard_profile = (OOJoystickStandardAxisProfile *) profile;
473 [standard_profile setPower: [standard_profile power] - STICKPROFILE_MAX_POWER / 20];
474 [stickHandler saveStickSettings];
475 }
476 [self showScreen];
477 return;
478}

◆ deleteSelected

- (void) deleteSelected

Definition at line 43 of file PlayerEntityStickProfile.m.

319{
320 OOJoystickAxisProfile *profile = [stickHandler getProfileForAxis: current_axis];
321 OOJoystickSplineAxisProfile *spline_profile;
322 if ([profile isKindOfClass: [OOJoystickSplineAxisProfile class]] && selected_control_point >= 0)
323 {
324 spline_profile = (OOJoystickSplineAxisProfile *)profile;
325 [spline_profile removeControl: selected_control_point];
328 [stickHandler saveStickSettings];
329 }
330 return;
331}
void removeControl:(NSInteger index)

◆ graphProfile:at:size:

- (void) graphProfile: (GLfloat) alpha
at: (Vector) at
size: (NSSize) size 
implementation

Provided by category StickProfileScreen(StickProfileInternal).

Definition at line 43 of file PlayerEntityStickProfile.m.

510 : (GLfloat) alpha at: (Vector) at size: (NSSize) size
511{
512 OOJoystickAxisProfile *profile = [stickHandler getProfileForAxis: current_axis];
513 OOJoystickSplineAxisProfile *spline_profile;
514 NSInteger i;
515 NSPoint point;
516 NSArray *control_points;
517
518 if (!profile) return;
519 graphRect = NSMakeRect(at.x, at.y, size.width, size.height);
521 OOGL(glColor4f(0.2,0.2,0.5,alpha));
522 OOGLBEGIN(GL_QUADS);
523 glVertex3f(at.x,at.y,at.z);
524 glVertex3f(at.x + size.width,at.y,at.z);
525 glVertex3f(at.x + size.width,at.y + size.height,at.z);
526 glVertex3f(at.x,at.y + size.height,at.z);
527 OOGLEND();
528 OOGL(glColor4f(0.9,0.9,0.9,alpha));
529 OOGL(GLScaledLineWidth(2.0f));
530 OOGLBEGIN(GL_LINE_STRIP);
531 for (i = 0; i <= size.width - 20; i++)
532 {
533 glVertex3f(at.x+i+10,at.y+10+(size.height-20)*[profile rawValue:((float)i)/(size.width-20)],at.z);
534 }
535 OOGLEND();
536 OOGL(glColor4f(0.5,0.0,0.5,alpha));
537 GLDrawFilledOval(at.x+10,at.y+10,at.z,NSMakeSize(4,4),20);
538 GLDrawFilledOval(at.x+size.width-10,at.y+size.height-10,at.z,NSMakeSize(4,4),20);
539 if ([profile isKindOfClass: [OOJoystickSplineAxisProfile class]])
540 {
541 spline_profile = (OOJoystickSplineAxisProfile *)profile;
542 control_points = [spline_profile controlPoints];
543 for (i = 0; i < (NSInteger)[control_points count]; i++)
544 {
545 if (i == selected_control_point)
546 {
547 OOGL(glColor4f(1.0,0.0,0.0,alpha));
548 }
549 else
550 {
551 OOGL(glColor4f(0.0,1.0,0.0,alpha));
552 }
553 point = [[control_points objectAtIndex: i] pointValue];
554 GLDrawFilledOval(at.x+10+point.x*(size.width - 20),at.y+10+point.y*(size.height-20),at.z,NSMakeSize(4,4),20);
555 }
556 }
557 OOGL(glColor4f(0.9,0.9,0.0,alpha));
558 OODrawStringAligned(DESC(@"oolite-stickprofile-movement"), at.x + size.width - 5, at.y, at.z, NSMakeSize(8,10), YES);
559 OODrawString(DESC(@"oolite-stickprofile-response"), at.x, at.y + size.height - 10, at.z, NSMakeSize(8,10));
560 return;
561}
void OODrawStringAligned(NSString *text, GLfloat x, GLfloat y, GLfloat z, NSSize siz, BOOL rightAlign)
void OODrawString(NSString *text, GLfloat x, GLfloat y, GLfloat z, NSSize siz)
#define OO_ENTER_OPENGL()
#define OOGLBEGIN
Definition OOOpenGL.h:253
void GLDrawFilledOval(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat step)
Definition OOOpenGL.m:165
void GLScaledLineWidth(GLfloat width)
Definition OOOpenGL.m:218
#define OOGL(statement)
Definition OOOpenGL.h:251
#define OOGLEND
Definition OOOpenGL.h:254
voidpf void uLong size
Definition ioapi.h:134

◆ increaseDeadzone

- (void) increaseDeadzone
implementation

Provided by category StickProfileScreen(StickProfileInternal).

Definition at line 43 of file PlayerEntityStickProfile.m.

376{
377 OOJoystickAxisProfile *profile = [stickHandler getProfileForAxis: current_axis];
378 if (profile)
379 {
380 [profile setDeadzone: [profile deadzone] + STICK_MAX_DEADZONE / 20];
381 }
382 [self showScreen];
383 return;
384}

◆ IncreaseParam

- (void) IncreaseParam
implementation

Provided by category StickProfileScreen(StickProfileInternal).

Definition at line 43 of file PlayerEntityStickProfile.m.

481{
482 OOJoystickAxisProfile *profile = [stickHandler getProfileForAxis: current_axis];
483 OOJoystickStandardAxisProfile *standard_profile;
484
485 if (profile && [profile isKindOfClass: [OOJoystickStandardAxisProfile class]])
486 {
487 standard_profile = (OOJoystickStandardAxisProfile *) profile;
488 [standard_profile setParameter: [standard_profile parameter] + 0.05];
489 [stickHandler saveStickSettings];
490 }
491 [self showScreen];
492 return;
493}

◆ IncreasePower

- (void) IncreasePower
implementation

Provided by category StickProfileScreen(StickProfileInternal).

Definition at line 43 of file PlayerEntityStickProfile.m.

451{
452 OOJoystickAxisProfile *profile = [stickHandler getProfileForAxis: current_axis];
453 OOJoystickStandardAxisProfile *standard_profile;
454
455 if (profile && [profile isKindOfClass: [OOJoystickStandardAxisProfile class]])
456 {
457 standard_profile = (OOJoystickStandardAxisProfile *) profile;
458 [standard_profile setPower: [standard_profile power] + STICKPROFILE_MAX_POWER / 20];
459 [stickHandler saveStickSettings];
460 }
461 [self showScreen];
462 return;
463}

◆ init

- (id) init

Definition at line 43 of file PlayerEntityStickProfile.m.

237{
238 int i, j;
239
240 if ((self = [super init]))
241 {
244 for (i = 0; i < 3; i++)
245 {
246 for (j = 0; j < 2; j++)
247 {
248 profiles[i][j] = nil;
249 }
250 }
251 }
252 return self;
253}
return nil
OOJoystickAxisProfile * profiles[3][2]
OOJoystickManager * stickHandler

◆ mouseDown:

- (void) mouseDown: (NSPoint) position

Definition at line 43 of file PlayerEntityStickProfile.m.

278 : (NSPoint) position
279{
280 OOJoystickAxisProfile *profile = [stickHandler getProfileForAxis: current_axis];
281 OOJoystickSplineAxisProfile *spline_profile;
282 NSPoint spline_position;
283
284 if (![profile isKindOfClass: [OOJoystickSplineAxisProfile class]])
285 {
286 return;
287 }
288 spline_profile = (OOJoystickSplineAxisProfile *)profile;
289 spline_position.x = (position.x - graphRect.origin.x - 10) / (graphRect.size.width - 20);
290 spline_position.y = (-position.y - graphRect.origin.y - 10) / (graphRect.size.height - 20);
291 if (spline_position.x >= 0.0 && spline_position.x <= 1.0 && spline_position.y >= 0.0 && spline_position.y <= 1.0)
292 {
293 if (dragged_control_point < 0)
294 {
295 selected_control_point = [spline_profile addControl: spline_position];
296 dragged_control_point = selected_control_point;
297 double_click_control_point = -1;
298 }
299 else
300 {
301 [spline_profile moveControl: dragged_control_point point: spline_position];
302 }
303 [stickHandler saveStickSettings];
304 }
305 return;
306}
float y
float x
voidpf uLong int origin
Definition ioapi.h:140

◆ mouseUp

- (void) mouseUp

Definition at line 43 of file PlayerEntityStickProfile.m.

309{
310 if (selected_control_point >= 0)
311 {
313 }
315 return;
316}

◆ nextAxis

- (void) nextAxis
implementation

Provided by category StickProfileScreen(StickProfileInternal).

Definition at line 43 of file PlayerEntityStickProfile.m.

340{
341 if (current_axis == AXIS_ROLL)
342 current_axis = AXIS_PITCH;
343 else if (current_axis == AXIS_PITCH)
344 current_axis = AXIS_YAW;
345 [self showScreen];
346 return;
347}

◆ nextProfileType

- (void) nextProfileType
implementation

Provided by category StickProfileScreen(StickProfileInternal).

Definition at line 43 of file PlayerEntityStickProfile.m.

398{
399 OOJoystickAxisProfile *profile = [stickHandler getProfileForAxis: current_axis];
400 double deadzone;
401
402 if ([profile isKindOfClass: [OOJoystickStandardAxisProfile class]])
403 {
404 deadzone = [profile deadzone];
405 [profiles[current_axis][0] release];
406 profiles[current_axis][0] = [profile retain];
407 if (!profiles[current_axis][1])
408 {
409 profiles[current_axis][1] = [[OOJoystickSplineAxisProfile alloc] init];
410 }
411 [profiles[current_axis][1] setDeadzone: deadzone];
412 [stickHandler setProfile: profiles[current_axis][1] forAxis: current_axis];
413 [stickHandler saveStickSettings];
414 }
415 [self showScreen];
416 return;
417}

◆ previousAxis

- (void) previousAxis
implementation

Provided by category StickProfileScreen(StickProfileInternal).

Definition at line 43 of file PlayerEntityStickProfile.m.

350{
351 if (current_axis == AXIS_PITCH)
352 current_axis = AXIS_ROLL;
353 else if (current_axis == AXIS_YAW)
354 current_axis = AXIS_PITCH;
355 [self showScreen];
356 return;
357}

◆ previousProfileType

- (void) previousProfileType
implementation

Provided by category StickProfileScreen(StickProfileInternal).

Definition at line 43 of file PlayerEntityStickProfile.m.

420{
421 OOJoystickAxisProfile *profile = [stickHandler getProfileForAxis: current_axis];
422 double deadzone;
423
424 if ([profile isKindOfClass: [OOJoystickSplineAxisProfile class]])
425 {
426 deadzone = [profile deadzone];
427 [profiles[current_axis][1] release];
428 profiles[current_axis][1] = [profile retain];
429 if (!profiles[current_axis][0])
430 {
431 profiles[current_axis][0] = [[OOJoystickStandardAxisProfile alloc] init];
432 }
433 [profiles[current_axis][0] setDeadzone: deadzone];
434 [stickHandler setProfile: profiles[current_axis][0] forAxis: current_axis];
435 [stickHandler saveStickSettings];
436 }
437 [self showScreen];
438 return;
439}

◆ profileType

- (NSString *) profileType
implementation

Provided by category StickProfileScreen(StickProfileInternal).

Definition at line 43 of file PlayerEntityStickProfile.m.

657{
658 OOJoystickAxisProfile *profile = [stickHandler getProfileForAxis: current_axis];
659
660 if ([profile isKindOfClass: [OOJoystickStandardAxisProfile class]])
661 {
662 return DESC(@"oolite-stickprofile-type-standard");
663 }
664 if ([profile isKindOfClass: [OOJoystickSplineAxisProfile class]])
665 {
666 return DESC(@"oolite-stickprofile-type-spline");
667 }
668 return DESC(@"oolite-stickprofile-type-standard");
669}

◆ saveSettings

- (void) saveSettings
implementation

Provided by category StickProfileScreen(StickProfileInternal).

Definition at line 43 of file PlayerEntityStickProfile.m.

583{
584 [stickHandler saveStickSettings];
585 return;
586}

◆ showScreen

- (void) showScreen
implementation

Provided by category StickProfileScreen(StickProfileInternal).

Definition at line 43 of file PlayerEntityStickProfile.m.

589{
590 OOJoystickAxisProfile *profile = [stickHandler getProfileForAxis: current_axis];
591 OOJoystickStandardAxisProfile *standard_profile;
592 NSString *v1 = @"||||||||||||||||||||";
593 NSString *v2 = @"....................";
594 int bars;
595 double value;
596 double power;
597
598 OOGUITabStop tabStop[GUI_MAX_COLUMNS];
599 tabStop[0] = 50;
600 tabStop[1] = 140;
601 [gui setTabStops:tabStop];
602 [gui setArray: [NSArray arrayWithObjects: DESC(@"oolite-stickprofile-axis"), [self currentAxis], nil ] forRow: GUI_ROW_STICKPROFILE_AXIS];
603 [gui setKey: GUI_KEY_OK forRow: GUI_ROW_STICKPROFILE_AXIS];
604 value = [profile deadzone];
605 bars = (int)(20 * value / STICK_MAX_DEADZONE + 0.5);
606 if (bars < 0) bars = 0;
607 if (bars > 20) bars = 20;
608 [gui setArray: [NSArray arrayWithObjects: DESC(@"oolite-stickprofile-deadzone"),
609 [NSString stringWithFormat:
610 @"%@%@ (%0.4f)",
611 [v1 substringToIndex: bars],
612 [v2 substringToIndex: 20 - bars],
613 value],
614 nil] forRow: GUI_ROW_STICKPROFILE_DEADZONE];
615 [gui setKey: GUI_KEY_OK forRow: GUI_ROW_STICKPROFILE_DEADZONE];
616 [gui setArray: [NSArray arrayWithObjects: DESC(@"oolite-stickprofile-profile-type"), [self profileType], nil ] forRow: GUI_ROW_STICKPROFILE_PROFILE_TYPE];
617 [gui setKey: GUI_KEY_OK forRow: GUI_ROW_STICKPROFILE_PROFILE_TYPE];
618 if ([profile isKindOfClass:[OOJoystickStandardAxisProfile class]])
619 {
620 standard_profile = (OOJoystickStandardAxisProfile*) profile;
621 power = [standard_profile power];
622 bars = (int)(20*power / STICKPROFILE_MAX_POWER + 0.5);
623 if (bars < 0) bars = 0;
624 if (bars > 20) bars = 20;
625 [gui setArray: [NSArray arrayWithObjects: DESC(@"oolite-stickprofile-range"),
626 [NSString stringWithFormat: @"%@%@ (%.1f) ", [v1 substringToIndex: bars], [v2 substringToIndex: 20 - bars], power],
627 nil] forRow: GUI_ROW_STICKPROFILE_POWER];
628 [gui setKey: GUI_KEY_OK forRow: GUI_ROW_STICKPROFILE_POWER];
629 value = [standard_profile parameter];
630 bars = 20*value;
631 if (bars < 0) bars = 0;
632 if (bars > 20) bars = 20;
633 [gui setArray: [NSArray arrayWithObjects: DESC(@"oolite-stickprofile-sensitivity"),
634 [NSString stringWithFormat: @"%@%@ (%0.2f) ", [v1 substringToIndex: bars], [v2 substringToIndex: 20 - bars], value],
635 nil] forRow: GUI_ROW_STICKPROFILE_PARAM];
636 [gui setKey: GUI_KEY_OK forRow: GUI_ROW_STICKPROFILE_PARAM];
637 [gui setColor:[OOColor yellowColor] forRow: GUI_ROW_STICKPROFILE_PARAM];
638 }
639 else
640 {
641 [gui setText: @"" forRow: GUI_ROW_STICKPROFILE_POWER];
642 [gui setKey: GUI_KEY_SKIP forRow: GUI_ROW_STICKPROFILE_POWER];
643 [gui setText: DESC(@"oolite-stickprofile-spline-instructions") forRow: GUI_ROW_STICKPROFILE_PARAM];
644 [gui setKey: GUI_KEY_SKIP forRow: GUI_ROW_STICKPROFILE_PARAM];
645 [gui setColor:[OOColor magentaColor] forRow: GUI_ROW_STICKPROFILE_PARAM];
646 }
647 [gui setText: DESC(@"gui-back") forRow: GUI_ROW_STICKPROFILE_BACK];
648 [gui setKey: GUI_KEY_OK forRow: GUI_ROW_STICKPROFILE_BACK];
649 [gui setSelectableRange: NSMakeRange(1, GUI_ROW_STICKPROFILE_BACK)];
650 [[UNIVERSE gameView] suppressKeysUntilKeyUp];
651 [gui setForegroundTextureKey:[PLAYER status] == STATUS_DOCKED ? @"docked_overlay" : @"paused_overlay"];
652 [gui setBackgroundTextureKey: @"settings"];
653 return;
654}
NSInteger OOGUITabStop
#define STICK_MAX_DEADZONE
#define STICKPROFILE_MAX_POWER
OOColor * yellowColor()
Definition OOColor.m:292
OOColor * magentaColor()
Definition OOColor.m:298
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque

◆ startEdit

- (void) startEdit
implementation

Provided by category StickProfileScreen(StickProfileInternal).

Definition at line 43 of file PlayerEntityStickProfile.m.

564{
565 int i, j;
566
567 for (i = 0; i < 3; i++)
568 {
569 for (j = 0; j < 2; j++)
570 {
571 [profiles[i][j] release];
572 profiles[i][j] = nil;
573 }
574 }
575 current_axis = AXIS_ROLL;
576 selected_control_point = -1;
577 dragged_control_point = -1;
578 double_click_control_point = -1;
579 return;
580}

◆ startGui:

- (void) startGui: (GuiDisplayGen *) gui_display_gen

Definition at line 43 of file PlayerEntityStickProfile.m.

267 : (GuiDisplayGen *) gui_display_gen
268{
269 gui = gui_display_gen;
270 [self startEdit];
271 [gui clear];
272 [gui setTitle:DESC(@"oolite-stickprofile-title")];
273 [self showScreen];
274 [gui setSelectedRow: GUI_ROW_STICKPROFILE_AXIS];
275 return;
276}

Member Data Documentation

◆ current_axis

- (NSUInteger) current_axis
private

Definition at line 45 of file PlayerEntityStickProfile.h.

◆ double_click_control_point

- (NSInteger) double_click_control_point
private

Definition at line 51 of file PlayerEntityStickProfile.h.

◆ dragged_control_point

- (NSInteger) dragged_control_point
private

Definition at line 50 of file PlayerEntityStickProfile.h.

◆ graphRect

- (NSRect) graphRect
private

Definition at line 48 of file PlayerEntityStickProfile.h.

◆ gui

- (GuiDisplayGen*) gui
private

Definition at line 47 of file PlayerEntityStickProfile.h.

◆ profiles

- (OOJoystickAxisProfile* profiles[3][2])
private

Definition at line 46 of file PlayerEntityStickProfile.h.

◆ selected_control_point

- (NSInteger) selected_control_point
private

Definition at line 49 of file PlayerEntityStickProfile.h.

◆ stickHandler

- (OOJoystickManager*) stickHandler
private

Definition at line 44 of file PlayerEntityStickProfile.h.


The documentation for this class was generated from the following files: