From 3c6261f566c62363d91af9602384a0eb468d922b Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 30 Jun 2023 06:45:49 -0500 Subject: [PATCH] Newspaper Articles: Give players option (in RP-1 GUI Window) to use last user screenshot instead of auto-screenshot --- Source/DifficultyPresets.cs | 1 + Source/Milestones/NewspaperUI.cs | 10 +++++++++- Source/UI/ContractGUI.cs | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Source/DifficultyPresets.cs b/Source/DifficultyPresets.cs index 3c4a8cd3ac1..cec1bb7e338 100644 --- a/Source/DifficultyPresets.cs +++ b/Source/DifficultyPresets.cs @@ -91,6 +91,7 @@ public class RP0Settings : GameParameters.CustomParameterNode public int CommsPayload = ContractGUI.MinPayload; public int WeatherPayload = ContractGUI.MinPayload; public string NewspaperTitle = "Space Gazette"; + public bool UseLastScreenshot = false; public bool AirlaunchTipShown = false; public bool RealChuteTipShown = false; diff --git a/Source/Milestones/NewspaperUI.cs b/Source/Milestones/NewspaperUI.cs index ff5c805e00e..afb5229d55e 100644 --- a/Source/Milestones/NewspaperUI.cs +++ b/Source/Milestones/NewspaperUI.cs @@ -8,6 +8,7 @@ using System.Collections.Generic; using KSP.Localization; using System.Text.RegularExpressions; +using System.IO; namespace RP0.Milestones { @@ -125,11 +126,18 @@ private static Sprite GetImage(Milestone m) { Texture2D tex = null; string filePath = $"{KSPUtil.ApplicationRootPath}/saves/{HighLogic.SaveFolder}/{m.name}.png"; - if (System.IO.File.Exists(filePath)) + if (System.IO.File.Exists(filePath) & !_settings.UseLastScreenshot) { tex = new Texture2D(2, 2); tex.LoadImage(System.IO.File.ReadAllBytes(filePath)); } + if (_settings.UseLastScreenshot) + { + var directory = new DirectoryInfo($"{KSPUtil.ApplicationRootPath}/Screenshots/"); + tex = new Texture2D(2, 2); + var latestFile = directory.GetFiles("*.png").OrderByDescending(f => f.LastWriteTime).First().FullName; + tex.LoadImage(System.IO.File.ReadAllBytes(latestFile)); + } if (tex == null) tex = GameDatabase.Instance.GetTexture(m.image, asNormalMap: false); Sprite sprite = Sprite.Create(tex, new Rect(0f, 0f, tex.width, tex.height), new Vector2(0.5f, 0.5f)); diff --git a/Source/UI/ContractGUI.cs b/Source/UI/ContractGUI.cs index 79dc02fad29..95bbcf33c24 100644 --- a/Source/UI/ContractGUI.cs +++ b/Source/UI/ContractGUI.cs @@ -17,6 +17,7 @@ public class ContractGUI : UIBase private static string[] _weatherSatContracts = new[] { "GEOWeather" }; private static string NewspaperTitle = "Space Gazette"; + private static bool _useLastScreenshot = false; private RP0Settings _settings; @@ -85,6 +86,21 @@ public void RenderContractsTab() { GUILayout.EndVertical(); } + + GUILayout.BeginVertical(); + try + { + GUILayout.Space(10f); + GUILayout.Space(10f); + GUILayout.Label($"Use this area to set how the automatic newspaper images are created. Not selected will take an automatic screenshot.", BoldLabel); + GUILayout.Space(10f); + _useLastScreenshot = GUILayout.Toggle(_useLastScreenshot, "Use last screenshot instead of auto screenshot for Newspaper"); + _settings.UseLastScreenshot = _useLastScreenshot; + } + finally + { + GUILayout.EndVertical(); + } } } }