// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps; namespace osu.Game.Screens.Select { public abstract class BeatmapDetailArea : Container { private const float details_padding = 10; private WorkingBeatmap beatmap; public virtual WorkingBeatmap Beatmap { get => beatmap; set { beatmap = value; Details.Beatmap = value?.BeatmapInfo; } } public readonly BeatmapDetails Details; protected Bindable CurrentTab { get => tabControl.Current; set => tabControl.Current = value; } private readonly Container content; protected override Container Content => content; private readonly BeatmapDetailAreaTabControl tabControl; protected BeatmapDetailArea() { AddRangeInternal(new Drawable[] { content = new Container { RelativeSizeAxes = Axes.Both, Padding = new MarginPadding { Top = BeatmapDetailAreaTabControl.HEIGHT }, Child = Details = new BeatmapDetails { RelativeSizeAxes = Axes.X, Alpha = 0, Margin = new MarginPadding { Top = details_padding }, } }, tabControl = new BeatmapDetailAreaTabControl { RelativeSizeAxes = Axes.X, TabItems = CreateTabItems(), OnFilter = OnTabChanged, }, }); } /// /// Refreshes the currently-displayed details. /// public virtual void Refresh() { } protected override void UpdateAfterChildren() { base.UpdateAfterChildren(); Details.Height = Math.Min(DrawHeight - details_padding * 3 - BeatmapDetailAreaTabControl.HEIGHT, 450); } /// /// Invoked when a new tab is selected. /// /// The tab that was selected. /// Whether the currently-selected mods should be considered. protected virtual void OnTabChanged(BeatmapDetailAreaTabItem tab, bool selectedMods) { switch (tab) { case BeatmapDetailAreaDetailTabItem _: Details.Show(); break; default: Details.Hide(); break; } } /// /// Creates the tabs to be displayed. /// /// The tabs. protected virtual BeatmapDetailAreaTabItem[] CreateTabItems() => new BeatmapDetailAreaTabItem[] { new BeatmapDetailAreaDetailTabItem(), }; } }