Пример #1
0
        void FLTree(OutModel mdl, ref int i)
        {
            var flags = ImGuiTreeNodeFlags.OpenOnDoubleClick |
                        ImGuiTreeNodeFlags.DefaultOpen |
                        ImGuiTreeNodeFlags.OpenOnArrow;

            if (mdl == selected)
            {
                flags |= ImGuiTreeNodeFlags.Selected;
            }
            var open = Theme.IconTreeNode(Icons.Cube_LightPink, $"{mdl.Name}##{i++}", flags);

            if (ImGui.IsItemClicked(0))
            {
                selected = mdl;
            }
            ImGui.SameLine();
            if (open)
            {
                if (ImGui.TreeNode("LODs"))
                {
                    for (int j = 0; j < mdl.LODs.Count; j++)
                    {
                        ImGui.Selectable(string.Format("{0}: {1}", j, mdl.LODs[j].Name));
                    }
                    ImGui.TreePop();
                }
                foreach (var child in mdl.Children)
                {
                    FLTree(child, ref i);
                }
                ImGui.TreePop();
            }
            i += 500;
        }
Пример #2
0
        void DoNode(NodeReference reference, int idx, Vector4 enabled, Vector4 disabled)
        {
            var    col   = instance.NodeEnabled(reference) ? enabled : disabled;
            string label = null;

            if (reference.IsAttachmentNode)
            {
                label = string.Format("Attachment##{0}", idx);
            }
            else
            {
                label = ImGuiExt.IDWithExtra(reference.Node.NodeName, idx);
            }
            ImGui.PushStyleColor(ImGuiCol.Text, col);
            char icon;

            NodeIcon(reference.Node, out icon);
            if (reference.Children.Count > 0)
            {
                if (Theme.IconTreeNode(icon, label, ImGuiTreeNodeFlags.OpenOnDoubleClick | ImGuiTreeNodeFlags.OpenOnArrow))
                {
                    int j = 0;
                    foreach (var child in reference.Children)
                    {
                        DoNode(child, j++, enabled, disabled);
                    }
                    ImGui.TreePop();
                }
            }
            else
            {
                if (ImGui.Selectable($"{icon}  {label}", selectedReference == reference))
                {
                    selectedReference = reference;
                }
            }
            ImGui.PopStyleColor();
        }
Пример #3
0
        void HierarchyPanel()
        {
            if (!(drawable is DF.DfmFile) && !(drawable is SphFile))
            {
                //Sur
                if (ImGui.Button("Open Sur"))
                {
                    var file = FileDialog.Open(SurFilters);
                    surname = System.IO.Path.GetFileName(file);
                    LibreLancer.Physics.Sur.SurFile sur;
                    try
                    {
                        using (var f = System.IO.File.OpenRead(file))
                        {
                            sur = new LibreLancer.Physics.Sur.SurFile(f);
                        }
                    }
                    catch (Exception)
                    {
                        sur = null;
                    }
                    if (sur != null)
                    {
                        ProcessSur(sur);
                    }
                }
                if (surs != null)
                {
                    ImGui.Separator();
                    ImGui.Text("Sur: " + surname);
                    ImGui.Checkbox("Show Hull", ref surShowHull);
                    ImGui.Checkbox("Show Hardpoints", ref surShowHps);
                    ImGui.Separator();
                }
            }
            if (ImGuiExt.Button("Apply Hardpoints", _isDirtyHp))
            {
                if (drawable is ModelFile)
                {
                    hprefs.Nodes[0].HardpointsToNodes(vmsModel.Root.Hardpoints);
                }
                else if (drawable is CmpFile)
                {
                    foreach (var mdl in vmsModel.AllParts)
                    {
                        var node = hprefs.Nodes.First((x) => x.Name == mdl.Path);
                        node.HardpointsToNodes(mdl.Hardpoints);
                    }
                }
                if (_isDirtyHp)
                {
                    _isDirtyHp = false;
                    parent.DirtyCountHp--;
                }
                popups.OpenPopup("Apply Complete");
            }
            if (vmsModel.AllParts.Length > 1 && ImGuiExt.Button("Apply Parts", _isDirtyPart))
            {
                WriteConstructs();
                if (_isDirtyPart)
                {
                    _isDirtyPart = false;
                    parent.DirtyCountPart--;
                }
                popups.OpenPopup("Apply Complete##Parts");
            }
            if (ImGuiExt.ToggleButton("Filter", doFilter))
            {
                doFilter = !doFilter;
            }
            if (doFilter)
            {
                ImGui.InputText("##filter", filterText.Pointer, (uint)filterText.Size, ImGuiInputTextFlags.None, filterText.Callback);
                currentFilter = filterText.GetText();
            }
            else
            {
                currentFilter = null;
            }

            ImGui.Separator();
            if (selectedNode != null)
            {
                ImGui.Text(selectedNode.Construct.ChildName);
                ImGui.Text(selectedNode.Construct.GetType().Name);
                ImGui.Text("Origin: " + selectedNode.Construct.Origin.ToString());
                var euler = selectedNode.Construct.Rotation.GetEulerDegrees();
                ImGui.Text(string.Format("Rotation: (Pitch {0:0.000}, Yaw {1:0.000}, Roll {2:0.000})", euler.X, euler.Y, euler.Z));
                ImGui.Separator();
            }

            if (!vmsModel.Root.Active)
            {
                var col = ImGui.GetStyle().Colors[(int)ImGuiCol.TextDisabled];
                ImGui.PushStyleColor(ImGuiCol.Text, col);
            }
            if (Theme.IconTreeNode(Icons.Tree_DarkGreen, "Root", ImGuiTreeNodeFlags.DefaultOpen))
            {
                if (!vmsModel.Root.Active)
                {
                    ImGui.PopStyleColor();
                }
                RootModelContext(vmsModel.Root.Active);
                if (vmsModel.Root.Children != null)
                {
                    foreach (var n in vmsModel.Root.Children)
                    {
                        DoConstructNode(n);
                    }
                }

                DoModel(vmsModel.Root);
                //if (!(drawable is SphFile)) DoModel(rootModel, null);
                ImGui.TreePop();
            }
            else
            {
                if (!vmsModel.Root.Active)
                {
                    ImGui.PopStyleColor();
                }
                RootModelContext(vmsModel.Root.Active);
            }
        }
Пример #4
0
        void DoModel(RigidModelPart part)
        {
            //Hardpoints
            bool open = Theme.IconTreeNode(Icons.Hardpoints, "Hardpoints");
            var  act  = NewHpMenu(part.Path);

            switch (act)
            {
            case ContextActions.NewFixed:
            case ContextActions.NewRevolute:
                newIsFixed = act == ContextActions.NewFixed;
                addTo      = part;
                newHpBuffer.Clear();
                popups.OpenPopup("New Hardpoint");
                break;
            }
            if (open)
            {
                List <Action> addActions = new List <Action>();
                foreach (var hp in part.Hardpoints)
                {
                    if (doFilter)
                    {
                        if (hp.Name.IndexOf(currentFilter, StringComparison.OrdinalIgnoreCase) == -1)
                        {
                            continue;
                        }
                    }
                    HardpointGizmo gz = null;
                    foreach (var gizmo in gizmos)
                    {
                        if (gizmo.Hardpoint == hp)
                        {
                            gz = gizmo;
                            break;
                        }
                    }

                    if (gz == null)
                    {
                        throw new Exception("gizmo for hp not exist");
                    }
                    if (hp.Definition is RevoluteHardpointDefinition)
                    {
                        ImGui.Text(Icons.Rev_LightSeaGreen.ToString());
                    }
                    else
                    {
                        ImGui.Text(Icons.Cube_Purple.ToString());
                    }
                    ImGui.SameLine();
                    ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, new Vector2(0));
                    ImGui.PushID("visible$" + hp.Name);
                    var push = !gz.Enabled;
                    if (push)
                    {
                        ImGui.PushStyleColor(ImGuiCol.Text, (uint)Color4.Gray.ToAbgr());
                    }
                    if (ImGui.Button(Icons.Eye.ToString()))
                    {
                        gz.Enabled = !gz.Enabled;
                    }
                    if (push)
                    {
                        ImGui.PopStyleColor();
                    }
                    ImGui.PopID();
                    ImGui.PopStyleVar(1);
                    ImGui.SameLine();
                    ImGui.Selectable(ImGuiExt.IDSafe(hp.Name));
                    var action = EditDeleteHpMenu(part.Path + hp.Name);
                    if (action == ContextActions.Delete)
                    {
                        hpDelete     = hp;
                        hpDeleteFrom = part.Hardpoints;
                        popups.OpenPopup("Confirm Delete");
                    }
                    if (action == ContextActions.Edit)
                    {
                        hpEditing = hp;
                    }
                    if (action == ContextActions.MirrorX)
                    {
                        var newHp = MakeDuplicate(GetDupName(hp.Name), hp);
                        //do mirroring
                        newHp.Definition.Position.X   = -newHp.Definition.Position.X;
                        newHp.Definition.Orientation *= new Matrix4x4(
                            -1, 0, 0, 0,
                            0, 1, 0, 0,
                            0, 0, 1, 0,
                            0, 0, 0, 1
                            );
                        //add
                        addActions.Add(() =>
                        {
                            part.Hardpoints.Add(newHp);
                            gizmos.Add(new HardpointGizmo(newHp, gz.Parent));
                            OnDirtyHp();
                        });
                    }
                    if (action == ContextActions.MirrorY)
                    {
                        var newHp = MakeDuplicate(GetDupName(hp.Name), hp);
                        //do mirroring
                        newHp.Definition.Position.Y   = -newHp.Definition.Position.Y;
                        newHp.Definition.Orientation *= new Matrix4x4(
                            1, 0, 0, 0,
                            0, -1, 0, 0,
                            0, 0, 1, 0,
                            0, 0, 0, 1
                            );
                        //add
                        addActions.Add(() =>
                        {
                            part.Hardpoints.Add(newHp);
                            gizmos.Add(new HardpointGizmo(newHp, gz.Parent));
                            OnDirtyHp();
                        });
                    }
                    if (action == ContextActions.MirrorZ)
                    {
                        var newHp = MakeDuplicate(GetDupName(hp.Name), hp);
                        //do mirroring
                        newHp.Definition.Position.Z   = -newHp.Definition.Position.Z;
                        newHp.Definition.Orientation *= new Matrix4x4(
                            1, 0, 0, 0,
                            0, 1, 0, 0,
                            0, 0, -1, 0,
                            0, 0, 0, 1
                            );
                        //add
                        addActions.Add(() =>
                        {
                            part.Hardpoints.Add(newHp);
                            gizmos.Add(new HardpointGizmo(newHp, gz.Parent));
                            OnDirtyHp();
                        });
                    }
                }
                foreach (var action in addActions)
                {
                    action();
                }
                ImGui.TreePop();
            }
        }
Пример #5
0
        void DoConstructNode(RigidModelPart cn)
        {
            var n      = ImGuiExt.IDSafe(string.Format("{0} ({1})", cn.Construct.ChildName, ConType(cn.Construct)));
            var tflags = ImGuiTreeNodeFlags.OpenOnArrow | ImGuiTreeNodeFlags.OpenOnDoubleClick;

            if (selectedNode == cn)
            {
                tflags |= ImGuiTreeNodeFlags.Selected;
            }
            var icon = Icons.Cube_LightYellow;

            if (cn.Construct is PrisConstruct)
            {
                icon = Icons.Con_Pris;
            }
            if (cn.Construct is SphereConstruct)
            {
                icon = Icons.Con_Sph;
            }
            if (cn.Construct is RevConstruct)
            {
                icon = Icons.Rev_LightCoral;
            }
            bool mdlVisible = cn.Active;

            if (!mdlVisible)
            {
                var disabledColor = ImGui.GetStyle().Colors[(int)ImGuiCol.TextDisabled];
                ImGui.PushStyleColor(ImGuiCol.Text, disabledColor);
            }
            if (Theme.IconTreeNode(icon, n, tflags))
            {
                if (!mdlVisible)
                {
                    ImGui.PopStyleColor();
                }
                if (ImGui.IsItemClicked(0))
                {
                    selectedNode = cn;
                }
                ConstructContext(cn, mdlVisible);
                if (cn.Children != null)
                {
                    foreach (var child in cn.Children)
                    {
                        DoConstructNode(child);
                    }
                }
                DoModel(cn);
                ImGui.TreePop();
            }
            else
            {
                if (!mdlVisible)
                {
                    ImGui.PopStyleColor();
                }
                if (ImGui.IsItemClicked(0))
                {
                    selectedNode = cn;
                }
                ConstructContext(cn, mdlVisible);
            }
        }