Skip to content

Commit

Permalink
Simplify colour logic for beatmap overlay filter rows
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Jun 28, 2024
1 parent 1668048 commit c1bec7a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@ public FeaturedArtistsTabItem()
[Resolved(canBeNull: true)]
private IDialogOverlay dialogOverlay { get; set; }

protected override Color4 GetStateColour() => colours.Orange1;

protected override void LoadComplete()
{
base.LoadComplete();

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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. 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;
Expand All @@ -24,7 +21,7 @@ public partial class BeatmapSearchMultipleSelectionFilterRow<T> : BeatmapSearchF
{
public new readonly BindableList<T> Current = new BindableList<T>();

private MultipleSelectionFilter filter;
private MultipleSelectionFilter filter = null!;

public BeatmapSearchMultipleSelectionFilterRow(LocalisableString header)
: base(header)
Expand All @@ -42,7 +39,6 @@ private void load()
/// <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>
Expand All @@ -69,7 +65,7 @@ protected override void LoadComplete()
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);
Expand Down Expand Up @@ -122,7 +118,7 @@ protected override void UpdateState()
{
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)
Expand Down
27 changes: 20 additions & 7 deletions osu.Game/Overlays/BeatmapListing/FilterTabItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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;
Expand All @@ -24,7 +25,7 @@ public partial class FilterTabItem<T> : TabItem<T>
[Resolved]
protected OverlayColourProvider ColourProvider { get; private set; }

private OsuSpriteText text;
protected OsuSpriteText Text;

protected Sample SelectSample { get; private set; } = null!;

Expand All @@ -39,7 +40,7 @@ private void load(AudioManager audio)
AutoSizeAxes = Axes.Both;
AddRangeInternal(new Drawable[]
{
text = new OsuSpriteText
Text = new OsuSpriteText
{
Font = OsuFont.GetFont(size: 13, weight: FontWeight.Regular),
Text = LabelFor(Value)
Expand Down Expand Up @@ -86,14 +87,26 @@ protected override void OnHoverLost(HoverLostEvent e)

protected virtual bool HighlightOnHoverWhenActive => false;

protected virtual void UpdateState()
protected virtual Color4 ColourActive => ColourProvider.Content1;
protected virtual Color4 ColourNormal => ColourProvider.Light2;

protected Color4 ColourForCurrentState
{
bool highlightHover = IsHovered && (!Active.Value || HighlightOnHoverWhenActive);
get
{
Color4 colour = Active.Value ? ColourActive : ColourNormal;

if (IsHovered && (!Active.Value || HighlightOnHoverWhenActive))
colour = colour.Lighten(0.2f);

text.FadeColour(highlightHover ? ColourProvider.Content2 : GetStateColour(), 200, Easing.OutQuint);
text.Font = text.Font.With(weight: Active.Value ? FontWeight.Bold : FontWeight.Regular);
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);
}
}
}

0 comments on commit c1bec7a

Please sign in to comment.