<commit_before>// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Diagnostics;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Logging;
using osu.Framework.Screens;
using osu.Game.Input;
using osu.Game.Online.API;
using osu.Game.Online.Rooms;
using osu.Game.Screens.OnlinePlay.Components;
using osu.Game.Screens.OnlinePlay.Match;
using osu.Game.Screens.OnlinePlay.Match.Components;
using osu.Game.Screens.Play;
using osu.Game.Screens.Play.HUD;
using osu.Game.Users;
using osuTK;
using Footer = osu.Game.Screens.OnlinePlay.Match.Components.Footer;

namespace osu.Game.Screens.OnlinePlay.Playlists
{
    public class PlaylistsRoomSubScreen : RoomSubScreen
    {
        public override string Title { get; }

        public override string ShortTitle => "playlist";

        [Resolved]
        private IAPIProvider api { get; set; }

        private readonly IBindable<bool> isIdle = new BindableBool();

        private MatchLeaderboard leaderboard;
        private OverlinedHeader participantsHeader;
        private SelectionPollingComponent selectionPollingComponent;

        public PlaylistsRoomSubScreen(Room room)
            : base(room)
        {
            Title = room.RoomID.Value == null ? "New playlist" : room.Name.Value;
            Activity.Value = new UserActivity.InLobby(room);
        }

        [BackgroundDependencyLoader(true)]
        private void load([CanBeNull] IdleTracker idleTracker)
        {
            if (idleTracker != null)
                isIdle.BindTo(idleTracker.IsIdle);

            AddInternal(selectionPollingComponent = new SelectionPollingComponent());
        }

        protected override void LoadComplete()
        {
            base.LoadComplete();

            isIdle.BindValueChanged(_ => updatePollingRate(), true);
            RoomId.BindValueChanged(id =>
            {
                if (id.NewValue != null)
                {
                    // Set the first playlist item.
                    // This is scheduled since updating the room and playlist may happen in an arbitrary order (via Room.CopyFrom()).
                    Schedule(() => SelectedItem.Value = Room.Playlist.FirstOrDefault());
                }
            }, true);
        }

        private void updatePollingRate()
        {
            selectionPollingComponent.TimeBetweenPolls.Value = isIdle.Value ? 30000 : 5000;
            Logger.Log($"Polling adjusted (selection: {selectionPollingComponent.TimeBetweenPolls.Value})");
        }

        protected override Screen CreateGameplayScreen() => new PlayerLoader(() => new PlaylistsPlayer(SelectedItem.Value)
        {
            Exited = () => leaderboard.RefreshScores()
        });

        protected override Drawable CreateMainContent() => new GridContainer
        {
            RelativeSizeAxes = Axes.Both,
            RowDimensions = new[]
            {
                new Dimension(GridSizeMode.AutoSize),
                new Dimension(GridSizeMode.AutoSize),
                new Dimension(GridSizeMode.AutoSize),
                new Dimension(),
            },
            Content = new[]
            {
                new Drawable[] { new Match.Components.Header() },
                new Drawable[]
                {
                    participantsHeader = new OverlinedHeader("Participants")
                    {
                        ShowLine = false
                    }
                },
                new Drawable[]
                {
                    new Container
                    {
                        RelativeSizeAxes = Axes.X,
                        AutoSizeAxes = Axes.Y,
                        Margin = new MarginPadding { Top = 5 },
                        Child = new ParticipantsDisplay(Direction.Horizontal)
                        {
                            Details = { BindTarget = participantsHeader.Details }
                        }
                    }
                },
                new Drawable[]
                {
                    new GridContainer
                    {
                        RelativeSizeAxes = Axes.Both,
                        Content = new[]
                        {
                            new Drawable[]
                            {
                                new Container
                                {
                                    RelativeSizeAxes = Axes.Both,
                                    Padding = new MarginPadding { Right = 5 },
                                    Child = new GridContainer
                                    {
                                        RelativeSizeAxes = Axes.Both,
                                        Content = new[]
                                        {
                                            new Drawable[] { new OverlinedPlaylistHeader(), },
                                            new Drawable[]
                                            {
                                                new DrawableRoomPlaylistWithResults
                                                {
                                                    RelativeSizeAxes = Axes.Both,
                                                    Items = { BindTarget = Room.Playlist },
                                                    SelectedItem = { BindTarget = SelectedItem },
                                                    RequestShowResults = item =>
                                                    {
                                                        Debug.Assert(RoomId.Value != null);
                                                        ParentScreen?.Push(new PlaylistsResultsScreen(null, RoomId.Value.Value, item, false));
                                                    }
                                                }
                                            },
                                        },
                                        RowDimensions = new[]
                                        {
                                            new Dimension(GridSizeMode.AutoSize),
                                            new Dimension(),
                                        }
                                    }
                                },
                                null,
                                new GridContainer
                                {
                                    RelativeSizeAxes = Axes.Both,
                                    Content = new[]
                                    {
                                        new[]
                                        {
                                            UserModsSection = new FillFlowContainer
                                            {
                                                RelativeSizeAxes = Axes.X,
                                                AutoSizeAxes = Axes.Y,
                                                Margin = new MarginPadding { Bottom = 10 },
                                                Children = new Drawable[]
                                                {
                                                    new OverlinedHeader("Extra mods"),
                                                    new FillFlowContainer
                                                    {
                                                        AutoSizeAxes = Axes.Both,
                                                        Direction = FillDirection.Horizontal,
                                                        Spacing = new Vector2(10, 0),
                                                        Children = new Drawable[]
                                                        {
                                                            new UserModSelectButton
                                                            {
                                                                Anchor = Anchor.CentreLeft,
                                                                Origin = Anchor.CentreLeft,
                                                                Width = 90,
                                                                Text = "Select",
                                                                Action = ShowUserModSelect,
                                                            },
                                                            new ModDisplay
                                                            {
                                                                Anchor = Anchor.CentreLeft,
                                                                Origin = Anchor.CentreLeft,
                                                                Current = UserMods,
                                                                Scale = new Vector2(0.8f),
                                                            },
                                                        }
                                                    }
                                                }
                                            },
                                        },
                                        new Drawable[]
                                        {
                                            new OverlinedHeader("Leaderboard")
                                        },
                                        new Drawable[] { leaderboard = new MatchLeaderboard { RelativeSizeAxes = Axes.Both }, },
                                        new Drawable[] { new OverlinedHeader("Chat"), },
                                        new Drawable[] { new MatchChatDisplay { RelativeSizeAxes = Axes.Both } }
                                    },
                                    RowDimensions = new[]
                                    {
                                        new Dimension(GridSizeMode.AutoSize),
                                        new Dimension(GridSizeMode.AutoSize),
                                        new Dimension(),
                                        new Dimension(GridSizeMode.AutoSize),
                                        new Dimension(GridSizeMode.Relative, size: 0.4f, minSize: 120),
                                    }
                                },
                                null
                            },
                        },
                        ColumnDimensions = new[]
                        {
                            new Dimension(GridSizeMode.Relative, size: 0.5f, maxSize: 400),
                            new Dimension(),
                            new Dimension(GridSizeMode.Relative, size: 0.5f, maxSize: 600),
                            new Dimension(),
                        }
                    }
                }
            },
        };

        protected override Drawable CreateFooter() => new Footer
        {
            OnStart = StartPlay
        };

        protected override RoomSettingsOverlay CreateRoomSettingsOverlay() => new PlaylistsRoomSettingsOverlay
        {
            EditPlaylist = () =>
            {<commit_msg>Remove participants from playlists screen<commit_after>// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Diagnostics;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Logging;
using osu.Framework.Screens;
using osu.Game.Input;
using osu.Game.Online.API;
using osu.Game.Online.Rooms;
using osu.Game.Screens.OnlinePlay.Components;
using osu.Game.Screens.OnlinePlay.Match;
using osu.Game.Screens.OnlinePlay.Match.Components;
using osu.Game.Screens.Play;
using osu.Game.Screens.Play.HUD;
using osu.Game.Users;
using osuTK;
using Footer = osu.Game.Screens.OnlinePlay.Match.Components.Footer;

namespace osu.Game.Screens.OnlinePlay.Playlists
{
    public class PlaylistsRoomSubScreen : RoomSubScreen
    {
        public override string Title { get; }

        public override string ShortTitle => "playlist";

        [Resolved]
        private IAPIProvider api { get; set; }

        private readonly IBindable<bool> isIdle = new BindableBool();

        private MatchLeaderboard leaderboard;
        private SelectionPollingComponent selectionPollingComponent;

        public PlaylistsRoomSubScreen(Room room)
            : base(room)
        {
            Title = room.RoomID.Value == null ? "New playlist" : room.Name.Value;
            Activity.Value = new UserActivity.InLobby(room);
        }

        [BackgroundDependencyLoader(true)]
        private void load([CanBeNull] IdleTracker idleTracker)
        {
            if (idleTracker != null)
                isIdle.BindTo(idleTracker.IsIdle);

            AddInternal(selectionPollingComponent = new SelectionPollingComponent());
        }

        protected override void LoadComplete()
        {
            base.LoadComplete();

            isIdle.BindValueChanged(_ => updatePollingRate(), true);
            RoomId.BindValueChanged(id =>
            {
                if (id.NewValue != null)
                {
                    // Set the first playlist item.
                    // This is scheduled since updating the room and playlist may happen in an arbitrary order (via Room.CopyFrom()).
                    Schedule(() => SelectedItem.Value = Room.Playlist.FirstOrDefault());
                }
            }, true);
        }

        private void updatePollingRate()
        {
            selectionPollingComponent.TimeBetweenPolls.Value = isIdle.Value ? 30000 : 5000;
            Logger.Log($"Polling adjusted (selection: {selectionPollingComponent.TimeBetweenPolls.Value})");
        }

        protected override Screen CreateGameplayScreen() => new PlayerLoader(() => new PlaylistsPlayer(SelectedItem.Value)
        {
            Exited = () => leaderboard.RefreshScores()
        });

        protected override Drawable CreateMainContent() => new GridContainer
        {
            RelativeSizeAxes = Axes.Both,
            Content = new[]
            {
                new Drawable[]
                {
                    new Container
                    {
                        RelativeSizeAxes = Axes.Both,
                        Padding = new MarginPadding { Right = 5 },
                        Child = new GridContainer
                        {
                            RelativeSizeAxes = Axes.Both,
                            Content = new[]
                            {
                                new Drawable[] { new OverlinedPlaylistHeader(), },
                                new Drawable[]
                                {
                                    new DrawableRoomPlaylistWithResults
                                    {
                                        RelativeSizeAxes = Axes.Both,
                                        Items = { BindTarget = Room.Playlist },
                                        SelectedItem = { BindTarget = SelectedItem },
                                        RequestShowResults = item =>
                                        {
                                            Debug.Assert(RoomId.Value != null);
                                            ParentScreen?.Push(new PlaylistsResultsScreen(null, RoomId.Value.Value, item, false));
                                        }
                                    }
                                },
                            },
                            RowDimensions = new[]
                            {
                                new Dimension(GridSizeMode.AutoSize),
                                new Dimension(),
                            }
                        }
                    },
                    null,
                    new GridContainer
                    {
                        RelativeSizeAxes = Axes.Both,
                        Content = new[]
                        {
                            new[]
                            {
                                UserModsSection = new FillFlowContainer
                                {
                                    RelativeSizeAxes = Axes.X,
                                    AutoSizeAxes = Axes.Y,
                                    Margin = new MarginPadding { Bottom = 10 },
                                    Children = new Drawable[]
                                    {
                                        new OverlinedHeader("Extra mods"),
                                        new FillFlowContainer
                                        {
                                            AutoSizeAxes = Axes.Both,
                                            Direction = FillDirection.Horizontal,
                                            Spacing = new Vector2(10, 0),
                                            Children = new Drawable[]
                                            {
                                                new UserModSelectButton
                                                {
                                                    Anchor = Anchor.CentreLeft,
                                                    Origin = Anchor.CentreLeft,
                                                    Width = 90,
                                                    Text = "Select",
                                                    Action = ShowUserModSelect,
                                                },
                                                new ModDisplay
                                                {
                                                    Anchor = Anchor.CentreLeft,
                                                    Origin = Anchor.CentreLeft,
                                                    Current = UserMods,
                                                    Scale = new Vector2(0.8f),
                                                },
                                            }
                                        }
                                    }
                                },
                            },
                            new Drawable[]
                            {
                                new OverlinedHeader("Leaderboard")
                            },
                            new Drawable[] { leaderboard = new MatchLeaderboard { RelativeSizeAxes = Axes.Both }, },
                            new Drawable[] { new OverlinedHeader("Chat"), },
                            new Drawable[] { new MatchChatDisplay { RelativeSizeAxes = Axes.Both } }
                        },
                        RowDimensions = new[]
                        {
                            new Dimension(GridSizeMode.AutoSize),
                            new Dimension(GridSizeMode.AutoSize),
                            new Dimension(),
                            new Dimension(GridSizeMode.AutoSize),
                            new Dimension(GridSizeMode.Relative, size: 0.4f, minSize: 120),
                        }
                    },
                },
            },
            ColumnDimensions = new[]
            {
                new Dimension(GridSizeMode.Relative, size: 0.5f, maxSize: 400),
                new Dimension(),
                new Dimension(GridSizeMode.Relative, size: 0.5f, maxSize: 600),
            }
        };

        protected override Drawable CreateFooter() => new Footer
        {
            OnStart = StartPlay
        };

        protected override RoomSettingsOverlay CreateRoomSettingsOverlay() => new PlaylistsRoomSettingsOverlay
        {
            EditPlaylist = () =>
            {
{'fraction_non_alphanumeric': 0.06295267387637662, 'fraction_numerical': 0.0036213910110129972, 'mean_word_length': 0.7816173221387539, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 220, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4043477', 'n_tokens_mistral': 3912, 'n_tokens_neox': 3593, 'n_words': 804}