Skip to content

Commit

Permalink
Fix tile Selection (#1903)
Browse files Browse the repository at this point in the history
Fixes #1902
Fixes #1899
Fixes #1899
  • Loading branch information
BinaryConstruct authored Jul 3, 2024
1 parent 77c39b4 commit 530ef4f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
32 changes: 32 additions & 0 deletions src/TEdit/Framework/XamlConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{

Expand Down
9 changes: 6 additions & 3 deletions src/TEdit/Themes/Templates.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
<enum:EnumItemList x:Key="PaintModeEnum" ResourceType="{x:Type p:Language}" EnumType="{x:Type editor:PaintMode}" SortBy="Value" />
<enum:EnumItemList x:Key="TrackModeEnum" ResourceType="{x:Type p:Language}" EnumType="{x:Type editor:TrackMode}" SortBy="Value" />
<enum:EnumItemList x:Key="JunctionBoxEnum" ResourceType="{x:Type p:Language}" EnumType="{x:Type editor:JunctionBoxMode}" SortBy="Value" />
Expand All @@ -17,13 +19,14 @@
<enum:EnumItemList x:Key="LiquidType" ResourceType="{x:Type p:Language}" EnumType="{x:Type config:LiquidType}" x:Shared="false" SortBy="Value" />
<enum:EnumItemList x:Key="LiquidAmountEnum" ResourceType="{x:Type p:Language}" EnumType="{x:Type editor:LiquidAmountMode}" SortBy="Value" />
<enum:EnumItemList x:Key="WireReplaceModeEnum" ResourceType="{x:Type p:Language}" EnumType="{x:Type editor:WireReplaceMode}" SortBy="Value" />
<cv:TEditColorToMediaColorConverter x:Key="TEditColorToMediaColorConverter" />

<DataTemplate x:Key="ColorPickerTemplate" >
<DataTemplate x:Key="ColorPickerTemplate" >
<DockPanel LastChildFill="True">
<Border BorderBrush="Black" BorderThickness="1" Margin="2,1" DockPanel.Dock="Left" >
<Rectangle Height="12" Width="12">
<Rectangle.Fill>
<SolidColorBrush Color="{Binding Path=Color}" />
<SolidColorBrush Color="{Binding Path=Color, Converter={StaticResource TEditColorToMediaColorConverter}}" />
</Rectangle.Fill>
</Rectangle>
</Border>
Expand Down
12 changes: 11 additions & 1 deletion src/TEdit/ViewModel/WorldViewModel.Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace TEdit.ViewModel;

public partial class WorldViewModel
{
private WorldEditor _worldEditor;

public void EditDelete()
{
if (Selection.IsActive)
Expand Down Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/TEdit/ViewModel/WorldViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public partial class WorldViewModel : ViewModelBase
private readonly ObservableCollection<string> _points = new ObservableCollection<string>();
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<ITool> _tools = new ObservableCollection<ITool>();
private UndoManager _undoManager;
Expand Down Expand Up @@ -490,6 +489,7 @@ public World CurrentWorld
rb.UpdateTile);

WorldEditor = new WorldEditor(CurrentWorld, Selection, undo, updateTiles);

}
else
{
Expand Down Expand Up @@ -519,7 +519,7 @@ public BrushSettings Brush

public TilePicker TilePicker
{
get { return _tilePicker; }
get { return WorldEditor?.TilePicker; }
}

public ObservableCollection<ITool> Tools
Expand Down

0 comments on commit 530ef4f

Please sign in to comment.