Exemplo n.º 1
0
        public override void Draw(ref bool isGameViewFocused)
        {
            var textureViewDescription = GetTextureViewDescription(_texture);

            if (!_textureViews.TryGetValue(textureViewDescription, out var textureView))
            {
                _textureViews.Add(textureViewDescription, textureView = AddDisposable(_context.GraphicsDevice.ResourceFactory.CreateTextureView(ref textureViewDescription)));
            }

            var imagePointer = _context.ImGuiRenderer.GetOrCreateImGuiBinding(
                _context.GraphicsDevice.ResourceFactory,
                textureView);

            var availableSize = ImGui.GetContentRegionAvail();

            var size = SizeF.CalculateSizeFittingAspectRatio(
                new SizeF(_texture.Width, _texture.Height),
                new Size((int)availableSize.X, (int)availableSize.Y));

            ImGui.Image(
                imagePointer,
                new Vector2(size.Width, size.Height),
                Vector2.Zero,
                Vector2.One,
                Vector4.One,
                Vector4.Zero);
        }
Exemplo n.º 2
0
        public override void Draw()
        {
            var imagePointer = Context.ImGuiRenderer.GetOrCreateImGuiBinding(
                Context.Game.GraphicsDevice.ResourceFactory,
                _textureView);

            var availableSize = ImGui.GetContentRegionAvail();

            var size = SizeF.CalculateSizeFittingAspectRatio(
                new SizeF(_texture.Width, _texture.Height),
                new Size((int)availableSize.X, (int)availableSize.Y));

            ImGui.Image(
                imagePointer,
                new Vector2(size.Width, size.Height),
                Vector2.Zero,
                Vector2.One,
                Vector4.One,
                Vector4.Zero);
        }
Exemplo n.º 3
0
        public override void Draw()
        {
            ImGui.BeginChild("mip level", new Vector2(150, 0), true, 0);

            for (var i = 0u; i < _texture.MipLevels; i++)
            {
                if (ImGui.Selectable($"MipMap {i}", i == _mipLevel))
                {
                    _mipLevel = i;
                }
            }

            ImGui.EndChild();

            ImGui.SameLine();

            var textureViewDescription = new TextureViewDescription(_texture, _mipLevel, 1, 0, 1);

            if (!_textureViews.TryGetValue(textureViewDescription, out var textureView))
            {
                _textureViews.Add(textureViewDescription, textureView = AddDisposable(Context.Game.GraphicsDevice.ResourceFactory.CreateTextureView(ref textureViewDescription)));
            }

            var imagePointer = Context.ImGuiRenderer.GetOrCreateImGuiBinding(
                Context.Game.GraphicsDevice.ResourceFactory,
                textureView);

            var availableSize = ImGui.GetContentRegionAvail();

            var size = SizeF.CalculateSizeFittingAspectRatio(
                new SizeF(_texture.Width, _texture.Height),
                new Size((int)availableSize.X, (int)availableSize.Y));

            ImGui.Image(
                imagePointer,
                new Vector2(size.Width, size.Height),
                Vector2.Zero,
                Vector2.One,
                Vector4.One,
                Vector4.Zero);
        }
Exemplo n.º 4
0
        public void Draw(ref bool isGameViewFocused)
        {
            float menuBarHeight = 0;

            if (ImGui.BeginMainMenuBar())
            {
                menuBarHeight = ImGui.GetWindowHeight();

                if (ImGui.BeginMenu("File"))
                {
                    if (ImGui.MenuItem("Exit", "Alt+F4", false, true))
                    {
                        Environment.Exit(0);
                    }

                    ImGui.EndMenu();
                }

                if (ImGui.BeginMenu("Jump"))
                {
                    if (ImGui.BeginMenu("Map"))
                    {
                        foreach (var mapCache in _context.Game.AssetStore.MapCaches)
                        {
                            var mapName = mapCache.GetNameKey().Translate();

                            if (ImGui.MenuItem($"{mapName} ({mapCache.Name})"))
                            {
                                var playableSides = _context.Game.GetPlayableSides();
                                var faction1      = playableSides.First();
                                var faction2      = playableSides.Last();

                                _context.Game.StartMultiPlayerGame(
                                    mapCache.Name,
                                    new EchoConnection(),
                                    new PlayerSetting?[]
                                {
                                    new PlayerSetting(null, faction1, new ColorRgb(255, 0, 0)),
                                    new PlayerSetting(null, faction2, new ColorRgb(255, 255, 255)),
                                },
                                    0);
                            }
                        }

                        ImGui.EndMenu();
                    }

                    ImGui.EndMenu();
                }

                if (ImGui.BeginMenu("Windows"))
                {
                    foreach (var view in _views)
                    {
                        if (ImGui.MenuItem(view.DisplayName, null, view.IsVisible, true))
                        {
                            view.IsVisible = true;

                            ImGui.SetWindowFocus(view.Name);
                        }
                    }

                    ImGui.EndMenu();
                }

                if (ImGui.BeginMenu("Preferences"))
                {
                    var isVSyncEnabled = _context.Game.GraphicsDevice.SyncToVerticalBlank;
                    if (ImGui.MenuItem("VSync", null, ref isVSyncEnabled, true))
                    {
                        _context.Game.GraphicsDevice.SyncToVerticalBlank = isVSyncEnabled;
                    }
                    var isFullscreen = _context.Game.Window.Fullscreen;
                    if (ImGui.MenuItem("Fullscreen", "Alt+Enter", ref isFullscreen, true))
                    {
                        _context.Game.Window.Fullscreen = isFullscreen;
                    }
                    ImGui.EndMenu();
                }

                if (_context.Game.Configuration.UseRenderDoc && ImGui.BeginMenu("RenderDoc"))
                {
                    var renderDoc = Game.RenderDoc;

                    if (ImGui.MenuItem("Trigger Capture"))
                    {
                        renderDoc.TriggerCapture();
                    }
                    if (ImGui.BeginMenu("Options"))
                    {
                        bool allowVsync = renderDoc.AllowVSync;
                        if (ImGui.Checkbox("Allow VSync", ref allowVsync))
                        {
                            renderDoc.AllowVSync = allowVsync;
                        }
                        bool validation = renderDoc.APIValidation;
                        if (ImGui.Checkbox("API Validation", ref validation))
                        {
                            renderDoc.APIValidation = validation;
                        }
                        int delayForDebugger = (int)renderDoc.DelayForDebugger;
                        if (ImGui.InputInt("Debugger Delay", ref delayForDebugger))
                        {
                            delayForDebugger           = Math.Clamp(delayForDebugger, 0, int.MaxValue);
                            renderDoc.DelayForDebugger = (uint)delayForDebugger;
                        }
                        bool verifyBufferAccess = renderDoc.VerifyBufferAccess;
                        if (ImGui.Checkbox("Verify Buffer Access", ref verifyBufferAccess))
                        {
                            renderDoc.VerifyBufferAccess = verifyBufferAccess;
                        }
                        bool overlayEnabled = renderDoc.OverlayEnabled;
                        if (ImGui.Checkbox("Overlay Visible", ref overlayEnabled))
                        {
                            renderDoc.OverlayEnabled = overlayEnabled;
                        }
                        bool overlayFrameRate = renderDoc.OverlayFrameRate;
                        if (ImGui.Checkbox("Overlay Frame Rate", ref overlayFrameRate))
                        {
                            renderDoc.OverlayFrameRate = overlayFrameRate;
                        }
                        bool overlayFrameNumber = renderDoc.OverlayFrameNumber;
                        if (ImGui.Checkbox("Overlay Frame Number", ref overlayFrameNumber))
                        {
                            renderDoc.OverlayFrameNumber = overlayFrameNumber;
                        }
                        bool overlayCaptureList = renderDoc.OverlayCaptureList;
                        if (ImGui.Checkbox("Overlay Capture List", ref overlayCaptureList))
                        {
                            renderDoc.OverlayCaptureList = overlayCaptureList;
                        }
                        ImGui.EndMenu();
                    }
                    if (ImGui.MenuItem("Launch Replay UI"))
                    {
                        renderDoc.LaunchReplayUI();
                    }

                    ImGui.EndMenu();
                }

                DrawTimingControls();

                var fpsText     = $"{ImGui.GetIO().Framerate:N2} FPS";
                var fpsTextSize = ImGui.CalcTextSize(fpsText).X;
                ImGui.SetCursorPosX(ImGui.GetWindowContentRegionWidth() - fpsTextSize);
                ImGui.Text(fpsText);

                ImGui.EndMainMenuBar();
            }

            foreach (var view in _views)
            {
                view.Draw(ref isGameViewFocused);
            }

            var launcherImage = _context.Game.LauncherImage;

            if (launcherImage != null)
            {
                var launcherImageMaxSize = new Vector2(150, 150);

                var launcherImageSize = SizeF.CalculateSizeFittingAspectRatio(
                    new SizeF(launcherImage.Width, launcherImage.Height),
                    new Size((int)launcherImageMaxSize.X, (int)launcherImageMaxSize.Y));

                const int launcherImagePadding = 10;
                ImGui.SetNextWindowPos(new Vector2(
                                           _context.Game.Window.ClientBounds.Width - launcherImageSize.Width - launcherImagePadding,
                                           menuBarHeight + launcherImagePadding));

                ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, Vector2.Zero);
                ImGui.Begin("LauncherImage", ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoInputs | ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoDecoration);

                ImGui.Image(
                    _context.ImGuiRenderer.GetOrCreateImGuiBinding(_context.Game.GraphicsDevice.ResourceFactory, launcherImage),
                    new Vector2(launcherImageSize.Width, launcherImageSize.Height),
                    Vector2.Zero,
                    Vector2.One,
                    Vector4.One,
                    Vector4.Zero);

                ImGui.End();
                ImGui.PopStyleVar();
            }
        }
Exemplo n.º 5
0
        public void Draw(ref bool isGameViewFocused)
        {
            var viewport = ImGui.GetMainViewport();

            ImGui.SetNextWindowPos(viewport.GetWorkPos());
            ImGui.SetNextWindowSize(viewport.GetWorkSize());
            ImGui.SetNextWindowViewport(viewport.ID);
            ImGui.PushStyleVar(ImGuiStyleVar.WindowRounding, 0.0f);
            ImGui.PushStyleVar(ImGuiStyleVar.WindowBorderSize, 0.0f);
            ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, Vector2.Zero);

            var windowFlags = ImGuiWindowFlags.MenuBar | ImGuiWindowFlags.NoDocking;

            windowFlags |= ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove;
            windowFlags |= ImGuiWindowFlags.NoBringToFrontOnFocus | ImGuiWindowFlags.NoNavFocus;
            //windowFlags |= ImGuiWindowFlags.NoBackground;

            ImGui.Begin("Root", windowFlags);

            ImGui.PopStyleVar(3);

            ImGui.DockSpace(ImGui.GetID("DockSpace"), Vector2.Zero, ImGuiDockNodeFlags.None);

            float menuBarHeight = 0;

            if (ImGui.BeginMenuBar())
            {
                menuBarHeight = ImGui.GetWindowHeight();

                if (ImGui.BeginMenu("File"))
                {
                    if (ImGui.MenuItem("Exit", "Alt+F4", false, true))
                    {
                        Environment.Exit(0);
                    }

                    ImGui.EndMenu();
                }

                if (ImGui.BeginMenu("Jump"))
                {
                    if (ImGui.BeginMenu("Faction: " + _faction.Side))
                    {
                        foreach (var side in _playableSides)
                        {
                            if (ImGui.MenuItem(side.Side))
                            {
                                _faction = side;
                                ImGui.SetWindowFocus(side.Name);
                            }
                        }

                        ImGui.EndMenu();
                    }

                    if (ImGui.BeginMenu("Map: " + _map.Item1.Name))
                    {
                        foreach (var mapCache in _maps)
                        {
                            if (ImGui.MenuItem(mapCache.Value))
                            {
                                _map = (mapCache.Key, mapCache.Value);
                            }
                        }

                        ImGui.EndMenu();
                    }

                    if (ImGui.Button("Go!"))
                    {
                        var random   = new Random();
                        var faction2 = _playableSides[random.Next(0, _playableSides.Count())];

                        if (_map.Item1.IsMultiplayer)
                        {
                            _context.Game.StartMultiPlayerGame(
                                _map.Item1.Name,
                                new EchoConnection(),
                                new PlayerSetting?[]
                            {
                                new PlayerSetting(null, _faction, new ColorRgb(255, 0, 0), PlayerOwner.Player),
                                new PlayerSetting(null, faction2, new ColorRgb(255, 255, 255), PlayerOwner.EasyAi),
                            },
                                0
                                );
                        }
                        else
                        {
                            _context.Game.StartSinglePlayerGame(_map.Item1.Name);
                        }
                    }

                    ImGui.EndMenu();
                }

                if (ImGui.BeginMenu("Windows"))
                {
                    foreach (var view in _views)
                    {
                        if (ImGui.MenuItem(view.DisplayName, null, view.IsVisible, true))
                        {
                            view.IsVisible = true;

                            ImGui.SetWindowFocus(view.Name);
                        }
                    }

                    ImGui.EndMenu();
                }

                if (ImGui.BeginMenu("Preferences"))
                {
                    var isVSyncEnabled = _context.Game.GraphicsDevice.SyncToVerticalBlank;
                    if (ImGui.MenuItem("VSync", null, ref isVSyncEnabled, true))
                    {
                        _context.Game.GraphicsDevice.SyncToVerticalBlank = isVSyncEnabled;
                    }
                    var isFullscreen = _context.Game.Window.Fullscreen;
                    if (ImGui.MenuItem("Fullscreen", "Alt+Enter", ref isFullscreen, true))
                    {
                        _context.Game.Window.Fullscreen = isFullscreen;
                    }
                    ImGui.EndMenu();
                }

                if (_context.Game.Configuration.UseRenderDoc && ImGui.BeginMenu("RenderDoc"))
                {
                    var renderDoc = Game.RenderDoc;

                    if (ImGui.MenuItem("Trigger Capture"))
                    {
                        renderDoc.TriggerCapture();
                    }
                    if (ImGui.BeginMenu("Options"))
                    {
                        bool allowVsync = renderDoc.AllowVSync;
                        if (ImGui.Checkbox("Allow VSync", ref allowVsync))
                        {
                            renderDoc.AllowVSync = allowVsync;
                        }
                        bool validation = renderDoc.APIValidation;
                        if (ImGui.Checkbox("API Validation", ref validation))
                        {
                            renderDoc.APIValidation = validation;
                        }
                        int delayForDebugger = (int)renderDoc.DelayForDebugger;
                        if (ImGui.InputInt("Debugger Delay", ref delayForDebugger))
                        {
                            delayForDebugger           = Math.Clamp(delayForDebugger, 0, int.MaxValue);
                            renderDoc.DelayForDebugger = (uint)delayForDebugger;
                        }
                        bool verifyBufferAccess = renderDoc.VerifyBufferAccess;
                        if (ImGui.Checkbox("Verify Buffer Access", ref verifyBufferAccess))
                        {
                            renderDoc.VerifyBufferAccess = verifyBufferAccess;
                        }
                        bool overlayEnabled = renderDoc.OverlayEnabled;
                        if (ImGui.Checkbox("Overlay Visible", ref overlayEnabled))
                        {
                            renderDoc.OverlayEnabled = overlayEnabled;
                        }
                        bool overlayFrameRate = renderDoc.OverlayFrameRate;
                        if (ImGui.Checkbox("Overlay Frame Rate", ref overlayFrameRate))
                        {
                            renderDoc.OverlayFrameRate = overlayFrameRate;
                        }
                        bool overlayFrameNumber = renderDoc.OverlayFrameNumber;
                        if (ImGui.Checkbox("Overlay Frame Number", ref overlayFrameNumber))
                        {
                            renderDoc.OverlayFrameNumber = overlayFrameNumber;
                        }
                        bool overlayCaptureList = renderDoc.OverlayCaptureList;
                        if (ImGui.Checkbox("Overlay Capture List", ref overlayCaptureList))
                        {
                            renderDoc.OverlayCaptureList = overlayCaptureList;
                        }
                        ImGui.EndMenu();
                    }
                    if (ImGui.MenuItem("Launch Replay UI"))
                    {
                        renderDoc.LaunchReplayUI();
                    }

                    ImGui.EndMenu();
                }

                DrawTimingControls();

                var fpsText     = $"{ImGui.GetIO().Framerate:N2} FPS";
                var fpsTextSize = ImGui.CalcTextSize(fpsText).X;
                ImGui.SetCursorPosX(ImGui.GetWindowContentRegionWidth() - fpsTextSize);
                ImGui.Text(fpsText);

                ImGui.EndMenuBar();
            }

            foreach (var view in _views)
            {
                view.Draw(ref isGameViewFocused);
            }

            var launcherImage = _context.Game.LauncherImage;

            if (launcherImage != null)
            {
                var launcherImageMaxSize = new Vector2(150, 150);

                var launcherImageSize = SizeF.CalculateSizeFittingAspectRatio(
                    new SizeF(launcherImage.Width, launcherImage.Height),
                    new Size((int)launcherImageMaxSize.X, (int)launcherImageMaxSize.Y));

                const int launcherImagePadding = 10;
                ImGui.SetNextWindowPos(new Vector2(
                                           _context.Game.Window.ClientBounds.Width - launcherImageSize.Width - launcherImagePadding,
                                           menuBarHeight + launcherImagePadding));

                ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, Vector2.Zero);
                ImGui.Begin("LauncherImage", ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoInputs | ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoDecoration);

                ImGui.Image(
                    _context.ImGuiRenderer.GetOrCreateImGuiBinding(_context.Game.GraphicsDevice.ResourceFactory, launcherImage),
                    new Vector2(launcherImageSize.Width, launcherImageSize.Height),
                    Vector2.Zero,
                    Vector2.One,
                    Vector4.One,
                    Vector4.Zero);

                ImGui.End();
                ImGui.PopStyleVar();
            }

            ImGui.End();
        }
Exemplo n.º 6
0
        private void DrawMainUi(ref bool isGameViewFocused)
        {
            if (ImGui.BeginMenuBar())
            {
                if (ImGui.BeginMenu("Installation"))
                {
                    foreach (var installation in _installations)
                    {
                        if (ImGui.MenuItem(installation.Game.DisplayName, null, _selectedInstallation == installation, true))
                        {
                            ChangeInstallation(installation);
                        }
                    }

                    ImGui.EndMenu();
                }
                if (ImGui.BeginMenu("Preferences"))
                {
                    bool isVSyncEnabled = _isVSyncEnabled;
                    if (ImGui.MenuItem("VSync", null, ref isVSyncEnabled, true))
                    {
                        SetVSync(isVSyncEnabled);
                    }
                    ImGui.EndMenu();
                }
                ImGui.EndMenuBar();
            }

            ImGui.BeginChild("sidebar", new Vector2(250, 0), true, 0);

            if (_launcherImage != null)
            {
                var availableSize = ImGui.GetContentRegionAvail();

                var launcherImageSize = SizeF.CalculateSizeFittingAspectRatio(
                    new SizeF(_launcherImage.Width, _launcherImage.Height),
                    new Size((int)availableSize.X, (int)availableSize.Y));

                ImGui.Image(
                    _imGuiRenderer.GetOrCreateImGuiBinding(_gameWindow.GraphicsDevice.ResourceFactory, _launcherImage),
                    new Vector2(launcherImageSize.Width, launcherImageSize.Height),
                    Vector2.Zero,
                    Vector2.One,
                    Vector4.One,
                    Vector4.Zero);
            }

            ImGui.PushItemWidth(-1);
            ImGuiUtility.InputText("##search", _searchTextBuffer, out var searchText);
            UpdateSearch(searchText);

            ImGui.PopItemWidth();

            ImGui.BeginChild("files list", Vector2.Zero, true);

            for (var i = 0; i < _files.Count; i++)
            {
                var entry = _files[i];

                if (ImGui.Selectable(entry.FilePath, i == _currentFile))
                {
                    _currentFile = i;

                    RemoveAndDispose(ref _contentView);

                    _game.ContentManager.Unload();

                    _contentView = AddDisposable(new ContentView(
                                                     new Views.AssetViewContext(_game, _gamePanel, _imGuiRenderer, entry)));
                }
                ImGuiUtility.DisplayTooltipOnHover(entry.FilePath);
            }

            ImGui.EndChild();
            ImGui.EndChild();

            ImGui.SameLine();

            if (_contentView != null)
            {
                ImGui.BeginChild("content");

                ImGui.Text(_contentView.DisplayName);

                if (isGameViewFocused)
                {
                    var message = "Press [ESC] to unfocus the 3D view.";
                    ImGui.SameLine(ImGui.GetWindowWidth() - ImGui.CalcTextSize(message).X);
                    ImGui.TextColored(new Vector4(1.0f, 0.0f, 0.0f, 1.0f), message);
                }

                ImGui.BeginChild("content view");

                _contentView.Draw(ref isGameViewFocused);

                ImGui.EndChild();
                ImGui.EndChild();
            }
        }
Exemplo n.º 7
0
        public void Draw(ref bool isGameViewFocused)
        {
            float menuBarHeight = 0;

            if (ImGui.BeginMainMenuBar())
            {
                menuBarHeight = ImGui.GetWindowHeight();

                if (ImGui.BeginMenu("File"))
                {
                    if (ImGui.MenuItem("Exit", "Alt+F4", false, true))
                    {
                        Environment.Exit(0);
                    }

                    ImGui.EndMenu();
                }

                if (ImGui.BeginMenu("Jump"))
                {
                    if (ImGui.BeginMenu("Map"))
                    {
                        foreach (var mapCache in _context.Game.ContentManager.IniDataContext.MapCaches)
                        {
                            var mapName = mapCache.GetNameKey().Translate();

                            if (ImGui.MenuItem($"{mapName} ({mapCache.Name})"))
                            {
                                var iniContext = _context.Game.ContentManager.IniDataContext;
                                var faction1   = iniContext.PlayerTemplates.Find(x => x.PlayableSide == true);
                                var faction2   = iniContext.PlayerTemplates.FindLast(x => x.PlayableSide == true);

                                _context.Game.StartMultiPlayerGame(
                                    mapCache.Name,
                                    new EchoConnection(),
                                    new[]
                                {
                                    new PlayerSetting(faction1.Side, new ColorRgb(255, 0, 0)),
                                    new PlayerSetting(faction2.Side, new ColorRgb(255, 255, 255)),
                                },
                                    0);
                            }
                        }

                        ImGui.EndMenu();
                    }

                    ImGui.EndMenu();
                }

                if (ImGui.BeginMenu("Windows"))
                {
                    foreach (var view in _views)
                    {
                        if (ImGui.MenuItem(view.DisplayName, null, view.IsVisible, true))
                        {
                            view.IsVisible = true;

                            ImGui.SetWindowFocus(view.Name);
                        }
                    }

                    ImGui.EndMenu();
                }

                if (ImGui.BeginMenu("Preferences"))
                {
                    var isVSyncEnabled = _context.Game.GraphicsDevice.SyncToVerticalBlank;
                    if (ImGui.MenuItem("VSync", null, ref isVSyncEnabled, true))
                    {
                        _context.Game.GraphicsDevice.SyncToVerticalBlank = isVSyncEnabled;
                    }
                    var isFullscreen = _context.Game.Window.Fullscreen;
                    if (ImGui.MenuItem("Fullscreen", "Alt+Enter", ref isFullscreen, true))
                    {
                        _context.Game.Window.Fullscreen = isFullscreen;
                    }
                    ImGui.EndMenu();
                }

                DrawTimingControls();

                var fpsText     = $"{ImGui.GetIO().Framerate:N2} FPS";
                var fpsTextSize = ImGui.CalcTextSize(fpsText).X;
                ImGui.SetCursorPosX(ImGui.GetWindowContentRegionWidth() - fpsTextSize);
                ImGui.Text(fpsText);

                ImGui.EndMainMenuBar();
            }

            foreach (var view in _views)
            {
                view.Draw(ref isGameViewFocused);
            }

            var launcherImage = _context.Game.LauncherImage;

            if (launcherImage != null)
            {
                var launcherImageMaxSize = new Vector2(150, 150);

                var launcherImageSize = SizeF.CalculateSizeFittingAspectRatio(
                    new SizeF(launcherImage.Width, launcherImage.Height),
                    new Size((int)launcherImageMaxSize.X, (int)launcherImageMaxSize.Y));

                const int launcherImagePadding = 10;
                ImGui.SetNextWindowPos(new Vector2(
                                           _context.Game.Window.ClientBounds.Width - launcherImageSize.Width - launcherImagePadding,
                                           menuBarHeight + launcherImagePadding));

                ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, Vector2.Zero);
                ImGui.Begin("LauncherImage", ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoInputs | ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoDecoration);

                ImGui.Image(
                    _context.ImGuiRenderer.GetOrCreateImGuiBinding(_context.Game.GraphicsDevice.ResourceFactory, launcherImage),
                    new Vector2(launcherImageSize.Width, launcherImageSize.Height),
                    Vector2.Zero,
                    Vector2.One,
                    Vector4.One,
                    Vector4.Zero);

                ImGui.End();
                ImGui.PopStyleVar();
            }
        }
Exemplo n.º 8
0
        private void DrawMainUi(ref bool isGameViewFocused)
        {
            if (ImGui.BeginMenuBar())
            {
                if (ImGui.BeginMenu("Installation"))
                {
                    foreach (var installation in _installations)
                    {
                        if (ImGui.MenuItem(installation.Game.DisplayName, null, _selectedInstallation == installation, true))
                        {
                            ChangeInstallation(installation);
                        }
                    }

                    ImGui.EndMenu();
                }
                ImGui.EndMenuBar();
            }

            ImGui.BeginChild("sidebar", new Vector2(250, 0), true, 0);

            if (_launcherImage != null)
            {
                var availableSize = ImGui.GetContentRegionAvailable();

                var launcherImageSize = SizeF.CalculateSizeFittingAspectRatio(
                    new SizeF(_launcherImage.Width, _launcherImage.Height),
                    new Size((int)availableSize.X, (int)availableSize.Y));

                ImGui.Image(
                    _imGuiRenderer.GetOrCreateImGuiBinding(_gameWindow.GraphicsDevice.ResourceFactory, _launcherImage),
                    new Vector2(launcherImageSize.Width, launcherImageSize.Height),
                    Vector2.Zero,
                    Vector2.One,
                    Vector4.One,
                    Vector4.Zero);
            }

            ImGui.PushItemWidth(-1);
            ImGuiUtility.InputText("##search", _searchTextBuffer, out var searchText);
            ImGui.PopItemWidth();

            ImGui.BeginChild("files list", true, 0);

            for (var i = 0; i < _files.Count; i++)
            {
                var entry = _files[i];

                if (!string.IsNullOrEmpty(searchText) && entry.FilePath.IndexOf(searchText, StringComparison.OrdinalIgnoreCase) < 0)
                {
                    continue;
                }

                if (ImGui.Selectable(entry.FilePath, i == _currentFile))
                {
                    _currentFile = i;

                    RemoveAndDispose(ref _contentView);

                    _game.ContentManager.Unload();

                    _contentView = AddDisposable(new ContentView(
                                                     new Views.AssetViewContext(_game, _gamePanel, _imGuiRenderer, entry)));
                }

                var shouldOpenSaveDialog = false;

                if (ImGui.BeginPopupContextItem("context" + i))
                {
                    _currentFile = i;

                    if (ImGui.Selectable("Export..."))
                    {
                        shouldOpenSaveDialog = true;
                    }

                    ImGui.EndPopup();
                }

                var exportId = "Export##ExportDialog" + i;
                if (shouldOpenSaveDialog)
                {
                    ImGui.OpenPopup(exportId);
                }

                if (ImGui.BeginPopupModal(exportId, WindowFlags.AlwaysAutoResize))
                {
                    ImGuiUtility.InputText("File Path", _filePathBuffer, out var filePath);

                    if (ImGui.Button("Save"))
                    {
                        using (var entryStream = entry.Open())
                        {
                            using (var fileStream = File.OpenWrite(filePath))
                            {
                                entryStream.CopyTo(fileStream);
                            }
                        }

                        ImGui.CloseCurrentPopup();
                    }

                    ImGui.SetItemDefaultFocus();

                    ImGui.SameLine();

                    if (ImGui.Button("Cancel"))
                    {
                        ImGui.CloseCurrentPopup();
                    }

                    ImGui.EndPopup();
                }
            }

            ImGui.EndChild();
            ImGui.EndChild();

            ImGui.SameLine();

            if (_contentView != null)
            {
                ImGui.BeginChild("content");

                ImGui.Text(_contentView.DisplayName);

                ImGui.BeginChild("content view");

                _contentView.Draw(ref isGameViewFocused);

                ImGui.EndChild();
                ImGui.EndChild();
            }
        }