Exemple #1
0
        void DoNode(LUtfNode node, LUtfNode parent, int idx)
        {
            string id = ImGuiExt.IDWithExtra(node.Name, parent.Name + idx);

            if (node.Children != null)
            {
                var flags  = selectedNode == node ? ImGuiTreeNodeFlags.Selected | tflags : tflags;
                var isOpen = ImGui.TreeNodeEx(id, flags);
                if (ImGui.IsItemClicked(0))
                {
                    selectedNode = node;
                }
                if (node.ResolvedName != null)
                {
                    ImGui.SameLine();
                    ImGui.TextDisabled("(" + ImGuiExt.IDSafe(node.ResolvedName) + ")");
                }
                ImGui.PushID(id);
                DoNodeMenu(id, node, parent);
                ImGui.PopID();
                //int i = 0;
                if (isOpen)
                {
                    for (int i = 0; i < node.Children.Count; i++)
                    {
                        DoNode(node.Children[i], node, (idx * 1024) + i);
                    }
                    ImGui.TreePop();
                }
            }
            else
            {
                if (node.Data != null)
                {
                    ImGui.Bullet();
                }
                else
                {
                    Theme.Icon("node_empty", Color4.White);
                    ImGui.SameLine();
                }
                bool selected = selectedNode == node;
                if (ImGui.Selectable(id, ref selected))
                {
                    selectedNode = node;
                }
                if (node.ResolvedName != null)
                {
                    ImGui.SameLine();
                    ImGui.TextDisabled("(" + ImGuiExt.IDSafe(node.ResolvedName) + ")");
                }
                DoNodeMenu(id, node, parent);
            }
        }
Exemple #2
0
 void DoModel(ModelFile mdl)
 {
     if (mdl.Hardpoints.Count > 0)
     {
         if (ImGui.TreeNode(ImGuiExt.Pad("Hardpoints")))
         {
             Theme.RenderTreeIcon("Hardpoints", "hardpoint", Color4.CornflowerBlue);
             foreach (var hp in mdl.Hardpoints)
             {
                 HardpointGizmo gz = null;
                 foreach (var gizmo in gizmos)
                 {
                     if (gizmo.Definition == hp)
                     {
                         gz = gizmo;
                         break;
                     }
                 }
                 if (hp is RevoluteHardpointDefinition)
                 {
                     Theme.Icon("rev", Color4.LightSeaGreen);
                 }
                 else
                 {
                     Theme.Icon("fix", Color4.Purple);
                 }
                 ImGui.SameLine();
                 if (Theme.IconButton("visible$" + hp.Name, "eye", gz.Enabled ? Color4.White : Color4.Gray))
                 {
                     gz.Enabled = !gz.Enabled;
                 }
                 ImGui.SameLine();
                 ImGui.Text(hp.Name);
             }
             ImGui.TreePop();
         }
         else
         {
             Theme.RenderTreeIcon("Hardpoints", "hardpoint", Color4.CornflowerBlue);
         }
     }
     else
     {
         Theme.Icon("hardpoint", Color4.CornflowerBlue);
         ImGui.SameLine();
         ImGui.Text("Hardpoints");
     }
 }
        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 = string.Format("{0}##{1}", reference.Node.NodeName, idx);
            }
            ImGui.PushStyleColor(ImGuiCol.Text, col);
            string icon;
            Color4 color;

            NodeIcon(reference.Node, out icon, out color);
            if (reference.Children.Count > 0)
            {
                if (ImGui.TreeNodeEx(ImGuiExt.Pad(label), ImGuiTreeNodeFlags.OpenOnDoubleClick | ImGuiTreeNodeFlags.OpenOnArrow))
                {
                    Theme.RenderTreeIcon(label.Split('#')[0], icon, color);
                    int j = 0;
                    foreach (var child in reference.Children)
                    {
                        DoNode(child, j++, enabled, disabled);
                    }
                    ImGui.TreePop();
                }
                else
                {
                    Theme.RenderTreeIcon(label.Split('#')[0], icon, color);
                }
            }
            else
            {
                Theme.Icon(icon, color);
                ImGui.SameLine();

                if (ImGui.Selectable(label, selectedReference == reference))
                {
                    selectedReference = reference;
                }
            }
            ImGui.PopStyleColor();
        }
Exemple #4
0
        void DoNode(LUtfNode node, LUtfNode parent, int idx)
        {
            string id = node.Name + "##" + parent.Name + idx;

            if (node.Children != null)
            {
                var flags  = selectedNode == node ? TreeNodeFlags.Selected | tflags : tflags;
                var isOpen = ImGui.TreeNodeEx(id, flags);
                if (ImGuiNative.igIsItemClicked(0))
                {
                    selectedNode = node;
                }
                ImGui.PushID(id);
                DoNodeMenu(id, node, parent);
                ImGui.PopID();
                //int i = 0;
                if (isOpen)
                {
                    for (int i = 0; i < node.Children.Count; i++)
                    {
                        DoNode(node.Children[i], node, (idx * 1024) + i);
                    }
                    ImGui.TreePop();
                }
            }
            else
            {
                if (node.Data != null)
                {
                    ImGui.Bullet();
                }
                else
                {
                    Theme.Icon("node_empty", Color4.White);
                    ImGui.SameLine();
                }
                bool selected = selectedNode == node;
                if (ImGui.SelectableEx(id, ref selected))
                {
                    selectedNode = node;
                }
                DoNodeMenu(id, node, parent);
            }
        }
        public static void DropdownButton(string id, ref int selected, IReadOnlyList <DropdownOption> options)
        {
            ImGui.PushID(id);
            bool         clicked = false;
            const string PADDING = "       ";
            string       text    = PADDING + ImGuiExt.IDSafe(options[selected].Name) + "   ";
            var          w       = ImGui.CalcTextSize(text).X;

            clicked = ImGui.Button(text);
            ImGui.SameLine();
            var cpos  = ImGuiNative.igGetCursorPosX();
            var cposY = ImGuiNative.igGetCursorPosY();

            Theme.TinyTriangle(cpos - 15, cposY + 15);
            ImGuiNative.igSetCursorPosX(cpos - w - 13);
            ImGuiNative.igSetCursorPosY(cposY + 2);
            Theme.Icon(options[selected].Icon, Color4.White);
            ImGui.SameLine();
            ImGuiNative.igSetCursorPosY(cposY);
            ImGui.SetCursorPosX(cpos - 6);
            ImGui.Dummy(Vector2.Zero);
            if (clicked)
            {
                ImGui.OpenPopup(id + "#popup");
            }
            if (ImGui.BeginPopup(id + "#popup"))
            {
                ImGui.MenuItem(id, false);
                for (int i = 0; i < options.Count; i++)
                {
                    var opt = options[i];
                    if (Theme.IconMenuItem(opt.Name, opt.Icon, Color4.White, true))
                    {
                        selected = i;
                    }
                }
                ImGui.EndPopup();
            }
            ImGui.PopID();
        }
Exemple #6
0
        protected override void Draw(double elapsed)
        {
            //Don't process all the imgui stuff when it isn't needed
            if (!loadingSpinnerActive && !guiHelper.DoRender(elapsed))
            {
                if (lastFrame != null)
                {
                    lastFrame.BlitToScreen();
                }
                WaitForEvent(); //Yield like a regular GUI program
                return;
            }
            TimeStep = elapsed;
            Viewport.Replace(0, 0, Width, Height);
            RenderState.ClearColor = new Color4(0.2f, 0.2f, 0.2f, 1f);
            RenderState.ClearAll();
            guiHelper.NewFrame(elapsed);
            ImGui.PushFont(ImGuiHelper.Noto);
            ImGui.BeginMainMenuBar();
            if (ImGui.BeginMenu("File"))
            {
                if (Theme.IconMenuItem("New", "new", Color4.White, true))
                {
                    var t = new UtfTab(this, new EditableUtf(), "Untitled");
                    ActiveTab = t;
                    AddTab(t);
                }
                if (Theme.IconMenuItem("Open", "open", Color4.White, true))
                {
                    var f = FileDialog.Open(UtfFilters);
                    OpenFile(f);
                }
                if (ActiveTab == null)
                {
                    Theme.IconMenuItem("Save", "save", Color4.LightGray, false);
                    Theme.IconMenuItem("Save As", "saveas", Color4.LightGray, false);
                }
                else
                {
                    if (Theme.IconMenuItem(string.Format("Save '{0}'", ActiveTab.DocumentName), "saveas", Color4.White, true))
                    {
                        Save();
                    }
                    if (Theme.IconMenuItem("Save As", "saveas", Color4.White, true))
                    {
                        SaveAs();
                    }
                }
                if (Theme.IconMenuItem("Quit", "quit", Color4.White, true))
                {
                    Exit();
                }
                ImGui.EndMenu();
            }
            if (ImGui.BeginMenu("View"))
            {
                Theme.IconMenuToggle("Log", "log", Color4.White, ref showLog, true);
                ImGui.EndMenu();
            }
            if (ImGui.BeginMenu("Tools"))
            {
                if (Theme.IconMenuItem("Options", "options", Color4.White, true))
                {
                    options.Show();
                }

                if (Theme.IconMenuItem("Resources", "resources", Color4.White, true))
                {
                    AddTab(new ResourcesTab(this, Resources, MissingResources, ReferencedMaterials, ReferencedTextures));
                }
                if (Theme.IconMenuItem("Import Collada", "import", Color4.White, true))
                {
                    string input;
                    if ((input = FileDialog.Open(ColladaFilters)) != null)
                    {
                        StartLoadingSpinner();
                        new Thread(() =>
                        {
                            List <ColladaObject> dae = null;
                            try
                            {
                                dae = ColladaSupport.Parse(input);
                                EnsureUIThread(() => FinishColladaLoad(dae, System.IO.Path.GetFileName(input)));
                            }
                            catch (Exception ex)
                            {
                                EnsureUIThread(() => ColladaError(ex));
                            }
                        }).Start();
                    }
                }
                if (Theme.IconMenuItem("Generate Icon", "genicon", Color4.White, true))
                {
                    string input;
                    if ((input = FileDialog.Open(ImageFilter)) != null)
                    {
                        gen3dbDlg.Open(input);
                    }
                }
                if (Theme.IconMenuItem("Infocard Browser", "browse", Color4.White, true))
                {
                    string input;
                    if ((input = FileDialog.Open(FreelancerIniFilter)) != null)
                    {
                        AddTab(new InfocardBrowserTab(input, this));
                    }
                }
                if (ImGui.MenuItem("Projectile Viewer"))
                {
                    if (ProjectileViewer.Create(this, out var pj))
                    {
                        tabs.Add(pj);
                    }
                }
                ImGui.EndMenu();
            }
            if (ImGui.BeginMenu("Help"))
            {
                if (Theme.IconMenuItem("Topics", "help", Color4.White, true))
                {
                    Shell.OpenCommand("https://wiki.librelancer.net/lanceredit:lanceredit");
                }
                if (Theme.IconMenuItem("About", "about", Color4.White, true))
                {
                    openAbout = true;
                }
                ImGui.EndMenu();
            }

            options.Draw();
            if (openAbout)
            {
                ImGui.OpenPopup("About");
                openAbout = false;
            }
            if (openError)
            {
                ImGui.OpenPopup("Error");
                openError = false;
            }

            if (openLoading)
            {
                ImGui.OpenPopup("Processing");
                openLoading = false;
            }
            bool pOpen = true;

            if (ImGui.BeginPopupModal("Error", ref pOpen, ImGuiWindowFlags.AlwaysAutoResize))
            {
                ImGui.Text("Error:");
                errorText.InputTextMultiline("##etext", new Vector2(430, 200), ImGuiInputTextFlags.ReadOnly);
                if (ImGui.Button("OK"))
                {
                    ImGui.CloseCurrentPopup();
                }
                ImGui.EndPopup();
            }
            pOpen = true;
            if (ImGui.BeginPopupModal("About", ref pOpen, ImGuiWindowFlags.AlwaysAutoResize))
            {
                ImGui.SameLine(ImGui.GetWindowWidth() / 2 - 64);
                Theme.Icon("reactor_128", Color4.White);
                CenterText(Version);
                CenterText("Callum McGing 2018-2020");
                ImGui.Separator();
                CenterText("Icons from Icons8: https://icons8.com/");
                CenterText("Icons from komorra: https://opengameart.org/content/kmr-editor-icon-set");
                ImGui.Separator();
                var btnW = ImGui.CalcTextSize("OK").X + ImGui.GetStyle().FramePadding.X * 2;
                ImGui.Dummy(Vector2.One);
                ImGui.SameLine(ImGui.GetWindowWidth() / 2 - (btnW / 2));
                if (ImGui.Button("OK"))
                {
                    ImGui.CloseCurrentPopup();
                }
                ImGui.EndPopup();
            }
            pOpen = true;
            if (ImGuiExt.BeginModalNoClose("Processing", ImGuiWindowFlags.AlwaysAutoResize))
            {
                ImGuiExt.Spinner("##spinner", 10, 2, ImGuiNative.igGetColorU32(ImGuiCol.ButtonHovered, 1));
                ImGui.SameLine();
                ImGui.Text("Processing");
                if (finishLoading)
                {
                    ImGui.CloseCurrentPopup();
                }
                ImGui.EndPopup();
            }
            //Confirmation
            if (doConfirm)
            {
                ImGui.OpenPopup("Confirm?##mainwindow");
                doConfirm = false;
            }
            pOpen = true;
            if (ImGui.BeginPopupModal("Confirm?##mainwindow", ref pOpen, ImGuiWindowFlags.AlwaysAutoResize))
            {
                ImGui.Text(confirmText);
                if (ImGui.Button("Yes"))
                {
                    confirmAction();
                    ImGui.CloseCurrentPopup();
                }
                ImGui.SameLine();
                if (ImGui.Button("No"))
                {
                    ImGui.CloseCurrentPopup();
                }
                ImGui.EndPopup();
            }
            var menu_height = ImGui.GetWindowSize().Y;

            ImGui.EndMainMenuBar();
            var size = ImGui.GetIO().DisplaySize;

            size.Y -= menu_height;
            //Window
            MissingResources.Clear();
            ReferencedMaterials.Clear();
            ReferencedTextures.Clear();
            foreach (var tab in tabs)
            {
                ((EditorTab)tab).DetectResources(MissingResources, ReferencedMaterials, ReferencedTextures);
            }
            ImGui.SetNextWindowSize(new Vector2(size.X, size.Y - 25), ImGuiCond.Always);
            ImGui.SetNextWindowPos(new Vector2(0, menu_height), ImGuiCond.Always, Vector2.Zero);
            bool childopened = true;

            ImGui.Begin("tabwindow", ref childopened,
                        ImGuiWindowFlags.NoTitleBar |
                        ImGuiWindowFlags.NoSavedSettings |
                        ImGuiWindowFlags.NoBringToFrontOnFocus |
                        ImGuiWindowFlags.NoMove |
                        ImGuiWindowFlags.NoResize);
            TabHandler.TabLabels(tabs, ref selected);
            var totalH = ImGui.GetWindowHeight();

            if (showLog)
            {
                ImGuiExt.SplitterV(2f, ref h1, ref h2, 8, 8, -1);
                h1 = totalH - h2 - 24f;
                if (tabs.Count > 0)
                {
                    h1 -= 20f;
                }
                ImGui.BeginChild("###tabcontent" + (selected != null ? selected.RenderTitle : ""), new Vector2(-1, h1), false, ImGuiWindowFlags.None);
            }
            else
            {
                ImGui.BeginChild("###tabcontent" + (selected != null ? selected.RenderTitle : ""));
            }
            if (selected != null)
            {
                selected.Draw();
                ((EditorTab)selected).SetActiveTab(this);
            }
            else
            {
                ActiveTab = null;
            }
            ImGui.EndChild();
            if (showLog)
            {
                ImGui.BeginChild("###log", new Vector2(-1, h2), false, ImGuiWindowFlags.None);
                ImGui.Text("Log");
                ImGui.SameLine(ImGui.GetWindowWidth() - 20);
                if (Theme.IconButton("closelog", "x", Color4.White))
                {
                    showLog = false;
                }
                logBuffer.InputTextMultiline("##logtext", new Vector2(-1, h2 - 24), ImGuiInputTextFlags.ReadOnly);
                ImGui.EndChild();
            }
            ImGui.End();
            gen3dbDlg.Draw();
            //Status bar
            ImGui.SetNextWindowSize(new Vector2(size.X, 25f), ImGuiCond.Always);
            ImGui.SetNextWindowPos(new Vector2(0, size.Y - 6f), ImGuiCond.Always, Vector2.Zero);
            bool sbopened = true;

            ImGui.Begin("statusbar", ref sbopened,
                        ImGuiWindowFlags.NoTitleBar |
                        ImGuiWindowFlags.NoSavedSettings |
                        ImGuiWindowFlags.NoBringToFrontOnFocus |
                        ImGuiWindowFlags.NoMove |
                        ImGuiWindowFlags.NoResize);
            if (updateTime > 9)
            {
                updateTime = 0;
                frequency  = RenderFrequency;
            }
            else
            {
                updateTime++;
            }
            string activename = ActiveTab == null ? "None" : ActiveTab.DocumentName;
            string utfpath    = ActiveTab == null ? "None" : ActiveTab.GetUtfPath();

            #if DEBUG
            const string statusFormat = "FPS: {0} | {1} Materials | {2} Textures | Active: {3} - {4}";
            #else
            const string statusFormat = "{1} Materials | {2} Textures | Active: {3} - {4}";
            #endif
            ImGui.Text(string.Format(statusFormat,
                                     (int)Math.Round(frequency),
                                     Resources.MaterialDictionary.Count,
                                     Resources.TextureDictionary.Count,
                                     activename,
                                     utfpath));
            ImGui.End();
            if (errorTimer > 0)
            {
                ImGuiExt.ToastText("An error has occurred\nCheck the log for details",
                                   new Color4(21, 21, 22, 128),
                                   Color4.Red);
            }
            ImGui.PopFont();
            if (lastFrame == null ||
                lastFrame.Width != Width ||
                lastFrame.Height != Height)
            {
                if (lastFrame != null)
                {
                    lastFrame.Dispose();
                }
                lastFrame = new RenderTarget2D(Width, Height);
            }
            RenderState.RenderTarget = lastFrame;
            RenderState.ClearColor   = new Color4(0.2f, 0.2f, 0.2f, 1f);
            RenderState.ClearAll();
            guiHelper.Render(RenderState);
            RenderState.RenderTarget = null;
            lastFrame.BlitToScreen();
            foreach (var tab in toAdd)
            {
                tabs.Add(tab);
                selected = tab;
            }
            toAdd.Clear();
        }
Exemple #7
0
        void DoModel(RigidModelPart part)
        {
            //Hardpoints
            bool open = ImGui.TreeNode(ImGuiExt.Pad("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;
            }
            Theme.RenderTreeIcon("Hardpoints", "hardpoint", Color4.CornflowerBlue);
            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 (hp.Definition is RevoluteHardpointDefinition)
                    {
                        Theme.Icon("rev", Color4.LightSeaGreen);
                    }
                    else
                    {
                        Theme.Icon("fix", Color4.Purple);
                    }
                    ImGui.SameLine();
                    if (Theme.IconButton("visible$" + hp.Name, "eye", gz.Enabled ? Color4.White : Color4.Gray))
                    {
                        gz.Enabled = !gz.Enabled;
                    }
                    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();
            }
        }
Exemple #8
0
        protected override void Draw(double elapsed)
        {
            TimeStep = elapsed;
            Viewport.Replace(0, 0, Width, Height);
            RenderState.ClearColor = new Color4(0.2f, 0.2f, 0.2f, 1f);
            RenderState.ClearAll();
            guiHelper.NewFrame(elapsed);
            ImGui.PushFont(ImGuiHelper.Noto);
            ImGui.BeginMainMenuBar();
            if (ImGui.BeginMenu("File"))
            {
                if (Theme.IconMenuItem("New", "new", Color4.White, true))
                {
                    var t = new UtfTab(this, new EditableUtf(), "Untitled");
                    ActiveTab = t;
                    AddTab(t);
                }
                if (Theme.IconMenuItem("Open", "open", Color4.White, true))
                {
                    var f = FileDialog.Open(UtfFilters);
                    OpenFile(f);
                }
                if (ActiveTab == null)
                {
                    Theme.IconMenuItem("Save", "save", Color4.LightGray, false);
                }
                else
                {
                    if (Theme.IconMenuItem(string.Format("Save '{0}'", ActiveTab.DocumentName), "save", Color4.White, true))
                    {
                        var f = FileDialog.Save(UtfFilters);
                        if (f != null)
                        {
                            ActiveTab.DocumentName = System.IO.Path.GetFileName(f);
                            ActiveTab.UpdateTitle();
                            string errText = "";
                            if (!ActiveTab.Utf.Save(f, ref errText))
                            {
                                openError = true;
                                if (errorText == null)
                                {
                                    errorText = new TextBuffer();
                                }
                                errorText.SetText(errText);
                            }
                        }
                    }
                }
                if (Theme.IconMenuItem("Quit", "quit", Color4.White, true))
                {
                    Exit();
                }
                ImGui.EndMenu();
            }
            bool openLoading = false;

            if (ImGui.BeginMenu("View"))
            {
                Theme.IconMenuToggle("Log", "log", Color4.White, ref showLog, true);
                ImGui.EndMenu();
            }
            if (ImGui.BeginMenu("Tools"))
            {
                if (Theme.IconMenuItem("Options", "options", Color4.White, true))
                {
                    showOptions = true;
                }

                if (Theme.IconMenuItem("Resources", "resources", Color4.White, true))
                {
                    AddTab(new ResourcesTab(Resources, MissingResources, ReferencedMaterials, ReferencedTextures));
                }
                if (Theme.IconMenuItem("Import Collada", "import", Color4.White, true))
                {
                    string input;
                    if ((input = FileDialog.Open(ColladaFilters)) != null)
                    {
                        openLoading   = true;
                        finishLoading = false;
                        new Thread(() =>
                        {
                            List <ColladaObject> dae = null;
                            try
                            {
                                dae = ColladaSupport.Parse(input);
                                EnsureUIThread(() => FinishColladaLoad(dae, System.IO.Path.GetFileName(input)));
                            }
                            catch (Exception ex)
                            {
                                EnsureUIThread(() => ColladaError(ex));
                            }
                        }).Start();
                    }
                }
                ImGui.EndMenu();
            }
            if (ImGui.BeginMenu("Help"))
            {
                if (Theme.IconMenuItem("Topics", "help", Color4.White, true))
                {
                    Shell.OpenCommand("https://wiki.librelancer.net/lanceredit:lanceredit");
                }
                if (Theme.IconMenuItem("About", "about", Color4.White, true))
                {
                    openAbout = true;
                }
                ImGui.EndMenu();
            }
            if (openAbout)
            {
                ImGui.OpenPopup("About");
                openAbout = false;
            }
            if (openError)
            {
                ImGui.OpenPopup("Error");
                openError = false;
            }
            if (openLoading)
            {
                ImGui.OpenPopup("Processing");
            }
            bool pOpen = true;

            if (ImGui.BeginPopupModal("Error", ref pOpen, ImGuiWindowFlags.AlwaysAutoResize))
            {
                ImGui.Text("Error:");
                errorText.InputTextMultiline("##etext", new Vector2(430, 200), ImGuiInputTextFlags.ReadOnly);
                if (ImGui.Button("OK"))
                {
                    ImGui.CloseCurrentPopup();
                }
                ImGui.EndPopup();
            }
            pOpen = true;
            if (ImGui.BeginPopupModal("About", ref pOpen, ImGuiWindowFlags.AlwaysAutoResize))
            {
                ImGui.SameLine(ImGui.GetWindowWidth() / 2 - 64);
                Theme.Icon("reactor_128", Color4.White);
                CenterText(Version);
                CenterText("Callum McGing 2018-2019");
                ImGui.Separator();
                CenterText("Icons from Icons8: https://icons8.com/");
                CenterText("Icons from komorra: https://opengameart.org/content/kmr-editor-icon-set");
                ImGui.Separator();
                var btnW = ImGui.CalcTextSize("OK").X + ImGui.GetStyle().FramePadding.X * 2;
                ImGui.Dummy(Vector2.One);
                ImGui.SameLine(ImGui.GetWindowWidth() / 2 - (btnW / 2));
                if (ImGui.Button("OK"))
                {
                    ImGui.CloseCurrentPopup();
                }
                ImGui.EndPopup();
            }
            pOpen = true;
            if (ImGui.BeginPopupModal("Processing", ref pOpen, ImGuiWindowFlags.AlwaysAutoResize))
            {
                ImGuiExt.Spinner("##spinner", 10, 2, ImGuiNative.igGetColorU32(ImGuiCol.ButtonHovered, 1));
                ImGui.SameLine();
                ImGui.Text("Processing");
                if (finishLoading)
                {
                    ImGui.CloseCurrentPopup();
                }
                ImGui.EndPopup();
            }
            var menu_height = ImGui.GetWindowSize().Y;

            ImGui.EndMainMenuBar();
            var size = (Vector2)ImGui.GetIO().DisplaySize;

            size.Y -= menu_height;
            //Window
            MissingResources.Clear();
            ReferencedMaterials.Clear();
            ReferencedTextures.Clear();
            foreach (var tab in tabs)
            {
                ((EditorTab)tab).DetectResources(MissingResources, ReferencedMaterials, ReferencedTextures);
            }
            ImGui.SetNextWindowSize(new Vector2(size.X, size.Y - 25), ImGuiCond.Always);
            ImGui.SetNextWindowPos(new Vector2(0, menu_height), ImGuiCond.Always, Vector2.Zero);
            bool childopened = true;

            ImGui.Begin("tabwindow", ref childopened,
                        ImGuiWindowFlags.NoTitleBar |
                        ImGuiWindowFlags.NoSavedSettings |
                        ImGuiWindowFlags.NoBringToFrontOnFocus |
                        ImGuiWindowFlags.NoMove |
                        ImGuiWindowFlags.NoResize);
            TabHandler.TabLabels(tabs, ref selected);
            var totalH = ImGui.GetWindowHeight();

            if (showLog)
            {
                ImGuiExt.SplitterV(2f, ref h1, ref h2, 8, 8, -1);
                h1 = totalH - h2 - 24f;
                if (tabs.Count > 0)
                {
                    h1 -= 20f;
                }
                ImGui.BeginChild("###tabcontent" + (selected != null ? selected.Title : ""), new Vector2(-1, h1), false, ImGuiWindowFlags.None);
            }
            else
            {
                ImGui.BeginChild("###tabcontent" + (selected != null ? selected.Title : ""));
            }
            if (selected != null)
            {
                selected.Draw();
                ((EditorTab)selected).SetActiveTab(this);
            }
            else
            {
                ActiveTab = null;
            }
            ImGui.EndChild();
            TabHandler.DrawTabDrag(tabs);
            if (showLog)
            {
                ImGui.BeginChild("###log", new Vector2(-1, h2), false, ImGuiWindowFlags.None);
                ImGui.Text("Log");
                ImGui.SameLine(ImGui.GetWindowWidth() - 20);
                if (Theme.IconButton("closelog", "x", Color4.White))
                {
                    showLog = false;
                }
                logBuffer.InputTextMultiline("##logtext", new Vector2(-1, h2 - 24), ImGuiInputTextFlags.ReadOnly);
                ImGui.EndChild();
            }
            ImGui.End();
            //Status bar
            ImGui.SetNextWindowSize(new Vector2(size.X, 25f), ImGuiCond.Always);
            ImGui.SetNextWindowPos(new Vector2(0, size.Y - 6f), ImGuiCond.Always, Vector2.Zero);
            bool sbopened = true;

            ImGui.Begin("statusbar", ref sbopened,
                        ImGuiWindowFlags.NoTitleBar |
                        ImGuiWindowFlags.NoSavedSettings |
                        ImGuiWindowFlags.NoBringToFrontOnFocus |
                        ImGuiWindowFlags.NoMove |
                        ImGuiWindowFlags.NoResize);
            if (updateTime > 9)
            {
                updateTime = 0;
                frequency  = RenderFrequency;
            }
            else
            {
                updateTime++;
            }
            string activename = ActiveTab == null ? "None" : ActiveTab.DocumentName;
            string utfpath    = ActiveTab == null ? "None" : ActiveTab.GetUtfPath();

            ImGui.Text(string.Format("FPS: {0} | {1} Materials | {2} Textures | Active: {3} - {4}",
                                     (int)Math.Round(frequency),
                                     Resources.MaterialDictionary.Count,
                                     Resources.TextureDictionary.Count,
                                     activename,
                                     utfpath));
            ImGui.End();
            if (errorTimer > 0)
            {
                ImGuiExt.ToastText("An error has occurred\nCheck the log for details",
                                   new Color4(21, 21, 22, 128),
                                   Color4.Red);
            }
            if (showOptions)
            {
                ImGui.Begin("Options", ref showOptions, ImGuiWindowFlags.AlwaysAutoResize);
                var pastC = cFilter;
                ImGui.Combo("Texture Filter", ref cFilter, filters, filters.Length);
                if (cFilter != pastC)
                {
                    switch (cFilter)
                    {
                    case 0:
                        RenderState.PreferredFilterLevel = TextureFiltering.Linear;
                        break;

                    case 1:
                        RenderState.PreferredFilterLevel = TextureFiltering.Bilinear;
                        break;

                    case 2:
                        RenderState.PreferredFilterLevel = TextureFiltering.Trilinear;
                        break;

                    default:
                        RenderState.AnisotropyLevel      = anisotropyLevels[cFilter - 3];
                        RenderState.PreferredFilterLevel = TextureFiltering.Anisotropic;
                        break;
                    }
                }
                ImGui.End();
            }
            ImGui.PopFont();
            guiHelper.Render(RenderState);
            foreach (var tab in toAdd)
            {
                tabs.Add(tab);
                selected = tab;
            }
            toAdd.Clear();
        }
Exemple #9
0
        void DoModel(ModelFile mdl, AbstractConstruct con)
        {
            //Hardpoints
            bool open = ImGui.TreeNode(ImGuiExt.Pad("Hardpoints"));
            var  act  = NewHpMenu(mdl.Path);

            switch (act)
            {
            case ContextActions.NewFixed:
            case ContextActions.NewRevolute:
                newIsFixed   = act == ContextActions.NewFixed;
                addTo        = mdl.Hardpoints;
                addConstruct = con;
                newHpBuffer.Clear();
                popups.OpenPopup("New Hardpoint");
                break;
            }
            Theme.RenderTreeIcon("Hardpoints", "hardpoint", Color4.CornflowerBlue);
            if (open)
            {
                foreach (var hp in mdl.Hardpoints)
                {
                    if (doFilter)
                    {
                        if (hp.Name.IndexOf(currentFilter, StringComparison.OrdinalIgnoreCase) == -1)
                        {
                            continue;
                        }
                    }
                    HardpointGizmo gz = null;
                    foreach (var gizmo in gizmos)
                    {
                        if (gizmo.Definition == hp)
                        {
                            gz = gizmo;
                            break;
                        }
                    }
                    if (hp is RevoluteHardpointDefinition)
                    {
                        Theme.Icon("rev", Color4.LightSeaGreen);
                    }
                    else
                    {
                        Theme.Icon("fix", Color4.Purple);
                    }
                    ImGui.SameLine();
                    if (Theme.IconButton("visible$" + hp.Name, "eye", gz.Enabled ? Color4.White : Color4.Gray))
                    {
                        gz.Enabled = !gz.Enabled;
                    }
                    ImGui.SameLine();
                    ImGui.Selectable(hp.Name);
                    var action = EditDeleteHpMenu(mdl.Path + hp.Name);
                    if (action == ContextActions.Delete)
                    {
                        hpDelete     = hp;
                        hpDeleteFrom = mdl.Hardpoints;
                        popups.OpenPopup("Confirm Delete");
                    }
                    if (action == ContextActions.Edit)
                    {
                        hpEditing = hp;
                    }
                }
                ImGui.TreePop();
            }
        }