Beispiel #1
0
        unsafe void NodeInformation()
        {
            ImGui.BeginChild("##scrollnode");
            ImGui.Text("Name: " + selectedNode.Name);
            if (selectedNode.Children != null)
            {
                ImGui.Text(selectedNode.Children.Count + " children");
                if (selectedNode != Utf.Root)
                {
                    ImGui.Separator();
                    ImGui.Text("Actions:");
                    if (ImGui.Button("Add Data"))
                    {
                        Confirm("Adding data will delete this node's children. Continue?", () =>
                        {
                            selectedNode.Children = null;
                            selectedNode.Data     = new byte[0];
                        });
                    }
                    if (ImGui.Button("Import Data"))
                    {
                        ImGui.OpenPopup("importactions");
                    }
                    if (ImGui.BeginPopup("importactions"))
                    {
                        if (ImGui.MenuItem("File"))
                        {
                            Confirm("Importing data will delete this node's children. Continue?", () =>
                            {
                                string path;
                                if ((path = FileDialog.Open()) != null)
                                {
                                    selectedNode.Children = null;
                                    selectedNode.Data     = File.ReadAllBytes(path);
                                }
                            });
                        }
                        if (ImGui.MenuItem("Texture"))
                        {
                            Confirm("Importing data will delete this node's children. Continue?", () =>
                            {
                                ImportTexture();
                            });
                        }
                        ImGui.EndPopup();
                    }

                    if (selectedNode.Name.StartsWith("joint map", StringComparison.OrdinalIgnoreCase))
                    {
                        if (ImGui.Button("View Joint Map"))
                        {
                            JointMapView jmv;
                            if ((jmv = JointMapView.Create(selectedNode)) != null)
                            {
                                jointViews.Add(jmv);
                            }
                        }
                        ;
                    }

                    if (selectedNode.Name.StartsWith("object map", StringComparison.OrdinalIgnoreCase))
                    {
                        if (ImGui.Button("View Object Map"))
                        {
                            JointMapView jmv;
                            if ((jmv = JointMapView.Create(selectedNode)) != null)
                            {
                                jointViews.Add(jmv);
                            }
                        }
                        ;
                    }
                }
            }
            else if (selectedNode.Data != null)
            {
                ImGui.Text(string.Format("Size: {0}", LibreLancer.DebugDrawing.SizeSuffix(selectedNode.Data.Length)));
                ImGui.Separator();
                if (selectedNode.Data.Length > 0)
                {
                    ImGui.Text("Previews:");
                    //String Preview
                    ImGui.Text("String:");
                    ImGui.SameLine();
                    ImGui.InputText("##strpreview", selectedNode.Data, (uint)Math.Min(selectedNode.Data.Length, 32), ImGuiInputTextFlags.ReadOnly, DummyCallback);
                    //Float Preview
                    ImGui.Text("Float:");
                    fixed(byte *ptr = selectedNode.Data)
                    {
                        for (int i = 0; i < 4 && (i < selectedNode.Data.Length / 4); i++)
                        {
                            ImGui.SameLine();
                            ImGui.Text(((float *)ptr)[i].ToString());
                        }
                    }

                    //Int Preview
                    ImGui.Text("Int:");
                    fixed(byte *ptr = selectedNode.Data)
                    {
                        for (int i = 0; i < 4 && (i < selectedNode.Data.Length / 4); i++)
                        {
                            ImGui.SameLine();
                            ImGui.Text(((int *)ptr)[i].ToString());
                        }
                    }
                }
                else
                {
                    ImGui.Text("Empty Data");
                }
                ImGui.Separator();
                ImGui.Text("Actions:");
                if (ImGui.Button("Edit"))
                {
                    ImGui.OpenPopup("editactions");
                }
                if (ImGui.BeginPopup("editactions"))
                {
                    if (ImGui.MenuItem("String Editor"))
                    {
                        if (selectedNode.Data.Length > 255)
                        {
                            popups.OpenPopup("Confirm?##stringedit");
                        }
                        else
                        {
                            text.SetBytes(selectedNode.Data, selectedNode.Data.Length);
                            popups.OpenPopup("String Editor");
                        }
                    }
                    if (ImGui.MenuItem("Hex Editor"))
                    {
                        hexdata = new byte[selectedNode.Data.Length];
                        selectedNode.Data.CopyTo(hexdata, 0);
                        mem = new MemoryEditor();
                        popups.OpenPopup("Hex Editor");
                    }
                    if (ImGui.MenuItem("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.MenuItem("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.MenuItem("Color Picker"))
                    {
                        var len = selectedNode.Data.Length / 4;
                        if (len < 3)
                        {
                            pickcolor4 = true;
                            color4     = Color4.Black;
                        }
                        else if (len == 3)
                        {
                            pickcolor4 = false;
                            color3     = new Vector3(
                                BitConverter.ToSingle(selectedNode.Data, 0),
                                BitConverter.ToSingle(selectedNode.Data, 4),
                                BitConverter.ToSingle(selectedNode.Data, 8));
                        }
                        else if (len > 3)
                        {
                            pickcolor4 = true;
                            color4     = new Vector4(
                                BitConverter.ToSingle(selectedNode.Data, 0),
                                BitConverter.ToSingle(selectedNode.Data, 4),
                                BitConverter.ToSingle(selectedNode.Data, 8),
                                BitConverter.ToSingle(selectedNode.Data, 12));
                        }
                        popups.OpenPopup("Color Picker");
                    }
                    ImGui.EndPopup();
                }
                ImGui.NextColumn();
                if (ImGui.Button("Texture Viewer"))
                {
                    Texture 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);
                        if (tex is Texture2D tex2d)
                        {
                            var tab = new TextureViewer(title, tex2d, null);
                            main.AddTab(tab);
                        }
                        else if (tex is TextureCube texcube)
                        {
                            var tab = new CubemapViewer(title, texcube, main);
                            main.AddTab(tab);
                        }
                    }
                    catch (Exception ex)
                    {
                        #if DEBUG
                        throw;
                        #else
                        ErrorPopup("Node data couldn't be opened as texture:\n" + ex.Message);
                        #endif
                    }
                }
                if (ImGui.Button("Play Audio"))
                {
                    var data = main.Audio.AllocateData();
                    using (var stream = new MemoryStream(selectedNode.Data))
                    {
                        main.Audio.PlayStream(stream);
                    }
                }
                if (ImGui.Button("Import Data"))
                {
                    ImGui.OpenPopup("importactions");
                }
                if (ImGui.BeginPopup("importactions"))
                {
                    if (ImGui.MenuItem("File"))
                    {
                        string path;
                        if ((path = FileDialog.Open()) != null)
                        {
                            selectedNode.Data = File.ReadAllBytes(path);
                        }
                    }
                    if (ImGui.MenuItem("Texture"))
                    {
                        ImportTexture();
                    }
                    ImGui.EndPopup();
                }
                if (ImGui.Button("Export Data"))
                {
                    if (selectedNode.Name.ToLowerInvariant() == "vmeshdata")
                    {
                        ImGui.OpenPopup("exportactions");
                    }
                    else
                    {
                        string path;
                        if ((path = FileDialog.Save()) != null)
                        {
                            File.WriteAllBytes(path, selectedNode.Data);
                        }
                    }
                }
                if (ImGui.BeginPopup("exportactions"))
                {
                    if (ImGui.MenuItem("Raw"))
                    {
                        string path;
                        if ((path = FileDialog.Save()) != null)
                        {
                            File.WriteAllBytes(path, selectedNode.Data);
                        }
                    }
                    if (ImGui.MenuItem("VMeshData"))
                    {
                        string path;
                        if ((path = FileDialog.Save()) != null)
                        {
                            LibreLancer.Utf.Vms.VMeshData dat = null;
                            try
                            {
                                dat = new LibreLancer.Utf.Vms.VMeshData(new ArraySegment <byte>(selectedNode.Data), new EmptyLib(), "");
                            }
                            catch (Exception ex)
                            {
                                ErrorPopup(string.Format("Not a valid VMeshData node\n{0}\n{1}", ex.Message, ex.StackTrace));
                            }
                            if (dat != null)
                            {
                                DumpObject.DumpVmeshData(path, dat);
                            }
                        }
                    }
                    ImGui.EndPopup();
                }
            }
            else
            {
                ImGui.Text("Empty");
                ImGui.Separator();
                ImGui.Text("Actions:");
                if (ImGui.Button("Add Data"))
                {
                    selectedNode.Data = new byte[0];
                }
                if (ImGui.Button("Import Data"))
                {
                    ImGui.OpenPopup("importactions");
                }
                if (ImGui.BeginPopup("importactions"))
                {
                    if (ImGui.MenuItem("File"))
                    {
                        string path;
                        if ((path = FileDialog.Open()) != null)
                        {
                            selectedNode.Data = File.ReadAllBytes(path);
                        }
                    }
                    if (ImGui.MenuItem("Texture"))
                    {
                        ImportTexture();
                    }
                    ImGui.EndPopup();
                }
            }

            var removeJmv = new List <JointMapView>();
            foreach (var jm in jointViews)
            {
                if (!jm.Draw())
                {
                    removeJmv.Add(jm);
                }
            }
            foreach (var jmv in removeJmv)
            {
                jointViews.Remove(jmv);
            }
            ImGui.EndChild();
        }
Beispiel #2
0
        unsafe void NodeInformation()
        {
            ImGui.BeginChild("##scrollnode", false, 0);
            ImGui.Text("Name: " + selectedNode.Name);
            if (selectedNode.Children != null)
            {
                ImGui.Text(selectedNode.Children.Count + " children");
                if (selectedNode != Utf.Root)
                {
                    ImGui.Separator();
                    ImGui.Text("Actions:");
                    if (ImGui.Button("Add Data"))
                    {
                        Confirm("Adding data will delete this node's children. Continue?", () =>
                        {
                            selectedNode.Children = null;
                            selectedNode.Data     = new byte[0];
                        });
                    }
                    if (ImGui.Button("Import Data"))
                    {
                        Confirm("Importing data will delete this node's children. Continue?", () =>
                        {
                            string path;
                            if ((path = FileDialog.Open()) != null)
                            {
                                selectedNode.Children = null;
                                selectedNode.Data     = File.ReadAllBytes(path);
                            }
                        });
                    }
                }
            }
            else if (selectedNode.Data != null)
            {
                ImGui.Text(string.Format("Size: {0}", LibreLancer.DebugDrawing.SizeSuffix(selectedNode.Data.Length)));
                ImGui.Separator();
                if (selectedNode.Data.Length > 0)
                {
                    ImGui.Text("Previews:");
                    //String Preview
                    ImGui.Text("String:");
                    ImGui.SameLine();
                    ImGui.InputText("", selectedNode.Data, (uint)Math.Min(selectedNode.Data.Length, 32), InputTextFlags.ReadOnly, DummyCallback);
                    //Float Preview
                    ImGui.Text("Float:");
                    fixed(byte *ptr = selectedNode.Data)
                    {
                        for (int i = 0; i < 4 && (i < selectedNode.Data.Length / 4); i++)
                        {
                            ImGui.SameLine();
                            ImGui.Text(((float *)ptr)[i].ToString());
                        }
                    }

                    //Int Preview
                    ImGui.Text("Int:");
                    fixed(byte *ptr = selectedNode.Data)
                    {
                        for (int i = 0; i < 4 && (i < selectedNode.Data.Length / 4); i++)
                        {
                            ImGui.SameLine();
                            ImGui.Text(((int *)ptr)[i].ToString());
                        }
                    }
                }
                else
                {
                    ImGui.Text("Empty Data");
                }
                ImGui.Separator();
                ImGui.Text("Actions:");
                if (ImGui.Button("Edit"))
                {
                    ImGui.OpenPopup("editactions");
                }
                if (ImGui.BeginPopup("editactions"))
                {
                    if (ImGui.MenuItem("String Editor"))
                    {
                        if (selectedNode.Data.Length > 255)
                        {
                            stringConfirm = true;
                        }
                        else
                        {
                            text.SetBytes(selectedNode.Data, selectedNode.Data.Length);
                            stringEditor = true;
                        }
                    }
                    if (ImGui.MenuItem("Hex Editor"))
                    {
                        hexdata = new byte[selectedNode.Data.Length];
                        selectedNode.Data.CopyTo(hexdata, 0);
                        mem       = new MemoryEditor();
                        hexEditor = true;
                    }
                    if (ImGui.MenuItem("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.MenuItem("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.MenuItem("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;
                    }
                    ImGui.EndPopup();
                }
                ImGui.NextColumn();
                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);
                    }
                }
            }
            else
            {
                ImGui.Text("Empty");
                ImGui.Separator();
                ImGui.Text("Actions:");
                if (ImGui.Button("Add Data"))
                {
                    selectedNode.Data = new byte[0];
                }
                if (ImGui.Button("Import Data"))
                {
                    string path;
                    if ((path = FileDialog.Open()) != null)
                    {
                        selectedNode.Data = File.ReadAllBytes(path);
                    }
                }
            }
            ImGui.EndChild();
        }