Skip to content

Commit 3a47f31

Browse files
committed
add theme loader options (theme filename, theme reload, save/load to settings)
1 parent 779f957 commit 3a47f31

File tree

5 files changed

+84
-20
lines changed

5 files changed

+84
-20
lines changed

UnityLauncherPro/App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@
7272
<setting name="useCustomTheme" serializeAs="String">
7373
<value>False</value>
7474
</setting>
75+
<setting name="themeFile" serializeAs="String">
76+
<value>theme.ini</value>
77+
</setting>
7578
</UnityLauncherPro.Properties.Settings>
7679
</userSettings>
7780
</configuration>

UnityLauncherPro/MainWindow.xaml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -695,19 +695,23 @@
695695
</StackPanel>
696696
<!-- settings-->
697697
<StackPanel Grid.Row="3" Orientation="Vertical" Margin="5,10,3,3" >
698-
<CheckBox x:Name="chkMinimizeToTaskbar" Content="Minimize to tray" Foreground="{DynamicResource ThemeButtonForeground}" Checked="ChkMinimizeToTaskbar_CheckedChanged" Unchecked="ChkMinimizeToTaskbar_CheckedChanged" Margin="0,0,0,4" ToolTip="When window is minimized, hides application into taskbar icon area"/>
699-
<CheckBox x:Name="chkRegisterExplorerMenu" Content="Register Explorer context menu" Foreground="{DynamicResource ThemeButtonForeground}" Unchecked="ChkRegisterExplorerMenu_CheckedChanged" Checked="ChkRegisterExplorerMenu_CheckedChanged" Margin="0,0,0,4" ToolTip="Install registry entry for Explorer context menu"/>
700-
<CheckBox x:Name="chkQuitAfterOpen" Content="Close after opening project" Foreground="{DynamicResource ThemeButtonForeground}" Checked="ChkQuitAfterOpen_CheckedChanged" Unchecked="ChkQuitAfterOpen_CheckedChanged" Margin="0,0,0,4" ToolTip="Closes launcher after running project (not really useful)"/>
701-
<CheckBox x:Name="chkQuitAfterCommandline" Content="Close after launching from Explorer" Foreground="{DynamicResource ThemeButtonForeground}" Unchecked="ChkQuitAfterCommandline_CheckedChanged" Checked="ChkQuitAfterCommandline_CheckedChanged" Margin="0,0,0,4" ToolTip="Close launcher after running from commandline or Explorer (recommended)"/>
702-
<CheckBox x:Name="chkShowLauncherArgumentsColumn" Content="Show commandline arguments column" Foreground="{DynamicResource ThemeButtonForeground}" Unchecked="ChkShowLauncherArgumentsColumn_CheckedChanged" Checked="ChkShowLauncherArgumentsColumn_CheckedChanged" Margin="0,0,0,4" ToolTip="Shows column for custom project commandline params"/>
703-
<CheckBox x:Name="chkShowGitBranchColumn" Content="Show git branch column" Foreground="{DynamicResource ThemeButtonForeground}" Checked="ChkShowGitBranchColumn_CheckedChanged" Unchecked="ChkShowGitBranchColumn_CheckedChanged" Margin="0,0,0,4" ToolTip="Shows column for project git branch info"/>
704-
<CheckBox x:Name="chkShowMissingFolderProjects" Content="Show projects that don't exist on disk" Foreground="{DynamicResource ThemeButtonForeground}" Checked="ChkShowMissingFolderProjects_CheckedChanged" Unchecked="ChkShowMissingFolderProjects_CheckedChanged" Margin="0,0,0,4" ToolTip="List in recent projects, even if the project folder is missing"/>
705-
<CheckBox x:Name="chkAllowSingleInstanceOnly" Content="Allow single instance only" Foreground="{DynamicResource ThemeButtonForeground}" Checked="ChkAllowSingleInstanceOnly_CheckedChanged" Unchecked="ChkAllowSingleInstanceOnly_CheckedChanged" Margin="0,0,0,4" ToolTip="Activates already running instance, instead of starting new exe (not working if app is minized to taskbar)"/>
706-
<CheckBox x:Name="chkEnableProjectRename" Content="Enable Project Rename F2 (Not recommended for beginners)" Foreground="{DynamicResource ThemeButtonForeground}" Margin="0,0,0,4" ToolTip="Can use F2 to rename project folders, Note that project will disappears from list on refresh, unless you open it (since its new path, not in unity recent projects registry)" Checked="ChkEnableProjectRename_Checked" Unchecked="ChkEnableProjectRename_Checked"/>
707-
<CheckBox x:Name="chkAskNameForQuickProject" Content="Ask name for New Project" Foreground="{DynamicResource ThemeButtonForeground}" Checked="ChkAskNameForQuickProject_Checked" Unchecked="ChkAskNameForQuickProject_Checked" Margin="0,0,0,4" ToolTip="If disabled, uses automatic quick project naming"/>
708-
<CheckBox x:Name="chkStreamerMode" Content="Streamer Mode (hide project names and folders)" Foreground="{DynamicResource ThemeButtonForeground}" Margin="0,0,0,4" ToolTip="Hide project names and folders in main view" Checked="ChkStreamerMode_Checked" Unchecked="ChkStreamerMode_Checked"/>
709-
<CheckBox x:Name="chkShowPlatform" Content="Show current target platform (if exists in .csproj)" Foreground="{DynamicResource ThemeButtonForeground}" Margin="0,0,0,4" ToolTip="Shows target platform column" Checked="ChkShowPlatform_Checked" Unchecked="ChkShowPlatform_Checked"/>
710-
<CheckBox x:Name="chkUseCustomTheme" Content="Use custom theme" Foreground="{DynamicResource ThemeButtonForeground}" Margin="0,0,0,4" ToolTip="Loads theme.ini from application folder" Checked="ChkUseCustomTheme_Checked" Unchecked="ChkUseCustomTheme_Checked"/>
698+
<CheckBox x:Name="chkMinimizeToTaskbar" Content="Minimize to tray" Foreground="{DynamicResource ThemeButtonForeground}" Checked="ChkMinimizeToTaskbar_CheckedChanged" Unchecked="ChkMinimizeToTaskbar_CheckedChanged" Margin="0,0,0,4" ToolTip="When window is minimized, hides application into taskbar icon area" HorizontalAlignment="Left"/>
699+
<CheckBox x:Name="chkRegisterExplorerMenu" Content="Register Explorer context menu" Foreground="{DynamicResource ThemeButtonForeground}" Unchecked="ChkRegisterExplorerMenu_CheckedChanged" Checked="ChkRegisterExplorerMenu_CheckedChanged" Margin="0,0,0,4" ToolTip="Install registry entry for Explorer context menu" HorizontalAlignment="Left"/>
700+
<CheckBox x:Name="chkQuitAfterOpen" Content="Close after opening project" Foreground="{DynamicResource ThemeButtonForeground}" Checked="ChkQuitAfterOpen_CheckedChanged" Unchecked="ChkQuitAfterOpen_CheckedChanged" Margin="0,0,0,4" ToolTip="Closes launcher after running project (not really useful)" HorizontalAlignment="Left"/>
701+
<CheckBox x:Name="chkQuitAfterCommandline" Content="Close after launching from Explorer" Foreground="{DynamicResource ThemeButtonForeground}" Unchecked="ChkQuitAfterCommandline_CheckedChanged" Checked="ChkQuitAfterCommandline_CheckedChanged" Margin="0,0,0,4" ToolTip="Close launcher after running from commandline or Explorer (recommended)" HorizontalAlignment="Left"/>
702+
<CheckBox x:Name="chkShowLauncherArgumentsColumn" Content="Show commandline arguments column" Foreground="{DynamicResource ThemeButtonForeground}" Unchecked="ChkShowLauncherArgumentsColumn_CheckedChanged" Checked="ChkShowLauncherArgumentsColumn_CheckedChanged" Margin="0,0,0,4" ToolTip="Shows column for custom project commandline params" HorizontalAlignment="Left"/>
703+
<CheckBox x:Name="chkShowGitBranchColumn" Content="Show git branch column" Foreground="{DynamicResource ThemeButtonForeground}" Checked="ChkShowGitBranchColumn_CheckedChanged" Unchecked="ChkShowGitBranchColumn_CheckedChanged" Margin="0,0,0,4" ToolTip="Shows column for project git branch info" HorizontalAlignment="Left"/>
704+
<CheckBox x:Name="chkShowMissingFolderProjects" Content="Show projects that don't exist on disk" Foreground="{DynamicResource ThemeButtonForeground}" Checked="ChkShowMissingFolderProjects_CheckedChanged" Unchecked="ChkShowMissingFolderProjects_CheckedChanged" Margin="0,0,0,4" ToolTip="List in recent projects, even if the project folder is missing" HorizontalAlignment="Left"/>
705+
<CheckBox x:Name="chkAllowSingleInstanceOnly" Content="Allow single instance only" Foreground="{DynamicResource ThemeButtonForeground}" Checked="ChkAllowSingleInstanceOnly_CheckedChanged" Unchecked="ChkAllowSingleInstanceOnly_CheckedChanged" Margin="0,0,0,4" ToolTip="Activates already running instance, instead of starting new exe (not working if app is minized to taskbar)" HorizontalAlignment="Left"/>
706+
<CheckBox x:Name="chkEnableProjectRename" Content="Enable Project Rename F2 (Not recommended for beginners)" Foreground="{DynamicResource ThemeButtonForeground}" Margin="0,0,0,4" ToolTip="Can use F2 to rename project folders, Note that project will disappears from list on refresh, unless you open it (since its new path, not in unity recent projects registry)" Checked="ChkEnableProjectRename_Checked" Unchecked="ChkEnableProjectRename_Checked" HorizontalAlignment="Left"/>
707+
<CheckBox x:Name="chkAskNameForQuickProject" Content="Ask name for New Project" Foreground="{DynamicResource ThemeButtonForeground}" Checked="ChkAskNameForQuickProject_Checked" Unchecked="ChkAskNameForQuickProject_Checked" Margin="0,0,0,4" ToolTip="If disabled, uses automatic quick project naming" HorizontalAlignment="Left"/>
708+
<CheckBox x:Name="chkStreamerMode" Content="Streamer Mode (hide project names and folders)" Foreground="{DynamicResource ThemeButtonForeground}" Margin="0,0,0,4" ToolTip="Hide project names and folders in main view" Checked="ChkStreamerMode_Checked" Unchecked="ChkStreamerMode_Checked" HorizontalAlignment="Left"/>
709+
<CheckBox x:Name="chkShowPlatform" Content="Show current target platform (if exists in .csproj)" Foreground="{DynamicResource ThemeButtonForeground}" Margin="0,0,0,4" ToolTip="Shows target platform column" Checked="ChkShowPlatform_Checked" Unchecked="ChkShowPlatform_Checked" HorizontalAlignment="Left"/>
710+
<StackPanel Grid.Row="3" Orientation="Horizontal" Margin="0,0,0,4">
711+
<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"/>
712+
<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" />
713+
<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"/>
714+
</StackPanel>
711715

712716
<StackPanel Grid.Row="3" Orientation="Horizontal" Margin="0,0,0,4">
713717
<TextBox x:Name="txtRootFolderForNewProjects" MinWidth="300" ToolTip="When you click &quot;Create Project&quot; in main page, new project is generated under this path+UnityVersion (eg. /2017a/)" Padding="0,3,0,0" TextChanged="TxtRootFolderForNewProjects_TextChanged" />

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public partial class MainWindow : Window
5050
Mutex myMutex;
5151

5252
Dictionary<string, SolidColorBrush> origResourceColors = new Dictionary<string, SolidColorBrush>();
53+
string themefile = "theme.ini";
5354

5455
public MainWindow()
5556
{
@@ -270,6 +271,8 @@ void LoadSettings()
270271
chkUseCustomTheme.IsChecked = Properties.Settings.Default.useCustomTheme;
271272
txtRootFolderForNewProjects.Text = Properties.Settings.Default.newProjectsRoot;
272273
txtWebglRelativePath.Text = Properties.Settings.Default.webglBuildPath;
274+
themefile = Properties.Settings.Default.themeFile;
275+
txtCustomThemeFile.Text = themefile;
273276

274277
// update optional grid columns, hidden or visible
275278
gridRecent.Columns[4].Visibility = (bool)chkShowLauncherArgumentsColumn.IsChecked ? Visibility.Visible : Visibility.Collapsed;
@@ -1732,11 +1735,7 @@ void ApplyTheme()
17321735
{
17331736
if (chkUseCustomTheme.IsChecked == false) return;
17341737

1735-
// 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)
1736-
// TODO set colors to resources
1737-
1738-
// TEST
1739-
var themefile = "theme.ini";
1738+
Console.WriteLine("Load theme: " + themefile);
17401739

17411740
if (File.Exists(themefile))
17421741
{
@@ -1751,8 +1750,19 @@ void ApplyTheme()
17511750
var row = colors[i].Split('=');
17521751
// skip bad rows
17531752
if (row.Length != 2) continue;
1754-
// apply color
1755-
Application.Current.Resources[row[0]] = (SolidColorBrush)(new BrushConverter().ConvertFrom(row[1].Trim()));
1753+
1754+
// parse color
1755+
try
1756+
{
1757+
var col = new BrushConverter().ConvertFrom(row[1].Trim());
1758+
// apply color
1759+
Application.Current.Resources[row[0]] = (SolidColorBrush)col;
1760+
}
1761+
catch (Exception e)
1762+
{
1763+
Console.WriteLine(e);
1764+
}
1765+
17561766
}
17571767
}
17581768
}
@@ -1771,6 +1781,8 @@ private void ChkUseCustomTheme_Checked(object sender, RoutedEventArgs e)
17711781
Properties.Settings.Default.useCustomTheme = isChecked;
17721782
Properties.Settings.Default.Save();
17731783

1784+
btnReloadTheme.IsEnabled = isChecked;
1785+
17741786
// reset colors now
17751787
if (isChecked == true)
17761788
{
@@ -1782,6 +1794,36 @@ private void ChkUseCustomTheme_Checked(object sender, RoutedEventArgs e)
17821794
}
17831795
}
17841796

1797+
private void BtnReloadTheme_Click(object sender, RoutedEventArgs e)
1798+
{
1799+
ApplyTheme();
1800+
}
1801+
1802+
private void TxtCustomThemeFile_LostFocus(object sender, RoutedEventArgs e)
1803+
{
1804+
var s = (TextBox)sender;
1805+
themefile = s.Text;
1806+
1807+
Properties.Settings.Default.themeFile = themefile;
1808+
Properties.Settings.Default.Save();
1809+
}
1810+
1811+
private void TxtCustomThemeFile_PreviewKeyDown(object sender, KeyEventArgs e)
1812+
{
1813+
switch (e.Key)
1814+
{
1815+
case Key.Return: // pressed enter in theme file text box
1816+
Console.WriteLine(txtCustomThemeFile.Text);
1817+
themefile = txtCustomThemeFile.Text;
1818+
1819+
Properties.Settings.Default.themeFile = themefile;
1820+
Properties.Settings.Default.Save();
1821+
1822+
btnReloadTheme.Focus();
1823+
break;
1824+
}
1825+
}
1826+
17851827

17861828
} // class
17871829
} //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
@@ -65,5 +65,8 @@
6565
<Setting Name="useCustomTheme" Type="System.Boolean" Scope="User">
6666
<Value Profile="(Default)">False</Value>
6767
</Setting>
68+
<Setting Name="themeFile" Type="System.String" Scope="User">
69+
<Value Profile="(Default)">theme.ini</Value>
70+
</Setting>
6871
</Settings>
6972
</SettingsFile>

0 commit comments

Comments
 (0)