Skip to content

Commit b21a699

Browse files
committed
adding/testing theme color editor
1 parent 4349e8a commit b21a699

File tree

5 files changed

+118
-15
lines changed

5 files changed

+118
-15
lines changed

UnityLauncherPro/Data/ThemeColor.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.ComponentModel;
3+
using System.Globalization;
4+
using System.Windows.Data;
5+
using System.Windows.Media;
6+
7+
namespace UnityLauncherPro
8+
{
9+
public class ThemeColor : IValueConverter
10+
{
11+
public string Key { get; set; }
12+
public SolidColorBrush Brush { get; set; }
13+
14+
15+
object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
16+
{
17+
return (SolidColorBrush)value;
18+
}
19+
20+
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
21+
{
22+
throw new NotImplementedException();
23+
}
24+
}
25+
}

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ void Start()
136136

137137
}
138138

139+
// TEST
140+
themeEditorWindow = new ThemeEditor();
141+
themeEditorWindow.Show();
142+
139143
isInitializing = false;
140144
}
141145

UnityLauncherPro/ThemeEditor.xaml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,33 @@
171171
</Style.Triggers>
172172
</Style>
173173

174+
<local:ThemeColor x:Key="SolidColorBrushConverter"/>
175+
174176
</Window.Resources>
175177

176178
<Grid>
177179
<Grid.RowDefinitions>
178180
<RowDefinition Height="300"/>
179181
<RowDefinition Height="*"/>
180182
</Grid.RowDefinitions>
183+
<!--<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">-->
181184
<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">
182185
<DataGrid.Columns>
183186
<DataGridTextColumn Header="Key" Binding="{Binding Key}" IsReadOnly="True" CanUserResize="False"/>
184-
<DataGridTextColumn Header="Value" Binding="{Binding Value}" IsReadOnly="True" CanUserResize="False"/>
187+
<DataGridTextColumn Header="Value" Binding="{Binding Brush}" IsReadOnly="True" CanUserResize="False">
188+
<DataGridTextColumn.CellStyle>
189+
<Style TargetType="{x:Type DataGridCell}">
190+
<!--TODO make this color opposise of background-->
191+
<Setter Property="Foreground" Value="White" />
192+
<Setter Property="Background" Value="{Binding Brush, Converter={StaticResource SolidColorBrushConverter}}" />
193+
<Style.Triggers>
194+
<DataTrigger Binding="{Binding Brush, Converter={StaticResource SolidColorBrushConverter}}" Value="true">
195+
<Setter Property="Foreground" Value="{DynamicResource ThemeGridGreenText}" />
196+
</DataTrigger>
197+
</Style.Triggers>
198+
</Style>
199+
</DataGridTextColumn.CellStyle>
200+
</DataGridTextColumn>
185201
</DataGrid.Columns>
186202
</DataGrid>
187203
<!--tools-->
@@ -204,6 +220,11 @@
204220
<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"/>
205221
<TextBox x:Name="txtBlue" VerticalAlignment="Center" IsUndoEnabled="True" Width="32" Margin="5,0,0,8" IsReadOnly="True" />
206222
</StackPanel>
223+
<StackPanel Orientation="Horizontal">
224+
<Label Foreground="{DynamicResource ThemeButtonForeground}" Width="40">Alpha</Label>
225+
<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"/>
226+
<TextBox x:Name="txtAlpha" VerticalAlignment="Center" IsUndoEnabled="True" Width="32" Margin="5,0,0,8" IsReadOnly="True" />
227+
</StackPanel>
207228
</StackPanel>
208229

209230
<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">

UnityLauncherPro/ThemeEditor.xaml.cs

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4+
using System.Collections.ObjectModel;
5+
using System.Data;
46
using System.Windows;
57
using System.Windows.Controls;
68
using System.Windows.Media;
@@ -10,7 +12,9 @@ namespace UnityLauncherPro
1012
public partial class ThemeEditor : Window
1113
{
1214
// TODO take from mainwindow?
13-
Dictionary<string, SolidColorBrush> origResourceColors = new Dictionary<string, SolidColorBrush>();
15+
//Dictionary<string, SolidColorBrush> origResourceColors = new Dictionary<string, SolidColorBrush>();
16+
//public static List<ThemeColor> themeColors;
17+
public static ObservableCollection<ThemeColor> themeColors = new ObservableCollection<ThemeColor>();
1418

1519
public ThemeEditor()
1620
{
@@ -19,53 +23,71 @@ public ThemeEditor()
1923

2024
private void Window_Loaded(object sender, RoutedEventArgs e)
2125
{
26+
themeColors.Clear();
27+
2228
// get original colors
2329
foreach (DictionaryEntry item in Application.Current.Resources.MergedDictionaries[0])
2430
{
2531
// take original colors, so can reset them
26-
origResourceColors[item.Key.ToString()] = (SolidColorBrush)item.Value;
27-
var col = (SolidColorBrush)item.Value;
32+
//origResourceColors[item.Key.ToString()] = (SolidColorBrush)item.Value;
33+
//var col = (SolidColorBrush)item.Value;
2834
//Console.WriteLine(item.Key.ToString() + "=" + col);
29-
35+
var themeColorPair = new ThemeColor();
36+
themeColorPair.Key = item.Key.ToString();
37+
themeColorPair.Brush = (SolidColorBrush)item.Value;
38+
themeColors.Add(themeColorPair);
3039
//var col = new BrushConverter().ConvertFrom(row[1].Trim());
3140
// apply color
3241
//Application.Current.Resources[row[0]] = (SolidColorBrush)col;
3342
}
3443

3544
// display current theme keys and values
36-
gridThemeColors.ItemsSource = origResourceColors;
45+
//gridThemeColors.ItemsSource = origResourceColors;
46+
gridThemeColors.ItemsSource = themeColors;
47+
//gridThemeColors.DataContext = themeColors;
3748

3849
}
3950

40-
string selectedKey = null;
51+
int selectedRow = -1;
52+
bool forceValue = false;
4153

4254
private void GridThemeColors_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
4355
{
4456
if (gridThemeColors.SelectedItem == null) return;
4557
//Console.WriteLine(gridThemeColors.SelectedItem);
46-
var k = gridThemeColors.SelectedItem as KeyValuePair<string, SolidColorBrush>?;
47-
selectedKey = k.Value.Key;
58+
var item = gridThemeColors.SelectedItem as ThemeColor;
59+
60+
//selectedRow = gridThemeColors.SelectedIndex;
61+
62+
//selectedKey = k.Value.Key;
4863
//Console.WriteLine("Selected: " +selectedKey + "=" + origResourceColors[selectedKey].ToString());
4964

5065
// show color
5166
// TODO show current color AND modified color next to each other
52-
rectSelectedColor.Fill = origResourceColors[selectedKey];
67+
//rectSelectedColor.Fill = origResourceColors[selectedKey];
68+
//var item = (string, SolidColorBrush)gridThemeColors.SelectedItem;
69+
rectSelectedColor.Fill = item.Brush;
5370

5471
//txtSelectedColorHex.Text = origResourceColors[selectedKey].ToString();
5572

56-
sliderRed.Value = origResourceColors[selectedKey].Color.R;
57-
sliderGreen.Value = origResourceColors[selectedKey].Color.G;
58-
sliderBlue.Value = origResourceColors[selectedKey].Color.B;
59-
73+
forceValue = true;
74+
sliderRed.Value = item.Brush.Color.R;
75+
forceValue = true;
76+
sliderGreen.Value = item.Brush.Color.G;
77+
forceValue = true;
78+
sliderBlue.Value = item.Brush.Color.B;
79+
forceValue = true;
80+
sliderAlpha.Value = item.Brush.Color.A;
81+
forceValue = false;
6082
}
6183

6284
void UpdateColorPreview()
6385
{
6486
var newColor = new Color();
65-
newColor.A = 255;
6687
newColor.R = byte.Parse(((int)sliderRed.Value).ToString());
6788
newColor.G = byte.Parse(((int)sliderGreen.Value).ToString());
6889
newColor.B = byte.Parse(((int)sliderBlue.Value).ToString());
90+
newColor.A = byte.Parse(((int)sliderAlpha.Value).ToString());
6991
var newColorBrush = new SolidColorBrush(newColor);
7092
rectSelectedColor.Fill = newColorBrush;
7193

@@ -74,34 +96,64 @@ void UpdateColorPreview()
7496
//origResourceColors[selectedKey] = newColorBrush;
7597
//gridThemeColors.Items.Refresh();
7698

99+
//DataRowView rowView = gridThemeColors.Items[ as DataRowView;
100+
//rowView.BeginEdit();
101+
//rowView[1] = "Change cell here";
102+
//rowView.EndEdit();
103+
//gridThemeColors.Items.Refresh();
104+
//Console.WriteLine(1234);
105+
106+
//themeColors[gridThemeColors.SelectedIndex].Key = "asdf";
107+
themeColors[gridThemeColors.SelectedIndex].Brush = newColorBrush;
108+
109+
// NOTE slow but works..
110+
gridThemeColors.Items.Refresh();
111+
77112
// TODO apply color changes to mainwindow
78113
}
79114

80115
private void SliderRed_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
81116
{
117+
if (forceValue == true) return;
82118
// onchanged is called before other components are ready..wpf :D
83119
if (txtRed == null) return;
84120
txtRed.Text = ((int)((Slider)sender).Value).ToString();
85121
UpdateColorPreview();
122+
forceValue = false;
86123
}
87124

88125
private void SliderGreen_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
89126
{
127+
if (forceValue == true) return;
90128
if (txtGreen == null) return;
91129
txtGreen.Text = ((int)((Slider)sender).Value).ToString();
92130
UpdateColorPreview();
131+
forceValue = false;
93132
}
94133

95134
private void SliderBlue_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
96135
{
136+
if (forceValue == true) return;
97137
if (txtBlue == null) return;
98138
txtBlue.Text = ((int)((Slider)sender).Value).ToString();
99139
UpdateColorPreview();
140+
forceValue = false;
141+
}
142+
143+
private void SliderAlpha_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
144+
{
145+
if (forceValue == true) return;
146+
if (txtAlpha == null) return;
147+
txtAlpha.Text = ((int)((Slider)sender).Value).ToString();
148+
UpdateColorPreview();
149+
forceValue = false;
100150
}
101151

102152
private void BtnSaveTheme_Click(object sender, RoutedEventArgs e)
103153
{
104154
Console.WriteLine("TODO save theme to file..");
105155
}
156+
157+
106158
}
107159
}

UnityLauncherPro/UnityLauncherPro.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
<Compile Include="Data\BuildReportItem.cs" />
8080
<Compile Include="Data\Platform.cs" />
8181
<Compile Include="Data\Tabs.cs" />
82+
<Compile Include="Data\ThemeColor.cs" />
8283
<Compile Include="GetProjects.cs" />
8384
<Compile Include="GetUnityInstallations.cs" />
8485
<Compile Include="GetUnityUpdates.cs" />

0 commit comments

Comments
 (0)