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

71 lines
1.9 KiB
C#
Raw Permalink Normal View History

2023-08-21 19:05:40 -04:00
using HarmonyLib;
using System.Collections.Generic;
namespace DiamondTimeViewer.Patches
2023-08-21 19:05:40 -04:00
{
2024-01-01 14:58:31 -05:00
[HarmonyPatch(typeof(MedalsDisplay), nameof(MedalsDisplay.Setup))]
2023-08-21 19:05:40 -04:00
internal class MedalsDisplaySetupPatch
{
static bool Prefix(MedalsDisplay __instance, float silver, float gold, List<string> eggUnlock)
{
if (Config.Mode == DisplayMode.Never)
2023-08-22 21:07:51 -04:00
return true;
2023-08-21 19:05:40 -04:00
// Get diamond time (since it is not passed in as a parameter)
float diamond = LevelSelect.instance.level.DiamondTime;
2023-08-22 21:07:51 -04:00
bool showDiamondTime = false;
2023-10-06 21:07:00 -04:00
if (diamond > 0.0f)
2023-08-22 21:07:51 -04:00
{
2023-10-06 21:07:00 -04:00
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;
}
2023-08-22 21:07:51 -04:00
}
string silverText = "<sprite=1> " + SegmentedTime.SPTimeText(silver);
2023-10-05 00:33:04 -04:00
string spacingText = "<space=0.5em> ";
2023-08-21 19:05:40 -04:00
string diamondText = "";
2023-08-22 21:07:51 -04:00
if (showDiamondTime)
2023-10-05 00:33:04 -04:00
{
if (Config.HideSilver)
silverText = "";
else
spacingText = "<space=0.25em> ";
2023-10-05 00:35:42 -04:00
diamondText = spacingText + "<sprite=3> " + SegmentedTime.SPTimeText(diamond, true);
2023-10-05 00:33:04 -04:00
}
if (silverText != "")
silverText += spacingText;
2023-10-05 00:33:04 -04:00
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>");
2023-08-21 19:05:40 -04:00
__instance.MedalTimes.text = string.Concat(new string[]
{
silverText,
2023-08-21 19:05:40 -04:00
"<sprite=2> ",
SegmentedTime.SPTimeText(gold),
diamondText,
eggText
});
// Skip original method
return false;
}
}
}