public void Update() { //a hack to detect when the user hides the GUI if (renderingManager == null) { renderingManager = (RenderingManager)GameObject.FindObjectOfType(typeof(RenderingManager)); } if (HighLogic.LoadedSceneIsFlight && renderingManager != null) { if (renderingManager.uiElementsToDisable.Length >= 1) { showGui = renderingManager.uiElementsToDisable[0].activeSelf; } } if (this != vessel.GetMasterMechJeb()) { return; } if (modulesUpdated) { computerModules.Sort(); modulesUpdated = false; } if (Input.GetKeyDown(KeyCode.V) && (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))) { MechJebModuleCustomWindowEditor windowEditor = GetComputerModule <MechJebModuleCustomWindowEditor>(); if (windowEditor != null) { windowEditor.CreateWindowFromSharingString(MuUtils.SystemClipboard); } } //periodically save settings in case we quit unexpectedly if (HighLogic.LoadedSceneIsEditor || vessel.isActiveVessel) { if (Time.time > lastSettingsSaveTime + 5) { //Debug.Log("MechJeb doing periodic settings save"); OnSave(null); lastSettingsSaveTime = Time.time; } } if (vessel == null) { return; //don't run ComputerModules' OnUpdate in editor } foreach (ComputerModule module in computerModules) { if (module.enabled) { module.OnUpdate(); } } }
protected override void WindowGUI(int windowID) { MechJebModuleCustomWindowEditor ed = core.GetComputerModule <MechJebModuleCustomWindowEditor>(); ed.registry.Find(i => i.id == "Toggle:RoverController.ControlHeading").DrawItem(); ed.registry.Find(i => i.id == "Editable:RoverController.heading").DrawItem(); ed.registry.Find(i => i.id == "Value:RoverController.headingErr").DrawItem(); ed.registry.Find(i => i.id == "Toggle:RoverController.ControlSpeed").DrawItem(); ed.registry.Find(i => i.id == "Editable:RoverController.speed").DrawItem(); ed.registry.Find(i => i.id == "Value:RoverController.speedErr").DrawItem(); base.WindowGUI(windowID); }
protected override void WindowGUI(int windowID) { GUILayout.BeginVertical(); if (GUILayout.Button("\nRestore factory default settings\n")) { KSP.IO.FileInfo.CreateForType <MechJebCore>("mechjeb_settings_global.cfg").Delete(); KSP.IO.FileInfo.CreateForType <MechJebCore>("mechjeb_settings_type_" + vessel.vesselName + ".cfg").Delete(); core.ReloadAllComputerModules(); } GUILayout.Label("Current skin: " + (GuiUtils.SkinType)skinId); if (GuiUtils.skin == null || skinId != 1) { if (GUILayout.Button("Use MechJeb 1 GUI skin")) { GuiUtils.LoadSkin(GuiUtils.SkinType.MechJeb1); skinId = 1; } } if (GuiUtils.skin == null || skinId != 0) { if (GUILayout.Button("Use MechJeb 2 GUI skin")) { GuiUtils.LoadSkin(GuiUtils.SkinType.Default); skinId = 0; } } if (GuiUtils.skin == null || skinId != 2) { if (GUILayout.Button("Use MJ2 Compact GUI skin")) { GuiUtils.LoadSkin(GuiUtils.SkinType.Compact); skinId = 2; } } MechJebModuleCustomWindowEditor ed = core.GetComputerModule <MechJebModuleCustomWindowEditor>(); ed.registry.Find(i => i.id == "Toggle:Settings.hideBrakeOnEject").DrawItem(); if (ToolbarManager.ToolbarAvailable) { ed.registry.Find(i => i.id == "Toggle:Menu.hideButton").DrawItem(); } GUILayout.EndVertical(); base.WindowGUI(windowID); }
protected override void WindowGUI(int windowID) { GUI.skin = isCompact ? GuiUtils.compactSkin : GuiUtils.skin; GUI.contentColor = text; GUILayout.BeginVertical(); for (int i = 0; i < items.Count; i++) { InfoItem item = items[i]; if (HighLogic.LoadedSceneIsEditor ? item.showInEditor : item.showInFlight) { item.DrawItem(); } else { GUILayout.Label(Localizer.Format(item.name));// } } if (items.Count == 0) { GUILayout.Label(Localizer.Format("#MechJeb_WindowEd_CustomInfoWindow_Label1")); //Add items to this window with the custom window editor. } GUILayout.EndVertical(); if (!IsOverlay && GUI.Button(new Rect(10, 0, 13, 20), "E", GuiUtils.yellowOnHover)) { MechJebModuleCustomWindowEditor editor = core.GetComputerModule <MechJebModuleCustomWindowEditor>(); if (editor != null) { editor.enabled = true; editor.editedWindow = this; } } if (!IsOverlay && GUI.Button(new Rect(25, 0, 13, 20), "C", GuiUtils.yellowOnHover)) { MuUtils.SystemClipboard = ToSharingString(); ScreenMessages.PostScreenMessage(Localizer.Format("#MechJeb_WindowEd_CustomInfoWindow_Scrmsg1", GetName()), 3.0f, ScreenMessageStyle.UPPER_RIGHT);//Configuration of <<1>> window copied to clipboard. } base.WindowGUI(windowID); }
protected override void WindowGUI(int windowID) { GUILayout.BeginVertical(); for (int i = 0; i < items.Count; i++) { InfoItem item = items[i]; if (HighLogic.LoadedSceneIsEditor ? item.showInEditor : item.showInFlight) { item.DrawItem(); } else { GUILayout.Label(item.name); } } if (items.Count == 0) { GUILayout.Label("Add items to this window with the custom window editor."); } GUILayout.EndVertical(); if (GUI.Button(new Rect(10, 0, 13, 20), "E", GuiUtils.yellowOnHover)) { MechJebModuleCustomWindowEditor editor = core.GetComputerModule <MechJebModuleCustomWindowEditor>(); if (editor != null) { editor.enabled = true; editor.editedWindow = this; } } if (GUI.Button(new Rect(25, 0, 13, 20), "C", GuiUtils.yellowOnHover)) { MuUtils.SystemClipboard = ToSharingString(); ScreenMessages.PostScreenMessage("Configuration of \"" + GetName() + "\" window copied to clipboard.", 3.0f, ScreenMessageStyle.UPPER_RIGHT); } base.WindowGUI(windowID); }
public override void DrawGUI(bool inEditor) { base.DrawGUI(inEditor); if (showInCurrentScene) { if (GUI.Button(new Rect(windowPos.x + 10, windowPos.y, 13, 20), "E", GuiUtils.yellowOnHover)) { MechJebModuleCustomWindowEditor editor = core.GetComputerModule <MechJebModuleCustomWindowEditor>(); if (editor != null) { editor.enabled = true; editor.editedWindow = this; } } if (GUI.Button(new Rect(windowPos.x + 25, windowPos.y, 13, 20), "C", GuiUtils.yellowOnHover)) { MuUtils.SystemClipboard = ToSharingString(); ScreenMessages.PostScreenMessage("Configuration of \"" + GetName() + "\" window copied to clipboard.", 3.0f, ScreenMessageStyle.UPPER_RIGHT); } } }
public void Update() { if (this != vessel.GetMasterMechJeb()) { return; } if (Input.GetKeyDown(KeyCode.V) && (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))) { MechJebModuleCustomWindowEditor windowEditor = GetComputerModule <MechJebModuleCustomWindowEditor>(); if (windowEditor != null) { windowEditor.CreateWindowFromSharingString(MuUtils.SystemClipboard); } } //periodically save settings in case we quit unexpectedly if (HighLogic.LoadedSceneIsEditor || vessel.isActiveVessel) { if (Time.time > lastSettingsSaveTime + 5) { //Debug.Log("MechJeb doing periodic settings save"); OnSave(null); lastSettingsSaveTime = Time.time; } } if (ResearchAndDevelopment.Instance != null && unorderedComputerModules.Any(a => !a.unlockChecked)) { foreach (ComputerModule module in GetComputerModules <ComputerModule>()) { try { module.UnlockCheck(); } catch (Exception e) { Debug.LogError("MechJeb module " + module.GetType().Name + " threw an exception in UnlockCheck: " + e); } } } GetComputerModule <MechJebModuleMenu>().OnMenuUpdate(); // Allow the menu movement, even while in Editor if (vessel == null) { return; //don't run ComputerModules' OnUpdate in editor } foreach (ComputerModule module in GetComputerModules <ComputerModule>()) { try { if (module.enabled) { module.OnUpdate(); } } catch (Exception e) { Debug.LogError("MechJeb module " + module.GetType().Name + " threw an exception in OnUpdate: " + e); } } }
protected override void WindowGUI(int windowID) { GUILayout.BeginVertical(); if (GUILayout.Button(Localizer.Format("#MechJeb_Settings_button1")))//"\nRestore factory default settings\n" { KSP.IO.FileInfo.CreateForType <MechJebCore>("mechjeb_settings_global.cfg").Delete(); if (vessel != null && vessel.vesselName != null) { KSP.IO.FileInfo.CreateForType <MechJebCore>("mechjeb_settings_type_" + vessel.vesselName + ".cfg").Delete(); } core.ReloadAllComputerModules(); GuiUtils.SetGUIScale(1); } GUILayout.Label(Localizer.Format("#MechJeb_Settings_label1", (GuiUtils.SkinType)skinId));//"Current skin: <<1>>" if (GuiUtils.skin == null || skinId != 1) { if (GUILayout.Button(Localizer.Format("#MechJeb_Settings_button2")))//"Use MechJeb 1 GUI skin" { GuiUtils.LoadSkin(GuiUtils.SkinType.MechJeb1); skinId = 1; } } if (GuiUtils.skin == null || skinId != 0) { if (GUILayout.Button(Localizer.Format("#MechJeb_Settings_button3")))//"Use MechJeb 2 GUI skin" { GuiUtils.LoadSkin(GuiUtils.SkinType.Default); skinId = 0; } } if (GuiUtils.skin == null || skinId != 2) { if (GUILayout.Button(Localizer.Format("#MechJeb_Settings_button4")))//"Use MJ2 Compact GUI skin" { GuiUtils.LoadSkin(GuiUtils.SkinType.Compact); skinId = 2; } } GUILayout.BeginHorizontal(); GUILayout.Label(Localizer.Format("#MechJeb_Settings_label2"), GUILayout.ExpandWidth(true));//"UI Scale:" UIScale.text = GUILayout.TextField(UIScale.text, GUILayout.Width(60)); GUILayout.EndHorizontal(); GuiUtils.SetGUIScale(UIScale.val); dontUseDropDownMenu = GUILayout.Toggle(dontUseDropDownMenu, Localizer.Format("#MechJeb_Settings_checkbox1"));//"Replace drop down menu with arrow selector" GuiUtils.dontUseDropDownMenu = dontUseDropDownMenu; MechJebModuleCustomWindowEditor ed = core.GetComputerModule <MechJebModuleCustomWindowEditor>(); ed.registry.Find(i => i.id == "Toggle:Settings.hideBrakeOnEject").DrawItem(); ed.registry.Find(i => i.id == "Toggle:Settings.useTitlebarDragging").DrawItem(); ed.registry.Find(i => i.id == "Toggle:Menu.useAppLauncher").DrawItem(); if (ToolbarManager.ToolbarAvailable || core.GetComputerModule <MechJebModuleMenu>().useAppLauncher) { ed.registry.Find(i => i.id == "Toggle:Menu.hideButton").DrawItem(); } ed.registry.Find(i => i.id == "General:Menu.MenuPosition").DrawItem(); ed.registry.Find(i => i.id == "Toggle:Settings.rssMode").DrawItem(); core.warp.activateSASOnWarp = GUILayout.Toggle(core.warp.activateSASOnWarp, Localizer.Format("#MechJeb_Settings_checkbox2"));//"Activate SAS on Warp" GUILayout.EndVertical(); base.WindowGUI(windowID); }
protected override void WindowGUI(int windowID) { MechJebModuleCustomWindowEditor ed = core.GetComputerModule <MechJebModuleCustomWindowEditor>(); bool alt = Input.GetKey(KeyCode.LeftAlt); if (GUI.Button(new Rect(windowPos.width - 48, 0, 13, 20), "?", GuiUtils.yellowOnHover)) { var help = core.GetComputerModule <MechJebModuleWaypointHelpWindow>(); help.selTopic = ((IList)help.topics).IndexOf("Controller"); help.enabled = help.selTopic > -1 || help.enabled; } ed.registry.Find(i => i.id == "Toggle:RoverController.ControlHeading").DrawItem(); GUILayout.BeginHorizontal(); ed.registry.Find(i => i.id == "Editable:RoverController.heading").DrawItem(); if (GUILayout.Button("-", GUILayout.Width(18))) { autopilot.heading.val -= (GameSettings.MODIFIER_KEY.GetKey() ? 5 : 1); } if (GUILayout.Button("+", GUILayout.Width(18))) { autopilot.heading.val += (GameSettings.MODIFIER_KEY.GetKey() ? 5 : 1); } GUILayout.EndHorizontal(); ed.registry.Find(i => i.id == "Value:RoverController.headingErr").DrawItem(); ed.registry.Find(i => i.id == "Toggle:RoverController.ControlSpeed").DrawItem(); GUILayout.BeginHorizontal(); ed.registry.Find(i => i.id == "Editable:RoverController.speed").DrawItem(); if (GUILayout.Button("-", GUILayout.Width(18))) { autopilot.speed.val -= (GameSettings.MODIFIER_KEY.GetKey() ? 5 : 1); } if (GUILayout.Button("+", GUILayout.Width(18))) { autopilot.speed.val += (GameSettings.MODIFIER_KEY.GetKey() ? 5 : 1); } GUILayout.EndHorizontal(); ed.registry.Find(i => i.id == "Value:RoverController.speedErr").DrawItem(); ed.registry.Find(i => i.id == "Toggle:RoverController.StabilityControl").DrawItem(); if (!core.settings.hideBrakeOnEject) { ed.registry.Find(i => i.id == "Toggle:RoverController.BrakeOnEject").DrawItem(); } ed.registry.Find(i => i.id == "Toggle:RoverController.BrakeOnEnergyDepletion").DrawItem(); if (autopilot.BrakeOnEnergyDepletion) { ed.registry.Find(i => i.id == "Toggle:RoverController.WarpToDaylight").DrawItem(); } GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Label("Target Speed", GUILayout.ExpandWidth(true)); GUILayout.Label(autopilot.tgtSpeed.ToString("F1"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Waypoints", GUILayout.ExpandWidth(true)); GUILayout.Label("Index " + (autopilot.WaypointIndex + 1).ToString() + " of " + autopilot.Waypoints.Count.ToString(), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); // GUILayout.Label("Debug1: " + autopilot.debug1.ToString("F3")); GUILayout.BeginHorizontal(); if (core.target != null && core.target.Target != null) // && (core.target.targetBody == orbit.referenceBody || (core.target.Orbit != null ? core.target.Orbit.referenceBody == orbit.referenceBody : false))) { { var vssl = core.target.Target.GetVessel(); if (GUILayout.Button("To Target")) { core.GetComputerModule <MechJebModuleWaypointWindow>().selIndex = -1; autopilot.WaypointIndex = 0; autopilot.Waypoints.Clear(); if (vssl != null) { autopilot.Waypoints.Add(new MechJebWaypoint(vssl, 25f)); } else { autopilot.Waypoints.Add(new MechJebWaypoint(core.target.GetPositionTargetPosition())); } autopilot.ControlHeading = autopilot.ControlSpeed = true; vessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, false); autopilot.LoopWaypoints = alt; } if (GUILayout.Button("Add Target")) { if (vssl != null) { autopilot.Waypoints.Add(new MechJebWaypoint(vssl, 25f)); } else { autopilot.Waypoints.Add(new MechJebWaypoint(core.target.GetPositionTargetPosition())); } // if (autopilot.WaypointIndex < 0) { autopilot.WaypointIndex = autopilot.Waypoints.Count - 1; } } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (autopilot.Waypoints.Count > 0) { if (!autopilot.ControlHeading || !autopilot.ControlSpeed) { if (GUILayout.Button("Drive")) { autopilot.WaypointIndex = Mathf.Max(0, (alt ? 0 : autopilot.WaypointIndex)); autopilot.ControlHeading = autopilot.ControlSpeed = true; // autopilot.LoopWaypoints = alt; } } else if (GUILayout.Button("Stop")) { // autopilot.WaypointIndex = -1; // more annoying than helpful autopilot.ControlHeading = autopilot.ControlSpeed = autopilot.LoopWaypoints = false; } } if (GUILayout.Button("Waypoints")) { var waypoints = core.GetComputerModule <MechJebModuleWaypointWindow>(); waypoints.enabled = !waypoints.enabled; if (waypoints.enabled) { waypoints.Mode = MechJebModuleWaypointWindow.WaypointMode.Rover; } } GUILayout.EndHorizontal(); GUILayout.EndVertical(); base.WindowGUI(windowID); }
public void Update() { if (this != vessel.GetMasterMechJeb() || (!FlightGlobals.ready && HighLogic.LoadedSceneIsFlight) || !ready) { return; } Profiler.BeginSample("MechJebCore.Update"); if (Input.GetKeyDown(KeyCode.V) && (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))) { MechJebModuleCustomWindowEditor windowEditor = GetComputerModule <MechJebModuleCustomWindowEditor>(); if (windowEditor != null) { windowEditor.CreateWindowFromSharingString(MuUtils.SystemClipboard); } } //periodically save settings in case we quit unexpectedly Profiler.BeginSample("MechJebCore.Update.OnSave"); if (HighLogic.LoadedSceneIsEditor || (vessel != null && vessel.isActiveVessel)) { if (Time.time > lastSettingsSaveTime + 5) { if (NeedToSave()) { Log.dbg("Periodic settings save"); OnSave(null); } lastSettingsSaveTime = Time.time; } } Profiler.EndSample(); if (ResearchAndDevelopment.Instance != null && unorderedComputerModules.Any(a => !a.unlockChecked)) { foreach (ComputerModule module in GetComputerModules <ComputerModule>()) { try { module.UnlockCheck(); } catch (Exception e) { Log.err(e, "module {0} threw an exception in UnlockCheck: {1}", module.GetType().Name, e); } } } Profiler.BeginSample("OnMenuUpdate"); GetComputerModule <MechJebModuleMenu>().OnMenuUpdate(); // Allow the menu movement, even while in Editor Profiler.EndSample(); if (vessel == null) { Profiler.EndSample(); return; //don't run ComputerModules' OnUpdate in editor } foreach (ComputerModule module in GetComputerModules <ComputerModule>()) { Profiler.BeginSample(module.profilerName); try { if (module.enabled) { module.OnUpdate(); } } catch (Exception e) { Log.err(e, "module {0} threw an exception in OnUpdate: {1}", module.GetType().Name, e); } Profiler.EndSample(); } Profiler.EndSample(); }
protected override void WindowGUI(int windowID) { GUILayout.BeginVertical(); if (GUILayout.Button("\nRestore factory default settings\n")) { KSP.IO.FileInfo.CreateForType <MechJebCore>("mechjeb_settings_global.cfg").Delete(); KSP.IO.FileInfo.CreateForType <MechJebCore>("mechjeb_settings_type_" + vessel.vesselName + ".cfg").Delete(); core.ReloadAllComputerModules(); GuiUtils.SetGUIScale(1); } GUILayout.Label("Current skin: " + (GuiUtils.SkinType)skinId); if (GuiUtils.skin == null || skinId != 1) { if (GUILayout.Button("Use MechJeb 1 GUI skin")) { GuiUtils.LoadSkin(GuiUtils.SkinType.MechJeb1); skinId = 1; } } if (GuiUtils.skin == null || skinId != 0) { if (GUILayout.Button("Use MechJeb 2 GUI skin")) { GuiUtils.LoadSkin(GuiUtils.SkinType.Default); skinId = 0; } } if (GuiUtils.skin == null || skinId != 2) { if (GUILayout.Button("Use MJ2 Compact GUI skin")) { GuiUtils.LoadSkin(GuiUtils.SkinType.Compact); skinId = 2; } } GUILayout.BeginHorizontal(); GUILayout.Label("UI Scale:", GUILayout.ExpandWidth(true)); UIScale.text = GUILayout.TextField(UIScale.text, GUILayout.Width(60)); GUILayout.EndHorizontal(); GuiUtils.SetGUIScale(UIScale.val); dontUseDropDownMenu = GUILayout.Toggle(dontUseDropDownMenu, "Replace drop down menu with arrow selector"); GuiUtils.dontUseDropDownMenu = dontUseDropDownMenu; MechJebModuleCustomWindowEditor ed = core.GetComputerModule <MechJebModuleCustomWindowEditor>(); ed.registry.Find(i => i.id == "Toggle:Settings.hideBrakeOnEject").DrawItem(); ed.registry.Find(i => i.id == "Toggle:Settings.useTitlebarDragging").DrawItem(); ed.registry.Find(i => i.id == "Toggle:Menu.useAppLauncher").DrawItem(); if (ToolbarManager.ToolbarAvailable || core.GetComputerModule <MechJebModuleMenu>().useAppLauncher) { ed.registry.Find(i => i.id == "Toggle:Menu.hideButton").DrawItem(); } GUILayout.EndVertical(); base.WindowGUI(windowID); }
public void Update() { if (renderingManager == null) { renderingManager = (RenderingManager)GameObject.FindObjectOfType(typeof(RenderingManager)); } if (HighLogic.LoadedSceneIsFlight && renderingManager != null) { if (renderingManager.uiElementsToDisable.Length >= 1) { showGui = renderingManager.uiElementsToDisable[0].activeSelf; } } if (this != vessel.GetMasterMechJeb()) { return; } if (modulesUpdated) { computerModules.Sort(); modulesUpdated = false; } if (Input.GetKeyDown(KeyCode.V) && (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))) { MechJebModuleCustomWindowEditor windowEditor = GetComputerModule <MechJebModuleCustomWindowEditor>(); if (windowEditor != null) { windowEditor.CreateWindowFromSharingString(MuUtils.SystemClipboard); } } //periodically save settings in case we quit unexpectedly if (HighLogic.LoadedSceneIsEditor || vessel.isActiveVessel) { if (Time.time > lastSettingsSaveTime + 5) { //Debug.Log("MechJeb doing periodic settings save"); OnSave(null); lastSettingsSaveTime = Time.time; } } if (ResearchAndDevelopment.Instance != null && computerModules.Any(a => !a.unlockChecked)) { foreach (ComputerModule module in computerModules) { try { module.UnlockCheck(); } catch (Exception e) { Debug.LogError("MechJeb module " + module.GetType().Name + " threw an exception in UnlockCheck: " + e); } } } if (vessel == null) { return; //don't run ComputerModules' OnUpdate in editor } foreach (ComputerModule module in computerModules) { try { if (module.enabled) { module.OnUpdate(); } } catch (Exception e) { Debug.LogError("MechJeb module " + module.GetType().Name + " threw an exception in OnUpdate: " + e); } } }