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

@ -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)