Skip to content

Commit ecf377a

Browse files
committed
Add years to time entries
1 parent 0767f99 commit ecf377a

File tree

5 files changed

+74
-25
lines changed

5 files changed

+74
-25
lines changed

MicroEngineerProject/MicroEngineer/Entries/BaseEntry.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public virtual object EntryValue
5959
break;
6060
case EntryType.Time:
6161
var time = Utility.ParseSecondsToTimeFormat((double?)value ?? 0);
62-
OnEntryTimeValueChanged?.Invoke(time.Days, time.Hours, time.Minutes, time.Seconds);
62+
OnEntryTimeValueChanged?.Invoke(time.Years, time.Days, time.Hours, time.Minutes, time.Seconds);
6363
break;
6464
case EntryType.LatitudeLongitude:
6565
var latLon = Utility.ParseDegreesToDMSFormat((double?)value ?? 0);
@@ -78,7 +78,7 @@ public virtual object EntryValue
7878
}
7979

8080
public delegate void EntryValueChanged(string value, string unit);
81-
public delegate void EntryTimeValueChanged(int days, int hours, int minutes, int seconds);
81+
public delegate void EntryTimeValueChanged(int years, int days, int hours, int minutes, int seconds);
8282
public delegate void EntryLatLonChanged(int degrees, int minutes, int seconds, string direction);
8383
public delegate void StageInfoChanged(List<Stage> stages);
8484
public event EntryValueChanged OnEntryValueChanged;

MicroEngineerProject/MicroEngineer/UI/Controls/TimeEntryControl.cs

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ public string EntryName
3232
set => NameLabel.text = value;
3333
}
3434

35+
public Label YearsValueLabel;
36+
public Label YearsUnitLabel;
37+
public string Years
38+
{
39+
get => YearsValueLabel.text;
40+
set => YearsValueLabel.text = value;
41+
}
42+
3543
public Label DaysValueLabel;
3644
public Label DaysUnitLabel;
3745
public string Days
@@ -64,46 +72,51 @@ public string Seconds
6472
set => SecondsValueLabel.text = value;
6573
}
6674

67-
public void SetValue(int days, int hours, int minutes, int seconds)
75+
public void SetValue(int years, int days, int hours, int minutes, int seconds)
6876
{
69-
70-
days = Mathf.Clamp(days, -9999, 9999);
77+
years = Mathf.Clamp(years, -9999, 9999);
78+
days = Mathf.Clamp(days, -425, 425);
7179
hours = Mathf.Clamp(hours, -23, 23);
7280
minutes = Mathf.Clamp(minutes, -59, 59);
7381
seconds = Mathf.Clamp(seconds, -59, 59);
7482

75-
Days = days.ToString("0");
76-
DisplayStyle showDays = days != 0 ? DisplayStyle.Flex : DisplayStyle.None;
83+
Years = years.ToString("0");
84+
DisplayStyle showYears = years != 0 ? DisplayStyle.Flex : DisplayStyle.None;
85+
YearsValueLabel.style.display = showYears;
86+
YearsUnitLabel.style.display = showYears;
87+
88+
Days = years == 0 ? days.ToString("0") : days.ToString("000");
89+
DisplayStyle showDays = years != 0 || days != 0 ? DisplayStyle.Flex : DisplayStyle.None;
7790
DaysValueLabel.style.display = showDays;
7891
DaysUnitLabel.style.display = showDays;
7992

80-
Hours = days == 0 ? hours.ToString("0") : hours.ToString("00");
81-
DisplayStyle showHours = days != 0 || hours != 0 ? DisplayStyle.Flex : DisplayStyle.None;
93+
Hours = days == 0 && years == 0 ? hours.ToString("0") : hours.ToString("00");
94+
DisplayStyle showHours = years != 0 || days != 0 || hours != 0 ? DisplayStyle.Flex : DisplayStyle.None;
8295
HoursValueLabel.style.display = showHours;
8396
HoursUnitLabel.style.display = showHours;
8497

85-
Minutes = hours == 0 && days == 0 ? minutes.ToString("0") : minutes.ToString("00");
86-
DisplayStyle showMinutes = days != 0 || hours != 0 || minutes != 0 ? DisplayStyle.Flex : DisplayStyle.None;
98+
Minutes = hours == 0 && days == 0 && years == 0? minutes.ToString("0") : minutes.ToString("00");
99+
DisplayStyle showMinutes = years != 0 || days != 0 || hours != 0 || minutes != 0 ? DisplayStyle.Flex : DisplayStyle.None;
87100
MinutesValueLabel.style.display = showMinutes;
88101
MinutesUnitLabel.style.display = showMinutes;
89102

90-
Seconds = minutes == 0 && hours == 0 && days == 0 ? seconds.ToString("0") : seconds.ToString("00");
103+
Seconds = minutes == 0 && hours == 0 && days == 0 && years == 0 ? seconds.ToString("0") : seconds.ToString("00");
91104
}
92105

93106
public TimeEntryControl(BaseEntry entry) : this()
94107
{
95108
EntryName = entry.Name;
96109

97110
var time = Utility.ParseSecondsToTimeFormat((double?)entry.EntryValue ?? 0);
98-
SetValue(time.Days, time.Hours, time.Minutes, time.Seconds);
111+
SetValue(time.Years, time.Days, time.Hours, time.Minutes, time.Seconds);
99112

100113
entry.OnEntryTimeValueChanged += HandleEntryTimeValueChanged;
101114
}
102115

103-
public TimeEntryControl(string entry, int days, int hours, int minutes, int seconds) : this()
116+
public TimeEntryControl(string entry, int years, int days, int hours, int minutes, int seconds) : this()
104117
{
105118
EntryName = entry;
106-
SetValue(days, hours, minutes, seconds);
119+
SetValue(years, days, hours, minutes, seconds);
107120
}
108121

109122
public TimeEntryControl()
@@ -128,6 +141,24 @@ public TimeEntryControl()
128141
ValueContainer.style.justifyContent = Justify.FlexEnd;
129142
hierarchy.Add(ValueContainer);
130143

144+
{
145+
YearsValueLabel = new Label()
146+
{
147+
name = "years-value"
148+
};
149+
YearsValueLabel.AddToClassList(UssValueClassName);
150+
YearsValueLabel.AddToClassList(UssOuterValueClassName);
151+
ValueContainer.Add(YearsValueLabel);
152+
YearsUnitLabel = new Label()
153+
{
154+
name = "years-unit",
155+
text = UNIT_YEAR
156+
};
157+
YearsUnitLabel.AddToClassList(UssUnitClassName);
158+
YearsUnitLabel.AddToClassList(UssInnerUnitClassName);
159+
ValueContainer.Add(YearsUnitLabel);
160+
}//years
161+
131162
{
132163
DaysValueLabel = new Label()
133164
{
@@ -204,6 +235,7 @@ public TimeEntryControl()
204235
public new class UxmlTraits : VisualElement.UxmlTraits
205236
{
206237
UxmlStringAttributeDescription _entry = new UxmlStringAttributeDescription() { name = "Entry", defaultValue = "Name" };
238+
UxmlIntAttributeDescription _years = new UxmlIntAttributeDescription() { name = "years", defaultValue = 1 };
207239
UxmlIntAttributeDescription _days = new UxmlIntAttributeDescription() { name = "days", defaultValue = 12 };
208240
UxmlIntAttributeDescription _hours = new UxmlIntAttributeDescription() { name = "hours", defaultValue = 34 };
209241
UxmlIntAttributeDescription _minutes = new UxmlIntAttributeDescription() { name = "minutes", defaultValue = 56 };
@@ -217,6 +249,7 @@ public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext
217249
{
218250
entry.EntryName = _entry.GetValueFromBag(bag, cc);
219251
entry.SetValue(
252+
_years.GetValueFromBag(bag, cc),
220253
_days.GetValueFromBag(bag, cc),
221254
_hours.GetValueFromBag(bag, cc),
222255
_minutes.GetValueFromBag(bag, cc),
@@ -226,6 +259,6 @@ public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext
226259
}
227260
}
228261

229-
public void HandleEntryTimeValueChanged(int days, int hours, int minutes, int seconds) => SetValue(days, hours, minutes, seconds);
262+
public void HandleEntryTimeValueChanged(int years, int days, int hours, int minutes, int seconds) => SetValue(years, days, hours, minutes, seconds);
230263
}
231264
}

MicroEngineerProject/MicroEngineer/Utilities/TimeParsed.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
{
33
public struct TimeParsed
44
{
5+
public int Years;
56
public int Days;
67
public int Hours;
78
public int Minutes;
89
public int Seconds;
910

10-
public static TimeParsed MaxValue() => new TimeParsed { Days = int.MaxValue, Hours = 23, Minutes = 59, Seconds = 59 };
11-
public static TimeParsed MinValue() => new TimeParsed { Days = int.MinValue, Hours = 23, Minutes = 59, Seconds = 59 };
11+
public static TimeParsed MaxValue() => new TimeParsed { Years = int.MaxValue, Days = 425, Hours = 5, Minutes = 59, Seconds = 59 };
12+
public static TimeParsed MinValue() => new TimeParsed { Years = -int.MaxValue, Days = 425, Hours = 5, Minutes = 59, Seconds = 59 };
1213
}
1314
}

MicroEngineerProject/MicroEngineer/Utilities/Utility.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,23 @@ public static TimeParsed ParseSecondsToTimeFormat(double inputSeconds)
6565
inputSeconds = Math.Ceiling(inputSeconds);
6666
var absoluteSeconds = Math.Abs(inputSeconds);
6767

68-
int days = (int)(absoluteSeconds / 21600);
69-
int hours = (int)((absoluteSeconds - days * 21600) / 3600);
70-
int minutes = (int)((absoluteSeconds - hours * 3600 - days * 21600) / 60);
71-
int seconds = (int)(absoluteSeconds - days * 21600 - hours * 3600 - minutes * 60);
68+
int years = (int)(absoluteSeconds / 9201600); // 426 days in a year
69+
int days = (int)((absoluteSeconds - years * 9201600) / 21600); // 6 hours in a day
70+
int hours = (int)((absoluteSeconds - years * 9201600 - days * 21600) / 3600);
71+
int minutes = (int)((absoluteSeconds - years * 9201600 - days * 21600 - hours * 3600 ) / 60);
72+
int seconds = (int)(absoluteSeconds - years * 9201600 - days * 21600 - hours * 3600 - minutes * 60);
7273

7374
// If inputSeconds is negative, reverse the sign of the higest calculated value
7475
if (inputSeconds < 0)
7576
{
76-
if (days != 0)
77-
days = -days;
77+
if (years != 0) years = -years;
78+
else if (days != 0) days = -days;
7879
else if (hours != 0) hours = -hours;
7980
else if (minutes != 0) minutes = -minutes;
8081
else if (seconds != 0) seconds = -seconds;
8182
}
8283

83-
return new TimeParsed() { Days = days, Hours = hours, Minutes = minutes, Seconds = seconds };
84+
return new TimeParsed() { Years = years, Days = days, Hours = hours, Minutes = minutes, Seconds = seconds };
8485
}
8586

8687
public static string SituationToString(VesselSituations situation)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
*
3+
*
4+
* TODO
5+
* - update UITK for 0.1.5
6+
* - add setting to enable/disable keybinding
7+
*
8+
*
9+
*
10+
*
11+
*
12+
*
13+
*
14+
*/

0 commit comments

Comments
 (0)