miuu-diamond-time-viewer/Patches/MedalsDisplayPatches.cs

74 lines
1.9 KiB
C#

using HarmonyLib;
using System.Collections.Generic;
namespace DiamondTimeViewer.Patches
{
[HarmonyPatch(typeof(MedalsDisplay))]
[HarmonyPatch("Setup")]
internal class MedalsDisplaySetupPatch
{
static bool Prefix(MedalsDisplay __instance, float silver, float gold, List<string> eggUnlock)
{
if (!Config.Enabled)
return true;
// Get diamond time (since it is not passed in as a parameter)
float diamond = LevelSelect.instance.level.DiamondTime;
bool showDiamondTime = false;
if (diamond > 0.0f)
{
switch (Config.Mode)
{
case DisplayMode.Always:
showDiamondTime = true;
break;
case DisplayMode.Diamond:
showDiamondTime = LevelSelect.instance.bestScore > 0f && LevelSelect.instance.bestScore <= diamond;
break;
case DisplayMode.Gold:
showDiamondTime = LevelSelect.instance.bestScore > 0f && LevelSelect.instance.bestScore <= gold;
break;
case DisplayMode.Never:
showDiamondTime = false;
break;
}
}
string silverText = "<sprite=1> " + SegmentedTime.SPTimeText(silver);
string spacingText = "<space=0.5em> ";
string diamondText = "";
if (showDiamondTime)
{
if (Config.HideSilver)
silverText = "";
else
spacingText = "<space=0.25em> ";
diamondText = spacingText + "<sprite=3> " + SegmentedTime.SPTimeText(diamond, true);
}
if (silverText != "")
silverText += spacingText;
bool hasEgg = eggUnlock != null && eggUnlock.Count > 0;
bool gotEgg = hasEgg && UnlockManager.Get().IsUnlocked(eggUnlock[0]) && !CosmeticValues.WasPurchased(eggUnlock[0]);
string eggText = "";
if (hasEgg)
eggText = spacingText + (gotEgg ? "<sprite=9>" : "<sprite=8>");
__instance.MedalTimes.text = string.Concat(new string[]
{
silverText,
"<sprite=2> ",
SegmentedTime.SPTimeText(gold),
diamondText,
eggText
});
// Skip original method
return false;
}
}
}