36#define GUI_ROW_STICKPROFILE_BACK 20
37#define GUI_ROW_STICKPROFILE_AXIS 1
38#define GUI_ROW_STICKPROFILE_DEADZONE 2
39#define GUI_ROW_STICKPROFILE_PROFILE_TYPE 3
40#define GUI_ROW_STICKPROFILE_POWER 4
41#define GUI_ROW_STICKPROFILE_PARAM 5
45@interface StickProfileScreen (StickProfileInternal)
61- (void) graphProfile: (GLfloat) alpha at: (Vector) at size: (NSSize) size;
67@implementation PlayerEntity (StickProfile)
71 gui_screen = GUI_SCREEN_STICKPROFILE;
72 [stickProfileScreen startGui: gui];
81 NSPoint mouse_position = NSMakePoint(
82 [gameView virtualJoystickPosition].
x * [gui
size].width,
83 [gameView virtualJoystickPosition].
y * [gui
size].height );
84 [stickProfileScreen mouseDown: mouse_position];
88 [stickProfileScreen mouseUp];
92 [stickProfileScreen deleteSelected];
94 [
self handleGUIUpDownArrowKeys];
98 [stickProfileScreen saveSettings];
99 [
self setGuiToStickMapperScreen: 0 resetCurrentRow: YES];
101 switch ([gui selectedRow])
104 if ([
self checkKeyPress:n_key_gui_arrow_left])
108 [stickProfileScreen previousAxis];
112 else if ([
self checkKeyPress: n_key_gui_arrow_right])
116 [stickProfileScreen nextAxis];
127 if ([
self checkKeyPress:n_key_gui_arrow_left])
131 [stickProfileScreen decreaseDeadzone];
135 else if ([
self checkKeyPress: n_key_gui_arrow_right])
139 [stickProfileScreen increaseDeadzone];
150 if ([
self checkKeyPress:n_key_gui_arrow_left])
154 [stickProfileScreen previousProfileType];
158 else if ([
self checkKeyPress: n_key_gui_arrow_right])
162 [stickProfileScreen nextProfileType];
173 if (![stickProfileScreen currentProfileIsSpline])
177 if ([
self checkKeyPress:n_key_gui_arrow_left])
181 [stickProfileScreen DecreasePower];
185 else if ([
self checkKeyPress: n_key_gui_arrow_right])
189 [stickProfileScreen IncreasePower];
200 if ([
self checkKeyPress:n_key_gui_arrow_left])
204 [stickProfileScreen DecreaseParam];
208 else if ([
self checkKeyPress: n_key_gui_arrow_right])
212 [stickProfileScreen IncreaseParam];
225- (void) stickProfileGraphAxisProfile: (GLfloat) alpha screenAt: (Vector) screenAt screenSize: (NSSize) screenSize
228 [stickProfileScreen graphProfile: alpha at: make_vector(screenAt.x - 110.0, screenAt.y - 100, screenAt.z) size: NSMakeSize(220,220)];
240 if ((
self = [super init]))
244 for (i = 0; i < 3; i++)
246 for (j = 0; j < 2; j++)
248 profiles[i][j] =
nil;
258 for (i = 0; i < 3; i++)
260 for (j = 0; j < 2; j++)
262 [profiles[i][j] release];
269 gui = gui_display_gen;
272 [gui
setTitle:DESC(@"oolite-stickprofile-title")];
278- (void) mouseDown: (NSPoint) position
282 NSPoint spline_position;
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)
293 if (dragged_control_point < 0)
295 selected_control_point = [spline_profile addControl: spline_position];
296 dragged_control_point = selected_control_point;
297 double_click_control_point = -1;
301 [spline_profile moveControl: dragged_control_point point: spline_position];
303 [stickHandler saveStickSettings];
310 if (selected_control_point >= 0)
312 double_click_control_point = selected_control_point;
314 dragged_control_point = -1;
318- (void) deleteSelected
326 selected_control_point = -1;
327 dragged_control_point = -1;
328 [stickHandler saveStickSettings];
336@implementation StickProfileScreen (StickProfileInternal)
361 switch (current_axis)
364 return DESC(
@"stickmapper-roll");
367 return DESC(
@"stickmapper-pitch");
370 return DESC(
@"stickmapper-yaw");
405 [profiles[current_axis][0] release];
406 profiles[current_axis][0] = [profile retain];
407 if (!profiles[current_axis][1])
411 [profiles[current_axis][1] setDeadzone: deadzone];
412 [stickHandler setProfile: profiles[current_axis][1] forAxis: current_axis];
413 [stickHandler saveStickSettings];
427 [profiles[current_axis][1] release];
428 profiles[current_axis][1] = [profile retain];
429 if (!profiles[current_axis][0])
433 [profiles[current_axis][0] setDeadzone: deadzone];
434 [stickHandler setProfile: profiles[current_axis][0] forAxis: current_axis];
435 [stickHandler saveStickSettings];
458 [standard_profile
setPower: [standard_profile
power] + STICKPROFILE_MAX_POWER / 20];
459 [stickHandler saveStickSettings];
473 [standard_profile
setPower: [standard_profile
power] - STICKPROFILE_MAX_POWER / 20];
474 [stickHandler saveStickSettings];
489 [stickHandler saveStickSettings];
504 [stickHandler saveStickSettings];
510- (void) graphProfile: (GLfloat) alpha at: (Vector) at size: (NSSize) size
516 NSArray *control_points;
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));
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);
528 OOGL(glColor4f(0.9,0.9,0.9,alpha));
531 for (i = 0; i <=
size.width - 20; i++)
533 glVertex3f(at.x+i+10,at.y+10+(
size.height-20)*[profile rawValue:((
float)i)/(
size.width-20)],at.z);
536 OOGL(glColor4f(0.5,0.0,0.5,alpha));
543 for (i = 0; i < (NSInteger)[control_points count]; i++)
545 if (i == selected_control_point)
547 OOGL(glColor4f(1.0,0.0,0.0,alpha));
551 OOGL(glColor4f(0.0,1.0,0.0,alpha));
553 point = [[control_points objectAtIndex: i] pointValue];
557 OOGL(glColor4f(0.9,0.9,0.0,alpha));
559 OODrawString(
DESC(
@"oolite-stickprofile-response"), at.x, at.y +
size.height - 10, at.z, NSMakeSize(8,10));
567 for (i = 0; i < 3; i++)
569 for (j = 0; j < 2; j++)
571 [profiles[i][j] release];
572 profiles[i][j] =
nil;
576 selected_control_point = -1;
577 dragged_control_point = -1;
578 double_click_control_point = -1;
584 [stickHandler saveStickSettings];
592 NSString *v1 =
@"||||||||||||||||||||";
593 NSString *v2 =
@"....................";
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];
606 if (bars < 0) bars = 0;
607 if (bars > 20) bars = 20;
608 [gui
setArray: [NSArray arrayWithObjects: DESC(@"oolite-stickprofile-deadzone"),
609 [NSString stringWithFormat:
611 [v1 substringToIndex: bars],
612 [v2 substringToIndex: 20 - bars],
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];
621 power = [standard_profile
power];
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];
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];
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];
647 [gui
setText: DESC(@"gui-back")
forRow: GUI_ROW_STICKPROFILE_BACK];
648 [gui
setKey: GUI_KEY_OK
forRow: GUI_ROW_STICKPROFILE_BACK];
650 [[UNIVERSE gameView] suppressKeysUntilKeyUp];
662 return DESC(
@"oolite-stickprofile-type-standard");
666 return DESC(
@"oolite-stickprofile-type-spline");
668 return DESC(
@"oolite-stickprofile-type-standard");
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 STICK_MAX_DEADZONE
#define STICKPROFILE_MAX_POWER
#define OO_ENTER_OPENGL()
void GLDrawFilledOval(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat step)
void GLScaledLineWidth(GLfloat width)
#define GUI_ROW_STICKPROFILE_PARAM
static BOOL stickProfileArrow_pressed
#define GUI_ROW_STICKPROFILE_AXIS
#define GUI_ROW_STICKPROFILE_BACK
#define GUI_ROW_STICKPROFILE_DEADZONE
#define GUI_ROW_STICKPROFILE_PROFILE_TYPE
#define GUI_ROW_STICKPROFILE_POWER
void previousProfileType()
BOOL currentProfileIsSpline()
BOOL setBackgroundTextureKey:(NSString *key)
BOOL setSelectedRow:(OOGUIRow row)
BOOL setForegroundTextureKey:(NSString *key)
void setText:forRow:(NSString *str,[forRow] OOGUIRow row)
void setSelectableRange:(NSRange range)
void setColor:forRow:(OOColor *color,[forRow] OOGUIRow row)
void setTitle:(NSString *str)
void setTabStops:(OOGUITabSettings stops)
void setArray:forRow:(NSArray *arr,[forRow] OOGUIRow row)
void setKey:forRow:(NSString *str,[forRow] OOGUIRow row)
void setDeadzone:(double newValue)
NSMutableArray * controlPoints
void removeControl:(NSInteger index)
void setPower:(double newValue)
void setParameter:(double newValue)
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque