From 530ef4f4ecf6c126602c1017b2c7b08503c52588 Mon Sep 17 00:00:00 2001 From: BinaryConstruct Date: Wed, 3 Jul 2024 15:50:48 -0500 Subject: [PATCH] Fix tile Selection (#1903) Fixes #1902 Fixes #1899 Fixes #1899 --- src/TEdit/Framework/XamlConverters.cs | 32 ++++++++++++++++++++ src/TEdit/Themes/Templates.xaml | 9 ++++-- src/TEdit/ViewModel/WorldViewModel.Editor.cs | 12 +++++++- src/TEdit/ViewModel/WorldViewModel.cs | 4 +-- 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/src/TEdit/Framework/XamlConverters.cs b/src/TEdit/Framework/XamlConverters.cs index c42bab3d..24636214 100644 --- a/src/TEdit/Framework/XamlConverters.cs +++ b/src/TEdit/Framework/XamlConverters.cs @@ -3,9 +3,41 @@ using System.Globalization; using System.Windows; using System.Windows.Data; +using TEdit.Common; namespace TEdit.Converters; +public class TEditColorToMediaColorConverter : IValueConverter +{ + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value == null) + return DependencyProperty.UnsetValue; + + if (value is TEditColor) + { + TEditColor tEditColor = (TEditColor)value; + return System.Windows.Media.Color.FromArgb(tEditColor.A, tEditColor.R, tEditColor.G, tEditColor.B); + } + + return DependencyProperty.UnsetValue; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value == null) + return DependencyProperty.UnsetValue; + + if (value is System.Windows.Media.Color) + { + System.Windows.Media.Color mediaColor = (System.Windows.Media.Color)value; + return new TEditColor(mediaColor.A, mediaColor.R, mediaColor.G, mediaColor.B); + } + + return DependencyProperty.UnsetValue; + } +} + public class EnumToBoolConverter : IValueConverter { diff --git a/src/TEdit/Themes/Templates.xaml b/src/TEdit/Themes/Templates.xaml index ad1c5e8c..162703a9 100644 --- a/src/TEdit/Themes/Templates.xaml +++ b/src/TEdit/Themes/Templates.xaml @@ -7,7 +7,9 @@ xmlns:editor="clr-namespace:TEdit.Editor;assembly=TEdit.Editor" xmlns:tedit="clr-namespace:TEdit.UI.Xaml" xmlns:p="clr-namespace:TEdit.Properties" - xmlns:enum="clr-namespace:TEdit.UI.Xaml.Enum"> + xmlns:enum="clr-namespace:TEdit.UI.Xaml.Enum" + xmlns:cv="clr-namespace:TEdit.Converters" + > @@ -17,13 +19,14 @@ + - + - + diff --git a/src/TEdit/ViewModel/WorldViewModel.Editor.cs b/src/TEdit/ViewModel/WorldViewModel.Editor.cs index 76d77414..3b1c0f8a 100644 --- a/src/TEdit/ViewModel/WorldViewModel.Editor.cs +++ b/src/TEdit/ViewModel/WorldViewModel.Editor.cs @@ -19,6 +19,8 @@ namespace TEdit.ViewModel; public partial class WorldViewModel { + private WorldEditor _worldEditor; + public void EditDelete() { if (Selection.IsActive) @@ -327,7 +329,15 @@ public void EditPaste() } } - private WorldEditor WorldEditor { get; set; } + private WorldEditor WorldEditor + { + get => _worldEditor; + set + { + _worldEditor = value; + RaisePropertyChanged("TilePicker"); + } + } public void SetPixel(int x, int y, PaintMode? mode = null, bool? erase = null) { diff --git a/src/TEdit/ViewModel/WorldViewModel.cs b/src/TEdit/ViewModel/WorldViewModel.cs index df723379..e31ce9ea 100644 --- a/src/TEdit/ViewModel/WorldViewModel.cs +++ b/src/TEdit/ViewModel/WorldViewModel.cs @@ -53,7 +53,6 @@ public partial class WorldViewModel : ViewModelBase private readonly ObservableCollection _points = new ObservableCollection(); private readonly Timer _saveTimer = new Timer(); private readonly Selection _selection = new Selection(); - private readonly TilePicker _tilePicker = new TilePicker(); private readonly MorphToolOptions _MorphToolOptions = new MorphToolOptions(); private readonly ObservableCollection _tools = new ObservableCollection(); private UndoManager _undoManager; @@ -490,6 +489,7 @@ public World CurrentWorld rb.UpdateTile); WorldEditor = new WorldEditor(CurrentWorld, Selection, undo, updateTiles); + } else { @@ -519,7 +519,7 @@ public BrushSettings Brush public TilePicker TilePicker { - get { return _tilePicker; } + get { return WorldEditor?.TilePicker; } } public ObservableCollection Tools