Skip to content

Commit

Permalink
Fix events going offscreen
Browse files Browse the repository at this point in the history
Word wrap the text, and dynamically adjust the height of each event accordingly
  • Loading branch information
clubby789 committed Sep 22, 2020
1 parent 69fe9ea commit 734dbb4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions ClockLib/OWClock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class OWClock : ModBehaviour
private Font _hudFont;
private float _xPos;
private float _yPos;
private float _width;

public static IModHelper Helper;
public static bool CountUp { get; private set; }
Expand Down Expand Up @@ -55,6 +56,7 @@ private void RecalculatePosition(GraphicSettings settings)
{
_yPos = settings.displayResHeight - 60f;
_xPos = Milliseconds ? settings.displayResWidth * 4 / 5 - 80f : settings.displayResWidth * 4 / 5 - 20f;
_width = settings.displayResWidth * 1 / 5;
}

private void OnGUI()
Expand All @@ -74,14 +76,17 @@ private void OnGUI()
style.font = _hudFont;
style.fontSize = 30;
style.normal.textColor = Color.white;
style.wordWrap = true;

var timestamp = CountUp ? "Time Elapsed: " + ParseTime(elapsed) : "Time Remaining: " + ParseTime(TimeLoop.GetSecondsRemaining());
GUI.Label(new Rect(_xPos, _yPos, 200f, 60f), timestamp, style);
// GUI.Label(new Rect(_xPos, _yPos, 200f, 60f), timestamp, style);
GUI.Label(new Rect(_xPos, _yPos, _width, 60f), timestamp, style);

style.fontSize = 20;
int shown = 0;
// Loop until desired number of events are shown
// OR we reach end of list
float yOff = 0;
for (int i = 0; (i < Save.eventList.Count) && (shown < EventCount); i++)
{
var timeEvent = Save.eventList[i];
Expand All @@ -92,8 +97,12 @@ private void OnGUI()
var scaleFactor = (timeEvent.Timestamp - elapsed) / 20;
style.normal.textColor = Color.Lerp(Color.red, Color.white, scaleFactor);
var timeString = CountUp ? ParseTime(timeEvent.Timestamp) : ParseTime(timeEvent.Timestamp - elapsed);
GUI.Label(new Rect(_xPos, _yPos - (shown * 20) - 20f, 200f, 20f), $"{timeString} - {timeEvent.Name}", style);
GUIContent guiText = new GUIContent($"{timeString} - {timeEvent.Name}");
float labelSize = style.CalcHeight(guiText, _width);
yOff += labelSize;
GUI.Label(new Rect(_xPos, _yPos - yOff, _width, labelSize), $"{timeString} - {timeEvent.Name}", style);
shown++;

}
}

Expand Down
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": "Adds a clock overlay and eventlist",
"version": "0.2.9",
"version": "0.3.0",
"owmlVersion": "0.7.3"
}

0 comments on commit 734dbb4

Please sign in to comment.