/// <summary> /// Builds the set tree from XivCache.GetAllRoots(). /// </summary> private void BuildSetTree() { // First we must generate all the dependency root nodes. var roots = XivCache.GetAllRootsDictionary(); var primaryTypeGroups = new Dictionary <XivItemType, ItemTreeElement>(); var primaryIdGroups = new Dictionary <XivItemType, Dictionary <int, ItemTreeElement> >(); var secondaryTypeGroups = new Dictionary <XivItemType, Dictionary <int, Dictionary <XivItemType, ItemTreeElement> > >(); var secondaryIdGroups = new Dictionary <XivItemType, Dictionary <int, Dictionary <XivItemType, Dictionary <int, ItemTreeElement> > > >(); // This giant for loop monstrosity builds the actual root nodes based on the dictionaries returned by XivCache.GetAllRoots() foreach (var kvPrimaryType in roots) { var primaryType = kvPrimaryType.Key; // Create the new node. primaryTypeGroups.Add(primaryType, new ItemTreeElement(null, null, XivItemTypes.NiceNames[primaryType], true)); // Add us to parent. SetElements.Add(primaryTypeGroups[primaryType]); // Ensure the other lists have our primary type reference. primaryIdGroups.Add(primaryType, new Dictionary <int, ItemTreeElement>()); secondaryTypeGroups.Add(primaryType, new Dictionary <int, Dictionary <XivItemType, ItemTreeElement> >()); secondaryIdGroups.Add(primaryType, new Dictionary <int, Dictionary <XivItemType, Dictionary <int, ItemTreeElement> > >()); foreach (var kvPrimaryId in kvPrimaryType.Value) { var primaryId = kvPrimaryId.Key; // Create the new node. primaryIdGroups[primaryType].Add(primaryId, new ItemTreeElement(null, primaryTypeGroups[primaryType], XivItemTypes.GetSystemPrefix(primaryType) + primaryId.ToString().PadLeft(4, '0'), true)); // Add us to parent. primaryTypeGroups[primaryType].Children.Add(primaryIdGroups[primaryType][primaryId]); // Ensure the other lists have our primary id reference. secondaryTypeGroups[primaryType].Add(primaryId, new Dictionary <XivItemType, ItemTreeElement>()); secondaryIdGroups[primaryType].Add(primaryId, new Dictionary <XivItemType, Dictionary <int, ItemTreeElement> >()); foreach (var kvSecondaryType in kvPrimaryId.Value) { var secondaryType = kvSecondaryType.Key; if (secondaryType != XivItemType.none) { // Create the new node. secondaryTypeGroups[primaryType][primaryId].Add(secondaryType, new ItemTreeElement(null, primaryIdGroups[primaryType][primaryId], XivItemTypes.NiceNames[secondaryType], true)); // Add us to parent. primaryIdGroups[primaryType][primaryId].Children.Add(secondaryTypeGroups[primaryType][primaryId][secondaryType]); // Ensure the other lists have our secondary type reference. secondaryIdGroups[primaryType][primaryId].Add(secondaryType, new Dictionary <int, ItemTreeElement>()); } foreach (var kvSecondaryId in kvSecondaryType.Value) { var secondaryId = kvSecondaryId.Key; if (secondaryType != XivItemType.none) { // Create the new node. secondaryIdGroups[primaryType][primaryId][secondaryType].Add(secondaryId, new ItemTreeElement(null, secondaryTypeGroups[primaryType][primaryId][secondaryType], XivItemTypes.GetSystemPrefix(secondaryType) + secondaryId.ToString().PadLeft(4, '0'), true)); // Add us to parent. secondaryTypeGroups[primaryType][primaryId][secondaryType].Children.Add(secondaryIdGroups[primaryType][primaryId][secondaryType][secondaryId]); } foreach (var kvSlot in kvSecondaryId.Value) { var root = kvSlot.Value; var slotName = Mdl.SlotAbbreviationDictionary.FirstOrDefault(x => x.Value == root.Slot).Key; if (secondaryType != XivItemType.none) { // This root has no slots, just list the parent as the root element. if (String.IsNullOrWhiteSpace(slotName)) { DependencyRootNodes.Add(root.ToString(), secondaryIdGroups[primaryType][primaryId][secondaryType][secondaryId]); break; } // Create the new node. var elem = new ItemTreeElement(null, secondaryIdGroups[primaryType][primaryId][secondaryType][secondaryId], slotName); // Add us to parent. secondaryIdGroups[primaryType][primaryId][secondaryType][secondaryId].Children.Add(elem); // Save us to the primary listing so the items can list themselves under us. DependencyRootNodes.Add(root.ToString(), elem); } else { // This root has no slots, just list the parent as the root element. if (String.IsNullOrWhiteSpace(slotName)) { DependencyRootNodes.Add(root.ToString(), primaryIdGroups[primaryType][primaryId]); break; } // Create the new node. var elem = new ItemTreeElement(null, primaryIdGroups[primaryType][primaryId], slotName); // Add us to parent. primaryIdGroups[primaryType][primaryId].Children.Add(elem); // Save us to the primary listing so the items can list themselves under us. DependencyRootNodes.Add(root.ToString(), elem); } } } } } } }