Skip to content

Commit 89e4384

Browse files
committed
adding custom theme loader and settings
1 parent a40de0f commit 89e4384

File tree

6 files changed

+173
-118
lines changed

6 files changed

+173
-118
lines changed

UnityLauncherPro/App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
<setting name="webglBuildPath" serializeAs="String">
7070
<value />
7171
</setting>
72+
<setting name="useCustomTheme" serializeAs="String">
73+
<value>False</value>
74+
</setting>
7275
</UnityLauncherPro.Properties.Settings>
7376
</userSettings>
7477
</configuration>

UnityLauncherPro/MainWindow.xaml

Lines changed: 76 additions & 75 deletions
Large diffs are not rendered by default.

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// https://github.com/unitycoder/UnityLauncherPro
33

44
using System;
5+
using System.Collections;
56
using System.Collections.Generic;
67
using System.ComponentModel;
78
using System.Diagnostics;
@@ -48,6 +49,8 @@ public partial class MainWindow : Window
4849
public static string preferredVersion = "none";
4950
Mutex myMutex;
5051

52+
Dictionary<string, SolidColorBrush> origResourceColors = new Dictionary<string, SolidColorBrush>();
53+
5154
public MainWindow()
5255
{
5356
InitializeComponent();
@@ -57,9 +60,6 @@ public MainWindow()
5760
void Start()
5861
{
5962
LoadSettings();
60-
61-
// TEST
62-
//ApplySkin();
6363

6464
// disable accesskeys without alt
6565
CoreCompatibilityPreferences.IsAltKeyRequiredInAccessKeyDefaultScope = true;
@@ -108,6 +108,14 @@ void Start()
108108
notifyIcon.Icon = new Icon(Application.GetResourceStream(new Uri("pack://application:,,,/Images/icon.ico")).Stream);
109109
notifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(NotifyIcon_MouseClick);
110110

111+
// get original colors
112+
foreach (DictionaryEntry item in Application.Current.Resources.MergedDictionaries[0])
113+
{
114+
origResourceColors[item.Key.ToString()] = (SolidColorBrush)item.Value;
115+
}
116+
117+
ApplyTheme();
118+
111119
isInitializing = false;
112120
}
113121

@@ -259,6 +267,7 @@ void LoadSettings()
259267
chkEnableProjectRename.IsChecked = Properties.Settings.Default.enableProjectRename;
260268
chkStreamerMode.IsChecked = Properties.Settings.Default.streamerMode;
261269
chkShowPlatform.IsChecked = Properties.Settings.Default.showTargetPlatform;
270+
chkUseCustomTheme.IsChecked = Properties.Settings.Default.useCustomTheme;
262271
txtRootFolderForNewProjects.Text = Properties.Settings.Default.newProjectsRoot;
263272
txtWebglRelativePath.Text = Properties.Settings.Default.webglBuildPath;
264273

@@ -1719,9 +1728,10 @@ private void MenuItemBrowsePersistentDataPath_Click(object sender, RoutedEventAr
17191728
}
17201729
}
17211730

1722-
void ApplySkin()
1731+
void ApplyTheme()
17231732
{
1724-
// TODO dont load, if skinning is disabled in settings
1733+
if (chkUseCustomTheme.IsChecked == false) return;
1734+
17251735
// TODO load current skin (or could save them into preferences from settings panel, so that it doesnt need to parse file everytime! and have reset colors button to reset them)
17261736
// TODO set colors to resources
17271737

@@ -1742,10 +1752,36 @@ void ApplySkin()
17421752
// skip bad rows
17431753
if (row.Length != 2) continue;
17441754
// apply color
1745-
Application.Current.Resources[row[0]] = (SolidColorBrush)(new BrushConverter().ConvertFrom(row[1]));
1755+
Application.Current.Resources[row[0]] = (SolidColorBrush)(new BrushConverter().ConvertFrom(row[1].Trim()));
17461756
}
17471757
}
1748-
} // loadskin()
1758+
}
1759+
1760+
void ResetTheme()
1761+
{
1762+
foreach (KeyValuePair<string, SolidColorBrush> item in origResourceColors)
1763+
{
1764+
Application.Current.Resources[item.Key] = item.Value;
1765+
}
1766+
}
1767+
1768+
private void ChkUseCustomTheme_Checked(object sender, RoutedEventArgs e)
1769+
{
1770+
var isChecked = (bool)((CheckBox)sender).IsChecked;
1771+
Properties.Settings.Default.useCustomTheme = isChecked;
1772+
Properties.Settings.Default.Save();
1773+
1774+
// reset colors now
1775+
if (isChecked == true)
1776+
{
1777+
ApplyTheme();
1778+
}
1779+
else
1780+
{
1781+
ResetTheme();
1782+
}
1783+
}
1784+
17491785

17501786
} // class
17511787
} //namespace

UnityLauncherPro/Properties/Settings.Designer.cs

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnityLauncherPro/Properties/Settings.settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,8 @@
6262
<Setting Name="webglBuildPath" Type="System.String" Scope="User">
6363
<Value Profile="(Default)" />
6464
</Setting>
65+
<Setting Name="useCustomTheme" Type="System.Boolean" Scope="User">
66+
<Value Profile="(Default)">False</Value>
67+
</Setting>
6568
</Settings>
6669
</SettingsFile>
Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
11
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:local="clr-namespace:UnityLauncherPro">
4-
<SolidColorBrush x:Key="DarkestBackground" Color="#FF121212"/>
5-
<SolidColorBrush x:Key="DarkMenuBar" Color="#FF0C0C0C"/>
6-
<SolidColorBrush x:Key="MainBackgroundColor" Color="#FF262626"/>
7-
<SolidColorBrush x:Key="TextBoxBackground" Color="#FF333337"/>
8-
<SolidColorBrush x:Key="ButtonBackground" Color="#FF3F3F46"/>
9-
<SolidColorBrush x:Key="ButtonForeground" Color="#FFC1C1C1"/>
10-
<SolidColorBrush x:Key="DeactiveTabForeground" Color="#FFC1C1C1"/>
11-
<SolidColorBrush x:Key="DeactiveTabBackground" Color="#FF1D1D1D"/>
12-
<SolidColorBrush x:Key="DatagridHeaderBackground" Color="#4C3F3F46"/>
13-
<SolidColorBrush x:Key="DatagridHeaderForeground" Color="#FFB6B6B6"/>
14-
<SolidColorBrush x:Key="DatagridHeaderBorder" Color="#4C000000"/>
15-
<SolidColorBrush x:Key="DataGridRowMouseOver" Color="#7F007ACC"/>
16-
<SolidColorBrush x:Key="DataGridRowSelectedBackground" Color="#FF007ACC"/>
17-
<SolidColorBrush x:Key="ScrollArrowPressed" Color="#FF838383"/>
18-
<SolidColorBrush x:Key="ScrollArrowForeground" Color="#FF5E5E64"/>
19-
<SolidColorBrush x:Key="ScrollBarThumbFill" Color="#FF6A6969"/>
20-
<SolidColorBrush x:Key="ScrollBarBackground" Color="#FF151515"/>
21-
<SolidColorBrush x:Key="ScrollBarFill" Color="#FF47474B"/>
4+
<SolidColorBrush x:Key="ThemeDarkestBackground" Color="#FF121212"/>
5+
<SolidColorBrush x:Key="ThemeDarkMenuBar" Color="#FF0C0C0C"/>
6+
<SolidColorBrush x:Key="ThemeMainBackgroundColor" Color="#FF262626"/>
7+
<SolidColorBrush x:Key="ThemeTextBoxBackground" Color="#FF333337"/>
8+
<SolidColorBrush x:Key="ThemeButtonBackground" Color="#FF3F3F46"/>
9+
<SolidColorBrush x:Key="ThemeButtonForeground" Color="#FFC1C1C1"/>
10+
<SolidColorBrush x:Key="ThemeDeactiveTabForeground" Color="#FFC1C1C1"/>
11+
<SolidColorBrush x:Key="ThemeDeactiveTabBackground" Color="#FF1D1D1D"/>
12+
<SolidColorBrush x:Key="ThemeDatagridHeaderBackground" Color="#4C3F3F46"/>
13+
<SolidColorBrush x:Key="ThemeDatagridHeaderForeground" Color="#FFB6B6B6"/>
14+
<SolidColorBrush x:Key="ThemeDatagridHeaderBorder" Color="#4C000000"/>
15+
<SolidColorBrush x:Key="ThemeDataGridRowMouseOver" Color="#7F007ACC"/>
16+
<SolidColorBrush x:Key="ThemeDataGridRowSelectedBackground" Color="#FF007ACC"/>
17+
<SolidColorBrush x:Key="ThemeScrollArrowPressed" Color="#FF838383"/>
18+
<SolidColorBrush x:Key="ThemeScrollArrowForeground" Color="#FF5E5E64"/>
19+
<SolidColorBrush x:Key="ThemeScrollBarThumbFill" Color="#FF6A6969"/>
20+
<SolidColorBrush x:Key="ThemeScrollBarBackground" Color="#FF151515"/>
21+
<SolidColorBrush x:Key="ThemeScrollBarFill" Color="#FF47474B"/>
2222

2323
<!--custom components-->
24-
<SolidColorBrush x:Key="ButtonForegroundDisabled" Color="#FF707070"/>
25-
<SolidColorBrush x:Key="ButtonBackgroundMouseOver" Color="#FF494949"/>
26-
<SolidColorBrush x:Key="ButtonWhiteText" Color="#FFFFFFFF"/>
27-
<SolidColorBrush x:Key="ButtonBackgroundPressed" Color="#FF0F0F0F"/>
28-
<SolidColorBrush x:Key="MainTitle" Color="#FFB8B8B8"/>
29-
<SolidColorBrush x:Key="ScrollBarEnabledForeground" Color="#FF000000"/>
24+
<SolidColorBrush x:Key="ThemeButtonForegroundDisabled" Color="#FF707070"/>
25+
<SolidColorBrush x:Key="ThemeButtonBackgroundMouseOver" Color="#FF494949"/>
26+
<SolidColorBrush x:Key="ThemeButtonWhiteText" Color="#FFFFFFFF"/>
27+
<SolidColorBrush x:Key="ThemeButtonBackgroundPressed" Color="#FF0F0F0F"/>
28+
<SolidColorBrush x:Key="ThemeMainTitle" Color="#FFB8B8B8"/>
29+
<SolidColorBrush x:Key="ThemeScrollBarEnabledForeground" Color="#FF000000"/>
3030

3131
<!--search-->
32-
<SolidColorBrush x:Key="SearchPlaceholder" Color="#7F919191"/>
33-
<SolidColorBrush x:Key="SearchClose" Color="#A3C1C1C1"/>
34-
<SolidColorBrush x:Key="SearchCaret" Color="#FFE2E2E2"/>
35-
<SolidColorBrush x:Key="SearchForeground" Color="#FFC7C7C7"/>
36-
<SolidColorBrush x:Key="SearchSelection" Color="#FF003966"/>
32+
<SolidColorBrush x:Key="ThemeSearchPlaceholder" Color="#7F919191"/>
33+
<SolidColorBrush x:Key="ThemeSearchClose" Color="#A3C1C1C1"/>
34+
<SolidColorBrush x:Key="ThemeSearchCaret" Color="#FFE2E2E2"/>
35+
<SolidColorBrush x:Key="ThemeSearchForeground" Color="#FFC7C7C7"/>
36+
<SolidColorBrush x:Key="ThemeSearchSelection" Color="#FF003966"/>
3737

3838
<!--window-->
39-
<SolidColorBrush x:Key="WindowMinClose" Color="#FFC3C3C3"/>
39+
<SolidColorBrush x:Key="ThemeWindowMinClose" Color="#FFC3C3C3"/>
4040

4141
<!--grids-->
42-
<SolidColorBrush x:Key="GridForeground" Color="#FFD8D8D8"/>
43-
<SolidColorBrush x:Key="GridHorizontalGridLines" Color="#4C000000"/>
44-
<SolidColorBrush x:Key="GridVerticalGridLines" Color="#19000000"/>
45-
<SolidColorBrush x:Key="GridGreenText" Color="#FF00C500"/>
46-
<SolidColorBrush x:Key="GridRedText" Color="#FFF54F4F"/>
42+
<SolidColorBrush x:Key="ThemeGridForeground" Color="#FFD8D8D8"/>
43+
<SolidColorBrush x:Key="ThemeGridHorizontalGridLines" Color="#4C000000"/>
44+
<SolidColorBrush x:Key="ThemeGridVerticalGridLines" Color="#19000000"/>
45+
<SolidColorBrush x:Key="ThemeGridGreenText" Color="#FF00C500"/>
46+
<SolidColorBrush x:Key="ThemeGridRedText" Color="#FFF54F4F"/>
4747

4848
<!--statusbar-->
49-
<SolidColorBrush x:Key="StatusText" Color="#FF595959"/>
49+
<SolidColorBrush x:Key="ThemeStatusText" Color="#FF595959"/>
5050

5151
</ResourceDictionary>

0 commit comments

Comments
 (0)