コード例 #1
0
        void Save()
        {
            var    at   = ActiveTab;
            Action save = () =>
            {
                if (!string.IsNullOrEmpty(at.FilePath))
                {
                    string errText = "";
                    if (!at.Utf.Save(at.FilePath, ref errText))
                    {
                        openError = true;
                        if (errorText == null)
                        {
                            errorText = new TextBuffer();
                        }
                        errorText.SetText(errText);
                    }
                }
                else
                {
                    RunSaveDialog(at);
                }
            };

            if (at.DirtyCountHp > 0 || at.DirtyCountPart > 0)
            {
                Confirm("This model has unapplied changes. Continue?", save);
            }
            else
            {
                save();
            }
        }
コード例 #2
0
 void GotoString()
 {
     for (int i = 0; i < stringsIds.Length; i++)
     {
         if (id == stringsIds[i])
         {
             gotoItem      = i;
             currentString = i;
             txt.SetText(manager.GetStringResource(stringsIds[i]));
         }
     }
 }
コード例 #3
0
 public void ErrorDialog(string text)
 {
     errorText?.Dispose();
     errorText = new TextBuffer();
     errorText.SetText(text);
     openError = true;
 }
コード例 #4
0
ファイル: MainWindow.cs プロジェクト: Regenhardt/Librelancer
 public MainWindow() : base(800, 600, false)
 {
     Version     = "LancerEdit " + Platform.GetInformationalVersion <MainWindow>();
     MaterialMap = new MaterialMap();
     MaterialMap.AddRegex(new LibreLancer.Ini.StringKeyValue("^nomad.*$", "NomadMaterialNoBendy"));
     MaterialMap.AddRegex(new LibreLancer.Ini.StringKeyValue("^n-texture.*$", "NomadMaterialNoBendy"));
     FLLog.UIThread   = this;
     FLLog.AppendLine = (x, severity) =>
     {
         logText.AppendLine(x);
         if (logText.Length > 16384)
         {
             logText.Remove(0, logText.Length - 16384);
         }
         logBuffer.SetText(logText.ToString());
         if (severity == LogSeverity.Error)
         {
             errorTimer = 9;
             Bell.Play();
         }
     };
     Config      = EditorConfiguration.Load();
     logBuffer   = new TextBuffer(32768);
     recentFiles = new RecentFilesHandler(OpenFile);
 }
コード例 #5
0
ファイル: ColladaTab.cs プロジェクト: sodomon2/Librelancer
 public ColladaTab(List<ColladaObject> objects, string fname, MainWindow win)
 {
     objs = objects;
     Autodetect();
     foreach (var obj in output)
         DoMats(obj);
     Title = string.Format("Collada Importer ({0})", fname);
     modelNameDefault = Path.GetFileNameWithoutExtension(fname);
     modelNameBuffer.SetText(modelNameDefault);
     this.win = win;
 }
コード例 #6
0
 public ImportModelTab(Model model, string fname, MainWindow win)
 {
     this.model = model;
     Autodetect();
     foreach (var obj in output)
     {
         DoMats(obj);
     }
     Title            = string.Format("Model Importer ({0})", fname);
     modelNameDefault = Path.GetFileNameWithoutExtension(fname);
     modelNameBuffer.SetText(modelNameDefault);
     this.win = win;
 }
コード例 #7
0
ファイル: MainWindow.cs プロジェクト: TRBlount/Librelancer
 public MainWindow(bool useDX9) : base(800, 600, false, useDX9)
 {
     MaterialMap = new MaterialMap();
     MaterialMap.AddRegex(new LibreLancer.Ini.StringKeyValue("^nomad.*$", "NomadMaterialNoBendy"));
     MaterialMap.AddRegex(new LibreLancer.Ini.StringKeyValue("^n-texture.*$", "NomadMaterialNoBendy"));
     FLLog.UIThread   = this;
     FLLog.AppendLine = (x) =>
     {
         logText.AppendLine(x);
         if (logText.Length > 16384)
         {
             logText.Remove(0, logText.Length - 16384);
         }
         logBuffer.SetText(logText.ToString());
     };
     logBuffer = new TextBuffer(32768);
 }
コード例 #8
0
ファイル: ColladaTab.cs プロジェクト: sodomon2/Librelancer
 void DoMats(OutModel mdl)
 {
     foreach(var lod in mdl.LODs) {
         for (int i = 0; i < lod.Geometry.Drawcalls.Length; i++) {
             var buf = new TextBuffer(256);
             buf.SetText(lod.Geometry.Drawcalls[i].Material.Name);
             mdl.Materials.Add(new MaterialName()
             {
                 Geometry = lod.Geometry,
                 Drawcall = i,
                 Name = buf
             });
             nameBuffers.Add(buf);
         }
     }
     foreach (var child in mdl.Children)
         DoMats(child);
 }
コード例 #9
0
 void DoNodeMenu(string id, LUtfNode node, LUtfNode parent)
 {
     if (ImGui.BeginPopupContextItem(id))
     {
         ImGui.MenuItem(node.Name, false);
         ImGui.Separator();
         if (ImGui.MenuItem("Rename", node != Utf.Root))
         {
             text.SetText(node.Name);
             renameNode = node;
             doRename   = true;
         }
         if (ImGui.MenuItem("Delete", node != Utf.Root))
         {
             deleteParent = parent;
             deleteNode   = node;
             doDelete     = true;
         }
         ImGui.EndPopup();
     }
 }
コード例 #10
0
        void NewHardpoint(PopupData data)
        {
            ImGui.Text("Name: ");
            ImGui.SameLine();
            newHpBuffer.InputText("##hpname", ImGuiInputTextFlags.None);
            ImGui.SameLine();
            if (ImGui.Button(".."))
            {
                ImGui.OpenPopup("names");
            }
            if (ImGui.BeginPopupContextItem("names"))
            {
                var infos = newIsFixed ? HardpointInformation.Fix : HardpointInformation.Rev;
                foreach (var item in infos)
                {
                    if (Theme.IconMenuItem(item.Name, item.Icon, item.Color, true))
                    {
                        switch (item.Autoname)
                        {
                        case HpNaming.None:
                            newHpBuffer.SetText(item.Name);
                            break;

                        case HpNaming.Number:
                            newHpBuffer.SetText(item.Name + GetHpNumbering(item.Name).ToString("00"));
                            break;

                        case HpNaming.Letter:
                            newHpBuffer.SetText(item.Name + GetHpLettering(item.Name));
                            break;
                        }
                    }
                }
                ImGui.EndPopup();
            }
            ImGui.Text("Type: " + (newIsFixed ? "Fixed" : "Revolute"));
            if (newErrorTimer > 0)
            {
                ImGui.TextColored(new Vector4(1, 0, 0, 1), "Hardpoint with that name already exists.");
            }
            if (ImGui.Button("Ok"))
            {
                var txt = newHpBuffer.GetText();
                if (txt.Length == 0)
                {
                    return;
                }
                if (gizmos.Any((x) => x.Definition.Name.Equals(txt, StringComparison.OrdinalIgnoreCase)))
                {
                    newErrorTimer = 6;
                }
                else
                {
                    HardpointDefinition def;
                    if (newIsFixed)
                    {
                        def = new FixedHardpointDefinition(txt);
                    }
                    else
                    {
                        def = new RevoluteHardpointDefinition(txt);
                    }
                    gizmos.Add(new HardpointGizmo(def, addConstruct));
                    addTo.Add(def);
                    ImGui.CloseCurrentPopup();
                }
            }
            ImGui.SameLine();
            if (ImGui.Button("Cancel"))
            {
                ImGui.CloseCurrentPopup();
            }
        }
コード例 #11
0
ファイル: UtfTab.cs プロジェクト: Regenhardt/Librelancer
 void DoNodeMenu(string id, LUtfNode node, LUtfNode parent)
 {
     if (ImGui.BeginPopupContextItem(id))
     {
         ImGui.MenuItem(node.Name, false);
         ImGui.MenuItem(string.Format("CRC: 0x{0:X}", CrcTool.FLModelCrc(node.Name)), false);
         ImGui.Separator();
         if (Theme.IconMenuItem(Icons.Edit, "Rename", node != Utf.Root))
         {
             text.SetText(node.Name);
             renameNode = node;
             popups.OpenPopup("Rename Node");
         }
         if (Theme.IconMenuItem(Icons.TrashAlt, "Delete", node != Utf.Root))
         {
             deleteParent = parent;
             deleteNode   = node;
             Confirm("Are you sure you want to delete: '" + node.Name + "'?", () =>
             {
                 if (selectedNode == deleteNode)
                 {
                     selectedNode = null;
                 }
                 deleteParent.Children.Remove(deleteNode);
             });
         }
         if (Theme.IconMenuItem(Icons.Eraser, "Clear", node.Children != null || node.Data != null))
         {
             clearNode = node;
             Confirm("Clearing this node will delete all data and children. Continue?", () =>
             {
                 clearNode.Data = null;
                 if (clearNode == Utf.Root)
                 {
                     clearNode.Children = new List <LUtfNode>();
                 }
                 else
                 {
                     clearNode.Children = null;
                 }
             });
         }
         ImGui.Separator();
         if (Theme.BeginIconMenu(Icons.PlusCircle, "Add"))
         {
             if (ImGui.MenuItem("Child"))
             {
                 text.SetText("");
                 addParent = null;
                 addNode   = node;
                 if (node.Data != null)
                 {
                     Confirm("Adding a node will clear data. Continue?", () =>
                     {
                         popups.OpenPopup("New Node");
                     });
                 }
                 else
                 {
                     popups.OpenPopup("New Node");
                 }
             }
             if (ImGui.MenuItem("Before", node != Utf.Root))
             {
                 text.SetText("");
                 addParent = parent;
                 addNode   = node;
                 addOffset = 0;
                 popups.OpenPopup("New Node");
             }
             if (ImGui.MenuItem("After", node != Utf.Root))
             {
                 text.SetText("");
                 addParent = parent;
                 addNode   = node;
                 addOffset = 1;
                 popups.OpenPopup("New Node");
             }
             ImGui.EndMenu();
         }
         ImGui.Separator();
         if (Theme.IconMenuItem(Icons.Cut, "Cut", node != Utf.Root))
         {
             parent.Children.Remove(node);
             main.ClipboardCopy = false;
             main.Clipboard     = node;
         }
         if (Theme.IconMenuItem(Icons.Copy, "Copy", node != Utf.Root))
         {
             main.ClipboardCopy = true;
             main.Clipboard     = node.MakeCopy();
         }
         if (main.Clipboard != null)
         {
             if (Theme.BeginIconMenu(Icons.Paste, "Paste"))
             {
                 if (ImGui.MenuItem("Before", node != Utf.Root))
                 {
                     if (main.ClipboardCopy)
                     {
                         var cpy = main.Clipboard.MakeCopy();
                         cpy.Parent = parent;
                         parent.Children.Insert(parent.Children.IndexOf(node), cpy);
                     }
                     else
                     {
                         main.Clipboard.Parent = parent;
                         parent.Children.Insert(parent.Children.IndexOf(node), main.Clipboard);
                         main.Clipboard = null;
                     }
                 }
                 if (ImGui.MenuItem("After", node != Utf.Root))
                 {
                     if (main.ClipboardCopy)
                     {
                         var cpy = main.Clipboard.MakeCopy();
                         cpy.Parent = parent;
                         parent.Children.Insert(parent.Children.IndexOf(node) + 1, cpy);
                     }
                     else
                     {
                         main.Clipboard.Parent = parent;
                         parent.Children.Insert(parent.Children.IndexOf(node) + 1, main.Clipboard);
                         main.Clipboard = null;
                     }
                 }
                 if (ImGui.MenuItem("Into"))
                 {
                     if (node.Data == null)
                     {
                         if (node.Children == null)
                         {
                             node.Children = new List <LUtfNode>();
                         }
                         if (main.ClipboardCopy)
                         {
                             var cpy = main.Clipboard.MakeCopy();
                             cpy.Parent = node;
                             node.Children.Add(cpy);
                         }
                         else
                         {
                             main.Clipboard.Parent = node;
                             node.Children.Add(main.Clipboard);
                             main.Clipboard = null;
                         }
                     }
                     else
                     {
                         pasteInto = node;
                         Confirm("Adding children will delete this node's data. Continue?", () =>
                         {
                             pasteInto.Data     = null;
                             pasteInto.Children = new List <LUtfNode>();
                             if (main.ClipboardCopy)
                             {
                                 var cpy    = main.Clipboard.MakeCopy();
                                 cpy.Parent = pasteInto;
                                 pasteInto.Children.Add(cpy);
                             }
                             else
                             {
                                 main.Clipboard.Parent = pasteInto;
                                 pasteInto.Children.Add(main.Clipboard);
                                 main.Clipboard = null;
                             }
                         });
                     }
                 }
                 ImGui.EndMenu();
             }
         }
         else
         {
             Theme.IconMenuItem(Icons.Paste, "Paste", false);
         }
         ImGui.EndPopup();
     }
 }
コード例 #12
0
        public override void Draw()
        {
            ImGui.Columns(2, "cols", true);
            //strings vs infocards
            if (ImGuiExt.ToggleButton("Strings", showStrings))
            {
                showStrings = true;
            }
            ImGui.SameLine();
            if (ImGuiExt.ToggleButton("Infocards", !showStrings))
            {
                showStrings = false;
            }
            ImGui.SameLine();
            ImGui.PushItemWidth(140);
            ImGui.InputInt("##id", ref id, 0, 0);
            ImGui.PopItemWidth();
            ImGui.SameLine();
            int gotoItem = -1;

            if (ImGui.Button("Go"))
            {
                if (showStrings)
                {
                    for (int i = 0; i < stringsIds.Length; i++)
                    {
                        if (id == stringsIds[i])
                        {
                            gotoItem      = i;
                            currentString = i;
                            txt.SetText(manager.GetStringResource(stringsIds[i]));
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < infocardsIds.Length; i++)
                    {
                        if (id == infocardsIds[i])
                        {
                            gotoItem        = i;
                            currentInfocard = i;
                            if (display == null)
                            {
                                display = new InfocardControl(win, RDLParse.Parse(manager.GetXmlResource(infocardsIds[currentInfocard]), win.Fonts), 100);
                            }
                            else
                            {
                                display.SetInfocard(RDLParse.Parse(manager.GetXmlResource(infocardsIds[currentInfocard]), win.Fonts));
                            }
                        }
                    }
                }
            }
            ImGui.Separator();
            //list
            ImGui.BeginChild("##list");
            if (showStrings)
            {
                if (gotoItem == -1)
                {
                    stringClipper.Begin(stringsIds.Length);
                    while (stringClipper.Step())
                    {
                        for (int i = stringClipper.DisplayStart; i < stringClipper.DisplayEnd; i++)
                        {
                            if (ImGui.Selectable(stringsIds[i] + "##" + i, currentString == i))
                            {
                                currentString = i;
                                txt.SetText(manager.GetStringResource(stringsIds[i]));
                            }
                        }
                    }
                    stringClipper.End();
                }
                else
                {
                    for (int i = 0; i < stringsIds.Length; i++)
                    {
                        ImGui.Selectable(stringsIds[i] + "##" + i, currentString == i);
                        if (currentString == i)
                        {
                            ImGui.SetScrollHere();
                        }
                    }
                }
            }
            else
            {
                if (gotoItem == -1)
                {
                    infocardClipper.Begin(infocardsIds.Length);
                    while (infocardClipper.Step())
                    {
                        for (int i = infocardClipper.DisplayStart; i < infocardClipper.DisplayEnd; i++)
                        {
                            if (ImGui.Selectable(infocardsIds[i] + "##" + i, currentInfocard == i))
                            {
                                currentInfocard = i;
                                if (display == null)
                                {
                                    display = new InfocardControl(win, RDLParse.Parse(manager.GetXmlResource(infocardsIds[currentInfocard]), win.Fonts), 100);
                                }
                                else
                                {
                                    display.SetInfocard(RDLParse.Parse(manager.GetXmlResource(infocardsIds[currentInfocard]), win.Fonts));
                                }
                            }
                        }
                    }
                    infocardClipper.End();
                }
                else
                {
                    for (int i = 0; i < infocardsIds.Length; i++)
                    {
                        ImGui.Selectable(infocardsIds[i] + "##" + i, currentInfocard == i);
                        if (currentInfocard == i)
                        {
                            ImGui.SetScrollHere();
                        }
                    }
                }
            }
            ImGui.EndChild();
            ImGui.NextColumn();
            //Display
            if (showStrings)
            {
                if (currentString != -1)
                {
                    ImGui.Text(stringsIds[currentString].ToString());
                    txt.InputTextMultiline("##txt", new Vector2(-1, ImGui.GetWindowHeight() - 70), ImGuiInputTextFlags.ReadOnly);
                }
            }
            else
            {
                if (currentInfocard != -1)
                {
                    ImGui.Text(infocardsIds[currentInfocard].ToString());
                    ImGui.BeginChild("##display");
                    display.Draw(ImGui.GetWindowWidth() - 15);
                    ImGui.EndChild();
                }
            }
        }
コード例 #13
0
            public void Draw(int i)
            {
                ImGui.PushID($"__argument_{i}");
                switch (Argument.Type)
                {
                case ScriptArgumentType.Boolean:
                    ImGui.Checkbox(Argument.Name, ref BooleanValue);
                    break;

                case ScriptArgumentType.Integer:
                    ImGui.InputInt(Argument.Name, ref IntegerValue, 1);
                    break;

                case ScriptArgumentType.String:
                    InputText.InputText(Argument.Name, ImGuiInputTextFlags.None, 100);
                    break;

                case ScriptArgumentType.Dropdown:
                    ImGui.Combo(Argument.Name, ref IntegerValue, Argument.Options.ToArray(),
                                Argument.Options.Count);
                    break;

                case ScriptArgumentType.Folder:
                    InputText.InputText(Argument.Name, ImGuiInputTextFlags.None, 100);
                    ImGui.SameLine();
                    if (ImGui.Button(".."))
                    {
                        var result = FileDialog.ChooseFolder();
                        if (!string.IsNullOrEmpty(result))
                        {
                            InputText.SetText(result);
                        }
                    }
                    break;

                case ScriptArgumentType.File:
                    InputText.InputText(Argument.Name, ImGuiInputTextFlags.None, 100);
                    ImGui.SameLine();
                    if (ImGui.Button(".."))
                    {
                        var result = FileDialog.Open();
                        if (!string.IsNullOrEmpty(result))
                        {
                            InputText.SetText(result);
                        }
                    }
                    break;

                case ScriptArgumentType.FileArray:
                    ImGui.Text(Argument.Name);
                    ImGui.Separator();
                    if (StringArray.Count == 0)
                    {
                        ImGui.Text("[empty]");
                    }
                    else
                    {
                        ImGui.Columns(2);
                        List <string> toRemove = new List <string>();
                        for (int j = 0; j < StringArray.Count; j++)
                        {
                            ImGui.Text(StringArray[j]);
                            ImGui.NextColumn();
                            if (ImGui.Button($"Remove##{j}"))
                            {
                                toRemove.Add(StringArray[j]);
                            }
                            ImGui.NextColumn();
                        }
                        foreach (var f in toRemove)
                        {
                            StringArray.Remove(f);
                        }
                        ImGui.Columns(1);
                    }

                    ImGui.Separator();
                    if (ImGui.Button("Add File"))
                    {
                        var result = FileDialog.Open();
                        if (!string.IsNullOrEmpty(result))
                        {
                            StringArray.Add(result);
                        }
                    }

                    break;
                }
                ImGui.PopID();
            }
コード例 #14
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();
        }
コード例 #15
0
ファイル: MainWindow.cs プロジェクト: TRBlount/Librelancer
        protected override void Draw(double elapsed)
        {
            EnableTextInput();
            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);
                    if (f != null && DetectFileType.Detect(f) == FileType.Utf)
                    {
                        var t = new UtfTab(this, new EditableUtf(f), System.IO.Path.GetFileName(f));
                        ActiveTab = t;
                        AddTab(t);
                    }
                }
                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();
                            ActiveTab.Utf.Save(f);
                        }
                    }
                }
                if (Theme.IconMenuItem("Quit", "quit", Color4.White, true))
                {
                    Exit();
                }
                ImGui.EndMenu();
            }
            bool openerror = false;

            if (ImGui.BeginMenu("Tools"))
            {
                if (ImGui.MenuItem("Options"))
                {
                    showOptions = true;
                }
                if (ImGui.MenuItem("Log"))
                {
                    showLog = true;
                }
                if (ImGui.MenuItem("Resources"))
                {
                    AddTab(new ResourcesTab(Resources, MissingResources, ReferencedMaterials, ReferencedTextures));
                }
                if (ImGui.MenuItem("Import Collada"))
                {
                    string input;
                    if ((input = FileDialog.Open(ColladaFilters)) != null)
                    {
                        List <ColladaObject> dae = null;
                        try
                        {
                            dae = ColladaSupport.Parse(input);
                            AddTab(new ColladaTab(dae, System.IO.Path.GetFileName(input), this));
                        }
                        catch (Exception ex)
                        {
                            if (errorText != null)
                            {
                                errorText.Dispose();
                            }
                            var str = "Import Error:\n" + ex.Message + "\n" + ex.StackTrace;
                            errorText = new TextBuffer();
                            errorText.SetText(str);
                            openerror = true;
                        }
                    }
                }
                ImGui.EndMenu();
            }
            if (ImGui.BeginMenu("Help"))
            {
                if (Theme.IconMenuItem("About", "about", Color4.White, true))
                {
                    openAbout = true;
                }
                ImGui.EndMenu();
            }
            if (openAbout)
            {
                ImGui.OpenPopup("About");
                openAbout = false;
            }
            if (openerror)
            {
                ImGui.OpenPopup("Error");
            }
            if (ImGui.BeginPopupModal("Error", WindowFlags.AlwaysAutoResize))
            {
                ImGui.Text("Error:");
                ImGui.InputTextMultiline("##etext", errorText.Pointer, (uint)errorText.Size,
                                         new Vector2(430, 200), InputTextFlags.ReadOnly, errorText.Callback);
                if (ImGui.Button("OK"))
                {
                    ImGui.CloseCurrentPopup();
                }
                ImGui.EndPopup();
            }
            if (ImGui.BeginPopupModal("About", WindowFlags.AlwaysAutoResize))
            {
                ImGui.Text("LancerEdit");
                ImGui.Text("Callum McGing 2018");
                ImGui.Separator();
                ImGui.Text("Icons from Icons8: https://icons8.com/");
                ImGui.Text("Icons from komorra: https://opengameart.org/content/kmr-editor-icon-set");
                ImGui.Separator();
                if (ImGui.Button("OK"))
                {
                    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)
            {
                tab.DetectResources(MissingResources, ReferencedMaterials, ReferencedTextures);
            }
            ImGui.SetNextWindowSize(new Vector2(size.X, size.Y - 25), Condition.Always);
            ImGui.SetNextWindowPos(new Vector2(0, menu_height), Condition.Always, Vector2.Zero);
            bool childopened = true;

            ImGui.BeginWindow("tabwindow", ref childopened,
                              WindowFlags.NoTitleBar |
                              WindowFlags.NoSavedSettings |
                              WindowFlags.NoBringToFrontOnFocus |
                              WindowFlags.NoMove |
                              WindowFlags.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, WindowFlags.Default);
            }
            else
            {
                ImGui.BeginChild("###tabcontent" + (selected != null ? selected.Title : ""));
            }
            if (selected != null)
            {
                selected.Draw();
                selected.SetActiveTab(this);
            }
            else
            {
                ActiveTab = null;
            }
            ImGui.EndChild();
            TabHandler.DrawTabDrag(tabs);
            if (showLog)
            {
                ImGui.BeginChild("###log", new Vector2(-1, h2), false, WindowFlags.Default);
                ImGui.Text("Log");
                ImGui.SameLine(ImGui.GetWindowWidth() - 20);
                if (Theme.IconButton("closelog", "x", Color4.White))
                {
                    showLog = false;
                }
                ImGui.InputTextMultiline("##logtext", logBuffer.Pointer, 32768, new Vector2(-1, h2 - 24),
                                         InputTextFlags.ReadOnly, logBuffer.Callback);
                ImGui.EndChild();
            }
            ImGui.EndWindow();
            //Status bar
            ImGui.SetNextWindowSize(new Vector2(size.X, 25f), Condition.Always);
            ImGui.SetNextWindowPos(new Vector2(0, size.Y - 6f), Condition.Always, Vector2.Zero);
            bool sbopened = true;

            ImGui.BeginWindow("statusbar", ref sbopened,
                              WindowFlags.NoTitleBar |
                              WindowFlags.NoSavedSettings |
                              WindowFlags.NoBringToFrontOnFocus |
                              WindowFlags.NoMove |
                              WindowFlags.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.EndWindow();
            if (showOptions)
            {
                ImGui.BeginWindow("Options", ref showOptions, WindowFlags.AlwaysAutoResize);
                var pastC = cFilter;
                ImGui.Combo("Texture Filter", ref cFilter, filters);
                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.EndWindow();
            }
            ImGui.PopFont();
            guiHelper.Render(RenderState);
            foreach (var tab in toAdd)
            {
                tabs.Add(tab);
                selected = tab;
            }
            toAdd.Clear();
        }