public TreeNode BuildTree(FrameNameTable.FrameNameTable table) { TreeNode root = new TreeNode("FrameResource Contents"); root.Tag = header; int numBlocks = header.NumFolderNames + header.NumGeometries + header.NumMaterialResources + header.NumBlendInfos + header.NumSkeletons + header.NumSkelHierachies; Dictionary <int, TreeNode> parsedNodes = new Dictionary <int, TreeNode>(); Dictionary <int, TreeNode> notAddedNodes = new Dictionary <int, TreeNode>(); //Add scene groups into the scene viewer. for (int i = 0; i != frameScenes.Count; i++) { FrameHeaderScene scene = frameScenes.Values.ElementAt(i); TreeNode node = new TreeNode(scene.ToString()); node.Tag = scene; node.Name = scene.RefID.ToString(); parsedNodes.Add(scene.RefID, node); root.Nodes.Add(node); AddChildren(parsedNodes, scene.Children, node); } foreach (var pair in frameObjects) { FrameObjectBase frame = (pair.Value as FrameObjectBase); TreeNode node; if (parsedNodes.ContainsKey(pair.Key)) { continue; } if (frame.ParentIndex1.Index == -1 && frame.ParentIndex2.Index == -1) { node = new TreeNode(frame.ToString()); node.Tag = frame; node.Name = frame.RefID.ToString(); root.Nodes.Add(node); parsedNodes.Add(frame.RefID, node); AddChildren(parsedNodes, frame.Children, node); } } foreach (var pair in frameObjects) { if (!parsedNodes.ContainsKey(pair.Key)) { FrameObjectBase frame = (pair.Value as FrameObjectBase); Debug.WriteLine("Failed " + frame.ToString()); TreeNode node = new TreeNode(frame.ToString()); node.Tag = frame; node.Name = frame.RefID.ToString(); root.Nodes.Add(node); //throw new FormatException("Unhandled frame! Name is: " + pair.Value.ToString()); } } return(root); }
public TreeNode BuildTree(FrameNameTable.FrameNameTable table) { TreeNode root = new TreeNode("FrameResource Contents"); root.Tag = header; int numBlocks = header.NumFolderNames + header.NumGeometries + header.NumMaterialResources + header.NumBlendInfos + header.NumSkeletons + header.NumSkelHierachies; Dictionary <int, TreeNode> parsedNodes = new Dictionary <int, TreeNode>(); Dictionary <int, TreeNode> notAddedNodes = new Dictionary <int, TreeNode>(); //Add scene groups into the scene viewer. for (int i = 0; i != frameScenes.Count; i++) { FrameHeaderScene scene = frameScenes.Values.ElementAt(i); TreeNode node = new TreeNode(scene.ToString()); node.Tag = scene; node.Name = scene.RefID.ToString(); parsedNodes.Add(i, node); root.Nodes.Add(node); } ////add entries from the table, add table data and then add to scene viewer. for (int i = 0; i != table.FrameData.Length; i++) { if (table.FrameData[i].FrameIndex == -1) { continue; } var frameData = table.FrameData[i]; FrameObjectBase fObject = (GetEntryFromIdx(numBlocks + frameData.FrameIndex).Data as FrameObjectBase); fObject.IsOnFrameTable = true; fObject.FrameNameTableFlags = table.FrameData[i].Flags; int p1idx = numBlocks + fObject.ParentIndex1.Index; int p2idx = numBlocks + fObject.ParentIndex2.Index; int thisKey = numBlocks + table.FrameData[i].FrameIndex; TreeNode node = (!parsedNodes.ContainsKey(thisKey)) ? new TreeNode(fObject.ToString()) : parsedNodes[thisKey]; node.Tag = fObject; node.Name = fObject.RefID.ToString(); if (p1idx == -1 && p2idx == -1) { //might be temp? it fixes cars loading in or non binded entries. root.Nodes.Add(node); continue; } else { FrameEntry pBase = (GetEntryFromIdx(p2idx).Data as FrameEntry); TreeNode[] nodes = root.Nodes.Find(pBase.RefID.ToString(), true); if (nodes.Length > 0) { nodes[0].Nodes.Add(node); } } if (!parsedNodes.ContainsKey(thisKey)) { parsedNodes.Add(thisKey, node); } } foreach (FrameHolder holder in NewFrames) { FrameObjectBase fObject = holder.Data as FrameObjectBase; if (fObject == null) { continue; } TreeNode node = (!parsedNodes.ContainsKey(holder.Idx)) ? new TreeNode(fObject.ToString()) : parsedNodes[holder.Idx]; node.Tag = fObject; node.Name = fObject.RefID.ToString(); if (!parsedNodes.ContainsKey(holder.Idx)) { parsedNodes.Add(holder.Idx, node); } } foreach (FrameHolder holder in NewFrames) { FrameObjectBase fObject = holder.Data as FrameObjectBase; if (fObject == null) { continue; } if (fObject.ParentIndex1.Index != -1) { parsedNodes[fObject.ParentIndex1.Index].Nodes.Add(parsedNodes[holder.Idx]); } else if (fObject.ParentIndex2.Index != -1) { parsedNodes[fObject.ParentIndex2.Index].Nodes.Add(parsedNodes[holder.Idx]); } else if (fObject.ParentIndex1.Index == -1 && fObject.ParentIndex2.Index == -1) { root.Nodes.Add(parsedNodes[holder.Idx]); } else { Debug.WriteLine("Not added {0}", holder.Data); } } return(root); }