public void Start() { windowStyle = new GUIStyle(HighLogic.Skin.window); windowStyle.stretchHeight = true; windowStyle.stretchWidth = true; windowPosition = KSPScienceSettings.getRectSetting("MonitorRect"); }
public static void Hide() { drawWindow = false; KSPScienceSettings.Hide(); if (HighLogic.LoadedScene == GameScenes.EDITOR) { EditorLogic.fetch.Unlock("library"); } }
private void OnDraw() { if (toolbarButton != null) { toolbarButton.UpdateIcon(drawWindow); } if (drawWindow) { windowPosition = GUI.Window(1234, windowPosition, OnWindow, "Science Monitor", windowStyle); KSPScienceSettings.setRectSetting("MonitorRect", windowPosition); } }
public void Start() { windowStyle = new GUIStyle(HighLogic.Skin.window); windowStyle.stretchHeight = true; windowStyle.stretchWidth = true; drawWindow = false; selectedBody = "All"; selectedExperiments = dataOutputList; System.Version ver = Assembly.GetAssembly(typeof(KSPScienceLibrary)).GetName().Version; version = "Version " + ver.Major + "." + ver.Minor + " Build " + ver.Build + "." + ver.Revision; windowPosition = KSPScienceSettings.getRectSetting("LibraryRect"); }
private void OnDraw() { if (toolbarButton != null) { toolbarButton.UpdateIcon(drawWindow); } if (!lastdrawWindow && drawWindow) { GetSciData(); } if (drawWindow) { windowPosition = GUI.Window(2345, windowPosition, OnWindow, "Science Library " + version, windowStyle); KSPScienceSettings.setRectSetting("LibraryRect", windowPosition); } lastdrawWindow = drawWindow; }
public void GetSciData() { if (ResearchAndDevelopment.Instance == null) { return; } dataOutputList = new List <Experiment>(); List <ScienceSubject> newExperiments = new List <ScienceSubject>(); List <string> exIds = ResearchAndDevelopment.GetExperimentIDs(); List <ScienceSubject> subjectslist = ResearchAndDevelopment.GetSubjects(); //I am glad this code runs only once! Too expensive! foreach (string id in exIds) { foreach (ExperimentSituations experimentSituation in Enum.GetValues(typeof(ExperimentSituations))) { foreach (CelestialBody body in FlightGlobals.Bodies) { bool ocean = body.ocean; if (ExperimentSituations.SrfSplashed == experimentSituation && !ocean) { continue; } if ((ExperimentSituations.FlyingHigh == experimentSituation || ExperimentSituations.FlyingLow == experimentSituation) && !body.atmosphere) { continue; } ScienceExperiment experiment = ResearchAndDevelopment.GetExperiment(id); bool available = experiment.IsAvailableWhile(experimentSituation, body); if (available) { bool shouldHaveBiome = experiment.BiomeIsRelevantWhile(experimentSituation); if (shouldHaveBiome) { foreach (string biome in ResearchAndDevelopment.GetBiomeTags(body)) { if (KSPScienceSettings.getBoolSetting("ShowOnlyKnownBiomes")) { bool foundBiome = subjectslist.Any(subject => subject.id.Contains("@" + body.name) && subject.id.Contains(biome.Replace(" ", ""))); if (!foundBiome) { continue; } } ScienceSubject ssj = new ScienceSubject(experiment, experimentSituation, body, biome); if (id == "asteroidSample") { ssj.scienceCap = experiment.scienceCap; } newExperiments.Add(ssj); } if (body.BiomeMap == null || body.BiomeMap.Attributes.Length == 0) { ScienceSubject ssj = new ScienceSubject(experiment, experimentSituation, body, ""); if (id == "asteroidSample") { ssj.scienceCap = experiment.scienceCap; } newExperiments.Add(ssj); } } else { ScienceSubject ssj = new ScienceSubject(experiment, experimentSituation, body, ""); if (id == "asteroidSample") { ssj.scienceCap = experiment.scienceCap; } newExperiments.Add(ssj); } } } } } foreach (ScienceSubject scienceSubject in subjectslist) { newExperiments.RemoveAll(subject => subject.id == scienceSubject.id); string title = scienceSubject.id; double earned = Math.Round(scienceSubject.science, 1); double remain = Math.Round(scienceSubject.scienceCap - scienceSubject.science, 1); string body = LibraryUtils.FindExperimentBody(scienceSubject.id.Split('@')[1]); string type = scienceSubject.id.Split('@')[0]; Experiment experiment = new Experiment(title, earned, remain, body, type); dataOutputList.Add(experiment); } foreach (ScienceSubject newExperiment in newExperiments) { newExperiment.scientificValue = 1f; CelestialBody thisBody = FlightGlobals.Bodies.Find(celestialBody => newExperiment.id.Split('@')[1].StartsWith(celestialBody.name)); Experiment ex = new Experiment(newExperiment.id, 0, Math.Round(newExperiment.scienceCap, 1), thisBody.name, newExperiment.id.Split('@')[0]); dataOutputList.Add(ex); } dataOutputList.Sort(SortByName); if (KSPScienceSettings.getBoolSetting("ShowOnlyKnownExperiments")) { allExperimentTypes = GetKnownExperimentTypes(); } else { allExperimentTypes = GetAllExperimentTypes(); } }
private void OnWindow(int windowID) { GUI.skin = KSPScienceSettings.getSkin(); GUILayout.BeginArea(new Rect(10, 10, windowPosition.width - 10, windowPosition.height - 10)); GUILayout.BeginHorizontal(); GUILayout.BeginVertical(GUILayout.MaxWidth(240)); GUILayout.Label("Experiment Filters"); scrollPlanet = GUILayout.BeginScrollView(scrollPlanet); int pressedCounter = 0; bool pressedlast = (pressedCounter == pressedFilterId); bool pressed; pressed = GUILayout.Toggle(pressedlast, "All Experiments", "Button"); if (pressed && !pressedlast) { pressedFilterId = pressedCounter; selectedBody = "All"; selectedExperiments = GetSelectedExperimentsByTypes(allExperimentTypes, dataOutputList); selectedExperiments2 = selectedExperiments; pressedPlanet = -1; } foreach (string experimentType in allExperimentTypes) { pressedCounter++; pressedlast = (pressedCounter == pressedFilterId); pressed = GUILayout.Toggle(pressedlast, experimentType, "Button"); if (pressed && !pressedlast) { pressedFilterId = pressedCounter; selectedBody = experimentType; selectedExperiments = GetSelectedExperimentsByType(experimentType); selectedExperiments2 = selectedExperiments; pressedPlanet = -1; } } CelestialBody sun = FlightGlobals.Bodies[0]; CelestialBody[] bodies = FlightGlobals.Bodies.ToArray(); Array.Sort(bodies, delegate(CelestialBody body1, CelestialBody body2) { if (body2.referenceBody == body1 && body1 != sun) { return(-1); } if (body1.referenceBody == body2 && body2 != sun) { return(1); } if (body1.referenceBody == body2.referenceBody && body2.referenceBody != sun) { return(0); } return((sun.transform.position - body1.transform.position).magnitude.CompareTo((sun.transform.position - body2.transform.position).magnitude)); }); pressedCounter = 0; GUILayout.Space(20); foreach (CelestialBody body in bodies) { bool pressedlastPlanet = (pressedCounter == pressedPlanet); bool pressedP; if (body.referenceBody != sun) { GUILayout.BeginHorizontal(); GUILayout.Space(60); } pressedP = GUILayout.Toggle(pressedlastPlanet, body.name, "Button"); if (pressedP && !pressedlastPlanet) { selectedBody = body.name; selectedExperiments2 = GetSelectedExperiments(selectedBody, selectedExperiments); pressedPlanet = pressedCounter; } if (body.referenceBody != sun) { GUILayout.EndHorizontal(); } pressedCounter++; } GUILayout.EndScrollView(); GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Label(selectedBody + " Experiments List"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (GUILayout.Button("Sort by Name")) { if (lastsorted == 1) { selectedExperiments2.Sort(SortByNameD); lastsorted = 5; } else { selectedExperiments2.Sort(SortByName); lastsorted = 1; } } if (GUILayout.Button("Sort by Earned")) { if (lastsorted == 2) { selectedExperiments2.Sort(SortByEarnedD); lastsorted = 6; } else { selectedExperiments2.Sort(SortByEarned); lastsorted = 2; } } if (GUILayout.Button("Sort by Remaining")) { if (lastsorted == 3) { selectedExperiments2.Sort(SortByRemainD); lastsorted = 7; } else { selectedExperiments2.Sort(SortByRemain); lastsorted = 3; } } if (GUILayout.Button("Sort by Type")) { if (lastsorted == 4) { selectedExperiments2.Sort(SortByTypeD); lastsorted = 8; } else { selectedExperiments2.Sort(SortByType); lastsorted = 4; } } GUILayout.EndHorizontal(); scrollPosition = GUILayout.BeginScrollView(scrollPosition); GUILayout.BeginHorizontal(); GUILayout.Space(20); GUILayout.BeginVertical(); GUILayout.Label("TYPE"); GUIStyle styleNew = KSPScienceSettings.getStyleSetting("LibraryNewExperiments"); GUIStyle styleDone = KSPScienceSettings.getStyleSetting("LibraryDoneExperiments"); foreach (Experiment experiment in selectedExperiments2) { if (experiment.earned == 0) { GUILayout.Label(experiment.FirstIdType, styleNew); } else { GUILayout.Label(experiment.FirstIdType, styleDone); } } GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.Label("EARNED"); foreach (Experiment experiment in selectedExperiments2) { if (experiment.earned == 0) { GUILayout.Label(experiment.earned.ToString(), styleNew); } else { GUILayout.Label(experiment.earned.ToString(), styleDone); } } GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.Label("REMAINING"); foreach (Experiment experiment in selectedExperiments2) { if (experiment.earned == 0) { GUILayout.Label(experiment.remain.ToString(), styleNew); } else { GUILayout.Label(experiment.remain.ToString(), styleDone); } } GUILayout.EndVertical(); GUILayout.Space(20); GUILayout.BeginVertical(); GUILayout.Label("Library"); foreach (Experiment experiment in selectedExperiments2) { if (experiment.earned == 0) { GUILayout.Label(experiment.fullName, styleNew); } else { GUILayout.Label(experiment.fullName, styleDone); } } GUILayout.EndVertical(); GUILayout.Space(20); GUILayout.EndHorizontal(); GUILayout.EndScrollView(); GUILayout.Space(20); GUILayout.EndVertical(); GUILayout.Space(20); GUILayout.EndHorizontal(); GUILayout.EndArea(); if (GUI.Button(new Rect(windowPosition.width - 42, 0, 21, 21), "S")) { KSPScienceSettings.Toggle(); } if (GUI.Button(new Rect(windowPosition.width - 21, 0, 21, 21), "X")) { Hide(); } if (GUI.RepeatButton(new Rect(windowPosition.width - 21, windowPosition.height - 21, 21, 21), "\u21d8")) { resizingWindow = true; } GUI.DragWindow(new Rect(0, 0, 10000, 20)); }
public static void Hide() { drawWindow = false; KSPScienceSettings.Hide(); }
private void OnWindow(int windowID) { GUI.skin = KSPScienceSettings.getSkin(); // GUILayout.BeginHorizontal(); // autoPauseOnNew = GUILayout.Toggle(autoPauseOnNew, "Auto Pause on new Science: " + autoPauseOnNew); // GUILayout.EndHorizontal(); scrollVector2 = GUILayout.BeginScrollView(scrollVector2); GUILayout.BeginHorizontal(); for (int i = 0; i <= 6; i++) { GUILayout.BeginVertical(); switch (i) { case 0: GUILayout.Label("ID"); break; case 1: GUILayout.Label("Earned"); break; case 2: GUILayout.Label("Max"); break; case 3: GUILayout.Label("Remains"); break; case 4: GUILayout.Label("OnShip"); break; case 5: GUILayout.Label("NextExp"); break; case 6: if (KSPScienceSettings.getBoolSetting("ShowDeployButton")) { GUILayout.Label("Deploy"); } break; } foreach (ExperimentView experimentView in Output) { if (experimentView.EarnedScience >= experimentView.FullScience && !experimentView.OnShip) { continue; } GUIStyle style = new GUIStyle(); if (experimentView.OnShip) { style = KSPScienceSettings.getStyleSetting("MonitorOnShipExperiments"); } else if (experimentView.EarnedScience > 0) { style = KSPScienceSettings.getStyleSetting("MonitorKSCExperiments"); } else { style = KSPScienceSettings.getStyleSetting("MonitorNewExperiments"); if (OnShip.Exists(view => view.FullExperimentId == experimentView.FullExperimentId)) { continue; } } switch (i) { case 0: GUILayout.Label(experimentView.FullExperimentId, style); break; case 1: { string strout = Math.Round(experimentView.EarnedScience, 1).ToString(); if (strout == "0") { strout = "-"; } GUILayout.Label(strout, style); } break; case 2: { string strout = Math.Round(experimentView.FullScience, 1).ToString(); if (strout == "0") { strout = "-"; } GUILayout.Label(strout, style); } break; case 3: double percent = (experimentView.FullScience - experimentView.EarnedScience) / experimentView.FullScience * 100; if (experimentView.FullScience == 0) { GUILayout.Label("-", style); } else if (percent >= 30) { GUIStyle tmpstyle = style; style = KSPScienceSettings.getStyleSetting("MonitorNewExperiments"); GUILayout.Label(Math.Round(percent) + "%", style); style = tmpstyle; } else { GUILayout.Label(Math.Round(percent) + "%", style); } break; case 4: GUILayout.Label(experimentView.OnShip ? "\u221a" : " ", style); break; case 5: { string strout = Math.Round(experimentView.NextExperimentScience, 1).ToString(); if (strout == "0") { strout = "-"; } GUILayout.Label(strout, style); } break; case 6: { if (KSPScienceSettings.getBoolSetting("ShowDeployButton")) { GUIStyle buttonStyle = new GUIStyle(GUI.skin.button); buttonStyle.margin = new RectOffset(0, 0, 0, 0); buttonStyle.normal.textColor = style.normal.textColor; if (experimentView.FullExperimentId.Split('@')[0] == "asteroidSample") { //ModuleAsteroid[] asteroids = FindObjectsOfType<ModuleAsteroid>(); //ModuleScienceContainer collector = FlightGlobals.ActiveVessel.FindPartModulesImplementing<ModuleScienceContainer>().First<ModuleScienceContainer>(); //will be added in next version. GUILayout.Button("------", buttonStyle, GUILayout.Height(15)); } else { bool foundFreeSpaceForExperiment = false; ModuleScienceExperiment moduleScienceExperiment = null; foreach (ModuleScienceExperiment _moduleScienceExperiment in FlightGlobals.ActiveVessel.FindPartModulesImplementing <ModuleScienceExperiment>()) { if (_moduleScienceExperiment.experimentID == experimentView.FullExperimentId.Split('@')[0]) { if (!_moduleScienceExperiment.Deployed && !_moduleScienceExperiment.Inoperable && _moduleScienceExperiment.GetScienceCount() == 0) { foundFreeSpaceForExperiment = true; moduleScienceExperiment = _moduleScienceExperiment; break; } } } if (foundFreeSpaceForExperiment) { if (GUILayout.Button("deploy", buttonStyle, GUILayout.Height(15))) { moduleScienceExperiment.DeployExperiment(); } } else { GUILayout.Button("------", buttonStyle, GUILayout.Height(15)); } } } } break; } // if (autoPauseOnNew && style.normal.textColor == Color.green) // { // //activate pause // TimeWarp.SetRate(0, true); // FlightDriver.SetPause(true); // } } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); GUILayout.EndScrollView(); //GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(20); GUILayout.EndHorizontal(); GUILayout.Space(20); if (GUI.Button(new Rect(windowPosition.width - 42, 0, 21, 21), "S")) { KSPScienceSettings.Toggle(); } if (GUI.Button(new Rect(windowPosition.width - 21, 0, 21, 21), "X")) { Hide(); } if (GUI.RepeatButton(new Rect(windowPosition.width - 21, windowPosition.height - 21, 21, 21), "\u21d8")) { resizingWindow = true; } GUI.DragWindow(new Rect(0, 0, 10000, 20)); }