Skip to content

Commit

Permalink
Merge pull request #707 from increddibelly/increddibelly-patch-4
Browse files Browse the repository at this point in the history
Add Day to in game clock
  • Loading branch information
nxPublic authored Oct 12, 2022
2 parents 5264ee1 + fb62b0f commit 8db0515
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,5 @@ packages/HarmonyX.2.3.1/lib/net45/0Harmony.xml
packages/HarmonyX.2.3.1/lib/net35/0Harmony.xml

# include libraries folder
!libraries/*
!libraries/*
/ValheimPlus/AssemblyPublicizer.exe
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,3 +445,4 @@ Please see [CONTRIBUTING.md](/CONTRIBUTING.md) for details on compiling V+ for d
* Nick 'baconparticles' P. - https://github.com/baconparticles
* An 'Hachidan' N. - https://github.com/ahnguyen09
* Abra - https://github.com/Abrackadabra
* Increddibelly - https://github.com/increddibelly
29 changes: 14 additions & 15 deletions ValheimPlus/GameClasses/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ private static void Postfix(ref Player __instance)
[HarmonyPatch(typeof(Player), "Update")]
public static class Player_Update_Patch
{

private static GameObject timeObj = null;
private static double savedEnvSeconds = -1;
private static double savedEnvMinutes = -1;
private static void Postfix(ref Player __instance, ref Vector3 ___m_moveDir, ref Vector3 ___m_lookDir, ref GameObject ___m_placementGhost, Transform ___m_eye)
{
if ((Configuration.Current.Player.IsEnabled && Configuration.Current.Player.queueWeaponChanges) && (ZInput.GetButtonDown("Hide") || ZInput.GetButtonDown("JoyHide")))
Expand Down Expand Up @@ -85,11 +84,8 @@ private static void Postfix(ref Player __instance, ref Vector3 ___m_moveDir, ref
ApplyDodgeHotkeys(ref __instance, ref ___m_moveDir, ref ___m_lookDir);
}


if (Configuration.Current.GameClock.IsEnabled)
{
String hours_str = "";
String minutes_str = "";
String amPM_str = "";

Hud hud = Hud.instance;
Expand Down Expand Up @@ -120,8 +116,11 @@ private static void Postfix(ref Player __instance, ref Vector3 ___m_moveDir, ref
else timeText = timeObj.GetComponent<Text>();

EnvMan env = EnvMan.instance;
if (savedEnvSeconds != env.m_totalSeconds)
// only update the time at most once per minute
if (savedEnvMinutes != env.m_totalSeconds/60)
{
int day = env.GetCurrentDay();

float minuteFrac = Mathf.Lerp(0, 24, env.GetDayFraction());
float hr24 = Mathf.Floor(minuteFrac);
minuteFrac = minuteFrac - hr24;
Expand All @@ -136,17 +135,17 @@ private static void Postfix(ref Player __instance, ref Vector3 ___m_moveDir, ref
if (hours_int > 12) hours_int -= 12;
}

if (hours_int < 10) hours_str = "0" + hours_int;
if (minutes_int < 10) minutes_str = "0" + minutes_int;
if (hours_int >= 10) hours_str = hours_int.ToString();
if (minutes_int >= 10) minutes_str = minutes_int.ToString();
// always show hours and minutes as double digits.
// combine all values into a single notification
timeText.text = $"Day {day}, {hours_int:00}:{minutes_int:00} {amPM_str}";

timeText.text = hours_str + ":" + minutes_str + amPM_str;
var staminaBarRec = hud.m_staminaBar2Root.transform as RectTransform;
var statusEffictBarRec = hud.m_statusEffectListRoot.transform as RectTransform;
timeObj.GetComponent<RectTransform>().position = new Vector2(staminaBarRec.position.x, statusEffictBarRec.position.y);
// place the time directly below the stamina bar
var staminaBarRect = hud.m_staminaBar2Root.transform as RectTransform;
var statusEffectBarRect = hud.m_statusEffectListRoot.transform as RectTransform;
timeObj.GetComponent<RectTransform>().position = new Vector2(staminaBarRect.position.x, statusEffectBarRect.position.y);
timeObj.SetActive(true);
savedEnvSeconds = env.m_totalSeconds;

savedEnvMinutes = env.m_totalSeconds/60;
}
}
}
Expand Down

0 comments on commit 8db0515

Please sign in to comment.