@@ -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}
0 commit comments