public void GUIDropDownDisplay(params GUILayoutOption[] GUIoptions) { if (GUILayout.Button(optionStrings[selectedOption], GUIoptions)) { listActive = true; } if (listStyle == null) { listStyle = new GUIStyle(GUI.skin.window); listStyle.padding = new RectOffset(1, 1, 1, 1); } if (buttonStyle == null) { buttonStyle = new GUIStyle(GUI.skin.button); buttonStyle.padding = new RectOffset(0, 0, 0, 0); } if (listActive && !hasActivated) { Vector3 upperLeft = FARGUIUtils.GetMousePos(); displayObject.ActivateDisplay(this.GetHashCode(), new Rect(upperLeft.x - 5, upperLeft.y - 5, 100, 150), ListDisplay, listStyle); hasActivated = true; InputLockManager.SetControlLock(ControlTypes.All, "DropdownScrollLock"); } if (hasActivated) { if (!displayObject.displayRect.Contains(FARGUIUtils.GetMousePos())) { listActive = false; hasActivated = false; displayObject.DisableDisplay(); InputLockManager.RemoveControlLock("DropdownScrollLock"); } } }
public static double TextEntryForDouble(string label, int labelWidth, double prevValue) { string valString = prevValue.ToString(); FARGUIUtils.TextEntryField(label, labelWidth, ref valString); if (!Regex.IsMatch(valString, @"^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$")) { return(prevValue); } return(double.Parse(valString)); }
private void debugWindow(int windowID) { GUIStyle thisStyle = new GUIStyle(GUI.skin.toggle); thisStyle.stretchHeight = true; thisStyle.stretchWidth = true; thisStyle.padding = new RectOffset(4, 4, 4, 4); thisStyle.margin = new RectOffset(4, 4, 4, 4); GUIStyle buttonStyle = new GUIStyle(GUI.skin.button); buttonStyle.stretchHeight = true; buttonStyle.stretchWidth = true; buttonStyle.padding = new RectOffset(4, 4, 4, 4); buttonStyle.margin = new RectOffset(4, 4, 4, 4); GUIStyle boxStyle = new GUIStyle(GUI.skin.box); boxStyle.stretchHeight = true; boxStyle.stretchWidth = true; boxStyle.padding = new RectOffset(4, 4, 4, 4); boxStyle.margin = new RectOffset(4, 4, 4, 4); activeTab = (MenuTab)GUILayout.SelectionGrid((int)activeTab, MenuTab_str, 4); if (activeTab == MenuTab.DebugAndData) { DebugAndDataTab(thisStyle); } else if (activeTab == MenuTab.PartClassification) { PartClassificationTab(buttonStyle, boxStyle); } else if (activeTab == MenuTab.AeroStress) { AeroStressTab(buttonStyle, boxStyle); } else { AeroDataTab(buttonStyle, boxStyle); } // SaveWindowPos.x = windowPos.x; // SaveWindowPos.y = windowPos.y; GUI.DragWindow(); debugWinPos = FARGUIUtils.ClampToScreen(debugWinPos); }
private void ChangeColor(string colorTitle, ref Color input, ref Texture2D texture) { GUILayout.BeginHorizontal(); GUILayout.Label(colorTitle + " (r,g,b):", GUILayout.Width(80)); bool updateTexture = false; GUILayout.BeginHorizontal(GUILayout.Width(150)); float tmp = input.r; input.r = (float)FARGUIUtils.TextEntryForDouble("", 0, input.r); updateTexture |= tmp != input.r; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(GUILayout.Width(150)); tmp = input.g; input.g = (float)FARGUIUtils.TextEntryForDouble("", 0, input.g); updateTexture |= tmp != input.g; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(GUILayout.Width(150)); tmp = input.b; input.b = (float)FARGUIUtils.TextEntryForDouble("", 0, input.b); updateTexture |= tmp != input.b; GUILayout.EndHorizontal(); if (updateTexture) { ReColorTexture(ref input, ref texture); } Rect textRect = GUILayoutUtility.GetRect(25, 15); textRect.Set(textRect.x, textRect.y + 10, textRect.width, textRect.height); GUI.DrawTexture(textRect, texture); GUILayout.EndHorizontal(); }
public void OnGUI() { GUI.skin = HighLogic.Skin; if (debugMenu) { debugWinPos = GUILayout.Window("FARDebug".GetHashCode(), debugWinPos, debugWindow, "FAR Debug Options, v0.14.6", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); if (!inputLocked && debugWinPos.Contains(FARGUIUtils.GetMousePos())) { InputLockManager.SetControlLock(ControlTypes.KSC_ALL, "FARDebugLock"); inputLocked = true; } else if (inputLocked && !debugWinPos.Contains(FARGUIUtils.GetMousePos())) { InputLockManager.RemoveControlLock("FARDebugLock"); inputLocked = false; } } else if (inputLocked) { InputLockManager.RemoveControlLock("FARDebugLock"); inputLocked = false; } }
private void AeroStressTab(GUIStyle buttonStyle, GUIStyle boxStyle) { int i = 0; int removeIndex = -1; GUILayout.BeginHorizontal(); GUILayout.BeginVertical(boxStyle); for (i = 0; i < FARAeroStress.StressTemplates.Count; i++) { GUILayout.BeginHorizontal(); bool active = GUILayout.Toggle(i == aeroStressIndex, FARAeroStress.StressTemplates[i].name, buttonStyle, GUILayout.Width(150)); if (GUILayout.Button("-", buttonStyle, GUILayout.Width(30), GUILayout.Height(30))) { removeIndex = i; } GUILayout.EndHorizontal(); if (active) { aeroStressIndex = i; } } if (removeIndex >= 0) { FARAeroStress.StressTemplates.RemoveAt(removeIndex); if (aeroStressIndex == removeIndex) { aeroStressIndex--; } removeIndex = -1; } if (GUILayout.Button("+", buttonStyle, GUILayout.Width(30), GUILayout.Height(30))) { FARPartStressTemplate newTemplate = new FARPartStressTemplate(); newTemplate.XZmaxStress = 500; newTemplate.YmaxStress = 500; newTemplate.name = "default"; newTemplate.isSpecialTemplate = false; newTemplate.minNumResources = 0; newTemplate.resources = new List <string>(); newTemplate.excludeResources = new List <string>(); newTemplate.rejectUnlistedResources = false; newTemplate.crewed = false; newTemplate.flowModeNeeded = false; newTemplate.flowMode = ResourceFlowMode.NO_FLOW; FARAeroStress.StressTemplates.Add(newTemplate); } GUILayout.EndVertical(); GUILayout.BeginVertical(boxStyle); FARPartStressTemplate activeTemplate = FARAeroStress.StressTemplates[aeroStressIndex]; string tmp; FARGUIUtils.TextEntryField("Name:", 80, ref activeTemplate.name); activeTemplate.YmaxStress = FARGUIUtils.TextEntryForDouble("Axial (Y-axis) Max Stress:", 240, activeTemplate.YmaxStress); activeTemplate.XZmaxStress = FARGUIUtils.TextEntryForDouble("Lateral (X,Z-axis) Max Stress:", 240, activeTemplate.XZmaxStress); activeTemplate.crewed = GUILayout.Toggle(activeTemplate.crewed, "Requires Crew Compartment"); tmp = activeTemplate.minNumResources.ToString(); FARGUIUtils.TextEntryField("Min Num Resources:", 80, ref tmp); tmp = Regex.Replace(tmp, @"[^\d]", ""); activeTemplate.minNumResources = Convert.ToInt32(tmp); GUILayout.Label("Req Resources:"); StringListUpdateGUI(activeTemplate.resources, buttonStyle, boxStyle); GUILayout.Label("Exclude Resources:"); StringListUpdateGUI(activeTemplate.excludeResources, buttonStyle, boxStyle); activeTemplate.rejectUnlistedResources = GUILayout.Toggle(activeTemplate.rejectUnlistedResources, "Reject Unlisted Res"); activeTemplate.flowModeNeeded = GUILayout.Toggle(activeTemplate.flowModeNeeded, "Requires Specific Flow Mode"); if (activeTemplate.flowModeNeeded) { activeTemplate.flowMode = (ResourceFlowMode)GUILayout.SelectionGrid((int)activeTemplate.flowMode, FlowMode_str, 1); } activeTemplate.isSpecialTemplate = GUILayout.Toggle(activeTemplate.isSpecialTemplate, "Special Hardcoded Usage"); FARAeroStress.StressTemplates[aeroStressIndex] = activeTemplate; GUILayout.EndVertical(); GUILayout.EndHorizontal(); }
private void AeroDataTab(GUIStyle buttonStyle, GUIStyle boxStyle) { int i = 0; GUILayout.BeginVertical(boxStyle); FARAeroUtil.areaFactor = FARGUIUtils.TextEntryForDouble("Area Factor:", 160, FARAeroUtil.areaFactor); FARAeroUtil.attachNodeRadiusFactor = FARGUIUtils.TextEntryForDouble("Node Diameter Factor:", 160, FARAeroUtil.attachNodeRadiusFactor * 2) * 0.5; FARAeroUtil.incompressibleRearAttachDrag = FARGUIUtils.TextEntryForDouble("Rear Node Drag, Incomp:", 160, FARAeroUtil.incompressibleRearAttachDrag); FARAeroUtil.sonicRearAdditionalAttachDrag = FARGUIUtils.TextEntryForDouble("Rear Node Drag, M = 1:", 160, FARAeroUtil.sonicRearAdditionalAttachDrag); FARControllableSurface.timeConstant = FARGUIUtils.TextEntryForDouble("Ctrl Surf Time Constant:", 160, FARControllableSurface.timeConstant); FARControllableSurface.timeConstantFlap = FARGUIUtils.TextEntryForDouble("Flap Time Constant:", 160, FARControllableSurface.timeConstantFlap); FARControllableSurface.timeConstantSpoiler = FARGUIUtils.TextEntryForDouble("Spoiler Time Constant:", 160, FARControllableSurface.timeConstantSpoiler); GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.Label("Celestial Body Atmosperic Properties"); GUILayout.BeginHorizontal(); GUILayout.BeginVertical(boxStyle); GUILayout.BeginHorizontal(); int j = 0; for (i = 0; i < FlightGlobals.Bodies.Count; i++) { CelestialBody body = FlightGlobals.Bodies[i]; if (!body.atmosphere) { continue; } bool active = GUILayout.Toggle(i == atmBodyIndex, body.GetName(), buttonStyle, GUILayout.Width(150), GUILayout.Height(40)); if (active) { atmBodyIndex = i; } if ((j + 1) % 4 == 0) { GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); } j++; } GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.BeginVertical(boxStyle); int flightGlobalsIndex = FlightGlobals.Bodies[atmBodyIndex].flightGlobalsIndex; double[] atmProperties = FARAeroUtil.bodyAtmosphereConfiguration[flightGlobalsIndex]; atmProperties[1] = FARGUIUtils.TextEntryForDouble("Ratio of Specific Heats:", 80, atmProperties[1]); double dTmp = 8314.5 / atmProperties[2]; dTmp = FARGUIUtils.TextEntryForDouble("Gas Molecular Mass:", 80, dTmp); atmProperties[2] = 8314.5 / dTmp; atmProperties[0] = atmProperties[1] * atmProperties[2]; atmProperties[3] = FARGUIUtils.TextEntryForDouble("Gas Viscosity:", 80, atmProperties[3]); atmProperties[4] = FARGUIUtils.TextEntryForDouble("Ref Temp for Viscosity:", 80, atmProperties[4]); FARAeroUtil.bodyAtmosphereConfiguration[flightGlobalsIndex] = atmProperties; GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.EndVertical(); }
private void AeroDataTab(GUIStyle buttonStyle, GUIStyle boxStyle) { int i = 0; GUILayout.BeginVertical(boxStyle); string tmp; tmp = FARAeroUtil.areaFactor.ToString(); FARGUIUtils.TextEntryField("Area Factor:", 160, ref tmp); tmp = Regex.Replace(tmp, @"[^\d+-\.]", ""); FARAeroUtil.areaFactor = Convert.ToDouble(tmp); tmp = (FARAeroUtil.attachNodeRadiusFactor * 2).ToString(); FARGUIUtils.TextEntryField("Node Diameter Factor:", 160, ref tmp); tmp = Regex.Replace(tmp, @"[^\d+-\.]", ""); FARAeroUtil.attachNodeRadiusFactor = Convert.ToDouble(tmp) * 0.5; tmp = FARAeroUtil.incompressibleRearAttachDrag.ToString(); FARGUIUtils.TextEntryField("Rear Node Drag, Incomp:", 160, ref tmp); tmp = Regex.Replace(tmp, @"[^\d+-\.]", ""); FARAeroUtil.incompressibleRearAttachDrag = Convert.ToDouble(tmp); tmp = FARAeroUtil.sonicRearAdditionalAttachDrag.ToString(); FARGUIUtils.TextEntryField("Rear Node Drag, M = 1:", 160, ref tmp); tmp = Regex.Replace(tmp, @"[^\d+-\.]", ""); FARAeroUtil.sonicRearAdditionalAttachDrag = Convert.ToDouble(tmp); tmp = FARControllableSurface.timeConstant.ToString(); FARGUIUtils.TextEntryField("Ctrl Surf Time Constant:", 160, ref tmp); tmp = Regex.Replace(tmp, @"[^\d+-\.]", ""); FARControllableSurface.timeConstant = Convert.ToDouble(tmp); tmp = FARControllableSurface.timeConstantFlap.ToString(); FARGUIUtils.TextEntryField("Flap/Spoiler Time Constant:", 160, ref tmp); tmp = Regex.Replace(tmp, @"[^\d+-\.]", ""); FARControllableSurface.timeConstantFlap = Convert.ToDouble(tmp); GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.Label("Celestial Body Atmosperic Properties"); GUILayout.BeginHorizontal(); GUILayout.BeginVertical(boxStyle); GUILayout.BeginHorizontal(); int j = 0; for (i = 0; i < FlightGlobals.Bodies.Count; i++) { CelestialBody body = FlightGlobals.Bodies[i]; if (!body.atmosphere) { continue; } bool active = GUILayout.Toggle(i == atmBodyIndex, body.GetName(), buttonStyle, GUILayout.Width(150), GUILayout.Height(40)); if (active) { atmBodyIndex = i; } if ((j + 1) % 4 == 0) { GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); } j++; } GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.BeginVertical(boxStyle); int flightGlobalsIndex = FlightGlobals.Bodies[atmBodyIndex].flightGlobalsIndex; Vector3d atmProperties = FARAeroUtil.bodyAtmosphereConfiguration[flightGlobalsIndex]; tmp = atmProperties.y.ToString(); FARGUIUtils.TextEntryField("Ratio of Specific Heats:", 80, ref tmp); tmp = Regex.Replace(tmp, @"[^\d+-\.]", ""); atmProperties.y = Convert.ToDouble(tmp); double dTmp = 8314.5 / atmProperties.z; tmp = dTmp.ToString(); FARGUIUtils.TextEntryField("Gas Molecular Mass:", 80, ref tmp); tmp = Regex.Replace(tmp, @"[^\d+-\.]", ""); atmProperties.z = 8314.5 / Convert.ToDouble(tmp); atmProperties.x = atmProperties.y * atmProperties.z; FARAeroUtil.bodyAtmosphereConfiguration[flightGlobalsIndex] = atmProperties; GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.EndVertical(); }