Skip to content

Commit

Permalink
Newspaper Articles: Give players option (in RP-1 GUI Window) to use l…
Browse files Browse the repository at this point in the history
…ast user screenshot instead of auto-screenshot
  • Loading branch information
pap1723 committed Jun 30, 2023
1 parent 8a32db8 commit 3c6261f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions Source/DifficultyPresets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion Source/Milestones/NewspaperUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Collections.Generic;
using KSP.Localization;
using System.Text.RegularExpressions;
using System.IO;

namespace RP0.Milestones
{
Expand Down Expand Up @@ -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));
Expand Down
16 changes: 16 additions & 0 deletions Source/UI/ContractGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
}
}
}

0 comments on commit 3c6261f

Please sign in to comment.