@@ -17,6 +17,17 @@ public sealed partial class NoteEdit : FancyWindow
17
17
[ Dependency ] private readonly IGameTiming _gameTiming = default ! ;
18
18
[ Dependency ] private readonly IClientConsoleHost _console = default ! ;
19
19
20
+ private enum Multipliers
21
+ {
22
+ Minutes ,
23
+ Hours ,
24
+ Days ,
25
+ Weeks ,
26
+ Months ,
27
+ Years ,
28
+ Centuries
29
+ }
30
+
20
31
public event Action < int , NoteType , string , NoteSeverity ? , bool , DateTime ? > ? SubmitPressed ;
21
32
22
33
public NoteEdit ( SharedAdminNote ? note , string playerName , bool canCreate , bool canEdit )
@@ -31,6 +42,20 @@ public NoteEdit(SharedAdminNote? note, string playerName, bool canCreate, bool c
31
42
32
43
ResetSubmitButton ( ) ;
33
44
45
+ // It's weird to use minutes as the IDs, but it works and makes sense kind of :)
46
+ ExpiryLengthDropdown . AddItem ( Loc . GetString ( "admin-note-button-minutes" ) , ( int ) Multipliers . Minutes ) ;
47
+ ExpiryLengthDropdown . AddItem ( Loc . GetString ( "admin-note-button-hours" ) , ( int ) Multipliers . Hours ) ;
48
+ ExpiryLengthDropdown . AddItem ( Loc . GetString ( "admin-note-button-days" ) , ( int ) Multipliers . Days ) ;
49
+ ExpiryLengthDropdown . AddItem ( Loc . GetString ( "admin-note-button-weeks" ) , ( int ) Multipliers . Weeks ) ;
50
+ ExpiryLengthDropdown . AddItem ( Loc . GetString ( "admin-note-button-months" ) , ( int ) Multipliers . Months ) ;
51
+ ExpiryLengthDropdown . AddItem ( Loc . GetString ( "admin-note-button-years" ) , ( int ) Multipliers . Years ) ;
52
+ ExpiryLengthDropdown . AddItem ( Loc . GetString ( "admin-note-button-centuries" ) , ( int ) Multipliers . Centuries ) ;
53
+ ExpiryLengthDropdown . OnItemSelected += OnLengthChanged ;
54
+
55
+ ExpiryLengthDropdown . SelectId ( ( int ) Multipliers . Weeks ) ;
56
+
57
+ ExpiryLineEdit . OnTextChanged += OnTextChanged ;
58
+
34
59
TypeOption . AddItem ( Loc . GetString ( "admin-note-editor-type-note" ) , ( int ) NoteType . Note ) ;
35
60
TypeOption . AddItem ( Loc . GetString ( "admin-note-editor-type-message" ) , ( int ) NoteType . Message ) ;
36
61
TypeOption . AddItem ( Loc . GetString ( "admin-note-editor-type-watchlist" ) , ( int ) NoteType . Watchlist ) ;
@@ -134,6 +159,7 @@ private void OnTypeChanged(OptionButton.ItemSelectedEventArgs args)
134
159
SecretCheckBox . Pressed = true ; // SS220 Secret Default
135
160
SeverityOption . Disabled = false ;
136
161
PermanentCheckBox . Pressed = true ;
162
+ SubmitButton . Disabled = true ;
137
163
UpdatePermanentCheckboxFields ( ) ;
138
164
break ;
139
165
case ( int ) NoteType . Message : // Message: these are shown to the player when they log on
@@ -172,8 +198,9 @@ private void UpdatePermanentCheckboxFields()
172
198
{
173
199
ExpiryLabel . Visible = ! PermanentCheckBox . Pressed ;
174
200
ExpiryLineEdit . Visible = ! PermanentCheckBox . Pressed ;
201
+ ExpiryLengthDropdown . Visible = ! PermanentCheckBox . Pressed ;
175
202
176
- ExpiryLineEdit . Text = ! PermanentCheckBox . Pressed ? DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss" ) : string . Empty ;
203
+ ExpiryLineEdit . Text = ! PermanentCheckBox . Pressed ? 1 . ToString ( ) : string . Empty ;
177
204
}
178
205
179
206
private void OnSecretPressed ( BaseButton . ButtonEventArgs _ )
@@ -187,6 +214,16 @@ private void OnSeverityChanged(OptionButton.ItemSelectedEventArgs args)
187
214
SeverityOption . SelectId ( args . Id ) ;
188
215
}
189
216
217
+ private void OnLengthChanged ( OptionButton . ItemSelectedEventArgs args )
218
+ {
219
+ ExpiryLengthDropdown . SelectId ( args . Id ) ;
220
+ }
221
+
222
+ private void OnTextChanged ( HistoryLineEdit . LineEditEventArgs args )
223
+ {
224
+ ParseExpiryTime ( ) ;
225
+ }
226
+
190
227
private void OnSubmitButtonPressed ( BaseButton . ButtonEventArgs args )
191
228
{
192
229
if ( ! ParseExpiryTime ( ) )
@@ -263,13 +300,24 @@ private bool ParseExpiryTime()
263
300
return true ;
264
301
}
265
302
266
- if ( string . IsNullOrWhiteSpace ( ExpiryLineEdit . Text ) || ! DateTime . TryParse ( ExpiryLineEdit . Text , out var result ) || DateTime . UtcNow > result )
303
+ if ( string . IsNullOrWhiteSpace ( ExpiryLineEdit . Text ) || ! uint . TryParse ( ExpiryLineEdit . Text , out var inputInt ) )
267
304
{
268
305
ExpiryLineEdit . ModulateSelfOverride = Color . Red ;
269
306
return false ;
270
307
}
271
308
272
- ExpiryTime = result . ToUniversalTime ( ) ;
309
+ var mult = ExpiryLengthDropdown . SelectedId switch
310
+ {
311
+ ( int ) Multipliers . Minutes => TimeSpan . FromMinutes ( 1 ) . TotalMinutes ,
312
+ ( int ) Multipliers . Hours => TimeSpan . FromHours ( 1 ) . TotalMinutes ,
313
+ ( int ) Multipliers . Days => TimeSpan . FromDays ( 1 ) . TotalMinutes ,
314
+ ( int ) Multipliers . Weeks => TimeSpan . FromDays ( 7 ) . TotalMinutes ,
315
+ ( int ) Multipliers . Months => TimeSpan . FromDays ( 30 ) . TotalMinutes ,
316
+ ( int ) Multipliers . Years => TimeSpan . FromDays ( 365 ) . TotalMinutes ,
317
+ ( int ) Multipliers . Centuries => TimeSpan . FromDays ( 36525 ) . TotalMinutes ,
318
+ _ => throw new ArgumentOutOfRangeException ( nameof ( ExpiryLengthDropdown . SelectedId ) , "Multiplier out of range :(" )
319
+ } ;
320
+ ExpiryTime = DateTime . UtcNow . AddMinutes ( inputInt * mult ) ;
273
321
ExpiryLineEdit . ModulateSelfOverride = null ;
274
322
return true ;
275
323
}
0 commit comments