-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Patch Part Tooltip resources, also patch PrintSI so that it doesn't p…
…rint trailing zeroes.
- Loading branch information
1 parent
e64253a
commit a06c3bf
Showing
6 changed files
with
104 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using HarmonyLib; | ||
using KSP.Localization; | ||
using KSP.UI.Screens; | ||
using System.Reflection.Emit; | ||
using System.Reflection; | ||
using System.Collections.Generic; | ||
|
||
namespace RealismOverhaul.Harmony | ||
{ | ||
[HarmonyPatch(typeof(KSPUtil))] | ||
internal class PatchKSPUtil | ||
{ | ||
[HarmonyPrefix] | ||
[HarmonyPatch("PrintSI")] | ||
internal static bool Prefix_PrintSI(double amount, string unitName, int sigFigs, bool longPrefix, ref string __result) | ||
{ | ||
__result = ResourceUnits.PrintSI(amount, unitName, sigFigs, longPrefix); | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using HarmonyLib; | ||
using KSP.Localization; | ||
using System.Collections.Generic; | ||
|
||
namespace RealismOverhaul.Harmony | ||
{ | ||
[HarmonyPatch(typeof(PartLoader))] | ||
internal class PatchPartLoader | ||
{ | ||
[HarmonyPostfix] | ||
[HarmonyPatch("CompilePartInfo")] | ||
internal static void Postfix_CompilePartInfo(AvailablePart newPartInfo, Part part) | ||
{ | ||
// better to fix in place, but we'll just recreate. | ||
newPartInfo.resourceInfos.Clear(); | ||
|
||
string rInfoStr = string.Empty; | ||
foreach(var partResource in part.Resources) | ||
{ | ||
int resID = partResource.info.id; | ||
AvailablePart.ResourceInfo resourceInfo = new AvailablePart.ResourceInfo(); | ||
resourceInfo.resourceName = partResource.resourceName; | ||
resourceInfo.displayName = partResource.info.displayName.LocalizeRemoveGender(); | ||
resourceInfo.info = Localizer.Format("#autoLOC_166269", ResourceUnits.PrintAmount(partResource.amount, resID, 6, "F1")); | ||
if (partResource.amount != partResource.maxAmount) | ||
resourceInfo.info += " " + Localizer.Format("#autoLOC_6004042", ResourceUnits.PrintAmount(partResource.maxAmount, resID, 6, "F1")); | ||
double tons = partResource.amount * (double)partResource.info.density; | ||
if (tons > 0d) | ||
resourceInfo.info += Localizer.Format("#autoLOC_166270", ResourceUnits.PrintMass(tons)); | ||
if (partResource.info.unitCost > 0f) | ||
resourceInfo.info += Localizer.Format("#autoLOC_166271", (partResource.amount * (double)partResource.info.unitCost).ToString("F2")); | ||
if (partResource.maxAmount > 0.0) | ||
resourceInfo.primaryInfo = "<b>" + resourceInfo.displayName + ": </b>" + ResourceUnits.PrintAmount(partResource.maxAmount, resID, 6, "F1"); | ||
|
||
if (!string.IsNullOrEmpty(resourceInfo.info)) | ||
{ | ||
newPartInfo.resourceInfos.Add(resourceInfo); | ||
if (rInfoStr != string.Empty) | ||
rInfoStr += "\n"; | ||
|
||
rInfoStr += resourceInfo.info; | ||
} | ||
} | ||
if (part.Resources.Count > 0) | ||
{ | ||
rInfoStr = rInfoStr + "\nDry Mass: " + part.mass; | ||
} | ||
newPartInfo.resourceInfo = rInfoStr; | ||
newPartInfo.resourceInfos.Sort((AvailablePart.ResourceInfo rp1, AvailablePart.ResourceInfo rp2) => rp1.resourceName.CompareTo(rp2.resourceName)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters