1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-19 03:42:55 +08:00

Simplify colour logic for beatmap overlay filter rows

This commit is contained in:
Dean Herbert 2024-06-28 14:55:55 +09:00
parent 1668048fb7
commit c1bec7a7c3
No known key found for this signature in database
3 changed files with 27 additions and 17 deletions

View File

@ -56,8 +56,6 @@ namespace osu.Game.Overlays.BeatmapListing
[Resolved(canBeNull: true)]
private IDialogOverlay dialogOverlay { get; set; }
protected override Color4 GetStateColour() => colours.Orange1;
protected override void LoadComplete()
{
base.LoadComplete();
@ -65,6 +63,9 @@ namespace osu.Game.Overlays.BeatmapListing
disclaimerShown = sessionStatics.GetBindable<bool>(Static.FeaturedArtistDisclaimerShownOnce);
}
protected override Color4 ColourNormal => colours.Orange1;
protected override Color4 ColourActive => colours.Orange2;
protected override bool OnClick(ClickEvent e)
{
if (!disclaimerShown.Value && dialogOverlay != null)

View File

@ -1,13 +1,10 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
#nullable disable
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@ -24,7 +21,7 @@ namespace osu.Game.Overlays.BeatmapListing
{
public new readonly BindableList<T> Current = new BindableList<T>();
private MultipleSelectionFilter filter;
private MultipleSelectionFilter filter = null!;
public BeatmapSearchMultipleSelectionFilterRow(LocalisableString header)
: base(header)
@ -42,7 +39,6 @@ namespace osu.Game.Overlays.BeatmapListing
/// <summary>
/// Creates a filter control that can be used to simultaneously select multiple values of type <typeparamref name="T"/>.
/// </summary>
[NotNull]
protected virtual MultipleSelectionFilter CreateMultipleSelectionFilter() => new MultipleSelectionFilter();
protected partial class MultipleSelectionFilter : FillFlowContainer<MultipleSelectionFilterTabItem>
@ -69,7 +65,7 @@ namespace osu.Game.Overlays.BeatmapListing
Current.BindCollectionChanged(currentChanged, true);
}
private void currentChanged(object sender, NotifyCollectionChangedEventArgs e)
private void currentChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
foreach (var c in Children)
c.Active.Value = Current.Contains(c.Value);
@ -122,7 +118,7 @@ namespace osu.Game.Overlays.BeatmapListing
{
base.UpdateState();
selectedUnderline.FadeTo(Active.Value ? 1 : 0, 200, Easing.OutQuint);
selectedUnderline.FadeColour(IsHovered ? ColourProvider.Content2 : GetStateColour(), 200, Easing.OutQuint);
selectedUnderline.FadeColour(ColourForCurrentState, 200, Easing.OutQuint);
}
protected override bool OnClick(ClickEvent e)

View File

@ -8,6 +8,7 @@ using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Extensions;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
@ -24,7 +25,7 @@ namespace osu.Game.Overlays.BeatmapListing
[Resolved]
protected OverlayColourProvider ColourProvider { get; private set; }
private OsuSpriteText text;
protected OsuSpriteText Text;
protected Sample SelectSample { get; private set; } = null!;
@ -39,7 +40,7 @@ namespace osu.Game.Overlays.BeatmapListing
AutoSizeAxes = Axes.Both;
AddRangeInternal(new Drawable[]
{
text = new OsuSpriteText
Text = new OsuSpriteText
{
Font = OsuFont.GetFont(size: 13, weight: FontWeight.Regular),
Text = LabelFor(Value)
@ -86,14 +87,26 @@ namespace osu.Game.Overlays.BeatmapListing
protected virtual bool HighlightOnHoverWhenActive => false;
protected virtual void UpdateState()
{
bool highlightHover = IsHovered && (!Active.Value || HighlightOnHoverWhenActive);
protected virtual Color4 ColourActive => ColourProvider.Content1;
protected virtual Color4 ColourNormal => ColourProvider.Light2;
text.FadeColour(highlightHover ? ColourProvider.Content2 : GetStateColour(), 200, Easing.OutQuint);
text.Font = text.Font.With(weight: Active.Value ? FontWeight.Bold : FontWeight.Regular);
protected Color4 ColourForCurrentState
{
get
{
Color4 colour = Active.Value ? ColourActive : ColourNormal;
if (IsHovered && (!Active.Value || HighlightOnHoverWhenActive))
colour = colour.Lighten(0.2f);
return colour;
}
}
protected virtual Color4 GetStateColour() => Active.Value ? ColourProvider.Content1 : ColourProvider.Light2;
protected virtual void UpdateState()
{
Text.FadeColour(ColourForCurrentState, 200, Easing.OutQuint);
Text.Font = Text.Font.With(weight: Active.Value ? FontWeight.Bold : FontWeight.Regular);
}
}
}