11using System ;
22using System . Collections ;
33using System . Collections . Generic ;
4+ using System . Collections . ObjectModel ;
5+ using System . Data ;
46using System . Windows ;
57using System . Windows . Controls ;
68using 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}
0 commit comments