From 23bb04016f2010989ce00d17bc09cc28baf524a3 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Sun, 20 Sep 2020 10:19:07 +0100 Subject: [PATCH] Add millisecond option --- ClockLib/OWClock.cs | 18 +++++++++++++++--- ClockLib/default-config.json | 3 ++- ClockLib/manifest.json | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/ClockLib/OWClock.cs b/ClockLib/OWClock.cs index f65ed6f..555e8cc 100644 --- a/ClockLib/OWClock.cs +++ b/ClockLib/OWClock.cs @@ -22,6 +22,7 @@ public class OWClock : ModBehaviour public static IModHelper Helper { get; private set; } private static EventFile save; public static bool CountUp { get; private set; } + public static bool Milliseconds { get; private set; } public static EventFile Save { get => save; set => save = value; } private List eventListStr = new List(); @@ -42,10 +43,14 @@ private void AddMenuItem() var eventMenu = ModHelper.Menus.PauseMenu.Copy("ADD EVENT"); var openInputButton = ModHelper.Menus.PauseMenu.ResumeButton.Duplicate("ADD EVENT"); openInputButton.OnClick += () => EventPopup(); + + var eventMenu2 = ModHelper.Menus.PauseMenu.Copy("DEBUG TIME"); + var openInputButton2 = ModHelper.Menus.PauseMenu.ResumeButton.Duplicate("DEBUG TIME"); + openInputButton2.OnClick += () => LogTime(); } private void LogTime() { - int currentTime = Convert.ToInt32(TimeLoop.GetSecondsElapsed()); + float currentTime = TimeLoop.GetSecondsElapsed(); base.ModHelper.Console.WriteLine(string.Format(": Time is {0}", currentTime)); } @@ -59,7 +64,7 @@ private void OnGUI() } Resolution currentRes = Screen.currentResolution; float yPos = currentRes.height - 60f; - float xPos = currentRes.width * 4/5 - 20f; + float xPos = Milliseconds ? currentRes.width * 4 / 5 - 80f : currentRes.width * 4/5 - 20f; float elapsed = TimeLoop.GetSecondsElapsed(); if (elapsed < 1f) { @@ -120,17 +125,24 @@ string ParseTime(float timestamp) { string minutes = Mathf.Floor(timestamp / 60f).ToString().PadLeft(2, '0'); string seconds = Mathf.Round(timestamp % 60f * 100f / 100f).ToString().PadLeft(2, '0'); - return string.Concat(new object[] + string clock = string.Concat(new object[] { minutes, ":", seconds }); + if (Milliseconds) + { + string milliseconds = Math.Round((timestamp - Math.Floor(timestamp))*1000).ToString().PadLeft(3, '0'); + clock = clock + ":" + milliseconds; + } + return clock; } public override void Configure(IModConfig config) { CountUp = config.GetSettingsValue("Count Up"); + Milliseconds = config.GetSettingsValue("Count In Milliseconds"); Helper = ModHelper; } diff --git a/ClockLib/default-config.json b/ClockLib/default-config.json index b756d7e..06f9600 100644 --- a/ClockLib/default-config.json +++ b/ClockLib/default-config.json @@ -1,6 +1,7 @@ { "enabled": true, "settings": { - "Count Up": true + "Count Up": true, + "Count In Milliseconds": false } } \ No newline at end of file diff --git a/ClockLib/manifest.json b/ClockLib/manifest.json index 81b7a86..e8afbbc 100644 --- a/ClockLib/manifest.json +++ b/ClockLib/manifest.json @@ -4,6 +4,6 @@ "name": "Clock", "uniqueName": "clubby789.OWClock", "description": "Add a clock overlay", - "version": "0.1.0", + "version": "0.2.0", "owmlVersion": "0.7.3" } \ No newline at end of file