From ddd9d3d4a3de2f8a7a10870ca61f531a9e0ffe36 Mon Sep 17 00:00:00 2001 From: NathanKell Date: Sun, 8 May 2022 19:30:11 -0700 Subject: [PATCH 1/3] For archived contracts, show accepted/finished dates. --- GameData/KSPCommunityFixes/Settings.cfg | 3 + KSPCommunityFixes/KSPCommunityFixes.csproj | 1 + .../QoL/ShowContractFinishDates.cs | 60 +++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 KSPCommunityFixes/QoL/ShowContractFinishDates.cs diff --git a/GameData/KSPCommunityFixes/Settings.cfg b/GameData/KSPCommunityFixes/Settings.cfg index 24f344b..ad56a9b 100644 --- a/GameData/KSPCommunityFixes/Settings.cfg +++ b/GameData/KSPCommunityFixes/Settings.cfg @@ -122,6 +122,9 @@ KSP_COMMUNITY_FIXES // Append "[Auto-Saved Craft]" when relevant to the craft name in the Launchpad / Runway UI AutoSavedCraftNameAtLaunch = true + + // Show date a contract finished when displaying info on a finished contract in Mission Control + ShowContractFinishDates = false // ########################## // Performance tweaks diff --git a/KSPCommunityFixes/KSPCommunityFixes.csproj b/KSPCommunityFixes/KSPCommunityFixes.csproj index 62fbbcb..24e097d 100644 --- a/KSPCommunityFixes/KSPCommunityFixes.csproj +++ b/KSPCommunityFixes/KSPCommunityFixes.csproj @@ -105,6 +105,7 @@ + diff --git a/KSPCommunityFixes/QoL/ShowContractFinishDates.cs b/KSPCommunityFixes/QoL/ShowContractFinishDates.cs new file mode 100644 index 0000000..f839096 --- /dev/null +++ b/KSPCommunityFixes/QoL/ShowContractFinishDates.cs @@ -0,0 +1,60 @@ +using HarmonyLib; +using KSP.UI.Screens; +using KSP.Localization; +using Contracts; +using System; +using System.Collections.Generic; + +namespace KSPCommunityFixes.QoL +{ + class ShowContractFinishDates : BasePatch + { + + protected override Version VersionMin => new Version(1, 12, 0); + + protected override void ApplyPatches(ref List patches) + { + patches.Add(new PatchInfo( + PatchMethodType.Postfix, + AccessTools.Method(typeof(MissionControl), "UpdateInfoPanelContract"), + this)); + } + + private static void MissionControl_UpdateInfoPanelContract_Postfix(MissionControl __instance, Contract contract) + { + if (__instance.displayMode == MissionControl.DisplayMode.Archive) + { + // Find an autoloc for the status + string stateStr = string.Empty; + switch (contract.ContractState) + { + case Contract.State.Failed: stateStr = "#autoLOC_900708"; break; + case Contract.State.Cancelled: stateStr = "#autoLOC_900711"; break; + case Contract.State.OfferExpired: stateStr = "#autoLOC_900714"; break; + case Contract.State.DeadlineExpired: stateStr = "#autoLOC_900715"; break; + case Contract.State.Declined: stateStr = "#autoLOC_900716"; break; + default: + case Contract.State.Completed: stateStr = "#autoLOC_900710"; break; + } + + // Find the Prestige string. It's the first Param, so we find the first + // place where text is formatted with the Params color + string searchStr = ""; + int idx = __instance.contractText.text.IndexOf(searchStr); + if (idx >= 0) + { + // Now skip after the double-newline + int insertionIdx = __instance.contractText.text.IndexOf("\n\n", idx); + if (insertionIdx > idx) + { + // Success! Splice around the date. + __instance.contractText.text = __instance.contractText.text.Substring(0, insertionIdx + 2) + + KSPRichTextUtil.TextDate(Localizer.Format("#autoLOC_266539"), contract.DateFinished) + + KSPRichTextUtil.TextDate(Localizer.Format(stateStr), contract.DateFinished) + + __instance.contractText.text.Substring(insertionIdx + 2); + } + } + } + } + } +} From 768a59f4089b78affe625dfe1c7b51050b1908ba Mon Sep 17 00:00:00 2001 From: NathanKell Date: Sun, 8 May 2022 19:35:10 -0700 Subject: [PATCH 2/3] Typo --- KSPCommunityFixes/QoL/ShowContractFinishDates.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KSPCommunityFixes/QoL/ShowContractFinishDates.cs b/KSPCommunityFixes/QoL/ShowContractFinishDates.cs index f839096..f10831c 100644 --- a/KSPCommunityFixes/QoL/ShowContractFinishDates.cs +++ b/KSPCommunityFixes/QoL/ShowContractFinishDates.cs @@ -49,7 +49,7 @@ private static void MissionControl_UpdateInfoPanelContract_Postfix(MissionContro { // Success! Splice around the date. __instance.contractText.text = __instance.contractText.text.Substring(0, insertionIdx + 2) - + KSPRichTextUtil.TextDate(Localizer.Format("#autoLOC_266539"), contract.DateFinished) + + KSPRichTextUtil.TextDate(Localizer.Format("#autoLOC_266539"), contract.DateAccepted) + KSPRichTextUtil.TextDate(Localizer.Format(stateStr), contract.DateFinished) + __instance.contractText.text.Substring(insertionIdx + 2); } From dbda49daa0430ed4f282b569a0937558a45421d7 Mon Sep 17 00:00:00 2001 From: NathanKell Date: Mon, 9 May 2022 13:40:57 -0700 Subject: [PATCH 3/3] Default Contract Date qol tweak to true --- GameData/KSPCommunityFixes/Settings.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GameData/KSPCommunityFixes/Settings.cfg b/GameData/KSPCommunityFixes/Settings.cfg index ad56a9b..54359d2 100644 --- a/GameData/KSPCommunityFixes/Settings.cfg +++ b/GameData/KSPCommunityFixes/Settings.cfg @@ -124,7 +124,7 @@ KSP_COMMUNITY_FIXES AutoSavedCraftNameAtLaunch = true // Show date a contract finished when displaying info on a finished contract in Mission Control - ShowContractFinishDates = false + ShowContractFinishDates = true // ########################## // Performance tweaks