Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For archived contracts, show accepted/finished dates. #36

Merged
merged 3 commits into from
May 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
}
}
}