public void SetupToolbarButton(DisplayModule module, bool active) { if (!ToolbarManager.ToolbarAvailable) { return; } if (!module.hidden) { IButton button; String name = CleanName(module.GetName()); if (!toolbarButtons.ContainsKey(name)) { print("Adding button for " + name); button = ToolbarManager.Instance.add("MechJeb2", name); toolbarButtons[name] = button; button.ToolTip = "MechJeb " + module.GetName(); //button.Visibility = new MJButtonVisibility(this); button.OnClick += (b) => { DisplayModule mod = FlightGlobals.ActiveVessel.GetMasterMechJeb().GetComputerModules <DisplayModule>().FirstOrDefault(m => m.GetName() == module.GetName()); if (mod != null) { mod.enabled = !mod.enabled; //print("Change " + module.GetName() + " to " + module.enabled); } }; } else { button = toolbarButtons[name]; //if (button.Visible != module.showInCurrentScene) } button.Visible = module.showInCurrentScene; String TexturePath = "MechJeb2/Icons/" + name; String TexturePathActive = TexturePath + "_active"; if (GameDatabase.Instance.GetTexture(TexturePath, false) == null) { TexturePath = "MechJeb2/Icons/QMark"; if (!missingIcons.Contains(name)) { missingIcons.Add(name); print("No icon for " + name); } } if (active & GameDatabase.Instance.GetTexture(TexturePathActive, false) == null) { TexturePathActive = TexturePath; if (!missingIcons.Contains(name + "_active")) { missingIcons.Add(name + "_active"); print("No icon for " + name + "_active"); } } button.TexturePath = active ? TexturePathActive : TexturePath; } }
/// <summary> /// Creates feature button and puts it to <see cref="featureButtons"/> list. /// </summary> /// <param name="module">Feature related module.</param> /// <param name="nameId">Feature unique name.</param> /// <param name="tooltip">The tooltip for button.</param> /// <param name="onClick">The button click handler.</param> /// <param name="isActive">Super light weight function to check whether the feature is activated at the moment.</param> public void CreateFeatureButton(DisplayModule module, string nameId, string tooltip, ClickHandler onClick, Func <bool> isActive) { var texturePath = "MechJeb2/Icons/" + nameId; var texturePathActive = texturePath + "_active"; var button = new Button(); button.button = ToolbarManager.Instance.add("MechJeb2", nameId); if (GameDatabase.Instance.GetTexture(texturePath, false) == null) { button.texturePath = Qmark; print("No icon for " + nameId); } else { button.texturePath = texturePath; } if (GameDatabase.Instance.GetTexture(texturePathActive, false) == null) { button.texturePathActive = texturePath; } else { button.texturePathActive = texturePathActive; } button.button.ToolTip = tooltip; button.button.OnClick += onClick; featureButtons.Add(() => { button.button.TexturePath = isActive() ? button.texturePathActive : button.texturePath; }, button); button.button.Visible = module.showInCurrentScene; button.button.TexturePath = button.texturePath; }
public void SetupToolBarButtons() { if (!ToolbarManager.ToolbarAvailable) { return; } SetupMainToolbarButton(); foreach (DisplayModule module in core.GetDisplayModules(DisplayOrder.instance).Where(m => !m.hidden)) { Button button; if (!toolbarButtons.ContainsKey(module)) { Debug.Log("Create button for module " + module.GetName()); String name = GetCleanName(module.GetName()); String TexturePath = "MechJeb2/Icons/" + name; String TexturePathActive = TexturePath + "_active"; button = new Button(); button.button = ToolbarManager.Instance.add("MechJeb2", name); if (GameDatabase.Instance.GetTexture(TexturePath, false) == null) { button.texturePath = Qmark; print("No icon for " + name); } else { button.texturePath = TexturePath; } if (GameDatabase.Instance.GetTexture(TexturePathActive, false) == null) { button.texturePathActive = TexturePath; //print("No icon for " + name + "_active"); } else { button.texturePathActive = TexturePathActive; } toolbarButtons[module] = button; button.button.ToolTip = "MechJeb " + module.GetName(); button.button.OnClick += (b) => { DisplayModule mod = FlightGlobals.ActiveVessel.GetMasterMechJeb().GetDisplayModules(DisplayOrder.instance).FirstOrDefault(m => m == module); if (mod != null) { mod.enabled = !mod.enabled; } }; } else { button = toolbarButtons[module]; } button.button.Visible = module.showInCurrentScene; button.button.TexturePath = module.isActive() ? button.texturePathActive : button.texturePath; } }
public void SetupToolBarButtons() { if (!ToolbarManager.ToolbarAvailable) { return; } SetupMainToolbarButton(); foreach (DisplayModule module in core.GetDisplayModules(DisplayOrder.instance).Where(m => !m.hidden)) { Button button; if (!toolbarButtons.ContainsKey(module)) { Debug.Log("Create button for module " + module.GetName()); String name = GetCleanName(module.IconName()); String TexturePath = "MechJeb2/Icons/" + name; String TexturePathActive = TexturePath + "_active"; button = new Button(); button.button = ToolbarManager.Instance.add("MechJeb2", name); if (GameDatabase.Instance.GetTexture(TexturePath, false) == null) { button.texturePath = Qmark; print("No icon for " + name); } else { button.texturePath = TexturePath; } if (GameDatabase.Instance.GetTexture(TexturePathActive, false) == null) { button.texturePathActive = TexturePath; //print("No icon for " + name + "_active"); } else { button.texturePathActive = TexturePathActive; } toolbarButtons[module] = button; button.button.ToolTip = "MechJeb " + module.GetName(); button.button.OnClick += (b) => { DisplayModule mod = FlightGlobals.ActiveVessel.GetMasterMechJeb().GetDisplayModules(DisplayOrder.instance).FirstOrDefault(m => m == module); if (mod != null) { mod.enabled = !mod.enabled; } }; } else { button = toolbarButtons[module]; } button.button.Visible = module.showInCurrentScene; button.button.TexturePath = module.isActive() ? button.texturePathActive : button.texturePath; } // create toolbar buttons for features if (featureButtons.Count == 0) { var maneuverPlannerModule = core.GetComputerModule <MechJebModuleManeuverPlanner>(); if (!HighLogic.LoadedSceneIsEditor && maneuverPlannerModule != null && !maneuverPlannerModule.hidden) { CreateFeatureButton(maneuverPlannerModule, "Exec_Node", "MechJeb Execute Next Node", (b) => { if (vessel.patchedConicSolver.maneuverNodes.Count > 0 && core.node != null) { if (core.node.enabled) { core.node.Abort(); } else { if (vessel.patchedConicSolver.maneuverNodes[0].DeltaV.magnitude > 0.0001) { core.node.ExecuteOneNode(maneuverPlannerModule); } else { ScreenMessages.PostScreenMessage("Maneuver burn vector not set", 3f); } } } else { ScreenMessages.PostScreenMessage("No maneuver nodes", 2f); } }, () => vessel.patchedConicSolver.maneuverNodes.Count > 0 && core.node != null && core.node.enabled); CreateFeatureButton(maneuverPlannerModule, "Autostage_Once", "MechJeb Autostage Once", (b) => { var w = core.GetComputerModule <MechJebModuleThrustWindow>(); if (core.staging.enabled && core.staging.autostagingOnce) { if (core.staging.users.Contains(w)) { core.staging.users.Remove(w); w.autostageSavedState = false; } } else { core.staging.AutostageOnce(w); } }, () => core.staging.enabled && core.staging.autostagingOnce); CreateFeatureButton(maneuverPlannerModule, "Auto_Warp", "MechJeb Auto-warp", (b) => { core.node.autowarp = !core.node.autowarp; }, () => core.node.autowarp); } } }
protected override void LateUpdate() { if (shutdown) return; if (!HighLogic.LoadedSceneIsFlight || !FlightGlobals.ready) return; if (SCANcontroller.controller == null) { way = null; return; } if (!SCANcontroller.controller.mechJebTargetSelection) { way = null; return; } v = FlightGlobals.ActiveVessel; if (v == null) { SCANcontroller.controller.MechJebLoaded = false; way = null; return; } if (v.mainBody != SCANcontroller.controller.LandingTargetBody) SCANcontroller.controller.LandingTargetBody = v.mainBody; data = SCANUtil.getData(v.mainBody); if (data == null) { SCANcontroller.controller.MechJebLoaded = false; way = null; return; } if (v.FindPartModulesImplementing<MechJebCore>().Count <= 0) { SCANcontroller.controller.MechJebLoaded = false; way = null; return; } core = v.GetMasterMechJeb(); if (core == null) { SCANcontroller.controller.MechJebLoaded = false; way = null; return; } if (HighLogic.CurrentGame.Mode != Game.Modes.SANDBOX) { if (guidanceModule == null) guidanceModule = (DisplayModule)core.GetComputerModule("MechJebModuleLandingGuidance"); if (guidanceModule == null) { SCANcontroller.controller.MechJebLoaded = false; way = null; return; } if (!guidanceModule.unlockChecked) return; if (guidanceModule.hidden) { SCANcontroller.controller.MechJebLoaded = false; shutdown = true; way = null; return; } } target = core.target; if (target == null) { SCANcontroller.controller.MechJebLoaded = false; way = null; return; } if (!SCANcontroller.controller.MechJebLoaded) { SCANcontroller.controller.MechJebLoaded = true; RenderingManager.AddToPostDrawQueue(1, drawTarget); } if (SCANcontroller.controller.LandingTarget != null) { way = SCANcontroller.controller.LandingTarget; } if (SCANcontroller.controller.TargetSelecting) { way = null; selectingTarget = true; if (SCANcontroller.controller.TargetSelectingActive) selectingInMap = true; else selectingInMap = false; coords = SCANcontroller.controller.LandingTargetCoords; return; } else if (selectingTarget) { selectingTarget = false; if (selectingInMap) { selectingInMap = false; coords = SCANcontroller.controller.LandingTargetCoords; way = new SCANwaypoint(coords.y, coords.x, siteName); target.SetPositionTarget(SCANcontroller.controller.LandingTargetBody, way.Latitude, way.Longitude); } } selectingInMap = false; selectingTarget = false; if (target.Target == null) { way = null; return; } if (target.targetBody != v.mainBody) { way = null; return; } if (!(target.Target is PositionTarget)) { way = null; return; } coords.x = target.targetLongitude; coords.y = target.targetLatitude; if (way != null) { if (!SCANUtil.ApproxEq(coords.x, way.Longitude) || !SCANUtil.ApproxEq(coords.y, way.Latitude)) { way = new SCANwaypoint(coords.y, coords.x, siteName); SCANcontroller.controller.LandingTarget = way; data.addToWaypoints(); } } else { way = new SCANwaypoint(coords.y, coords.x, siteName); SCANcontroller.controller.LandingTarget = way; data.addToWaypoints(); } }
public void SetupToolbarButton(DisplayModule module, bool active) { if (!ToolbarManager.ToolbarAvailable) { return; } IButton button; String name = CleanName(module.GetName()); if (!toolbarButtons.ContainsKey(name)) { if (module.hidden) { return; } print("Adding button for " + name); button = ToolbarManager.Instance.add("MechJeb2", name); toolbarButtons[name] = button; button.ToolTip = "MechJeb " + module.GetName(); button.OnClick += (b) => { DisplayModule mod = FlightGlobals.ActiveVessel.GetMasterMechJeb().GetComputerModules <DisplayModule>().FirstOrDefault(m => m.GetName() == module.GetName()); if (mod != null) { mod.enabled = !mod.enabled; } }; } else { button = toolbarButtons[name]; } button.Visible = module.showInCurrentScene && !module.hidden; String TexturePath = "MechJeb2/Icons/" + name; String TexturePathActive = TexturePath + "_active"; if (!actualIcons.ContainsKey(TexturePath)) { if (GameDatabase.Instance.GetTexture(TexturePath, false) == null) { actualIcons[TexturePath] = Qmark; print("No icon for " + name); } else { actualIcons[TexturePath] = TexturePath; } } if (active && !actualIcons.ContainsKey(TexturePathActive)) { if (GameDatabase.Instance.GetTexture(TexturePathActive, false) == null) { actualIcons[TexturePathActive] = TexturePath; print("No icon for " + name + "_active"); } else { actualIcons[TexturePathActive] = TexturePathActive; } } button.TexturePath = active ? actualIcons[TexturePathActive] : actualIcons[TexturePath]; }