From 8a21b563654057b63f37bb5daaceb73f6a7857c3 Mon Sep 17 00:00:00 2001 From: VladiStep Date: Thu, 4 May 2023 19:20:58 +0300 Subject: [PATCH 1/2] Fix #1356. --- UndertaleModTool/Controls/ColorPicker.xaml.cs | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/UndertaleModTool/Controls/ColorPicker.xaml.cs b/UndertaleModTool/Controls/ColorPicker.xaml.cs index ae14ed3f0..bbaa5d9ad 100644 --- a/UndertaleModTool/Controls/ColorPicker.xaml.cs +++ b/UndertaleModTool/Controls/ColorPicker.xaml.cs @@ -102,33 +102,40 @@ public class ColorTextConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - uint val = System.Convert.ToUInt32(value); - bool hasAlpha = bool.Parse((string)parameter); - return "#" + (hasAlpha ? val.ToString("X8") : val.ToString("X8")[2..]); + try + { + uint val = System.Convert.ToUInt32(value); + bool hasAlpha = bool.Parse((string)parameter); + return "#" + (hasAlpha ? val.ToString("X8") : val.ToString("X8")[2..]); + } + catch (Exception ex) + { + return new ValidationResult(false, ex.Message); + } } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { - string val = (string)value; - bool hasAlpha = bool.Parse((string)parameter); - - if (val[0] != '#') - return new ValidationResult(false, "Invalid color string"); + try + { + string val = (string)value; + bool hasAlpha = bool.Parse((string)parameter); - val = val[1..]; - if (val.Length != (hasAlpha ? 8 : 6)) - return new ValidationResult(false, "Invalid color string"); + if (val[0] != '#') + return new ValidationResult(false, "Invalid color string"); - if (!hasAlpha) - val = "FF" + val; // add alpha (255) + val = val[1..]; + if (val.Length != (hasAlpha ? 8 : 6)) + return new ValidationResult(false, "Invalid color string"); - try - { + if (!hasAlpha) + val = "FF" + val; // add alpha (255) + return System.Convert.ToUInt32(val, 16); } - catch (Exception e) + catch (Exception ex) { - return new ValidationResult(false, e.Message); + return new ValidationResult(false, ex.Message); } } } From c58f51a2326c0078703e37cf2714981b0c9a43f4 Mon Sep 17 00:00:00 2001 From: VladiStep Date: Thu, 4 May 2023 19:31:16 +0300 Subject: [PATCH 2/2] Improve the color picker hint. --- UndertaleModTool/Controls/ColorPicker.xaml | 2 +- UndertaleModTool/Controls/ColorPicker.xaml.cs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/UndertaleModTool/Controls/ColorPicker.xaml b/UndertaleModTool/Controls/ColorPicker.xaml index 2a3857eeb..f5f63ef3d 100644 --- a/UndertaleModTool/Controls/ColorPicker.xaml +++ b/UndertaleModTool/Controls/ColorPicker.xaml @@ -24,7 +24,7 @@ - + diff --git a/UndertaleModTool/Controls/ColorPicker.xaml.cs b/UndertaleModTool/Controls/ColorPicker.xaml.cs index bbaa5d9ad..2cfd330b0 100644 --- a/UndertaleModTool/Controls/ColorPicker.xaml.cs +++ b/UndertaleModTool/Controls/ColorPicker.xaml.cs @@ -59,7 +59,8 @@ public ColorPicker() ColorText.SetBinding(TextBox.TextProperty, binding); ColorText.MaxLength = HasAlpha ? 9 : 7; - ColorText.ToolTip = $"{(HasAlpha ? "A, " : "")}B, G, R"; + ColorText.ToolTip = $"#{(HasAlpha ? "AA" : "")}BBGGRR"; + ToolTipService.SetInitialShowDelay(ColorText, 250); } private static void OnHasAlphaChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) @@ -77,7 +78,7 @@ private static void OnHasAlphaChanged(DependencyObject dependencyObject, Depende colorPicker.ColorText.SetBinding(TextBox.TextProperty, binding); colorPicker.ColorText.MaxLength = hasAlpha ? 9 : 7; - colorPicker.ColorText.ToolTip = $"{(hasAlpha ? "A, " : "")}B, G, R"; + colorPicker.ColorText.ToolTip = $"#{(hasAlpha ? "AA" : "")}BBGGRR"; } }