Наследование: KASModuleAttachCore, IJointLockState
Пример #1
0
        public void Update()
        {
            if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.K))
            {
                if (GuiConfigToogle)
                {
                    Debug.Log("KASAddonDebugMenu - Closing KAS debug tools");
                    GuiConfigToogle = false;
                }
                else
                {
                    Debug.Log("KASAddonDebugMenu - Opening KAS debug tools");
                    GuiConfigToogle = true;
                }
            }

            if (GuiConfigToogle)
            {
                if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.Mouse0))
                {
                    Debug.Log("KASAddonDebugMenu - On click");
                    clickedPart = KAS_Shared.GetPartUnderCursor();
                    if (clickedPart)
                    {
                        moduleWinch = null;
                        moduleGrab = null;
                        moduleMagnet = null;
                        moduleSuctionCup = null;
                        moduleGrapple = null;
                        moduleTimedBomb = null;
                        modulePort = null;
                        moduleAnchor = null;
                        moduleStrut = null;
                        moduleRotor = null;

                        moduleWinch = clickedPart.GetComponent<KASModuleWinch>();
                        moduleGrab = clickedPart.GetComponent<KASModuleGrab>();
                        moduleMagnet = clickedPart.GetComponent<KASModuleMagnet>();
                        moduleSuctionCup = clickedPart.GetComponent<KASModuleSuctionCup>();
                        moduleGrapple = clickedPart.GetComponent<KASModuleGrapplingHook>();
                        moduleTimedBomb = clickedPart.GetComponent<KASModuleTimedBomb>();
                        modulePort = clickedPart.GetComponent<KASModulePort>();
                        moduleAnchor = clickedPart.GetComponent<KASModuleAnchor>();
                        moduleStrut = clickedPart.GetComponent<KASModuleStrut>();
                        moduleRotor = clickedPart.GetComponent<KASModuleRotor>();
                    }     
                }
            }

            if (FlightGlobals.ActiveVessel.heightFromTerrain == -1f)
            {
                if (FlightGlobals.ActiveVessel.Landed)
                {
                    KAS_Shared.DebugWarning("Warning ! ActiveVessel is landed and heightFromTerrain are negative (" + FlightGlobals.ActiveVessel.heightFromTerrain + ")");
                }
            }
        }
Пример #2
0
        private void GuiMainWindow(int windowID)
        {
            GuiStyles();
            GUILayout.Space(15);

            //Get all winches
            if (allWinchModule == null) allWinchModule = GameObject.FindObjectsOfType(typeof(KASModuleWinch)) as KASModuleWinch[];

            //Default selection / Force selection of the first system if no system are selected
            if (selectedWinchModule == null || selectedWinchModule.vessel != FlightGlobals.ActiveVessel)
            {
                foreach (KASModuleWinch winchModule in allWinchModule)
                {
                    if (winchModule.vessel == FlightGlobals.ActiveVessel)
                    {
                        selectedWinchModule = winchModule;
                        break;
                    }
                }
            }

            #region System loop
            //scrollPos = GUILayout.BeginScrollView(scrollPos, guiDataboxStyle, GUILayout.Width(800f), GUILayout.Height(scrollHeight));
            GUILayout.BeginVertical(guiDataboxStyle);
            int i = 0;
            foreach (KASModuleWinch winchModule in allWinchModule)
            {
                if (winchModule.vessel != FlightGlobals.ActiveVessel || !winchModule.isActive) continue;

                GUILayout.BeginHorizontal();

                string sysname;
                if (winchModule.winchName != "" && winchModule.winchName != null)
                {
                    sysname = winchModule.winchName;
                }
                else
                {
                    sysname = "Winch(" + i + ")";
                    i++;
                }

                #region System title & selection
                GUILayout.BeginVertical();
                if (winchModule == selectedWinchModule)
                {
                    GUILayout.Label(new GUIContent("> " + sysname, "Selected KAS System"), guiBoldCenterStyle, GUILayout.Width(150f));
                }
                else
                {
                    GUILayout.Label(new GUIContent("  " + sysname, "KAS System"), guiCenterStyle, GUILayout.Width(150f));
                }

                if ((Event.current.type == EventType.repaint) && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
                {
                    if (Input.GetMouseButtonDown(0))
                    {
                        selectedWinchModule = winchModule;
                    }
                    if (!winchModule.highLightStarted)
                    {
                        winchModule.part.SetHighlight(true);
                        winchModule.highLightStarted = true;
                    }
                }
                else
                {
                    if (winchModule.highLightStarted)
                    {
                        winchModule.part.SetHighlight(false);
                        winchModule.highLightStarted = false;
                    }
                }

                GUILayout.EndVertical();
                #endregion

                #region Cable control

                //release
                winchModule.release.active = GUILayout.Toggle(winchModule.release.active, new GUIContent("Release", "Release connector/hook"), guiButtonStyle, GUILayout.Width(60f));

                //Eject
                if (!winchModule.ejectEnabled || winchModule.headState != KASModuleWinch.PlugState.Locked) GUI.enabled = false;
                if (GUILayout.Button(new GUIContent("Eject", "Eject connector/hook"), guiButtonStyle, GUILayout.Width(40f)))
                {
                    winchModule.Eject();
                }
                GUI.enabled = true;

                //Retract
                if (winchModule.extend.active)
                {
                    GUI.enabled = false;
                }

                winchModule.retract.active = GUILayout.Toggle(winchModule.retract.active, new GUIContent("<<", "Toggle retract"), guiButtonStyle);

                if (GUILayout.RepeatButton(new GUIContent("<", "Retract"), guiButtonStyle))
                {
                    winchModule.guiRepeatRetract = true;
                    winchModule.retract.active = true;
                }
                else if (winchModule.guiRepeatRetract)
                {
                    winchModule.guiRepeatRetract = false;
                    winchModule.retract.active = false;
                }

                GUI.enabled = true;

                //Cable length
                GUI.skin.label.alignment = TextAnchor.MiddleCenter;
                if (winchModule.cableJoint)
                {
                    GUILayout.Label(new GUIContent(winchModule.cableJoint.maxDistance.ToString("0.00"), "Current cable length"), guiYellowStyle, GUILayout.Width(40f));
                    float strainDistance = winchModule.cableJoint.maxDistance - winchModule.cableRealLenght;
                    float warningPercentage = 10;
                    float warningDistance = (winchModule.cableJoint.maxDistance / 100) * warningPercentage;

                    GUILayout.Label("|", guiCenterStyle);

                    if (strainDistance < 0)
                    {
                        GUILayout.Label(new GUIContent(strainDistance.ToString("0.00"), "Cable is under strain"), guiMagentaStyle, GUILayout.Width(40f));
                    }
                    else if (strainDistance < warningDistance)
                    {
                        GUILayout.Label(new GUIContent(strainDistance.ToString("0.00"), "Distance before strain"), guiYellowStyle, GUILayout.Width(40f));
                    }
                    else if (strainDistance > warningDistance)
                    {
                        GUILayout.Label(new GUIContent(strainDistance.ToString("0.00"), "Distance before strain"), guigreenStyle, GUILayout.Width(40f));
                    }
                }
                else
                {
                    GUILayout.Label(new GUIContent("Retracted", "Cable is retracted and locked"), guigreenStyle, GUILayout.Width(93f));
                }

                //Extend
                if (winchModule.retract.active)
                {
                    GUI.enabled = false;
                }

                if (GUILayout.RepeatButton(new GUIContent(">", "Extend"), guiButtonStyle))
                {
                    winchModule.extend.active = true;
                    winchModule.guiRepeatExtend = true;
                }
                else if (winchModule.guiRepeatExtend)
                {
                    winchModule.guiRepeatExtend = false;
                    winchModule.extend.active = false;
                }

                winchModule.extend.active = GUILayout.Toggle(winchModule.extend.active, new GUIContent(">>", "Toggle extend"), guiButtonStyle);
                GUI.enabled = true;

                //
                winchModule.motorSpeedSetting = GUILayout.HorizontalSlider(winchModule.motorSpeedSetting, 0, winchModule.motorMaxSpeed, GUILayout.Width(100f));
                GUI.Box(GUILayoutUtility.GetLastRect(), new GUIContent("", "Motor speed setting"));
                GUILayout.Label(new GUIContent(winchModule.motorSpeed.ToString("0.00") + " / " + winchModule.motorSpeedSetting.ToString("0.00"), "Current motor speed / Motor speed setting"), guiCenterStyle, GUILayout.Width(90f));

                if (GUILayout.RepeatButton(new GUIContent("<", "Turn connected port to left"), guiButtonStyle))
                {
                    winchModule.EventWinchHeadLeft();
                    winchModule.guiRepeatTurnLeft = true;
                }
                else if (winchModule.guiRepeatTurnLeft)
                {
                    winchModule.guiRepeatTurnLeft = false;
                }

                if (GUILayout.RepeatButton(new GUIContent(">", "Turn connected port to right"), guiButtonStyle))
                {
                    winchModule.EventWinchHeadRight();
                    winchModule.guiRepeatTurnRight = true;
                }
                else if (winchModule.guiRepeatTurnRight)
                {

                    winchModule.guiRepeatTurnRight = false;
                }

                #endregion

                #region Winch & Connector & Hook controls

                if (winchModule.headState == KASModuleWinch.PlugState.Deployed || winchModule.headState == KASModuleWinch.PlugState.Locked) GUI.enabled = false;
                winchModule.PlugDocked = GUILayout.Toggle(winchModule.PlugDocked, new GUIContent("Docked", "Plug mode"), guiButtonStyle, GUILayout.Width(60f));
                if (GUILayout.Button(new GUIContent("Unplug", "Unplug"), guiButtonStyle, GUILayout.Width(60f)))
                {
                    winchModule.UnplugHead();
                }
                GUI.enabled = true;

                KASModuleMagnet moduleHookMagnet = winchModule.GetHookMagnet();
                KASModuleSuctionCup moduleHookSuction = winchModule.GetHookSuction();
                KASModuleGrapplingHook moduleHookGrapple = winchModule.GetHookGrapple();

                if (moduleHookMagnet)
                {
                    moduleHookMagnet.MagnetActive = GUILayout.Toggle(moduleHookMagnet.MagnetActive, new GUIContent("Magnet", "Magnet On/Off"), guiButtonStyle, GUILayout.Width(60f));
                }

                if (moduleHookSuction)
                {
                    if (!moduleHookSuction.attachMode.FixedJoint) GUI.enabled = false;
                    if (GUILayout.Button(new GUIContent("Detach", "Detach attached object(s)"), guiButtonStyle, GUILayout.Width(60f)))
                    {
                        moduleHookSuction.DetachSuction();
                    }
                    GUI.enabled = true;
                }

                if (moduleHookGrapple)
                {
                    if (!moduleHookGrapple.attachMode.StaticJoint && !moduleHookGrapple.attachMode.FixedJoint) GUI.enabled = false;
                    if (GUILayout.Button(new GUIContent("Detach", "Detach from ground or part"), guiButtonStyle, GUILayout.Width(60f)))
                    {
                        moduleHookGrapple.Detach();
                    }
                    GUI.enabled = true;
                }

                if (!moduleHookMagnet && !moduleHookSuction && !moduleHookGrapple)
                {
                    GUI.enabled = false;
                    GUILayout.Button(new GUIContent("-", "Nothing connected or hook not supported"), guiButtonStyle, GUILayout.Width(60f));
                    GUI.enabled = true;
                }

                #endregion

                GUILayout.EndHorizontal();

            }
            GUILayout.EndVertical();
            //GUILayout.EndScrollView();
            #endregion

            #region GUI - Close
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Close", guiButtonStyle, GUILayout.Width(60f)))
            {
                GuiActive = false;
            }

            remameActived = GUILayout.Toggle(remameActived, new GUIContent("Rename", "Rename a winch"), guiButtonStyle, GUILayout.Width(60f));
            if (remameActived)
            {
                tempWinchName = GUILayout.TextField(tempWinchName, GUILayout.Width(120f));
                if (GUILayout.Button(new GUIContent("Set", "Set selected winch name to current text"), guiButtonStyle, GUILayout.Width(60f)))
                {
                    selectedWinchModule.winchName = tempWinchName;
                    remameActived = false;
                }
            }

            GUILayout.EndHorizontal();
            #endregion

            #region GUI - Tooltip & Drag windows
            GUI.Label(new Rect(0, 18, guiWindowPos.width, 30), GUI.tooltip, guiTooltipStyle);
            GUI.DragWindow();
            #endregion
        }
Пример #3
0
        void OnGUI()
        {
            if (!clickedWinch) return;

            GUI.skin = HighLogic.Skin;
            GUI.skin.label.alignment = TextAnchor.MiddleCenter;
            GUI.skin.button.alignment = TextAnchor.MiddleCenter;

            guiButtonStyle = new GUIStyle(GUI.skin.button);
            guiButtonStyle.normal.textColor = guiButtonStyle.focused.textColor = Color.white;
            guiButtonStyle.hover.textColor = guiButtonStyle.active.textColor = Color.yellow;
            guiButtonStyle.onNormal.textColor = guiButtonStyle.onFocused.textColor = guiButtonStyle.onHover.textColor = guiButtonStyle.onActive.textColor = Color.green;
            guiButtonStyle.padding = new RectOffset(4, 4, 4, 4);
            guiButtonStyle.alignment = TextAnchor.MiddleCenter;

            Vector3 headScreenPoint = Camera.main.WorldToScreenPoint(clickedWinch.headTransform.position);

            GUILayout.BeginArea(new Rect(headScreenPoint.x, Screen.height - headScreenPoint.y, 200, 200));
            GUILayout.BeginVertical();

            if (clickedWinch.evaHolderPart)
            {
                if (GUILayout.Button("Drop (Key " + grabHeadKey + ")", guiButtonStyle, GUILayout.Width(100f)))
                {
                    clickedWinch.DropHead(); ;
                    clickedWinch = null;
                }
            }
            else
            {
                if (GUILayout.Button("Grab (Key " + grabHeadKey + ")", guiButtonStyle, GUILayout.Width(100f)))
                {
                    clickedWinch.GrabHead(FlightGlobals.ActiveVessel);
                    clickedWinch = null;
                }
                if (clickedWinch)
                {
                    if (clickedWinch.headState == KASModuleWinch.PlugState.Deployed)
                    {
                        KASModuleGrab grabbedModule = KAS_Shared.GetGrabbedPartModule(FlightGlobals.ActiveVessel);
                        if (grabbedModule && !grabbedModule.part.packed)
                        {
                            KASModulePort grabbedPort = grabbedModule.GetComponent<KASModulePort>();
                            if (grabbedPort)
                            {
                                if (GUILayout.Button("Plug grabbed", guiButtonStyle, GUILayout.Width(100f)))
                                {
                                    grabbedModule.Drop();
                                    grabbedPort.transform.rotation = Quaternion.FromToRotation(grabbedPort.portNode.forward, -clickedWinch.headPortNode.forward) * grabbedPort.transform.rotation;
                                    grabbedPort.transform.position = grabbedPort.transform.position - (grabbedPort.portNode.position - clickedWinch.headPortNode.position);
                                    clickedWinch.PlugHead(grabbedPort, KASModuleWinch.PlugState.PlugDocked);
                                    clickedWinch = null;
                                }
                            }
                        }
                    }
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.EndArea();
        }
Пример #4
0
        private void UpdateWinchMouseGrab()
        {
            if (Input.GetKeyDown(KeyCode.Mouse1))
            {
                if (clickedWinch)
                {
                    clickedWinch = null;
                    return;
                }
                if (FlightGlobals.ActiveVessel.isEVA)
                {
                    KerbalEVA kerbalEva = KAS_Shared.GetKerbalEvaUnderCursor();
                    if (kerbalEva)
                    {
                        KASModuleWinch winchModule = KAS_Shared.GetWinchModuleGrabbed(kerbalEva.vessel);
                        if (winchModule)
                        {
                            clickedWinch = winchModule;
                            return;
                        }
                    }
                    

                    Transform headTransform = KAS_Shared.GetTransformUnderCursor();
                    if (headTransform)
                    {
                        KASModuleWinchHead winchHeadModule = headTransform.gameObject.GetComponent<KASModuleWinchHead>();
                        if (winchHeadModule)
                        {
                            float dist = Vector3.Distance(FlightGlobals.ActiveVessel.transform.position, headTransform.position);
                            if (dist <= radius)
                            {
                                clickedWinch = winchHeadModule.connectedWinch;
                                return;
                            }
                        }
                    }
                }
            }
        }
Пример #5
0
        void OnGUI()
        {
            if (!clickedWinch) return;

            GUI.skin = HighLogic.Skin;
            GUI.skin.label.alignment = TextAnchor.MiddleCenter;
            GUI.skin.button.alignment = TextAnchor.MiddleCenter;

            guiButtonStyle = new GUIStyle(GUI.skin.button);
            guiButtonStyle.normal.textColor = guiButtonStyle.focused.textColor = Color.white;
            guiButtonStyle.hover.textColor = guiButtonStyle.active.textColor = Color.yellow;
            guiButtonStyle.onNormal.textColor = guiButtonStyle.onFocused.textColor = guiButtonStyle.onHover.textColor = guiButtonStyle.onActive.textColor = Color.green;
            guiButtonStyle.padding = new RectOffset(4, 4, 4, 4);
            guiButtonStyle.alignment = TextAnchor.MiddleCenter;

            Vector3 headScreenPoint = Camera.main.WorldToScreenPoint(clickedWinch.headTransform.position);

            GUILayout.BeginArea(new Rect(headScreenPoint.x, Screen.height - headScreenPoint.y, 200, 200));
            GUILayout.BeginVertical();

            if (clickedWinch.evaHolderPart)
            {
                if (GUILayout.Button("Drop (Key " + grabHeadKey + ")", guiButtonStyle, GUILayout.Width(100f)))
                {
                    clickedWinch.DropHead(); ;
                    clickedWinch = null;
                }
            }
            else
            {
                if (GUILayout.Button("Grab (Key " + grabHeadKey + ")", guiButtonStyle, GUILayout.Width(100f)))
                {
                    clickedWinch.GrabHead(FlightGlobals.ActiveVessel);
                    clickedWinch = null;
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.EndArea();
        }