// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System.Linq; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Input.Events; using osu.Game.Beatmaps; using osu.Game.Online.API.Requests; using osu.Game.Overlays.BeatmapSet; using osu.Game.Overlays.BeatmapSet.Scores; using osu.Game.Overlays.Comments; using osu.Game.Rulesets; using osuTK; using osuTK.Graphics; namespace osu.Game.Overlays { public class BeatmapSetOverlay : OnlineOverlay { public const float X_PADDING = 40; public const float Y_PADDING = 25; public const float RIGHT_WIDTH = 275; [Resolved] private RulesetStore rulesets { get; set; } private readonly Bindable beatmapSet = new Bindable(); // receive input outside our bounds so we can trigger a close event on ourselves. public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true; public BeatmapSetOverlay() : base(OverlayColourScheme.Blue) { Info info; CommentsSection comments; Child = new FillFlowContainer { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, Direction = FillDirection.Vertical, Spacing = new Vector2(0, 20), Children = new Drawable[] { info = new Info(), new ScoresContainer { Beatmap = { BindTarget = Header.HeaderContent.Picker.Beatmap } }, comments = new CommentsSection() } }; Header.BeatmapSet.BindTo(beatmapSet); info.BeatmapSet.BindTo(beatmapSet); comments.BeatmapSet.BindTo(beatmapSet); Header.HeaderContent.Picker.Beatmap.ValueChanged += b => { info.Beatmap = b.NewValue; ScrollFlow.ScrollToStart(); }; } protected override BeatmapSetHeader CreateHeader() => new BeatmapSetHeader(); protected override Color4 GetBackgroundColour() => ColourProvider.Background6; protected override void PopOutComplete() { base.PopOutComplete(); beatmapSet.Value = null; } protected override bool OnClick(ClickEvent e) { Hide(); return true; } public void FetchAndShowBeatmap(int beatmapId) { beatmapSet.Value = null; var req = new GetBeatmapSetRequest(beatmapId, BeatmapSetLookupType.BeatmapId); req.Success += res => { beatmapSet.Value = res.ToBeatmapSet(rulesets); Header.HeaderContent.Picker.Beatmap.Value = Header.BeatmapSet.Value.Beatmaps.First(b => b.OnlineBeatmapID == beatmapId); }; API.Queue(req); Show(); } public void FetchAndShowBeatmapSet(int beatmapSetId) { beatmapSet.Value = null; var req = new GetBeatmapSetRequest(beatmapSetId); req.Success += res => beatmapSet.Value = res.ToBeatmapSet(rulesets); API.Queue(req); Show(); } /// /// Show an already fully-populated beatmap set. /// /// The set to show. public void ShowBeatmapSet(BeatmapSetInfo set) { beatmapSet.Value = set; Show(); } private class CommentsSection : BeatmapSetLayoutSection { public readonly Bindable BeatmapSet = new Bindable(); public CommentsSection() { CommentsContainer comments; Add(comments = new CommentsContainer()); BeatmapSet.BindValueChanged(beatmapSet => { if (beatmapSet.NewValue?.OnlineBeatmapSetID is int onlineBeatmapSetID) { Show(); comments.ShowComments(CommentableType.Beatmapset, onlineBeatmapSetID); } else { Hide(); } }, true); } } } }