Browse Source

Structured layers WIP

flabbet 4 years ago
parent
commit
362c72cbcb

+ 1 - 1
PixiEditor/Helpers/Converters/LayersToStructuredLayersConverter.cs

@@ -15,7 +15,7 @@ namespace PixiEditor.Helpers.Converters
                 return new StructuredLayerTree(layers, structure).Items;
                 return new StructuredLayerTree(layers, structure).Items;
             }
             }
 
 
-            return null;
+            return new StructuredLayerTree();
         }
         }
 
 
         public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
         public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)

+ 1 - 1
PixiEditor/Models/Layers/LayerStructureItem.cs

@@ -4,7 +4,7 @@ namespace PixiEditor.Models.Layers
 {
 {
     public class LayerStructureItem
     public class LayerStructureItem
     {
     {
-        public ObservableCollection<Layer> Children { get; set; }
+        public ObservableCollection<Layer> Children { get; set; } = new ObservableCollection<Layer>();
 
 
         public LayerStructureItem(ObservableCollection<Layer> children)
         public LayerStructureItem(ObservableCollection<Layer> children)
         {
         {

+ 6 - 3
PixiEditor/Models/Layers/StructuredLayerTree.cs

@@ -1,17 +1,15 @@
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Collections.ObjectModel;
 using System.Linq;
 using System.Linq;
-using PixiEditor.Helpers.Extensions;
 
 
 namespace PixiEditor.Models.Layers
 namespace PixiEditor.Models.Layers
 {
 {
     public class StructuredLayerTree
     public class StructuredLayerTree
     {
     {
-        public ObservableCollection<LayerStructureItem> Items { get; set; }
+        public ObservableCollection<LayerStructureItem> Items { get; set; } = new ObservableCollection<LayerStructureItem>();
 
 
         public StructuredLayerTree(IEnumerable<Layer> layers, LayerStructure structure)
         public StructuredLayerTree(IEnumerable<Layer> layers, LayerStructure structure)
         {
         {
-            Items = new ();
             if (structure == null || structure.Items.Count == 0)
             if (structure == null || structure.Items.Count == 0)
             {
             {
                 foreach (var layer in layers)
                 foreach (var layer in layers)
@@ -33,5 +31,10 @@ namespace PixiEditor.Models.Layers
                 Items.Add(new LayerStructureItem(itemChildren));
                 Items.Add(new LayerStructureItem(itemChildren));
             }
             }
         }
         }
+
+        public StructuredLayerTree()
+        {
+            
+        }
     }
     }
 }
 }

+ 29 - 17
PixiEditor/Views/UserControls/LayerStructureItemContainer.xaml

@@ -4,58 +4,70 @@
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:local="clr-namespace:PixiEditor.Views.UserControls"
              xmlns:local="clr-namespace:PixiEditor.Views.UserControls"
-             xmlns:vws="clr-namespace:PixiEditor.Views"
+             xmlns:vws="clr-namespace:PixiEditor.Views" xmlns:ui="clr-namespace:PixiEditor.Helpers.UI"
              mc:Ignorable="d" 
              mc:Ignorable="d" 
-             d:DesignHeight="450" d:DesignWidth="800" Name="uc">
+             d:DesignHeight="60" d:DesignWidth="250" Name="uc">
     <Grid>
     <Grid>
-        <vws:LayerItem Tag="{Binding Path=DataContext, ElementName=layersItemsControl}" 
+        <ItemsControl Name="itemsControl" ItemsSource="{Binding Item.Children, ElementName=uc}">
+            <ItemsControl.ItemsPanel>
+                <ItemsPanelTemplate>
+                    <ui:ReversedOrderStackPanel Orientation="Vertical" />
+                </ItemsPanelTemplate>
+            </ItemsControl.ItemsPanel>
+            <ItemsControl.ItemTemplate>
+                <DataTemplate>
+            <vws:LayerItem Tag="{Binding Path=DataContext, ElementName=layersItemsControl}" 
                                        LayerIndex="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
                                        LayerIndex="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
                                 Path=(ItemsControl.AlternationIndex)}" 
                                 Path=(ItemsControl.AlternationIndex)}" 
                                        SetActiveLayerCommand="{Binding DataContext.LayersViewModel.SetActiveLayerCommand, 
                                        SetActiveLayerCommand="{Binding DataContext.LayersViewModel.SetActiveLayerCommand, 
                             ElementName=layersItemsControl}"
                             ElementName=layersItemsControl}"
-                                       LayerName="{Binding Name, Mode=TwoWay}" IsActive="{Binding IsActive, Mode=TwoWay}"
+                                       LayerName="{Binding Name, Mode=TwoWay}" 
+                                       IsActive="{Binding IsActive, Mode=TwoWay}"
                                        IsRenaming="{Binding IsRenaming, Mode=TwoWay}"
                                        IsRenaming="{Binding IsRenaming, Mode=TwoWay}"
                                        PreviewImage="{Binding LayerBitmap}"
                                        PreviewImage="{Binding LayerBitmap}"
                                       MoveToBackCommand="{Binding DataContext.LayersViewModel.MoveToBackCommand, ElementName=layersItemsControl}"
                                       MoveToBackCommand="{Binding DataContext.LayersViewModel.MoveToBackCommand, ElementName=layersItemsControl}"
                                       MoveToFrontCommand="{Binding DataContext.LayersViewModel.MoveToFrontCommand, ElementName=layersItemsControl}">
                                       MoveToFrontCommand="{Binding DataContext.LayersViewModel.MoveToFrontCommand, ElementName=layersItemsControl}">
-            <vws:LayerItem.ContextMenu>
-                <ContextMenu>
-                    <MenuItem Header="Delete"
+                <vws:LayerItem.ContextMenu>
+                    <ContextMenu>
+                        <MenuItem Header="Delete"
                                          Command="{Binding PlacementTarget.Tag.LayersViewModel.DeleteLayersCommand, 
                                          Command="{Binding PlacementTarget.Tag.LayersViewModel.DeleteLayersCommand, 
                                             RelativeSource={RelativeSource AncestorType=ContextMenu}}"
                                             RelativeSource={RelativeSource AncestorType=ContextMenu}}"
                                          CommandParameter="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
                                          CommandParameter="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
                                 Path=(ItemsControl.AlternationIndex)}" />
                                 Path=(ItemsControl.AlternationIndex)}" />
-                    <MenuItem Header="Rename"
+                        <MenuItem Header="Rename"
                                      Command="{Binding PlacementTarget.Tag.LayersViewModel.RenameLayerCommand, 
                                      Command="{Binding PlacementTarget.Tag.LayersViewModel.RenameLayerCommand, 
                                             RelativeSource={RelativeSource AncestorType=ContextMenu}}"
                                             RelativeSource={RelativeSource AncestorType=ContextMenu}}"
                                      CommandParameter="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
                                      CommandParameter="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
                                 Path=(ItemsControl.AlternationIndex)}" />
                                 Path=(ItemsControl.AlternationIndex)}" />
-                    <MenuItem Header="Move to front"
+                        <MenuItem Header="Move to front"
                                      Command="{Binding PlacementTarget.Tag.LayersViewModel.MoveToFrontCommand, 
                                      Command="{Binding PlacementTarget.Tag.LayersViewModel.MoveToFrontCommand, 
                                             RelativeSource={RelativeSource AncestorType=ContextMenu}}"
                                             RelativeSource={RelativeSource AncestorType=ContextMenu}}"
                                      CommandParameter="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
                                      CommandParameter="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
                                 Path=(ItemsControl.AlternationIndex)}" />
                                 Path=(ItemsControl.AlternationIndex)}" />
-                    <MenuItem Header="Move to back"
+                        <MenuItem Header="Move to back"
                                     Command="{Binding PlacementTarget.Tag.LayersViewModel.MoveToBackCommand, 
                                     Command="{Binding PlacementTarget.Tag.LayersViewModel.MoveToBackCommand, 
                                             RelativeSource={RelativeSource AncestorType=ContextMenu}}"
                                             RelativeSource={RelativeSource AncestorType=ContextMenu}}"
                                      CommandParameter="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
                                      CommandParameter="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
                                 Path=(ItemsControl.AlternationIndex)}" />
                                 Path=(ItemsControl.AlternationIndex)}" />
-                    <Separator/>
-                    <MenuItem Header="Merge selected"
+                        <Separator/>
+                        <MenuItem Header="Merge selected"
                                      Command="{Binding PlacementTarget.Tag.LayersViewModel.MergeSelectedCommand, 
                                      Command="{Binding PlacementTarget.Tag.LayersViewModel.MergeSelectedCommand, 
                                             RelativeSource={RelativeSource AncestorType=ContextMenu}}"/>
                                             RelativeSource={RelativeSource AncestorType=ContextMenu}}"/>
-                    <MenuItem Header="Merge with above"
+                        <MenuItem Header="Merge with above"
                                      Command="{Binding PlacementTarget.Tag.LayersViewModel.MergeWithAboveCommand, 
                                      Command="{Binding PlacementTarget.Tag.LayersViewModel.MergeWithAboveCommand, 
                                             RelativeSource={RelativeSource AncestorType=ContextMenu}}"
                                             RelativeSource={RelativeSource AncestorType=ContextMenu}}"
                                      CommandParameter="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
                                      CommandParameter="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
                                 Path=(ItemsControl.AlternationIndex)}" />
                                 Path=(ItemsControl.AlternationIndex)}" />
-                    <MenuItem Header="Merge with below"
+                        <MenuItem Header="Merge with below"
                                     Command="{Binding PlacementTarget.Tag.LayersViewModel.MergeWithBelowCommand, 
                                     Command="{Binding PlacementTarget.Tag.LayersViewModel.MergeWithBelowCommand, 
                                             RelativeSource={RelativeSource AncestorType=ContextMenu}}"
                                             RelativeSource={RelativeSource AncestorType=ContextMenu}}"
                                     CommandParameter="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
                                     CommandParameter="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
                                 Path=(ItemsControl.AlternationIndex)}" />
                                 Path=(ItemsControl.AlternationIndex)}" />
-                </ContextMenu>
-            </vws:LayerItem.ContextMenu>
-        </vws:LayerItem>
+                    </ContextMenu>
+                </vws:LayerItem.ContextMenu>
+            </vws:LayerItem>
+                </DataTemplate>
+            </ItemsControl.ItemTemplate>
+        </ItemsControl>
     </Grid>
     </Grid>
 </UserControl>
 </UserControl>

+ 3 - 3
PixiEditor/Views/UserControls/LayerStructureItemContainer.xaml.cs

@@ -1,5 +1,4 @@
-using PixiEditor.Models.Layers;
-using System;
+using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
 using System.Text;
 using System.Text;
@@ -13,11 +12,12 @@ using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
 using System.Windows.Shapes;
+using PixiEditor.Models.Layers;
 
 
 namespace PixiEditor.Views.UserControls
 namespace PixiEditor.Views.UserControls
 {
 {
     /// <summary>
     /// <summary>
-    /// Interaction logic for LayerStructureItemContainer.xaml
+    /// Interaction logic for LayerStructureItemContainer.xaml.
     /// </summary>
     /// </summary>
     public partial class LayerStructureItemContainer : UserControl
     public partial class LayerStructureItemContainer : UserControl
     {
     {

+ 2 - 2
PixiEditor/Views/UserControls/LayersManager.xaml

@@ -10,7 +10,7 @@
              xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters" 
              xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters" 
              d:DataContext="{d:DesignInstance Type=local:LayersManager}"
              d:DataContext="{d:DesignInstance Type=local:LayersManager}"
              mc:Ignorable="d"
              mc:Ignorable="d"
-             d:DesignHeight="450" d:DesignWidth="300" Name="uc">
+             d:DesignHeight="450" d:DesignWidth="250" Name="uc">
     <UserControl.Resources>
     <UserControl.Resources>
         <converters:NotNullToBoolConverter x:Key="NotNullToBoolConverter" />
         <converters:NotNullToBoolConverter x:Key="NotNullToBoolConverter" />
         <converters:FloatNormalizeConverter x:Key="FloatNormalizeConverter" />
         <converters:FloatNormalizeConverter x:Key="FloatNormalizeConverter" />
@@ -55,7 +55,7 @@
                 </ItemsControl.ItemsPanel>
                 </ItemsControl.ItemsPanel>
                 <ItemsControl.ItemTemplate>
                 <ItemsControl.ItemTemplate>
                     <DataTemplate>
                     <DataTemplate>
-                        
+                        <local:LayerStructureItemContainer Item="{Binding}"/>
                     </DataTemplate>
                     </DataTemplate>
                 </ItemsControl.ItemTemplate>
                 </ItemsControl.ItemTemplate>
             </ItemsControl>
             </ItemsControl>