<commit_before>//Copyright (c) 2007-2016 ppy Pty Ltd <<EMAIL>>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Game.Database;
using OpenTK;

namespace osu.Game.Beatmaps.Drawable
{
    class BeatmapGroup : Container, IStateful<BeatmapGroupState>
    {
        public BeatmapPanel SelectedPanel;

        /// <summary>
        /// Fires when one of our difficulties was selected. Will fire on first expand.
        /// </summary>
        public Action<BeatmapGroup, BeatmapInfo> SelectionChanged;

        private BeatmapSetInfo beatmapSet;
        private BeatmapSetHeader header;
        private FlowContainer difficulties;

        private BeatmapGroupState state;

        public List<BeatmapPanel> BeatmapPanels;

        public BeatmapGroupState State
        {
            get { return state; }
            set
            {
                state = value;
                switch (state)
                {
                    case BeatmapGroupState.Expanded:
                        FadeTo(1, 250);
                        difficulties.Show();

                        header.State = PanelSelectedState.Selected;
                        break;
                    case BeatmapGroupState.Collapsed:
                        FadeTo(0.5f, 250);

                        header.State = PanelSelectedState.NotSelected;
                        difficulties.Hide();
                        break;
                }
            }
        }

        public BeatmapGroup(BeatmapSetInfo beatmapSet)
        {
            this.beatmapSet = beatmapSet;

            Alpha = 0;
            AutoSizeAxes = Axes.Y;
            RelativeSizeAxes = Axes.X;

            BeatmapPanels = beatmapSet.Beatmaps.Select(b =>
                new BeatmapPanel(b)
                {
                    GainedSelection = panelGainedSelection,
                    Anchor = Anchor.TopRight,
                    Origin = Anchor.TopRight,
                    RelativeSizeAxes = Axes.X,
                }).ToList();
                

            Children = new[]
            {
                new FlowContainer
                {
                    RelativeSizeAxes = Axes.X,
                    AutoSizeAxes = Axes.Y,
                    Direction = FlowDirection.VerticalOnly,
                    Children = new Framework.Graphics.Drawable[]
                    {
                        header = new BeatmapSetHeader(beatmapSet)
                        {
                            GainedSelection = headerGainedSelection,
                            RelativeSizeAxes = Axes.X,
                            Anchor = Anchor.TopRight,
                            Origin = Anchor.TopRight,
                        },
                        difficulties = new FlowContainer
                        {
                            RelativeSizeAxes = Axes.X,
                            AutoSizeAxes = Axes.Y,
                            Margin = new MarginPadding { Top = 5 },
                            Padding = new MarginPadding { Left = 75 },
                            Spacing = new Vector2(0, 5),
                            Direction = FlowDirection.VerticalOnly,
                            Alpha = 0,
                            Children = BeatmapPanels
                        }
                    }
                }
            };
        }

        public override void Load(BaseGame game)
        {
            base.Load(game);
            State = BeatmapGroupState.Collapsed;
        }

        private void headerGainedSelection(BeatmapSetHeader panel)
        {
            State = BeatmapGroupState.Expanded;

            if (SelectedPanel == null)
                BeatmapPanels.First().State = PanelSelectedState.Selected;
        }

        private void panelGainedSelection(BeatmapPanel panel)
        {
            try
            {
                if (SelectedPanel == panel) return;

                if (SelectedPanel != null)
                    SelectedPanel.State = PanelSelectedState.NotSelected;
                SelectedPanel = panel;
            }
            finally<commit_msg>More comments.<commit_after>//Copyright (c) 2007-2016 ppy Pty Ltd <<EMAIL>>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Game.Database;
using OpenTK;

namespace osu.Game.Beatmaps.Drawable
{
    class BeatmapGroup : Container, IStateful<BeatmapGroupState>
    {
        public BeatmapPanel SelectedPanel;

        /// <summary>
        /// Fires when one of our difficulties was selected. Will fire on first expand.
        /// </summary>
        public Action<BeatmapGroup, BeatmapInfo> SelectionChanged;

        private BeatmapSetInfo beatmapSet;
        private BeatmapSetHeader header;
        private FlowContainer difficulties;

        private BeatmapGroupState state;

        public List<BeatmapPanel> BeatmapPanels;

        public BeatmapGroupState State
        {
            get { return state; }
            set
            {
                state = value;
                switch (state)
                {
                    case BeatmapGroupState.Expanded:
                        FadeTo(1, 250);
                        difficulties.Show();

                        header.State = PanelSelectedState.Selected;
                        break;
                    case BeatmapGroupState.Collapsed:
                        FadeTo(0.5f, 250);

                        header.State = PanelSelectedState.NotSelected;
                        difficulties.Hide();
                        break;
                }
            }
        }

        public BeatmapGroup(BeatmapSetInfo beatmapSet)
        {
            this.beatmapSet = beatmapSet;

            Alpha = 0;
            AutoSizeAxes = Axes.Y;
            RelativeSizeAxes = Axes.X;

            BeatmapPanels = beatmapSet.Beatmaps.Select(b =>
                new BeatmapPanel(b)
                {
                    GainedSelection = panelGainedSelection,
                    Anchor = Anchor.TopRight,
                    Origin = Anchor.TopRight,
                    RelativeSizeAxes = Axes.X,
                }).ToList();
                

            Children = new[]
            {
                new FlowContainer
                {
                    RelativeSizeAxes = Axes.X,
                    AutoSizeAxes = Axes.Y,
                    Direction = FlowDirection.VerticalOnly,
                    Children = new Framework.Graphics.Drawable[]
                    {
                        header = new BeatmapSetHeader(beatmapSet)
                        {
                            GainedSelection = headerGainedSelection,
                            RelativeSizeAxes = Axes.X,
                            Anchor = Anchor.TopRight,
                            Origin = Anchor.TopRight,
                        },
                        difficulties = new FlowContainer
                        {
                            RelativeSizeAxes = Axes.X,
                            AutoSizeAxes = Axes.Y,
                            Margin = new MarginPadding { Top = 5 },
                            Padding = new MarginPadding { Left = 75 },
                            Spacing = new Vector2(0, 5),
                            Direction = FlowDirection.VerticalOnly,
                            Alpha = 0,
                            Children = BeatmapPanels
                        }
                    }
                }
            };
        }

        public override void Load(BaseGame game)
        {
            base.Load(game);
            State = BeatmapGroupState.Collapsed;
        }

        private void headerGainedSelection(BeatmapSetHeader panel)
        {
            State = BeatmapGroupState.Expanded;

            //we want to make sure one of our children is selected in the case none have been selected yet.
            if (SelectedPanel == null)
                BeatmapPanels.First().State = PanelSelectedState.Selected;
        }

        private void panelGainedSelection(BeatmapPanel panel)
        {
            try
            {
                if (SelectedPanel == panel) return;

                if (SelectedPanel != null)
                    SelectedPanel.State = PanelSelectedState.NotSelected;
                SelectedPanel = panel;
            }
            finally
{'fraction_non_alphanumeric': 0.06655270655270655, 'fraction_numerical': 0.005698005698005698, 'mean_word_length': 1.1695920889987639, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1357615', 'n_tokens_mistral': 2181, 'n_tokens_neox': 1976, 'n_words': 443}