33using RemoteTech . FlightComputer . Commands ;
44using UnityEngine ;
55using KSP . Localization ;
6+ using static RemoteTech . FlightComputer . SteeringHelper ;
7+ using RemoteTech . FlightComputer ;
68
79namespace RemoteTech . UI
810{
@@ -82,14 +84,13 @@ private double DeltaV
8284 }
8385 }
8486
85- private FlightAttitude Attitude { get { return mAttitude ; } }
86-
8787 private FlightComputer . FlightComputer mFlightComputer ;
8888 private Action mOnClickQueue ;
8989
9090 private ComputerMode mMode ;
9191 private FlightAttitude mAttitude ;
9292 private float mThrottle ;
93+ private FlightControlOutput mControlOutputMask = 0 ;
9394
9495 private String mPitch = "90" ;
9596 private String mRoll = "90" ;
@@ -190,6 +191,16 @@ public void Draw()
190191 RTUtil . MouseWheelTriggerField ( ref mRoll , "rt_phr3" , ( ) => { Roll ++ ; } , ( ) => { Roll -- ; } , GUILayout . Width ( width3 ) ) ;
191192 }
192193 GUILayout . EndHorizontal ( ) ;
194+ GUILayout . Space ( 5 ) ;
195+
196+ GUILayout . BeginHorizontal ( ) ;
197+ {
198+ RTUtil . FakeStateButton ( new GUIContent ( Localizer . Format ( "#RT_AttitudeFragment_IgnorePit" ) , Localizer . Format ( "#RT_AttitudeFragment_IgnorePit_desc" ) ) , ( ) => RTCore . Instance . StartCoroutine ( OnControlClick ( FlightControlOutput . IgnorePitch ) ) , ( int ) ( mControlOutputMask & FlightControlOutput . IgnorePitch ) , ( int ) FlightControlOutput . IgnorePitch , GUILayout . Width ( width3 ) ) ; //"IGN\nPIT", "Ignore pitch control."
199+ RTUtil . FakeStateButton ( new GUIContent ( Localizer . Format ( "#RT_AttitudeFragment_IgnoreHdr" ) , Localizer . Format ( "#RT_AttitudeFragment_IgnoreHdr_desc" ) ) , ( ) => RTCore . Instance . StartCoroutine ( OnControlClick ( FlightControlOutput . IgnoreHeading ) ) , ( int ) ( mControlOutputMask & FlightControlOutput . IgnoreHeading ) , ( int ) FlightControlOutput . IgnoreHeading , GUILayout . Width ( width3 ) ) ; //"IGN\nHDR", "Ignore heading control."
200+ RTUtil . FakeStateButton ( new GUIContent ( Localizer . Format ( "#RT_AttitudeFragment_IgnoreRll" ) , Localizer . Format ( "#RT_AttitudeFragment_IgnoreRll_desc" ) ) , ( ) => RTCore . Instance . StartCoroutine ( OnControlClick ( FlightControlOutput . IgnoreRoll ) ) , ( int ) ( mControlOutputMask & FlightControlOutput . IgnoreRoll ) , ( int ) FlightControlOutput . IgnoreRoll , GUILayout . Width ( width3 ) ) ; //"IGN\nRLL", "Ignore roll control."
201+ }
202+ GUILayout . EndHorizontal ( ) ;
203+ GUILayout . Space ( 5 ) ;
193204
194205 GUILayout . BeginHorizontal ( ) ;
195206 {
@@ -243,6 +254,43 @@ private IEnumerator OnAttitudeClick(FlightAttitude state)
243254 }
244255 }
245256
257+ private IEnumerator OnControlClick ( FlightControlOutput output )
258+ {
259+ yield return null ;
260+ if ( mFlightComputer . InputAllowed )
261+ {
262+ switch ( output )
263+ {
264+ case FlightControlOutput . IgnorePitch :
265+ if ( ( mControlOutputMask & FlightControlOutput . IgnorePitch ) == FlightControlOutput . IgnorePitch )
266+ mControlOutputMask &= ~ FlightControlOutput . IgnorePitch ;
267+ else
268+ mControlOutputMask |= FlightControlOutput . IgnorePitch ;
269+ break ;
270+
271+ case FlightControlOutput . IgnoreHeading :
272+ if ( ( mControlOutputMask & FlightControlOutput . IgnoreHeading ) == FlightControlOutput . IgnoreHeading )
273+ mControlOutputMask &= ~ FlightControlOutput . IgnoreHeading ;
274+ else
275+ mControlOutputMask |= FlightControlOutput . IgnoreHeading ;
276+ break ;
277+
278+ case FlightControlOutput . IgnoreRoll :
279+ if ( ( mControlOutputMask & FlightControlOutput . IgnoreRoll ) == FlightControlOutput . IgnoreRoll )
280+ mControlOutputMask &= ~ FlightControlOutput . IgnoreRoll ;
281+ else
282+ mControlOutputMask |= FlightControlOutput . IgnoreRoll ;
283+ break ;
284+ }
285+
286+ bool pitch = ( mControlOutputMask & FlightControlOutput . IgnorePitch ) == FlightControlOutput . IgnorePitch ,
287+ heading = ( mControlOutputMask & FlightControlOutput . IgnoreHeading ) == FlightControlOutput . IgnoreHeading ,
288+ roll = ( mControlOutputMask & FlightControlOutput . IgnoreRoll ) == FlightControlOutput . IgnoreRoll ;
289+
290+ mFlightComputer . Enqueue ( FlightControlCommand . WithPHR ( pitch , heading , roll ) ) ;
291+ }
292+ }
293+
246294 private void Confirm ( )
247295 {
248296 ICommand newCommand ;
@@ -264,22 +312,22 @@ private void Confirm()
264312 case ComputerMode . TargetPos :
265313 mAttitude = ( mAttitude == FlightAttitude . Null ) ? FlightAttitude . Prograde : mAttitude ;
266314 newCommand =
267- AttitudeCommand . WithAttitude ( Attitude , ReferenceFrame . TargetParallel ) ;
315+ AttitudeCommand . WithAttitude ( mAttitude , ReferenceFrame . TargetParallel ) ;
268316 break ;
269317 case ComputerMode . Orbital :
270318 mAttitude = ( mAttitude == FlightAttitude . Null ) ? FlightAttitude . Prograde : mAttitude ;
271319 newCommand =
272- AttitudeCommand . WithAttitude ( Attitude , ReferenceFrame . Orbit ) ;
320+ AttitudeCommand . WithAttitude ( mAttitude , ReferenceFrame . Orbit ) ;
273321 break ;
274322 case ComputerMode . Surface :
275323 mAttitude = ( mAttitude == FlightAttitude . Null ) ? FlightAttitude . Prograde : mAttitude ;
276324 newCommand =
277- AttitudeCommand . WithAttitude ( Attitude , ReferenceFrame . Surface ) ;
325+ AttitudeCommand . WithAttitude ( mAttitude , ReferenceFrame . Surface ) ;
278326 break ;
279327 case ComputerMode . TargetVel :
280328 mAttitude = ( mAttitude == FlightAttitude . Null ) ? FlightAttitude . Prograde : mAttitude ;
281329 newCommand =
282- AttitudeCommand . WithAttitude ( Attitude , ReferenceFrame . TargetVelocity ) ;
330+ AttitudeCommand . WithAttitude ( mAttitude , ReferenceFrame . TargetVelocity ) ;
283331 break ;
284332 case ComputerMode . Custom :
285333 mAttitude = FlightAttitude . Null ;
@@ -344,6 +392,15 @@ public void getActiveFlightMode()
344392
345393 if ( mMode == ComputerMode . Orbital || mMode == ComputerMode . Surface || mMode == ComputerMode . TargetPos || mMode == ComputerMode . TargetVel )
346394 mAttitude = mappedCommand . computerAttitude ;
395+
396+ var activeIgnoreCmd = FlightControlCommand . findActiveControlCmd ( mFlightComputer ) ;
397+ if ( activeIgnoreCmd != null )
398+ {
399+ mControlOutputMask = 0 ;
400+ if ( activeIgnoreCmd . ignorePitchOutput ) { mControlOutputMask |= FlightControlOutput . IgnorePitch ; }
401+ if ( activeIgnoreCmd . ignoreHeadingOutput ) { mControlOutputMask |= FlightControlOutput . IgnoreHeading ; }
402+ if ( activeIgnoreCmd . ignoreRollOutput ) { mControlOutputMask |= FlightControlOutput . IgnoreRoll ; }
403+ }
347404 }
348405
349406 /// <summary>
@@ -354,6 +411,7 @@ public void Reset()
354411 // get active command
355412 mMode = ComputerMode . Off ;
356413 mAttitude = FlightAttitude . Null ;
414+ mControlOutputMask = 0 ;
357415 }
358416 }
359417}
0 commit comments