Skip to content

Commit 6a92b19

Browse files
committed
theme editor: add reset theme, add save theme (to file), set theme editor window colors to local colors (so they wont ever get changed)
1 parent 5a5379a commit 6a92b19

File tree

2 files changed

+82
-38
lines changed

2 files changed

+82
-38
lines changed

UnityLauncherPro/ThemeEditor.xaml

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:local="clr-namespace:UnityLauncherPro"
77
mc:Ignorable="d"
8-
Title="ThemeEditor" Height="450" Width="500" WindowStyle="ToolWindow" Loaded="Window_Loaded" Background="{DynamicResource ThemeDarkestBackground}">
8+
Title="ThemeEditor" Height="450" Width="500" WindowStyle="ToolWindow" Loaded="Window_Loaded" Background="#FF121212">
99
<!--TODO take from mainwindow?-->
1010
<Window.Resources>
1111
<!-- custom buttons -->
@@ -26,7 +26,7 @@
2626
<Setter TargetName="shortcutbutton" Property="Background" Value="#FF0F0F0F" />
2727
</Trigger>
2828
<Trigger Property="IsFocused" Value="true">
29-
<Setter TargetName="shortcutbutton" Property="BorderBrush" Value="{DynamicResource ThemeButtonFocusOutline}" />
29+
<Setter TargetName="shortcutbutton" Property="BorderBrush" Value="#FF003D61" />
3030
<Setter TargetName="shortcutbutton" Property="BorderThickness" Value="1" />
3131
</Trigger>
3232
</ControlTemplate.Triggers>
@@ -38,15 +38,15 @@
3838
<!--TODO move to styles-->
3939
<!-- datagrid rows & row selection -->
4040
<Style TargetType="DataGridRow">
41-
<Setter Property="Background" Value="{DynamicResource ThemeButtonBackground}" />
41+
<Setter Property="Background" Value="#FF3F3F46" />
4242
<Setter Property="BorderBrush" Value="{x:Null}" />
4343
<Setter Property="BorderThickness" Value="0,0,0,0" />
4444
<Style.Triggers>
4545
<!--<Trigger Property="IsMouseOver" Value="True">
4646
<Setter Property="Background" Value="{StaticResource DataGridRowMouseOver}"/>
4747
</Trigger>-->
4848
<Trigger Property="IsSelected" Value="True">
49-
<Setter Property="Background" Value="{DynamicResource ThemeDataGridRowSelectedBackground}" />
49+
<Setter Property="Background" Value="#FF007ACC" />
5050
</Trigger>
5151
</Style.Triggers>
5252
</Style>
@@ -76,17 +76,17 @@
7676
<Setter.Value>
7777
<ControlTemplate TargetType="{x:Type RepeatButton}">
7878
<!-- button background -->
79-
<Border Name="Border" Margin="1" CornerRadius="0" BorderThickness="0" Background="{DynamicResource ThemeButtonBackground}" BorderBrush="{x:Null}">
79+
<Border Name="Border" Margin="1" CornerRadius="0" BorderThickness="0" Background="#FF3F3F46" BorderBrush="{x:Null}">
8080
<!-- arrow sign -->
81-
<Path HorizontalAlignment="Center" VerticalAlignment="Center" Fill="{DynamicResource ThemeScrollArrowForeground}" Data="{Binding Path=Content,RelativeSource={RelativeSource TemplatedParent}}" />
81+
<Path HorizontalAlignment="Center" VerticalAlignment="Center" Fill="#FF5E5E64" Data="{Binding Path=Content,RelativeSource={RelativeSource TemplatedParent}}" />
8282
</Border>
8383
<ControlTemplate.Triggers>
8484
<!-- NOTE order matters, if pressed is before mouseover, then it gets overwritten -->
8585
<Trigger Property="IsMouseOver" Value="true">
86-
<Setter TargetName="Border" Property="Background" Value="{DynamicResource ThemeTextBoxBackground}" />
86+
<Setter TargetName="Border" Property="Background" Value="#FF333337" />
8787
</Trigger>
8888
<Trigger Property="IsPressed" Value="true">
89-
<Setter TargetName="Border" Property="Background" Value="{DynamicResource ThemeScrollArrowPressed}" />
89+
<Setter TargetName="Border" Property="Background" Value="#FF838383" />
9090
</Trigger>
9191
<Trigger Property="IsEnabled" Value="false">
9292
<Setter Property="Foreground" Value="Black"/>
@@ -123,7 +123,7 @@
123123
<Border Name="Border" CornerRadius="0" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" />
124124
<ControlTemplate.Triggers>
125125
<Trigger Property="IsMouseOver" Value="true">
126-
<Setter TargetName="Border" Property="Background" Value="{DynamicResource ThemeScrollBarThumbFill}" />
126+
<Setter TargetName="Border" Property="Background" Value="#FF6A6969" />
127127
</Trigger>
128128
</ControlTemplate.Triggers>
129129
</ControlTemplate>
@@ -139,7 +139,7 @@
139139
<RowDefinition MaxHeight="18"/>
140140
</Grid.RowDefinitions>
141141
<!-- scrollbar background -->
142-
<Border Grid.RowSpan="3" CornerRadius="0" Background="{DynamicResource ThemeScrollBarBackground}" />
142+
<Border Grid.RowSpan="3" CornerRadius="0" Background="#FF151515" />
143143
<!-- scrollbar top button -->
144144
<RepeatButton Grid.Row="0" Style="{StaticResource ScrollBarLineButton}" Height="18" Command="ScrollBar.LineUpCommand" Content="M 0 4 L 8 4 L 4 0 Z" />
145145
<Track Name="PART_Track" Grid.Row="1" IsDirectionReversed="true">
@@ -148,7 +148,7 @@
148148
</Track.DecreaseRepeatButton>
149149
<Track.Thumb>
150150
<!-- scrollbar foreground -->
151-
<Thumb Style="{StaticResource ScrollBarThumb}" Margin="1,0,1,0" Background="{DynamicResource ThemeScrollBarFill}" BorderBrush="{x:Null}"/>
151+
<Thumb Style="{StaticResource ScrollBarThumb}" Margin="1,0,1,0" Background="#FF47474B" BorderBrush="{x:Null}"/>
152152
</Track.Thumb>
153153
<Track.IncreaseRepeatButton>
154154
<RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageDownCommand" />
@@ -181,7 +181,7 @@
181181
<RowDefinition Height="*"/>
182182
</Grid.RowDefinitions>
183183
<!--<DataGrid Grid.Row="0" x:Name="gridThemeColors" KeyboardNavigation.TabNavigation="None" SelectionMode="Single" Margin="3,0" HeadersVisibility="None" AutoGenerateColumns="False" IsSynchronizedWithCurrentItem="True" Foreground="{DynamicResource ThemeButtonForeground}" Background="{DynamicResource ThemeMainBackgroundColor}" IsTabStop="True" TabIndex="1" EnableRowVirtualization="False" VerticalScrollBarVisibility="Visible" SelectionChanged="GridThemeColors_SelectionChanged">-->
184-
<DataGrid Grid.Row="0" x:Name="gridThemeColors" KeyboardNavigation.TabNavigation="None" SelectionMode="Single" Margin="3,0" HeadersVisibility="None" AutoGenerateColumns="False" IsSynchronizedWithCurrentItem="True" Foreground="{DynamicResource ThemeButtonForeground}" Background="{DynamicResource ThemeMainBackgroundColor}" IsTabStop="True" TabIndex="1" EnableRowVirtualization="False" VerticalScrollBarVisibility="Visible" SelectionChanged="GridThemeColors_SelectionChanged">
184+
<DataGrid Grid.Row="0" x:Name="gridThemeColors" KeyboardNavigation.TabNavigation="None" SelectionMode="Single" Margin="3,0" HeadersVisibility="None" AutoGenerateColumns="False" IsSynchronizedWithCurrentItem="True" Foreground="#FFC1C1C1" Background="#FF262626" IsTabStop="True" TabIndex="1" EnableRowVirtualization="False" VerticalScrollBarVisibility="Visible" SelectionChanged="GridThemeColors_SelectionChanged">
185185
<DataGrid.Columns>
186186
<DataGridTextColumn Header="Key" Binding="{Binding Key}" IsReadOnly="True" CanUserResize="False"/>
187187
<DataGridTextColumn Header="Value" Binding="{Binding Brush}" IsReadOnly="True" CanUserResize="False">
@@ -192,7 +192,7 @@
192192
<Setter Property="Background" Value="{Binding Brush, Converter={StaticResource SolidColorBrushConverter}}" />
193193
<Style.Triggers>
194194
<DataTrigger Binding="{Binding Brush, Converter={StaticResource SolidColorBrushConverter}}" Value="true">
195-
<Setter Property="Foreground" Value="{DynamicResource ThemeGridGreenText}" />
195+
<Setter Property="Foreground" Value="White" />
196196
</DataTrigger>
197197
</Style.Triggers>
198198
</Style>
@@ -206,30 +206,34 @@
206206
<!--<TextBox x:Name="txtSelectedColorHex" VerticalAlignment="Center" IsUndoEnabled="True" TabIndex="0" Width="189" Height="24" Margin="10,0,0,0" />-->
207207
<StackPanel Orientation="Vertical" Margin="10,0,0,0">
208208
<StackPanel Orientation="Horizontal">
209-
<Label Foreground="{DynamicResource ThemeButtonForeground}" Width="40">Red</Label>
209+
<Label Foreground="#FFC1C1C1" Width="44">Red</Label>
210210
<Slider x:Name="sliderRed" AutoToolTipPlacement="TopLeft" AutoToolTipPrecision="0" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Width="128" Height="28" Value="255" Maximum="255" LargeChange="0" SmallChange="1" ValueChanged="SliderRed_ValueChanged"/>
211211
<TextBox x:Name="txtRed" VerticalAlignment="Center" IsUndoEnabled="True" Width="32" Margin="5,0,0,8" IsReadOnly="True" />
212212
</StackPanel>
213213
<StackPanel Orientation="Horizontal">
214-
<Label Foreground="{DynamicResource ThemeButtonForeground}" Width="40">Green</Label>
214+
<Label Foreground="#FFC1C1C1" Width="44">Green</Label>
215215
<Slider x:Name="sliderGreen" AutoToolTipPlacement="TopLeft" AutoToolTipPrecision="0" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Width="128" Height="28" Value="255" Maximum="255" LargeChange="0" SmallChange="1" ValueChanged="SliderGreen_ValueChanged"/>
216216
<TextBox x:Name="txtGreen" VerticalAlignment="Center" IsUndoEnabled="True" Width="32" Margin="5,0,0,8" IsReadOnly="True" />
217217
</StackPanel>
218218
<StackPanel Orientation="Horizontal">
219-
<Label Foreground="{DynamicResource ThemeButtonForeground}" Width="40">Blue</Label>
219+
<Label Foreground="#FFC1C1C1" Width="44">Blue</Label>
220220
<Slider x:Name="sliderBlue" AutoToolTipPlacement="TopLeft" AutoToolTipPrecision="0" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Width="128" Height="28" Value="255" Maximum="255" LargeChange="0" SmallChange="1" ValueChanged="SliderBlue_ValueChanged"/>
221221
<TextBox x:Name="txtBlue" VerticalAlignment="Center" IsUndoEnabled="True" Width="32" Margin="5,0,0,8" IsReadOnly="True" />
222222
</StackPanel>
223223
<StackPanel Orientation="Horizontal">
224-
<Label Foreground="{DynamicResource ThemeButtonForeground}" Width="40">Alpha</Label>
224+
<Label Foreground="#FFC1C1C1" Width="44">Alpha</Label>
225225
<Slider x:Name="sliderAlpha" AutoToolTipPlacement="TopLeft" AutoToolTipPrecision="0" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Width="128" Height="28" Value="255" Maximum="255" LargeChange="0" SmallChange="1" ValueChanged="SliderAlpha_ValueChanged"/>
226226
<TextBox x:Name="txtAlpha" VerticalAlignment="Center" IsUndoEnabled="True" Width="32" Margin="5,0,0,8" IsReadOnly="True" />
227227
</StackPanel>
228228
</StackPanel>
229-
230-
<Button Style="{StaticResource CustomButton}" x:Name="btnSaveTheme" Background="{DynamicResource ThemeButtonBackground}" Foreground="#FFC1C1C1" BorderBrush="{x:Null}" VerticalAlignment="Center" Height="35" Click="BtnSaveTheme_Click" TabIndex="3" Width="157" Margin="16,0,0,0">
231-
<Label Foreground="{DynamicResource ThemeButtonForeground}" Content="Save Theme"/>
232-
</Button>
229+
<StackPanel Orientation="Vertical" Margin="25,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Center">
230+
<Button x:Name="btnResetTheme" Style="{StaticResource CustomButton}" Background="#FF3F3F46" Foreground="#FFC1C1C1" BorderBrush="{x:Null}" VerticalAlignment="Center" Height="36" Click="BtnResetTheme_Click" TabIndex="3" Width="78.5" Margin="0,0,0,20">
231+
<Label Foreground="#FFC1C1C1" Content="Reset Theme"/>
232+
</Button>
233+
<Button x:Name="btnSaveTheme" Style="{StaticResource CustomButton}" Background="#FF3F3F46" Foreground="#FFC1C1C1" BorderBrush="{x:Null}" VerticalAlignment="Center" Height="36" TabIndex="3" Width="157" Margin="0" Click="BtnSaveTheme_Click">
234+
<Label Foreground="#FFC1C1C1" Content="Save Theme"/>
235+
</Button>
236+
</StackPanel>
233237
</StackPanel>
234238

235239
</Grid>

UnityLauncherPro/ThemeEditor.xaml.cs

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using System.Collections.Generic;
44
using System.Collections.ObjectModel;
55
using System.Data;
6+
using System.Diagnostics;
7+
using System.IO;
68
using System.Windows;
79
using System.Windows.Controls;
810
using System.Windows.Media;
@@ -11,10 +13,11 @@ namespace UnityLauncherPro
1113
{
1214
public partial class ThemeEditor : Window
1315
{
14-
// TODO take from mainwindow?
15-
//Dictionary<string, SolidColorBrush> origResourceColors = new Dictionary<string, SolidColorBrush>();
16-
//public static List<ThemeColor> themeColors;
1716
public static ObservableCollection<ThemeColor> themeColors = new ObservableCollection<ThemeColor>();
17+
static ObservableCollection<ThemeColor> themeColorsOrig = new ObservableCollection<ThemeColor>();
18+
19+
// hack for adjusting slider, without triggering onchange..
20+
bool forceValue = false;
1821

1922
public ThemeEditor()
2023
{
@@ -25,31 +28,25 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
2528
{
2629
themeColors.Clear();
2730

28-
// get original colors
31+
// get original colors to collection
2932
foreach (DictionaryEntry item in Application.Current.Resources.MergedDictionaries[0])
3033
{
31-
// take original colors, so can reset them
32-
//origResourceColors[item.Key.ToString()] = (SolidColorBrush)item.Value;
33-
//var col = (SolidColorBrush)item.Value;
34-
//Console.WriteLine(item.Key.ToString() + "=" + col);
3534
var themeColorPair = new ThemeColor();
3635
themeColorPair.Key = item.Key.ToString();
3736
themeColorPair.Brush = (SolidColorBrush)item.Value;
3837
themeColors.Add(themeColorPair);
39-
//var col = new BrushConverter().ConvertFrom(row[1].Trim());
40-
// apply color
41-
//Application.Current.Resources[row[0]] = (SolidColorBrush)col;
38+
39+
// take backup copy
40+
var themeColorPair2 = new ThemeColor();
41+
themeColorPair2.Key = item.Key.ToString();
42+
themeColorPair2.Brush = (SolidColorBrush)item.Value;
43+
themeColorsOrig.Add(themeColorPair2);
4244
}
4345

4446
// display current theme keys and values
45-
//gridThemeColors.ItemsSource = origResourceColors;
4647
gridThemeColors.ItemsSource = themeColors;
47-
//gridThemeColors.DataContext = themeColors;
48-
4948
}
5049

51-
int selectedRow = -1;
52-
bool forceValue = false;
5350

5451
private void GridThemeColors_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
5552
{
@@ -153,9 +150,52 @@ private void SliderAlpha_ValueChanged(object sender, RoutedPropertyChangedEventA
153150

154151
private void BtnSaveTheme_Click(object sender, RoutedEventArgs e)
155152
{
156-
Console.WriteLine("TODO save theme to file..");
153+
// NOTE for now its application root folder, would be nicer to have fixed themes/ folder
154+
var rootFolder = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
155+
List<string> iniRows = new List<string>();
156+
iniRows.Add("# Created with UnityLauncherPro built-in theme editor " + DateTime.Now.ToString("dd/MM/YYYY"));
157+
for (int i = 0; i < themeColors.Count; i++)
158+
{
159+
iniRows.Add(themeColors[i].Key + "=" + themeColors[i].Brush.ToString());
160+
}
161+
// TODO ask for output filename
162+
var themePath = Path.Combine(rootFolder, "custom.ini");
163+
File.WriteAllLines(themePath, iniRows);
164+
Console.WriteLine("Saved theme: " + themePath);
157165
}
158166

167+
private void BtnResetTheme_Click(object sender, RoutedEventArgs e)
168+
{
169+
for (int i = 0; i < themeColorsOrig.Count; i++)
170+
{
171+
// reset collection colors
172+
// FIXME fails if exit theme editor, then come back to reset
173+
themeColors[i].Brush = themeColorsOrig[i].Brush;
174+
175+
// reset application colors
176+
Application.Current.Resources[themeColors[i].Key] = themeColorsOrig[i].Brush;
177+
}
178+
179+
// reset current button
180+
if (gridThemeColors.SelectedItem != null)
181+
{
182+
var item = gridThemeColors.SelectedItem as ThemeColor;
183+
forceValue = true;
184+
sliderRed.Value = item.Brush.Color.R;
185+
txtRed.Text = sliderRed.Value.ToString();
186+
forceValue = true;
187+
sliderGreen.Value = item.Brush.Color.G;
188+
txtGreen.Text = sliderGreen.Value.ToString();
189+
forceValue = true;
190+
sliderBlue.Value = item.Brush.Color.B;
191+
txtBlue.Text = sliderBlue.Value.ToString();
192+
forceValue = true;
193+
sliderAlpha.Value = item.Brush.Color.A;
194+
txtAlpha.Text = sliderAlpha.Value.ToString();
195+
forceValue = false;
196+
}
159197

198+
gridThemeColors.Items.Refresh();
199+
}
160200
}
161201
}

0 commit comments

Comments
 (0)