// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; using System.Linq; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Graphics.Containers; using osu.Game.Scoring; using osuTK; namespace osu.Game.Screens.Ranking { public class ScorePanelList : CompositeDrawable { /// /// Normal spacing between all panels. /// private const float panel_spacing = 5; /// /// Spacing around both sides of the expanded panel. This is added on top of . /// private const float expanded_panel_spacing = 15; private readonly Flow flow; private readonly ScrollContainer scroll; private ScorePanel expandedPanel; public ScorePanelList(ScoreInfo initialScore) { RelativeSizeAxes = Axes.Both; InternalChild = scroll = new OsuScrollContainer(Direction.Horizontal) { RelativeSizeAxes = Axes.Both, Child = flow = new Flow { Anchor = Anchor.Centre, Origin = Anchor.Centre, Direction = FillDirection.Horizontal, Spacing = new Vector2(panel_spacing, 0), AutoSizeAxes = Axes.Both, } }; AddScore(initialScore); ShowScore(initialScore); } public void AddScore(ScoreInfo score) { flow.Add(new ScorePanel(score) { Anchor = Anchor.Centre, Origin = Anchor.Centre, }.With(p => { p.StateChanged += s => { if (s == PanelState.Expanded) ShowScore(score); }; })); } public void ShowScore(ScoreInfo score) { foreach (var p in flow.Where(p => p.Score != score)) p.State = PanelState.Contracted; if (expandedPanel != null) expandedPanel.Margin = new MarginPadding(0); expandedPanel = flow.Single(p => p.Score == score); expandedPanel.State = PanelState.Expanded; expandedPanel.Margin = new MarginPadding { Horizontal = expanded_panel_spacing }; float scrollOffset = flow.IndexOf(expandedPanel) * (ScorePanel.CONTRACTED_WIDTH + panel_spacing); scroll.ScrollTo(scrollOffset); } protected override void Update() { base.Update(); flow.Padding = new MarginPadding { Horizontal = DrawWidth / 2f - expandedPanel.DrawWidth / 2f - expanded_panel_spacing }; } private class Flow : FillFlowContainer { public override IEnumerable FlowingChildren => AliveInternalChildren.OfType().OrderByDescending(s => s.Score.TotalScore).ThenByDescending(s => s.Score.OnlineScoreID); } } }