public void EngageSmartASSControl(MechJebModuleSmartASS.Mode mode, MechJebModuleSmartASS.Target target, bool forceEnable) { MechJebCore masterMechJeb = this.vessel.GetMasterMechJeb(); if (masterMechJeb != null) { MechJebModuleSmartASS masterSmartASS = masterMechJeb.GetComputerModule <MechJebModuleSmartASS>(); if (masterSmartASS != null) { if (forceEnable) { // Prevent that the presence of other attitude controllers disables SmartASS masterSmartASS.autoDisableSmartASS = false; } masterSmartASS.mode = mode; masterSmartASS.target = target; masterSmartASS.Engage(); masterSmartASS.enabled = true; // show GUI } else { Debug.LogError("MechJeb couldn't find MechJebModuleSmartASS for control."); } } else { Debug.LogError("MechJeb couldn't find the master MechJeb module for the current vessel."); } }
public MechJebModuleScriptActionSmartASS(MechJebModuleScript scriptModule, MechJebCore core, MechJebModuleScriptActionsList actionsList) : base(scriptModule, core, actionsList, NAME) { this.smartAss = core.GetComputerModule <MechJebModuleSmartASS>(); int modeIdx = 0; foreach (MechJebModuleSmartASS.Target target in Enum.GetValues(typeof(MechJebModuleSmartASS.Target))) { if (TargetIsMode[(int)target] && target != MechJebModuleSmartASS.Target.AUTO) { isTargetMode.Add(true); modeModes.Add((MechJebModuleSmartASS.Mode) 0); targetModes.Add(target); modeStrings.Add(TargetTexts[(int)target]); targetModeSelectorIdxs[(int)target] = modeIdx++; } } foreach (MechJebModuleSmartASS.Mode mode in Enum.GetValues(typeof(MechJebModuleSmartASS.Mode))) { if (mode != MechJebModuleSmartASS.Mode.AUTO) { modeModes.Add(mode); isTargetMode.Add(false); targetModes.Add((MechJebModuleSmartASS.Target) 0); modeStrings.Add(ModeTexts[(int)mode]); modeModeSelectorIdxs[(int)mode] = modeIdx++; targets[(int)mode] = new List <MechJebModuleSmartASS.Target>(); targetStrings[(int)mode] = new List <String>(); } } foreach (MechJebModuleSmartASS.Target target in Enum.GetValues(typeof(MechJebModuleSmartASS.Target))) { if (!TargetIsMode[(int)target]) { MechJebModuleSmartASS.Mode mode = Target2Mode[(int)target]; targetSelectorIdxs[(int)target] = targets[(int)mode].Count; targets[(int)mode].Add(target); targetStrings[(int)mode].Add(TargetTexts[(int)target]); } } }
override public void WindowGUI(int windowID) { base.preWindowGUI(windowID); base.WindowGUI(windowID); int modeSelectorIdx = TargetIsMode[(int)target] ? targetModeSelectorIdxs[(int)target] : modeModeSelectorIdxs[(int)Target2Mode[(int)target]]; GUILayout.BeginHorizontal(GUILayout.Width(150)); modeSelectorIdx = GuiUtils.ComboBox.Box(modeSelectorIdx, modeStrings.ToArray(), modeStrings); GUILayout.EndHorizontal(); bool showForceRol = false; if (this.isTargetMode[modeSelectorIdx]) { target = this.targetModes[modeSelectorIdx]; showForceRol = (target == MechJebModuleSmartASS.Target.NODE); } else { MechJebModuleSmartASS.Mode mode = this.modeModes[modeSelectorIdx]; List <String> targetStrings = this.targetStrings[(int)mode]; if (targetStrings.Count == 1) { target = this.targets[(int)mode][0]; } else { int targetSelectorIdx = (Target2Mode[(int)target] == mode) ? targetSelectorIdxs[(int)target] : 0; GUILayout.BeginHorizontal(GUILayout.Width(160)); targetSelectorIdx = GuiUtils.ComboBox.Box(targetSelectorIdx, targetStrings.ToArray(), targetStrings); GUILayout.EndHorizontal(); target = this.targets[(int)mode][targetSelectorIdx]; } switch (mode) { case MechJebModuleSmartASS.Mode.ORBITAL: case MechJebModuleSmartASS.Mode.TARGET: showForceRol = true; break; case MechJebModuleSmartASS.Mode.ADVANCED: GUILayout.BeginHorizontal(GUILayout.Width(220)); advReference = (AttitudeReference)GuiUtils.ComboBox.Box((int)advReference, ReferenceTexts, ReferenceTexts); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(GUILayout.Width(200)); advDirection = (Vector6.Direction)GuiUtils.ComboBox.Box((int)advDirection, DirectionTexts, DirectionTexts); GUILayout.EndHorizontal(); showForceRol = true; break; } switch (target) { case MechJebModuleSmartASS.Target.SURFACE: GUILayout.Label("", GUI.skin.label, GUILayout.ExpandWidth(true)); forceYaw = GUILayout.Toggle(forceYaw, "Heading: ", GUILayout.ExpandWidth(false)); srfHdg.text = GUILayout.TextField(srfHdg.text, GUILayout.ExpandWidth(false), GUILayout.Width(37)); GUILayout.Label("°", GUILayout.ExpandWidth(true)); forcePitch = GUILayout.Toggle(forcePitch, "Pitch: ", GUILayout.ExpandWidth(false)); srfPit.text = GUILayout.TextField(srfPit.text, GUILayout.ExpandWidth(false), GUILayout.Width(37)); GUILayout.Label("°", GUILayout.ExpandWidth(true)); forceRol = GUILayout.Toggle(forceRol, "Roll: ", GUILayout.ExpandWidth(false)); srfRol.text = GUILayout.TextField(srfRol.text, GUILayout.ExpandWidth(false), GUILayout.Width(37)); GUILayout.Label("°", GUILayout.ExpandWidth(false)); break; case MechJebModuleSmartASS.Target.SURFACE_PROGRADE: case MechJebModuleSmartASS.Target.SURFACE_RETROGRADE: GUILayout.Label("", GUI.skin.label, GUILayout.ExpandWidth(true)); forcePitch = GUILayout.Toggle(forcePitch, "Pitch: ", GUILayout.ExpandWidth(false)); srfVelPit.text = GUILayout.TextField(srfVelPit.text, GUILayout.ExpandWidth(false), GUILayout.Width(37)); GUILayout.Label("°", GUILayout.ExpandWidth(true)); forceRol = GUILayout.Toggle(forceRol, "Roll: ", GUILayout.ExpandWidth(false)); srfVelRol.text = GUILayout.TextField(srfVelRol.text, GUILayout.ExpandWidth(false), GUILayout.Width(37)); GUILayout.Label("°", GUILayout.ExpandWidth(true)); forceYaw = GUILayout.Toggle(forceYaw, "Yaw: ", GUILayout.ExpandWidth(false)); srfVelYaw.text = GUILayout.TextField(srfVelYaw.text, GUILayout.ExpandWidth(false), GUILayout.Width(37)); GUILayout.Label("°", GUILayout.ExpandWidth(false)); break; } } GUILayout.Label("", GUILayout.ExpandWidth(true)); if (showForceRol) { forceRol = GUILayout.Toggle(forceRol, "Force Roll: ", GUILayout.ExpandWidth(false)); rol.text = GUILayout.TextField(rol.text, GUILayout.Width(37)); GUILayout.Label("°", GUILayout.ExpandWidth(false)); } targetName = TargetTexts[(int)target]; base.postWindowGUI(windowID); }