Skip to content

Commit

Permalink
Add millisecond option
Browse files Browse the repository at this point in the history
  • Loading branch information
clubby789 committed Sep 20, 2020
1 parent d2c9f15 commit 23bb040
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
18 changes: 15 additions & 3 deletions ClockLib/OWClock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> eventListStr = new List<string>();
Expand All @@ -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));
}

Expand All @@ -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)
{
Expand Down Expand Up @@ -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<bool>("Count Up");
Milliseconds = config.GetSettingsValue<bool>("Count In Milliseconds");
Helper = ModHelper;
}

Expand Down
3 changes: 2 additions & 1 deletion ClockLib/default-config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"enabled": true,
"settings": {
"Count Up": true
"Count Up": true,
"Count In Milliseconds": false
}
}
2 changes: 1 addition & 1 deletion ClockLib/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 23bb040

Please sign in to comment.