asm: add NewYear setting

This commit is contained in:
Lacoi 2023-11-03 16:13:34 +01:00
parent c9e6f2ec26
commit 70ed633bc0
4 changed files with 158 additions and 1 deletions

View file

@ -1228,6 +1228,22 @@ namespace ServerManagerTool.Lib
get { return (float)GetValue(EventColorsChanceOverrideProperty); }
set { SetValue(EventColorsChanceOverrideProperty, value); }
}
public static readonly DependencyProperty NewYear1UTCProperty = DependencyProperty.Register(nameof(NewYear1UTC), typeof(DateTime), typeof(ServerProfile), new PropertyMetadata(DateTime.MinValue));
[DataMember]
public DateTime NewYear1UTC
{
get { return (DateTime)GetValue(NewYear1UTCProperty); }
set { SetValue(NewYear1UTCProperty, value); }
}
public static readonly DependencyProperty NewYear2UTCProperty = DependencyProperty.Register(nameof(NewYear2UTC), typeof(DateTime), typeof(ServerProfile), new PropertyMetadata(DateTime.MinValue));
[DataMember]
public DateTime NewYear2UTC
{
get { return (DateTime)GetValue(NewYear2UTCProperty); }
set { SetValue(NewYear2UTCProperty, value); }
}
#endregion
#region Rules
@ -4116,6 +4132,16 @@ namespace ServerManagerTool.Lib
serverArgs.Append("?EventColorsChanceOverride=").Append(this.EventColorsChanceOverride);
}
if (this.NewYear1UTC != DateTime.MinValue)
{
serverArgs.Append("?NewYear1UTC=").Append((new DateTimeOffset(this.NewYear1UTC.ToUniversalTime())).ToUnixTimeSeconds().ToString());
}
if (this.NewYear2UTC != DateTime.MinValue)
{
serverArgs.Append("?NewYear2UTC=").Append((new DateTimeOffset(this.NewYear2UTC.ToUniversalTime())).ToUnixTimeSeconds().ToString());
}
if (!string.IsNullOrWhiteSpace(this.AdditionalArgs))
{
var addArgs = this.AdditionalArgs.TrimStart();
@ -4423,6 +4449,11 @@ namespace ServerManagerTool.Lib
serverArgs.Append(" -MaxNumOfSaveBackups=").Append(this.MaxNumOfSaveBackups);
}
if (this.NewYear1UTC != DateTime.MinValue || this.NewYear2UTC != DateTime.MinValue)
{
serverArgs.Append(" -NewYearEvent");
}
return serverArgs.ToString();
}
@ -6136,6 +6167,8 @@ namespace ServerManagerTool.Lib
this.ClearValue(EventNameProperty);
this.ClearValue(EventColorsChanceOverrideProperty);
this.ClearValue(NewYear1UTCProperty);
this.ClearValue(NewYear2UTCProperty);
}
public void ResetSOTFSection()
@ -6923,6 +6956,8 @@ namespace ServerManagerTool.Lib
this.SetValue(EventNameProperty, sourceProfile.EventName);
this.SetValue(EventColorsChanceOverrideProperty, sourceProfile.EventColorsChanceOverride);
this.SetValue(NewYear1UTCProperty, sourceProfile.NewYear1UTC);
this.SetValue(NewYear2UTCProperty, sourceProfile.NewYear2UTC);
}
private void SyncServerFiles(ServerProfile sourceProfile)

View file

@ -1817,6 +1817,7 @@
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="100" />
@ -1832,7 +1833,53 @@
<cctl:AnnotatedSlider Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="4" Label="{DynamicResource ServerSettings_EventColorsChanceOverrideLabel}" Value="{Binding EventColorsChanceOverride}" Suffix="{Binding EventColorsChanceOverride, Converter={StaticResource FloatToPercentageConverter}}" Minimum="0" Maximum="1" SmallChange="0.05" LargeChange="0.1" TickFrequency="0.1" ToolTip="{DynamicResource ServerSettings_EventColorsChanceOverrideTooltip}"/>
<TextBlock Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="6" Margin="5,0,5,0" Text="{DynamicResource ServerSettings_EventNote}" FontWeight="Bold" TextWrapping="WrapWithOverflow" IsEnabled="False"/>
<Label Grid.Row="2" Grid.Column="0" Content="{DynamicResource ServerSettings_NewYear1UTCLabel}" ToolTip="{DynamicResource ServerSettings_NewYear1UTCTooltip}" VerticalAlignment="Center"/>
<TextBox Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" ToolTip="{DynamicResource ServerSettings_NewYear1UTCTooltip}">
<Validation.ErrorTemplate>
<ControlTemplate>
<StackPanel>
<!-- Placeholder for the TextBox itself -->
<AdornedElementPlaceholder x:Name="textBox"/>
<TextBlock Text="{Binding [0].ErrorContent}" Background="Red" Foreground="White"/>
</StackPanel>
</ControlTemplate>
</Validation.ErrorTemplate>
<TextBox.Text>
<Binding Path="NewYear1UTC">
<Binding.Converter>
<cc:DateTimeToStringConverter />
</Binding.Converter>
<Binding.ValidationRules>
<cvr:DateTimeValidationRule ValidatesOnTargetUpdated="true" />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
<Label Grid.Row="2" Grid.Column="2" Content="{DynamicResource ServerSettings_NewYear2UTCLabel}" ToolTip="{DynamicResource ServerSettings_NewYear2UTCTooltip}" VerticalAlignment="Center"/>
<TextBox Grid.Row="2" Grid.Column="3" VerticalAlignment="Center" ToolTip="{DynamicResource ServerSettings_NewYear2UTCTooltip}">
<Validation.ErrorTemplate>
<ControlTemplate>
<StackPanel>
<!-- Placeholder for the TextBox itself -->
<AdornedElementPlaceholder x:Name="textBox"/>
<TextBlock Text="{Binding [0].ErrorContent}" Background="Red" Foreground="White"/>
</StackPanel>
</ControlTemplate>
</Validation.ErrorTemplate>
<TextBox.Text>
<Binding Path="NewYear2UTC">
<Binding.Converter>
<cc:DateTimeToStringConverter />
</Binding.Converter>
<Binding.ValidationRules>
<cvr:DateTimeValidationRule ValidatesOnTargetUpdated="true" />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
<TextBlock Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="6" Margin="5,0,5,0" Text="{DynamicResource ServerSettings_EventNote}" FontWeight="Bold" TextWrapping="WrapWithOverflow" IsEnabled="False"/>
</Grid>
</GroupBox>
</Grid>

View file

@ -0,0 +1,35 @@
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Markup;
namespace ServerManagerTool.Common.Converters
{
public class DateTimeToStringConverter : MarkupExtension, IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
DateTime datetime = (DateTime)value;
if (datetime == DateTime.MinValue)
return "";
return datetime.ToString("yyyy.MM.dd HH:mm:ss");
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is null || value.ToString() == string.Empty)
return DateTime.MinValue;
if (!DateTime.TryParse(value.ToString(), out DateTime datetime))
return DateTime.MinValue;
return datetime;
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return this;
}
}
}

View file

@ -0,0 +1,40 @@
using ServerManagerTool.Common.Extensions;
using System;
using System.Windows.Controls;
namespace ServerManagerTool.Common.ValidationRules
{
public class DateTimeValidationRule : ValidationRule
{
private static readonly DateTime MinUnixDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
private static readonly DateTime MaxUnixDate = new DateTime(2038, 1, 19, 3, 14, 7, 0, DateTimeKind.Utc);
public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
{
string strDateTime = (string)value;
if (strDateTime.IsEmpty())
{
return new ValidationResult(true, null);
}
if (!DateTime.TryParse(strDateTime, out DateTime datetime))
{
return new ValidationResult(false, "Invalid Date. Date must be formatted as yyyy.mm.dd hh:mm:ss");
}
if (datetime.ToUniversalTime() <= MinUnixDate)
{
return new ValidationResult(false, $"Invalid Date. The Date must be after {MinUnixDate.ToLocalTime().ToString("yyyy.MM.dd HH:mm:ss")}");
}
if (datetime.ToUniversalTime() >= MaxUnixDate)
{
return new ValidationResult(false, $"Invalid Date. The Date must be before {MaxUnixDate.ToLocalTime().ToString("yyyy.MM.dd HH:mm:ss")}");
}
return new ValidationResult(true, null);
}
}
}