From 4ab0ec68ec7c25baa86c6fa165d308475b5f0c90 Mon Sep 17 00:00:00 2001 From: CactusPie Date: Thu, 6 Apr 2023 19:59:59 +0200 Subject: [PATCH] Added themes support --- src/CactusPie.MapLocation.Minimap/App.xaml | 6 +- src/CactusPie.MapLocation.Minimap/App.xaml.cs | 2 + .../CactusPie.MapLocation.Minimap.csproj | 2 + .../Data/MapConfiguration.cs | 1 + .../MainWindow.xaml | 17 +- .../MainWindow.xaml.cs | 6 +- .../ThemeSelector.xaml | 15 + .../ThemeSelector.xaml.cs | 52 + .../Themes/ColourfulDarkTheme.xaml | 4505 ++++++++++++++++ .../Themes/ColourfulDarkTheme.xaml.cs | 43 + .../Themes/ColourfulLightTheme.xaml | 4555 ++++++++++++++++ .../Themes/ColourfulLightTheme.xaml.cs | 43 + .../Themes/DarkTheme.xaml | 4644 +++++++++++++++++ .../Themes/DarkTheme.xaml.cs | 43 + .../Themes/LightTheme.xaml | 4461 ++++++++++++++++ .../Themes/LightTheme.xaml.cs | 43 + .../Themes/ThemesController.cs | 61 + .../appsettings.json | 4 +- 18 files changed, 18492 insertions(+), 11 deletions(-) create mode 100644 src/CactusPie.MapLocation.Minimap/ThemeSelector.xaml create mode 100644 src/CactusPie.MapLocation.Minimap/ThemeSelector.xaml.cs create mode 100644 src/CactusPie.MapLocation.Minimap/Themes/ColourfulDarkTheme.xaml create mode 100644 src/CactusPie.MapLocation.Minimap/Themes/ColourfulDarkTheme.xaml.cs create mode 100644 src/CactusPie.MapLocation.Minimap/Themes/ColourfulLightTheme.xaml create mode 100644 src/CactusPie.MapLocation.Minimap/Themes/ColourfulLightTheme.xaml.cs create mode 100644 src/CactusPie.MapLocation.Minimap/Themes/DarkTheme.xaml create mode 100644 src/CactusPie.MapLocation.Minimap/Themes/DarkTheme.xaml.cs create mode 100644 src/CactusPie.MapLocation.Minimap/Themes/LightTheme.xaml create mode 100644 src/CactusPie.MapLocation.Minimap/Themes/LightTheme.xaml.cs create mode 100644 src/CactusPie.MapLocation.Minimap/Themes/ThemesController.cs diff --git a/src/CactusPie.MapLocation.Minimap/App.xaml b/src/CactusPie.MapLocation.Minimap/App.xaml index c5ac112..6ba1e03 100644 --- a/src/CactusPie.MapLocation.Minimap/App.xaml +++ b/src/CactusPie.MapLocation.Minimap/App.xaml @@ -3,6 +3,10 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Startup="ApplicationStartup"> - + + + + + diff --git a/src/CactusPie.MapLocation.Minimap/App.xaml.cs b/src/CactusPie.MapLocation.Minimap/App.xaml.cs index e2e235d..4c9e9e6 100644 --- a/src/CactusPie.MapLocation.Minimap/App.xaml.cs +++ b/src/CactusPie.MapLocation.Minimap/App.xaml.cs @@ -51,8 +51,10 @@ private IComponentContext CreateContainer() containerBuilder.RegisterType().AsSelf().InstancePerDependency(); containerBuilder.RegisterType().AsSelf().InstancePerDependency(); containerBuilder.RegisterType().AsSelf().InstancePerDependency(); + containerBuilder.RegisterType().AsSelf().InstancePerDependency(); containerBuilder.RegisterType().As().InstancePerDependency(); containerBuilder.RegisterType().As().SingleInstance(); + containerBuilder.RegisterInstance(mapConfiguration).AsSelf(); containerBuilder.Register(_ => { diff --git a/src/CactusPie.MapLocation.Minimap/CactusPie.MapLocation.Minimap.csproj b/src/CactusPie.MapLocation.Minimap/CactusPie.MapLocation.Minimap.csproj index 49e1082..1f17d8d 100644 --- a/src/CactusPie.MapLocation.Minimap/CactusPie.MapLocation.Minimap.csproj +++ b/src/CactusPie.MapLocation.Minimap/CactusPie.MapLocation.Minimap.csproj @@ -182,6 +182,7 @@ PreserveNewest + @@ -191,6 +192,7 @@ + diff --git a/src/CactusPie.MapLocation.Minimap/Data/MapConfiguration.cs b/src/CactusPie.MapLocation.Minimap/Data/MapConfiguration.cs index f55edcf..dfa21b3 100644 --- a/src/CactusPie.MapLocation.Minimap/Data/MapConfiguration.cs +++ b/src/CactusPie.MapLocation.Minimap/Data/MapConfiguration.cs @@ -4,4 +4,5 @@ public class MapConfiguration { public int ListenPort { get; init; } public string? ListenIpAddress { get; init; } + public string? Theme { get; init; } } \ No newline at end of file diff --git a/src/CactusPie.MapLocation.Minimap/MainWindow.xaml b/src/CactusPie.MapLocation.Minimap/MainWindow.xaml index 56888b9..9605e8e 100644 --- a/src/CactusPie.MapLocation.Minimap/MainWindow.xaml +++ b/src/CactusPie.MapLocation.Minimap/MainWindow.xaml @@ -6,16 +6,17 @@ xmlns:local="clr-namespace:CactusPie.MapLocation.Minimap" xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" mc:Ignorable="d" + Style="{DynamicResource CustomWindowStyle}" KeyDown="MainWindow_OnKeyDown" - Title="EFT Map" Height="450" Width="900"> + Title="EFT Map" Height="450" Width="1000"> - - + + @@ -40,16 +41,16 @@ Your position data will appear below [ - game_x_position + game_x_position map_x_position - game_z_position + game_z_position map_z_position ] - + @@ -71,7 +72,7 @@ - + @@ -105,7 +106,7 @@ Width="5" /> - + diff --git a/src/CactusPie.MapLocation.Minimap/MainWindow.xaml.cs b/src/CactusPie.MapLocation.Minimap/MainWindow.xaml.cs index 639053c..40e3165 100644 --- a/src/CactusPie.MapLocation.Minimap/MainWindow.xaml.cs +++ b/src/CactusPie.MapLocation.Minimap/MainWindow.xaml.cs @@ -19,6 +19,7 @@ public partial class MainWindow : Window private readonly IMapCreationDataManager _mapCreationDataManager; private readonly Func _addNewMapDialogFactory; private readonly Func _plotWindowFactory; + private readonly Func _themeSelectorFactory; private readonly IMapDataReceiver _mapDataReceiver; public MainWindow @@ -26,12 +27,14 @@ public MainWindow Func mapDataReceiverFactory, IMapCreationDataManager mapCreationDataManager, Func addNewMapDialogFactory, - Func plotWindowFactory + Func plotWindowFactory, + Func themeSelectorFactory ) { _mapCreationDataManager = mapCreationDataManager; _addNewMapDialogFactory = addNewMapDialogFactory; _plotWindowFactory = plotWindowFactory; + _themeSelectorFactory = themeSelectorFactory; _mapDataReceiver = mapDataReceiverFactory(); InitializeComponent(); } @@ -40,6 +43,7 @@ protected override void OnInitialized(EventArgs e) { base.OnInitialized(e); ReloadMapCreationPositionData(); + ControlsStackPanel.Children.Add(_themeSelectorFactory()); _mapDataReceiver.MapPositionDataReceived += MapDataReceiverOnMapPositionDataReceived; _mapDataReceiver.StartReceivingData(); diff --git a/src/CactusPie.MapLocation.Minimap/ThemeSelector.xaml b/src/CactusPie.MapLocation.Minimap/ThemeSelector.xaml new file mode 100644 index 0000000..606cfee --- /dev/null +++ b/src/CactusPie.MapLocation.Minimap/ThemeSelector.xaml @@ -0,0 +1,15 @@ + + + Light Theme + Dark Theme + Colorful Light Theme + Colorful Dark Theme + + diff --git a/src/CactusPie.MapLocation.Minimap/ThemeSelector.xaml.cs b/src/CactusPie.MapLocation.Minimap/ThemeSelector.xaml.cs new file mode 100644 index 0000000..e772941 --- /dev/null +++ b/src/CactusPie.MapLocation.Minimap/ThemeSelector.xaml.cs @@ -0,0 +1,52 @@ +using System; +using System.Linq; +using System.Windows; +using System.Windows.Controls; +using CactusPie.MapLocation.Minimap.Data; +using CactusPie.MapLocation.Minimap.Themes; + +namespace CactusPie.MapLocation.Minimap; + +public partial class ThemeSelector : UserControl +{ + private readonly MapConfiguration _mapConfiguration; + + public ThemeSelector(MapConfiguration mapConfiguration) + { + _mapConfiguration = mapConfiguration; + InitializeComponent(); + } + + protected override void OnInitialized(EventArgs e) + { + base.OnInitialized(e); + + if (_mapConfiguration.Theme != null) + { + ThemeComboBox.SelectedItem = ThemeComboBox.Items + .Cast() + .FirstOrDefault(x => x.Content as string == _mapConfiguration.Theme); + } + } + + private void ThemeComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) + { + string? selectedThemeName = (e.AddedItems[0] as ComboBoxItem)?.Content as string; + + if (selectedThemeName == null) + { + throw new InvalidOperationException("Invalid theme name"); + } + + ThemesController.ThemeTypes themeType = selectedThemeName switch + { + "Light Theme" => ThemesController.ThemeTypes.Light, + "Dark Theme" => ThemesController.ThemeTypes.Dark, + "Colorful Light Theme" => ThemesController.ThemeTypes.ColourfulLight, + "Colorful Dark Theme" => ThemesController.ThemeTypes.ColourfulDark, + _ => throw new ArgumentOutOfRangeException($"Invalid theme name: {selectedThemeName}") + }; + + ThemesController.SetTheme(themeType); + } +} \ No newline at end of file diff --git a/src/CactusPie.MapLocation.Minimap/Themes/ColourfulDarkTheme.xaml b/src/CactusPie.MapLocation.Minimap/Themes/ColourfulDarkTheme.xaml new file mode 100644 index 0000000..1223dd1 --- /dev/null +++ b/src/CactusPie.MapLocation.Minimap/Themes/ColourfulDarkTheme.xaml @@ -0,0 +1,4505 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +