public UtfTab(MainWindow main, EditableUtf utf, string title) { this.main = main; Utf = utf; Title = title; text = new TextBuffer(); main.Resources.AddResources(utf.Export(), Unique.ToString()); }
public UtfTab(MainWindow main, EditableUtf utf, string title) { this.main = main; Utf = utf; DocumentName = title; Title = string.Format("{0}##{1}", title, Unique); text = new TextBuffer(); main.Resources.AddResources(utf.Export(), Unique.ToString()); RegisterPopups(); }
//generated parameter is used for utf generated internally, like from the collada exporter //saves a bunch of copies when opening a large UTF from disk public UtfTab(MainWindow main, EditableUtf utf, string title, bool generated = false) { this.main = main; Utf = utf; DocumentName = title; Title = title; text = new TextBuffer(); if (generated) { utf.Source = utf.Export(); } if (utf.Source != null) { main.Resources.AddResources(utf.Source, Unique.ToString()); utf.Source = null; } RegisterPopups(); }
public override void Draw() { //Child Window var size = ImGui.GetWindowSize(); ImGui.BeginChild("##utfchild", new Vector2(size.X - 15, size.Y - 50), false, 0); //Layout if (selectedNode != null) { ImGui.Columns(2, "NodeColumns", true); } //Headers ImGui.Separator(); ImGui.Text("Nodes"); if (selectedNode != null) { ImGui.NextColumn(); ImGui.Text("Node Information"); ImGui.NextColumn(); } ImGui.Separator(); //Tree ImGui.BeginChild("##scroll"); var flags = selectedNode == Utf.Root ? ImGuiTreeNodeFlags.Selected | tflags : tflags; var isOpen = ImGui.TreeNodeEx("/", flags); if (ImGui.IsItemClicked(0)) { selectedNode = Utf.Root; } ImGui.PushID("/##ROOT"); DoNodeMenu("/##ROOT", Utf.Root, null); ImGui.PopID(); if (isOpen) { for (int i = 0; i < Utf.Root.Children.Count; i++) { DoNode(Utf.Root.Children[i], Utf.Root, i); } ImGui.TreePop(); } ImGui.EndChild(); //End Tree if (selectedNode != null) { //Node preview ImGui.NextColumn(); NodeInformation(); } //Action Bar ImGui.EndChild(); ImGui.Separator(); if (ImGui.Button("Actions")) { ImGui.OpenPopup("actions"); } if (ImGui.BeginPopup("actions")) { if (ImGui.MenuItem("View Model")) { IDrawable drawable = null; ModelNodes hpn = new ModelNodes(); try { drawable = LibreLancer.Utf.UtfLoader.GetDrawable(Utf.Export(), main.Resources); drawable.Initialize(main.Resources); if (Utf.Root.Children.Any((x) => x.Name.Equals("cmpnd", StringComparison.OrdinalIgnoreCase))) { foreach (var child in Utf.Root.Children.Where((x) => x.Name.EndsWith(".3db", StringComparison.OrdinalIgnoreCase))) { var n = new ModelHpNode(); n.Name = child.Name; n.Node = child; n.HardpointsNode = child.Children.FirstOrDefault((x) => x.Name.Equals("hardpoints", StringComparison.OrdinalIgnoreCase)); hpn.Nodes.Add(n); } var cmpnd = Utf.Root.Children.First((x) => x.Name.Equals("cmpnd", StringComparison.OrdinalIgnoreCase)); hpn.Cons = cmpnd.Children.FirstOrDefault((x) => x.Name.Equals("cons", StringComparison.OrdinalIgnoreCase)); } else { var n = new ModelHpNode(); n.Name = "ROOT"; n.Node = Utf.Root; n.HardpointsNode = Utf.Root.Children.FirstOrDefault((x) => x.Name.Equals("hardpoints", StringComparison.OrdinalIgnoreCase)); hpn.Nodes.Add(n); } } catch (Exception ex) { ErrorPopup("Could not open as model\n" + ex.Message + "\n" + ex.StackTrace); drawable = null; } if (drawable != null) { main.AddTab(new ModelViewer(DocumentName, drawable, main, this, hpn)); } } if (ImGui.MenuItem("Export Collada")) { LibreLancer.Utf.Cmp.ModelFile model = null; LibreLancer.Utf.Cmp.CmpFile cmp = null; try { var drawable = LibreLancer.Utf.UtfLoader.GetDrawable(Utf.Export(), main.Resources); model = (drawable as LibreLancer.Utf.Cmp.ModelFile); cmp = (drawable as LibreLancer.Utf.Cmp.CmpFile); } catch (Exception) { ErrorPopup("Could not open as model"); model = null; } if (model != null) { var output = FileDialog.Save(); if (output != null) { model.Path = DocumentName; try { ColladaExport.ExportCollada(model, main.Resources, output); } catch (Exception ex) { ErrorPopup("Error\n" + ex.Message + "\n" + ex.StackTrace); } } } if (cmp != null) { var output = FileDialog.Save(); if (output != null) { cmp.Path = DocumentName; try { ColladaExport.ExportCollada(cmp, main.Resources, output); } catch (Exception ex) { ErrorPopup("Error\n" + ex.Message + "\n" + ex.StackTrace); } } } } if (ImGui.MenuItem("View Ale")) { AleFile ale = null; try { ale = new AleFile(Utf.Export()); } catch (Exception) { ErrorPopup("Could not open as ale"); ale = null; } if (ale != null) { main.AddTab(new AleViewer(Title, ale, main)); } } if (ImGui.MenuItem("Resolve Audio Hashes")) { var folder = FileDialog.ChooseFolder(); if (folder != null) { var idtable = new IDTable(folder); foreach (var n in Utf.Root.IterateAll()) { if (n.Name.StartsWith("0x")) { uint v; if (uint.TryParse(n.Name.Substring(2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out v)) { idtable.UtfNicknameTable.TryGetValue(v, out n.ResolvedName); } } else { n.ResolvedName = null; } } } } ImGui.EndPopup(); } ImGui.SameLine(); if (ImGui.Button("Reload Resources")) { main.Resources.RemoveResourcesForId(Unique.ToString()); main.Resources.AddResources(Utf.Export(), Unique.ToString()); } Popups(); }
public override bool Draw() { //Child Window var size = ImGui.GetWindowSize(); ImGui.BeginChild("##utfchild", new Vector2(size.X - 15, size.Y - 50), false, 0); //Layout if (selectedNode != null) { ImGui.Columns(2, "NodeColumns", true); } //Headers ImGui.Separator(); ImGui.Text("Nodes"); if (selectedNode != null) { ImGui.NextColumn(); ImGui.Text("Node Information"); ImGui.NextColumn(); } ImGui.Separator(); //Tree ImGui.BeginChild("##scroll", false, 0); var flags = selectedNode == Utf.Root ? TreeNodeFlags.Selected | tflags : tflags; var isOpen = ImGui.TreeNodeEx("/", flags); if (ImGuiNative.igIsItemClicked(0)) { selectedNode = Utf.Root; } ImGui.PushID("/##ROOT"); DoNodeMenu("/##ROOT", Utf.Root, null); ImGui.PopID(); if (isOpen) { for (int i = 0; i < Utf.Root.Children.Count; i++) { DoNode(Utf.Root.Children[i], Utf.Root, i); } ImGui.TreePop(); } ImGui.EndChild(); //End Tree if (selectedNode != null) { //Node preview ImGui.NextColumn(); NodeInformation(); } //Action Bar ImGui.EndChild(); ImGui.Separator(); if (ImGui.Button("Actions")) { ImGui.OpenPopup("actions"); } if (ImGui.BeginPopup("actions")) { if (ImGui.MenuItem("View Model")) { IDrawable drawable = null; try { drawable = LibreLancer.Utf.UtfLoader.GetDrawable(Utf.Export(), main.Resources); drawable.Initialize(main.Resources); } catch (Exception) { ErrorPopup("Could not open as model"); drawable = null; } if (drawable != null) { main.AddTab(new ModelViewer("Model Viewer (" + Title + ")", Title, drawable, main, this)); } } if (ImGui.MenuItem("View Ale")) { AleFile ale = null; try { ale = new AleFile(Utf.Export()); } catch (Exception) { ErrorPopup("Could not open as ale"); ale = null; } if (ale != null) { main.AddTab(new AleViewer("Ale Viewer (" + Title + ")", Title, ale, main)); } } if (ImGui.MenuItem("Refresh Resources")) { main.Resources.RemoveResourcesForId(Unique.ToString()); main.Resources.AddResources(Utf.Export(), Unique.ToString()); } ImGui.EndPopup(); } Popups(); return(open); }
void NodeInformation() { ImGui.Text("Name: " + selectedNode.Name); if (selectedNode.Children != null) { ImGui.Text(selectedNode.Children.Count + " children"); } else { ImGui.Text(string.Format("Size: {0}", LibreLancer.DebugDrawing.SizeSuffix(selectedNode.Data.Length))); if (ImGui.Button("Hex Editor")) { hexdata = new byte[selectedNode.Data.Length]; selectedNode.Data.CopyTo(hexdata, 0); mem = new MemoryEditor(); hexEditor = true; } if (ImGui.Button("Float Editor")) { floats = new float[selectedNode.Data.Length / 4]; for (int i = 0; i < selectedNode.Data.Length / 4; i++) { floats[i] = BitConverter.ToSingle(selectedNode.Data, i * 4); } floatEditor = true; } if (ImGui.Button("Int Editor")) { ints = new int[selectedNode.Data.Length / 4]; for (int i = 0; i < selectedNode.Data.Length / 4; i++) { ints[i] = BitConverter.ToInt32(selectedNode.Data, i * 4); } intEditor = true; } if (ImGui.Button("Color Picker")) { var len = selectedNode.Data.Length / 4; if (len < 3) { pickcolor4 = true; color4 = new System.Numerics.Vector4(0, 0, 0, 1); } else if (len == 3) { pickcolor4 = false; color3 = new System.Numerics.Vector3( BitConverter.ToSingle(selectedNode.Data, 0), BitConverter.ToSingle(selectedNode.Data, 4), BitConverter.ToSingle(selectedNode.Data, 8)); } else if (len > 3) { pickcolor4 = true; color4 = new System.Numerics.Vector4( BitConverter.ToSingle(selectedNode.Data, 0), BitConverter.ToSingle(selectedNode.Data, 4), BitConverter.ToSingle(selectedNode.Data, 8), BitConverter.ToSingle(selectedNode.Data, 12)); } colorPicker = true; } if (ImGui.Button("Texture Viewer")) { Texture2D tex = null; try { using (var stream = new MemoryStream(selectedNode.Data)) { tex = LibreLancer.ImageLib.Generic.FromStream(stream); } var title = string.Format("{0} ({1})", selectedNode.Name, Title); var tab = new TextureViewer(title, tex); main.AddTab(tab); } catch (Exception) { ErrorPopup("Node data couldn't be opened as texture"); } } if (ImGui.Button("Play Audio")) { var data = main.Audio.AllocateData(); using (var stream = new MemoryStream(selectedNode.Data)) { main.Audio.PlaySound(stream); } } if (ImGui.Button("Import Data")) { string path; if ((path = FileDialog.Open()) != null) { selectedNode.Data = File.ReadAllBytes(path); } } if (ImGui.Button("Export Data")) { string path; if ((path = FileDialog.Save()) != null) { File.WriteAllBytes(path, selectedNode.Data); } } if (ImGui.Button("View Model")) { IDrawable drawable = null; try { drawable = LibreLancer.Utf.UtfLoader.GetDrawable(Utf.Export(), main.Resources); drawable.Initialize(main.Resources); } catch (Exception) { ErrorPopup("Could not open as model"); drawable = null; } if (drawable != null) { main.AddTab(new ModelViewer("Model Viewer", drawable, main.RenderState, main.Viewport)); } } } }