Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 135 additions & 32 deletions GUI/App.xaml

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions GUI/AppSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.IO;
using System.Text.Json;

namespace GUI
{
public static class AppSettings
{
private static readonly string SettingsPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"MeiBrowser", "settings.json");

public static string SelectedTheme { get; set; } = "Dark";

public static void Load()
{
try
{
if (File.Exists(SettingsPath))
{
var json = File.ReadAllText(SettingsPath);
var data = JsonSerializer.Deserialize<SettingsData>(json);
if (data != null)
SelectedTheme = data.SelectedTheme ?? "Dark";
}
}
catch { }
}

public static void Save()
{
try
{
var dir = Path.GetDirectoryName(SettingsPath);
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir!);

var data = new SettingsData { SelectedTheme = SelectedTheme };
var json = JsonSerializer.Serialize(data);
File.WriteAllText(SettingsPath, json);
}
catch { }
}

private class SettingsData
{
public string? SelectedTheme { get; set; }
}
}
}
14 changes: 12 additions & 2 deletions GUI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:local="clr-namespace:GUI"
mc:Ignorable="d"
Loaded="Window_Loaded"
Background="#1E1E1E"
Background="{DynamicResource WindowBackgroundBrush}"
Title="MainWindow" Height="450" Width="800">

<Grid>
Expand All @@ -30,9 +30,19 @@
Width="150" Height="30" Margin="10,0,0,10"
HorizontalAlignment="Center"
Click="ResetButton_Click" />

<ComboBox Grid.Row="0" Grid.Column="2" x:Name="ThemeSelector"
Width="150" Height="30" Margin="10,0,0,10"
SelectionChanged="Theme_SelectionChanged"
VerticalContentAlignment="Center">
<ComboBoxItem Content="Dark" IsSelected="True"/>
<ComboBoxItem Content="Light"/>
<ComboBoxItem Content="Brown"/>
<ComboBoxItem Content="Custom..."/>
</ComboBox>
</StackPanel>

<TreeView Background="#2A2A2A" Name="FileTree" Grid.Row="1" Grid.ColumnSpan="2" ItemsSource="{Binding RootItems}">
<TreeView Background="{DynamicResource ControlBackgroundBrush}" Name="FileTree" Grid.Row="1" Grid.ColumnSpan="2" ItemsSource="{Binding RootItems}">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type local:FileItem}" ItemsSource="{Binding Children}">
<StackPanel Orientation="Horizontal" Margin="2">
Expand Down
118 changes: 117 additions & 1 deletion GUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using System.Windows.Shapes;
using Core;
using Dark.Net;
using Microsoft.Win32;
using System.IO;

namespace GUI
{
Expand All @@ -32,6 +34,7 @@ public partial class MainWindow : Window
private string downloadUrl = "";

private string appVersion = "1.1";
private bool isInitializing = true;

public MainWindow()
{
Expand All @@ -56,6 +59,19 @@ public MainWindow()
#region package selection
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
AppSettings.Load();
ApplyTheme(AppSettings.SelectedTheme);

for (int i = 0; i < ThemeSelector.Items.Count; i++)
{
if (ThemeSelector.Items[i] is ComboBoxItem item && item.Content.ToString() == AppSettings.SelectedTheme)
{
ThemeSelector.SelectedIndex = i;
break;
}
}

isInitializing = false;
await ShowPopup();
}

Expand Down Expand Up @@ -283,6 +299,105 @@ private async Task StartDownload(string savePath)
DownloadingOverlay.Visibility = Visibility.Collapsed;
}
#endregion

private void Theme_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (isInitializing) return;

if (ThemeSelector.SelectedItem is ComboBoxItem item)
{
string choice = item.Content.ToString();

if (choice == "Custom...")
{
var dialog = new OpenFileDialog();
dialog.Filter = "XAML Theme Files (*.xaml)|*.xaml";
if (dialog.ShowDialog() == true)
{
try
{
var customDict = new ResourceDictionary { Source = new Uri(dialog.FileName) };
if (!customDict.Contains("WindowBackgroundColor"))
{
MessageBox.Show("Invalid theme file: Missing 'WindowBackgroundColor'.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

Application.Current.Resources.MergedDictionaries.Clear();
Application.Current.Resources.MergedDictionaries.Add(customDict);

if (customDict["WindowBackgroundColor"] is Color bgColor)
{
double luminance = (0.299 * bgColor.R + 0.587 * bgColor.G + 0.114 * bgColor.B) / 255;
DarkNet.Instance.SetWindowThemeWpf(this, luminance > 0.5 ? Theme.Light : Theme.Dark);
}

AppSettings.SelectedTheme = dialog.FileName;
AppSettings.Save();
return;
}
catch (Exception ex)
{
MessageBox.Show($"Failed to load theme: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
}
else
{
return;
}
}

ApplyTheme(choice);
AppSettings.SelectedTheme = choice;
AppSettings.Save();
}
}

private void ApplyTheme(string themeName)
{
Uri themeUri = null;
Theme darkNetTheme = Theme.Dark;

if (themeName == "Dark")
{
themeUri = new Uri("Themes/Dark.xaml", UriKind.Relative);
darkNetTheme = Theme.Dark;
}
else if (themeName == "Light")
{
themeUri = new Uri("Themes/Light.xaml", UriKind.Relative);
darkNetTheme = Theme.Light;
}
else if (themeName == "Brown")
{
themeUri = new Uri("Themes/Brown.xaml", UriKind.Relative);
darkNetTheme = Theme.Dark;
}
else if (File.Exists(themeName))
{
try
{
var customDict = new ResourceDictionary { Source = new Uri(themeName) };
Application.Current.Resources.MergedDictionaries.Clear();
Application.Current.Resources.MergedDictionaries.Add(customDict);
if (customDict["WindowBackgroundColor"] is Color bgColor)
{
double luminance = (0.299 * bgColor.R + 0.587 * bgColor.G + 0.114 * bgColor.B) / 255;
DarkNet.Instance.SetWindowThemeWpf(this, luminance > 0.5 ? Theme.Light : Theme.Dark);
}
return;
}
catch { }
}

if (themeUri != null)
{
Application.Current.Resources.MergedDictionaries.Clear();
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = themeUri });
DarkNet.Instance.SetWindowThemeWpf(this, darkNetTheme);
}
}
}

public class FileItem
Expand All @@ -308,4 +423,5 @@ public FileItem(string name, long sizeInBytes, FileItem? parent = null, SophonMa
ElementsCount = 0;
}
}
}

}
14 changes: 7 additions & 7 deletions GUI/StartDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
WindowStartupLocation="CenterOwner"
WindowStyle="ToolWindow" ResizeMode="NoResize"
mc:Ignorable="d"
Background="#1E1E1E"
Title="StartDialog" Height="470" Width="600">
Background="{DynamicResource WindowBackgroundBrush}"
Title="Select Game Options" Height="470" Width="600">

<Grid>
<Grid Margin="20">
Expand All @@ -33,7 +33,7 @@
SelectionChanged="ModeCombo_SelectionChanged" />

<Button x:Name="ModeHelpButton" Grid.Row="0" Grid.Column="2" Content="Infos" Height="32" Width="75"
HorizontalAlignment="Right" Click="ModeHelpButton_Click" Background="#2A2A2A"/>
HorizontalAlignment="Right" Click="ModeHelpButton_Click" />

<!-- Game -->
<TextBlock Grid.Row="1" Grid.Column="0" Text="Game:" VerticalAlignment="Center"/>
Expand All @@ -56,9 +56,9 @@

<!-- Custom sophon -->
<TextBlock x:Name="CustomSophonTitle" Visibility="Hidden" Grid.Row="2" Grid.Column="0" Text="URL:" VerticalAlignment="Center"/>
<TextBox Visibility="Hidden" x:Name="CustomSophonUrl" Margin="15" Grid.Column="1" Grid.Row="2" Height="30" Background="#2A2A2A" Foreground="White" BorderThickness="1"/>
<TextBox Visibility="Hidden" x:Name="CustomSophonUrl" Margin="15" Grid.Column="1" Grid.Row="2" Height="30" Background="{DynamicResource ControlBackgroundBrush}" Foreground="{DynamicResource WindowForegroundBrush}" BorderThickness="1"/>
<Button Visibility="Hidden" x:Name="CheckSophonButton" Grid.Row="2" Grid.Column="2" Content="Check" Height="32" Width="75"
HorizontalAlignment="Right" Click="CheckSophonButton_Click" Background="#2A2A2A"/>
HorizontalAlignment="Right" Click="CheckSophonButton_Click" />

<!-- Version -->
<TextBlock Grid.Row="3" Grid.Column="0" Text="Version:" VerticalAlignment="Center"/>
Expand All @@ -77,12 +77,12 @@
<CheckBox x:Name="DiffMode" IsEnabled="False" Margin="15" Grid.Row="5" Grid.Column="1" Grid.ColumnSpan="2" Content="Only show new/changed files from previous version" IsThreeState="False"/>

<Button x:Name="ConfirmButton" IsEnabled="False" Grid.Row="6" Grid.Column="1" Grid.ColumnSpan="2" Content="Confirm" Height="32" Width="100"
HorizontalAlignment="Right" Click="Confirm_Click" Background="#2A2A2A"/>
HorizontalAlignment="Right" Click="Confirm_Click" />
</Grid>

<Grid x:Name="LoadingOverlay" Background="#80000000" Visibility="Collapsed" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="Loading..." Foreground="White" FontSize="16" HorizontalAlignment="Center"/>
<TextBlock Text="Loading..." Foreground="{DynamicResource WindowForegroundBrush}" FontSize="16" HorizontalAlignment="Center"/>
<ProgressBar IsIndeterminate="True" Width="200" Height="20"/>
</StackPanel>
</Grid>
Expand Down
14 changes: 14 additions & 0 deletions GUI/Themes/Brown.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Color x:Key="WindowBackgroundColor">#3E2723</Color>
<Color x:Key="WindowForegroundColor">#D7CCC8</Color>

<SolidColorBrush x:Key="WindowBackgroundBrush" Color="{StaticResource WindowBackgroundColor}"/>
<SolidColorBrush x:Key="WindowForegroundBrush" Color="{StaticResource WindowForegroundColor}"/>

<SolidColorBrush x:Key="ControlBackgroundBrush" Color="#4E342E"/>
<SolidColorBrush x:Key="ControlBorderBrush" Color="#6D4C41"/>
<SolidColorBrush x:Key="ControlHighlightBrush" Color="#795548"/>
<SolidColorBrush x:Key="ControlDisabledBrush" Color="#3E2723"/>
<SolidColorBrush x:Key="ControlDisabledForegroundBrush" Color="#8D6E63"/>
</ResourceDictionary>
14 changes: 14 additions & 0 deletions GUI/Themes/Dark.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Color x:Key="WindowBackgroundColor">#1E1E1E</Color>
<Color x:Key="WindowForegroundColor">#E0E0E0</Color>

<SolidColorBrush x:Key="WindowBackgroundBrush" Color="{StaticResource WindowBackgroundColor}"/>
<SolidColorBrush x:Key="WindowForegroundBrush" Color="{StaticResource WindowForegroundColor}"/>

<SolidColorBrush x:Key="ControlBackgroundBrush" Color="#2A2A2A"/>
<SolidColorBrush x:Key="ControlBorderBrush" Color="#3A3A3A"/>
<SolidColorBrush x:Key="ControlHighlightBrush" Color="#4A4A4A"/>
<SolidColorBrush x:Key="ControlDisabledBrush" Color="#1A1A1A"/>
<SolidColorBrush x:Key="ControlDisabledForegroundBrush" Color="#666666"/>
</ResourceDictionary>
14 changes: 14 additions & 0 deletions GUI/Themes/Light.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Color x:Key="WindowBackgroundColor">#FFFFFF</Color>
<Color x:Key="WindowForegroundColor">#000000</Color>

<SolidColorBrush x:Key="WindowBackgroundBrush" Color="{StaticResource WindowBackgroundColor}"/>
<SolidColorBrush x:Key="WindowForegroundBrush" Color="{StaticResource WindowForegroundColor}"/>

<SolidColorBrush x:Key="ControlBackgroundBrush" Color="#F0F0F0"/>
<SolidColorBrush x:Key="ControlBorderBrush" Color="#CCCCCC"/>
<SolidColorBrush x:Key="ControlHighlightBrush" Color="#E0E0E0"/>
<SolidColorBrush x:Key="ControlDisabledBrush" Color="#DDDDDD"/>
<SolidColorBrush x:Key="ControlDisabledForegroundBrush" Color="#AAAAAA"/>
</ResourceDictionary>