예제 #1
0
        private void LoginWindow(IPlayerProvider playerProvider)
        {
            ImGui.SetNextWindowSize(_playerWindowSize);
            if (!ImGui.Begin($"Fantasy Player: {playerProvider.PlayerState.ServiceName} Login",
                             ref _plugin.Configuration.PlayerSettings.PlayerWindowShown,
                             ImGuiWindowFlags.NoResize))
            {
                return;
            }

            if (!playerProvider.PlayerState.IsAuthenticating)
            {
                InterfaceUtils.TextCentered($"Please login to {playerProvider.PlayerState.ServiceName} to start.");
                if (InterfaceUtils.ButtonCentered("Login"))
                {
                    playerProvider.StartAuth();
                }
            }
            else
            {
                InterfaceUtils.TextCentered("Waiting for a response to login... Please check your browser.");
                if (InterfaceUtils.ButtonCentered("Re-open Url"))
                {
                    playerProvider.RetryAuth();
                }
            }

            ImGui.End();
        }
예제 #2
0
        private void ErrorWindowLoop()
        {
            ImGui.SetNextWindowSize(_errorWindowSize);
            if (ImGui.Begin("Fantasy Player: Error",
                            ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoResize))
            {
                var textParts = _plugin.PlayerManager.ErrorMessage.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var part in textParts)
                {
                    InterfaceUtils.TextCentered(part);
                }
                ImGui.PushStyleColor(ImGuiCol.Text, InterfaceUtils.DarkenColor);
                InterfaceUtils.TextCentered("(If this error has occurred right after an update please try restarting your game.)");
                ImGui.PopStyleColor();
                if (InterfaceUtils.ButtonCentered("Close Window"))
                {
                    _plugin.PlayerManager.ErrorMessage = null;
                }

                ImGui.End();
            }
        }
예제 #3
0
        private void MainWindow(PlayerStateStruct playerState, IPlayerProvider currentProvider)
        {
            ImGui.SetNextWindowBgAlpha(_plugin.Configuration.PlayerSettings.Transparency);
            SetDefaultWindowSize(_plugin.Configuration.PlayerSettings);


            var lockFlags = (_plugin.Configuration.PlayerSettings.PlayerLocked)
                ? ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoResize
                : ImGuiWindowFlags.None;

            var clickThroughFlags = (_plugin.Configuration.PlayerSettings.DisableInput)
                ? ImGuiWindowFlags.NoMouseInputs | ImGuiWindowFlags.NoResize
                : ImGuiWindowFlags.None;

            var playerSettings = _plugin.Configuration.PlayerSettings;

            if (!ImGui.Begin($"Fantasy Player##C{playerSettings.CompactPlayer}&N{playerSettings.NoButtons}",
                             ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoScrollbar | lockFlags |
                             clickThroughFlags))
            {
                return;
            }

            //Disable FirstRun
            if (_plugin.Configuration.PlayerSettings.FirstRunNone)
            {
                _plugin.Configuration.PlayerSettings.FirstRunNone = false;
                _plugin.Configuration.Save();
            }

            //////////////// Right click popup ////////////////

            if (ImGui.BeginPopupContextWindow())
            {
                if (_playerManager.PlayerProviders.Count > 1)
                {
                    if (ImGui.BeginMenu("Switch provider"))
                    {
                        foreach (var provider in _playerManager.PlayerProviders)
                        {
                            if (provider.Value == _playerManager.CurrentPlayerProvider)
                            {
                                continue;
                            }
                            if (ImGui.MenuItem(provider.Key.Name.Replace("Provider", "")))
                            {
                                _playerManager.CurrentPlayerProvider = provider.Value;
                                _plugin.Configuration.PlayerSettings.DefaultProvider = provider.Key.FullName;
                                _plugin.Configuration.Save();
                            }
                        }
                        ImGui.EndMenu();
                    }

                    ImGui.Separator();
                }

                if (!_plugin.Configuration.SpotifySettings.LimitedAccess)
                {
                    if (ImGui.MenuItem("Compact mode", null, ref _plugin.Configuration.PlayerSettings.CompactPlayer))
                    {
                        if (_plugin.Configuration.PlayerSettings.NoButtons)
                        {
                            _plugin.Configuration.PlayerSettings.NoButtons = false;
                        }
                    }

                    if (ImGui.MenuItem("Hide Buttons", null, ref _plugin.Configuration.PlayerSettings.NoButtons))
                    {
                        if (_plugin.Configuration.PlayerSettings.CompactPlayer)
                        {
                            _plugin.Configuration.PlayerSettings.CompactPlayer = false;
                        }
                    }

                    ImGui.Separator();
                }

                ImGui.MenuItem("Lock player", null, ref _plugin.Configuration.PlayerSettings.PlayerLocked);
                ImGui.MenuItem("Show player", null, ref _plugin.Configuration.PlayerSettings.PlayerWindowShown);
                ImGui.MenuItem("Show config", null, ref _plugin.Configuration.ConfigShown);

                ImGui.EndPopup();
            }

            //////////////// Window Basics ////////////////

            if (playerState.CurrentlyPlaying.Id == null)
            {
                InterfaceUtils.TextCentered($"Nothing is playing on {playerState.ServiceName}.");
                return;
            }

            {
                //////////////// Window Setup ////////////////

                ImGui.PushStyleColor(ImGuiCol.Button, InterfaceUtils.TransparentColor);
                ImGui.PushStyleColor(ImGuiCol.ButtonActive, InterfaceUtils.TransparentColor);
                ImGui.PushStyleColor(ImGuiCol.ButtonHovered, InterfaceUtils.DarkenButtonColor);

                var track = playerState.CurrentlyPlaying;

                if (playerState.IsPlaying)
                {
                    _progressDelta += ImGui.GetIO().DeltaTime;
                }

                if (_progressMs != playerState.ProgressMs)
                {
                    _progressDelta = 0;
                }
                _progressMs = playerState.ProgressMs;

                var percent = playerState.ProgressMs * 100f / track.DurationMs +
                              (_progressDelta / (track.DurationMs / 100000f)); //me good maths

                _progressMs = playerState.ProgressMs;

                var artists = track.Artists.Aggregate("", (current, artist) => current + (artist + ", "));

                if (!_plugin.Configuration.PlayerSettings.NoButtons)
                {
                    //////////////// Play and Pause ////////////////

                    var stateIcon = (playerState.IsPlaying)
                        ? FontAwesomeIcon.Pause.ToIconString()
                        : FontAwesomeIcon.Play.ToIconString();

                    ImGui.PushFont(UiBuilder.IconFont);

                    if (ImGui.Button(FontAwesomeIcon.Backward.ToIconString()))
                    {
                        currentProvider.SetSkip(false);
                    }

                    if (InterfaceUtils.ButtonCentered(stateIcon))
                    {
                        currentProvider.SetPauseOrPlay(!playerState.IsPlaying);
                    }

                    //////////////// Shuffle and Repeat ////////////////

                    ImGui.SameLine(ImGui.GetWindowSize().X / 2 +
                                   (ImGui.GetFontSize() + ImGui.CalcTextSize(FontAwesomeIcon.Random.ToIconString()).X));

                    if (playerState.ShuffleState)
                    {
                        ImGui.PushStyleColor(ImGuiCol.Text, _plugin.Configuration.PlayerSettings.AccentColor);
                    }

                    if (ImGui.Button(FontAwesomeIcon.Random.ToIconString()))
                    {
                        currentProvider.SetShuffle(!playerState.ShuffleState);
                    }

                    if (playerState.ShuffleState)
                    {
                        ImGui.PopStyleColor();
                    }

                    if (playerState.RepeatState != "off")
                    {
                        ImGui.PushStyleColor(ImGuiCol.Text, _plugin.Configuration.PlayerSettings.AccentColor);
                    }

                    var buttonIcon = FontAwesomeIcon.Retweet.ToIconString();

                    if (playerState.RepeatState == "track")
                    {
                        buttonIcon = FontAwesomeIcon.Music.ToIconString();
                    }

                    ImGui.SameLine(ImGui.GetWindowSize().X / 2 -
                                   (ImGui.GetFontSize() + ImGui.CalcTextSize(buttonIcon).X +
                                    ImGui.CalcTextSize(FontAwesomeIcon.Random.ToIconString()).X));

                    if (ImGui.Button(buttonIcon))
                    {
                        currentProvider.SwapRepeatState();
                    }

                    if (playerState.RepeatState != "off")
                    {
                        ImGui.PopStyleColor();
                    }

                    ImGui.SameLine(ImGui.GetWindowSize().X -
                                   (ImGui.GetFontSize() +
                                    ImGui.CalcTextSize(FontAwesomeIcon.Forward.ToIconString()).X));
                    if (ImGui.Button(FontAwesomeIcon.Forward.ToIconString()))
                    {
                        currentProvider.SetSkip(true);
                    }

                    ImGui.PopFont();
                }

                if (!_plugin.Configuration.PlayerSettings.CompactPlayer)
                {
                    //////////////// Progress Bar ////////////////

                    ImGui.PushStyleColor(ImGuiCol.PlotHistogram, _plugin.Configuration.PlayerSettings.AccentColor);
                    ImGui.ProgressBar(percent / 100f, new Vector2(-1, 2f));
                    ImGui.PopStyleColor();

                    Vector2 imageSize = new Vector2(100 * ImGui.GetIO().FontGlobalScale,
                                                    100 * ImGui.GetIO().FontGlobalScale);

                    //////////////// Text ////////////////

                    InterfaceUtils.TextCentered(track.Name);

                    ImGui.PushStyleColor(ImGuiCol.Text, InterfaceUtils.DarkenColor);

                    ImGui.Spacing();
                    InterfaceUtils.TextCentered(artists.Remove(artists.Length - 2));


                    ImGui.PopStyleColor();
                }

                ImGui.PopStyleColor(3);
            }

            ImGui.End();
        }