From e421f6eb56dc40bb0f63d23393ee84ed4b0c2452 Mon Sep 17 00:00:00 2001 From: Dylan Smith Date: Wed, 28 Sep 2005 20:20:46 +0000 Subject: [PATCH] Allow keyboard arrow keys to override stick git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@143 127b21dd-08f5-0310-b4b7-95ae10353056 --- PlayerEntity.h | 3 +++ PlayerEntity.m | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/PlayerEntity.h b/PlayerEntity.h index d27d8b8b..817d439e 100644 --- a/PlayerEntity.h +++ b/PlayerEntity.h @@ -435,6 +435,9 @@ Your fair use and other rights are in no way affected by the above. // Keeping track of joysticks int numSticks; JoystickHandler *stickHandler; + BOOL keyboardRollPitchOverride; + + // For PlayerEntity (StickMapper) int selFunctionIdx; BOOL waitingForStickCallback; NSArray *stickFunctions; diff --git a/PlayerEntity.m b/PlayerEntity.m index 3e62029f..2b7ec4c6 100644 --- a/PlayerEntity.m +++ b/PlayerEntity.m @@ -3148,6 +3148,19 @@ static BOOL taking_snapshot; else if(numSticks) { virtualStick=[stickHandler getRollPitchAxis]; + if(virtualStick.x == STICK_AXISUNASSIGNED || + virtualStick.y == STICK_AXISUNASSIGNED) + { + // Not assigned - set to zero. + virtualStick.x=0; + virtualStick.y=0; + } + else if(virtualStick.x != 0 || + virtualStick.y != 0) + { + // cancel keyboard override, stick has been waggled + keyboardRollPitchOverride=NO; + } } double roll_dampner = ROLL_DAMPING_FACTOR * delta_t; @@ -3158,18 +3171,20 @@ static BOOL taking_snapshot; { if ([gameView isDown:key_roll_left]) { + keyboardRollPitchOverride=YES; if (flight_roll > 0.0) flight_roll = 0.0; [self decrease_flight_roll:delta_t*roll_delta]; rolling = YES; } if ([gameView isDown:key_roll_right]) { + keyboardRollPitchOverride=YES; if (flight_roll < 0.0) flight_roll = 0.0; [self increase_flight_roll:delta_t*roll_delta]; rolling = YES; } } - if(mouse_control_on || numSticks) + if((mouse_control_on || numSticks) && !keyboardRollPitchOverride) { double stick_roll = max_flight_roll * virtualStick.x; if (flight_roll < stick_roll) @@ -3206,18 +3221,20 @@ static BOOL taking_snapshot; { if ([gameView isDown:key_pitch_back]) { + keyboardRollPitchOverride=YES; if (flight_pitch < 0.0) flight_pitch = 0.0; [self increase_flight_pitch:delta_t*pitch_delta]; pitching = YES; } if ([gameView isDown:key_pitch_forward]) { + keyboardRollPitchOverride=YES; if (flight_pitch > 0.0) flight_pitch = 0.0; [self decrease_flight_pitch:delta_t*pitch_delta]; pitching = YES; } } - if(mouse_control_on || numSticks) + if((mouse_control_on || numSticks) && !keyboardRollPitchOverride) { double stick_pitch = max_flight_pitch * virtualStick.y; if (flight_pitch < stick_pitch)