private void EngageTranslatronControl(MechJebModuleThrustController.TMode mode) { MechJebCore masterMechJeb = vessel.GetMasterMechJeb(); if (masterMechJeb != null) { MechJebModuleTranslatron moduleTranslatron = masterMechJeb.GetComputerModule <MechJebModuleTranslatron>(); if (moduleTranslatron != null && !moduleTranslatron.hidden) { if ((thrust.users.Count > 1) && !thrust.users.Contains(moduleTranslatron)) { return; } moduleTranslatron.SetMode(mode); } else { Debug.LogError("MechJeb couldn't find MechJebModuleTranslatron for translatron control via action group."); } } else { Debug.LogError("MechJeb couldn't find the master MechJeb module for the current vessel."); } }
public void SetMode(MechJebModuleThrustController.TMode newMode) { MechJebModuleThrustController.TMode oldMode = core.thrust.tmode; core.thrust.tmode = newMode; if (core.thrust.tmode != oldMode) { core.thrust.trans_spd_act = Convert.ToInt16(trans_spd); windowPos = new Rect(windowPos.x, windowPos.y, 10, 10); if (core.thrust.tmode == MechJebModuleThrustController.TMode.OFF) { core.thrust.users.Remove(this); } else { core.thrust.users.Add(this); } } }
protected override void WindowGUI(int windowID) { GUIStyle sty = new GUIStyle(GUI.skin.button); sty.normal.textColor = sty.focused.textColor = Color.white; sty.hover.textColor = sty.active.textColor = Color.yellow; sty.onNormal.textColor = sty.onFocused.textColor = sty.onHover.textColor = sty.onActive.textColor = Color.green; sty.padding = new RectOffset(8, 8, 8, 8); GUILayout.BeginVertical(); if ((core.thrust.users.Count > 1) && !core.thrust.users.Contains(this)) { if (!autoMode) { windowPos = new Rect(windowPos.x, windowPos.y, 10, 10); autoMode = true; } sty.normal.textColor = Color.red; sty.onActive = sty.onFocused = sty.onHover = sty.onNormal = sty.active = sty.focused = sty.hover = sty.normal; GUILayout.Button("AUTO", sty, GUILayout.ExpandWidth(true)); } else { if (autoMode) { windowPos = new Rect(windowPos.x, windowPos.y, 10, 10); autoMode = false; } MechJebModuleThrustController.TMode oldMode = core.thrust.tmode; core.thrust.tmode = (MechJebModuleThrustController.TMode)GUILayout.SelectionGrid((int)core.thrust.tmode, trans_texts, 2, sty); if (core.thrust.tmode != oldMode) { core.thrust.trans_spd_act = Convert.ToInt16(trans_spd); windowPos = new Rect(windowPos.x, windowPos.y, 10, 10); if (core.thrust.tmode == MechJebModuleThrustController.TMode.OFF) { core.thrust.users.Remove(this); } else { core.thrust.users.Add(this); } } core.thrust.trans_kill_h = GUILayout.Toggle(core.thrust.trans_kill_h, "Kill H/S", GUILayout.ExpandWidth(true)); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); GUILayout.Label("Speed"); trans_spd = GUILayout.TextField(trans_spd, GUILayout.ExpandWidth(true)); trans_spd = Regex.Replace(trans_spd, @"[^\d.+-]", ""); GUILayout.EndHorizontal(); if (GUILayout.Button("EXECUTE", sty, GUILayout.ExpandWidth(true))) { core.thrust.trans_spd_act = Convert.ToSingle(trans_spd); GUIUtility.keyboardControl = 0; } } if (core.thrust.tmode != MechJebModuleThrustController.TMode.OFF) { GUILayout.Label("Active speed: " + MuMech.MuUtils.ToSI(core.thrust.trans_spd_act) + "m/s", GUILayout.ExpandWidth(true)); } GUILayout.FlexibleSpace(); GUIStyle tsty = new GUIStyle(GUI.skin.label); tsty.alignment = TextAnchor.UpperCenter; GUILayout.Label("Automation", tsty, GUILayout.ExpandWidth(true)); sty.normal.textColor = sty.focused.textColor = sty.hover.textColor = sty.active.textColor = sty.onNormal.textColor = sty.onFocused.textColor = sty.onHover.textColor = sty.onActive.textColor = (abort != AbortStage.OFF) ? Color.red : Color.green; if (GUILayout.Button((abort != AbortStage.OFF) ? "DON'T PANIC!" : "PANIC!!!", sty, GUILayout.ExpandWidth(true))) { if (abort != AbortStage.OFF) { if ((abort == AbortStage.LAND) || (abort == AbortStage.LANDING)) { core.GetComputerModule <MechJebModuleLandingAutopilot>().StopLanding(); } else { core.thrust.ThrustOff(); core.thrust.users.Remove(this); core.attitude.attitudeDeactivate(); } abort = AbortStage.OFF; } else { abort = AbortStage.THRUSTOFF; core.thrust.users.Add(this); } } GUILayout.EndVertical(); base.WindowGUI(windowID); }
protected override void WindowGUI(int windowID) { GUIStyle sty = new GUIStyle(GUI.skin.button); sty.normal.textColor = sty.focused.textColor = Color.white; sty.hover.textColor = sty.active.textColor = Color.yellow; sty.onNormal.textColor = sty.onFocused.textColor = sty.onHover.textColor = sty.onActive.textColor = Color.green; sty.padding = new RectOffset(8, 8, 8, 8); GUILayout.BeginVertical(); if ((core.thrust.users.Count > 1) && !core.thrust.users.Contains(this)) { if (!autoMode) { windowPos = new Rect(windowPos.x, windowPos.y, 10, 10); autoMode = true; } sty.normal.textColor = Color.red; sty.onActive = sty.onFocused = sty.onHover = sty.onNormal = sty.active = sty.focused = sty.hover = sty.normal; GUILayout.Button(Localizer.Format("#MechJeb_Trans_auto"), sty, GUILayout.ExpandWidth(true)); } else { if (autoMode) { windowPos = new Rect(windowPos.x, windowPos.y, 10, 10); autoMode = false; } MechJebModuleThrustController.TMode newMode = (MechJebModuleThrustController.TMode)GUILayout.SelectionGrid((int)core.thrust.tmode, trans_texts, 2, sty); SetMode(newMode); float val = (GameSettings.MODIFIER_KEY.GetKey() ? 5 : 1); // change by 5 if the mod_key is held down, else by 1 -- would be better if it actually worked... core.thrust.trans_kill_h = GUILayout.Toggle(core.thrust.trans_kill_h, Localizer.Format("#MechJeb_Trans_kill_h"), GUILayout.ExpandWidth(true)); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); GuiUtils.SimpleTextBox(Localizer.Format("#MechJeb_Trans_spd"), trans_spd, "", 37); bool change = false; if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) { trans_spd -= val; change = true; } if (GUILayout.Button("0", GUILayout.ExpandWidth(false))) { trans_spd = 0; change = true; } if (GUILayout.Button("+", GUILayout.ExpandWidth(false))) { trans_spd += val; change = true; } GUILayout.EndHorizontal(); if (GUILayout.Button(Localizer.Format("#MechJeb_Trans_spd_act") + ":", sty, GUILayout.ExpandWidth(true)) || change) { core.thrust.trans_spd_act = (float)trans_spd.val; GUIUtility.keyboardControl = 0; } } if (core.thrust.tmode != MechJebModuleThrustController.TMode.OFF) { GUILayout.Label(Localizer.Format("#MechJeb_Trans_current_spd") + MuMech.MuUtils.ToSI(core.thrust.trans_spd_act) + "m/s", GUILayout.ExpandWidth(true)); } GUILayout.FlexibleSpace(); GUIStyle tsty = new GUIStyle(GUI.skin.label); tsty.alignment = TextAnchor.UpperCenter; GUILayout.Label("Automation", tsty, GUILayout.ExpandWidth(true)); sty.normal.textColor = sty.focused.textColor = sty.hover.textColor = sty.active.textColor = sty.onNormal.textColor = sty.onFocused.textColor = sty.onHover.textColor = sty.onActive.textColor = (abort != AbortStage.OFF) ? Color.red : Color.green; if (GUILayout.Button((abort != AbortStage.OFF) ? Localizer.Format("#MechJeb_Trans_NOPANIC") : Localizer.Format("#MechJeb_Trans_PANIC"), sty, GUILayout.ExpandWidth(true))) { PanicSwitch(); } GUILayout.EndVertical(); base.WindowGUI(windowID); }