Browse Source

Fixed multiple nested subgroups

flabbet 4 years ago
parent
commit
90452e58e9

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

@@ -25,7 +25,7 @@ namespace PixiEditor.Models.Layers
             List<object> obj = new(Layers.Reverse());
             foreach (var subfolder in Subfolders)
             {
-                obj.Insert(subfolder.DisplayIndex - DisplayIndex, subfolder);
+                obj.Insert(Math.Clamp(subfolder.DisplayIndex - DisplayIndex, 0, obj.Count), subfolder);
             }
 
             obj.Reverse();

+ 26 - 21
PixiEditor/Models/Layers/StructuredLayerTree.cs

@@ -53,27 +53,7 @@ namespace PixiEditor.Models.Layers
                     continue;
                 }
 
-                if (parsedFolders.Any(x => x.StructureData.StartLayerGuid == layers[i].LayerGuid))
-                {
-                    groupsAtIndex = parsedFolders.Where(x => x.StructureData.StartLayerGuid == layers[i].LayerGuid).ToList();
-                    for (int j = 0; j < groupsAtIndex.Count; j++)
-                    {
-                        LayerGroup group = groupsAtIndex[j];
-
-                        if (currentFolder != null)
-                        {
-                            unfinishedFolders.Push(currentFolder);
-                        }
-
-                        groupsAtIndex[j] = parsedFolders.First(x => x.StructureData.StartLayerGuid == layers[i].LayerGuid);
-                        groupsAtIndex[j].DisplayIndex = RootDirectoryItems.Count;
-                        groupsAtIndex[j].TopIndex = CalculateTopIndex(group.DisplayIndex, group.StructureData, layers);
-                        if (groupsAtIndex[j].StructureData.EndLayerGuid != layers[i].LayerGuid)
-                        {
-                            currentFolder = groupsAtIndex[j];
-                        }
-                    }
-                }
+                AssignGroup(parsedFolders, layers, ref currentFolder, ref groupsAtIndex, unfinishedFolders, i);
 
                 if (currentFolder == null && !layersInStructure.Contains(layers[i].LayerGuid))
                 {
@@ -86,6 +66,31 @@ namespace PixiEditor.Models.Layers
             }
         }
 
+        private void AssignGroup(List<LayerGroup> parsedFolders, ObservableCollection<Layer> layers, ref LayerGroup currentFolder, ref List<LayerGroup> groupsAtIndex, Stack<LayerGroup> unfinishedFolders, int i)
+        {
+            if (parsedFolders.Any(x => x.StructureData.StartLayerGuid == layers[i].LayerGuid))
+            {
+                groupsAtIndex = parsedFolders.Where(x => x.StructureData.StartLayerGuid == layers[i].LayerGuid).ToList();
+                for (int j = 0; j < groupsAtIndex.Count; j++)
+                {
+                    LayerGroup group = groupsAtIndex[j];
+
+                    if (currentFolder != null)
+                    {
+                        unfinishedFolders.Push(currentFolder);
+                    }
+
+                    groupsAtIndex[j] = parsedFolders.First(x => x.StructureData.StartLayerGuid == layers[i].LayerGuid);
+                    groupsAtIndex[j].DisplayIndex = RootDirectoryItems.Count;
+                    groupsAtIndex[j].TopIndex = CalculateTopIndex(group.DisplayIndex, group.StructureData, layers);
+                    if (groupsAtIndex[j].StructureData.EndLayerGuid != layers[i].LayerGuid)
+                    {
+                        currentFolder = groupsAtIndex[j];
+                    }
+                }
+            }
+        }
+
         private int CalculateTopIndex(int displayIndex, GuidStructureItem structureData, ObservableCollection<Layer> layers)
         {
             int originalTopIndex = layers.IndexOf(layers.First(x => x.LayerGuid == structureData.EndLayerGuid));

+ 18 - 3
PixiEditor/Views/UserControls/RawLayersViewer.xaml

@@ -47,11 +47,26 @@
                             <TextBlock Foreground="White" Text="End Layer: "/>
                                 <TextBlock Foreground="Wheat" Text="{Binding EndLayerGuid}"/>
                         </StackPanel>
-                        <StackPanel Orientation="Horizontal">
-                            <TextBlock Foreground="White" Text="Start Layer: "/>
+                            <StackPanel Orientation="Horizontal">
+                                <TextBlock Foreground="White" Text="Start Layer: "/>
                                 <TextBlock Foreground="Wheat" Text="{Binding StartLayerGuid}"/>
+                            </StackPanel>
+                            <StackPanel Orientation="Horizontal">
+                                <TextBlock Foreground="White" Text="Subgroups: "/>
+                                <ItemsControl ItemsSource="{Binding Subgroups}">
+                                    <ItemsControl.ItemsPanel>
+                                        <ItemsPanelTemplate>
+                                            <StackPanel Orientation="Horizontal"/>
+                                        </ItemsPanelTemplate>
+                                    </ItemsControl.ItemsPanel>
+                                    <ItemsControl.ItemTemplate>
+                                        <DataTemplate>
+                                            <TextBlock Foreground="Wheat" Text="{Binding Name}"/>
+                                        </DataTemplate>
+                                    </ItemsControl.ItemTemplate>
+                                </ItemsControl>
+                            </StackPanel>
                         </StackPanel>
-                    </StackPanel>
                     </Border>
                 </DataTemplate>
             </ItemsControl.ItemTemplate>

+ 1 - 6
PixiEditor/Views/UserControls/RawLayersViewer.xaml.cs

@@ -34,12 +34,7 @@ namespace PixiEditor.Views.UserControls
 
         // Using a DependencyProperty as the backing store for Structure.  This enables animation, styling, binding, etc...
         public static readonly DependencyProperty StructureProperty =
-            DependencyProperty.Register("Structure", typeof(LayerStructure), typeof(RawLayersViewer), new PropertyMetadata(default(LayerStructure), StructureChangedCallback));
-
-        private static void StructureChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
-        {
-            Debug.Write("asd");
-        }
+            DependencyProperty.Register("Structure", typeof(LayerStructure), typeof(RawLayersViewer), new PropertyMetadata(default(LayerStructure)));
 
         public RawLayersViewer()
         {