/// <summary> /// Draws the window if it is visible. /// </summary> public void Draw( ) { if (!IsVisible) { return; } if (!GameHelper.AllowChecklistWindow( )) { IsVisible = false; OnCloseEvent(this, EventArgs.Empty); } if (_skin == null) { // Initialize our skin and styles. _skin = GameObject.Instantiate(HighLogic.Skin) as GUISkin; _skin.horizontalScrollbarThumb.fixedHeight = wScale(13); _skin.horizontalScrollbar.fixedHeight = wScale(13); _labelStyle = new GUIStyle(_skin.label) { fontSize = wScale(11), fontStyle = FontStyle.Italic, }; _progressLabelStyle = new GUIStyle(_skin.label) { fontStyle = FontStyle.BoldAndItalic, alignment = TextAnchor.MiddleCenter, fontSize = wScale(11), normal = { textColor = new Color(0.322f, 0.298f, 0.004f), }, }; _situationStyle = new GUIStyle(_progressLabelStyle) { fontSize = wScale(13), alignment = TextAnchor.MiddleCenter, fontStyle = FontStyle.Normal, fixedHeight = wScale(25), contentOffset = wScale(new Vector2(0, 6)), wordWrap = true, normal = { textColor = new Color(0.7f, 0.8f, 0.8f), } }; _experimentProgressLabelStyle = new GUIStyle(_skin.label) { fontSize = wScale(16), alignment = TextAnchor.MiddleLeft, padding = wScale(new RectOffset(0, 0, 4, 0)) }; _textFieldStyle = new GUIStyle(_skin.textField) { fontSize = wScale(16), alignment = TextAnchor.MiddleLeft, }; _horizontalScrollbarOnboardStyle = new GUIStyle(_skin.horizontalScrollbar) { normal = { background = _emptyTexture, }, }; _compactWindowStyle = new GUIStyle(_skin.window) { padding = wScale(new RectOffset(0, 4, 4, 4)) }; _compactLabelStyle = new GUIStyle(_labelStyle) { fontSize = wScale(9) }; _compactSituationStyle = new GUIStyle(_situationStyle) { fontSize = wScale(11), contentOffset = wScale(new Vector2(0, 3)) }; _compactButtonStyle = new GUIStyle(_skin.button) { padding = new RectOffset(), fixedHeight = wScale(16) }; _closeButtonStyle = new GUIStyle(_skin.button) { // int left, int right, int top, int bottom padding = wScale(new RectOffset(2, 2, 2, 2)), margin = wScale(new RectOffset(1, 1, 1, 1)), stretchWidth = false, stretchHeight = false, alignment = TextAnchor.MiddleCenter, }; _windowStyle = new GUIStyle(_skin.window) { fontSize = (int)(_skin.window.fontSize * _parent.Config.UiScale), padding = wScale(_skin.window.padding), margin = wScale(_skin.window.margin), border = wScale(_skin.window.border), contentOffset = wScale(_skin.window.contentOffset), }; _skin.window = _windowStyle; } var oldSkin = GUI.skin; GUI.skin = _skin; if (_compactMode) { _rect3 = GUILayout.Window(_window3Id, _rect3, DrawCompactControls, string.Empty, _compactWindowStyle); } else { _rect = GUILayout.Window(_windowId, _rect, DrawControls, "[x] Science!"); } if (!string.IsNullOrEmpty(_lastTooltip)) { _tooltipStyle = _tooltipStyle ?? new GUIStyle(_skin.window) { normal = { background = GUI.skin.window.normal.background }, wordWrap = true }; _tooltipBoxStyle = _tooltipBoxStyle ?? new GUIStyle(_skin.box) { // fontSize = wScale(11), // int left, int right, int top, int bottom padding = wScale(new RectOffset(4, 4, 4, 4)), wordWrap = true }; float boxHeight = _tooltipBoxStyle.CalcHeight(new GUIContent(_lastTooltip), wScale(190)); GUI.Window(_window2Id, new Rect(Mouse.screenPos.x + wScale(15), Mouse.screenPos.y + wScale(15), wScale(200), boxHeight + wScale(10)), x => { GUI.Box(new Rect(wScale(5), wScale(5), wScale(190), boxHeight), _lastTooltip, _tooltipBoxStyle); }, string.Empty, _tooltipStyle); } GUI.skin = oldSkin; }
/// <summary> /// Draws the window if it is visible. /// </summary> public void Draw( ) { if (!IsVisible) { return; } if (!GameHelper.WindowVisibility( )) { IsVisible = false; OnCloseEvent(this, EventArgs.Empty); } if (_skin == null) { // Initialize our skin and styles. _skin = GameObject.Instantiate(HighLogic.Skin) as GUISkin; _skin.horizontalScrollbarThumb.fixedHeight = 13; _skin.horizontalScrollbar.fixedHeight = 13; _labelStyle = new GUIStyle(_skin.label) { fontSize = 11, fontStyle = FontStyle.Italic, }; _progressLabelStyle = new GUIStyle(_skin.label) { fontStyle = FontStyle.BoldAndItalic, alignment = TextAnchor.MiddleCenter, fontSize = 11, normal = { textColor = new Color(0.322f, 0.298f, 0.004f), }, }; _situationStyle = new GUIStyle(_progressLabelStyle) { fontSize = 13, alignment = TextAnchor.MiddleLeft, fontStyle = FontStyle.Normal, fixedHeight = 25, contentOffset = new Vector2(0, 6), normal = { textColor = new Color(0.7f, 0.8f, 0.8f), }, }; _experimentProgressLabelStyle = new GUIStyle(_skin.label) { padding = new RectOffset(0, 0, 4, 0), }; _horizontalScrollbarOnboardStyle = new GUIStyle(_skin.horizontalScrollbar) { normal = { background = _emptyTexture, }, }; _compactWindowStyle = new GUIStyle(_skin.window) { padding = new RectOffset(0, 4, 4, 4), }; _compactLabelStyle = new GUIStyle(_labelStyle) { fontSize = 9, }; _compactSituationStyle = new GUIStyle(_situationStyle) { fontSize = 11, contentOffset = new Vector2(0, -3), }; _compactButtonStyle = new GUIStyle(_skin.button) { padding = new RectOffset(), fixedHeight = 16 }; _closeButtonStyle = new GUIStyle(_skin.button) { // int left, int right, int top, int bottom padding = new RectOffset(2, 2, 6, 2), }; } var oldSkin = GUI.skin; GUI.skin = _skin; if (_compactMode) { _rect3 = GUILayout.Window(_window3Id, _rect3, DrawCompactControls, string.Empty, _compactWindowStyle); } else { _rect = GUILayout.Window(_windowId, _rect, DrawControls, "[x] Science!"); var ClosePos = new Rect(_rect.xMin + _rect.width - 20, _rect.yMin + 2, 18, 18); --GUI.depth; if (GUI.Button(ClosePos, "X", _closeButtonStyle)) { IsVisible = false; OnCloseEvent(this, EventArgs.Empty); } } if (!string.IsNullOrEmpty(_lastTooltip)) { _tooltipStyle = _tooltipStyle ?? new GUIStyle(_skin.window) { normal = { background = _emptyTexture, }, }; GUI.Window(_window2Id, new Rect(Mouse.screenPos.x + 15, Mouse.screenPos.y + 15, 500, 30), x => { GUI.Label(new Rect(), _lastTooltip); }, string.Empty, _tooltipStyle); } GUI.skin = oldSkin; }
/// <summary> /// Refreshes the experiment cache. THIS IS VERY EXPENSIVE. /// CB: Actually doesn't seem much worse than UpdateExperiments() /// </summary> public void RefreshExperimentCache( ) { // Init var StartTime = DateTime.Now; // _logger.Info( "RefreshExperimentCache" ); // Quick check for things we depend on if (ResearchAndDevelopment.Instance == null) { _logger.Debug("ResearchAndDevelopment not instantiated."); AllExperiments = new List <Experiment>( ); UpdateFilter( ); return; } if (PartLoader.Instance == null) { _logger.Debug("PartLoader not instantiated."); AllExperiments = new List <Experiment>( ); UpdateFilter( ); return; } // Temporary experiment list var exps = new List <Experiment>( ); /*foreach( var P in PartLoader.Instance.parts ) * { * var Modules = P.partPrefab.FindModulesImplementing<ModuleScienceExperiment>( ); * if( Modules.Count > 0 ) * { * foreach( var M in Modules ) * { * _logger.Debug( "PART " + P.name + " HAS EXPERIMENT " + M.experimentID ); * } * } * }*/ // Find all experiments - These should be in an object var experiments = PartLoader.Instance.parts .SelectMany(x => x.partPrefab.FindModulesImplementing <ModuleScienceExperiment>( )) .Select(x => new { Module = x, Experiment = ResearchAndDevelopment.GetExperiment(x.experimentID), }) .Where(x => x.Experiment != null) .GroupBy(x => x.Experiment) .ToDictionary(x => x.Key, x => x.First( ).Module); experiments.Remove(ResearchAndDevelopment.GetExperiment("evaReport")); experiments.Remove(ResearchAndDevelopment.GetExperiment("surfaceSample")); /* _logger.Debug( "Found " + experiments.Count + " experimnents" ); * foreach( var XX in experiments ) * { * if( XX.Value != null ) * _logger.Debug( "EXPERIMENT " + XX.Key.experimentTitle ); * }*/ // Find all celestial bodies var bodies = new AllBodies( ); // Find all situations var situations = Enum.GetValues(typeof(ExperimentSituations)).Cast <ExperimentSituations>( ); // Find the KSC baby biomes /* MOVE THIS ELSE WHERE */ _kscBiomes = new List <string>( ); _kscBiomes = _kscBiomes.Any() ? _kscBiomes : UnityEngine.Object.FindObjectsOfType <Collider>( ) .Where(x => x.gameObject.layer == 15) .Select(x => x.gameObject.tag) .Where(x => x != "Untagged") .Where(x => !x.Contains("KSC_Runway_Light")) .Where(x => !x.Contains("KSC_Pad_Flag_Pole")) .Where(x => !x.Contains("Ladder")) .Select(x => Vessel.GetLandedAtString(x)) .Select(x => x.Replace(" ", "")) .Distinct() .ToList(); // Unlocked experiment list - Maybe merge with "var experiments" above AvailableExperiments.Clear( ); // Grab the list of science experiments var SciDict = GetScienceSubjects( ); // Find the science stored in vessels var onboardScience = GameHelper.GetOnboardScience(Config.CheckDebris); // We need the level of the RnD facility in career mode float RnDLevel = ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.ResearchAndDevelopment); // Loop around all experiments foreach (var experiment in experiments.Keys) { // Examine each experiment in turn if (experiment.requiredExperimentLevel > RnDLevel) { continue; // Need to upgrade the RnD facility in career mode. } var sitMask = experiment.situationMask; var biomeMask = experiment.biomeMask; // OrbitalScience support if (sitMask == 0 && experiments[experiment] != null) { var sitMaskField = experiments[experiment].GetType( ).GetField("sitMask"); if (sitMaskField != null) { sitMask = (uint)(int)sitMaskField.GetValue(experiments[experiment]); _logger.Debug("Setting sitMask to " + sitMask + " for " + experiment.experimentTitle); } if (biomeMask == 0) { var biomeMaskField = experiments[experiment].GetType( ).GetField("bioMask"); if (biomeMaskField != null) { biomeMask = (uint)(int)biomeMaskField.GetValue(experiments[experiment]); _logger.Debug("Setting biomeMask to " + biomeMask + " for " + experiment.experimentTitle); } } } // Check this experiment in all biomes on all bodies foreach (var b in bodies.List) { var body = b.Value; if (experiment.requireAtmosphere && !body.HasAtmosphere) { continue; // If the whole planet doesn't have an atmosphere, then there's not much point continuing. } foreach (var situation in situations) { if (situation == ExperimentSituations.SrfSplashed && !body.HasOcean) { continue; // Some planets don't have an ocean for us to be splashed down in. } if (situation == ExperimentSituations.SrfLanded && !body.HasSurface) { continue; // Jool and the Sun don't have a surface. } if ((situation == ExperimentSituations.FlyingHigh || situation == ExperimentSituations.FlyingLow) && !body.HasAtmosphere) { continue; // Some planets don't have an atmosphere for us to fly in. } if ((sitMask & (uint)situation) == 0) { continue; // This experiment isn't valid for our current situation. } if (body.Biomes.Any( ) && (biomeMask & (uint)situation) != 0) { foreach (var biome in body.Biomes) { exps.Add(new Experiment(experiment, new Situation(body.CelestialBody, situation, biome), onboardScience, SciDict, AvailableExperiments)); } /* MOVE THIS OUT OF THE LOOP - HANDLE IT SEPERATLY */ // Can't really avoid magic constants here - Kerbin and Shores if ((body.Name == "Kerbin") && situation == ExperimentSituations.SrfLanded) { foreach (var kscBiome in _kscBiomes) // Ew. { exps.Add(new Experiment(experiment, new Situation(body.CelestialBody, situation, "Shores", kscBiome), onboardScience, SciDict, AvailableExperiments)); } } } else { exps.Add(new Experiment(experiment, new Situation(body.CelestialBody, situation), onboardScience, SciDict, AvailableExperiments)); } } } } // Done replace the old list with the new one AllExperiments = exps; // We need to redo the filter UpdateFilter( ); var Elapsed = DateTime.Now - StartTime; _logger.Trace("RefreshExperimentCache Done - " + Elapsed.ToString( ) + "ms"); }