//--- Menu item callbacks
        // Root menu:
        private void ShowCelestialMenu(int index, TextMenu.Item ti)
        {
            currentMenu = MenuList.Celestials;

            // MOARdV: Bug warning: rightColumnWidth for ShowCelestialMenu and
            // ShowVesselMenu is hard-coded to 8, which fits the default format
            // string.  It really needs to be sized appropriately, which isn't
            // easy if the format string is configured with non-fixed size.
            // Maybe the format string should be non-configurable?
            //
            // Mihara: Well, why not make it another module parameter then and
            // let the modder who uses it worry about that? Most won't change it.
            activeMenu = new TextMenu();
            activeMenu.rightColumnWidth = distanceColumnWidth;

            activeMenu.labelColor     = nameColorTag;
            activeMenu.selectedColor  = selectedColorTag;
            activeMenu.disabledColor  = unavailableColorTag;
            activeMenu.rightTextColor = distanceColorTag;

            UpdateLists();

            if (selectedCelestial != null)
            {
                int idx = celestialsList.FindIndex(x => x.body == selectedCelestial);
                activeMenu.currentSelection = idx;
            }
        }
        // Decouple port menu...
        private void DecouplePort(int index, TextMenu.Item ti)
        {
            var thatPort = undockablesList[index] as ModuleDockingNode;
            var thatClaw = undockablesList[index] as ModuleGrappleNode;

            if (thatPort != null)
            {
                switch (thatPort.state)
                {
                case "Docked (docker)":
                    thatPort.Undock();
                    break;

                case "PreAttached":
                    thatPort.Decouple();
                    break;
                }
            }
            // Mihara: Claws require multiple different calls depending on state --
            // Release releases the claw that grabbed something else, while Decouple releases the claw that grabbed your own vessel.
            // FIXME: This needs further research.
            if (thatClaw != null)
            {
                thatClaw.Release();
            }
            UpdateUndockablesList();
            activeMenu  = topMenu;
            currentMenu = MenuList.Root;
            UpdateLists();
        }
 public void ButtonProcessor(int buttonID)
 {
     if (buttonID == buttonUp)
     {
         activeMenu.PreviousItem();
     }
     if (buttonID == buttonDown)
     {
         activeMenu.NextItem();
     }
     if (buttonID == buttonEnter)
     {
         activeMenu.SelectItem();
     }
     if (buttonID == buttonEsc)
     {
         if (currentMenu == MenuList.Ports)
         {
             // Take advantage of the fact that ShowVesselMenu does not
             // care about the parameters.
             ShowVesselMenu(0, null);
         }
         else
         {
             activeMenu  = topMenu;
             currentMenu = MenuList.Root;
         }
     }
     if (buttonID == buttonHome)
     {
         sortMode = sortMode == SortMode.Alphabetic ? SortMode.Distance : SortMode.Alphabetic;
         UpdateLists();
     }
 }
        private void ShowCrewEVA(int index, TextMenu.Item ti)
        {
            currentMenu = MenuList.CrewEVA;

            activeMenu                = new TextMenu();
            activeMenu.labelColor     = nameColorTag;
            activeMenu.selectedColor  = selectedColorTag;
            activeMenu.disabledColor  = unavailableColorTag;
            activeMenu.rightTextColor = distanceColorTag;

            var vesselCrew = vessel.GetVesselCrew();

            for (int crewIdx = 0; crewIdx < vesselCrew.Count; ++crewIdx)
            {
                if (vesselCrew[crewIdx] != null)
                {
                    var tmi = new TextMenu.Item();
                    tmi.action     = CrewEVA;
                    tmi.labelText  = vesselCrew[crewIdx].name;
                    tmi.rightText  = vesselCrew[crewIdx].experienceTrait.Title;
                    tmi.isSelected = false;
                    tmi.id         = crewIdx;
                    activeMenu.Add(tmi);
                }
            }
        }
예제 #5
0
        // Vessel Menu
        private void TargetVessel(int index, TextMenu.Item ti)
        {
            if (selectedVessel == vesselsList[index].vessel)
            {
                // Already selected.  Are there ports?
                if (UpdatePortsList() > 0)
                {
                    currentMenu = MenuList.Ports;

                    activeMenu = new TextMenu();
                    activeMenu.rightColumnWidth = 7;

                    activeMenu.labelColor     = nameColorTag;
                    activeMenu.selectedColor  = selectedColorTag;
                    activeMenu.disabledColor  = unavailableColorTag;
                    activeMenu.rightTextColor = distanceColorTag;

                    UpdateLists();

                    if (selectedPort != null)
                    {
                        int idx = portsList.FindIndex(x => x == selectedPort);
                        activeMenu.currentSelection = idx;
                    }
                }
            }
            else
            {
                vesselsList[index].SetTarget();
                selectedCelestial = null;
                selectedPort      = null;

                activeMenu.SetSelected(index, true);
            }
        }
예제 #6
0
        private void ShowUndockMenu(int index, TextMenu.Item ti)
        {
            currentMenu = MenuList.Undock;

            activeMenu = new TextMenu();

            activeMenu.labelColor     = nameColorTag;
            activeMenu.selectedColor  = selectedColorTag;
            activeMenu.disabledColor  = unavailableColorTag;
            activeMenu.rightTextColor = distanceColorTag;
            UpdateLists();
        }
예제 #7
0
        // MOARdV: Spaceplane Guidance can not be implemented cleanly, because
        // MJ's MechJebModuleSpaceplaneGuidance is missing the 'public'
        // keyword.  We could use another controller (like ourself), but that
        // means one is forced to use our menu to turn it off (the MJ GUI is
        // not able to change the setting), and vice versa.  Since every other
        // place where we interface with MJ, we use MJ's objects as the
        // controller, this breaks our design model.  If/when MJ makes the
        // module public, all of the commented code here related to it can be
        // uncommented, and this missive can be deleted.
        //private void SpaceplaneGuidance(int index, TextMenu.Item tmi)
        //{
        //	UpdateJebReferences();
        //	if (activeJeb != null) {
        //		var autopilot = activeJeb.GetComputerModule<MechJebModuleSpaceplaneAutopilot>();
        //		if (autopilot != null) {
        //			MechJebModuleSpaceplaneGuidance is not currently public.  Can't use it.
        //			var autopilotController = activeJeb.GetComputerModule<MechJebModuleSpaceplaneGuidance>();
        //			if (autopilotController != null) {
        //				if (autopilot.enabled && autopilot.mode == MechJebModuleSpaceplaneAutopilot.Mode.HOLD) {
        //					autopilot.AutopilotOff();
        //				} else if (!autopilot.enabled) {
        //					autopilot.HoldHeadingAndAltitude(autopilotController);
        //				}
        //			}
        //		}
        //	}
        //}

        private void CircularizeMenu(int index, TextMenu.Item tmi)
        {
            currentMenu = MJMenu.CircularizeMenu;

            activeMenu               = new TextMenu();
            activeMenu.labelColor    = JUtil.ColorToColorTag(itemColorValue);
            activeMenu.selectedColor = JUtil.ColorToColorTag(selectedColorValue);
            activeMenu.disabledColor = JUtil.ColorToColorTag(unavailableColorValue);
            activeMenu.menuTitle     = "== Circularize Menu:";

            activeMenu.Add(new TextMenu.Item("At Next Ap", DoCircularize, (int)JSIMechJeb.TimeReference.APOAPSIS));
            activeMenu.Add(new TextMenu.Item("At Next Pe", DoCircularize, (int)JSIMechJeb.TimeReference.PERIAPSIS));
            activeMenu.Add(new TextMenu.Item("In 15s", DoCircularize, (int)JSIMechJeb.TimeReference.X_FROM_NOW));
        }
예제 #8
0
        private void TargetMenu(int index, TextMenu.Item tmi)
        {
            currentMenu = MJMenu.TargetMenu;

            activeMenu               = new TextMenu();
            activeMenu.labelColor    = JUtil.ColorToColorTag(itemColorValue);
            activeMenu.selectedColor = JUtil.ColorToColorTag(selectedColorValue);
            activeMenu.disabledColor = JUtil.ColorToColorTag(unavailableColorValue);

            foreach (JSIMechJeb.Target target in targetTargets)
            {
                activeMenu.Add(new TextMenu.Item(JSIMechJeb.TargetTexts[(int)target].Replace('\n', ' '), SelectTarget));
            }
        }
예제 #9
0
        private void ShowReferenceMenu(int index, TextMenu.Item ti)
        {
            currentMenu = MenuList.Reference;

            activeMenu = new TextMenu();

            activeMenu.labelColor     = nameColorTag;
            activeMenu.selectedColor  = selectedColorTag;
            activeMenu.disabledColor  = unavailableColorTag;
            activeMenu.rightTextColor = distanceColorTag;

            UpdateLists();

            activeMenu.currentSelection = referencePoints.FindIndex(x => x.part == vessel.GetReferenceTransformPart());
        }
예제 #10
0
        // Decouple port menu...
        private void DecouplePort(int index, TextMenu.Item ti)
        {
            switch (undockablesList[index].state)
            {
            case "Docked (docker)":
                undockablesList[index].Undock();
                break;

            case "PreAttached":
                undockablesList[index].Decouple();
                break;
            }
            UpdateUndockablesList();
            activeMenu  = topMenu;
            currentMenu = MenuList.Root;
            UpdateLists();
        }
예제 #11
0
 public void ClickProcessor(int buttonID)
 {
     if (buttonID == buttonUp)
     {
         activeMenu.PreviousItem();
     }
     else if (buttonID == buttonDown)
     {
         activeMenu.NextItem();
     }
     else if (buttonID == buttonEnter)
     {
         activeMenu.SelectItem();
     }
     else if (buttonID == buttonEsc)
     {
         activeMenu  = topMenu;
         currentMenu = MJMenu.RootMenu;
     }
     else if (buttonID == buttonHome)
     {
         if (currentMenu == MJMenu.RootMenu && activeMenu.currentSelection == 5 && smartassAvailable)
         {
             // If Force Roll is highlighted, the Home key will increment the
             // roll value.
             double currentRoll = GetForceRollAngle() + forceRollStep;
             if (currentRoll > 180.0)
             {
                 currentRoll -= 360.0;
             }
             else if (currentRoll < -180.0)
             {
                 currentRoll += 360.0;
             }
             SetForceRoll(true, currentRoll);
             forceRollMenuItem.isSelected = true;
             //activeSmartass.rol = currentRoll;
             //if (forceRollMenuItem.isSelected)
             //{
             //    activeSmartass.Engage();
             //}
         }
     }
 }
예제 #12
0
        private void ShowFiltersMenu(int index, TextMenu.Item ti)
        {
            currentMenu = MenuList.Filters;

            activeMenu = new TextMenu();

            activeMenu.labelColor     = nameColorTag;
            activeMenu.selectedColor  = selectedColorTag;
            activeMenu.disabledColor  = unavailableColorTag;
            activeMenu.rightTextColor = distanceColorTag;
            for (int i = 0; i < vesselFilter.Count; i++)
            {
                var filter = vesselFilter.ElementAt(i);
                var tmi    = new TextMenu.Item();
                tmi.labelText  = filter.Key.ToString().PadRight(9) + (filter.Value ? "- On" : "- Off");
                tmi.isSelected = filter.Value;
                tmi.action     = ToggleFilter;
                activeMenu.Add(tmi);
            }
        }
예제 #13
0
        private void ShowSpaceObjectMenu(int index, TextMenu.Item ti)
        {
            currentMenu = MenuList.SpaceObjects;

            activeMenu = new TextMenu();
            activeMenu.rightColumnWidth = distanceColumnWidth;

            activeMenu.labelColor     = nameColorTag;
            activeMenu.selectedColor  = selectedColorTag;
            activeMenu.disabledColor  = unavailableColorTag;
            activeMenu.rightTextColor = distanceColorTag;

            UpdateLists();

            if (selectedVessel != null)
            {
                int idx = spaceObjectsList.FindIndex(x => x.vessel == selectedVessel);
                activeMenu.currentSelection = idx;
            }
        }
예제 #14
0
        public void Start()
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }

            // Grrrrrr.
            if (!string.IsNullOrEmpty(nameColor))
            {
                nameColorValue = ConfigNode.ParseColor32(nameColor);
            }
            if (!string.IsNullOrEmpty(distanceColor))
            {
                distanceColorValue = ConfigNode.ParseColor32(distanceColor);
            }
            if (!string.IsNullOrEmpty(selectedColor))
            {
                selectedColorValue = ConfigNode.ParseColor32(selectedColor);
            }
            if (!string.IsNullOrEmpty(unavailableColor))
            {
                unavailableColorValue = ConfigNode.ParseColor32(unavailableColor);
            }

            persistentVarName = "targetfilter" + internalProp.propID;
            rpmComp           = RasterPropMonitorComputer.Instantiate(internalProp);
            // 7 is the bitmask for ship-station-probe;
            VesselFilterFromBitmask(rpmComp.GetVar(persistentVarName, defaultFilter));

            nameColorTag          = JUtil.ColorToColorTag(nameColorValue);
            distanceColorTag      = JUtil.ColorToColorTag(distanceColorValue);
            selectedColorTag      = JUtil.ColorToColorTag(selectedColorValue);
            unavailableColorTag   = JUtil.ColorToColorTag(unavailableColorValue);
            distanceFormatString  = distanceFormatString.UnMangleConfigText();
            menuTitleFormatString = menuTitleFormatString.UnMangleConfigText();

            topMenu.labelColor    = nameColorTag;
            topMenu.selectedColor = selectedColorTag;
            topMenu.disabledColor = unavailableColorTag;

            if (!string.IsNullOrEmpty(pageTitle))
            {
                pageTitle = pageTitle.UnMangleConfigText();
            }

            foreach (CelestialBody body in FlightGlobals.Bodies)
            {
                celestialsList.Add(new Celestial(body, vessel.transform.position));
            }

            FindReferencePoints();
            UpdateUndockablesList();

            var menuActions = new List <Action <int, TextMenu.Item> >();

            menuActions.Add(ShowCelestialMenu);
            menuActions.Add(ShowVesselMenu);
            menuActions.Add(ShowSpaceObjectMenu);
            menuActions.Add(ShowReferenceMenu);
            menuActions.Add(ShowUndockMenu);
            menuActions.Add(ArmGrapple);
            menuActions.Add(ShowFiltersMenu);
            menuActions.Add(ClearTarget);

            for (int i = 0; i < rootMenu.Count; ++i)
            {
                var menuitem = new TextMenu.Item();
                menuitem.labelText = rootMenu[i];
                menuitem.action    = menuActions[i];
                topMenu.Add(menuitem);
                switch (menuitem.labelText)
                {
                case clearTargetItemText:
                    clearTarget = topMenu[i];
                    break;

                case undockItemText:
                    undockMenuItem = topMenu[i];
                    break;

                case armGrappleText:
                    grappleMenuItem = topMenu[i];
                    break;
                }
            }

            activeMenu = topMenu;
        }
예제 #15
0
        public void Start()
        {
            // I guess I shouldn't have expected Squad to actually do something nice for a modder like that.
            // In 0.23, loading in non-alphabetical order is still broken.

            // But now we have KSPAssembly and KSPAssemblyDependency, which actually sidestep the issue, and finally
            // Mu told someone about it and now I can avoid this path hardlinking.
            // Actually, better yet. Let it check for the new canonical location instead. Because f**k installation problems.
            if (!JSI.InstallationPathWarning.Warn())
            {
                return;
            }

            GameEvents.onUndock.Add(UndockCallback);

            if (!string.IsNullOrEmpty(itemColor))
            {
                itemColorValue = ConfigNode.ParseColor32(itemColor);
            }
            if (!string.IsNullOrEmpty(selectedColor))
            {
                selectedColorValue = ConfigNode.ParseColor32(selectedColor);
            }
            if (!string.IsNullOrEmpty(unavailableColor))
            {
                unavailableColorValue = ConfigNode.ParseColor32(unavailableColor);
            }

            topMenu.labelColor    = JUtil.ColorToColorTag(itemColorValue);
            topMenu.selectedColor = JUtil.ColorToColorTag(selectedColorValue);
            topMenu.disabledColor = JUtil.ColorToColorTag(unavailableColorValue);

            RasterPropMonitorComputer rpmComp = RasterPropMonitorComputer.Instantiate(internalProp, true);
            Func <bool> isMjAvailable         = (Func <bool>)rpmComp.GetMethod("JSIMechJeb:GetMechJebAvailable", internalProp, typeof(Func <bool>));

            if (isMjAvailable == null)
            {
                throw new NotImplementedException("isMjAvailable");
            }
            UpdateMethods(rpmComp);

            // If MechJeb is installed, but not found on the craft, menu options can't be populated correctly.
            if (isMjAvailable())
            {
                mjAvailable       = true;
                smartassAvailable = GetModuleExists("MechJebModuleSmartASS");

                topMenu.Add(new TextMenu.Item(JSIMechJeb.TargetTexts[(int)JSIMechJeb.Target.OFF], SmartASS_Off));
                topMenu.Add(new TextMenu.Item(JSIMechJeb.TargetTexts[(int)JSIMechJeb.Target.KILLROT].Replace('\n', ' '), SmartASS_KillRot));
                nodeMenuItem = new TextMenu.Item(JSIMechJeb.TargetTexts[(int)JSIMechJeb.Target.NODE], SmartASS_Node);
                topMenu.Add(nodeMenuItem);
                topMenu.Add(new TextMenu.Item(JSIMechJeb.ModeTexts[(int)JSIMechJeb.Mode.ORBITAL], OrbitalMenu));
                topMenu.Add(new TextMenu.Item(JSIMechJeb.ModeTexts[(int)JSIMechJeb.Mode.SURFACE], SurfaceMenu));
                targetMenuItem = new TextMenu.Item(JSIMechJeb.ModeTexts[(int)JSIMechJeb.Mode.TARGET], TargetMenu);
                topMenu.Add(targetMenuItem);
                forceRollMenuItem = new TextMenu.Item(String.Format("Force Roll: {0:f0}", GetForceRollAngle()), ToggleForceRoll);
                topMenu.Add(forceRollMenuItem);
                topMenu.Add(new TextMenu.Item("Execute Next Node", ExecuteNode, (int)MJMenu.ExecuteNodeMenu));
                topMenu.Add(new TextMenu.Item("Ascent Guidance", AscentGuidance, (int)MJMenu.AscentGuidanceMenu));
                topMenu.Add(new TextMenu.Item("Land Somewhere", LandingGuidance, (int)MJMenu.LandingGuidanceMenu));
                topMenu.Add(new TextMenu.Item("Docking Guidance", DockingGuidance, (int)MJMenu.DockingGuidanceMenu));
                //topMenu.Add(new TextMenu.Item("Hold Alt & Heading", SpaceplaneGuidance, (int)MJMenu.SpacePlaneMenu));
                topMenu.Add(new TextMenu.Item("Circularize", CircularizeMenu, (int)MJMenu.CircularizeMenu));
            }
            else
            {
                mjAvailable       = false;
                smartassAvailable = false;
            }
            activeMenu = topMenu;
        }