Skip to content

Commit

Permalink
Got custom colours working including saving between sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
pekempy committed Jan 30, 2019
1 parent 5ad169d commit a2481f4
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 115 deletions.
10 changes: 2 additions & 8 deletions App.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,10 @@
<setting name="theme" serializeAs="String">
<value>dark</value>
</setting>
<setting name="primarylight" serializeAs="String">
<setting name="primary" serializeAs="String">
<value />
</setting>
<setting name="accentlight" serializeAs="String">
<value />
</setting>
<setting name="primarydark" serializeAs="String">
<value />
</setting>
<setting name="accentdark" serializeAs="String">
<setting name="accent" serializeAs="String">
<value />
</setting>
</GameLauncher.Properties.Settings>
Expand Down
2 changes: 2 additions & 0 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ public void LoadSettings()
//Theme Light or Dark
if (Settings.Default.theme.ToString() == "Dark") { ThemeAssist.SetTheme(Application.Current.MainWindow, BaseTheme.Dark); }
else if (Settings.Default.theme.ToString() == "Light") { ThemeAssist.SetTheme(Application.Current.MainWindow, BaseTheme.Light); }
if (Settings.Default.primary.ToString() != "") { new PaletteHelper().ReplacePrimaryColor(Settings.Default.primary.ToString()); }
if (Settings.Default.accent.ToString() != "") { new PaletteHelper().ReplaceAccentColor(Settings.Default.accent.ToString()); }
}
}
}
38 changes: 7 additions & 31 deletions Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 2 additions & 8 deletions Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@
<Setting Name="theme" Type="System.String" Scope="User">
<Value Profile="(Default)">dark</Value>
</Setting>
<Setting Name="primarylight" Type="System.String" Scope="User">
<Setting Name="primary" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="accentlight" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="primarydark" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="accentdark" Type="System.String" Scope="User">
<Setting Name="accent" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
Expand Down
4 changes: 2 additions & 2 deletions Views/PosterView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public void RefreshList()
public void RefreshList2(CollectionViewSource cvscvs)
{
GameListCVS = cvscvs;
if (FilterGenreName != null) { GameListCVS.Filter += new FilterEventHandler(GenreFilter); }
if (GameSearchBar.Text != null) { GameListCVS.Filter += new FilterEventHandler(GameSearch); }
if (FilterGenreName != null || FilterGenreName != "") { GameListCVS.Filter += new FilterEventHandler(GenreFilter); }
if (GameSearchBar.Text != null) {GameListCVS.Filter += new FilterEventHandler(GameSearch); }
if (GameListCVS.View != null) //This is getting a null "GameListCVS.View" on genre only, works if searchbar updated
GameListCVS.View.Refresh();
}
Expand Down
104 changes: 76 additions & 28 deletions Views/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,35 +73,83 @@
Grid.ColumnSpan="4" Grid.RowSpan="10"
Visibility="{Binding Path=IsChecked, ElementName=ThemeBtn, Converter={StaticResource b2v}}">
<!-- CONTENT OF THE THEMES TAB GOES IN HERE -->
<StackPanel HorizontalAlignment="Left">
<TextBlock Height="40">Enable Dark Mode</TextBlock>
<TextBlock Height="40">Primary Color (coming soon)</TextBlock>
<TextBlock Height="40">Accent Color (coming soon)</TextBlock>
</StackPanel>
<StackPanel HorizontalAlignment="Right" Width="85">
<ToggleButton x:Name="themeToggle"
HorizontalAlignment="Right"
Style="{StaticResource MaterialDesignSwitchAccentToggleButton}"
Checked="DarkModeToggle_Checked"
Unchecked="DarkModeToggle_Unchecked"
VerticalAlignment="Top"
Margin="0 0 20 0"/>
<StackPanel Orientation="Horizontal" Margin="0 15 0 0" Width="90">
<TextBox x:Name="ColorPrimary"
Width="60"
Height="30"
materialDesign:HintAssist.Hint="Hex Code"
KeyDown="ChangePrimary"
MaxLength="6"/>
<Rectangle x:Name="ColorPrimaryRect" Height="25" Width="25" Fill="White" />
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock>Enable Dark Mode</TextBlock>
<ToggleButton x:Name="themeToggle"
Style="{StaticResource MaterialDesignSwitchAccentToggleButton}"
Margin="60 0 0 0"
HorizontalAlignment="Right"
Checked="DarkModeToggle_Checked"
Unchecked="DarkModeToggle_Unchecked" />
</StackPanel>
<TextBlock />
<TextBlock HorizontalAlignment="Left" Width="160" Height="16" VerticalAlignment="Top"><Run Text="Primary Colour"/></TextBlock>
<StackPanel Margin="0 5 0 0" Height="125" VerticalAlignment="Top">
<WrapPanel Width="auto" Height="125">
<!-- Row One Buttons (PRIMARY) -->
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="PPink" Background="#e91e63" Tag="Pink" Click="ChangePrimary_OnClick"/>
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="PRed" Background="#f44336" Tag="Red" Click="ChangePrimary_OnClick"/>
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="PDeepOrange" Background="#ff5722" Tag="DeepOrange" Click="ChangePrimary_OnClick"/>
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="POrange" Background="#ffc107" Tag="Orange" Click="ChangePrimary_OnClick"/>
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="PYellow" Background="#ffeb3b" Tag="Yellow" Click="ChangePrimary_OnClick"/>
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="PLime" Background="#8bc34a" Tag="Lime" Click="ChangePrimary_OnClick" />
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="PGreen" Background="#4caf50" Tag="Green" Click="ChangePrimary_OnClick" />
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="PTeal" Background="#009688" Tag="Teal" Click="ChangePrimary_OnClick" />
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="PCyan" Background="#00bcd4" Tag="Cyan" Click="ChangePrimary_OnClick" />
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="PBlue" Background="#3369e8" Tag="Blue" Click="ChangePrimary_OnClick" />
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="PIndigo" Background="#3f51b5" Tag="Indigo" Click="ChangePrimary_OnClick" />
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="PDeepPurple" Background="#673ab7" Tag="DeepPurple" Click="ChangePrimary_OnClick" />
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="PPurple" Background="#9c27b0" Tag="Purple" Click="ChangePrimary_OnClick" />
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="PBlueGrey" Background="#607d8b" Tag="BlueGrey" Click="ChangePrimary_OnClick" />
</WrapPanel>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0 5 0 0" Width="90">
<TextBox x:Name="ColorAccent"
Width="60"
Height="30"
materialDesign:HintAssist.Hint="Hex Code"
KeyDown="ChangeAccent" />
<Rectangle x:Name="ColorAccentRect" Height="25" Width="25" Fill="White" />
<TextBlock />
<TextBlock HorizontalAlignment="Left" Width="160" Height="16" VerticalAlignment="Top"><Run Text="Accent Colour"/></TextBlock>
<StackPanel Margin="0 5 0 0" Height="125" VerticalAlignment="Top">
<WrapPanel Width="auto" Height="125">
<!-- Row Two Buttons (ACCENT) -->
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="APink" Background="#e91e63" Tag="Pink" Click="ChangeAccent_OnClick"/>
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="ARed" Background="#f44336" Tag="Red" Click="ChangeAccent_OnClick"/>
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="ADeepOrange" Background="#ff5722" Tag="DeepOrange" Click="ChangeAccent_OnClick"/>
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="AOrange" Background="#ffc107" Tag="Orange" Click="ChangeAccent_OnClick"/>
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="AYellow" Background="#ffeb3b" Tag="Yellow" Click="ChangeAccent_OnClick"/>
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="ALime" Background="#8bc34a" Tag="Lime" Click="ChangeAccent_OnClick" />
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="AGreen" Background="#4caf50" Tag="Green" Click="ChangeAccent_OnClick" />
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="ATeal" Background="#009688" Tag="Teal" Click="ChangeAccent_OnClick" />
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="ACyan" Background="#00bcd4" Tag="Cyan" Click="ChangeAccent_OnClick" />
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="ABlue" Background="#3369e8" Tag="Blue" Click="ChangeAccent_OnClick" />
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="AIndigo" Background="#3f51b5" Tag="Indigo" Click="ChangeAccent_OnClick" />
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="ADeepPurple" Background="#673ab7" Tag="DeepPurple" Click="ChangeAccent_OnClick" />
<Button Margin="5,5,5,5" MaxHeight="50" MaxWidth="50" BorderThickness="0"
x:Name="APurple" Background="#9c27b0" Tag="Purple" Click="ChangeAccent_OnClick" />
</WrapPanel>
</StackPanel>
</StackPanel>
</Grid>
Expand Down
50 changes: 12 additions & 38 deletions Views/SettingsView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ public SettingsView()
InitializeComponent();
var converter = new System.Windows.Media.BrushConverter();
if (Settings.Default.theme == "Dark") { themeToggle.IsChecked = true; }
if (Settings.Default.primarylight != "")
{
ColorPrimary.Text = Settings.Default.primarylight;
ColorPrimaryRect.Fill = (Brush)converter.ConvertFromString("#" + ColorPrimary.Text);
}
if (Settings.Default.accentlight != "")
{
ColorAccent.Text = Settings.Default.accentlight;
ColorAccentRect.Fill = (Brush)converter.ConvertFromString("#" + ColorAccent.Text);
}
}

private void DarkModeToggle_Checked(object sender, RoutedEventArgs e)
Expand All @@ -52,38 +42,22 @@ private void DarkModeToggle_Unchecked(object sender, RoutedEventArgs e)
SaveSettings();
}

private void ChangePrimary(object sender, KeyEventArgs e)
private void ChangePrimary_OnClick(object sender, RoutedEventArgs e)
{
if (e.Key == Key.Return)
{
var regexColorCode = new Regex("^#[a-fA-F0-9]{6}$");
if (regexColorCode.IsMatch("#" + ColorPrimary.Text.Trim()))
{
var converter = new System.Windows.Media.BrushConverter();
var brush = (Brush)converter.ConvertFromString("#" + ColorPrimary.Text);
Properties.Settings.Default.primarylight = ColorPrimary.Text;
SaveSettings();
ColorPrimaryRect.Fill = brush;
//new PaletteHelper().ReplacePrimaryColor(brush.ToString());
//brush.ToString() doesn't work lol, needs a "swatch"
}
}
Console.WriteLine(((Button)sender).Tag.ToString());
string newPrimaryColour = ((Button)sender).Tag.ToString();
new PaletteHelper().ReplacePrimaryColor(newPrimaryColour);
Properties.Settings.Default.primary = newPrimaryColour;
SaveSettings();
}

private void ChangeAccent(object sender, KeyEventArgs e)
private void ChangeAccent_OnClick(object sender, RoutedEventArgs e)
{
if (e.Key == Key.Return)
{
var regexColorCode = new Regex("^#[a-fA-F0-9]{6}$");
if (regexColorCode.IsMatch("#" + ColorPrimary.Text.Trim()))
{
var converter = new System.Windows.Media.BrushConverter();
var brush = (Brush)converter.ConvertFromString("#" + ColorAccent.Text);
Properties.Settings.Default.accentlight = ColorAccent.Text;
SaveSettings();
ColorAccentRect.Fill = brush;
}
}
Console.WriteLine(((Button)sender).Tag.ToString());
string newAccentColour = ((Button)sender).Tag.ToString();
new PaletteHelper().ReplaceAccentColor(newAccentColour);
Properties.Settings.Default.accent = newAccentColour;
SaveSettings();
}


Expand Down

0 comments on commit a2481f4

Please sign in to comment.