Ragnarok Settings

- added Ragnarok settings
This commit is contained in:
Brett Hewitson 2022-06-22 15:08:18 +10:00
parent 711cf955c3
commit 87f86036d7
28 changed files with 708 additions and 58 deletions

View file

@ -1553,6 +1553,18 @@
<sys:String x:Key="ServerSettings_HexagonCostMultiplierLabel">Hexagon Cost Multiplier</sys:String>
<sys:String x:Key="ServerSettings_HexagonCostMultiplierTooltip">Specifies the multiplier for the hexagon cost of items.</sys:String>
<sys:String x:Key="ServerSettings_RagnarokLabel">Enable Ragnarok Settings</sys:String>
<sys:String x:Key="ServerSettings_Ragnarok_AllowMultipleTamedUnicornsLabel">Allow Multiple Tamed Unicorns</sys:String>
<sys:String x:Key="ServerSettings_Ragnarok_AllowMultipleTamedUnicornsTooltip">If enabled, will allow one wild and unlimited tamed Unicorns on the map. Otherwise only one unicorn on the map at a time.</sys:String>
<sys:String x:Key="ServerSettings_Ragnarok_UnicornSpawnIntervalLabel">Unicorn Spawn Interval</sys:String>
<sys:String x:Key="ServerSettings_Ragnarok_UnicornSpawnIntervalTooltip">How long the game should wait before spawning a new Unicorn if the wild one is killed (or tamed, if AllowMultipleTamedUnicorns is enabled). This value sets the minimum amount of time (in hours), and the maximum is equal to 2x this value.</sys:String>
<sys:String x:Key="ServerSettings_Ragnarok_EnableVolcanoLabel">Enable Volcano</sys:String>
<sys:String x:Key="ServerSettings_Ragnarok_EnableVolcanoTooltip">If enabled, will allow the volcano to become active.</sys:String>
<sys:String x:Key="ServerSettings_Ragnarok_VolcanoIntervalLabel">Volcano Interval</sys:String>
<sys:String x:Key="ServerSettings_Ragnarok_VolcanoIntervalTooltip">0 = 5000 (min) - 15000 (max) seconds between instances of the volcano becoming active. Any number above 0 acts as a multiplier.</sys:String>
<sys:String x:Key="ServerSettings_Ragnarok_VolcanoIntensityLabel">Volcano Intensity</sys:String>
<sys:String x:Key="ServerSettings_Ragnarok_VolcanoIntensityTooltip">The lower the value, the more intense the volcano's eruption will be. Recommended to leave at 1.0, the minimum value is 0.25, and for multiplayer games, it should not go below 0.5. Very high numbers will basically disable the flaming rocks flung out of the volcano.</sys:String>
<sys:String x:Key="ServerSettings_FjordurLabel">Enable Fjordur Settings</sys:String>
<sys:String x:Key="ServerSettings_UseFjordurTraversalBuffLabel">Enable Fjordur Biome Teleport</sys:String>
<sys:String x:Key="ServerSettings_UseFjordurTraversalBuffTooltip">If enabled, will allow biome teleport on Fjordur map.</sys:String>

View file

@ -10,6 +10,7 @@
GUS_GameSession,
GUS_MultiHome,
GUS_MessageOfTheDay,
GUS_Ragnarok,
// Game.ini
Game_ShooterGameMode,

View file

@ -23,6 +23,7 @@ namespace ServerManagerTool.Lib
{ IniSections.GUS_GameSession, "/Script/Engine.GameSession"},
{ IniSections.GUS_MultiHome, "MultiHome" },
{ IniSections.GUS_MessageOfTheDay, "MessageOfTheDay" },
{ IniSections.GUS_Ragnarok, "Ragnarok" },
// GameUserSettings sections, not used by server manager

View file

@ -1811,22 +1811,69 @@ namespace ServerManagerTool.Lib
set { SetValue(HexagonCostMultiplierProperty, value); }
}
public static readonly DependencyProperty EnableFjordurSettingsProperty = DependencyProperty.Register(nameof(EnableFjordurSettings), typeof(bool), typeof(ServerProfile), new PropertyMetadata(false));
[DataMember]
public bool EnableFjordurSettings
public static readonly DependencyProperty Ragnarok_EnableSettingsProperty = DependencyProperty.Register(nameof(Ragnarok_EnableSettings), typeof(bool), typeof(ServerProfile), new PropertyMetadata(false));
public bool Ragnarok_EnableSettings
{
get { return (bool)GetValue(EnableFjordurSettingsProperty); }
set { SetValue(EnableFjordurSettingsProperty, value); }
get { return (bool)GetValue(Ragnarok_EnableSettingsProperty); }
set { SetValue(Ragnarok_EnableSettingsProperty, value); }
}
public static readonly DependencyProperty Ragnarok_AllowMultipleTamedUnicornsProperty = DependencyProperty.Register(nameof(Ragnarok_AllowMultipleTamedUnicorns), typeof(bool), typeof(ServerProfile), new PropertyMetadata(false));
[IniFileEntry(IniFiles.GameUserSettings, IniSections.GUS_Ragnarok, ServerProfileCategory.Rules, "AllowMultipleTamedUnicorns", ConditionedOn = nameof(Ragnarok_EnableSettings), ClearSectionIfEmpty = true)]
public bool Ragnarok_AllowMultipleTamedUnicorns
{
get { return (bool)GetValue(Ragnarok_AllowMultipleTamedUnicornsProperty); }
set { SetValue(Ragnarok_AllowMultipleTamedUnicornsProperty, value); }
}
public static readonly DependencyProperty Ragnarok_UnicornSpawnIntervalProperty = DependencyProperty.Register(nameof(Ragnarok_UnicornSpawnInterval), typeof(int), typeof(ServerProfile), new PropertyMetadata(24));
[IniFileEntry(IniFiles.GameUserSettings, IniSections.GUS_Ragnarok, ServerProfileCategory.Rules, "UnicornSpawnInterval", ConditionedOn = nameof(Ragnarok_EnableSettings), ClearSectionIfEmpty = true)]
public int Ragnarok_UnicornSpawnInterval
{
get { return (int)GetValue(Ragnarok_UnicornSpawnIntervalProperty); }
set { SetValue(Ragnarok_UnicornSpawnIntervalProperty, value); }
}
public static readonly DependencyProperty Ragnarok_EnableVolcanoProperty = DependencyProperty.Register(nameof(Ragnarok_EnableVolcano), typeof(bool), typeof(ServerProfile), new PropertyMetadata(true));
[IniFileEntry(IniFiles.GameUserSettings, IniSections.GUS_Ragnarok, ServerProfileCategory.Rules, "EnableVolcano", ConditionedOn = nameof(Ragnarok_EnableSettings), ClearSectionIfEmpty = true)]
public bool Ragnarok_EnableVolcano
{
get { return (bool)GetValue(Ragnarok_EnableVolcanoProperty); }
set { SetValue(Ragnarok_EnableVolcanoProperty, value); }
}
public static readonly DependencyProperty Ragnarok_VolcanoIntervalProperty = DependencyProperty.Register(nameof(Ragnarok_VolcanoInterval), typeof(int), typeof(ServerProfile), new PropertyMetadata(0));
[IniFileEntry(IniFiles.GameUserSettings, IniSections.GUS_Ragnarok, ServerProfileCategory.Rules, "VolcanoInterval", ConditionedOn = nameof(Ragnarok_EnableSettings), ClearSectionIfEmpty = true)]
public int Ragnarok_VolcanoInterval
{
get { return (int)GetValue(Ragnarok_VolcanoIntervalProperty); }
set { SetValue(Ragnarok_VolcanoIntervalProperty, value); }
}
public static readonly DependencyProperty Ragnarok_VolcanoIntensityProperty = DependencyProperty.Register(nameof(Ragnarok_VolcanoIntensity), typeof(float), typeof(ServerProfile), new PropertyMetadata(1.0f));
[IniFileEntry(IniFiles.GameUserSettings, IniSections.GUS_Ragnarok, ServerProfileCategory.Rules, "VolcanoIntensity", ConditionedOn = nameof(Ragnarok_EnableSettings), ClearSectionIfEmpty = true)]
public float Ragnarok_VolcanoIntensity
{
get { return (float)GetValue(Ragnarok_VolcanoIntensityProperty); }
set { SetValue(Ragnarok_VolcanoIntensityProperty, value); }
}
public static readonly DependencyProperty Fjordur_EnableSettingsProperty = DependencyProperty.Register(nameof(Fjordur_EnableSettings), typeof(bool), typeof(ServerProfile), new PropertyMetadata(false));
public bool Fjordur_EnableSettings
{
get { return (bool)GetValue(Fjordur_EnableSettingsProperty); }
set { SetValue(Fjordur_EnableSettingsProperty, value); }
}
public static readonly DependencyProperty UseFjordurTraversalBuffProperty = DependencyProperty.Register(nameof(UseFjordurTraversalBuff), typeof(bool), typeof(ServerProfile), new PropertyMetadata(true));
[IniFileEntry(IniFiles.GameUserSettings, IniSections.GUS_ServerSettings, ServerProfileCategory.Rules, ConditionedOn = nameof(EnableFjordurSettings))]
[IniFileEntry(IniFiles.GameUserSettings, IniSections.GUS_ServerSettings, ServerProfileCategory.Rules, ConditionedOn = nameof(Fjordur_EnableSettings))]
public bool UseFjordurTraversalBuff
{
get { return (bool)GetValue(UseFjordurTraversalBuffProperty); }
set { SetValue(UseFjordurTraversalBuffProperty, value); }
}
public bool ClampItemStats
{
get
@ -5677,6 +5724,14 @@ namespace ServerManagerTool.Lib
this.ClearValue(HexagonRewardMultiplierProperty);
this.ClearValue(HexagonCostMultiplierProperty);
this.ClearValue(Ragnarok_EnableSettingsProperty);
this.ClearValue(Ragnarok_AllowMultipleTamedUnicornsProperty);
this.ClearValue(Ragnarok_UnicornSpawnIntervalProperty);
this.ClearValue(Ragnarok_EnableVolcanoProperty);
this.ClearValue(Ragnarok_VolcanoIntervalProperty);
this.ClearValue(Ragnarok_VolcanoIntensityProperty);
this.ClearValue(Fjordur_EnableSettingsProperty);
this.ClearValue(UseFjordurTraversalBuffProperty);
this.ClearNullableValue(ItemStatClamps_GenericQualityProperty);
@ -6395,6 +6450,14 @@ namespace ServerManagerTool.Lib
this.SetValue(HexagonRewardMultiplierProperty, sourceProfile.HexagonRewardMultiplier);
this.SetValue(HexagonCostMultiplierProperty, sourceProfile.HexagonCostMultiplier);
this.SetValue(Ragnarok_EnableSettingsProperty, sourceProfile.Ragnarok_EnableSettings);
this.SetValue(Ragnarok_AllowMultipleTamedUnicornsProperty, sourceProfile.Ragnarok_AllowMultipleTamedUnicorns);
this.SetValue(Ragnarok_UnicornSpawnIntervalProperty, sourceProfile.Ragnarok_UnicornSpawnInterval);
this.SetValue(Ragnarok_EnableVolcanoProperty, sourceProfile.Ragnarok_EnableVolcano);
this.SetValue(Ragnarok_VolcanoIntervalProperty, sourceProfile.Ragnarok_VolcanoInterval);
this.SetValue(Ragnarok_VolcanoIntensityProperty, sourceProfile.Ragnarok_VolcanoIntensity);
this.SetValue(Fjordur_EnableSettingsProperty, sourceProfile.Fjordur_EnableSettings);
this.SetValue(UseFjordurTraversalBuffProperty, sourceProfile.UseFjordurTraversalBuff);
this.SetNullableValue(ItemStatClamps_GenericQualityProperty, sourceProfile.ItemStatClamps_GenericQuality);

View file

@ -2151,10 +2151,62 @@
<GroupBox Style="{StaticResource GroupBoxStyle}">
<GroupBox.Header>
<cctl:CheckBoxAndTextBlock IsChecked="{Binding EnableFjordurSettings, Mode=TwoWay}" Text="{DynamicResource ServerSettings_FjordurLabel}" />
<cctl:CheckBoxAndTextBlock IsChecked="{Binding Ragnarok_EnableSettings, Mode=TwoWay}" Text="{DynamicResource ServerSettings_RagnarokLabel}" />
</GroupBox.Header>
<Grid IsEnabled="{Binding EnableFjordurSettings}">
<Grid IsEnabled="{Binding Ragnarok_EnableSettings}">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<cctl:CheckBoxAndTextBlock Grid.Row="0" Grid.Column="0" Margin="5,5,5,0" HorizontalAlignment="Left"
IsChecked="{Binding Ragnarok_AllowMultipleTamedUnicorns, Mode=TwoWay}"
Text="{DynamicResource ServerSettings_Ragnarok_AllowMultipleTamedUnicornsLabel}"
ToolTip="{DynamicResource ServerSettings_Ragnarok_AllowMultipleTamedUnicornsTooltip}"/>
<cctl:AnnotatedIntSlider Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Margin="5,5,5,0"
Minimum="1" Maximum="48" SmallChange="1" LargeChange="1" TickFrequency="6"
Label="{DynamicResource ServerSettings_Ragnarok_UnicornSpawnIntervalLabel}"
Value="{Binding Ragnarok_UnicornSpawnInterval, Converter={cc:IntRangeValueConverter 1, 48}}"
Suffix="{DynamicResource SliderUnits_Hours}"
ToolTip="{DynamicResource ServerSettings_Ragnarok_UnicornSpawnIntervalTooltip}"/>
<cctl:CheckBoxAndTextBlock Grid.Row="2" Grid.Column="0" Margin="5,5,5,0" HorizontalAlignment="Left"
IsChecked="{Binding Ragnarok_EnableVolcano, Mode=TwoWay}"
Text="{DynamicResource ServerSettings_Ragnarok_EnableVolcanoLabel}"
ToolTip="{DynamicResource ServerSettings_Ragnarok_EnableVolcanoTooltip}"/>
<cctl:AnnotatedIntSlider Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3" Margin="5,5,5,0" IsEnabled="{Binding Ragnarok_EnableVolcano}"
Minimum="0" Maximum="10" SmallChange="1" LargeChange="1" TickFrequency="1"
Label="{DynamicResource ServerSettings_Ragnarok_VolcanoIntervalLabel}"
Value="{Binding Ragnarok_VolcanoInterval, Converter={cc:IntRangeValueConverter 0, 100}}"
Suffix="{DynamicResource SliderUnits_Multiplier}"
ToolTip="{DynamicResource ServerSettings_Ragnarok_VolcanoIntervalTooltip}"/>
<cctl:AnnotatedSlider Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="3" Margin="5,5,5,0" IsEnabled="{Binding Ragnarok_EnableVolcano}"
Minimum="0.25" Maximum="10" SmallChange="0.1" LargeChange="1" TickFrequency="1"
Label="{DynamicResource ServerSettings_Ragnarok_VolcanoIntensityLabel}"
Value="{Binding Ragnarok_VolcanoIntensity, Converter={cc:FloatRangeValueConverter 0.25, 10.0}}"
Suffix="{DynamicResource SliderUnits_Multiplier}"
ToolTip="{DynamicResource ServerSettings_Ragnarok_VolcanoIntensityTooltip}"/>
</Grid>
</GroupBox>
<GroupBox Style="{StaticResource GroupBoxStyle}">
<GroupBox.Header>
<cctl:CheckBoxAndTextBlock IsChecked="{Binding Fjordur_EnableSettings, Mode=TwoWay}" Text="{DynamicResource ServerSettings_FjordurLabel}" />
</GroupBox.Header>
<Grid IsEnabled="{Binding Fjordur_EnableSettings}">
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>

View file

@ -19,7 +19,8 @@
<u style="font-size: .9em;">CHANGE</u>
<br/>
<ul>
<li>Fjordur Settings - added checkbox to enable/disable settings.</li>
<li>Rules Section - Fjordur Settings - added checkbox to enable/disable settings.</li>
<li>Rules Section - Ragnarok Settings - added settings for Ragnarok, located at the bottom of the section.</li>
</ul>
</p>
</div>

View file

@ -67,6 +67,12 @@ namespace ServerManagerTool.Common.Attibutes
/// </summary>
public bool ClearSection;
/// <summary>
/// Clear the section after processing this value and the section is empty.
/// NOTE: DO NOT USE this setting for the standard setting sections, only use for custom sections or mod sections.
/// </summary>
public bool ClearSectionIfEmpty;
/// <summary>
/// If true, the value will always be written with quotes, if remove, the value will always be written without quotes even if added.
/// </summary>

View file

@ -0,0 +1,292 @@
<UserControl x:Class="ServerManagerTool.Common.Controls.AnnotatedIntSlider"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignWidth="300"
d:DesignHeight="25"
x:Name="Control">
<UserControl.Resources>
<ResourceDictionary>
<SolidColorBrush x:Key="SliderThumb.Static.Foreground" Color="#FFE5E5E5"/>
<SolidColorBrush x:Key="SliderThumb.MouseOver.Background" Color="#FFDCECFC"/>
<SolidColorBrush x:Key="SliderThumb.MouseOver.Border" Color="#FF7Eb4EA"/>
<SolidColorBrush x:Key="SliderThumb.Pressed.Background" Color="#FFDAECFC"/>
<SolidColorBrush x:Key="SliderThumb.Pressed.Border" Color="#FF569DE5"/>
<SolidColorBrush x:Key="SliderThumb.Disabled.Background" Color="#FFF0F0F0"/>
<SolidColorBrush x:Key="SliderThumb.Disabled.Border" Color="#FFD9D9D9"/>
<SolidColorBrush x:Key="SliderThumb.Static.Background" Color="#FFF0F0F0"/>
<SolidColorBrush x:Key="SliderThumb.Static.Border" Color="#FFACACAC"/>
<SolidColorBrush x:Key="SliderThumb.Track.Border" Color="#FFD6D6D6"/>
<SolidColorBrush x:Key="SliderThumb.Track.BorderBackground" Color="#FFE7EAEA"/>
<SolidColorBrush x:Key="SliderThumb.Grip.Fill" Color="#FFE6DFD8"/>
<SolidColorBrush x:Key="SliderThumb.Tick.Bottom" Color="#FFD8CCBC"/>
<SolidColorBrush x:Key="SliderThumb.Track.Background" Color="#FFBFA786"/>
<ControlTemplate x:Key="SliderThumbHorizontalTop" TargetType="{x:Type Thumb}">
<Grid HorizontalAlignment="Center" UseLayoutRounding="True" VerticalAlignment="Center">
<Path x:Name="grip" Data="M 0,6 C0,6 5.5,0 5.5,0 5.5,0 11,6 11,6 11,6 11,18 11,18 11,18 0,18 0,18 0,18 0,6 0,6 z" Fill="{StaticResource SliderThumb.Static.Background}" Stretch="Fill" SnapsToDevicePixels="True" Stroke="{StaticResource SliderThumb.Static.Border}" StrokeThickness="1" UseLayoutRounding="True" VerticalAlignment="Center"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.MouseOver.Background}"/>
<Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.MouseOver.Border}"/>
</Trigger>
<Trigger Property="IsDragging" Value="true">
<Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.Pressed.Background}"/>
<Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.Pressed.Border}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.Disabled.Background}"/>
<Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.Disabled.Border}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="SliderThumbHorizontalBottom" TargetType="{x:Type Thumb}">
<Grid HorizontalAlignment="Center" UseLayoutRounding="True" VerticalAlignment="Center">
<Path x:Name="grip" Data="M 0,12 C0,12 5.5,18 5.5,18 5.5,18 11,12 11,12 11,12 11,0 11,0 11,0 0,0 0,0 0,0 0,12 0,12 z" Fill="{StaticResource SliderThumb.Static.Background}" Stretch="Fill" SnapsToDevicePixels="True" Stroke="{StaticResource SliderThumb.Static.Border}" StrokeThickness="1" UseLayoutRounding="True" VerticalAlignment="Center"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.MouseOver.Background}"/>
<Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.MouseOver.Border}"/>
</Trigger>
<Trigger Property="IsDragging" Value="true">
<Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.Pressed.Background}"/>
<Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.Pressed.Border}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.Disabled.Background}"/>
<Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.Disabled.Border}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<Style x:Key="RepeatButtonTransparent" TargetType="{x:Type RepeatButton}">
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Focusable" Value="false"/>
<Setter Property="IsTabStop" Value="false"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RepeatButton}">
<Rectangle Fill="{TemplateBinding Background}" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<ControlTemplate x:Key="SliderThumbHorizontalDefault" TargetType="{x:Type Thumb}">
<Grid HorizontalAlignment="Center" UseLayoutRounding="True" VerticalAlignment="Center">
<Path x:Name="grip" Data="M 0,0 C0,0 11,0 11,0 11,0 11,18 11,18 11,18 0,18 0,18 0,18 0,0 0,0 z" Fill="{DynamicResource SliderThumb.Grip.Fill}" Stretch="Fill" SnapsToDevicePixels="True" Stroke="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" StrokeThickness="1" UseLayoutRounding="True" VerticalAlignment="Center"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.MouseOver.Background}"/>
<Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.MouseOver.Border}"/>
</Trigger>
<Trigger Property="IsDragging" Value="true">
<Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.Pressed.Background}"/>
<Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.Pressed.Border}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.Disabled.Background}"/>
<Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.Disabled.Border}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="SliderHorizontal" TargetType="{x:Type Slider}">
<Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto" MinHeight="{TemplateBinding MinHeight}"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TickBar x:Name="TopTick" Fill="{TemplateBinding Foreground}" Height="4" Margin="0,0,0,2" Placement="Top" Grid.Row="0" Visibility="Collapsed"/>
<TickBar x:Name="BottomTick" Fill="{DynamicResource SliderThumb.Tick.Bottom}" Height="4" Margin="0,2,0,0" Placement="Bottom" Grid.Row="2" Visibility="Collapsed"/>
<Border x:Name="TrackBackground" BorderBrush="{StaticResource SliderThumb.Track.Border}" BorderThickness="1" Background="{StaticResource SliderThumb.Track.BorderBackground}" Height="4.0" Margin="5,0" Grid.Row="1" VerticalAlignment="center">
<Canvas Margin="-6,-1" Background="{DynamicResource SliderThumb.Track.Background}">
<Rectangle x:Name="PART_SelectionRange" Fill="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" Height="4.0" Visibility="Hidden"/>
</Canvas>
</Border>
<Track x:Name="PART_Track" Grid.Row="1">
<Track.DecreaseRepeatButton>
<RepeatButton Command="{x:Static Slider.DecreaseLarge}" Style="{StaticResource RepeatButtonTransparent}"/>
</Track.DecreaseRepeatButton>
<Track.IncreaseRepeatButton>
<RepeatButton Command="{x:Static Slider.IncreaseLarge}" Style="{StaticResource RepeatButtonTransparent}"/>
</Track.IncreaseRepeatButton>
<Track.Thumb>
<Thumb x:Name="Thumb" Focusable="False" Height="18" OverridesDefaultStyle="True" Template="{StaticResource SliderThumbHorizontalDefault}" VerticalAlignment="Center" Width="11" Foreground="#FFBFA786"/>
</Track.Thumb>
</Track>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="TickPlacement" Value="TopLeft">
<Setter Property="Visibility" TargetName="TopTick" Value="Visible"/>
<Setter Property="Template" TargetName="Thumb" Value="{StaticResource SliderThumbHorizontalTop}"/>
<Setter Property="Margin" TargetName="TrackBackground" Value="5,2,5,0"/>
</Trigger>
<Trigger Property="TickPlacement" Value="BottomRight">
<Setter Property="Visibility" TargetName="BottomTick" Value="Visible"/>
<Setter Property="Template" TargetName="Thumb" Value="{StaticResource SliderThumbHorizontalBottom}"/>
<Setter Property="Margin" TargetName="TrackBackground" Value="5,0,5,2"/>
</Trigger>
<Trigger Property="TickPlacement" Value="Both">
<Setter Property="Visibility" TargetName="TopTick" Value="Visible"/>
<Setter Property="Visibility" TargetName="BottomTick" Value="Visible"/>
</Trigger>
<Trigger Property="IsSelectionRangeEnabled" Value="true">
<Setter Property="Visibility" TargetName="PART_SelectionRange" Value="Visible"/>
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="true">
<Setter Property="Foreground" TargetName="Thumb" Value="Blue"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="SliderThumbVerticalLeft" TargetType="{x:Type Thumb}">
<Grid HorizontalAlignment="Center" UseLayoutRounding="True" VerticalAlignment="Center">
<Path x:Name="grip" Data="M 6,11 C6,11 0,5.5 0,5.5 0,5.5 6,0 6,0 6,0 18,0 18,0 18,0 18,11 18,11 18,11 6,11 6,11 z" Fill="{StaticResource SliderThumb.Static.Background}" Stretch="Fill" Stroke="{StaticResource SliderThumb.Static.Border}"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.MouseOver.Background}"/>
<Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.MouseOver.Border}"/>
</Trigger>
<Trigger Property="IsDragging" Value="true">
<Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.Pressed.Background}"/>
<Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.Pressed.Border}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.Disabled.Background}"/>
<Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.Disabled.Border}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="SliderThumbVerticalRight" TargetType="{x:Type Thumb}">
<Grid HorizontalAlignment="Center" UseLayoutRounding="True" VerticalAlignment="Center">
<Path x:Name="grip" Data="M 12,11 C12,11 18,5.5 18,5.5 18,5.5 12,0 12,0 12,0 0,0 0,0 0,0 0,11 0,11 0,11 12,11 12,11 z" Fill="{StaticResource SliderThumb.Static.Background}" Stretch="Fill" Stroke="{StaticResource SliderThumb.Static.Border}"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.MouseOver.Background}"/>
<Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.MouseOver.Border}"/>
</Trigger>
<Trigger Property="IsDragging" Value="true">
<Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.Pressed.Background}"/>
<Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.Pressed.Border}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.Disabled.Background}"/>
<Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.Disabled.Border}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="SliderThumbVerticalDefault" TargetType="{x:Type Thumb}">
<Grid HorizontalAlignment="Center" UseLayoutRounding="True" VerticalAlignment="Center">
<Path x:Name="grip" Data="M0.5,0.5 L18.5,0.5 18.5,11.5 0.5,11.5z" Fill="{StaticResource SliderThumb.Static.Background}" Stretch="Fill" Stroke="{StaticResource SliderThumb.Static.Border}"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.MouseOver.Background}"/>
<Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.MouseOver.Border}"/>
</Trigger>
<Trigger Property="IsDragging" Value="true">
<Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.Pressed.Background}"/>
<Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.Pressed.Border}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Fill" TargetName="grip" Value="{StaticResource SliderThumb.Disabled.Background}"/>
<Setter Property="Stroke" TargetName="grip" Value="{StaticResource SliderThumb.Disabled.Border}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="SliderVertical" TargetType="{x:Type Slider}">
<Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition MinWidth="{TemplateBinding MinWidth}" Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TickBar x:Name="TopTick" Grid.Column="0" Fill="{TemplateBinding Foreground}" Margin="0,0,2,0" Placement="Left" Visibility="Collapsed" Width="4"/>
<TickBar x:Name="BottomTick" Grid.Column="2" Fill="{TemplateBinding Foreground}" Margin="2,0,0,0" Placement="Right" Visibility="Collapsed" Width="4"/>
<Border x:Name="TrackBackground" BorderBrush="{StaticResource SliderThumb.Track.Border}" BorderThickness="1" Background="{StaticResource SliderThumb.Track.BorderBackground}" Grid.Column="1" HorizontalAlignment="center" Margin="0,5" Width="4.0">
<Canvas Margin="-1,-6">
<Rectangle x:Name="PART_SelectionRange" Fill="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" Visibility="Hidden" Width="4.0"/>
</Canvas>
</Border>
<Track x:Name="PART_Track" Grid.Column="1">
<Track.DecreaseRepeatButton>
<RepeatButton Command="{x:Static Slider.DecreaseLarge}" Style="{StaticResource RepeatButtonTransparent}"/>
</Track.DecreaseRepeatButton>
<Track.IncreaseRepeatButton>
<RepeatButton Command="{x:Static Slider.IncreaseLarge}" Style="{StaticResource RepeatButtonTransparent}"/>
</Track.IncreaseRepeatButton>
<Track.Thumb>
<Thumb x:Name="Thumb" Focusable="False" Height="11" OverridesDefaultStyle="True" Template="{StaticResource SliderThumbVerticalDefault}" VerticalAlignment="Top" Width="18"/>
</Track.Thumb>
</Track>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="TickPlacement" Value="TopLeft">
<Setter Property="Visibility" TargetName="TopTick" Value="Visible"/>
<Setter Property="Template" TargetName="Thumb" Value="{StaticResource SliderThumbVerticalLeft}"/>
<Setter Property="Margin" TargetName="TrackBackground" Value="2,5,0,5"/>
</Trigger>
<Trigger Property="TickPlacement" Value="BottomRight">
<Setter Property="Visibility" TargetName="BottomTick" Value="Visible"/>
<Setter Property="Template" TargetName="Thumb" Value="{StaticResource SliderThumbVerticalRight}"/>
<Setter Property="Margin" TargetName="TrackBackground" Value="0,5,2,5"/>
</Trigger>
<Trigger Property="TickPlacement" Value="Both">
<Setter Property="Visibility" TargetName="TopTick" Value="Visible"/>
<Setter Property="Visibility" TargetName="BottomTick" Value="Visible"/>
</Trigger>
<Trigger Property="IsSelectionRangeEnabled" Value="true">
<Setter Property="Visibility" TargetName="PART_SelectionRange" Value="Visible"/>
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="true">
<Setter Property="Foreground" TargetName="Thumb" Value="Blue"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<Style x:Key="AnnotatedSliderStyle" TargetType="{x:Type Slider}">
<Setter Property="Stylus.IsPressAndHoldEnabled" Value="false"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Foreground" Value="{StaticResource SliderThumb.Static.Foreground}"/>
<Setter Property="Template" Value="{StaticResource SliderHorizontal}"/>
<Style.Triggers>
<Trigger Property="Orientation" Value="Vertical">
<Setter Property="Template" Value="{StaticResource SliderVertical}"/>
</Trigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{Binding LabelRelativeWidth}" MinWidth="{Binding LabelRelativeMinWidth}"/>
<ColumnDefinition Width="{Binding SliderRelativeWidth}" MinWidth="{Binding SliderRelativeMinWidth}"/>
<ColumnDefinition Width="{Binding ValueRelativeWidth}" MinWidth="{Binding ValueRelativeMinWidth}"/>
<ColumnDefinition Width="{Binding SuffixRelativeWidth}" MinWidth="{Binding SuffixRelativeMinWidth}"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Content="{Binding Label}" VerticalContentAlignment="Center"/>
<Slider x:Name="Slider" Grid.Column="1" Value="{Binding Value, Mode=OneWay}" Margin="0,0,5,0"
Minimum="{Binding Minimum}"
Maximum="{Binding Maximum}"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
HorizontalContentAlignment="Stretch"
LargeChange="{Binding LargeChange}"
SmallChange="{Binding SmallChange}"
TickFrequency="{Binding TickFrequency}" Style="{DynamicResource AnnotatedSliderStyle}"
ValueChanged="Slider_ValueChanged"/>
<TextBox x:Name="Text" Grid.Column="2" Text="{Binding Value, Mode=TwoWay, StringFormat={}{0:#######,##0}}" VerticalContentAlignment="Center" MinHeight="{Binding ValueRelativeMinHeight}"/>
<Label Grid.Column="3" Content="{Binding Suffix}" VerticalContentAlignment="Center" />
</Grid>
</UserControl>

View file

@ -0,0 +1,156 @@
using System.Windows;
using System.Windows.Controls;
namespace ServerManagerTool.Common.Controls
{
/// <summary>
/// Interaction logic for AnnotatedSlider.xaml
/// </summary>
public partial class AnnotatedIntSlider : UserControl
{
public static readonly DependencyProperty LabelProperty = DependencyProperty.Register(nameof(Label), typeof(string), typeof(AnnotatedIntSlider));
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(nameof(Value), typeof(int), typeof(AnnotatedIntSlider), new FrameworkPropertyMetadata(default(int), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public static readonly DependencyProperty SuffixProperty = DependencyProperty.Register(nameof(Suffix), typeof(string), typeof(AnnotatedIntSlider));
public static readonly DependencyProperty MinimumProperty = DependencyProperty.Register(nameof(Minimum), typeof(int), typeof(AnnotatedIntSlider));
public static readonly DependencyProperty MaximumProperty = DependencyProperty.Register(nameof(Maximum), typeof(int), typeof(AnnotatedIntSlider));
public static readonly DependencyProperty LargeChangeProperty = DependencyProperty.Register(nameof(LargeChange), typeof(int), typeof(AnnotatedIntSlider));
public static readonly DependencyProperty SmallChangeProperty = DependencyProperty.Register(nameof(SmallChange), typeof(int), typeof(AnnotatedIntSlider));
public static readonly DependencyProperty TickFrequencyProperty = DependencyProperty.Register(nameof(TickFrequency), typeof(int), typeof(AnnotatedIntSlider));
public static readonly DependencyProperty LabelRelativeWidthProperty = DependencyProperty.Register(nameof(LabelRelativeWidth), typeof(string), typeof(AnnotatedIntSlider), new PropertyMetadata("4*"));
public static readonly DependencyProperty LabelRelativeMinWidthProperty = DependencyProperty.Register(nameof(LabelRelativeMinWidth), typeof(string), typeof(AnnotatedIntSlider), new PropertyMetadata("0"));
public static readonly DependencyProperty SliderRelativeWidthProperty = DependencyProperty.Register(nameof(SliderRelativeWidth), typeof(string), typeof(AnnotatedIntSlider), new PropertyMetadata("8*"));
public static readonly DependencyProperty SliderRelativeMinWidthProperty = DependencyProperty.Register(nameof(SliderRelativeMinWidth), typeof(string), typeof(AnnotatedIntSlider), new PropertyMetadata("0"));
public static readonly DependencyProperty ValueRelativeWidthProperty = DependencyProperty.Register(nameof(ValueRelativeWidth), typeof(string), typeof(AnnotatedIntSlider), new PropertyMetadata("2*"));
public static readonly DependencyProperty ValueRelativeMinWidthProperty = DependencyProperty.Register(nameof(ValueRelativeMinWidth), typeof(string), typeof(AnnotatedIntSlider), new PropertyMetadata("50"));
public static readonly DependencyProperty ValueRelativeMinHeightProperty = DependencyProperty.Register(nameof(ValueRelativeMinHeight), typeof(string), typeof(AnnotatedIntSlider), new PropertyMetadata("25"));
public static readonly DependencyProperty SuffixRelativeWidthProperty = DependencyProperty.Register(nameof(SuffixRelativeWidth), typeof(string), typeof(AnnotatedIntSlider), new PropertyMetadata("1*"));
public static readonly DependencyProperty SuffixRelativeMinWidthProperty = DependencyProperty.Register(nameof(SuffixRelativeMinWidth), typeof(string), typeof(AnnotatedIntSlider), new PropertyMetadata("0"));
public AnnotatedIntSlider()
{
InitializeComponent();
this.Focusable = true;
(this.Content as FrameworkElement).DataContext = this;
}
public string Label
{
get { return (string)GetValue(LabelProperty); }
set { SetValue(LabelProperty, value); }
}
public int Value
{
get { return (int)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}
public string Suffix
{
get { return (string)GetValue(SuffixProperty); }
set { SetValue(SuffixProperty, value); }
}
public int Minimum
{
get { return (int)GetValue(MinimumProperty); }
set { SetValue(MinimumProperty, value); }
}
public int Maximum
{
get { return (int)GetValue(MaximumProperty); }
set { SetValue(MaximumProperty, value); }
}
public int LargeChange
{
get { return (int)GetValue(LargeChangeProperty); }
set { SetValue(LargeChangeProperty, value); }
}
public int SmallChange
{
get { return (int)GetValue(SmallChangeProperty); }
set { SetValue(SmallChangeProperty, value); }
}
public int TickFrequency
{
get { return (int)GetValue(TickFrequencyProperty); }
set { SetValue(TickFrequencyProperty, value); }
}
public string LabelRelativeWidth
{
get { return (string)GetValue(LabelRelativeWidthProperty); }
set { SetValue(LabelRelativeWidthProperty, value); }
}
public string LabelRelativeMinWidth
{
get { return (string)GetValue(LabelRelativeMinWidthProperty); }
set { SetValue(LabelRelativeMinWidthProperty, value); }
}
public string SliderRelativeWidth
{
get { return (string)GetValue(SliderRelativeWidthProperty); }
set { SetValue(SliderRelativeWidthProperty, value); }
}
public string SliderRelativeMinWidth
{
get { return (string)GetValue(SliderRelativeMinWidthProperty); }
set { SetValue(SliderRelativeMinWidthProperty, value); }
}
public string ValueRelativeWidth
{
get { return (string)GetValue(ValueRelativeWidthProperty); }
set { SetValue(ValueRelativeWidthProperty, value); }
}
public string ValueRelativeMinWidth
{
get { return (string)GetValue(ValueRelativeMinWidthProperty); }
set { SetValue(ValueRelativeMinWidthProperty, value); }
}
public string ValueRelativeMinHeight
{
get { return (string)GetValue(ValueRelativeMinHeightProperty); }
set { SetValue(ValueRelativeMinHeightProperty, value); }
}
public string SuffixRelativeWidth
{
get { return (string)GetValue(SuffixRelativeWidthProperty); }
set { SetValue(SuffixRelativeWidthProperty, value); }
}
public string SuffixRelativeMinWidth
{
get { return (string)GetValue(SuffixRelativeMinWidthProperty); }
set { SetValue(SuffixRelativeMinWidthProperty, value); }
}
private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (Slider.IsFocused)
{
unchecked
{
Value = (int)e.NewValue;
}
}
}
public new bool Focus()
{
return Slider.Focus();
}
}
}

View file

@ -30,7 +30,7 @@ namespace ServerManagerTool.Common.Converters
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
double scaledValue = System.Convert.ToDouble(value);
var scaledValue = System.Convert.ToDouble(value);
var sliderValue = scaledValue;
sliderValue = Math.Max(MinValue, sliderValue);

View file

@ -11,8 +11,8 @@ namespace ServerManagerTool.Common.Converters
if (value == null || parameter == null)
return false;
string checkValue = value.ToString();
string targetValue = parameter.ToString();
var checkValue = value.ToString();
var targetValue = parameter.ToString();
return checkValue.Equals(targetValue, StringComparison.InvariantCultureIgnoreCase);
}
@ -21,8 +21,8 @@ namespace ServerManagerTool.Common.Converters
if (value == null || parameter == null)
return null;
bool useValue = (bool)value;
string targetValue = parameter.ToString();
var useValue = System.Convert.ToBoolean(value);
var targetValue = parameter.ToString();
if (useValue)
return Enum.Parse(targetType, targetValue);

View file

@ -4,11 +4,9 @@ using System.Windows.Data;
namespace ServerManagerTool.Common.Converters
{
public class EnumFlagsConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null || parameter == null)
return false;
@ -18,8 +16,7 @@ namespace ServerManagerTool.Common.Converters
return (flagsValue & targetFlagValue) == targetFlagValue;
}
public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException("Cannot convert flags value back");
}

View file

@ -0,0 +1,62 @@
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Markup;
namespace ServerManagerTool.Common.Converters
{
public class FloatRangeValueConverter : MarkupExtension, IValueConverter
{
public const string DEFAULT_CULTURE_CODE = "en-US";
protected float MinValue { get; set; }
protected float MaxValue { get; set; }
public FloatRangeValueConverter()
{
MinValue = float.MinValue;
MaxValue = float.MaxValue;
}
public FloatRangeValueConverter(float minValue)
{
MinValue = minValue;
MaxValue = float.MaxValue;
}
public FloatRangeValueConverter(float minValue, float maxValue)
{
MinValue = minValue;
MaxValue = maxValue;
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var scaledValue = System.Convert.ToSingle(value);
var sliderValue = scaledValue;
sliderValue = Math.Max(MinValue, sliderValue);
sliderValue = Math.Min(MaxValue, sliderValue);
return sliderValue;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is null || value.ToString() == string.Empty)
return default;
if (!float.TryParse(value.ToString(), NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.GetCultureInfo(DEFAULT_CULTURE_CODE), out float sliderValue))
return default;
sliderValue = Math.Max(MinValue, sliderValue);
sliderValue = Math.Min(MaxValue, sliderValue);
var scaledValue = sliderValue;
return scaledValue;
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return this;
}
}
}

View file

@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace ServerManagerTool.Common.Converters
@ -12,13 +8,13 @@ namespace ServerManagerTool.Common.Converters
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if(value == null)
if (value == null)
{
return false;
}
var strValue = value as string;
if(String.IsNullOrWhiteSpace(strValue))
if (string.IsNullOrWhiteSpace(strValue))
{
return false;
}

View file

@ -7,6 +7,7 @@ namespace ServerManagerTool.Common.Converters
{
public class IntRangeValueConverter : MarkupExtension, IValueConverter
{
public const string DEFAULT_CULTURE_CODE = "en-US";
protected int MinValue { get; set; }
protected int MaxValue { get; set; }
@ -30,7 +31,7 @@ namespace ServerManagerTool.Common.Converters
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
double scaledValue = System.Convert.ToInt32(value);
var scaledValue = System.Convert.ToInt32(value);
var sliderValue = scaledValue;
sliderValue = Math.Max(MinValue, sliderValue);
@ -43,7 +44,7 @@ namespace ServerManagerTool.Common.Converters
if (value is null || value.ToString() == string.Empty)
return default;
if (!int.TryParse(value.ToString(), out int sliderValue))
if (!int.TryParse(value.ToString(), NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.GetCultureInfo(DEFAULT_CULTURE_CODE), out int sliderValue))
return default;
sliderValue = Math.Max(MinValue, sliderValue);

View file

@ -9,7 +9,7 @@ namespace ServerManagerTool.Common.Converters
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
double scaledValue = System.Convert.ToInt32(value);
var scaledValue = System.Convert.ToInt32(value);
return scaledValue == 0 ? Visibility.Collapsed : Visibility.Visible;
}

View file

@ -9,7 +9,7 @@ namespace ServerManagerTool.Common.Converters
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool flag = false;
var flag = false;
if (value is bool)
{
flag = (bool)value;

View file

@ -9,7 +9,7 @@ namespace ServerManagerTool.Common.Converters
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
double scaledValue = System.Convert.ToInt32(value);
var scaledValue = System.Convert.ToInt32(value);
return scaledValue == 0 ? Visibility.Visible : Visibility.Collapsed;
}

View file

@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace ServerManagerTool.Common.Converters
@ -12,13 +8,13 @@ namespace ServerManagerTool.Common.Converters
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if(value == null)
if (value == null)
{
return true;
}
var strValue = value as string;
if(String.IsNullOrWhiteSpace(strValue))
if (string.IsNullOrWhiteSpace(strValue))
{
return true;
}

View file

@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace ServerManagerTool.Common.Converters

View file

@ -27,11 +27,8 @@ namespace ServerManagerTool.Common.Converters
return 0;
}
int hours;
Int32.TryParse(split[0], out hours);
int minutes;
Int32.TryParse(split[1], out minutes);
int.TryParse(split[0], out int hours);
int.TryParse(split[1], out int minutes);
return hours * 60 + minutes;
}

View file

@ -11,7 +11,7 @@ namespace ServerManagerTool.Common.Converters
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
double scaledValue = System.Convert.ToInt32(value);
var scaledValue = System.Convert.ToInt32(value);
var sliderValue = (int)TimeSpan.FromSeconds(scaledValue).TotalHours;
sliderValue = Math.Max(MIN_VALUE, sliderValue);

View file

@ -11,7 +11,7 @@ namespace ServerManagerTool.Common.Converters
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
double scaledValue = System.Convert.ToInt32(value);
var scaledValue = System.Convert.ToInt32(value);
var sliderValue = (int)TimeSpan.FromSeconds(scaledValue).TotalMinutes;
sliderValue = Math.Max(MIN_VALUE, sliderValue);

View file

@ -8,26 +8,23 @@ namespace ServerManagerTool.Common.Converters
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
// Value is seconds since midnight.
var seconds = (int)value;
var seconds = System.Convert.ToInt32(value);
var hours = Math.Min(Math.Max(seconds / 3600, 0), 23);
var minutes = Math.Min(Math.Max((seconds % 3600) / 60, 0), 59);
return String.Format("{0:00}:{1:00}", hours, minutes);
return string.Format("{0:00}:{1:00}", hours, minutes);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var strTime = (string)value;
var split = strTime.Split(':');
if(split.Length != 2)
if (split.Length != 2)
{
return 0;
}
int hours;
Int32.TryParse(split[0], out hours);
int minutes;
Int32.TryParse(split[1], out minutes);
int.TryParse(split[0], out int hours);
int.TryParse(split[1], out int minutes);
return hours * 3600 + minutes * 60;
}

View file

@ -9,7 +9,7 @@ namespace ServerManagerTool.Common.Converters
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
int unixTimestamp = (int)value;
var unixTimestamp = System.Convert.ToInt32(value);
return DateTimeUtils.UnixTimeStampToDateTime(unixTimestamp).ToString(culture);
}

View file

@ -218,6 +218,7 @@ namespace ServerManagerTool.Common.Serialization
if (attr.ClearSection)
{
WriteValue(iniFiles, attr.File, attr.Section, null, null);
ClearSectionIfEmpty(iniFiles, attr);
}
//
@ -240,6 +241,7 @@ namespace ServerManagerTool.Common.Serialization
{
// The condition value was not set to true, so clear this attribute instead of writing it
WriteValue(iniFiles, attr.File, attr.Section, keyName, null);
ClearSectionIfEmpty(iniFiles, attr);
continue;
}
}
@ -252,6 +254,7 @@ namespace ServerManagerTool.Common.Serialization
{
// The attributed value was set to false, so clear this attribute instead of writing it
WriteValue(iniFiles, attr.File, attr.Section, keyName, null);
ClearSectionIfEmpty(iniFiles, attr);
}
continue;
}
@ -325,6 +328,7 @@ namespace ServerManagerTool.Common.Serialization
{
// The attributed value does not have a value, so clear this attribute instead of writing it.
WriteValue(iniFiles, attr.File, attr.Section, keyName, null);
ClearSectionIfEmpty(iniFiles, attr);
continue;
}
@ -338,6 +342,7 @@ namespace ServerManagerTool.Common.Serialization
{
// The attributed value is the same as the specified value, so clear this attribute instead of writing it.
WriteValue(iniFiles, attr.File, attr.Section, keyName, null);
ClearSectionIfEmpty(iniFiles, attr);
continue;
}
}
@ -369,6 +374,8 @@ namespace ServerManagerTool.Common.Serialization
}
}
}
ClearSectionIfEmpty(iniFiles, attr);
}
catch (Exception)
{
@ -380,6 +387,19 @@ namespace ServerManagerTool.Common.Serialization
SaveFiles(iniFiles);
}
private void ClearSectionIfEmpty(Dictionary<string, IniFile> iniFiles, BaseIniFileEntryAttribute attr)
{
if (attr.ClearSectionIfEmpty)
{
var section = ReadSection(iniFiles, attr.File, attr.Section);
var hasKeys = section?.Any() ?? false;
if (!hasKeys)
{
WriteValue(iniFiles, attr.File, attr.Section, null, null);
}
}
}
public IEnumerable<string> ReadSection(Enum iniFile, Enum section)
{
return ReadSection(iniFile, SectionNames[section]);

View file

@ -13,6 +13,7 @@
</PropertyGroup>
<ItemGroup>
<None Remove="Controls\AnnotatedCheckBoxAndLongSlider.xaml" />
<None Remove="Controls\AnnotatedIntSlider.xaml" />
<None Remove="Controls\CheckBoxAndTextBlock.xaml" />
</ItemGroup>
<ItemGroup>
@ -32,6 +33,9 @@
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\AnnotatedCheckBoxAndIntegerSlider.xaml" />
<Page Include="Controls\AnnotatedIntSlider.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\AnnotatedSlider.xaml" />
<Page Include="Controls\CheckBoxAndTextBlock.xaml">
<SubType>Designer</SubType>

View file

@ -58,7 +58,7 @@ namespace ServerManagerTool.Common.Utils
if (!result)
return false;
return result = SaveToFile(file, iniFile);
return SaveToFile(file, iniFile);
}
/// <summary>
@ -80,7 +80,7 @@ namespace ServerManagerTool.Common.Utils
if (!result)
return false;
return result = SaveToFile(file, iniFile);
return SaveToFile(file, iniFile);
}
public static IniFile ReadFromFile(string file)