Skip to content

Commit

Permalink
Merge pull request #953 from shananas/DarkModeToggleTest
Browse files Browse the repository at this point in the history
Dark Mode Toggle
  • Loading branch information
Vladabdf authored Dec 17, 2023
2 parents cd00dba + ee0fbed commit 3fe37b4
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 24 deletions.
60 changes: 60 additions & 0 deletions OpenKh.Tools.ModsManager/Services/ColorThemeService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xe.Tools;

namespace OpenKh.Tools.ModsManager.Services
{
public class ColorThemeService : BaseNotifyPropertyChanged
{
public bool DarkMode
{
get
{
return ConfigurationService.DarkMode;
}
set
{
ConfigurationService.DarkMode = value;

OnPropertyChanged(nameof(DarkMode));
OnPropertyChanged(nameof(BackgroundColor));
OnPropertyChanged(nameof(TextColor));
}
}

public string BackgroundColor
{
get
{
if (DarkMode)
{
return "#2D2D2D";
}
else
{
return "white";
}
}
}

public string TextColor
{
get
{
if (ConfigurationService.DarkMode)
{
return "white";
}
else
{
return "black";
}
}
}

public static readonly ColorThemeService Instance = new ColorThemeService();
}
}
10 changes: 10 additions & 0 deletions OpenKh.Tools.ModsManager/Services/ConfigurationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ private class Config
public bool isEGSVersion { get; internal set; } = true;
public List<string> GamesToExtract { get; internal set; } = new List<string> { "kh2" };
public string LaunchGame { get; internal set; } = "kh2";
public bool DarkMode { get; internal set; } = true;

public void Save(string fileName)
{
Expand Down Expand Up @@ -404,5 +405,14 @@ public static string LaunchGame
_config.Save(ConfigPath);
}
}
public static bool DarkMode
{
get => _config.DarkMode;
set
{
_config.DarkMode = value;
_config.Save(ConfigPath);
}
}
}
}
5 changes: 3 additions & 2 deletions OpenKh.Tools.ModsManager/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public interface IChangeModEnableState
}

public class MainViewModel : BaseNotifyPropertyChanged, IChangeModEnableState
{
{
public ColorThemeService ColorTheme => ColorThemeService.Instance;
private static Version _version = Assembly.GetEntryAssembly()?.GetName()?.Version;
private static string ApplicationName = Utilities.GetApplicationName();
private static string ApplicationVersion = Utilities.GetApplicationVersion();
Expand All @@ -43,7 +44,7 @@ public class MainViewModel : BaseNotifyPropertyChanged, IChangeModEnableState
private bool _panaceaQuickMenuEnabled;
private bool _devView;
private bool _autoUpdateMods = false;
private string _launchGame = "kh2";
private string _launchGame = "kh2";
private List<string> _supportedGames = new List<string>()
{
"kh2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace OpenKh.Tools.ModsManager.ViewModels
{
public class SetupWizardViewModel : BaseNotifyPropertyChanged
{
public ColorThemeService ColorTheme => ColorThemeService.Instance;
private const int BufferSize = 65536;
private static readonly string PanaceaDllName = "OpenKH.Panacea.dll";
private static string ApplicationName = Utilities.GetApplicationName();
Expand Down
2 changes: 1 addition & 1 deletion OpenKh.Tools.ModsManager/Views/InstallModView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
WindowStartupLocation="CenterScreen"
ResizeMode="NoResize"
FocusManager.FocusedElement="{Binding ElementName=txtSourceModUrl}"
Title="Install a new mod or Lua Script..." Height="160" Width="300" SizeToContent="Height" Background="#2D2D2D" Foreground="White">
Title="Install a new mod or Lua Script..." Height="160" Width="300" SizeToContent="Height" Background="{Binding ColorTheme.BackgroundColor}" Foreground="{Binding ColorTheme.TextColor}">
<Window.InputBindings>
<KeyBinding Key="Esc" Command="{Binding CloseCommand}"/>
</Window.InputBindings>
Expand Down
1 change: 1 addition & 0 deletions OpenKh.Tools.ModsManager/Views/InstallModView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace OpenKh.Tools.ModsManager.Views
/// </summary>
public partial class InstallModView : Window
{
public ColorThemeService ColorTheme => ColorThemeService.Instance;
private static readonly IEnumerable<FileDialogFilter> _zipFilter = FileDialogFilterComposer
.Compose()
.AddExtensions("Mod archive", "zip", "kh2pcpatch", "kh1pcpatch", "compcpatch", "bbspcpatch", "lua");
Expand Down
1 change: 1 addition & 0 deletions OpenKh.Tools.ModsManager/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<MenuItem Header="Auto Update Mods" IsCheckable="True" ToolTip="When enabled Mod Manager will automatically update all mods on startup." IsChecked="{Binding AutoUpdateMods}" StaysOpenOnClick="True"/>
<MenuItem Header="Check for update" Command="{Binding CheckOpenkhUpdateCommand}"/>
<MenuItem Header="Check Mods for Updates" Command="{Binding CheckForModUpdatesCommand}"/>
<MenuItem Header="DarkMode" IsCheckable="True" IsChecked="{Binding ColorTheme.DarkMode}" StaysOpenOnClick="True"/>
<MenuItem Header="Panacea Settings" Visibility="{Binding PanaceaSettings}">
<MenuItem Header="Enable Console" IsCheckable="True" IsChecked="{Binding PanaceaConsoleEnabled}" StaysOpenOnClick="True"/>
<MenuItem Header="Enable Debug Log" IsCheckable="True" IsChecked="{Binding PanaceaDebugLogEnabled}" IsEnabled="{Binding PanaceaConsoleEnabled}" StaysOpenOnClick="True"/>
Expand Down
6 changes: 3 additions & 3 deletions OpenKh.Tools.ModsManager/Views/ModDetailsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
<UserControl.Resources>
<SolidColorBrush x:Key="textHyperlink" Color="#569CD6" />
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="White"/>
<Setter Property="Foreground" Value="{Binding ColorThemeService.TextColor}"/>
</Style>
<Style TargetType="Expander">
<Setter Property="Foreground" Value="White"/>
<Setter Property="Foreground" Value="{Binding ColorThemeService.TextColor}"/>
</Style>
</UserControl.Resources>
<StackPanel Background="#2D2D2D">
<StackPanel Background="{Binding BackgroundColor}">
<TextBlock Margin="0 0 0 3" FontWeight="Bold" Text="{Binding Title}" d:Text="Mod title"/>
<StackPanel Visibility="{Binding SourceVisibility}">
<TextBlock Margin="0 0 0 3">
Expand Down
20 changes: 10 additions & 10 deletions OpenKh.Tools.ModsManager/Views/ModManagerView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:OpenKh.Tools.ModsManager.Views"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="600" Background="#2D2D2D">
d:DesignHeight="450" d:DesignWidth="600" Background="{Binding ColorTheme.BackgroundColor}">
<UserControl.Resources>
<ControlTemplate x:Key="modList" TargetType="ListBox">
<Border Name="Border" BorderThickness="1">
Expand All @@ -18,22 +18,22 @@
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Margin="3" Background="#2D2D2D">
<TextBlock HorizontalAlignment="Center" Text="Highest priority" Foreground="White"/>
<StackPanel Grid.Row="0" Margin="3" Background="{Binding ColorTheme.BackgroundColor}">
<TextBlock HorizontalAlignment="Center" Text="Highest priority" Foreground="{Binding ColorTheme.TextColor}"/>
<Separator Margin="3" Background="#FFABADB3"/>
</StackPanel>
<StackPanel Grid.Row="2" Margin="3" Background="#2D2D2D">
<StackPanel Grid.Row="2" Margin="3" Background="{Binding ColorTheme.BackgroundColor}">
<Separator Margin="3" Background="#FFABADB3"/>
<TextBlock HorizontalAlignment="Center" Text="Lowest priority" Foreground="White"/>
<TextBlock HorizontalAlignment="Center" Text="Lowest priority" Foreground="{Binding ColorTheme.TextColor}"/>
</StackPanel>
<ScrollViewer Grid.Row="1" Margin="0" Background="#2D2D2D">
<ScrollViewer Grid.Row="1" Margin="0" Background="{Binding ColorTheme.BackgroundColor}">
<StackPanel Margin="0" IsItemsHost="True"/>
</ScrollViewer>
</Grid>
</Border>
</ControlTemplate>
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="White"/>
<Setter Property="Foreground" Value="{Binding ColorTheme.TextColor}"/>
</Style>
</UserControl.Resources>
<Grid Margin="10">
Expand Down Expand Up @@ -67,9 +67,9 @@
</CheckBox.Content>
</CheckBox>
<StackPanel Grid.Column="1">
<TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="White"/>
<TextBlock Text="{Binding Author}" Foreground="White"/>
<TextBlock Visibility="{Binding UpdateVisibility}" Text="Update available" Foreground="White"/>
<TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="{Binding ColorTheme.TextColor}"/>
<TextBlock Text="{Binding Author}" Foreground="{Binding ColorTheme.TextColor}"/>
<TextBlock Visibility="{Binding UpdateVisibility}" Text="Update available" Foreground="{Binding ColorTheme.TextColor}"/>
</StackPanel>
</Grid>
</DataTemplate>
Expand Down
6 changes: 3 additions & 3 deletions OpenKh.Tools.ModsManager/Views/PresetsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
WindowStartupLocation="CenterScreen"
ResizeMode="NoResize"
FocusManager.FocusedElement="{Binding ElementName=txtSourceModUrl}"
Title="Presets" Height="300" Width="300" SizeToContent="Height" Background="#2D2D2D">
Title="Presets" Height="300" Width="300" SizeToContent="Height" Background="{Binding ColorTheme.BackgroundColor}">

<Window.InputBindings>
<KeyBinding Key="Esc" Command="{Binding CloseCommand}"/>
Expand All @@ -23,7 +23,7 @@

<!-- Add new preset -->
<StackPanel DockPanel.Dock="Bottom">
<TextBlock Margin="0 0 0 3" Foreground="White">Name Preset</TextBlock>
<TextBlock Margin="0 0 0 3" Foreground="{Binding ColorTheme.TextColor}">Name Preset</TextBlock>
<Grid Margin="0 0 0 5" Background="White">
<TextBlock Margin="5,1" MinWidth="50" Text="Enter New Preset Name"
Foreground="Gray" Visibility="{Binding ElementName=txtSourceModUrl, Path=Text.IsEmpty, Converter={StaticResource BooleanToVisibilityConverter}}" IsHitTestVisible="False"/>
Expand All @@ -38,7 +38,7 @@
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<ScrollViewer Grid.Column="0" MinHeight="200">
<ListView Name="List_Presets" ItemsSource="{Binding Path=MainVm.PresetList}" Background="#2D2D2D" Foreground="White">
<ListView Name="List_Presets" ItemsSource="{Binding Path=MainVm.PresetList}" Background="{Binding ColorTheme.BackgroundColor}" Foreground="{Binding ColorTheme.TextColor}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
Expand Down
2 changes: 2 additions & 0 deletions OpenKh.Tools.ModsManager/Views/PresetsWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using OpenKh.Tools.ModsManager.Services;
using OpenKh.Tools.ModsManager.ViewModels;
using System.Windows;
using System.Windows.Controls;
Expand All @@ -7,6 +8,7 @@ namespace OpenKh.Tools.ModsManager.Views
{
public partial class PresetsWindow : Window
{
public ColorThemeService ColorTheme => ColorThemeService.Instance;
public MainViewModel MainVm { get; set; }
public RelayCommand CloseCommand { get; }
public string PresetName { get; set; }
Expand Down
10 changes: 5 additions & 5 deletions OpenKh.Tools.ModsManager/Views/SetupWizardWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
<SolidColorBrush x:Key="textHyperlink" Color="#569CD6" />
<Style TargetType="CheckBox">
<Setter Property="Foreground" Value="White"/>
<Setter Property="Foreground" Value="{Binding ColorTheme.TextColor}"/>
</Style>
<Style TargetType="xctk:WizardPage">
<Setter Property="Foreground" Value="White"/>
<Setter Property="Background" Value="#2D2D2D"/>
<Setter Property="HeaderBackground" Value="#2D2D2D"/>
<Setter Property="Foreground" Value="{Binding ColorTheme.TextColor}"/>
<Setter Property="Background" Value="{Binding ColorTheme.BackgroundColor}"/>
<Setter Property="HeaderBackground" Value="{Binding ColorTheme.BackgroundColor}"/>
<Setter Property="ExteriorPanelBackground" Value="#FF4E4E4E"/>
</Style>
</Window.Resources>
Expand All @@ -30,7 +30,7 @@
FinishButtonClosesWindow="True"
CurrentPage="{Binding ElementName=PageGameEdition}"
PageChanged="Wizard_PageChanged"
Finish="Wizard_Finish" Background="#2D2D2D">
Finish="Wizard_Finish" Background="{Binding ColorTheme.BackgroundColor}">

<xctk:WizardPage
x:Name="IntroPage"
Expand Down

0 comments on commit 3fe37b4

Please sign in to comment.