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; moduleMagnet = null; moduleGrapple = null; modulePort = null; moduleAnchor = null; moduleStrut = null; moduleRotor = null; moduleWinch = clickedPart.GetComponent <KASModuleWinch>(); moduleMagnet = clickedPart.GetComponent <KASModuleMagnet>(); moduleGrapple = clickedPart.GetComponent <KASModuleHarpoon>(); 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 + ")"); } } }
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; moduleMagnet = null; moduleGrapple = null; modulePort = null; moduleAnchor = null; moduleStrut = null; moduleRotor = null; moduleWinch = clickedPart.GetComponent<KASModuleWinch>(); moduleMagnet = clickedPart.GetComponent<KASModuleMagnet>(); moduleGrapple = clickedPart.GetComponent<KASModuleHarpoon>(); 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 + ")"); } } }
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 GUILayout.BeginVertical(guiDataboxStyle); int i = 0; foreach (KASModuleWinch winchModule in allWinchModule) { if (winchModule.vessel != FlightGlobals.ActiveVessel || !winchModule.isActive || winchModule.CheckBlocked()) { continue; } GUILayout.BeginHorizontal(); string sysname; if (!string.IsNullOrEmpty(winchModule.winchName)) { 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, false); winchModule.highLightStarted = true; } } else { if (winchModule.highLightStarted) { winchModule.part.SetHighlight(false, 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(); KASModuleHarpoon moduleHookGrapple = winchModule.GetHookGrapple(); if (moduleHookMagnet) { moduleHookMagnet.MagnetActive = GUILayout.Toggle( moduleHookMagnet.MagnetActive, new GUIContent("Magnet", "Magnet On/Off"), guiButtonStyle, GUILayout.Width(60f)); } 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 && !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(); #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 }