From 9a1cdcf7b62bf13801b20825a38676e1ffb76990 Mon Sep 17 00:00:00 2001 From: NathanKell Date: Sun, 28 May 2023 18:04:11 -0700 Subject: [PATCH] Warning dialog for breaking change --- Source/RealSolarSystem.csproj | 1 + Source/StartupPopup.cs | 48 +++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 Source/StartupPopup.cs diff --git a/Source/RealSolarSystem.csproj b/Source/RealSolarSystem.csproj index 845f84a1..c2384263 100644 --- a/Source/RealSolarSystem.csproj +++ b/Source/RealSolarSystem.csproj @@ -50,6 +50,7 @@ + diff --git a/Source/StartupPopup.cs b/Source/StartupPopup.cs new file mode 100644 index 00000000..e2a693c1 --- /dev/null +++ b/Source/StartupPopup.cs @@ -0,0 +1,48 @@ +using System; +using System.IO; +using System.Linq; +using System.Reflection; +using UnityEngine; + +namespace RealSolarSystem +{ + [KSPAddon(KSPAddon.Startup.Instantly, true)] + public class StartupPopup : MonoBehaviour + { + private const string PreferenceFileName = "RSSFinalizeOrbitWarning"; + private static string PreferenceFilePath => Path.Combine( + Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), + "PluginData", + PreferenceFileName); + + public void Start() + { + if (AssemblyLoader.loadedAssemblies.Any(a => string.Equals(a.name, "ksp_plugin_adapter", StringComparison.OrdinalIgnoreCase))) + return; + + if (File.Exists(PreferenceFilePath)) return; + + PopupDialog.SpawnPopupDialog( + new Vector2(0, 0), + new Vector2(0, 0), + new MultiOptionDialog( + "RSSStartupDialog", + "Warning: This version contains breaking changes for non-Principia users. Significant and necessary fixes have been implemented, which may result in planets changing positions in their orbits. Existing maneuvers and vessels in flight may have dramatically altered future encounters. For existing saves, it is recommended to revert to the prior CKAN version and upgrading is not recommended. Please create backups before attempting to update existing saves.", + "Real Solar System", + HighLogic.UISkin, + new DialogGUIVerticalLayout( + new DialogGUIButton("Don't show again", RememberPreference, true), + new DialogGUIButton("Ok", () => { }, true) + ) + ), + true, + HighLogic.UISkin); + } + + private static void RememberPreference() + { + // create empty file + File.Create(PreferenceFilePath).Close(); + } + } +}