Esempio n. 1
0
 private void InitializeEditors()
 {
     Dispatcher.InvokeAsync(() =>
     {
         SimpleItemsTab.Content = new InventoryViewer(LoadedSaveFile);
         foreach (var node in LoadedSaveFile.Nodes)
         {
             var treeNode = new SaveNodeTreeViewItem(node);
             BuildVisualSubTree(treeNode, null);
             advancedTabTreeView.Items.Add(treeNode);
         }
         LoadQuickActions();
     });
 }
Esempio n. 2
0
        private void BuildVisualSubTree(SaveNodeTreeViewItem treeNode, string filter)
        {
            if (treeNode.Node.Value is Inventory inv)
            {
                // For inventory, we insert virtual nodes for the sub inventories.
                var subinventories = inv.SubInventories.Select(_ => (NodeEntry) new VirtualNodeEntry()
                {
                    Value = _
                }).ToList();
                foreach (var subinventory in subinventories)
                {
                    var real        = subinventory as VirtualNodeEntry ?? throw new Exception("subinventory is not a VirtualNodeEntry, wtf?!");
                    var data        = real.Value as Inventory.SubInventory;
                    var simpleItems = new VirtualNodeEntry {
                        Value = "Simple items"
                    };
                    var modableItems = new VirtualNodeEntry {
                        Value = "Modable Items"
                    };
                    foreach (var itemNode in treeNode.Node.Children)
                    {
                        if (data.Items.Contains(itemNode.Value) && (filter == null || itemNode.ToString().ToLowerInvariant().Contains(filter)))
                        {
                            var item = ((ItemData)itemNode.Value).Data;
                            if (item is ItemData.SimpleItemData sid)
                            {
                                simpleItems.Children.Add(itemNode);
                            }
                            else
                            {
                                modableItems.Children.Add(itemNode);
                            }
                        }
                    }

                    if (simpleItems.Children.Count > 0)
                    {
                        subinventory.Children.Add(simpleItems);
                    }
                    if (modableItems.Children.Count > 0)
                    {
                        subinventory.Children.Add(modableItems);
                    }
                }
                foreach (var item in SaveNodeTreeViewItem.FromList(subinventories.Where(_ => filter == null || _.Children.Count > 0).ToList()))
                {
                    treeNode.Items.Add(item);
                }
                foreach (var child in treeNode.Items)
                {
                    BuildVisualSubTree((SaveNodeTreeViewItem)child, filter);
                }

                return;
            }

            if (treeNode.Node.Value is CharacterCustomizationAppearances cca)
            {
                // For CCA we also insert virtual nodes for the three sections
                var sections = new List <CharacterCustomizationAppearances.Section> {
                    cca.FirstSection, cca.SecondSection, cca.ThirdSection
                };

                foreach (var section in sections)
                {
                    var treeSection = new SaveNodeTreeViewItem(new VirtualNodeEntry {
                        Value = section
                    });
                    foreach (var appearanceSection in section.AppearanceSections)
                    {
                        if (filter == null || appearanceSection.ToString().ToLowerInvariant().Contains(filter))
                        {
                            treeSection.Items.Add(new SaveNodeTreeViewItem(new VirtualNodeEntry {
                                Value = appearanceSection
                            }));
                        }
                    }

                    if (treeSection.Items.Count > 0)
                    {
                        treeNode.Items.Add(treeSection);
                    }
                }

                return;
            }

            if (treeNode.Node.Value is FactsTable ft)
            {
                foreach (var fe in ft.FactEntries)
                {
                    if (filter == null || fe.ToString().ToLowerInvariant().Contains(filter))
                    {
                        treeNode.Items.Add(new SaveNodeTreeViewItem(new VirtualNodeEntry {
                            Value = fe
                        }));
                    }
                }

                return;
            }

            if (treeNode.Node.Children.Count > 0)
            {
                var nodes = new List <SaveNodeTreeViewItem>();
                nodes.AddRange(SaveNodeTreeViewItem.FromList(treeNode.Node.Children).ToArray());

                foreach (var child in nodes)
                {
                    BuildVisualSubTree((SaveNodeTreeViewItem)child, filter);
                    if (filter == null || child.Header.ToString().ToLowerInvariant().Contains(filter) || child.Items.Count > 0)
                    {
                        treeNode.Items.Add(child);
                    }
                }
            }
        }