/// <summary> /// Selects Object under the mouse curser. /// </summary> internal void SelectMouseObject() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); int layerMask = ~0; if (!Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity, layerMask)) { return; } StaticInstance myHitinstance = GetRootFromHit(hit.collider.gameObject); if (myHitinstance == null) { Log.Normal("No RootObject found"); return; } else { if (KerbalKonstructs.selectedInstance != null) { KerbalKonstructs.DeselectObject(true, true); } //Log.Normal("Try to select Object: " + myHitinstance.mesh.name); myHitinstance.HighlightObject(XKCDColors.Green_Yellow); KerbalKonstructs.SelectInstance(myHitinstance, true); if (!EditorGUI.instance.IsOpen()) { EditorGUI.instance.Open(); } } }
public override void Draw() { if (MapView.MapIsEnabled) { if (KerbalKonstructs.selectedInstance != null) { KerbalKonstructs.DeselectObject(true, true); } } KKWindow = new GUIStyle(GUI.skin.window); KKWindow.padding = new RectOffset(3, 3, 5, 5); if (bHalfwindow) { if (!bHalvedWindow) { facilityManagerRect = new Rect(facilityManagerRect.xMin, facilityManagerRect.yMin, facilityManagerRect.width, facilityManagerRect.height - 200); bHalvedWindow = true; } } if (!bHalfwindow) { if (bHalvedWindow) { facilityManagerRect = new Rect(facilityManagerRect.xMin, facilityManagerRect.yMin, facilityManagerRect.width, facilityManagerRect.height + 200); bHalvedWindow = false; } } facilityManagerRect = GUI.Window(0xB01B2B5, facilityManagerRect, drawFacilityManagerWindow, "", KKWindow); }
public void CreatePreviewInstance(StaticModel model) { StaticInstance instance = new StaticInstance(); GroupCenter groupCenter = null;//XXX StaticsEditorGUI.GetCloesedCenter(FlightGlobals.ActiveVessel.transform.position); if (groupCenter == null) { MiscUtils.HUDMessage("No Local GroupCenter found. Create one, then try again"); } //instance.mesh = GameObject.Instantiate(model.prefab); instance.RadiusOffset = (float)FlightGlobals.ActiveVessel.altitude; instance.CelestialBody = KerbalKonstructs.instance.GetCurrentBody(); instance.Group = groupCenter.Group; instance.RadialPosition = KerbalKonstructs.instance.GetCurrentBody().transform.InverseTransformPoint(FlightGlobals.ActiveVessel.transform.position); instance.RotationAngle = 0f; instance.Orientation = Vector3.up; instance.VisibilityRange = 25000f; instance.configPath = KerbalKonstructs.newInstancePath + "/" + model.name + "-instances.cfg"; instance.configUrl = null; instance.model = model; instance.Orientate(); instance.Activate(); KerbalKonstructs.SelectInstance(instance, true); currPreview = instance; }
void OnFacilitySelected(FacilityItem facility) { selectedFacility = facility; KerbalKonstructs.SelectInstance(selectedFacility.facility, false); FacilityManager.selectedInstance = selectedFacility.facility; FacilityManager.instance.Open(); }
public void Close() { if (KerbalKonstructs.selectedInstance != null) { KerbalKonstructs.DeselectObject(true, true); } SetActive(false); }
/// <summary> /// Spawns an Instance of an defined StaticModel /// </summary> /// <param name="model"></param> /// <param name="fOffset"></param> /// <param name="vPosition"></param> /// <param name="fAngle"></param> /// <returns></returns> public string SpawnInstance(StaticModel model, float fOffset, Vector3 vPosition) { StaticInstance instance = new StaticInstance(); instance.Orientation = Vector3.up; instance.heighReference = HeightReference.Terrain; instance.VisibilityRange = (PhysicsGlobals.Instance.VesselRangesDefault.flying.unload + 3000); instance.Group = "SaveGame"; instance.RadialPosition = vPosition; instance.model = model; if (instance.model == null) { Log.UserError("LoadFromSave: Canot find model named: " + model.name); instance = null; } //instance.mesh = UnityEngine.Object.Instantiate(instance.model.prefab); instance.CelestialBody = KerbalKonstructs.instance.GetCurrentBody(); instance.RadiusOffset = fOffset; instance.RotationAngle = 0; instance.RefLatitude = KKMath.GetLatitudeInDeg(instance.RadialPosition); instance.RefLongitude = KKMath.GetLongitudeInDeg(instance.RadialPosition); InstanceUtil.CreateGroupCenterIfMissing(instance); bool oldLegacySpawn = KerbalKonstructs.convertLegacyConfigs; instance.Orientate(); instance.Activate(); KerbalKonstructs.convertLegacyConfigs = oldLegacySpawn; KerbalKonstructs.SelectInstance(instance, true); selectedInstance = instance; startPosition = selectedInstance.position; instance.Update(); instance.isInSavegame = true; instance.HighlightObject(XKCDColors.FreshGreen); this.Open(); return(instance.UUID); }
public override void Close() { if (KerbalKonstructs.selectedInstance != null) { KerbalKonstructs.DeselectObject(true, true); } MerchantGUI.lastInstance = null; StorageGUI.lastInstance = null; base.Close(); }
public void ToggleEditor() { if (KerbalKonstructs.selectedInstance != null) { KerbalKonstructs.DeselectObject(true, true); } this.Toggle(); if (snapTargetInstance != null) { snapTargetInstance.HighlightObject(UnityEngine.Color.clear); snapTargetInstance = null; } }
/// <summary> /// Spawns an Instance of an defined StaticModel /// </summary> /// <param name="model"></param> /// <param name="fOffset"></param> /// <param name="vPosition"></param> /// <param name="fAngle"></param> /// <returns></returns> internal void SpawnInstance(StaticModel model, GroupCenter groupCenter, Vector3 position, Vector3 rotation) { StaticInstance instance = new StaticInstance(); instance.model = model; //instance.mesh = UnityEngine.Object.Instantiate(model.prefab); instance.CelestialBody = FlightGlobals.currentMainBody; instance.groupCenter = groupCenter; instance.Group = groupCenter.Group; instance.transform.position = position; instance.transform.parent = groupCenter.gameObject.transform; instance.RelativePosition = instance.transform.localPosition; instance.Orientation = rotation; if (!Directory.Exists(KSPUtil.ApplicationRootPath + "GameData/" + KerbalKonstructs.newInstancePath)) { Directory.CreateDirectory(KSPUtil.ApplicationRootPath + "GameData/" + KerbalKonstructs.newInstancePath); } instance.configPath = KerbalKonstructs.newInstancePath + "/" + model.name + "-instances.cfg"; instance.configUrl = null; enableColliders = false; enableColliders2 = false; instance.Orientate(); instance.Activate(); KerbalKonstructs.SelectInstance(instance, true); GrassColor2 grassMod = instance.gameObject.GetComponent <GrassColor2>(); if (grassMod != null) { grassMod.UpdateCallBack(StaticsEditorGUI.defaultGrassPreset); } }
void OnSelect(InstanceItem item) { var instance = item.instance; EditorGUI.CloseEditors(); if (!EditorGUI.instance.IsOpen()) { EditorGUI.instance.Open(); } if (selectedObject != null) { selectedObject.HighlightObject(UnityEngine.Color.clear); selectedObject = instance; } if (snapTargetInstance == instance) { snapTargetInstance = null; } KerbalKonstructs.SelectInstance(instance, false); instance.HighlightObject(XKCDColors.Green_Yellow); }
/// <summary> /// Called after Awake. used for setting up references between objects and initializing windows. /// </summary> public void Start() { Log.Warning("WindowManager Start"); KKmain = KerbalKonstructs.instance; KKmain.WindowManager = this; }
/// <summary> /// Instance Editor window /// </summary> /// <param name="windowID"></param> void InstanceEditorWindow(int windowID) { UpdateVectors(); GUILayout.BeginHorizontal(); { GUI.enabled = false; GUILayout.Button("-KK-", UIMain.DeadButton, GUILayout.Height(21)); GUILayout.FlexibleSpace(); GUILayout.Button("Mod Editor", UIMain.DeadButton, GUILayout.Height(21)); GUILayout.FlexibleSpace(); GUI.enabled = true; if (GUILayout.Button("X", UIMain.DeadButtonRed, GUILayout.Height(21))) { //KerbalKonstructs.instance.saveObjects(); KerbalKonstructs.DeselectObject(true, true); } } GUILayout.EndHorizontal(); GUILayout.Space(1); GUILayout.Box(tHorizontalSep, UIMain.BoxNoBorder, GUILayout.Height(4)); GUILayout.Space(2); GUILayout.BeginHorizontal(); if (isInRange) { GUILayout.Button(selectedInstance.model.title + " (" + selectedInstance.indexInGroup.ToString() + ")", GUILayout.Height(23)); } else { GUILayout.Button("Out of Range", UIMain.ButtonRed, GUILayout.Height(23)); } if (wasInRange && !isInRange) { wasInRange = false; selectedInstance.HighlightObject(XKCDColors.Reddish); } if (!wasInRange && isInRange) { wasInRange = true; selectedInstance.HighlightObject(XKCDColors.FreshGreen); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); if (!foldedIn) { GUILayout.Label("Increment"); increment = float.Parse(GUILayout.TextField(increment.ToString(), 5, GUILayout.Width(48))); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (GUILayout.Button("0.001", GUILayout.Height(18))) { increment = 0.001f; } if (GUILayout.Button("0.01", GUILayout.Height(18))) { increment = 0.01f; } if (GUILayout.Button("0.1", GUILayout.Height(18))) { increment = 0.1f; } if (GUILayout.Button("1", GUILayout.Height(18))) { increment = 1f; } if (GUILayout.Button("10", GUILayout.Height(18))) { increment = 10f; } if (GUILayout.Button("25", GUILayout.Height(16))) { increment = 25f; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); } else { GUILayout.Label("i"); increment = float.Parse(GUILayout.TextField(increment.ToString(), 3, GUILayout.Width(25))); if (GUILayout.Button("0.1", GUILayout.Height(23))) { increment = 0.1f; } if (GUILayout.Button("1", GUILayout.Height(23))) { increment = 1f; } if (GUILayout.Button("10", GUILayout.Height(23))) { increment = 10f; } } } GUILayout.EndHorizontal(); // // Set reference butons // GUILayout.BeginHorizontal(); { GUILayout.Label("Reference System: "); GUILayout.FlexibleSpace(); GUI.enabled = (referenceSystem == Space.World); if (GUILayout.Button(new GUIContent(UIMain.iconCubes.texture, "Model"), GUILayout.Height(23), GUILayout.Width(23))) { referenceSystem = Space.Self; UpdateGizmo(); UpdateVectors(); } GUI.enabled = (referenceSystem == Space.Self); if (GUILayout.Button(new GUIContent(UIMain.iconWorld.texture, "World"), GUILayout.Height(23), GUILayout.Width(23))) { referenceSystem = Space.World; UpdateGizmo(); UpdateVectors(); } GUI.enabled = true; GUILayout.Label(referenceSystem.ToString()); } GUILayout.EndHorizontal(); float fTempWidth = 80f; // // Position editing // GUILayout.BeginHorizontal(); GUILayout.Label("Back / Forward:"); GUILayout.FlexibleSpace(); ; if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21))) { SetTransform(Vector3.back * increment); } if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21))) { SetTransform(Vector3.forward * increment); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Left / Right:"); GUILayout.FlexibleSpace(); if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21))) { SetTransform(Vector3.left * increment); } if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21))) { SetTransform(Vector3.right * increment); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.EndHorizontal(); GUI.enabled = true; // // Altitude editing // GUILayout.BeginHorizontal(); { GUILayout.Label("Alt."); GUILayout.FlexibleSpace(); selectedInstance.RadiusOffset = float.Parse(GUILayout.TextField(selectedInstance.RadiusOffset.ToString(), 25, GUILayout.Width(fTempWidth))); if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21))) { SetTransform(Vector3.down * increment); } if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21))) { SetTransform(Vector3.up * increment); } } GUILayout.EndHorizontal(); GUI.enabled = true; GUILayout.Space(5); fTempWidth = 80f; GUI.enabled = true; // // Rotation // GUILayout.BeginHorizontal(); { GUILayout.Label("Heading:"); GUILayout.FlexibleSpace(); GUILayout.TextField(heading.ToString(), 9, GUILayout.Width(fTempWidth)); if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(23))) { SetRotation(-increment); } if (GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(23))) { SetRotation(-increment); } if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(23))) { SetRotation(increment); } if (GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(23))) { SetRotation(increment); } } GUILayout.EndHorizontal(); GUILayout.Space(1); GUILayout.Box(tHorizontalSep, UIMain.BoxNoBorder, GUILayout.Height(4)); GUILayout.Space(2); GUILayout.Space(5); GUI.enabled = true; GUI.enabled = true; GUILayout.FlexibleSpace(); GUILayout.BeginHorizontal(); { GUI.enabled = isInRange; if (GUILayout.Button("Save&Close", GUILayout.Width(110), GUILayout.Height(23))) { selectedInstance.ToggleAllColliders(true); KerbalKonstructs.DeselectObject(true, true); selectedInstance.HighlightObject(Color.clear); } GUI.enabled = true; GUILayout.FlexibleSpace(); if (GUILayout.Button("Destroy", GUILayout.Height(21))) { DeleteInstance(); } } GUILayout.EndHorizontal(); GUILayout.Space(15); GUILayout.Space(1); GUILayout.Box(tHorizontalSep, UIMain.BoxNoBorder, GUILayout.Height(4)); GUILayout.Space(2); if (GUI.tooltip != "") { var labelSize = GUI.skin.GetStyle("Label").CalcSize(new GUIContent(GUI.tooltip)); GUI.Box(new Rect(Event.current.mousePosition.x - (25 + (labelSize.x / 2)), Event.current.mousePosition.y - 40, labelSize.x + 10, labelSize.y + 5), GUI.tooltip); } GUI.DragWindow(new Rect(0, 0, 10000, 10000)); }
/// <summary> /// Called after Awake. used for setting up references between objects and initializing windows. /// </summary> public void Start() { KKmain = KerbalKonstructs.instance; }
/// <summary> /// Instance Editor window /// </summary> /// <param name="windowID"></param> void InstanceEditorWindow(int windowID) { UpdateVectors(); GUILayout.BeginHorizontal(); { GUI.enabled = false; GUILayout.Button("-KK-", UIMain.DeadButton, GUILayout.Height(21)); GUILayout.FlexibleSpace(); GUILayout.Button("Instance Editor", UIMain.DeadButton, GUILayout.Height(21)); GUILayout.FlexibleSpace(); GUI.enabled = true; if (GUILayout.Button("X", UIMain.DeadButtonRed, GUILayout.Height(21))) { //KerbalKonstructs.instance.saveObjects(); KerbalKonstructs.DeselectObject(true, true); //this.Close(); } } GUILayout.EndHorizontal(); GUILayout.Space(1); GUILayout.Box(tHorizontalSep, UIMain.BoxNoBorder, GUILayout.Height(4)); GUILayout.Space(2); GUILayout.BeginHorizontal(); GUILayout.Button(selectedInstance.model.title + " (" + selectedInstance.indexInGroup.ToString() + ")", GUILayout.Height(23)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label("Position"); GUILayout.FlexibleSpace(); if (GUILayout.Button(new GUIContent(tCopyPos, "Copy Position"), GUILayout.Width(23), GUILayout.Height(23))) { savedpos = true; savedPosition = selectedInstance.transform.localPosition; savedRotation = selectedInstance.transform.localEulerAngles; // Debug.Log("KK: Instance position copied"); } if (GUILayout.Button(new GUIContent(tPastePos, "Paste Position"), GUILayout.Width(23), GUILayout.Height(23))) { if (savedpos) { selectedInstance.transform.localPosition = savedPosition; selectedInstance.transform.localEulerAngles = savedRotation; ApplySettings(); // Debug.Log("KK: Instance position pasted"); } } if (GUILayout.Button(new GUIContent(tSnap, "Snap to Target"), GUILayout.Width(23), GUILayout.Height(23))) { if (StaticsEditorGUI.instance.snapTargetInstance == null) { Log.UserError("No Snaptarget selected"); } else { selectedInstance.transform.localPosition = StaticsEditorGUI.instance.snapTargetInstance.transform.localPosition; selectedInstance.transform.localEulerAngles = StaticsEditorGUI.instance.snapTargetInstance.transform.localEulerAngles; ApplySettings(); } } GUILayout.FlexibleSpace(); GUILayout.Label("Increment"); increment = float.Parse(GUILayout.TextField(increment.ToString(), 5, GUILayout.Width(48))); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (GUILayout.Button("0.001", GUILayout.Height(18))) { increment = 0.001f; } if (GUILayout.Button("0.01", GUILayout.Height(18))) { increment = 0.01f; } if (GUILayout.Button("0.1", GUILayout.Height(18))) { increment = 0.1f; } if (GUILayout.Button("1", GUILayout.Height(18))) { increment = 1f; } if (GUILayout.Button("10", GUILayout.Height(18))) { increment = 10f; } if (GUILayout.Button("25", GUILayout.Height(16))) { increment = 25f; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); } GUILayout.EndHorizontal(); // // Set reference butons // GUILayout.BeginHorizontal(); { GUILayout.Label("Reference System: "); GUILayout.Label(referenceSystem.ToString(), UIMain.LabelWhite); GUILayout.FlexibleSpace(); GUI.enabled = (referenceSystem == Reference.Center); if (GUILayout.Button(new GUIContent(UIMain.iconCubes.texture, "Model"), GUILayout.Height(23), GUILayout.Width(23))) { referenceSystem = Reference.Model; UpdateGizmo(); UpdateVectors(); } GUI.enabled = (referenceSystem == Reference.Model); if (GUILayout.Button(new GUIContent(UIMain.iconWorld.texture, "Group Center"), GUILayout.Height(23), GUILayout.Width(23))) { referenceSystem = Reference.Center; UpdateGizmo(); UpdateVectors(); } GUI.enabled = true; } GUILayout.EndHorizontal(); // // Model Switching // GUILayout.BeginHorizontal(); { GUILayout.Label("Selected Variant: "); GUI.enabled = (selectedInstance.model.hasVariants); string vaiantstring = (String.IsNullOrEmpty(selectedInstance.VariantName)) ? "N.A." : selectedInstance.VariantName; if (GUILayout.Button(vaiantstring, GUILayout.Width(150), GUILayout.Height(21))) { VariantSelector.staticInstance = selectedInstance; VariantSelector.Open(); } GUI.enabled = true; GUILayout.FlexibleSpace(); } GUILayout.EndHorizontal(); // // Position editing // GUILayout.BeginHorizontal(); GUILayout.Label("Back / Fwd:"); GUILayout.FlexibleSpace(); posZStr = (GUILayout.TextField(posZStr, 11, GUILayout.Width(fTempWidth))); if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21))) { SetTransform(Vector3.back * increment); } if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21))) { SetTransform(Vector3.forward * increment); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Left / Right:"); GUILayout.FlexibleSpace(); posXStr = (GUILayout.TextField(posXStr, 11, GUILayout.Width(fTempWidth))); if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21))) { SetTransform(Vector3.left * increment); } if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21))) { SetTransform(Vector3.right * increment); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Down / Up:"); GUILayout.FlexibleSpace(); posYStr = (GUILayout.TextField(posYStr, 11, GUILayout.Width(fTempWidth))); if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21))) { SetTransform(Vector3.down * increment); } if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21))) { SetTransform(Vector3.up * increment); } GUILayout.EndHorizontal(); GUI.enabled = true; if (GUILayout.Button("Snap to Terrain", GUILayout.Height(21))) { Vector3 pos = selectedInstance.CelestialBody.GetWorldSurfacePosition(selectedInstance.RefLatitude, selectedInstance.RefLongitude, selectedInstance.surfaceHeight); selectedInstance.transform.position = pos; ApplySettings(); } GUI.enabled = true; GUILayout.Space(5); // // Orientation quick preset // GUILayout.Space(1); GUILayout.Box(tHorizontalSep, UIMain.BoxNoBorder, GUILayout.Height(4)); GUILayout.Space(2); //GUILayout.BeginHorizontal(); //{ // GUILayout.Label("Euler Rot."); // GUILayout.FlexibleSpace(); // GUILayout.Label("X", GUILayout.Height(18)); // oriXStr = (GUILayout.TextField(oriXStr, 6, GUILayout.Width(48), GUILayout.Height(18))); // GUILayout.Label("Y", GUILayout.Height(18)); // oriYStr = (GUILayout.TextField(oriYStr, 6, GUILayout.Width(48), GUILayout.Height(18))); // GUILayout.Label("Z", GUILayout.Height(18)); // oriZStr = (GUILayout.TextField(oriZStr, 6, GUILayout.Width(48), GUILayout.Height(18))); //} //GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label("Orientation:"); GUILayout.FlexibleSpace(); if (GUILayout.Button(new GUIContent("Zero", "Zero Rotation"), GUILayout.Height(21), GUILayout.Width(50))) { selectedInstance.transform.localEulerAngles = Vector3.zero; ApplySettings(); } if (GUILayout.Button(new GUIContent("C-U", "allign UP to GroupCenter Up-vector"), GUILayout.Height(21), GUILayout.Width(50))) { Vector3 newfwd = Vector3.ProjectOnPlane(selectedInstance.transform.forward, selectedInstance.transform.parent.up).normalized; Quaternion rotation = new Quaternion(); rotation.SetLookRotation(newfwd, selectedInstance.transform.parent.up); selectedInstance.transform.rotation = rotation; ApplySettings(); } } if (GUILayout.Button(new GUIContent("P-U", "alling UP to Position-Up"), GUILayout.Height(21), GUILayout.Width(50))) { Vector3 newfwd = Vector3.ProjectOnPlane(selectedInstance.transform.forward, upVector).normalized; Quaternion rotation = new Quaternion(); rotation.SetLookRotation(newfwd, upVector); selectedInstance.transform.rotation = rotation; ApplySettings(); } GUILayout.EndHorizontal(); // // Orientation adjustment // GUILayout.BeginHorizontal(); { GUILayout.Label("Pitch:"); GUILayout.FlexibleSpace(); fTempWidth = 80f; oriXStr = (GUILayout.TextField(oriXStr, 8, GUILayout.Width(fTempWidth))); if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21))) { SetRotation(Vector3.right, increment); } if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21))) { SetRotation(Vector3.left, increment); } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label("Roll:"); GUILayout.FlexibleSpace(); oriZStr = (GUILayout.TextField(oriZStr, 8, GUILayout.Width(fTempWidth))); if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21))) { SetRotation(Vector3.forward, increment); } if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21))) { SetRotation(Vector3.back, increment); } } GUILayout.EndHorizontal(); // // Rotation // GUILayout.BeginHorizontal(); { GUILayout.Label("Yaw:"); GUILayout.FlexibleSpace(); // rotStr = GUILayout.TextField(rotStr, 9, GUILayout.Width(fTempWidth)); // GUILayout.Box(Vector3.Angle(Vector3.ProjectOnPlane(selectedInstance.gameObject.transform.forward, selectedInstance.gameObject.transform.up), selectedInstance.gameObject.transform.parent.forward).ToString(), GUILayout.Width(fTempWidth)); //GUILayout.Box(GetHeading(), GUILayout.Width(fTempWidth)); oriYStr = (GUILayout.TextField(oriYStr, 8, GUILayout.Width(fTempWidth))); if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(23))) { SetRotation(Vector3.up, -increment); } if (GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(23))) { SetRotation(Vector3.up, -increment); } if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(23))) { SetRotation(Vector3.up, increment); } if (GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(23))) { SetRotation(Vector3.up, increment); } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label("Heading: ", GUILayout.Height(23)); GUILayout.Space(5); GUILayout.Button(instanceHeading.ToString(), UIMain.DeadButton, GUILayout.Height(23)); GUILayout.FlexibleSpace(); } GUILayout.EndHorizontal(); GUILayout.Space(1); GUILayout.Box(tHorizontalSep, UIMain.BoxNoBorder, GUILayout.Height(4)); GUILayout.Space(2); // // Scale // GUILayout.BeginHorizontal(); { GUILayout.Label("Model Scale: "); GUILayout.FlexibleSpace(); selectedInstance.ModelScale = Math.Max(0.01f, float.Parse(GUILayout.TextField(selectedInstance.ModelScale.ToString(), 4, GUILayout.Width(fTempWidth)))); if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(23))) { selectedInstance.ModelScale = Math.Max(0.01f, selectedInstance.ModelScale - increment); ApplySettings(); } if (GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(23))) { selectedInstance.ModelScale = Math.Max(0.01f, selectedInstance.ModelScale - increment); ApplySettings(); } if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(23))) { selectedInstance.ModelScale += increment; ApplySettings(); } if (GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(23))) { selectedInstance.ModelScale += increment; ApplySettings(); } } GUILayout.EndHorizontal(); GUILayout.Space(5); GUI.enabled = true; if (GUILayout.Button("Facility Type: " + selectedInstance.facilityType.ToString(), GUILayout.Height(23))) { if (!FacilityEditor.instance.IsOpen()) { FacilityEditor.instance.Open(); } } GUILayout.BeginHorizontal(); { GUILayout.Label("GrasColor: ", GUILayout.Height(23)); GUILayout.FlexibleSpace(); GUI.enabled = ((grasColorEnabled || grassColor2Enabled) && (!UI2.GrassEditor.isOpen || GrassColorUI.instance.IsOpen())); if (GUILayout.Button("Preset", GUILayout.Width(90), GUILayout.Height(23))) { if (grasColorEnabled) { GrassColorPresetUI.callBack = GrassColorUI.instance.UpdateCallBack; GrassColorUI.selectedInstance = selectedInstance; GrassColorUI.instance.SetupFields(); GrassColorPresetUI.instance.Open(); } if (grassColor2Enabled) { GrassColorPresetUI2.callBack = grassMod2.UpdateCallBack; GrassColorPresetUI2.instance.Open(); } } if (GUILayout.Button("Edit", GUILayout.Width(90), GUILayout.Height(23))) { if (grasColorEnabled) { GrassColorUI.instance.Open(); } if (grassColor2Enabled) { UI2.GrassEditor.Open(); } } GUI.enabled = true; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label("Set Group: ", GUILayout.Height(23)); GUILayout.FlexibleSpace(); if (GUILayout.Button(selectedInstance.Group, GUILayout.Width(185), GUILayout.Height(23))) { GroupSelectorUI.instance.Close(); GroupSelectorUI.showOnlyLocal = true; GroupSelectorUI.titleText = "Select a new Group"; GroupSelectorUI.callBack = SetGroup; GroupSelectorUI.instance.Open(); } } GUILayout.EndHorizontal(); GUILayout.Space(3); GUILayout.BeginHorizontal(); { enableColliders = GUILayout.Toggle(enableColliders, "Enable Colliders", GUILayout.Width(140), GUILayout.Height(23)); if (enableColliders != enableColliders2) { selectedInstance.ToggleAllColliders(enableColliders); enableColliders2 = enableColliders; } GUILayout.FlexibleSpace(); if (GUILayout.Button("Duplicate", GUILayout.Width(130), GUILayout.Height(23))) { selectedInstance.SaveConfig(); KerbalKonstructs.DeselectObject(true, true); SpawnInstance(selectedInstance.model, selectedInstance.groupCenter, selectedInstance.position, selectedInstance.Orientation); MiscUtils.HUDMessage("Spawned duplicate " + selectedInstance.model.title, 10, 2); } } GUILayout.EndHorizontal(); GUILayout.Space(5); GUILayout.BeginHorizontal(); { bool isScanable2 = GUILayout.Toggle(selectedInstance.isScanable, "Static will show up on anomaly scanners", GUILayout.Width(250), GUILayout.Height(23)); if (isScanable2 != selectedInstance.isScanable) { selectedInstance.isScanable = isScanable2; ApplySettings(); } } GUILayout.EndHorizontal(); GUILayout.Space(6); GUI.enabled = true; GUI.enabled = !LaunchSiteEditor.instance.IsOpen(); // Make a new LaunchSite here: if (!selectedInstance.hasLauchSites && string.IsNullOrEmpty(selectedInstance.model.DefaultLaunchPadTransform)) { GUI.enabled = false; } if (GUILayout.Button((selectedInstance.hasLauchSites ? "Edit" : "Make") + " Launchsite", GUILayout.Height(23))) { LaunchSiteEditor.instance.Open(); } GUILayout.FlexibleSpace(); GUI.enabled = true; GUILayout.BeginHorizontal(); { if (GUILayout.Button("Save", GUILayout.Width(110), GUILayout.Height(23))) { selectedInstance.SaveConfig(); MiscUtils.HUDMessage("Saved changes to this object.", 10, 2); } GUILayout.FlexibleSpace(); if (GUILayout.Button("Save&Close", GUILayout.Width(110), GUILayout.Height(23))) { selectedInstance.SaveConfig(); MiscUtils.HUDMessage("Saved changes to this object.", 10, 2); KerbalKonstructs.DeselectObject(true, true); } } GUILayout.EndHorizontal(); GUILayout.Space(10); GUILayout.BeginHorizontal(); { if (GUILayout.Button("Revert changes", GUILayout.Height(21))) { if (selectedInstance.groupCenter != origCenter) { StaticDatabase.ChangeGroup(selectedInstance, origCenter); } selectedInstance.RelativePosition = origPosition; selectedInstance.transform.localPosition = origPosition; selectedInstance.transform.localEulerAngles = origRotation; selectedInstance.Orientation = origRotation; selectedInstance.ModelScale = origScale; ApplySettings(); } if (GUILayout.Button("Delete Instance", GUILayout.Height(21))) { DeleteInstance(); } } GUILayout.EndHorizontal(); GUILayout.Space(5); GUILayout.Space(1); GUILayout.Box(tHorizontalSep, UIMain.BoxNoBorder, GUILayout.Height(4)); GUILayout.Space(2); if (GUI.tooltip != "") { var labelSize = GUI.skin.GetStyle("Label").CalcSize(new GUIContent(GUI.tooltip)); GUI.Box(new Rect(Event.current.mousePosition.x - (25 + (labelSize.x / 2)), Event.current.mousePosition.y - 40, labelSize.x + 10, labelSize.y + 5), GUI.tooltip); } GUI.DragWindow(new Rect(0, 0, 10000, 10000)); }
/// <summary> /// instances /// </summary> internal void ShowInstancesScroll() { UpdateInstances(); for (int ix = 0; ix < allStaticInstances.Length; ix++) //foreach (StaticObject obj in allStaticInstances) { bool isLocal = true; if (allStaticInstances[ix].CelestialBody == FlightGlobals.currentMainBody) { var dist = Vector3.Distance(FlightGlobals.ActiveVessel.GetTransform().position, allStaticInstances[ix].position); isLocal = (dist < KerbalKonstructs.localGroupRange); } else { isLocal = false; } if (isLocal) { GUILayout.BeginHorizontal(); GUILayout.Button("" + allStaticInstances[ix].Group, UIMain.DeadButton3, GUILayout.Width(120), GUILayout.Height(23)); if (allStaticInstances[ix].hasLauchSites) { LaunchSiteSelectorGUI.ShowCategory(allStaticInstances[ix].launchSite); } else { GUILayout.Button("", UIMain.DeadButton3, GUILayout.Width(23), GUILayout.Height(23)); } //GUI.enabled = (obj != selectedObject); if (GUILayout.Button(new GUIContent("" + allStaticInstances[ix].model.title + " ( " + allStaticInstances[ix].indexInGroup.ToString() + " )", "Edit this instance."), GUILayout.Height(23))) { enableColliders = true; EditorGUI.CloseEditors(); if (!EditorGUI.instance.IsOpen()) { EditorGUI.instance.Open(); } if (selectedObject != null) { selectedObjectPrevious = selectedObject; allStaticInstances[ix].HighlightObject(Color.clear); } if (snapTargetInstance == allStaticInstances[ix]) { snapTargetInstance = null; } KerbalKonstructs.SelectInstance(allStaticInstances[ix], false); //obj.selectObject(false); allStaticInstances[ix].HighlightObject(XKCDColors.Green_Yellow); } //GUI.enabled = true; GUI.enabled = (snapTargetInstance != allStaticInstances[ix] && allStaticInstances[ix] != selectedObject); if (GUILayout.Button(new GUIContent(tFocus, "Set as snap target."), GUILayout.Height(23), GUILayout.Width(23))) { if (snapTargetInstance != null) { snapTargetInstancePrevious = snapTargetInstance; Color highlightColor3 = new Color(0, 0, 0, 0); snapTargetInstance.HighlightObject(highlightColor3); } snapTargetInstance = allStaticInstances[ix]; Color highlightColor4 = XKCDColors.RedPink; allStaticInstances[ix].HighlightObject(highlightColor4); } GUI.enabled = true; GUILayout.EndHorizontal(); GUILayout.Space(2); } } }
private void DrawBaseManagerWindow(int windowID) { if (!isInitialized) { InitializeLayout(); } GUILayout.BeginHorizontal(); { GUI.enabled = false; GUILayout.Button("-KK-", DeadButton, GUILayout.Height(16)); GUILayout.FlexibleSpace(); GUILayout.Button("Inflight Base Boss", DeadButton, GUILayout.Height(16)); GUILayout.FlexibleSpace(); GUI.enabled = true; if (GUILayout.Button("X", DeadButtonRed, GUILayout.Height(16))) { bShowFacilities = false; this.Close(); return; } } GUILayout.EndHorizontal(); GUILayout.Space(1); GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4)); GUILayout.Space(5); GUILayout.Box("Flight Tools", BoxNoBorder); GUILayout.BeginHorizontal(); { GUILayout.Space(2); GUILayout.Label("Landing Guide ", LabelInfo); if (GUILayout.Button(LandingGuideUI.instance.IsOpen() ? tIconOpen : tIconClosed, GUILayout.Height(18), GUILayout.Width(56))) { KerbalKonstructs.instance.UpdateCache(); LandingGuideUI.instance.Toggle(); } GUILayout.FlexibleSpace(); GUILayout.Label("NGS ", LabelInfo); if (NavGuidanceSystem.instance.IsOpen()) { tToggle2 = tIconOpen; } else { tToggle2 = tIconClosed; } if (GUILayout.Button(tToggle2, GUILayout.Height(18), GUILayout.Width(18))) { NavGuidanceSystem.instance.Toggle(); } GUILayout.Space(2); } GUILayout.EndHorizontal(); GUILayout.Space(2); GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4)); GUILayout.Space(2); GUILayout.Box("Selected Base", BoxNoBorder); GUILayout.Space(2); GUILayout.BeginHorizontal(); { string sNearestbase = ""; LaunchSiteManager.getNearestBase(FlightGlobals.ActiveVessel.GetTransform().position, out Base, out Base2, out Range, out lBase, out lBase2); if (FlightGlobals.ActiveVessel.altitude > 75000) { GUILayout.Label("No base's beacon in range at this altitude.", LabelInfo); } else if (Base == "") { GUILayout.Label("No nearest base found.", LabelInfo); } else { if (Range < 10000) { sNearestbase = Base + " at " + Range.ToString("#0.0") + " m"; } else { sNearestbase = Base + " at " + (Range / 1000).ToString("#0.0") + " km"; } GUILayout.Space(5); GUILayout.Label("Nearest Base: ", LabelInfo); GUILayout.Label(sNearestbase, LabelInfo, GUILayout.Width(150)); if (NavGuidanceSystem.instance.IsOpen()) { GUILayout.FlexibleSpace(); if (GUILayout.Button("NGS", GUILayout.Height(21))) { NavGuidanceSystem.setTargetSite(lBase); smessage = "NGS set to " + Base; MiscUtils.HUDMessage(smessage, 10, 2); } } } } GUILayout.EndHorizontal(); GUILayout.Space(2); GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4)); GUILayout.Space(2); GUILayout.Box("Base Status", BoxNoBorder); if (MiscUtils.isCareerGame()) { if (Range < 5000) { LaunchSiteManager.getSiteOpenCloseState(Base, out sClosed, out fOpenCost); fOpenCost /= 2f; if (FlightGlobals.ActiveVessel.Landed && sClosed == "Closed") { GUILayout.Space(2); GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4)); GUILayout.Space(2); if (GUILayout.Button("Open Base for " + fOpenCost + " funds", GUILayout.Height(23))) { double currentfunds = Funding.Instance.Funds; if (fOpenCost > currentfunds) { MiscUtils.HUDMessage("Insufficient funds to open this site!", 10, 0); } else { LaunchSiteManager.OpenLaunchSite(LaunchSiteManager.GetLaunchSiteByName(Base)); if (MiscUtils.isCareerGame()) { Funding.Instance.AddFunds(-LaunchSiteManager.GetLaunchSiteByName(Base).OpenCost, TransactionReasons.Cheating); } smessage = Base + " opened"; MiscUtils.HUDMessage(smessage, 10, 2); } } } if (FlightGlobals.ActiveVessel.Landed && sClosed == "Open") { GUI.enabled = false; GUILayout.Button("Base is Open", GUILayout.Height(23)); GUI.enabled = true; } if (FlightGlobals.ActiveVessel.Landed && (sClosed == "OpenLocked" || sClosed == "ClosedLocked")) { GUI.enabled = false; GUILayout.Button("Base cannot be opened or closed", GUILayout.Height(23)); GUI.enabled = true; } GUILayout.Space(2); GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4)); GUILayout.Space(2); } else { GUILayout.Label("Bases can only be opened or closed at the base when within 5km of the base.", LabelInfo); } //if (Range > 100000) //{ // if (bLanded) // { // GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4)); // GUILayout.Space(2); // GUILayout.Label("This feature is WIP.", LabelInfo); // GUI.enabled = false; // if (GUILayout.Button("Found a New Base", GUILayout.Height(23))) // { // foundingBase = true; // } // GUI.enabled = true; // GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4)); // GUILayout.Space(2); // } //} //else //{ // GUILayout.Label("This feature is WIP.", LabelInfo); //} } GUILayout.Space(2); GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4)); GUILayout.Space(2); GUILayout.Box("Operational Facilities", BoxNoBorder); if (FlightGlobals.ActiveVessel.Landed) { if (GUILayout.Button("Show/Hide", GUILayout.Height(23))) { if (bShowFacilities) { bShowFacilities = false; } else { CacheFacilities(); bShowFacilities = true; } } if (bShowFacilities && allFacilities.Count == 0) { GUILayout.Label("No facilities within 5000m", LabelInfo); } if (bShowFacilities && allFacilities.Count > 0) { scrollPos = GUILayout.BeginScrollView(scrollPos); { for (int i = 0; i < allFacilities.Count; i++) { GUILayout.BeginHorizontal(); { bIsOpen = allFacilities[i].myFacilities[0].isOpen; if (!bIsOpen) { iFundsOpen2 = allFacilities[i].myFacilities[0].OpenCost; if (iFundsOpen2 == 0) { bIsOpen = true; } } if (GUILayout.Button(allFacilities[i].model.title, GUILayout.Height(23))) { selectedObject = allFacilities[i]; KerbalKonstructs.SelectInstance(allFacilities[i], false); FacilityManager.selectedInstance = allFacilities[i]; FacilityManager.instance.Open(); } if (bIsOpen) { GUILayout.Label(tIconOpen, GUILayout.Height(23), GUILayout.Width(23)); } if (!bIsOpen) { GUILayout.Label(tIconClosed, GUILayout.Height(23), GUILayout.Width(23)); } } GUILayout.EndHorizontal(); } } GUILayout.EndScrollView(); } else { GUILayout.Label("Click the button above to display a list of nearby operational facilities.", LabelInfo); } } else { GUILayout.Label("Nearby facilities can only be shown when landed.", LabelInfo); bShowFacilities = false; } GUILayout.FlexibleSpace(); GUILayout.Space(2); GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4)); GUILayout.Space(2); GUILayout.Box("Other Features", BoxNoBorder); if (GUILayout.Button("Start Air Racing!", GUILayout.Height(23))) { AirRacing.instance.Open(); AirRacing.runningRace = true; NavGuidanceSystem.instance.Close(); FacilityManager.instance.Close(); } if (GUILayout.Button("Basic Orbital Data", GUILayout.Height(23))) { AirRacing.instance.Open(); AirRacing.runningRace = false; AirRacing.basicorbitalhud = true; NavGuidanceSystem.instance.Close(); FacilityManager.instance.Close(); } GUILayout.Space(5); GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4)); GUILayout.Space(2); GUI.DragWindow(new Rect(0, 0, 10000, 10000)); }