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; }
internal void DeleteGroupCenter() { if (selectedObjectPrevious == selectedGroup) { selectedObjectPrevious = null; } InputLockManager.RemoveControlLock("KKShipLock"); InputLockManager.RemoveControlLock("KKEVALock"); InputLockManager.RemoveControlLock("KKCamModes"); if (KerbalKonstructs.camControl.active) { KerbalKonstructs.camControl.disable(); } if (selectedGroup == StaticsEditorGUI.GetActiveGroup()) { StaticsEditorGUI.SetActiveGroup(null); } selectedGroup.DeleteGroupCenter(); selectedGroup = null; StaticsEditorGUI.ResetLocalGroupList(); this.Close(); }
internal static GroupCenter GetCloesedCenter(Vector3 myPosition) { if (localGroups.Length == 0) { return(null); } if (activeGroup != null) { return(activeGroup); } GroupCenter closest = localGroups[0]; float dist = Vector3.Distance(myPosition, closest.gameObject.transform.position); foreach (GroupCenter center in localGroups) { if (Vector3.Distance(myPosition, center.gameObject.transform.position) < dist) { dist = Vector3.Distance(myPosition, center.gameObject.transform.position); closest = center; } } return(closest); }
private void GroupSelectorWindow(int WindowID) { GUI.enabled = true; GUILayout.BeginHorizontal(); { GUI.enabled = false; GUILayout.Button("-KK-", UIMain.DeadButton, GUILayout.Height(21)); GUILayout.FlexibleSpace(); GUILayout.Button(titleText, UIMain.DeadButton, GUILayout.Height(21)); GUILayout.FlexibleSpace(); GUI.enabled = true; if (GUILayout.Button("X", UIMain.DeadButtonRed, GUILayout.Height(21))) { //KerbalKonstructs.instance.saveObjects(); this.Close(); } } GUILayout.EndHorizontal(); GUILayout.Space(1); GUILayout.Box(UIMain.tHorizontalSep.texture, UIMain.BoxNoBorder, GUILayout.Height(4)); scrollPointer = GUILayout.BeginScrollView(scrollPointer); { foreach (GroupCenter center in centers2Display) { GUI.enabled = (selectedCenter != center); if (GUILayout.Button(center.CelestialBody.name + ":" + center.Group, GUILayout.Height(23))) { selectedCenter = center; } } GUI.enabled = true; } GUILayout.EndScrollView(); GUI.enabled = true; GUILayout.BeginHorizontal(); { if (GUILayout.Button("OK", GUILayout.Height(23))) { callBack.Invoke(selectedCenter); this.Close(); } if (GUILayout.Button("Cancel", GUILayout.Height(23))) { this.Close(); } } GUILayout.EndHorizontal(); GUI.DragWindow(new Rect(0, 0, 10000, 10000)); }
void SpawnGroup() { EditorGUI.instance.Close(); MapDecalEditor.Instance.Close(); EditorGUI.selectedInstance = null; GroupCenter groupCenter = new GroupCenter { RadialPosition = FlightGlobals.currentMainBody.transform.InverseTransformPoint(FlightGlobals.ActiveVessel.transform.position), Group = "NewGroup", CelestialBody = FlightGlobals.currentMainBody }; groupCenter.Spawn(); GroupEditor.selectedGroup = groupCenter; if (GroupEditor.selectedGroup == null) { Log.UserError("No Group created"); } else { Log.Normal("Group Editor spawned"); localGroups.Add(new GroupItem(groupCenter)); UIKit.UpdateListContent(localGroups); GroupEditor.instance.Open(); } }
/// <summary> /// Wrapper to draw editors /// </summary> /// <param name="instance"></param> public void drawEditor(StaticInstance instance) { if (instance == null) { return; } if (selectedInstance != instance) { selectedInstance = instance; SetupFields(); SetupVectors(); SetupGizmo(); grassMod = selectedInstance.mesh.GetComponent <GrasColor>(); grassMod2 = selectedInstance.mesh.GetComponent <GrassColor2>(); grasColorEnabled = (grassMod != null); grassColor2Enabled = (grassMod2 != null); origCenter = selectedInstance.groupCenter; origPosition = selectedInstance.transform.localPosition; origRotation = selectedInstance.transform.localEulerAngles; origScale = selectedInstance.ModelScale; } toolRect = GUI.Window(0x004B1E3, toolRect, InstanceEditorWindow, "", UIMain.KKWindow); }
/// <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.gameObject = UnityEngine.Object.Instantiate(model.prefab); instance.CelestialBody = FlightGlobals.currentMainBody; instance.groupCenter = groupCenter; instance.Group = groupCenter.Group; instance.gameObject.transform.position = position; instance.gameObject.transform.parent = groupCenter.gameObject.transform; instance.RelativePosition = instance.gameObject.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.SpawnObject(true); }
public override void Close() { callBack = delegate { }; selectedCenter = null; titleText = "unset"; base.Close(); }
//void SetLocalsGroup(string sGroup, float fRange) //{ // if (sGroup == "") // return; // foreach (StaticInstance obj in StaticDatabase.GetAllStatics()) // { // if (obj.CelestialBody == FlightGlobals.currentMainBody) // { // var dist = Vector3.Distance(FlightGlobals.ActiveVessel.GetTransform().position, obj.gameObject.transform.position); // if (dist < fRange) // { // StaticDatabase.ChangeGroup(obj, sGroup); // } // } // } //} /// <summary> /// wrapper for editorGUI spawnInstance /// </summary> /// <param name="model"></param> internal void SpawnInstance(StaticModel model) { GroupCenter center = GetCloesedCenter(FlightGlobals.ActiveVessel.transform.position); EditorGUI.instance.SpawnInstance(model, center, FlightGlobals.ActiveVessel.transform.position, Vector3.zero); if (!EditorGUI.instance.IsOpen()) { EditorGUI.instance.Open(); } }
void OnSelect(GroupItem item) { activeGroup = item.group; EditorGUI.CloseEditors(); MapDecalEditor.Instance.Close(); GroupEditor.instance.Close(); GroupEditor.selectedGroup = item.group; // MapDecalEditor.selectedDecal = mapDecalInstance; GroupEditor.instance.Open(); }
public void Close() { SetActive(false); if (KerbalKonstructs.camControl.active) { KerbalKonstructs.camControl.disable(); } EditorGizmo.CloseGizmo(); CloseEditors(); selectedObjectPrevious = null; }
public override void Close() { if (KerbalKonstructs.camControl.active) { KerbalKonstructs.camControl.disable(); } CloseVectors(); EditorGizmo.CloseGizmo(); CloseEditors(); selectedObjectPrevious = null; base.Close(); }
public void Open() { UpdateUI(); if (selectedObjectPrevious != selectedGroup) { selectedObjectPrevious = selectedGroup; EditorGizmo.SetupMoveGizmo(selectedGroup.gameObject, Quaternion.identity, OnMoveCallBack, WhenMovedCallBack); if (!KerbalKonstructs.camControl.active) { KerbalKonstructs.camControl.enable(selectedGroup.gameObject); } } SetActive(true); }
/// <summary> /// Wrapper to draw editors /// </summary> /// <param name="groupCenter"></param> internal void drawEditor(GroupCenter groupCenter) { if (groupCenter == null) { return; } if (selectedObjectPrevious != groupCenter) { selectedObjectPrevious = groupCenter; SetupVectors(); if (!KerbalKonstructs.camControl.active) { KerbalKonstructs.camControl.enable(groupCenter.gameObject); } } toolRect = GUI.Window(0xB00B1E3, toolRect, GroupEditorWindow, "", UIMain.KKWindow); }
internal static void AddPQSCenter(string tgtName) { CelestialBody body = ConfigUtil.GetCelestialBody("HomeWorld"); var mods = body.pqsController.GetComponentsInChildren <PQSCity>(true); PQSCity tgtPQS = null; foreach (var m in mods) { //Log.Normal("PQSName: " + m.name); if (m.name == tgtName) { tgtPQS = m; continue; } } if (tgtPQS == null) { Log.Normal("No BasePQS found: " + tgtName); return; } GroupCenter newGroup = new GroupCenter(); newGroup.isBuiltIn = true; newGroup.Group = tgtName + "_Builtin"; newGroup.CelestialBody = body; newGroup.RotationAngle = tgtPQS.reorientFinalAngle; newGroup.RadialPosition = tgtPQS.repositionRadial; //newGroup.RadiusOffset = (float)0; newGroup.RadiusOffset = (float)tgtPQS.repositionRadiusOffset; //newGroup.repositionToSphere = false; newGroup.SeaLevelAsReference = tgtPQS.repositionToSphere; newGroup.Spawn(); //newGroup.Update(); //Log.Normal("Added GroupCenter:" + newGroup.Group); }
/// <summary> /// Wrapper to draw editors /// </summary> /// <param name="groupCenter"></param> internal void drawEditor(GroupCenter groupCenter) { if (groupCenter == null) { return; } if (selectedObjectPrevious != groupCenter) { selectedObjectPrevious = groupCenter; SetupVectors(); UpdateStrings(); EditorGizmo.SetupMoveGizmo(groupCenter.gameObject, Quaternion.identity, OnMoveCallBack, WhenMovedCallBack); if (!KerbalKonstructs.camControl.active) { KerbalKonstructs.camControl.enable(groupCenter.gameObject); } } toolRect = GUI.Window(0xB07B1E3, toolRect, GroupEditorWindow, "", UIMain.KKWindow); }
/// <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); } }
internal GroupCenter GetCloesedCenter(Vector3 position) { if (activeGroup != null) { return(activeGroup); } float bestDist = float.PositiveInfinity; GroupCenter closest = null; for (int i = localGroups.Count; i-- > 0;) { var gc = localGroups[i].group; float dist = (position - gc.gameObject.transform.position).sqrMagnitude; if (dist < bestDist) { bestDist = dist; closest = gc; } } return(closest); }
internal static void AddPQSCenter2(string tgtName) { CelestialBody body = ConfigUtil.GetCelestialBody("HomeWorld"); var mods = body.pqsController.GetComponentsInChildren <PQSCity2>(true); PQSCity2 tgtPQS = null; foreach (var m in mods) { //Log.Normal("PQS2Name: " + m.name); if (m.name == tgtName) { tgtPQS = m; continue; } } if (tgtPQS == null) { Log.Normal("No BasePQS found: " + tgtName); return; } GroupCenter newGroup = new GroupCenter(); newGroup.isBuiltIn = true; newGroup.Group = tgtName + "_Builtin"; newGroup.CelestialBody = body; newGroup.RotationAngle = (float)tgtPQS.rotation; newGroup.RadialPosition = KKMath.GetRadiadFromLatLng(body, tgtPQS.lat, tgtPQS.lon); //newGroup.RadiusOffset = (float)0; newGroup.RadiusOffset = (float)tgtPQS.alt; newGroup.SeaLevelAsReference = true; //newGroup.repositionToSphere = tgtPQS.repositionToSphere; newGroup.Spawn(); }
/// <summary> /// CallBack Functions for Group Selection /// </summary> /// <param name="newGroup"></param> internal void SetGroup(GroupCenter newGroup) { Log.Normal("setting Group from " + selectedInstance.groupCenter.Group + " to " + newGroup.Group); StaticDatabase.ChangeGroup(selectedInstance, newGroup); ApplySettings(); }
public GroupItem(GroupCenter group) { this.group = group; }
internal static void SetActiveGroup(GroupCenter group) { activeGroup = group; }
/// <summary> /// Footer for Groups /// </summary> internal void ShowGroupFooter() { GUILayout.BeginHorizontal(); { //GUILayout.Label("Filter by Group:", GUILayout.Width(140)); //GUILayout.FlexibleSpace(); //groupfilter = GUILayout.TextField(groupfilter, 40, GUILayout.Width(140)); if (GUILayout.Button("Spawn new Group", GUILayout.Width(170))) { EditorGUI.instance.Close(); MapDecalEditor.Instance.Close(); EditorGUI.selectedInstance = null; GroupCenter groupCenter = new GroupCenter { RadialPosition = FlightGlobals.currentMainBody.transform.InverseTransformPoint(FlightGlobals.ActiveVessel.transform.position), Group = "NewGroup", CelestialBody = FlightGlobals.currentMainBody }; groupCenter.Spawn(); GroupEditor.selectedGroup = groupCenter; if (GroupEditor.selectedGroup == null) { Log.UserError("No Group created"); } else { GroupEditor.instance.Open(); Log.Normal("Group Editor spawned"); } ResetLocalGroupList(); } GUILayout.FlexibleSpace(); GUILayout.Button("active Group:" + ((activeGroup != null) ? activeGroup.Group : " not set") + " ", UIMain.DeadButton3, GUILayout.Width(150), GUILayout.Height(23)); if (GUILayout.Button("Set Active Group", GUILayout.Width(170))) { GroupSelectorUI.instance.Close(); GroupSelectorUI.showOnlyLocal = true; GroupSelectorUI.callBack = SetActiveGroup; GroupSelectorUI.titleText = "Select active Group"; GroupSelectorUI.instance.Open(); } GUI.enabled = ((activeGroup != null) && Vector3.Distance(activeGroup.gameObject.transform.position, FlightGlobals.ActiveVessel.transform.position) < KerbalKonstructs.localGroupRange); if (GUILayout.Button("clone group to active", GUILayout.Width(170))) { GroupSelectorUI.instance.Close(); GroupSelectorUI.showOnlyLocal = false; GroupSelectorUI.titleText = "Select Group to Clone"; GroupSelectorUI.callBack = activeGroup.CopyGroup; GroupSelectorUI.instance.Open(); } GUI.enabled = true; } GUILayout.EndHorizontal(); }
void UpdateUI() { landingGuide.SetIsOnWithoutNotify(LandingGuideUI.instance.IsOpen()); navGuidance.SetIsOnWithoutNotify(NavGuidanceSystem.instance.IsOpen()); var Range = float.PositiveInfinity; //FIXME atmo scaling? other worlds? ... if (FlightGlobals.ActiveVessel.altitude > 75000) { center = null; noBasesBeacon.SetActive(true); noNearestBase.SetActive(false); nearestBaseGroup.SetActive(false); } else { center = StaticDatabase.GetClosestLaunchCenter();; if (center == null) { noBasesBeacon.SetActive(false); noNearestBase.SetActive(true); nearestBaseGroup.SetActive(false); } else { noBasesBeacon.SetActive(false); noNearestBase.SetActive(false); nearestBaseGroup.SetActive(true); Vector3 vPosition = FlightGlobals.ActiveVessel.GetTransform().position; ngsSite = LaunchSiteManager.getNearestBase(center, vPosition); Range = Vector3.Distance(center.gameObject.transform.position, vPosition); string info; if (Range < 10000) { info = center.Group + " at " + Range.ToString("#0.0") + " m"; } else { info = center.Group + " at " + (Range / 1000).ToString("#0.0") + " km"; } nearestBase.Info(info); bool ngs = NavGuidanceSystem.instance.IsOpen(); ngsFiller.SetActive(!ngs); setNGSTarget.SetActive(ngs); } } if (!MiscUtils.isCareerGame()) { careerGroup.SetActive(false); } else { careerGroup.SetActive(true); if (!FlightGlobals.ActiveVessel.Landed || Range > 5000) { //FIXME a bouncy landing will be laggy if (launchsiteItems.Count > 0) { launchsiteItems.Clear(); UIKit.UpdateListContent(launchsiteItems); } basesCanBeOpened.SetActive(true); openSite.SetActive(false); siteIsOpen.SetActive(false); siteCannoteBeOpened.SetActive(false); } else { basesCanBeOpened.SetActive(false); if (launchsiteItems.Count != center.launchsites.Count) { BuildLaunchsites(); } UpdateLaunchsite(); } //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); //} } UpdateFaclilitiesGroup(); }