From 4011da033bba3c51cf591857f2fb14ad8c8e10d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sat, 23 Oct 2021 17:59:52 +0200 Subject: [PATCH] Split off thumbnail to separate component --- .../Beatmaps/Drawables/Cards/BeatmapCard.cs | 26 ++++----- .../Drawables/Cards/BeatmapCardThumbnail.cs | 54 +++++++++++++++++++ 2 files changed, 63 insertions(+), 17 deletions(-) create mode 100644 osu.Game/Beatmaps/Drawables/Cards/BeatmapCardThumbnail.cs diff --git a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs index e3af253db9..d52e8f6c20 100644 --- a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs +++ b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs @@ -23,7 +23,6 @@ using osu.Game.Overlays.BeatmapSet; using osuTK; using osu.Game.Overlays.BeatmapListing.Panels; using osu.Game.Resources.Localisation.Web; -using osuTK.Graphics; using DownloadButton = osu.Game.Beatmaps.Drawables.Cards.Buttons.DownloadButton; namespace osu.Game.Beatmaps.Drawables.Cards @@ -42,7 +41,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards private readonly BeatmapDownloadTracker downloadTracker; - private UpdateableOnlineBeatmapSetCover leftCover; + private BeatmapCardThumbnail thumbnail; private FillFlowContainer leftIconArea; private Container rightAreaBackground; @@ -98,24 +97,16 @@ namespace osu.Game.Beatmaps.Drawables.Cards Colour = Colour4.White }, }, - new Container + thumbnail = new BeatmapCardThumbnail(beatmapSet) { Name = @"Left (icon) area", Size = new Vector2(height), - Children = new Drawable[] + Child = leftIconArea = new FillFlowContainer { - leftCover = new UpdateableOnlineBeatmapSetCover(BeatmapSetCoverType.List) - { - RelativeSizeAxes = Axes.Both, - OnlineInfo = beatmapSet - }, - leftIconArea = new FillFlowContainer - { - Margin = new MarginPadding(5), - AutoSizeAxes = Axes.Both, - Direction = FillDirection.Horizontal, - Spacing = new Vector2(1) - } + Margin = new MarginPadding(5), + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Horizontal, + Spacing = new Vector2(1) } }, new Container @@ -395,10 +386,11 @@ namespace osu.Game.Beatmaps.Drawables.Cards if (IsHovered) targetWidth = targetWidth - icon_area_width + corner_radius; + thumbnail.Dimmed.Value = IsHovered; + mainContent.ResizeWidthTo(targetWidth, TRANSITION_DURATION, Easing.OutQuint); mainContentBackground.Dimmed.Value = IsHovered; - leftCover.FadeColour(IsHovered ? OsuColour.Gray(0.2f) : Color4.White, TRANSITION_DURATION, Easing.OutQuint); statisticsContainer.FadeTo(IsHovered ? 1 : 0, TRANSITION_DURATION, Easing.OutQuint); rightAreaBackground.FadeColour(downloadTracker.State.Value == DownloadState.LocallyAvailable ? colours.Lime0 : colourProvider.Background3, TRANSITION_DURATION, Easing.OutQuint); diff --git a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardThumbnail.cs b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardThumbnail.cs new file mode 100644 index 0000000000..b9304e744a --- /dev/null +++ b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardThumbnail.cs @@ -0,0 +1,54 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Bindables; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Game.Graphics; +using osu.Game.Online.API.Requests.Responses; +using osuTK.Graphics; + +namespace osu.Game.Beatmaps.Drawables.Cards +{ + public class BeatmapCardThumbnail : Container + { + public BindableBool Dimmed { get; } = new BindableBool(); + + private readonly APIBeatmapSet beatmapSetInfo; + + private readonly UpdateableOnlineBeatmapSetCover cover; + private readonly Container content; + + protected override Container Content => content; + + public BeatmapCardThumbnail(APIBeatmapSet beatmapSetInfo) + { + this.beatmapSetInfo = beatmapSetInfo; + + InternalChildren = new Drawable[] + { + cover = new UpdateableOnlineBeatmapSetCover(BeatmapSetCoverType.List) + { + RelativeSizeAxes = Axes.Both, + OnlineInfo = beatmapSetInfo + }, + content = new Container + { + RelativeSizeAxes = Axes.Both + } + }; + } + + protected override void LoadComplete() + { + base.LoadComplete(); + Dimmed.BindValueChanged(_ => updateState(), true); + FinishTransforms(true); + } + + private void updateState() + { + cover.FadeColour(Dimmed.Value ? OsuColour.Gray(0.2f) : Color4.White, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint); + } + } +}