void DetermineNextAction() { DiscreteAction desiredAction = GetDesiredAction(); if (desiredAction == DiscreteAction.Attack) { Attack(); } else if (desiredAction == DiscreteAction.Idle) { EnterIdleState(); } else { IndexDirection2 desiredMoveDir = GetDesiredMoveDirection(desiredAction); if (desiredAction == DiscreteAction.Jump) { Jump(desiredMoveDir); } else { MoveDirection_Tile = DetermineActualMoveDirection(desiredMoveDir); } } _justFinishedIdling = false; }
public Bitset GetBitsetForDiscreteBinding(DiscreteAction action) { if (!discreteActionsMap.ContainsKey(action)) { return(null); } return(discreteActionsMap[action].Bitset); }
public void UnsetDiscreteBinding(DiscreteAction action) { if (!discreteActionsMap.ContainsKey(action)) { return; } discreteActionsMap.Remove(action); }
IndexDirection2 GetDesiredMoveDirection(DiscreteAction action) { IndexDirection2 desiredMoveDir = IndexDirection2.zero; IndexDirection2 toPlayer = IndexDirection2.zero; _enemyMove.speed = _baseSpeed; if (_enemy.ShouldFollowBait()) { desiredMoveDir = GetDirectionToBait(); } else if (chasePlayerIfInSight && IsPlayerInSight(MAX_DISTANCE_PLAYER_CAN_BE_SEEN, out toPlayer)) { _enemyMove.speed = _baseSpeed * chaseSpeedMultiplier; desiredMoveDir = toPlayer; } else { if (MoveDirection_Tile.IsZero()) { desiredMoveDir = GetRandomTileDirection(); } else { if (action == DiscreteAction.ChangeDirection) { List <IndexDirection2> excludeDirections = new List <IndexDirection2>(); excludeDirections.Add(MoveDirection_Tile); if (avoidsReversingDirections) { excludeDirections.Add(MoveDirection_Tile.Reversed); } desiredMoveDir = GetRandomTileDirectionExcluding(excludeDirections); } else if (action == DiscreteAction.Jump) { desiredMoveDir = GetRandomTileDirection(); } else { desiredMoveDir = MoveDirection_Tile; } } } if (!WorldInfo.Instance.IsInDungeon) { desiredMoveDir = EnforceBoundary(desiredMoveDir); } return(desiredMoveDir); }
public void SetDiscreteBinding(Bitset state, DiscreteAction action) { foreach (var keyVal in discreteActionsMap) { if (keyVal.Value.Equals(state)) { discreteActionsMap.Remove(keyVal.Key); break; } } discreteActionsMap[action] = new DiscreteActionEntry(action, state); }
public void DoChooseDiscreteActionWindow(int window) { if (!m_ChooseDiscreteAction) { return; } var currentPreset = m_Controller.GetCurrentPreset(); if (GUILayout.Button("Cancel")) { m_ChooseDiscreteAction = false; return; } m_ChooseDiscreteActionScroll = GUILayout.BeginScrollView(m_ChooseDiscreteActionScroll); foreach (var action in (DiscreteAction[])Enum.GetValues(typeof(DiscreteAction))) { if (action == DiscreteAction.None) { continue; } var bitset = currentPreset.GetBitsetForDiscreteBinding(action); if (bitset != null) { continue; } if (GUILayout.Button(Stringify.DiscreteActionToString(action))) { m_ChosenDiscreteAction = action; m_ChooseDiscreteAction = false; m_CurrentlyEditingDiscreteAction = action; m_ClickSleepTimer = 0.25f; } } GUILayout.EndScrollView(); }
public void EvaluateDiscreteAction(ControllerConfiguration controller, DiscreteAction action, FlightCtrlState state) { switch (action) { case DiscreteAction.None: return; case DiscreteAction.YawPlus: m_Yaw.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.YawMinus: m_Yaw.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.PitchPlus: m_Pitch.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.PitchMinus: m_Pitch.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.PitchTrimPlus: m_Pitch.SetTrim(Utility.Clamp(m_Pitch.GetTrim() + controller.discreteActionStep, -1.0f, 1.0f)); return; case DiscreteAction.PitchTrimMinus: m_Pitch.SetTrim(Utility.Clamp(m_Pitch.GetTrim() - controller.discreteActionStep, -1.0f, 1.0f)); return; case DiscreteAction.RollPlus: m_Roll.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.RollMinus: m_Roll.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.XPlus: m_X.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.XMinus: m_X.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.YPlus: m_Y.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.YMinus: m_Y.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.ZPlus: m_Z.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.ZMinus: m_Z.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.ThrottlePlus: m_Throttle.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.ThrottleMinus: m_Throttle.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.CutThrottle: m_Throttle.SetValue(-state.mainThrottle); return; case DiscreteAction.FullThrottle: m_Throttle.SetValue(1.0f - state.mainThrottle); return; case DiscreteAction.NextPreset: if (controller.currentPreset >= controller.presets.Count - 1) { return; } controller.currentPreset++; ScreenMessages.PostScreenMessage("PRESET: " + controller.GetCurrentPreset().name.ToUpper(), 1.0f, ScreenMessageStyle.UPPER_CENTER); return; case DiscreteAction.PreviousPreset: if (controller.currentPreset <= 0) { return; } controller.currentPreset--; ScreenMessages.PostScreenMessage("PRESET: " + controller.GetCurrentPreset().name.ToUpper(), 1.0f, ScreenMessageStyle.UPPER_CENTER); return; case DiscreteAction.CyclePresets: controller.currentPreset++; if (controller.currentPreset >= controller.presets.Count) { controller.currentPreset = 0; } ScreenMessages.PostScreenMessage("PRESET: " + controller.GetCurrentPreset().name.ToUpper(), 1.0f, ScreenMessageStyle.LOWER_CENTER); return; case DiscreteAction.CameraZoomPlus: m_CameraZoom.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.CameraZoomMinus: m_CameraZoom.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.CameraXPlus: m_CameraHeading.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.CameraXMinus: m_CameraHeading.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.CameraYPlus: m_CameraPitch.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.CameraYMinus: m_CameraPitch.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.OrbitMapToggle: if (!MapView.MapIsEnabled) { MapView.EnterMapView(); } else { MapView.ExitMapView(); } return; case DiscreteAction.TimeWarpPlus: WarpController.IncreaseWarp(); return; case DiscreteAction.TimeWarpMinus: WarpController.DecreaseWarp(); return; case DiscreteAction.PhysicsTimeWarpPlus: WarpController.IncreasePhysicsWarp(); return; case DiscreteAction.PhysicsTimeWarpMinus: WarpController.DecreasePhysicsWarp(); return; case DiscreteAction.NavballToggle: if (MapView.MapIsEnabled && MapView.fetch != null) { // MapView.fetch.maneuverModeToggle.OnPress.Invoke(); } return; case DiscreteAction.IVAViewToggle: if (CameraManager.Instance != null) { CameraManager.Instance.SetCameraIVA(); } return; case DiscreteAction.CameraViewToggle: if (FlightCamera.fetch != null) { FlightCamera.fetch.SetNextMode(); } return; case DiscreteAction.SASHold: FlightGlobals.ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.SAS, true); return; case DiscreteAction.TogglePrecisionControls: if (FlightInputHandler.fetch != null) { FlightInputHandler.fetch.precisionMode = !FlightInputHandler.fetch.precisionMode; //Change color on flight input gauges manually. Hardcoded colors, but unlikely to change. foreach (var r in FlightInputHandler.fetch.inputGaugeRenderers) { if (FlightInputHandler.fetch.precisionMode) r.material.color = new Color(0.255f, 0.992f, 0.996f); else r.material.color = new Color(0.976f, 0.451f, 0.024f); } } return; case DiscreteAction.ResetTrim: m_Yaw.SetTrim(0.0f); m_Pitch.SetTrim(0.0f); m_Roll.SetTrim(0.0f); return; case DiscreteAction.IVANextCamera: CameraController.Instance.NextIVACamera(); return; case DiscreteAction.IVALookWindow: CameraController.Instance.FocusIVAWindow(); return; } if (m_DisableVesselControls) { return; } // all other actions switch (action) { case DiscreteAction.Stage: Staging.ActivateNextStage(); return; case DiscreteAction.Gear: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Gear); return; case DiscreteAction.Light: EVAController.Instance.ToggleHeadlamp(); FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Light); return; case DiscreteAction.RCS: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.RCS); return; case DiscreteAction.SAS: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.SAS); return; case DiscreteAction.Brakes: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Brakes); return; case DiscreteAction.BrakesHold: FlightGlobals.ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, true); return; case DiscreteAction.Abort: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Abort); return; case DiscreteAction.Custom01: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom01); return; case DiscreteAction.Custom02: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom02); return; case DiscreteAction.Custom03: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom03); return; case DiscreteAction.Custom04: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom04); return; case DiscreteAction.Custom05: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom05); return; case DiscreteAction.Custom06: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom06); return; case DiscreteAction.Custom07: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom07); return; case DiscreteAction.Custom08: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom08); return; case DiscreteAction.Custom09: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom09); return; case DiscreteAction.Custom10: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom10); return; case DiscreteAction.SASHold: FlightGlobals.ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.SAS, true); return; case DiscreteAction.LockStage: if (FlightInputHandler.fetch != null) { FlightInputHandler.fetch.stageLock = !FlightInputHandler.fetch.stageLock; } return; case DiscreteAction.EVAInteract: EVAController.Instance.DoInteract(); return; case DiscreteAction.EVAJump: EVAController.Instance.DoJump(); return; case DiscreteAction.EVAToggleJetpack: EVAController.Instance.ToggleJetpack(); return; case DiscreteAction.EVAAutoRunToggle: EVAController.Instance.ToggleAutorun(); return; case DiscreteAction.EVAPlantFlag: EVAController.Instance.DoPlantFlag(); return; } }
public Bitset GetBitsetForDiscreteBinding(DiscreteAction action) { if (!discreteActionsMap.ContainsKey(action)) return null; return discreteActionsMap[action]; }
} // Required for XML serialization public DiscreteActionEntry(DiscreteAction action, Bitset bitset) { this.Action = action; this.Bitset = bitset; }
public void EvaluateDiscreteActionRelease(ControllerConfiguration controller, DiscreteAction action, FlightCtrlState state) { switch (action) { case DiscreteAction.None: return; case DiscreteAction.YawPlus: m_Yaw.SetIncrement(0); return; case DiscreteAction.YawMinus: m_Yaw.SetIncrement(0); return; case DiscreteAction.PitchPlus: m_Pitch.SetIncrement(0); return; case DiscreteAction.PitchMinus: m_Pitch.SetIncrement(0); return; case DiscreteAction.RollPlus: m_Roll.SetIncrement(0); return; case DiscreteAction.RollMinus: m_Roll.SetIncrement(0); return; case DiscreteAction.XPlus: m_X.SetIncrement(0); return; case DiscreteAction.XMinus: m_X.SetIncrement(0); return; case DiscreteAction.YPlus: m_Y.SetIncrement(0); return; case DiscreteAction.YMinus: m_Y.SetIncrement(0); return; case DiscreteAction.ZPlus: m_Z.SetIncrement(0); return; case DiscreteAction.ZMinus: m_Z.SetIncrement(0); return; case DiscreteAction.ThrottlePlus: m_Throttle.SetIncrement(0); return; case DiscreteAction.ThrottleMinus: m_Throttle.SetIncrement(0); return; case DiscreteAction.CameraZoomPlus: m_CameraZoom.SetIncrement(0); return; case DiscreteAction.CameraZoomMinus: m_CameraZoom.SetIncrement(0); return; case DiscreteAction.CameraXPlus: m_CameraHeading.SetIncrement(0); return; case DiscreteAction.CameraXMinus: m_CameraHeading.SetIncrement(0); return; case DiscreteAction.CameraYPlus: m_CameraPitch.SetIncrement(0); return; case DiscreteAction.CameraYMinus: m_CameraPitch.SetIncrement(0); return; } if (m_DisableVesselControls) { return; } switch (action) { case DiscreteAction.SASHold: FlightGlobals.ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.SAS, false); return; case DiscreteAction.BrakesHold: FlightGlobals.ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, false); return; } }
public void EvaluateDiscreteAction(ControllerConfiguration controller, DiscreteAction action, FlightCtrlState state) { switch (action) { case DiscreteAction.None: return; case DiscreteAction.YawPlus: m_Yaw.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.YawMinus: m_Yaw.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.PitchPlus: m_Pitch.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.PitchMinus: m_Pitch.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.PitchTrimPlus: m_Pitch.SetTrim(Utility.Clamp(m_Pitch.GetTrim() + controller.discreteActionStep, -1.0f, 1.0f)); return; case DiscreteAction.PitchTrimMinus: m_Pitch.SetTrim(Utility.Clamp(m_Pitch.GetTrim() - controller.discreteActionStep, -1.0f, 1.0f)); return; case DiscreteAction.RollPlus: m_Roll.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.RollMinus: m_Roll.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.XPlus: m_X.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.XMinus: m_X.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.YPlus: m_Y.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.YMinus: m_Y.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.ZPlus: m_Z.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.ZMinus: m_Z.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.ThrottlePlus: m_Throttle.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.ThrottleMinus: m_Throttle.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.CutThrottle: m_Throttle.SetValue(-state.mainThrottle); return; case DiscreteAction.FullThrottle: m_Throttle.SetValue(1.0f - state.mainThrottle); return; case DiscreteAction.NextPreset: if (controller.currentPreset >= controller.presets.Count - 1) { return; } controller.currentPreset++; ScreenMessages.PostScreenMessage("PRESET: " + controller.GetCurrentPreset().name.ToUpper(), 1.0f, ScreenMessageStyle.UPPER_CENTER); return; case DiscreteAction.PreviousPreset: if (controller.currentPreset <= 0) { return; } controller.currentPreset--; ScreenMessages.PostScreenMessage("PRESET: " + controller.GetCurrentPreset().name.ToUpper(), 1.0f, ScreenMessageStyle.UPPER_CENTER); return; case DiscreteAction.CyclePresets: controller.currentPreset++; if (controller.currentPreset >= controller.presets.Count) { controller.currentPreset = 0; } ScreenMessages.PostScreenMessage("PRESET: " + controller.GetCurrentPreset().name.ToUpper(), 1.0f, ScreenMessageStyle.LOWER_CENTER); return; case DiscreteAction.CameraZoomPlus: m_CameraZoom.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.CameraZoomMinus: m_CameraZoom.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.CameraXPlus: m_CameraHeading.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.CameraXMinus: m_CameraHeading.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.CameraYPlus: m_CameraPitch.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.CameraYMinus: m_CameraPitch.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.OrbitMapToggle: if (!MapView.MapIsEnabled) { MapView.EnterMapView(); } else { MapView.ExitMapView(); } return; case DiscreteAction.TimeWarpPlus: WarpController.IncreaseWarp(); return; case DiscreteAction.TimeWarpMinus: WarpController.DecreaseWarp(); return; case DiscreteAction.PhysicsTimeWarpPlus: WarpController.IncreasePhysicsWarp(); return; case DiscreteAction.PhysicsTimeWarpMinus: WarpController.DecreasePhysicsWarp(); return; case DiscreteAction.NavballToggle: if (MapView.MapIsEnabled && MapView.fetch != null) { MapView.fetch.maneuverModeToggle.OnPress.Invoke(); } return; case DiscreteAction.IVAViewToggle: if (CameraManager.Instance != null) { CameraManager.Instance.SetCameraIVA(); } return; case DiscreteAction.CameraViewToggle: if (FlightCamera.fetch != null) { FlightCamera.fetch.SetNextMode(); } return; case DiscreteAction.SASHold: FlightGlobals.ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.SAS, true); return; case DiscreteAction.TogglePrecisionControls: if (FlightInputHandler.fetch != null) { FlightInputHandler.fetch.precisionMode = !FlightInputHandler.fetch.precisionMode; //Change color on flight input gauges manually. Hardcoded colors, but unlikely to change. foreach (var r in FlightInputHandler.fetch.inputGaugeRenderers) { if (FlightInputHandler.fetch.precisionMode) { r.material.color = new Color(0.255f, 0.992f, 0.996f); } else { r.material.color = new Color(0.976f, 0.451f, 0.024f); } } } return; case DiscreteAction.ResetTrim: m_Yaw.SetTrim(0.0f); m_Pitch.SetTrim(0.0f); m_Roll.SetTrim(0.0f); state.ResetTrim(); return; case DiscreteAction.IVANextCamera: CameraController.Instance.NextIVACamera(); return; case DiscreteAction.IVALookWindow: CameraController.Instance.FocusIVAWindow(); return; } if (m_DisableVesselControls) { return; } // all other actions switch (action) { case DiscreteAction.Stage: Staging.ActivateNextStage(); return; case DiscreteAction.Gear: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Gear); return; case DiscreteAction.Light: EVAController.Instance.ToggleHeadlamp(); FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Light); return; case DiscreteAction.RCS: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.RCS); return; case DiscreteAction.SAS: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.SAS); return; case DiscreteAction.Brakes: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Brakes); return; case DiscreteAction.BrakesHold: FlightGlobals.ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, true); return; case DiscreteAction.Abort: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Abort); return; case DiscreteAction.Custom01: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom01); return; case DiscreteAction.Custom02: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom02); return; case DiscreteAction.Custom03: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom03); return; case DiscreteAction.Custom04: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom04); return; case DiscreteAction.Custom05: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom05); return; case DiscreteAction.Custom06: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom06); return; case DiscreteAction.Custom07: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom07); return; case DiscreteAction.Custom08: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom08); return; case DiscreteAction.Custom09: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom09); return; case DiscreteAction.Custom10: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom10); return; case DiscreteAction.SASHold: FlightGlobals.ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.SAS, true); return; case DiscreteAction.LockStage: if (FlightInputHandler.fetch != null) { FlightInputHandler.fetch.stageLock = !FlightInputHandler.fetch.stageLock; } return; case DiscreteAction.EVAInteract: EVAController.Instance.DoInteract(); return; case DiscreteAction.EVAJump: EVAController.Instance.DoJump(); return; case DiscreteAction.EVAToggleJetpack: EVAController.Instance.ToggleJetpack(); return; case DiscreteAction.EVAAutoRunToggle: EVAController.Instance.ToggleAutorun(); return; case DiscreteAction.EVAPlantFlag: EVAController.Instance.DoPlantFlag(); return; } }
public static string DiscreteActionToString(DiscreteAction action) { switch (action) { case DiscreteAction.None: return("None"); case DiscreteAction.YawPlus: return("Yaw+"); case DiscreteAction.YawMinus: return("Yaw-"); case DiscreteAction.PitchPlus: return("Pitch+"); case DiscreteAction.PitchMinus: return("Pitch-"); case DiscreteAction.RollPlus: return("Roll+"); case DiscreteAction.RollMinus: return("Roll-"); case DiscreteAction.XPlus: return("Translate X+"); case DiscreteAction.XMinus: return("Translate X-"); case DiscreteAction.YPlus: return("Translate Y+"); case DiscreteAction.YMinus: return("Translate Y-"); case DiscreteAction.ZPlus: return("Translate Z+"); case DiscreteAction.ZMinus: return("Translate Z-"); case DiscreteAction.ThrottlePlus: return("Throttle+"); case DiscreteAction.ThrottleMinus: return("Throttle-"); case DiscreteAction.Stage: return("Stage"); case DiscreteAction.Gear: return("Gear"); case DiscreteAction.Light: return("Light"); case DiscreteAction.RCS: return("RCS"); case DiscreteAction.SAS: return("SAS"); case DiscreteAction.Brakes: return("Brakes"); case DiscreteAction.Abort: return("Abort"); case DiscreteAction.Custom01: return("Custom 1"); case DiscreteAction.Custom02: return("Custom 2"); case DiscreteAction.Custom03: return("Custom 3"); case DiscreteAction.Custom04: return("Custom 4"); case DiscreteAction.Custom05: return("Custom 5"); case DiscreteAction.Custom06: return("Custom 6"); case DiscreteAction.Custom07: return("Custom 7"); case DiscreteAction.Custom08: return("Custom 8"); case DiscreteAction.Custom09: return("Custom 9"); case DiscreteAction.Custom10: return("Custom 10"); case DiscreteAction.EVAToggleJetpack: return("Toggle jetpack (EVA)"); case DiscreteAction.EVAToggleHeadlamps: return("Headlamps (EVA) [Toggle]"); case DiscreteAction.CutThrottle: return("Cut throttle"); case DiscreteAction.FullThrottle: return("Full throttle"); case DiscreteAction.NextPreset: return("Next preset"); case DiscreteAction.PreviousPreset: return("Previous preset"); case DiscreteAction.CyclePresets: return("Cycle presets"); case DiscreteAction.CameraZoomPlus: return("Camera zoom+"); case DiscreteAction.CameraZoomMinus: return("Camera zoom-"); case DiscreteAction.CameraXPlus: return("Camera X+"); case DiscreteAction.CameraXMinus: return("Camera X-"); case DiscreteAction.CameraYPlus: return("Camera Y+"); case DiscreteAction.CameraYMinus: return("Camera Y-"); case DiscreteAction.OrbitMapToggle: return("Orbit map [Toggle]"); case DiscreteAction.TimeWarpPlus: return("TimeWarp+"); case DiscreteAction.TimeWarpMinus: return("TimeWarp-"); case DiscreteAction.PhysicsTimeWarpPlus: return("Physics TimeWarp+"); case DiscreteAction.PhysicsTimeWarpMinus: return("Physics TimeWarp-"); case DiscreteAction.NavballToggle: return("Navball [Toggle]"); case DiscreteAction.IVAViewToggle: return("IVA view [Toggle]"); case DiscreteAction.CameraViewToggle: return("Camera view [Toggle]"); case DiscreteAction.SASHold: return("SAS (Hold)"); case DiscreteAction.LockStage: return("Lock staging"); case DiscreteAction.TogglePrecisionControls: return("Precision controls [Toggle]"); case DiscreteAction.ResetTrim: return("Reset trim"); default: return("Unknown action"); } }
public void EvaluateDiscreteAction(ControllerConfiguration controller, DiscreteAction action, FlightCtrlState state) { KerbalEVA eva = null; if (FlightGlobals.ActiveVessel.isEVA) { eva = FlightGlobals.ActiveVessel.GetComponent <KerbalEVA>(); } switch (action) { case DiscreteAction.None: return; case DiscreteAction.YawPlus: m_Yaw.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.YawMinus: m_Yaw.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.PitchPlus: m_Pitch.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.PitchMinus: m_Pitch.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.RollPlus: m_Roll.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.RollMinus: m_Roll.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.XPlus: m_X.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.XMinus: m_X.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.YPlus: m_Y.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.YMinus: m_Y.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.ZPlus: m_Z.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.ZMinus: m_Z.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.ThrottlePlus: m_Throttle.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.ThrottleMinus: m_Throttle.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.Stage: Staging.ActivateNextStage(); return; case DiscreteAction.Gear: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Gear); return; case DiscreteAction.Light: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Light); return; case DiscreteAction.RCS: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.RCS); return; case DiscreteAction.SAS: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.SAS); return; case DiscreteAction.Brakes: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Brakes); return; case DiscreteAction.Abort: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Abort); return; case DiscreteAction.Custom01: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom01); return; case DiscreteAction.Custom02: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom02); return; case DiscreteAction.Custom03: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom03); return; case DiscreteAction.Custom04: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom04); return; case DiscreteAction.Custom05: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom05); return; case DiscreteAction.Custom06: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom06); return; case DiscreteAction.Custom07: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom07); return; case DiscreteAction.Custom08: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom08); return; case DiscreteAction.Custom09: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom09); return; case DiscreteAction.Custom10: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom10); return; case DiscreteAction.EVAToggleJetpack: if (eva != null) { eva.JetpackDeployed = !eva.JetpackDeployed; } return; case DiscreteAction.EVAToggleHeadlamps: if (eva != null) { eva.lampOn = !eva.lampOn; } return; case DiscreteAction.CutThrottle: m_Throttle.SetValue(-state.mainThrottle); return; case DiscreteAction.FullThrottle: m_Throttle.SetValue(1.0f - state.mainThrottle); return; case DiscreteAction.NextPreset: if (controller.currentPreset >= controller.presets.Count - 1) { return; } controller.currentPreset++; ScreenMessages.PostScreenMessage("PRESET: " + controller.GetCurrentPreset().name.ToUpper(), 1.0f, ScreenMessageStyle.UPPER_CENTER); return; case DiscreteAction.PreviousPreset: if (controller.currentPreset <= 0) { return; } controller.currentPreset--; ScreenMessages.PostScreenMessage("PRESET: " + controller.GetCurrentPreset().name.ToUpper(), 1.0f, ScreenMessageStyle.UPPER_CENTER); return; case DiscreteAction.CyclePresets: controller.currentPreset++; if (controller.currentPreset >= controller.presets.Count) { controller.currentPreset = 0; } ScreenMessages.PostScreenMessage("PRESET: " + controller.GetCurrentPreset().name.ToUpper(), 1.0f, ScreenMessageStyle.LOWER_CENTER); return; case DiscreteAction.CameraZoomPlus: m_CameraZoom.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.CameraZoomMinus: m_CameraZoom.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.CameraXPlus: m_CameraHeading.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.CameraXMinus: m_CameraHeading.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.CameraYPlus: m_CameraPitch.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.CameraYMinus: m_CameraPitch.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.OrbitMapToggle: if (!MapView.MapIsEnabled) { MapView.EnterMapView(); } else { MapView.ExitMapView(); } return; case DiscreteAction.TimeWarpPlus: WarpController.IncreaseWarp(); return; case DiscreteAction.TimeWarpMinus: WarpController.DecreaseWarp(); return; case DiscreteAction.PhysicsTimeWarpPlus: WarpController.IncreasePhysicsWarp(); return; case DiscreteAction.PhysicsTimeWarpMinus: WarpController.DecreasePhysicsWarp(); return; case DiscreteAction.NavballToggle: if (MapView.MapIsEnabled && MapView.fetch != null) { MapView.fetch.maneuverModeToggle.OnPress.Invoke(); } return; case DiscreteAction.IVAViewToggle: if (CameraManager.Instance != null) { CameraManager.Instance.SetCameraIVA(); } return; case DiscreteAction.CameraViewToggle: if (FlightCamera.fetch != null) { FlightCamera.fetch.SetNextMode(); } return; case DiscreteAction.SASHold: FlightGlobals.ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.SAS, true); return; case DiscreteAction.LockStage: if (FlightInputHandler.fetch != null) { FlightInputHandler.fetch.stageLock = !FlightInputHandler.fetch.stageLock; } return; case DiscreteAction.TogglePrecisionControls: if (FlightInputHandler.fetch != null) { FlightInputHandler.fetch.precisionMode = !FlightInputHandler.fetch.precisionMode; } return; case DiscreteAction.ResetTrim: m_Yaw.SetTrim(0.0f); m_Pitch.SetTrim(0.0f); m_Roll.SetTrim(0.0f); state.ResetTrim(); return; } }
public static string DiscreteActionToString(DiscreteAction action) { switch (action) { case DiscreteAction.None: return("None"); case DiscreteAction.YawPlus: return("Yaw+"); case DiscreteAction.YawMinus: return("Yaw-"); case DiscreteAction.PitchPlus: return("Pitch+"); case DiscreteAction.PitchMinus: return("Pitch-"); case DiscreteAction.PitchTrimPlus: return("Pitch Trim+"); case DiscreteAction.PitchTrimMinus: return("Pitch Trim-"); case DiscreteAction.RollPlus: return("Roll+"); case DiscreteAction.RollMinus: return("Roll-"); case DiscreteAction.XPlus: return("Translate X+"); case DiscreteAction.XMinus: return("Translate X-"); case DiscreteAction.YPlus: return("Translate Y+"); case DiscreteAction.YMinus: return("Translate Y-"); case DiscreteAction.ZPlus: return("Translate Z+"); case DiscreteAction.ZMinus: return("Translate Z-"); case DiscreteAction.ThrottlePlus: return("Throttle+"); case DiscreteAction.ThrottleMinus: return("Throttle-"); case DiscreteAction.Stage: return("Stage"); case DiscreteAction.Gear: return("Gear"); case DiscreteAction.Light: return("Light"); case DiscreteAction.RCS: return("RCS"); case DiscreteAction.SAS: return("SAS"); case DiscreteAction.Brakes: return("Brakes (Toggle)"); case DiscreteAction.BrakesHold: return("Brakes (Hold)"); case DiscreteAction.Abort: return("Abort"); case DiscreteAction.Custom01: return("Custom 1"); case DiscreteAction.Custom02: return("Custom 2"); case DiscreteAction.Custom03: return("Custom 3"); case DiscreteAction.Custom04: return("Custom 4"); case DiscreteAction.Custom05: return("Custom 5"); case DiscreteAction.Custom06: return("Custom 6"); case DiscreteAction.Custom07: return("Custom 7"); case DiscreteAction.Custom08: return("Custom 8"); case DiscreteAction.Custom09: return("Custom 9"); case DiscreteAction.Custom10: return("Custom 10"); case DiscreteAction.EVAToggleJetpack: return("EVA Jetpack [Toggle]"); case DiscreteAction.EVAInteract: return("EVA Interact"); case DiscreteAction.EVAJump: return("EVA Jump"); case DiscreteAction.EVAPlantFlag: return("EVA Plant Flag"); case DiscreteAction.EVAAutoRunToggle: return("EVA AutoRun [Toggle]"); case DiscreteAction.CutThrottle: return("Cut Throttle"); case DiscreteAction.FullThrottle: return("Full Throttle"); case DiscreteAction.NextPreset: return("Next Preset"); case DiscreteAction.PreviousPreset: return("Previous Preset"); case DiscreteAction.CyclePresets: return("Cycle Presets"); case DiscreteAction.CameraZoomPlus: return("Camera Zoom+"); case DiscreteAction.CameraZoomMinus: return("Camera Zoom-"); case DiscreteAction.CameraXPlus: return("Camera X+"); case DiscreteAction.CameraXMinus: return("Camera X-"); case DiscreteAction.CameraYPlus: return("Camera Y+"); case DiscreteAction.CameraYMinus: return("Camera Y-"); case DiscreteAction.OrbitMapToggle: return("Orbit Map [Toggle]"); case DiscreteAction.TimeWarpPlus: return("TimeWarp+"); case DiscreteAction.TimeWarpMinus: return("TimeWarp-"); case DiscreteAction.PhysicsTimeWarpPlus: return("Physics TimeWarp+"); case DiscreteAction.PhysicsTimeWarpMinus: return("Physics TimeWarp-"); case DiscreteAction.NavballToggle: return("Navball [Toggle]"); case DiscreteAction.IVAViewToggle: return("IVA View [Toggle]"); case DiscreteAction.CameraViewToggle: return("Camera View [Toggle]"); case DiscreteAction.SASHold: return("SAS (Hold)"); case DiscreteAction.LockStage: return("Lock Staging"); case DiscreteAction.TogglePrecisionControls: return("Precision Controls [Toggle]"); case DiscreteAction.ResetTrim: return("Reset Trim"); case DiscreteAction.IVANextCamera: return("IVA Next Kerbal"); case DiscreteAction.IVALookWindow: return("IVA Focus Window"); default: return("Unknown Action"); } }
public override void DoWindow(int window) { GUI.DragWindow(new Rect(0, 0, 10000, 20)); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("X", GUILayout.Height(16)) || m_Controller == null || m_Controller.iface == null) { shouldBeDestroyed = true; if (m_Controller != null) { m_Controller.presetEditorOpen = false; AdvancedFlyByWire.Instance.SaveState(null); } GUILayout.EndHorizontal(); return; } GUILayout.EndHorizontal(); var currentPreset = m_Controller.GetCurrentPreset(); GUILayout.BeginHorizontal(); GUILayout.Label("Preset: "); currentPreset.name = GUILayout.TextField(currentPreset.name, GUILayout.Width(256)); if (m_Controller.currentPreset > 0) { if (GUILayout.Button("<")) { m_Controller.currentPreset--; } } else { GUI.enabled = false; GUILayout.Button("<"); GUI.enabled = true; } if (m_Controller.currentPreset < m_Controller.presets.Count - 1) { if (GUILayout.Button(">")) { m_Controller.currentPreset++; } } else { GUI.enabled = false; GUILayout.Button(">"); GUI.enabled = true; } if (GUILayout.Button("New")) { m_Controller.presets.Add(new ControllerPreset()); m_Controller.currentPreset = m_Controller.presets.Count - 1; } if (GUILayout.Button("Clone")) { var preset = m_Controller.presets[m_Controller.currentPreset]; var newPreset = new ControllerPreset(); foreach (var pair in preset.continuousActionsMap) { newPreset.continuousActionsMap.Add(pair.Key, new KeyValuePair <Bitset, int>(pair.Value.Key.Copy(), pair.Value.Value)); } foreach (var pair in preset.discreteActionsMap) { newPreset.discreteActionsMap.Add(pair.Key, pair.Value.Copy()); } m_Controller.presets.Add(newPreset); m_Controller.currentPreset = m_Controller.presets.Count - 1; } string destructiveRemoveLabel = "Delete"; if (m_DestructiveActionWait) { destructiveRemoveLabel = "Sure?"; } if (m_Controller.presets.Count <= 1 || m_Controller.currentPreset == 0) { GUI.enabled = false; } if (GUILayout.Button(destructiveRemoveLabel)) { if (m_DestructiveActionWait) { if (m_Controller.presets.Count > 1) { m_Controller.presets.RemoveAt(m_Controller.currentPreset); m_Controller.currentPreset--; if (m_Controller.currentPreset < 0) { m_Controller.currentPreset = 0; } m_DestructiveActionWait = false; m_DestructiveActionTimer = 0.0f; } } else { m_DestructiveActionWait = true; m_DestructiveActionTimer = 2.0f; } } GUI.enabled = true; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (m_ChooseDiscreteAction || m_ChooseContinuousAction) { GUI.enabled = false; } if (GUILayout.Button("Add button")) { m_ChooseDiscreteAction = true; m_ChosenDiscreteAction = DiscreteAction.None; m_ChooseDiscreteActionRect = new Rect(Input.mousePosition.x, Screen.height - Input.mousePosition.y, 256, 512); } if (GUILayout.Button("Add axis")) { m_ChooseContinuousAction = true; m_ChosenContinuousAction = ContinuousAction.None; m_ChooseContinuousActionRect = new Rect(Input.mousePosition.x, Screen.height - Input.mousePosition.y, 256, 512); } GUI.enabled = true; GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); m_ScrollPosition = GUILayout.BeginScrollView(m_ScrollPosition); foreach (var action in (ContinuousAction[])Enum.GetValues(typeof(ContinuousAction))) { if (action == ContinuousAction.None) { continue; } var axisBitsetPair = currentPreset.GetBitsetForContinuousBinding(action); if (axisBitsetPair.Value == null) { continue; } GUILayout.BeginHorizontal(); GUILayout.Label(Stringify.ContinuousActionToString(action)); GUILayout.FlexibleSpace(); string label = ""; if (m_CurrentlyEditingContinuousAction == action) { label = "Press desired combination"; var buttonsMask = m_Controller.iface.GetButtonsMask(); for (int i = 0; i < m_Controller.iface.GetAxesCount(); i++) { if (Math.Abs(m_Controller.iface.GetAxisState(i) - axisSnapshot[i]) > 0.1 && m_ClickSleepTimer == 0.0f) { currentPreset.SetContinuousBinding(i, buttonsMask, action, false); m_CurrentlyEditingContinuousAction = ContinuousAction.None; } } } axisBitsetPair = currentPreset.GetBitsetForContinuousBinding(action); if (m_CurrentlyEditingContinuousAction != action) { if (axisBitsetPair.Value == null) { label = "Click to assign"; } else { label = m_Controller.iface.ConvertMaskToName(axisBitsetPair.Value, true, axisBitsetPair.Key); } } if (GUILayout.Button(label, GUILayout.Width(220))) { if (m_CurrentlyEditingContinuousAction != action) { m_CurrentlyEditingContinuousAction = action; m_CurrentlyEditingDiscreteAction = DiscreteAction.None; m_ClickSleepTimer = 0.25f; for (int i = 0; i < m_Controller.iface.GetAxesCount(); i++) { axisSnapshot[i] = m_Controller.iface.GetAxisState(i); } } m_CurrentMask = null; } GUILayout.Space(8); var inverted = GUILayout.Toggle(currentPreset.IsContinuousBindingInverted(action), "", GUILayout.Width(32)); currentPreset.SetContinuousBindingInverted(action, inverted); GUILayout.Label("Invert", GUILayout.Width(40)); GUILayout.Space(8); if (GUILayout.Button("X")) { currentPreset.UnsetContinuousBinding(action); m_CurrentlyEditingContinuousAction = ContinuousAction.None; m_CurrentlyEditingDiscreteAction = DiscreteAction.None; } GUILayout.EndHorizontal(); GUILayout.Space(4); } foreach (var action in (DiscreteAction[])Enum.GetValues(typeof(DiscreteAction))) { if (action == DiscreteAction.None) { continue; } var bitset = currentPreset.GetBitsetForDiscreteBinding(action); if (bitset == null) { continue; } GUILayout.BeginHorizontal(); GUILayout.Label(Stringify.DiscreteActionToString(action)); GUILayout.FlexibleSpace(); string label = ""; if (m_CurrentlyEditingDiscreteAction == action) { label = "Press desired combination"; if (m_CurrentMask != null && m_ClickSleepTimer == 0.0f) { currentPreset.SetDiscreteBinding(m_CurrentMask, action); m_CurrentMask = null; m_CurrentlyEditingDiscreteAction = DiscreteAction.None; } } bitset = currentPreset.GetBitsetForDiscreteBinding(action); if (m_CurrentlyEditingDiscreteAction != action) { if (bitset == null) { label = "Click to assign"; } else { label = m_Controller.iface.ConvertMaskToName(bitset); } } if (GUILayout.Button(label, GUILayout.Width(220))) { if (m_CurrentlyEditingDiscreteAction != action) { m_CurrentlyEditingDiscreteAction = action; m_CurrentlyEditingContinuousAction = ContinuousAction.None; m_ClickSleepTimer = 0.25f; } m_CurrentMask = null; } GUILayout.Space(96); if (GUILayout.Button("X")) { currentPreset.UnsetDiscreteBinding(action); m_CurrentlyEditingContinuousAction = ContinuousAction.None; m_CurrentlyEditingDiscreteAction = DiscreteAction.None; } GUILayout.EndHorizontal(); GUILayout.Space(0); } GUILayout.EndScrollView(); }
public void EvaluateDiscreteAction(ControllerConfiguration controller, DiscreteAction action, FlightCtrlState state) { switch (action) { case DiscreteAction.None: return; case DiscreteAction.YawPlus: m_Yaw.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.YawMinus: m_Yaw.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.PitchPlus: m_Pitch.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.PitchMinus: m_Pitch.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.PitchTrimPlus: m_Pitch.SetTrim(Utility.Clamp(m_Pitch.GetTrim() + controller.discreteActionStep, -1.0f, 1.0f)); return; case DiscreteAction.PitchTrimMinus: m_Pitch.SetTrim(Utility.Clamp(m_Pitch.GetTrim() - controller.discreteActionStep, -1.0f, 1.0f)); return; case DiscreteAction.RollPlus: m_Roll.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.RollMinus: m_Roll.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.XPlus: m_X.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.XMinus: m_X.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.YPlus: m_Y.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.YMinus: m_Y.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.ZPlus: m_Z.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.ZMinus: m_Z.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.ThrottlePlus: m_Throttle.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.ThrottleMinus: m_Throttle.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.CutThrottle: m_Throttle.SetValue(-state.mainThrottle); return; case DiscreteAction.FullThrottle: m_Throttle.SetValue(1.0f - state.mainThrottle); return; case DiscreteAction.NextPreset: if (controller.currentPreset >= controller.presets.Count - 1) { return; } controller.currentPreset++; ScreenMessages.PostScreenMessage("PRESET: " + controller.GetCurrentPreset().name.ToUpper(), 1.0f, ScreenMessageStyle.UPPER_CENTER); return; case DiscreteAction.PreviousPreset: if (controller.currentPreset <= 0) { return; } controller.currentPreset--; ScreenMessages.PostScreenMessage("PRESET: " + controller.GetCurrentPreset().name.ToUpper(), 1.0f, ScreenMessageStyle.UPPER_CENTER); return; case DiscreteAction.CyclePresets: controller.currentPreset++; if (controller.currentPreset >= controller.presets.Count) { controller.currentPreset = 0; } ScreenMessages.PostScreenMessage("PRESET: " + controller.GetCurrentPreset().name.ToUpper(), 1.0f, ScreenMessageStyle.LOWER_CENTER); return; case DiscreteAction.CameraZoomPlus: m_CameraZoom.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.CameraZoomMinus: m_CameraZoom.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.CameraXPlus: m_CameraHeading.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.CameraXMinus: m_CameraHeading.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.CameraYPlus: m_CameraPitch.SetIncrement(1, controller.discreteActionStep); return; case DiscreteAction.CameraYMinus: m_CameraPitch.SetIncrement(-1, controller.discreteActionStep); return; case DiscreteAction.OrbitMapToggle: if (!MapView.MapIsEnabled) { MapView.EnterMapView(); } else { MapView.ExitMapView(); } return; case DiscreteAction.TimeWarpPlus: WarpController.IncreaseWarp(); return; case DiscreteAction.TimeWarpMinus: WarpController.DecreaseWarp(); return; case DiscreteAction.PhysicsTimeWarpPlus: WarpController.IncreasePhysicsWarp(); return; case DiscreteAction.PhysicsTimeWarpMinus: WarpController.DecreasePhysicsWarp(); return; case DiscreteAction.StopWarp: WarpController.StopWarp(); return; case DiscreteAction.NavballToggle: if (MapView.MapIsEnabled && MapView.fetch != null) { // MapView.fetch.maneuverModeToggle.OnPress.Invoke(); } return; case DiscreteAction.IVAViewToggle: if (CameraManager.Instance != null) { CameraManager.Instance.SetCameraIVA(); } return; case DiscreteAction.CameraViewToggle: if (FlightCamera.fetch != null) { FlightCamera.fetch.SetNextMode(); } return; case DiscreteAction.SASHold: FlightGlobals.ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.SAS, true); return; case DiscreteAction.SASStabilityAssist: setAutopilotMode(VesselAutopilot.AutopilotMode.StabilityAssist, 0); return; case DiscreteAction.SASPrograde: setAutopilotMode(VesselAutopilot.AutopilotMode.Prograde, 1); return; case DiscreteAction.SASRetrograde: setAutopilotMode(VesselAutopilot.AutopilotMode.Retrograde, 2); return; case DiscreteAction.SASNormal: setAutopilotMode(VesselAutopilot.AutopilotMode.Normal, 3); return; case DiscreteAction.SASAntinormal: setAutopilotMode(VesselAutopilot.AutopilotMode.Antinormal, 4); return; case DiscreteAction.SASRadialIn: setAutopilotMode(VesselAutopilot.AutopilotMode.RadialIn, 5); return; case DiscreteAction.SASRadialOut: setAutopilotMode(VesselAutopilot.AutopilotMode.RadialOut, 6); return; case DiscreteAction.SASManeuver: setAutopilotMode(VesselAutopilot.AutopilotMode.Maneuver, 7); return; case DiscreteAction.SASTarget: setAutopilotMode(VesselAutopilot.AutopilotMode.Target, 8); return; case DiscreteAction.SASAntiTarget: setAutopilotMode(VesselAutopilot.AutopilotMode.AntiTarget, 9); return; case DiscreteAction.SASManeuverOrTarget: if (!setAutopilotMode(VesselAutopilot.AutopilotMode.Maneuver, 7)) { setAutopilotMode(VesselAutopilot.AutopilotMode.Target, 8); } ; return; case DiscreteAction.TogglePrecisionControls: if (FlightInputHandler.fetch != null) { FlightInputHandler.fetch.precisionMode = !FlightInputHandler.fetch.precisionMode; GameEvents.Input.OnPrecisionModeToggle.Fire(FlightInputHandler.fetch.precisionMode); } return; case DiscreteAction.ResetTrim: m_Yaw.SetTrim(0.0f); m_Pitch.SetTrim(0.0f); m_Roll.SetTrim(0.0f); return; case DiscreteAction.IVANextCamera: CameraController.Instance.NextIVACamera(); return; case DiscreteAction.IVALookWindow: CameraController.Instance.FocusIVAWindow(); return; } if (m_DisableVesselControls) { return; } // all other actions switch (action) { case DiscreteAction.Stage: KSP.UI.Screens.StageManager.ActivateNextStage(); return; case DiscreteAction.Gear: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Gear); return; case DiscreteAction.Light: EVAController.Instance.ToggleHeadlamp(); FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Light); return; case DiscreteAction.RCS: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.RCS); return; case DiscreteAction.SAS: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.SAS); return; case DiscreteAction.Brakes: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Brakes); return; case DiscreteAction.BrakesHold: FlightGlobals.ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, true); return; case DiscreteAction.Abort: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Abort); return; case DiscreteAction.Custom01: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom01); return; case DiscreteAction.Custom02: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom02); return; case DiscreteAction.Custom03: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom03); return; case DiscreteAction.Custom04: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom04); return; case DiscreteAction.Custom05: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom05); return; case DiscreteAction.Custom06: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom06); return; case DiscreteAction.Custom07: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom07); return; case DiscreteAction.Custom08: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom08); return; case DiscreteAction.Custom09: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom09); return; case DiscreteAction.Custom10: FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom10); return; case DiscreteAction.SASHold: FlightGlobals.ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.SAS, true); return; case DiscreteAction.LockStage: if (FlightInputHandler.fetch != null) { FlightInputHandler.fetch.stageLock = !FlightInputHandler.fetch.stageLock; } return; case DiscreteAction.EVAInteract: EVAController.Instance.DoInteract(); return; case DiscreteAction.EVAJump: EVAController.Instance.DoJump(); return; case DiscreteAction.EVAToggleJetpack: EVAController.Instance.ToggleJetpack(); return; case DiscreteAction.EVAAutoRunToggle: EVAController.Instance.ToggleAutorun(); return; case DiscreteAction.EVAPlantFlag: EVAController.Instance.DoPlantFlag(); return; } }
public virtual void DoWindow(int window) { GUI.DragWindow(new Rect(0, 0, 10000, 20)); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("X", GUILayout.Height(16)) || m_Controller == null || m_Controller.iface == null) { shouldBeDestroyed = true; if (m_Controller != null) { m_Controller.presetEditorOpen = false; } } GUILayout.EndHorizontal(); var currentPreset = m_Controller.GetCurrentPreset(); GUILayout.BeginHorizontal(); GUILayout.Label("Preset: "); currentPreset.name = GUILayout.TextField(currentPreset.name, GUILayout.Width(256)); if (m_Controller.currentPreset > 0) { if (GUILayout.Button("<")) { m_Controller.currentPreset--; } } else { GUI.enabled = false; GUILayout.Button("<"); GUI.enabled = true; } if (m_Controller.currentPreset < m_Controller.presets.Count - 1) { if (GUILayout.Button(">")) { m_Controller.currentPreset++; } } else { GUI.enabled = false; GUILayout.Button(">"); GUI.enabled = true; } if (GUILayout.Button("New")) { m_Controller.presets.Add(new ControllerPreset()); m_Controller.currentPreset = m_Controller.presets.Count - 1; } string destructiveRemoveLabel = "Delete"; if (m_DestructiveActionWait) { destructiveRemoveLabel = "Sure?"; } if (m_Controller.presets.Count <= 1) { GUI.enabled = false; } if (GUILayout.Button(destructiveRemoveLabel)) { if (m_DestructiveActionWait) { if (m_Controller.presets.Count > 1) { m_Controller.presets.RemoveAt(m_Controller.currentPreset); m_Controller.currentPreset--; if (m_Controller.currentPreset < 0) { m_Controller.currentPreset = 0; } m_DestructiveActionWait = false; m_DestructiveActionTimer = 0.0f; } } else { m_DestructiveActionWait = true; m_DestructiveActionTimer = 2.0f; } } GUI.enabled = true; GUILayout.EndHorizontal(); m_ScrollPosition = GUILayout.BeginScrollView(m_ScrollPosition); GUILayout.Label("Continuous actions"); foreach (var action in (ContinuousAction[])Enum.GetValues(typeof(ContinuousAction))) { if (action == ContinuousAction.None) { continue; } GUILayout.BeginHorizontal(); GUILayout.Label(Stringify.ContinuousActionToString(action)); GUILayout.FlexibleSpace(); string label = ""; var axisBitsetPair = currentPreset.GetBitsetForContinuousBinding(action); if (m_CurrentlyEditingContinuousAction == action) { label = "Press desired combination"; for (int i = 0; i < m_Controller.iface.GetAxesCount(); i++) { if (Math.Abs(m_Controller.iface.GetAxisState(i) - axisSnapshot[i]) > 0.1 && m_ClickSleepTimer == 0.0f) { currentPreset.SetContinuousBinding(i, m_Controller.iface.GetButtonsMask(), action); m_CurrentlyEditingContinuousAction = ContinuousAction.None; } } } axisBitsetPair = currentPreset.GetBitsetForContinuousBinding(action); if (m_CurrentlyEditingContinuousAction != action) { if (axisBitsetPair.Value == null) { label = "Click to assign"; } else { label = m_Controller.iface.ConvertMaskToName(axisBitsetPair.Value, true, axisBitsetPair.Key); } } if (GUILayout.Button(label, GUILayout.Width(256))) { if (m_CurrentlyEditingContinuousAction != action) { m_CurrentlyEditingContinuousAction = action; m_CurrentlyEditingDiscreteAction = DiscreteAction.None; m_ClickSleepTimer = 0.25f; for (int i = 0; i < m_Controller.iface.GetAxesCount(); i++) { axisSnapshot[i] = m_Controller.iface.GetAxisState(i); } } m_CurrentMask = null; } if (GUILayout.Button("X")) { currentPreset.UnsetContinuousBinding(action); m_CurrentlyEditingContinuousAction = ContinuousAction.None; m_CurrentlyEditingDiscreteAction = DiscreteAction.None; } GUILayout.EndHorizontal(); } GUILayout.Label("Discrete actions"); foreach (var action in (DiscreteAction[])Enum.GetValues(typeof(DiscreteAction))) { if (action == DiscreteAction.None) { continue; } GUILayout.BeginHorizontal(); GUILayout.Label(Stringify.DiscreteActionToString(action)); GUILayout.FlexibleSpace(); string label = ""; var bitset = currentPreset.GetBitsetForDiscreteBinding(action); if (m_CurrentlyEditingDiscreteAction == action) { label = "Press desired combination"; if (m_CurrentMask != null && m_ClickSleepTimer == 0.0f) { currentPreset.SetDiscreteBinding(m_CurrentMask, action); m_CurrentMask = null; m_CurrentlyEditingDiscreteAction = DiscreteAction.None; } } bitset = currentPreset.GetBitsetForDiscreteBinding(action); if (m_CurrentlyEditingDiscreteAction != action) { if (bitset == null) { label = "Click to assign"; } else { label = m_Controller.iface.ConvertMaskToName(bitset); } } if (GUILayout.Button(label, GUILayout.Width(256))) { if (m_CurrentlyEditingDiscreteAction != action) { m_CurrentlyEditingDiscreteAction = action; m_CurrentlyEditingContinuousAction = ContinuousAction.None; m_ClickSleepTimer = 0.25f; } m_CurrentMask = null; } if (GUILayout.Button("X")) { currentPreset.UnsetDiscreteBinding(action); m_CurrentlyEditingContinuousAction = ContinuousAction.None; m_CurrentlyEditingDiscreteAction = DiscreteAction.None; } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); }
public void SetDiscreteBinding(Bitset state, DiscreteAction action) { foreach (var keyVal in discreteActionsMap) { if(keyVal.Value.Equals(state)) { discreteActionsMap.Remove(keyVal.Key); break; } } discreteActionsMap[action] = state; }
public void EvaluateDiscreteActionRelease(ControllerConfiguration controller, DiscreteAction action, FlightCtrlState state) { switch (action) { case DiscreteAction.None: return; case DiscreteAction.YawPlus: m_Yaw.SetIncrement(0); return; case DiscreteAction.YawMinus: m_Yaw.SetIncrement(0); return; case DiscreteAction.PitchPlus: m_Pitch.SetIncrement(0); return; case DiscreteAction.PitchMinus: m_Pitch.SetIncrement(0); return; case DiscreteAction.RollPlus: m_Roll.SetIncrement(0); return; case DiscreteAction.RollMinus: m_Roll.SetIncrement(0); return; case DiscreteAction.XPlus: m_X.SetIncrement(0); return; case DiscreteAction.XMinus: m_X.SetIncrement(0); return; case DiscreteAction.YPlus: m_Y.SetIncrement(0); return; case DiscreteAction.YMinus: m_Y.SetIncrement(0); return; case DiscreteAction.ZPlus: m_Z.SetIncrement(0); return; case DiscreteAction.ZMinus: m_Z.SetIncrement(0); return; case DiscreteAction.ThrottlePlus: m_Throttle.SetIncrement(0); return; case DiscreteAction.ThrottleMinus: m_Throttle.SetIncrement(0); return; case DiscreteAction.CameraZoomPlus: m_CameraZoom.SetIncrement(0); return; case DiscreteAction.CameraZoomMinus: m_CameraZoom.SetIncrement(0); return; case DiscreteAction.CameraXPlus: m_CameraHeading.SetIncrement(0); return; case DiscreteAction.CameraXMinus: m_CameraHeading.SetIncrement(0); return; case DiscreteAction.CameraYPlus: m_CameraPitch.SetIncrement(0); return; case DiscreteAction.CameraYMinus: m_CameraPitch.SetIncrement(0); return; case DiscreteAction.SASHold: FlightGlobals.ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.SAS, false); return; } }
public virtual void DoWindow(int window) { GUI.DragWindow(new Rect(0, 0, 10000, 20)); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("X", GUILayout.Height(16)) || m_Controller == null || m_Controller.iface == null) { shouldBeDestroyed = true; if (m_Controller != null) { m_Controller.presetEditorOpen = false; AdvancedFlyByWire.Instance.SaveState(null); } return; } GUILayout.EndHorizontal(); var currentPreset = m_Controller.GetCurrentPreset(); GUILayout.BeginHorizontal(); GUILayout.Label("Preset: "); currentPreset.name = GUILayout.TextField(currentPreset.name, GUILayout.Width(256)); if (m_Controller.currentPreset > 0) { if (GUILayout.Button("<")) { m_Controller.currentPreset--; } } else { GUI.enabled = false; GUILayout.Button("<"); GUI.enabled = true; } if (m_Controller.currentPreset < m_Controller.presets.Count - 1) { if (GUILayout.Button(">")) { m_Controller.currentPreset++; } } else { GUI.enabled = false; GUILayout.Button(">"); GUI.enabled = true; } if (GUILayout.Button("New")) { m_Controller.presets.Add(new ControllerPreset()); m_Controller.currentPreset = m_Controller.presets.Count - 1; } string destructiveRemoveLabel = "Delete"; if (m_DestructiveActionWait) { destructiveRemoveLabel = "Sure?"; } if (m_Controller.presets.Count <= 1 || m_Controller.currentPreset == 0) { GUI.enabled = false; } if (GUILayout.Button(destructiveRemoveLabel)) { if(m_DestructiveActionWait) { if(m_Controller.presets.Count > 1) { m_Controller.presets.RemoveAt(m_Controller.currentPreset); m_Controller.currentPreset--; if (m_Controller.currentPreset < 0) { m_Controller.currentPreset = 0; } m_DestructiveActionWait = false; m_DestructiveActionTimer = 0.0f; } } else { m_DestructiveActionWait = true; m_DestructiveActionTimer = 2.0f; } } GUI.enabled = true; GUILayout.EndHorizontal(); m_ScrollPosition = GUILayout.BeginScrollView(m_ScrollPosition); GUILayout.Label("Continuous actions"); foreach (var action in (ContinuousAction[])Enum.GetValues(typeof(ContinuousAction))) { if (action == ContinuousAction.None) { continue; } GUILayout.BeginHorizontal(); GUILayout.Label(Stringify.ContinuousActionToString(action)); GUILayout.FlexibleSpace(); string label = ""; var axisBitsetPair = currentPreset.GetBitsetForContinuousBinding(action); if (m_CurrentlyEditingContinuousAction == action) { label = "Press desired combination"; var buttonsMask = m_Controller.iface.GetButtonsMask(); for (int i = 0; i < m_Controller.iface.GetAxesCount(); i++) { if (Math.Abs(m_Controller.iface.GetAxisState(i) - axisSnapshot[i]) > 0.1 && m_ClickSleepTimer == 0.0f) { currentPreset.SetContinuousBinding(i, buttonsMask, action, false); m_CurrentlyEditingContinuousAction = ContinuousAction.None; } } } axisBitsetPair = currentPreset.GetBitsetForContinuousBinding(action); if (m_CurrentlyEditingContinuousAction != action) { if (axisBitsetPair.Value == null) { label = "Click to assign"; } else { label = m_Controller.iface.ConvertMaskToName(axisBitsetPair.Value, true, axisBitsetPair.Key); } } if (GUILayout.Button(label, GUILayout.Width(220))) { if (m_CurrentlyEditingContinuousAction != action) { m_CurrentlyEditingContinuousAction = action; m_CurrentlyEditingDiscreteAction = DiscreteAction.None; m_ClickSleepTimer = 0.25f; for (int i = 0; i < m_Controller.iface.GetAxesCount(); i++) { axisSnapshot[i] = m_Controller.iface.GetAxisState(i); } } m_CurrentMask = null; } GUILayout.Space(8); var inverted = GUILayout.Toggle(currentPreset.IsContinuousBindingInverted(action), ""); currentPreset.SetContinuousBindingInverted(action, inverted); GUILayout.Label("Invert"); GUILayout.Space(8); if (GUILayout.Button("X")) { currentPreset.UnsetContinuousBinding(action); m_CurrentlyEditingContinuousAction = ContinuousAction.None; m_CurrentlyEditingDiscreteAction = DiscreteAction.None; } GUILayout.EndHorizontal(); } GUILayout.Label("Discrete actions"); foreach (var action in (DiscreteAction[])Enum.GetValues(typeof(DiscreteAction))) { if (action == DiscreteAction.None) { continue; } GUILayout.BeginHorizontal(); GUILayout.Label(Stringify.DiscreteActionToString(action)); GUILayout.FlexibleSpace(); string label = ""; var bitset = currentPreset.GetBitsetForDiscreteBinding(action); if (m_CurrentlyEditingDiscreteAction == action) { label = "Press desired combination"; if (m_CurrentMask != null && m_ClickSleepTimer == 0.0f) { currentPreset.SetDiscreteBinding(m_CurrentMask, action); m_CurrentMask = null; m_CurrentlyEditingDiscreteAction = DiscreteAction.None; } } bitset = currentPreset.GetBitsetForDiscreteBinding(action); if (m_CurrentlyEditingDiscreteAction != action) { if (bitset == null) { label = "Click to assign"; } else { label = m_Controller.iface.ConvertMaskToName(bitset); } } if (GUILayout.Button(label, GUILayout.Width(256))) { if (m_CurrentlyEditingDiscreteAction != action) { m_CurrentlyEditingDiscreteAction = action; m_CurrentlyEditingContinuousAction = ContinuousAction.None; m_ClickSleepTimer = 0.25f; } m_CurrentMask = null; } if (GUILayout.Button("X")) { currentPreset.UnsetDiscreteBinding(action); m_CurrentlyEditingContinuousAction = ContinuousAction.None; m_CurrentlyEditingDiscreteAction = DiscreteAction.None; } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); }