Skip to content

Commit

Permalink
Fixed counting current pregnancy to total count when hovering over UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco committed Dec 16, 2020
1 parent f293d5f commit 4f8435c
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions KK_Pregnancy/GUI/PregnancyGui.StatusIcons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private class StatusIcons : MonoBehaviour
private static Sprite _unknownSprite;
private static Sprite _leaveSprite;

private const string ICON_NAME = "Pregnancy_Icon";
private const string ICON_NAME = "Pregnancy_Icon";

private static readonly List<KeyValuePair<SaveData.Heroine, RectTransform>> _currentHeroine = new List<KeyValuePair<SaveData.Heroine, RectTransform>>();

Expand Down Expand Up @@ -109,7 +109,8 @@ IEnumerator CreatePregnancyIconCo()
/// </summary>
[HarmonyPostfix]
[HarmonyPatch(typeof(ParamUI), "SetHeroine", typeof(SaveData.Heroine))]
private static void ParamUI_SetHeroine(ParamUI __instance, SaveData.Heroine _heroine) {
private static void ParamUI_SetHeroine(ParamUI __instance, SaveData.Heroine _heroine)
{
var objFemaleRoot = Traverse.Create(__instance).Field("objFemaleRoot").GetValue<GameObject>();
if (objFemaleRoot == null) return;

Expand All @@ -119,8 +120,8 @@ IEnumerator HeroineCanvasPreviewUpdateCo()
{
yield return new WaitForEndOfFrame();

_currentHeroine.Clear();
SetQuickStatusIcon(objFemaleRoot, _heroine, -214f, -26f);
_currentHeroine.Clear();
SetQuickStatusIcon(objFemaleRoot, _heroine, -214f, -26f);
}

_pluginInstance.StartCoroutine(HeroineCanvasPreviewUpdateCo());
Expand Down Expand Up @@ -196,10 +197,11 @@ private void OnGUI()
GUILayout.Label($"{adjustedDay}: {(adjustedSafe ? "Safe" : "Risky")}");
}

if (pregData.PregnancyCount > 0)
var pregnancyCount = pregData.IsPregnant ? pregData.PregnancyCount - 1 : pregData.PregnancyCount;
if (pregnancyCount > 0)
{
GUILayout.FlexibleSpace();
GUILayout.Label($"This character was pregnant {pregData.PregnancyCount} times.");
GUILayout.Label($"This character was pregnant {pregnancyCount} times.");
}

if (pregData.WeeksSinceLastPregnancy > 0)
Expand Down Expand Up @@ -262,7 +264,8 @@ private static void SetHeart(GameObject heartObj, SaveData.Heroine heroine, floa
/// <param name="heroine">Is the preg icon shown</param>
/// <param name="xOffset">Offset from the character image</param>
/// <param name="yOffset">Offset from the character image</param>
private static void SetQuickStatusIcon(GameObject characterImageObj, SaveData.Heroine heroine, float xOffset, float yOffset) {
private static void SetQuickStatusIcon(GameObject characterImageObj, SaveData.Heroine heroine, float xOffset, float yOffset)
{
var existing = characterImageObj.transform.Find(ICON_NAME);

if (heroine == null)
Expand All @@ -275,8 +278,8 @@ private static void SetQuickStatusIcon(GameObject characterImageObj, SaveData.He
if (existing == null)
{
var newChildIcon = new GameObject();
newChildIcon.AddComponent<RectTransform>();
newChildIcon.AddComponent<Image>();
newChildIcon.AddComponent<RectTransform>();
newChildIcon.AddComponent<Image>();

var copy = Instantiate(newChildIcon, characterImageObj.transform);
copy.name = ICON_NAME;
Expand All @@ -294,7 +297,8 @@ private static void SetQuickStatusIcon(GameObject characterImageObj, SaveData.He
}
}

private static void AddPregIcon(Transform pregIconTransform, SaveData.Heroine heroine) {
private static void AddPregIcon(Transform pregIconTransform, SaveData.Heroine heroine)
{
var image = pregIconTransform.GetComponent<Image>();

_currentHeroine.Add(new KeyValuePair<SaveData.Heroine, RectTransform>(heroine, image.GetComponent<RectTransform>()));
Expand Down

0 comments on commit 4f8435c

Please sign in to comment.