Skip to content

Commit

Permalink
Implemented configurable colours for Mortar/Target indicators.
Browse files Browse the repository at this point in the history
  • Loading branch information
sirdoombox committed Mar 16, 2020
1 parent 16463cf commit 221416f
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 33 deletions.
17 changes: 17 additions & 0 deletions PostScriptumMortarCalculator/Events/ColorChangedEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Windows.Media;

namespace PostScriptumMortarCalculator.Events
{
public class ColorChangedEvent
{
public enum Type { Mortar, Target }
public Type TypeChanged { get; }
public Color NewColor { get; }

public ColorChangedEvent(Type typeChanged, Color newColor)
{
TypeChanged = typeChanged;
NewColor = newColor;
}
}
}
4 changes: 4 additions & 0 deletions PostScriptumMortarCalculator/Models/UserConfigModel.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Windows.Media;
using Newtonsoft.Json;

namespace PostScriptumMortarCalculator.Models
Expand All @@ -10,5 +11,8 @@ public class UserConfigModel
[JsonProperty] public double GridOpacity { get; set; } = 0.25d;
[JsonProperty] public string LastMapName { get; set; }
[JsonProperty] public string LastMortarName { get; set; }
[JsonProperty] public Color MortarIndicatorColor { get; set; } = Colors.Blue;
[JsonProperty] public Color TargetIndicatorColor { get; set; } = Colors.Red;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
<Compile Include="Converters\InverseBooleanToVisibilityConverter.cs" />
<Compile Include="Converters\RoundedVector2ToPointConverter.cs" />
<Compile Include="Converters\StringToAccentBrushConverter.cs" />
<Compile Include="Events\ColorChangedEvent.cs" />
<Compile Include="Events\MortarChangedEvent.cs" />
<Compile Include="Events\PositionChangedEvent.cs" />
<Compile Include="Extensions\NumericExtensions.cs" />
Expand Down
15 changes: 14 additions & 1 deletion PostScriptumMortarCalculator/ViewModels/MapViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using PostScriptumMortarCalculator.Events;
using PostScriptumMortarCalculator.Extensions;
using PostScriptumMortarCalculator.Models;
Expand All @@ -13,7 +14,7 @@

namespace PostScriptumMortarCalculator.ViewModels
{
public class MapViewModel : Screen, IHandle<MortarChangedEvent>
public class MapViewModel : Screen, IHandle<MortarChangedEvent>, IHandle<ColorChangedEvent>
{
public RoundedVector2 TargetPositionPixels { get; set; }

Expand Down Expand Up @@ -63,6 +64,10 @@ public class MapViewModel : Screen, IHandle<MortarChangedEvent>

public double GridOpacity { get; set; }

public SolidColorBrush MortarBrush { get; set; }

public SolidColorBrush TargetBrush { get; set; }

public string MapImageSource => c_RESOURCE_PATH + SelectedMap.MapImagePath;

private const string c_RESOURCE_PATH = "/PostScriptumMortarCalculator;component/Assets";
Expand Down Expand Up @@ -259,5 +264,13 @@ private void RecalculateTargetSplash()
DistancePixels.ToScaledMeters(MapPixelsPerMeter)))
.ToPixelScale(MapPixelsPerMeter) * 2;
}

public void Handle(ColorChangedEvent message)
{
if(message.TypeChanged == ColorChangedEvent.Type.Mortar)
MortarBrush = new SolidColorBrush(message.NewColor);
else
TargetBrush = new SolidColorBrush(message.NewColor);
}
}
}
24 changes: 23 additions & 1 deletion PostScriptumMortarCalculator/ViewModels/UserConfigViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Linq;
using System.Windows;
using System.Windows.Media;
using MahApps.Metro;
using PostScriptumMortarCalculator.Events;
using PostScriptumMortarCalculator.Models;
using PostScriptumMortarCalculator.Services;
using Stylet;
Expand All @@ -15,22 +17,30 @@ public class UserConfigViewModel : Screen
public BindableCollection<string> Accents { get; set; }
= new BindableCollection<string>();

public Color MortarIndicatorColour { get; set; }

public Color TargetIndicatorColour { get; set; }

public string SelectedTheme { get; set; }
public string SelectedAccent { get; set; }

private readonly ConfigService m_configService;
private readonly UserConfigModel m_configModel;
private readonly IEventAggregator m_eventAggregator;

public UserConfigViewModel(ConfigService configService)
public UserConfigViewModel(ConfigService configService, IEventAggregator eventAggregator)
{
DisplayName = "Settings";
m_configService = configService;
m_eventAggregator = eventAggregator;
m_configModel = m_configService.ActiveConfig;
Accents.AddRange(ThemeManager.ColorSchemes.Select(x => x.Name));
Themes.AddRange(ThemeManager.Themes.GroupBy(x => x.BaseColorScheme).Select(x => x.First())
.Select(x => x.BaseColorScheme));
SelectedTheme = m_configModel.Theme;
SelectedAccent = m_configModel.Accent;
MortarIndicatorColour = m_configModel.MortarIndicatorColor;
TargetIndicatorColour = m_configModel.TargetIndicatorColor;
}

protected override void OnPropertyChanged(string propertyName)
Expand All @@ -50,5 +60,17 @@ public void OnSelectedThemeChanged()
m_configModel.Theme = SelectedTheme;
ThemeManager.ChangeThemeBaseColor(Application.Current, SelectedTheme);
}

public void OnMortarIndicatorColorChanged()
{
m_configModel.MortarIndicatorColor = MortarIndicatorColour;
m_eventAggregator.Publish(new ColorChangedEvent(ColorChangedEvent.Type.Mortar, MortarIndicatorColour));
}

public void OnTargetIndicatorColorChanged()
{
m_configModel.TargetIndicatorColor = TargetIndicatorColour;
m_eventAggregator.Publish(new ColorChangedEvent(ColorChangedEvent.Type.Target, TargetIndicatorColour));
}
}
}
8 changes: 4 additions & 4 deletions PostScriptumMortarCalculator/Views/MapView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
MouseUp="{s:Action MouseUp}"
MouseMove="{s:Action MouseMove}" />
<!-- Mortar position indicator. -->
<Ellipse Fill="Blue"
<Ellipse Fill="{Binding MortarBrush}"
Canvas.ZIndex="100"
Canvas.Left="{Binding MortarPositionPixels.X}"
Canvas.Top="{Binding MortarPositionPixels.Y}"
Expand All @@ -119,7 +119,7 @@
<TranslateTransform X="-2.5" Y="-2.5" />
</Ellipse.RenderTransform>
</Ellipse>
<Path Fill="Blue"
<Path Fill="{Binding MortarBrush}"
Opacity="{Binding IndicatorOpacity}"
Visibility="{Binding IsMortarPositionSet, Converter={StaticResource BooleanToVisibility}}"
IsHitTestVisible="False">
Expand All @@ -145,7 +145,7 @@
Height="{Binding TargetInnateSplashPixels.Y}"
Visibility="{Binding IsTargetPositionSet, Converter={StaticResource BooleanToVisibility}}"
Style="{StaticResource AreaStyleEllipse}"
Fill="Red">
Fill="{Binding TargetBrush}">
<Ellipse.RenderTransform>
<TransformGroup>
<TranslateTransform X="{Binding HalfTargetInnateSplashPixels.X}"
Expand All @@ -163,7 +163,7 @@
Opacity="{Binding IndicatorOpacity}"
Visibility="{Binding IsMortarAndTargetSet, Converter={StaticResource BooleanToVisibility}}"
StrokeThickness="5"
Stroke="Red" />
Stroke="{Binding TargetBrush}" />
</Canvas>
</panAndZoom:ZoomBorder>
</Grid>
Expand Down
98 changes: 71 additions & 27 deletions PostScriptumMortarCalculator/Views/UserConfigView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,75 @@
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance viewModels:UserConfigViewModel}">
<StackPanel>
<StackPanel.Resources>
<Thickness x:Key="ControlMargin">0 10 0 0</Thickness>
</StackPanel.Resources>
<ComboBox ItemsSource="{Binding Themes}"
SelectedItem="{Binding SelectedTheme}"
mah:TextBoxHelper.UseFloatingWatermark="True"
mah:TextBoxHelper.Watermark="Theme" />
<ComboBox Margin="{StaticResource ControlMargin}"
ItemsSource="{Binding Accents}"
SelectedItem="{Binding SelectedAccent}"
mah:TextBoxHelper.UseFloatingWatermark="True"
mah:TextBoxHelper.Watermark="Accent">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"
Foreground="{Binding Converter={StaticResource StringToAccentBrush}}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<xctk:ColorPicker ShowTabHeaders="False"
UsingAlphaChannel="False"
ShowDropDownButton="False"
DropDownBackground="{DynamicResource MahApps.Brushes.Control.Background}"
BorderThickness="0"
ColorMode="ColorCanvas"/>
</StackPanel>
<ScrollViewer HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Disabled"
CanContentScroll="True">
<StackPanel>
<StackPanel.Resources>
<Thickness x:Key="ControlMargin">0 10 0 0</Thickness>
<Style TargetType="xctk:ColorPicker">
<Setter Property="ShowTabHeaders" Value="False" />
<Setter Property="UsingAlphaChannel" Value="False" />
<Setter Property="ShowDropDownButton" Value="False" />
<Setter Property="DropDownBackground" Value="{DynamicResource MahApps.Brushes.Control.Background}" />
<Setter Property="Background" Value="{DynamicResource MahApps.Brushes.Control.Background}" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="ColorMode" Value="ColorCanvas" />
</Style>
<Style TargetType="ComboBox" BasedOn="{StaticResource MahApps.Styles.ComboBox}">
<Setter Property="mah:TextBoxHelper.UseFloatingWatermark" Value="True" />
</Style>
<Style TargetType="Label">
<Setter Property="Foreground" Value="{DynamicResource MahApps.Brushes.Accent}" />
<Setter Property="FontWeight" Value="Black" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="FontSize" Value="18" />
</Style>
<Style TargetType="DockPanel">
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="Margin" Value="{StaticResource ControlMargin}" />
<Style.Resources>
<Style TargetType="Label">
<Setter Property="MinWidth" Value="200"/>
<Setter Property="DockPanel.Dock" Value="Left" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="Foreground" Value="{DynamicResource MahApps.Brushes.Accent}" />
<Setter Property="FontWeight" Value="Bold" />
</Style>
</Style.Resources>
</Style>
</StackPanel.Resources>
<Border Margin="5" BorderBrush="{DynamicResource MahApps.Brushes.Accent}" BorderThickness="1">
<StackPanel Margin="5">
<Label Content="Colours &amp; Themes" />
<ComboBox ItemsSource="{Binding Themes}"
SelectedItem="{Binding SelectedTheme}"
mah:TextBoxHelper.Watermark="Theme" />
<ComboBox Margin="{StaticResource ControlMargin}"
ItemsSource="{Binding Accents}"
SelectedItem="{Binding SelectedAccent}"
mah:TextBoxHelper.Watermark="Accent">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"
Foreground="{Binding Converter={StaticResource StringToAccentBrush}}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<DockPanel>
<Label Content="Mortar Indicator Colour"/>
<xctk:ColorPicker SelectedColor="{Binding MortarIndicatorColour}" />
</DockPanel>
<DockPanel>
<Label Content="Target Indicator Colour"/>
<xctk:ColorPicker SelectedColor="{Binding TargetIndicatorColour}" />
</DockPanel>
</StackPanel>
</Border>
</StackPanel>
</ScrollViewer>
</UserControl>

0 comments on commit 221416f

Please sign in to comment.