/// <summary> /// Reset the modes /// </summary> public void Reset() { // get active command mMode = ComputerMode.Off; mAttitude = FlightAttitude.Null; mControlOutputMask = 0; }
public void mapFlightMode(FlightMode flightMode, FlightAttitude flightAttitude, ReferenceFrame frame) { computerMode = ComputerMode.Off; computerAttitude = flightAttitude; switch (flightMode) { case FlightMode.Off: { computerMode = ComputerMode.Off; break; } case FlightMode.KillRot: { computerMode = ComputerMode.Kill; break; } case FlightMode.AttitudeHold: { computerMode = ComputerMode.Custom; switch (frame) { case ReferenceFrame.Maneuver: { computerMode = ComputerMode.Node; break; } case ReferenceFrame.Orbit: { computerMode = ComputerMode.Orbital; break; } case ReferenceFrame.Surface: { computerMode = ComputerMode.Surface; break; } case ReferenceFrame.TargetParallel: { computerMode = ComputerMode.TargetPos; break; } case ReferenceFrame.TargetVelocity: { computerMode = ComputerMode.TargetVel; break; } } break; } } }
// Called by RTUtil.Button // General-purpose function has to represent enums as integers private IEnumerator OnModeClick(ComputerMode state) { yield return(null); if (mFlightComputer.InputAllowed) { mMode = (state < 0) ? ComputerMode.Off : state; Confirm(); } }
private IEnumerator OnAttitudeClick(FlightAttitude state) { yield return(null); if (mFlightComputer.InputAllowed) { mAttitude = (state < 0) ? FlightAttitude.Null : state; if (mMode == ComputerMode.Off || mMode == ComputerMode.Kill || mMode == ComputerMode.Node) { mMode = ComputerMode.Orbital; } Confirm(); } }
/// <summary> /// Get the current active FlightMode and map it to the Computermode /// </summary> public void getActiveFlightMode() { // check the current flight mode if (mFlightComputer.CurrentFlightMode == null) { Reset(); return; } // get active command SimpleTypes.ComputerModeMapper mappedCommand = mFlightComputer.CurrentFlightMode.mapFlightMode(); mMode = mappedCommand.computerMode; mAttitude = FlightAttitude.Null; if (mMode == ComputerMode.Orbital || mMode == ComputerMode.Surface || mMode == ComputerMode.TargetPos || mMode == ComputerMode.TargetVel) { mAttitude = mappedCommand.computerAttitude; } }
/// <summary> /// Get the current active FlightMode and map it to the Computermode /// </summary> public void getActiveFlightMode() { // check the current flight mode if (mFlightComputer.CurrentFlightMode == null) { Reset(); return; } // get active command SimpleTypes.ComputerModeMapper mappedCommand = mFlightComputer.CurrentFlightMode.mapFlightMode(); mMode = mappedCommand.computerMode; mAttitude = FlightAttitude.Null; if (mMode == ComputerMode.Orbital || mMode == ComputerMode.Surface || mMode == ComputerMode.TargetPos || mMode == ComputerMode.TargetVel) { mAttitude = mappedCommand.computerAttitude; } var activeIgnoreCmd = FlightControlCommand.findActiveControlCmd(mFlightComputer); if (activeIgnoreCmd != null) { mControlOutputMask = 0; if (activeIgnoreCmd.ignorePitchOutput) { mControlOutputMask |= FlightControlOutput.IgnorePitch; } if (activeIgnoreCmd.ignoreHeadingOutput) { mControlOutputMask |= FlightControlOutput.IgnoreHeading; } if (activeIgnoreCmd.ignoreRollOutput) { mControlOutputMask |= FlightControlOutput.IgnoreRoll; } } }
/// <summary> /// Reset the modes /// </summary> public void Reset() { // get active command mMode = ComputerMode.Off; mAttitude = FlightAttitude.Null; }
public void Draw() { float width3 = 156 / 3 - GUI.skin.button.margin.right * 2.0f / 3.0f; if (Event.current.Equals(Event.KeyboardEvent("return"))) { if (GUI.GetNameOfFocusedControl().StartsWith("rt_phr")) { mPitch = Pitch.ToString(); mHeading = Heading.ToString(); mRoll = Roll.ToString(); if (mFlightComputer.InputAllowed) { mMode = ComputerMode.Custom; Confirm(); } } else if (GUI.GetNameOfFocusedControl() == "rt_burn") { OnBurnClick(); } } GUILayout.BeginVertical(); { GUILayout.BeginHorizontal(); { RTUtil.FakeStateButton(new GUIContent(Localizer.Format("#RT_AttitudeFragment_KILL"), Localizer.Format("#RT_AttitudeFragment_KILL_desc")), () => RTCore.Instance.StartCoroutine(OnModeClick(ComputerMode.Kill)), (int)mMode, (int)ComputerMode.Kill, GUILayout.Width(width3)); //"KILL", "Kill rotation." RTUtil.FakeStateButton(new GUIContent(Localizer.Format("#RT_AttitudeFragment_NODE"), Localizer.Format("#RT_AttitudeFragment_NODE_desc")), () => RTCore.Instance.StartCoroutine(OnModeClick(ComputerMode.Node)), (int)mMode, (int)ComputerMode.Node, GUILayout.Width(width3)); //"NODE", "Prograde points in the direction of the first maneuver node." RTUtil.FakeStateButton(new GUIContent(Localizer.Format("#RT_AttitudeFragment_RVEL"), Localizer.Format("#RT_AttitudeFragment_RVEL_desc")), () => RTCore.Instance.StartCoroutine(OnModeClick(ComputerMode.TargetVel)), (int)mMode, (int)ComputerMode.TargetVel, GUILayout.Width(width3)); //"RVEL", "Prograde relative to target velocity." } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { RTUtil.FakeStateButton(new GUIContent(Localizer.Format("#RT_AttitudeFragment_ORB"), Localizer.Format("#RT_AttitudeFragment_ORB_desc")), () => RTCore.Instance.StartCoroutine(OnModeClick(ComputerMode.Orbital)), (int)mMode, (int)ComputerMode.Orbital, GUILayout.Width(width3)); //"ORB", "Prograde relative to orbital velocity." RTUtil.FakeStateButton(new GUIContent(Localizer.Format("#RT_AttitudeFragment_SRF"), Localizer.Format("#RT_AttitudeFragment_SRF_desc")), () => RTCore.Instance.StartCoroutine(OnModeClick(ComputerMode.Surface)), (int)mMode, (int)ComputerMode.Surface, GUILayout.Width(width3)); //"SRF", "Prograde relative to surface velocity." RTUtil.FakeStateButton(new GUIContent(Localizer.Format("#RT_AttitudeFragment_TGT"), Localizer.Format("#RT_AttitudeFragment_TGT_desc")), () => RTCore.Instance.StartCoroutine(OnModeClick(ComputerMode.TargetPos)), (int)mMode, (int)ComputerMode.TargetPos, GUILayout.Width(width3)); //"TGT", "Prograde points directly at target." } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { RTUtil.FakeStateButton(new GUIContent(Localizer.Format("#RT_AttitudeFragment_OFF"), Localizer.Format("#RT_AttitudeFragment_OFF_desc")), () => RTCore.Instance.StartCoroutine(OnModeClick(ComputerMode.Off)), (int)mMode, (int)ComputerMode.Off, GUILayout.Width(width3)); //"OFF", "Set Attitude to Off." RTUtil.FakeStateButton(new GUIContent(Localizer.Format("#RT_AttitudeFragment_CUSTOM"), Localizer.Format("#RT_AttitudeFragment_CUSTOM_desc")), () => RTCore.Instance.StartCoroutine(OnModeClick(ComputerMode.Custom)), (int)mMode, (int)ComputerMode.Custom, GUILayout.ExpandWidth(true)); //"CUSTOM", "Prograde fixed as pitch, heading, roll relative to north pole." } GUILayout.EndHorizontal(); GUILayout.Space(5); GUILayout.BeginHorizontal(); { RTUtil.FakeStateButton(new GUIContent(Localizer.Format("#RT_AttitudeFragment_Prograde"), Localizer.Format("#RT_AttitudeFragment_Prograde_desc")), () => RTCore.Instance.StartCoroutine(OnAttitudeClick(FlightAttitude.Prograde)), (int)mAttitude, (int)FlightAttitude.Prograde, GUILayout.Width(width3)); //"GRD\n+", "Orient to Prograde." RTUtil.FakeStateButton(new GUIContent(Localizer.Format("#RT_AttitudeFragment_RadialPlus"), Localizer.Format("#RT_AttitudeFragment_RadialPlus_desc")), () => RTCore.Instance.StartCoroutine(OnAttitudeClick(FlightAttitude.RadialPlus)), (int)mAttitude, (int)FlightAttitude.RadialPlus, GUILayout.Width(width3)); //"RAD\n+", "Orient to Radial." RTUtil.FakeStateButton(new GUIContent(Localizer.Format("#RT_AttitudeFragment_NormalPlus"), Localizer.Format("#RT_AttitudeFragment_NormalPlus_desc")), () => RTCore.Instance.StartCoroutine(OnAttitudeClick(FlightAttitude.NormalPlus)), (int)mAttitude, (int)FlightAttitude.NormalPlus, GUILayout.Width(width3)); //"NRM\n+", "Orient to Normal." } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { RTUtil.FakeStateButton(new GUIContent(Localizer.Format("#RT_AttitudeFragment_Retrograde"), Localizer.Format("#RT_AttitudeFragment_Retrograde_desc")), () => RTCore.Instance.StartCoroutine(OnAttitudeClick(FlightAttitude.Retrograde)), (int)mAttitude, (int)FlightAttitude.Retrograde, GUILayout.Width(width3)); //"GRD\n-", "Orient to Retrograde." RTUtil.FakeStateButton(new GUIContent(Localizer.Format("#RT_AttitudeFragment_RadialMinus"), Localizer.Format("#RT_AttitudeFragment_RadialMinus_desc")), () => RTCore.Instance.StartCoroutine(OnAttitudeClick(FlightAttitude.RadialMinus)), (int)mAttitude, (int)FlightAttitude.RadialMinus, GUILayout.Width(width3)); //"RAD\n-", "Orient to Anti-radial." RTUtil.FakeStateButton(new GUIContent(Localizer.Format("#RT_AttitudeFragment_NormalMinus"), Localizer.Format("#RT_AttitudeFragment_NormalMinus_desc")), () => RTCore.Instance.StartCoroutine(OnAttitudeClick(FlightAttitude.NormalMinus)), (int)mAttitude, (int)FlightAttitude.NormalMinus, GUILayout.Width(width3)); //"NRM\n-", "Orient to Anti-normal." } GUILayout.EndHorizontal(); GUILayout.Space(5); GUILayout.BeginHorizontal(); { GUILayout.Label(new GUIContent(Localizer.Format("#RT_AttitudeFragment_PIT"), Localizer.Format("#RT_AttitudeFragment_PIT_desc")), GUILayout.Width(width3));//"PIT:", "Sets pitch." RTUtil.RepeatButton("+", () => { Pitch++; }); RTUtil.RepeatButton("-", () => { Pitch--; }); RTUtil.MouseWheelTriggerField(ref mPitch, "rt_phr1", () => { Pitch++; }, () => { Pitch--; }, GUILayout.Width(width3)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label(new GUIContent(Localizer.Format("#RT_AttitudeFragment_HDG"), Localizer.Format("#RT_AttitudeFragment_HDG_desc")), GUILayout.Width(width3));//"HDG:", "Sets heading." RTUtil.RepeatButton("+", () => { Heading++; }); RTUtil.RepeatButton("-", () => { Heading--; }); RTUtil.MouseWheelTriggerField(ref mHeading, "rt_phr2", () => { Heading++; }, () => { Heading--; }, GUILayout.Width(width3)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label(new GUIContent(Localizer.Format("#RT_AttitudeFragment_RLL"), Localizer.Format("#RT_AttitudeFragment_RLL_desc")), GUILayout.Width(width3));//"RLL:", "Sets roll." RTUtil.RepeatButton("+", () => { Roll++; }); RTUtil.RepeatButton("-", () => { Roll--; }); RTUtil.MouseWheelTriggerField(ref mRoll, "rt_phr3", () => { Roll++; }, () => { Roll--; }, GUILayout.Width(width3)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label(Localizer.Format("#RT_AttitudeFragment_Throttle"));//"Throttle: " GUILayout.FlexibleSpace(); GUILayout.Label(mThrottle.ToString("P")); } GUILayout.EndHorizontal(); RTUtil.HorizontalSlider(ref mThrottle, 0, 1); GUI.SetNextControlName("rt_burn"); RTUtil.TextField(ref mDuration); GUILayout.BeginHorizontal(); { RTUtil.Button(new GUIContent(Localizer.Format("#RT_AttitudeFragment_BURN"), Localizer.Format("#RT_AttitudeFragment_BURN_desc")), //"BURN", "Example: 125, 125s, 5m20s, 1d6h20m10s, 123m/s." OnBurnClick, GUILayout.Width(width3)); RTUtil.Button(new GUIContent(Localizer.Format("#RT_AttitudeFragment_EXEC"), Localizer.Format("#RT_AttitudeFragment_EXEC_desc")), //"EXEC", "Executes next and subsequent maneuver nodes." OnExecClick, GUILayout.Width(width3)); RTUtil.Button(new GUIContent(">>", Localizer.Format("#RT_AttitudeFragment_Queue_desc")), //"Toggles the queue and delay functionality." mOnClickQueue, GUILayout.Width(width3)); } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); }
/// <summary> /// Get the current active FlightMode and map it to the Computermode /// </summary> public void getActiveFlightMode() { // check the current flight mode if (mFlightComputer.currentFlightMode == null) { Reset(); return; } // get active command SimpleTypes.ComputerModeMapper mappedCommand = mFlightComputer.currentFlightMode.mapFlightMode(); mMode = mappedCommand.computerMode; mAttitude = FlightAttitude.Null; if(mMode == ComputerMode.Orbital || mMode == ComputerMode.Surface || mMode == ComputerMode.TargetPos || mMode == ComputerMode.TargetVel) mAttitude = mappedCommand.computerAttitude; }
private IEnumerator OnAttitudeClick(FlightAttitude state) { yield return null; if (mFlightComputer.InputAllowed) { mAttitude = (state < 0) ? FlightAttitude.Null : state; if (mMode == ComputerMode.Off || mMode == ComputerMode.Kill || mMode == ComputerMode.Node) { mMode = ComputerMode.Orbital; } Confirm(); } }
// Called by RTUtil.Button // General-purpose function has to represent enums as integers private IEnumerator OnModeClick(ComputerMode state) { yield return null; if (mFlightComputer.InputAllowed) { mMode = (state < 0) ? ComputerMode.Off : state; Confirm(); } }
public void Draw() { float width3 = 156 / 3 - GUI.skin.button.margin.right * 2.0f / 3.0f; if (Event.current.Equals(Event.KeyboardEvent("return"))) { if (GUI.GetNameOfFocusedControl().StartsWith("rt_phr")) { mPitch = Pitch.ToString(); mHeading = Heading.ToString(); mRoll = Roll.ToString(); if (mFlightComputer.InputAllowed) { mMode = ComputerMode.Custom; Confirm(); } } else if (GUI.GetNameOfFocusedControl() == "rt_burn") { OnBurnClick(); } } GUILayout.BeginVertical(); { GUILayout.BeginHorizontal(); { GUIStyle guiTableRow = new GUIStyle(HighLogic.Skin.label); guiTableRow.normal.textColor = Color.white; RTUtil.FakeStateButton(new GUIContent("KILL", "Kill rotation."), () => RTCore.Instance.StartCoroutine(OnModeClick(ComputerMode.Kill)), (int)mMode, (int)ComputerMode.Kill, GUILayout.Width(width3)); RTUtil.FakeStateButton(new GUIContent("NODE", "Prograde points in the direction of the first maneuver node."), () => RTCore.Instance.StartCoroutine(OnModeClick(ComputerMode.Node)), (int)mMode, (int)ComputerMode.Node, GUILayout.Width(width3)); RTUtil.FakeStateButton(new GUIContent("RVEL", "Prograde relative to target velocity."), () => RTCore.Instance.StartCoroutine(OnModeClick(ComputerMode.TargetVel)), (int)mMode, (int)ComputerMode.TargetVel, GUILayout.Width(width3)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { RTUtil.FakeStateButton(new GUIContent("ORB", "Prograde relative to orbital velocity."), () => RTCore.Instance.StartCoroutine(OnModeClick(ComputerMode.Orbital)), (int)mMode, (int)ComputerMode.Orbital, GUILayout.Width(width3)); RTUtil.FakeStateButton(new GUIContent("SRF", "Prograde relative to surface velocity."), () => RTCore.Instance.StartCoroutine(OnModeClick(ComputerMode.Surface)), (int)mMode, (int)ComputerMode.Surface, GUILayout.Width(width3)); RTUtil.FakeStateButton(new GUIContent("TGT", "Prograde points directly at target."), () => RTCore.Instance.StartCoroutine(OnModeClick(ComputerMode.TargetPos)), (int)mMode, (int)ComputerMode.TargetPos, GUILayout.Width(width3)); } GUILayout.EndHorizontal(); RTUtil.FakeStateButton(new GUIContent("CUSTOM", "Prograde fixed as pitch, heading, roll relative to north pole."), () => RTCore.Instance.StartCoroutine(OnModeClick(ComputerMode.Custom)), (int)mMode, (int)ComputerMode.Custom, GUILayout.ExpandWidth(true)); GUILayout.Space(5); GUILayout.BeginHorizontal(); { RTUtil.FakeStateButton(new GUIContent("GRD\n+", "Orient to Prograde."), () => RTCore.Instance.StartCoroutine(OnAttitudeClick(FlightAttitude.Prograde)), (int)mAttitude, (int)FlightAttitude.Prograde, GUILayout.Width(width3)); RTUtil.FakeStateButton(new GUIContent("RAD\n+", "Orient to Radial."), () => RTCore.Instance.StartCoroutine(OnAttitudeClick(FlightAttitude.RadialPlus)), (int)mAttitude, (int)FlightAttitude.RadialPlus, GUILayout.Width(width3)); RTUtil.FakeStateButton(new GUIContent("NRM\n+", "Orient to Normal."), () => RTCore.Instance.StartCoroutine(OnAttitudeClick(FlightAttitude.NormalPlus)), (int)mAttitude, (int)FlightAttitude.NormalPlus, GUILayout.Width(width3)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { RTUtil.FakeStateButton(new GUIContent("GRD\n-", "Orient to Retrograde."), () => RTCore.Instance.StartCoroutine(OnAttitudeClick(FlightAttitude.Retrograde)), (int)mAttitude, (int)FlightAttitude.Retrograde, GUILayout.Width(width3)); RTUtil.FakeStateButton(new GUIContent("RAD\n-", "Orient to Anti-radial."), () => RTCore.Instance.StartCoroutine(OnAttitudeClick(FlightAttitude.RadialMinus)), (int)mAttitude, (int)FlightAttitude.RadialMinus, GUILayout.Width(width3)); RTUtil.FakeStateButton(new GUIContent("NRM\n-", "Orient to Anti-normal."), () => RTCore.Instance.StartCoroutine(OnAttitudeClick(FlightAttitude.NormalMinus)), (int)mAttitude, (int)FlightAttitude.NormalMinus, GUILayout.Width(width3)); } GUILayout.EndHorizontal(); GUILayout.Space(5); GUILayout.BeginHorizontal(); { GUILayout.Label(new GUIContent("PIT:", "Sets pitch."), GUILayout.Width(width3)); RTUtil.RepeatButton("+", () => { Pitch++; }); RTUtil.RepeatButton("-", () => { Pitch--; }); RTUtil.MouseWheelTriggerField(ref mPitch, "rt_phr1", () => { Pitch++; }, () => { Pitch--; }, GUILayout.Width(width3)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label(new GUIContent("HDG:", "Sets heading."), GUILayout.Width(width3)); RTUtil.RepeatButton("+", () => { Heading++; }); RTUtil.RepeatButton("-", () => { Heading--; }); RTUtil.MouseWheelTriggerField(ref mHeading, "rt_phr2", () => { Heading++; }, () => { Heading--; }, GUILayout.Width(width3)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label(new GUIContent("RLL:", "Sets roll."), GUILayout.Width(width3)); RTUtil.RepeatButton("+", () => { Roll++; }); RTUtil.RepeatButton("-", () => { Roll--; }); RTUtil.MouseWheelTriggerField(ref mRoll, "rt_phr3", () => { Roll++; }, () => { Roll--; }, GUILayout.Width(width3)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label("Throttle: "); GUILayout.FlexibleSpace(); GUILayout.Label(mThrottle.ToString("P")); } GUILayout.EndHorizontal(); RTUtil.HorizontalSlider(ref mThrottle, 0, 1); GUI.SetNextControlName("rt_burn"); RTUtil.TextField(ref mDuration); GUILayout.BeginHorizontal(); { RTUtil.Button(new GUIContent("BURN", "Example: 125, 125s, 5m20s, 1d6h20m10s, 123m/s."), OnBurnClick, GUILayout.Width(width3)); RTUtil.Button(new GUIContent("EXEC", "Executes next maneuver node."), OnExecClick, GUILayout.Width(width3)); RTUtil.Button(new GUIContent(">>", "Toggles the queue and delay functionality."), mOnClickQueue, GUILayout.Width(width3)); } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); }