Skip to content

Commit

Permalink
Added themes support
Browse files Browse the repository at this point in the history
  • Loading branch information
CactusPie committed Apr 6, 2023
1 parent 62c03a9 commit 4ab0ec6
Show file tree
Hide file tree
Showing 18 changed files with 18,492 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/CactusPie.MapLocation.Minimap/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="ApplicationStartup">
<Application.Resources>

<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Themes/LightTheme.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
2 changes: 2 additions & 0 deletions src/CactusPie.MapLocation.Minimap/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ private IComponentContext CreateContainer()
containerBuilder.RegisterType<PlotWindow>().AsSelf().InstancePerDependency();
containerBuilder.RegisterType<MainWindow>().AsSelf().InstancePerDependency();
containerBuilder.RegisterType<AddNewMapDialog>().AsSelf().InstancePerDependency();
containerBuilder.RegisterType<ThemeSelector>().AsSelf().InstancePerDependency();
containerBuilder.RegisterType<MapDataReceiver>().As<IMapDataReceiver>().InstancePerDependency();
containerBuilder.RegisterType<MapCreationDataManager>().As<IMapCreationDataManager>().SingleInstance();
containerBuilder.RegisterInstance(mapConfiguration).AsSelf();

containerBuilder.Register(_ =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
<Content Include="Maps\Images\reserve_underground_south.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

</ItemGroup>

<ItemGroup>
Expand All @@ -191,6 +192,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="nulastudio.NetCoreBeauty" Version="1.2.9.3" />
<PackageReference Include="PresentationFramework.Aero2" Version="1.0.1" />
<PackageReference Include="ScottPlot.WPF" Version="4.1.61" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/CactusPie.MapLocation.Minimap/Data/MapConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ public class MapConfiguration
{
public int ListenPort { get; init; }
public string? ListenIpAddress { get; init; }
public string? Theme { get; init; }
}
17 changes: 9 additions & 8 deletions src/CactusPie.MapLocation.Minimap/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<Border Grid.Row="0" Padding="5" Background="White">
<Grid Background="White">
<Border Grid.Row="0" Padding="5" Background="{DynamicResource BackgroundColour}">
<Grid Background="{DynamicResource BackgroundColour}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
Expand All @@ -40,16 +41,16 @@
</TextBlock>
<TextBlock Grid.Row="1" FontSize="14" Margin="0 0 0 0" HorizontalAlignment="Center">
Your position data will appear below [
<Run Foreground="Blue">game_x_position</Run>
<Run Foreground="CornflowerBlue">game_x_position</Run>
<Run Foreground="Green">map_x_position</Run>
<Run Foreground="Blue">game_z_position</Run>
<Run Foreground="CornflowerBlue">game_z_position</Run>
<Run Foreground="Green">map_z_position</Run>
]
</TextBlock>
<TextBox Name="CurrentPositionTextBox" Grid.Row="2" IsReadOnly="True" VerticalAlignment="Center"></TextBox>
</Grid>

<StackPanel Orientation="Horizontal" Grid.Row="1" Margin="0 5 0 5">
<StackPanel Name="ControlsStackPanel" Orientation="Horizontal" Grid.Row="1" Margin="0 5 0 5">
<CheckBox Name="MapCreationModeCheckbox" IsChecked="False" VerticalAlignment="Center" Margin="0 0 5 0"
Checked="MapCreationModeCheckbox_OnChecked" Unchecked="MapCreationModeCheckbox_OnUnchecked">
<CheckBox.LayoutTransform>
Expand All @@ -71,7 +72,7 @@
</CheckBox.LayoutTransform>
<TextBlock Text="Follow player (hotkey: f)" VerticalAlignment="Center" />
</CheckBox>
<Button Click="ClearDrawingButton_OnClick" Width="150" Height="30">Clear drawing</Button>
<Button Click="ClearDrawingButton_OnClick" Width="150" Height="30" Margin="0 0 5 0">Clear drawing</Button>
</StackPanel>
<StackPanel Name="MapCreationButtonsStackPanel" Grid.Row="2" Orientation="Horizontal" Margin="0 5 0 5" Visibility="Collapsed">
<Button Name="StartCreatingMapButton" Width="150" Height="30" Margin="0 0 5 0" Click="StartCreatingMapButton_OnClick">Add new map</Button>
Expand Down Expand Up @@ -105,7 +106,7 @@
Width="5"
/>

<Grid Name="MapDataGrid" Grid.Column="2" Visibility="Collapsed" Background="White">
<Grid Name="MapDataGrid" Grid.Column="2" Visibility="Collapsed" Background="{DynamicResource BackgroundColour}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
Expand Down
6 changes: 5 additions & 1 deletion src/CactusPie.MapLocation.Minimap/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@ public partial class MainWindow : Window
private readonly IMapCreationDataManager _mapCreationDataManager;
private readonly Func<AddNewMapDialog> _addNewMapDialogFactory;
private readonly Func<PlotWindow> _plotWindowFactory;
private readonly Func<ThemeSelector> _themeSelectorFactory;
private readonly IMapDataReceiver _mapDataReceiver;

public MainWindow
(
Func<IMapDataReceiver> mapDataReceiverFactory,
IMapCreationDataManager mapCreationDataManager,
Func<AddNewMapDialog> addNewMapDialogFactory,
Func<PlotWindow> plotWindowFactory
Func<PlotWindow> plotWindowFactory,
Func<ThemeSelector> themeSelectorFactory
)
{
_mapCreationDataManager = mapCreationDataManager;
_addNewMapDialogFactory = addNewMapDialogFactory;
_plotWindowFactory = plotWindowFactory;
_themeSelectorFactory = themeSelectorFactory;
_mapDataReceiver = mapDataReceiverFactory();
InitializeComponent();
}
Expand All @@ -40,6 +43,7 @@ protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
ReloadMapCreationPositionData();
ControlsStackPanel.Children.Add(_themeSelectorFactory());

_mapDataReceiver.MapPositionDataReceived += MapDataReceiverOnMapPositionDataReceived;
_mapDataReceiver.StartReceivingData();
Expand Down
15 changes: 15 additions & 0 deletions src/CactusPie.MapLocation.Minimap/ThemeSelector.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<UserControl x:Class="CactusPie.MapLocation.Minimap.ThemeSelector"
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"
xmlns:local="clr-namespace:CactusPie.MapLocation.Minimap"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<ComboBox Name="ThemeComboBox" SelectedIndex="0" SelectionChanged="ThemeComboBox_OnSelectionChanged">
<ComboBoxItem>Light Theme</ComboBoxItem>
<ComboBoxItem>Dark Theme</ComboBoxItem>
<ComboBoxItem>Colorful Light Theme</ComboBoxItem>
<ComboBoxItem>Colorful Dark Theme</ComboBoxItem>
</ComboBox>
</UserControl>
52 changes: 52 additions & 0 deletions src/CactusPie.MapLocation.Minimap/ThemeSelector.xaml.cs
Original file line number Diff line number Diff line change
@@ -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<ComboBoxItem>()
.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);
}
}
Loading

0 comments on commit 4ab0ec6

Please sign in to comment.