Skip to content

Commit 3ca6b71

Browse files
committed
load themes from application/Themes/ folder, remove themefile global var, move Start() method into OnWindowLoaded (to get nicer error messages), make highlight and inactive highlight colors for recent datagrid transparent (to see custom selected row colors), theme editor: clear orig colors list on enter window
1 parent baf1607 commit 3ca6b71

File tree

4 files changed

+48
-30
lines changed

4 files changed

+48
-30
lines changed

UnityLauncherPro/MainWindow.xaml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
xmlns:System="clr-namespace:System;assembly=mscorlib"
88
xmlns:converters="clr-namespace:UnityLauncherPro.Converters" x:Class="UnityLauncherPro.MainWindow"
99
mc:Ignorable="d"
10-
Title="UnityLauncherPro" Height="650" Width="880" WindowStartupLocation="CenterScreen" Background="{DynamicResource ThemeDarkestBackground}" MinWidth="600" MinHeight="650" AllowsTransparency="True" WindowStyle="None" Margin="0" KeyDown="OnWindowKeyDown" Closing="Window_Closing" SizeChanged="Window_SizeChanged" Icon="Images/icon.ico" Activated="Window_Activated">
10+
Title="UnityLauncherPro" Height="650" Width="880" WindowStartupLocation="CenterScreen" Background="{DynamicResource ThemeDarkestBackground}" MinWidth="600" MinHeight="650" AllowsTransparency="True" WindowStyle="None" Margin="0" KeyDown="OnWindowKeyDown" Closing="Window_Closing" SizeChanged="Window_SizeChanged" Icon="Images/icon.ico" Activated="Window_Activated" Loaded="Window_Loaded">
1111
<Window.Resources>
1212

1313
<converters:LastModifiedConverter x:Key="lastModifiedConverter"/>
@@ -220,7 +220,17 @@
220220
</Trigger>
221221
</Style.Triggers>
222222
<Style.Resources>
223-
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}"/>
223+
<!--<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}"/>-->
224+
225+
<!--<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="{DynamicResource ThemeGridRowHighlight}"/>-->
226+
<!--<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="{DynamicResource ThemeGridRowHighlight}"/>-->
227+
228+
<!--<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="{DynamicResource ThemeGridRowHighlight.Color}"/>-->
229+
<!--<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="{Binding DynamicResource ThemeGridRowHighlight, Converter={StaticResource solidColorBrushToColorConverter}, ElementName=SolidColorBrush}"/>-->
230+
<!--<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="{DynamicResource Color1}"/>-->
231+
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}">Transparent</SolidColorBrush>
232+
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}">Transparent</SolidColorBrush>
233+
<!--<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}">Red</SolidColorBrush>-->
224234
</Style.Resources>
225235
</Style>
226236

@@ -923,7 +933,7 @@
923933
<CheckBox x:Name="chkUseCustomTheme" Content="Load custom theme" Foreground="{DynamicResource ThemeButtonForeground}" Margin="0,0,0,4" ToolTip="Loads theme.ini from application folder" Checked="ChkUseCustomTheme_Checked" Unchecked="ChkUseCustomTheme_Checked" HorizontalAlignment="Left"/>
924934
<TextBox x:Name="txtCustomThemeFile" MinWidth="128" ToolTip="Default is theme.ini" Padding="0,3,0,0" Margin="5,0,0,0" Text="theme.ini" LostFocus="TxtCustomThemeFile_LostFocus" PreviewKeyDown="TxtCustomThemeFile_PreviewKeyDown" />
925935
<Button Style="{StaticResource CustomButton}" ToolTip="Reload theme" x:Name="btnReloadTheme" Content="" Height="22" Width="22" HorizontalAlignment="Right" VerticalAlignment="Top" FontSize="16" Padding="1,-2,1,1" BorderBrush="{x:Null}" Click="BtnReloadTheme_Click" Margin="5,0,0,0"/>
926-
<Button Style="{StaticResource CustomButton}" ToolTip="Explore Themes folder (application root)" x:Name="btnExploreFolder" Content="..." Height="22" Width="22" HorizontalAlignment="Right" VerticalAlignment="Top" FontSize="16" Padding="1,-2,1,1" BorderBrush="{x:Null}" Click="BtnExploreFolder_Click" Margin="5,0,0,0"/>
936+
<Button Style="{StaticResource CustomButton}" ToolTip="Explore Themes folder" x:Name="btnExploreFolder" Content="..." Height="22" Width="22" HorizontalAlignment="Right" VerticalAlignment="Top" FontSize="16" Padding="1,-2,1,1" BorderBrush="{x:Null}" Click="BtnExploreFolder_Click" Margin="5,0,0,0"/>
927937
<Button Style="{StaticResource CustomButton}" ToolTip="Open theme editor" x:Name="btnThemeEditor" Content="" Height="22" Width="22" HorizontalAlignment="Right" VerticalAlignment="Top" Padding="1,-2,1,1" BorderBrush="{x:Null}" Click="BtnThemeEditor_Click" Margin="5,0,0,0"/>
928938
</StackPanel>
929939

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public partial class MainWindow : Window
5151
string adbLogCatArgs = defaultAdbLogCatArgs;
5252

5353
Dictionary<string, SolidColorBrush> origResourceColors = new Dictionary<string, SolidColorBrush>();
54-
string themefile = "theme.ini";
54+
5555
string latestBuildReportProjectPath = null;
5656

5757
[DllImport("user32", CharSet = CharSet.Unicode)]
@@ -66,13 +66,11 @@ public partial class MainWindow : Window
6666
public MainWindow()
6767
{
6868
InitializeComponent();
69-
Start();
69+
Init();
7070
}
7171

72-
void Start()
72+
void Init()
7373
{
74-
LoadSettings();
75-
7674
// disable accesskeys without alt
7775
CoreCompatibilityPreferences.IsAltKeyRequiredInAccessKeyDefaultScope = true;
7876

@@ -81,6 +79,11 @@ void Start()
8179
Resizable_BorderLess_Chrome.CornerRadius = new CornerRadius(0);
8280
Resizable_BorderLess_Chrome.CaptionHeight = 1.0;
8381
WindowChrome.SetWindowChrome(this, Resizable_BorderLess_Chrome);
82+
}
83+
84+
void Start()
85+
{
86+
LoadSettings();
8487

8588
// get unity installations
8689
dataGridUnitys.Items.Clear();
@@ -122,7 +125,7 @@ void Start()
122125
origResourceColors[item.Key.ToString()] = (SolidColorBrush)item.Value;
123126
}
124127

125-
ApplyTheme();
128+
ApplyTheme(txtCustomThemeFile.Text);
126129

127130
// for autostart with minimized
128131
if (Properties.Settings.Default.runAutomatically == true && Properties.Settings.Default.runAutomaticallyMinimized == true)
@@ -311,8 +314,7 @@ void LoadSettings()
311314
chkUseCustomTheme.IsChecked = Properties.Settings.Default.useCustomTheme;
312315
txtRootFolderForNewProjects.Text = Properties.Settings.Default.newProjectsRoot;
313316
txtWebglRelativePath.Text = Properties.Settings.Default.webglBuildPath;
314-
themefile = Properties.Settings.Default.themeFile;
315-
txtCustomThemeFile.Text = themefile;
317+
txtCustomThemeFile.Text = Properties.Settings.Default.themeFile;
316318

317319
chkEnablePlatformSelection.IsChecked = Properties.Settings.Default.enablePlatformSelection;
318320
chkRunAutomatically.IsChecked = Properties.Settings.Default.runAutomatically;
@@ -1997,15 +1999,17 @@ private void MenuItemBrowsePersistentDataPath_Click(object sender, RoutedEventAr
19971999
}
19982000
}
19992001

2000-
void ApplyTheme()
2002+
void ApplyTheme(string themeFile)
20012003
{
20022004
if (chkUseCustomTheme.IsChecked == false) return;
20032005

20042006
//Console.WriteLine("Load theme: " + themefile);
20052007

2006-
if (File.Exists(themefile) == true)
2008+
themeFile = "Themes/" + themeFile;
2009+
2010+
if (File.Exists(themeFile) == true)
20072011
{
2008-
var colors = File.ReadAllLines(themefile);
2012+
var colors = File.ReadAllLines(themeFile);
20092013

20102014
// parse lines
20112015
for (int i = 0, length = colors.Length; i < length; i++)
@@ -2034,7 +2038,7 @@ void ApplyTheme()
20342038
}
20352039
else
20362040
{
2037-
Console.WriteLine("Theme file not found: " + themefile);
2041+
Console.WriteLine("Theme file not found: " + themeFile);
20382042
}
20392043
}
20402044

@@ -2059,7 +2063,7 @@ private void ChkUseCustomTheme_Checked(object sender, RoutedEventArgs e)
20592063
// reset colors now
20602064
if (isChecked == true)
20612065
{
2062-
ApplyTheme();
2066+
ApplyTheme(txtCustomThemeFile.Text);
20632067
}
20642068
else
20652069
{
@@ -2069,14 +2073,13 @@ private void ChkUseCustomTheme_Checked(object sender, RoutedEventArgs e)
20692073

20702074
private void BtnReloadTheme_Click(object sender, RoutedEventArgs e)
20712075
{
2072-
ApplyTheme();
2076+
ApplyTheme(txtCustomThemeFile.Text);
20732077
}
20742078

20752079
private void TxtCustomThemeFile_LostFocus(object sender, RoutedEventArgs e)
20762080
{
20772081
var s = (TextBox)sender;
2078-
themefile = s.Text;
2079-
Properties.Settings.Default.themeFile = themefile;
2082+
Properties.Settings.Default.themeFile = s.Text;
20802083
Properties.Settings.Default.Save();
20812084
}
20822085

@@ -2085,8 +2088,7 @@ private void TxtCustomThemeFile_PreviewKeyDown(object sender, KeyEventArgs e)
20852088
switch (e.Key)
20862089
{
20872090
case Key.Return: // pressed enter in theme file text box
2088-
themefile = txtCustomThemeFile.Text;
2089-
Properties.Settings.Default.themeFile = themefile;
2091+
Properties.Settings.Default.themeFile = txtCustomThemeFile.Text;
20902092
Properties.Settings.Default.Save();
20912093
btnReloadTheme.Focus();
20922094
break;
@@ -2095,7 +2097,7 @@ private void TxtCustomThemeFile_PreviewKeyDown(object sender, KeyEventArgs e)
20952097

20962098
private void BtnExploreFolder_Click(object sender, RoutedEventArgs e)
20972099
{
2098-
Tools.LaunchExplorer(System.AppDomain.CurrentDomain.BaseDirectory);
2100+
Tools.LaunchExplorer(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Themes"));
20992101
}
21002102

21012103
private void ChkEnablePlatformSelection_Checked(object sender, RoutedEventArgs e)
@@ -2394,6 +2396,12 @@ private void MenuItemDownloadWebGLModule_Click(object sender, RoutedEventArgs e)
23942396
if (unity == null) return;
23952397
Tools.DownloadAdditionalModules(unity.Path, unity.Version, "WebGL");
23962398
}
2399+
2400+
private void Window_Loaded(object sender, RoutedEventArgs e)
2401+
{
2402+
Start();
2403+
2404+
}
23972405
} // class
23982406
} //namespace
23992407

UnityLauncherPro/Resources/Colors.xaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<SolidColorBrush x:Key="ThemeButtonBackgroundPressed" Color="#FF0F0F0F"/>
2828
<SolidColorBrush x:Key="ThemeMainTitle" Color="#FFB8B8B8"/>
2929
<SolidColorBrush x:Key="ThemeScrollBarEnabledForeground" Color="#FF000000"/>
30-
30+
3131
<!--search-->
3232
<SolidColorBrush x:Key="ThemeSearchPlaceholder" Color="#7F919191"/>
3333
<SolidColorBrush x:Key="ThemeSearchClose" Color="#A3C1C1C1"/>
@@ -38,7 +38,7 @@
3838
<!--window-->
3939
<SolidColorBrush x:Key="ThemeWindowMinClose" Color="#FFC3C3C3"/>
4040

41-
<!--grids-->
41+
<!--datagrids-->
4242
<SolidColorBrush x:Key="ThemeGridForeground" Color="#FFD8D8D8"/>
4343
<SolidColorBrush x:Key="ThemeGridHorizontalGridLines" Color="#4C000000"/>
4444
<SolidColorBrush x:Key="ThemeGridVerticalGridLines" Color="#19000000"/>
@@ -51,9 +51,8 @@
5151
<!--platform selection combobox-->
5252
<SolidColorBrush x:Key="ThemeDropDownBorderBorderBrush" Color="#FF171717"/>
5353
<SolidColorBrush x:Key="ThemeDropDownBorderBackground" Color="#FF2E2E34"/>
54-
54+
5555
<!--focused button outline-->
5656
<SolidColorBrush x:Key="ThemeButtonFocusOutline" Color="#FF003D61"/>
5757

58-
5958
</ResourceDictionary>

UnityLauncherPro/ThemeEditor.xaml.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public ThemeEditor()
2828
private void Window_Loaded(object sender, RoutedEventArgs e)
2929
{
3030
themeColors.Clear();
31+
themeColorsOrig.Clear();
3132

3233
//foreach (KeyValuePair<string, SolidColorBrush> item in origResourceColors)
3334
//{
@@ -36,14 +37,13 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
3637

3738
// get original colors to collection
3839
foreach (DictionaryEntry item in Application.Current.Resources.MergedDictionaries[0])
39-
//foreach (DictionaryEntry item in Application.Current.Resources[themeColors[i].Key])
4040
{
4141
// take currently used colors
4242
var currentColor = Application.Current.Resources[item.Key];
4343

4444
var themeColorPair = new ThemeColor();
4545
themeColorPair.Key = item.Key.ToString();
46-
themeColorPair.Brush = (SolidColorBrush)currentColor;// (SolidColorBrush)item.Value;
46+
themeColorPair.Brush = (SolidColorBrush)currentColor;
4747
themeColors.Add(themeColorPair);
4848

4949
// take backup copy
@@ -166,7 +166,7 @@ private void SliderAlpha_ValueChanged(object sender, RoutedPropertyChangedEventA
166166

167167
private void BtnSaveTheme_Click(object sender, RoutedEventArgs e)
168168
{
169-
var themeFolder = Path.Combine(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName), "Themes");
169+
var themeFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Themes");
170170

171171
if (Directory.Exists(themeFolder) == false) Directory.CreateDirectory(themeFolder);
172172

@@ -196,10 +196,11 @@ private void BtnSaveTheme_Click(object sender, RoutedEventArgs e)
196196

197197
private void BtnResetTheme_Click(object sender, RoutedEventArgs e)
198198
{
199+
Console.WriteLine(themeColorsOrig.Count);
200+
Console.WriteLine(themeColors.Count);
199201
for (int i = 0; i < themeColorsOrig.Count; i++)
200202
{
201203
// reset collection colors
202-
// FIXME fails if exit theme editor, then come back to reset
203204
themeColors[i].Brush = themeColorsOrig[i].Brush;
204205

205206
// reset application colors

0 commit comments

Comments
 (0)