forked from fluffy-mods/ColonyManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdateInterval.cs
78 lines (66 loc) · 2.87 KB
/
UpdateInterval.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// UpdateInterval.cs
// Copyright Karel Kroeze, 2019-2020
using System.Collections.Generic;
using RimWorld;
using UnityEngine;
using Verse;
namespace FluffyManager
{
public class UpdateInterval
{
private static UpdateInterval _daily;
public string label;
public int ticks;
public UpdateInterval( int ticks, string label )
{
this.ticks = ticks;
this.label = label;
}
public static UpdateInterval Daily
{
get
{
if ( _daily == null ) _daily = new UpdateInterval( GenDate.TicksPerDay, "FM.Daily".Translate() );
return _daily;
}
}
public void Draw( Rect canvas, ManagerJob job )
{
Text.Anchor = TextAnchor.MiddleCenter;
// how many hours have passed since the last update?
var lastUpdate = Find.TickManager.TicksGame - job.lastAction;
var progress = (float) lastUpdate / GenDate.TicksPerHour;
var nextUpdate = (float) job.UpdateInterval.ticks / GenDate.TicksPerHour;
// how far over time are we? Draw redder if further over time.
var progressColour = progress < nextUpdate
? Color.white
: Color.Lerp( Color.white, Color.red, ( progress - nextUpdate ) / nextUpdate * 2f );
if ( nextUpdate < 12 && progress < 12 )
{
var nextUpdateHandle = new ClockHandle( nextUpdate, GenUI.MouseoverColor );
var progressHandle =
new ClockHandle( progress, progressColour );
Clock.Draw( canvas.ContractedBy( 4f ), nextUpdateHandle, progressHandle );
}
else
{
var nextUpdateMarker =
new CalendarMarker( nextUpdate / GenDate.HoursPerDay, GenUI.MouseoverColor, false );
var progressMarker = new CalendarMarker( progress / GenDate.HoursPerDay, progressColour, true );
Calendar.Draw( canvas.ContractedBy( 2f ), progressMarker, nextUpdateMarker );
}
TooltipHandler.TipRegion( canvas,
"FM.LastUpdateTooltip".Translate(
lastUpdate.TimeString(),
job.UpdateInterval.ticks.TimeString() ) );
Widgets.DrawHighlightIfMouseover( canvas );
if ( Widgets.ButtonInvisible( canvas ) )
{
var options = new List<FloatMenuOption>();
foreach ( var interval in Utilities.UpdateIntervalOptions )
options.Add( new FloatMenuOption( interval.label, () => job.UpdateInterval = interval ) );
Find.WindowStack.Add( new FloatMenu( options ) );
}
}
}
}