예제 #1
0
        protected override void Draw(double elapsed)
        {
            VertexBuffer.TotalDrawcalls = 0;
            EnableTextInput();
            Viewport.Replace(0, 0, Width, Height);
            RenderState.ClearColor = new Color4(0.2f, 0.2f, 0.2f, 1f);
            RenderState.ClearAll();
            //
            if (world != null)
            {
                if (wireFrame)
                {
                    RenderState.Wireframe = true;
                }
                world.Renderer.Draw();
                RenderState.Wireframe = false;
            }
            //
            guiHelper.NewFrame(elapsed);
            ImGui.PushFont(ImGuiHelper.Noto);
            //Main Menu
            ImGui.BeginMainMenuBar();
            if (ImGui.BeginMenu("File"))
            {
                if (Theme.IconMenuItem("Open", "open", Color4.White, true))
                {
                    var folder = FileDialog.ChooseFolder();
                    if (folder != null)
                    {
                        if (GameConfig.CheckFLDirectory(folder))
                        {
                            openLoad = true;
                            LoadData(folder);
                        }
                        else
                        {
                            //Error dialog
                        }
                    }
                }
                if (Theme.IconMenuItem("Quit", "quit", Color4.White, true))
                {
                    Exit();
                }
                ImGui.EndMenu();
            }
            if (world != null)
            {
                if (ImGui.MenuItem("Change System (F6)"))
                {
                    sysIndex         = sysIndexLoaded;
                    openChangeSystem = true;
                }
            }
            if (ImGui.BeginMenu("View"))
            {
                if (ImGui.MenuItem("Debug Text", "", showDebug, true))
                {
                    showDebug = !showDebug;
                }
                if (ImGui.MenuItem("Wireframe", "", wireFrame, true))
                {
                    wireFrame = !wireFrame;
                }
                if (ImGui.MenuItem("Infocard", "", infocardOpen, true))
                {
                    infocardOpen = !infocardOpen;
                }
                if (ImGui.MenuItem("VSync", "", vSync, true))
                {
                    vSync = !vSync;
                    SetVSync(vSync);
                }
                ImGui.EndMenu();
            }
            var h = ImGui.GetWindowHeight();

            ImGui.EndMainMenuBar();
            //Other Windows
            if (world != null)
            {
                if (showDebug)
                {
                    ImGui.SetNextWindowPos(new Vector2(0, h), ImGuiCond.Always, Vector2.Zero);

                    ImGui.Begin("##debugWindow", ImGuiWindowFlags.NoTitleBar |
                                ImGuiWindowFlags.NoMove | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoBringToFrontOnFocus);
                    ImGui.Text(string.Format(DEBUG_TEXT, curSystem.Name, curSystem.Nickname,
                                             camera.Position.X, camera.Position.Y, camera.Position.Z,
                                             DebugDrawing.SizeSuffix(GC.GetTotalMemory(false)), (int)Math.Round(RenderFrequency), VertexBuffer.TotalDrawcalls, VertexBuffer.TotalBuffers));
                    ImGui.End();
                }
                ImGui.SetNextWindowSize(new Vector2(100, 100), ImGuiCond.FirstUseEver);
                if (infocardOpen)
                {
                    if (ImGui.Begin("Infocard", ref infocardOpen))
                    {
                        var szX = Math.Max(20, ImGui.GetWindowWidth());
                        var szY = Math.Max(20, ImGui.GetWindowHeight());
                        if (icard == null)
                        {
                            icard = new InfocardControl(this, systemInfocard, szX);
                        }
                        icard.Draw(szX);
                    }
                    ImGui.End();
                }
            }
            //dialogs must be children of window or ImGui default "Debug" window appears
            if (openChangeSystem)
            {
                ImGui.OpenPopup("Change System");
                openChangeSystem = false;
            }
            bool popupopen = true;

            if (ImGui.BeginPopupModal("Change System", ref popupopen, ImGuiWindowFlags.AlwaysAutoResize))
            {
                ImGui.Combo("System", ref sysIndex, systems, systems.Length);
                if (ImGui.Button("Ok"))
                {
                    if (sysIndex != sysIndexLoaded)
                    {
                        camera.UpdateProjection();
                        camera.Free = false;
                        camera.Zoom = 5000;
                        Resources.ClearTextures();
                        curSystem      = GameData.GetSystem(systems[sysIndex]);
                        systemInfocard = GameData.GetInfocard(curSystem.Infocard, fontMan);
                        if (icard != null)
                        {
                            icard.SetInfocard(systemInfocard);
                        }
                        GameData.LoadAllSystem(curSystem);
                        world.LoadSystem(curSystem, Resources);
                        sysIndexLoaded = sysIndex;
                    }
                    ImGui.CloseCurrentPopup();
                }
                ImGui.SameLine();
                if (ImGui.Button("Cancel"))
                {
                    ImGui.CloseCurrentPopup();
                }
                ImGui.EndPopup();
            }
            if (openLoad)
            {
                ImGui.OpenPopup("Loading");
                openLoad = false;
            }
            popupopen = true;
            if (ImGui.BeginPopupModal("Loading", ref popupopen, ImGuiWindowFlags.AlwaysAutoResize))
            {
                if (world != null)
                {
                    ImGui.CloseCurrentPopup();
                }
                ImGuiExt.Spinner("##spinner", 10, 2, ImGuiNative.igGetColorU32(ImGuiCol.ButtonHovered, 1));
                ImGui.SameLine();
                ImGui.Text("Loading");
                ImGui.EndPopup();
            }
            ImGui.PopFont();
            guiHelper.Render(RenderState);
        }
예제 #2
0
        protected override void Draw(double elapsed)
        {
            VertexBuffer.TotalDrawcalls = 0;
            EnableTextInput();
            RenderContext.ReplaceViewport(0, 0, Width, Height);
            RenderContext.ClearColor = new Color4(0.2f, 0.2f, 0.2f, 1f);
            RenderContext.ClearAll();
            //
            if (world != null)
            {
                if (wireFrame)
                {
                    RenderContext.Wireframe = true;
                }
                world.Renderer.Draw();
                RenderContext.Wireframe = false;
            }
            //
            guiHelper.NewFrame(elapsed);
            ImGui.PushFont(ImGuiHelper.Noto);
            //Main Menu
            ImGui.BeginMainMenuBar();
            if (ImGui.BeginMenu("File"))
            {
                if (Theme.IconMenuItem(Icons.Open, "Open", true))
                {
                    var folder = FileDialog.ChooseFolder();
                    if (folder != null)
                    {
                        if (GameConfig.CheckFLDirectory(folder))
                        {
                            openLoad = true;
                            LoadData(folder);
                        }
                        else
                        {
                            //Error dialog
                        }
                    }
                }
                if (Theme.IconMenuItem(Icons.Quit, "Quit", true))
                {
                    Exit();
                }
                ImGui.EndMenu();
            }
            if (world != null)
            {
                if (ImGui.MenuItem("Change System (F6)"))
                {
                    sysIndex         = sysIndexLoaded;
                    openChangeSystem = true;
                }
            }
            if (ImGui.BeginMenu("View"))
            {
                if (ImGui.MenuItem("Debug Text", "", showDebug, true))
                {
                    showDebug = !showDebug;
                }
                if (ImGui.MenuItem("Wireframe", "", wireFrame, true))
                {
                    wireFrame = !wireFrame;
                }
                if (ImGui.MenuItem("Infocard", "", infocardOpen, true))
                {
                    infocardOpen = !infocardOpen;
                }
                if (ImGui.MenuItem("Universe Map", "", universeOpen, true))
                {
                    universeOpen = !universeOpen;
                }
                if (ImGui.MenuItem("Controls", "", controlsOpen, true))
                {
                    controlsOpen = !controlsOpen;
                }

                if (ImGui.MenuItem("VSync", "", vSync, true))
                {
                    vSync = !vSync;
                    SetVSync(vSync);
                }
                ImGui.EndMenu();
            }
            var h = ImGui.GetWindowHeight();

            ImGui.EndMainMenuBar();
            //Other Windows
            if (camera != null && controlsOpen)
            {
                if (ImGui.Begin("Controls", ref controlsOpen))
                {
                    ImGui.Text("WSAD - Movement");
                    ImGui.Text("Arrow Keys - Rotation");
                    ImGui.SliderFloat("Move Speed", ref camera.MoveSpeed, 1, 12000);
                    if (ImGui.Button(LOWSPEED.ToString()))
                    {
                        camera.MoveSpeed = LOWSPEED;
                    }
                    ImGui.SameLine();
                    if (ImGui.Button(MEDSPEED.ToString()))
                    {
                        camera.MoveSpeed = MEDSPEED;
                    }
                    ImGui.SameLine();
                    if (ImGui.Button(HIGHSPEED.ToString()))
                    {
                        camera.MoveSpeed = HIGHSPEED;
                    }
                    ImGui.End();
                }
            }
            if (world != null)
            {
                if (showDebug)
                {
                    ImGui.SetNextWindowPos(new Vector2(0, h), ImGuiCond.Always, Vector2.Zero);

                    ImGui.Begin("##debugWindow", ImGuiWindowFlags.NoTitleBar |
                                ImGuiWindowFlags.NoMove | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoBringToFrontOnFocus);
                    ImGui.Text(string.Format(DEBUG_TEXT, curSystem.Name, curSystem.Nickname,
                                             camera.Position.X, camera.Position.Y, camera.Position.Z,
                                             DebugDrawing.SizeSuffix(GC.GetTotalMemory(false)), (int)Math.Round(RenderFrequency), VertexBuffer.TotalDrawcalls, VertexBuffer.TotalBuffers));
                    ImGui.End();
                }
                if (infocardOpen)
                {
                    ImGui.SetNextWindowSize(new Vector2(300, 300), ImGuiCond.FirstUseEver);
                    if (ImGui.Begin("Infocard", ref infocardOpen))
                    {
                        var szX = Math.Max(20, ImGui.GetWindowWidth());
                        var szY = Math.Max(20, ImGui.GetWindowHeight());
                        if (icard == null)
                        {
                            icard = new InfocardControl(this, systemInfocard, szX);
                        }
                        icard.Draw(szX);
                        ImGui.End();
                    }
                }

                if (universeOpen)
                {
                    ImGui.SetNextWindowSize(new Vector2(300, 300), ImGuiCond.FirstUseEver);
                    if (ImGui.Begin("Map", ref universeOpen))
                    {
                        ImGui.BeginTabBar("##maptabs");
                        if (ImGui.BeginTabItem("Universe"))
                        {
                            var    szX    = Math.Max(20, ImGui.GetWindowWidth());
                            var    szY    = Math.Max(20, ImGui.GetWindowHeight() - 50);
                            string result = UniverseMap.Draw(universeBackgroundRegistered, GameData, (int)szX,
                                                             (int)szY, 20);
                            if (result != null)
                            {
                                for (int i = 0; i < systems.Length; i++)
                                {
                                    if (result.Equals(systems[i], StringComparison.OrdinalIgnoreCase))
                                    {
                                        sysIndex = i;
                                        ChangeSystem();
                                        break;
                                    }
                                }
                            }

                            ImGui.EndTabItem();
                        }

                        if (ImGui.BeginTabItem("System"))
                        {
                            var szX = Math.Max(20, ImGui.GetWindowWidth());
                            var szY = Math.Max(20, ImGui.GetWindowHeight() - 70);
                            systemMap.Draw((int)szX, (int)szY, elapsed);
                            ImGui.EndTabItem();
                        }

                        ImGui.EndTabBar();
                        ImGui.End();
                    }
                }
            }
            //dialogs must be children of window or ImGui default "Debug" window appears
            if (openChangeSystem)
            {
                ImGui.OpenPopup("Change System");
                openChangeSystem = false;
            }
            bool popupopen = true;

            if (ImGui.BeginPopupModal("Change System", ref popupopen, ImGuiWindowFlags.AlwaysAutoResize))
            {
                ImGui.Combo("System", ref sysIndex, systems, systems.Length);
                if (ImGui.Button("Ok"))
                {
                    ChangeSystem();
                    ImGui.CloseCurrentPopup();
                }
                ImGui.SameLine();
                if (ImGui.Button("Cancel"))
                {
                    ImGui.CloseCurrentPopup();
                }
                ImGui.EndPopup();
            }
            if (openLoad)
            {
                ImGui.OpenPopup("Loading");
                openLoad = false;
            }
            popupopen = true;
            if (ImGui.BeginPopupModal("Loading", ref popupopen, ImGuiWindowFlags.AlwaysAutoResize))
            {
                if (world != null)
                {
                    ImGui.CloseCurrentPopup();
                }
                ImGuiExt.Spinner("##spinner", 10, 2, ImGui.GetColorU32(ImGuiCol.ButtonHovered, 1));
                ImGui.SameLine();
                ImGui.Text("Loading");
                ImGui.EndPopup();
            }
            ImGui.PopFont();
            guiHelper.Render(RenderContext);
        }