Skip to content

Commit

Permalink
Merge pull request #36 from NathanKell/ShowContractFinishDates
Browse files Browse the repository at this point in the history
For archived contracts, show accepted/finished dates.
  • Loading branch information
gotmachine authored May 14, 2022
2 parents b8cd6fd + dbda49d commit 2b7ff3a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
3 changes: 3 additions & 0 deletions GameData/KSPCommunityFixes/Settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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 = true
// ##########################
// Performance tweaks
Expand Down
1 change: 1 addition & 0 deletions KSPCommunityFixes/KSPCommunityFixes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<Compile Include="Internal\PatchSettings.cs" />
<Compile Include="Performance\TextureLoaderOptimizations.cs" />
<Compile Include="QoL\AutoSavedCraftNameAtLaunch.cs" />
<Compile Include="QoL\ShowContractFinishDates.cs" />
<Compile Include="QoL\DisableManeuverTool.cs" />
<Compile Include="QoL\FairingMouseOverPersistence.cs" />
<Compile Include="QoL\TweakableWheelsAutostrut.cs" />
Expand Down
60 changes: 60 additions & 0 deletions KSPCommunityFixes/QoL/ShowContractFinishDates.cs
Original file line number Diff line number Diff line change
@@ -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<PatchInfo> 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 = "<b><color=#" + RUIutils.ColorToHex(RichTextUtil.colorParams) + ">";
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.DateAccepted)
+ KSPRichTextUtil.TextDate(Localizer.Format(stateStr), contract.DateFinished)
+ __instance.contractText.text.Substring(insertionIdx + 2);
}
}
}
}
}
}

0 comments on commit 2b7ff3a

Please sign in to comment.