1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-12 13:13:22 +08:00

Merge pull request #5823 from iiSaLMaN/implement-grouped-difficulty-icons

Implement grouped difficulty icons

Co-authored-by: Dean Herbert <pe@ppy.sh>
This commit is contained in:
Dean Herbert 2019-08-25 12:19:16 +09:00 committed by GitHub
commit 7fd63b39fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 128 additions and 18 deletions

View File

@ -9,7 +9,6 @@ using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Overlays.Direct; using osu.Game.Overlays.Direct;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
using osu.Game.Users; using osu.Game.Users;
using osuTK; using osuTK;
@ -24,7 +23,7 @@ namespace osu.Game.Tests.Visual.Online
typeof(IconPill) typeof(IconPill)
}; };
private BeatmapSetInfo getUndownloadableBeatmapSet(RulesetInfo ruleset) => new BeatmapSetInfo private BeatmapSetInfo getUndownloadableBeatmapSet() => new BeatmapSetInfo
{ {
OnlineBeatmapSetID = 123, OnlineBeatmapSetID = 123,
Metadata = new BeatmapMetadata Metadata = new BeatmapMetadata
@ -56,23 +55,62 @@ namespace osu.Game.Tests.Visual.Online
{ {
new BeatmapInfo new BeatmapInfo
{ {
Ruleset = ruleset, Ruleset = Ruleset.Value,
Version = "Test", Version = "Test",
StarDifficulty = 6.42, StarDifficulty = 6.42,
} }
} }
}; };
[BackgroundDependencyLoader] private BeatmapSetInfo getManyDifficultiesBeatmapSet(RulesetStore rulesets)
private void load()
{ {
var ruleset = new OsuRuleset().RulesetInfo; var beatmaps = new List<BeatmapInfo>();
var normal = CreateWorkingBeatmap(ruleset).BeatmapSetInfo; for (int i = 0; i < 100; i++)
{
beatmaps.Add(new BeatmapInfo
{
Ruleset = rulesets.GetRuleset(i % 4),
StarDifficulty = 2 + i % 4 * 2,
BaseDifficulty = new BeatmapDifficulty
{
OverallDifficulty = 3.5f,
}
});
}
return new BeatmapSetInfo
{
OnlineBeatmapSetID = 1,
Metadata = new BeatmapMetadata
{
Title = "many difficulties beatmap",
Artist = "test",
Author = new User
{
Username = "BanchoBot",
Id = 3,
}
},
OnlineInfo = new BeatmapSetOnlineInfo
{
HasVideo = true,
HasStoryboard = true,
Covers = new BeatmapSetOnlineCovers(),
},
Beatmaps = beatmaps,
};
}
[BackgroundDependencyLoader]
private void load(RulesetStore rulesets)
{
var normal = CreateWorkingBeatmap(Ruleset.Value).BeatmapSetInfo;
normal.OnlineInfo.HasVideo = true; normal.OnlineInfo.HasVideo = true;
normal.OnlineInfo.HasStoryboard = true; normal.OnlineInfo.HasStoryboard = true;
var undownloadable = getUndownloadableBeatmapSet(ruleset); var undownloadable = getUndownloadableBeatmapSet();
var manyDifficulties = getManyDifficultiesBeatmapSet(rulesets);
Child = new BasicScrollContainer Child = new BasicScrollContainer
{ {
@ -81,15 +119,17 @@ namespace osu.Game.Tests.Visual.Online
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical, Direction = FillDirection.Full,
Padding = new MarginPadding(20), Padding = new MarginPadding(20),
Spacing = new Vector2(0, 20), Spacing = new Vector2(5, 20),
Children = new Drawable[] Children = new Drawable[]
{ {
new DirectGridPanel(normal), new DirectGridPanel(normal),
new DirectListPanel(normal),
new DirectGridPanel(undownloadable), new DirectGridPanel(undownloadable),
new DirectGridPanel(manyDifficulties),
new DirectListPanel(normal),
new DirectListPanel(undownloadable), new DirectListPanel(undownloadable),
new DirectListPanel(manyDifficulties),
}, },
}, },
}; };

View File

@ -516,6 +516,7 @@ namespace osu.Game.Tests.Visual.SongSelect
OnlineBeatmapID = b * 10, OnlineBeatmapID = b * 10,
Path = $"extra{b}.osu", Path = $"extra{b}.osu",
Version = $"Extra {b}", Version = $"Extra {b}",
Ruleset = rulesets.GetRuleset((b - 1) % 4),
StarDifficulty = 2, StarDifficulty = 2,
BaseDifficulty = new BeatmapDifficulty BaseDifficulty = new BeatmapDifficulty
{ {

View File

@ -0,0 +1,37 @@
// 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.
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Graphics;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets;
using osuTK.Graphics;
namespace osu.Game.Beatmaps.Drawables
{
/// <summary>
/// A difficulty icon that contains a counter on the right-side of it.
/// </summary>
/// <remarks>
/// Used in cases when there are too many difficulty icons to show.
/// </remarks>
public class GroupedDifficultyIcon : DifficultyIcon
{
public GroupedDifficultyIcon(List<BeatmapInfo> beatmaps, RulesetInfo ruleset, Color4 counterColour)
: base(beatmaps.OrderBy(b => b.StarDifficulty).Last(), ruleset, false)
{
AddInternal(new OsuSpriteText
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Padding = new MarginPadding { Left = Size.X },
Margin = new MarginPadding { Left = 2, Right = 5 },
Font = OsuFont.GetFont(size: 14, weight: FontWeight.SemiBold),
Text = beatmaps.Count.ToString(),
Colour = counterColour,
});
}
}
}

View File

@ -151,7 +151,7 @@ namespace osu.Game.Overlays.Direct
AutoSizeAxes = Axes.X, AutoSizeAxes = Axes.X,
Height = 20, Height = 20,
Margin = new MarginPadding { Top = vertical_padding, Bottom = vertical_padding }, Margin = new MarginPadding { Top = vertical_padding, Bottom = vertical_padding },
Children = GetDifficultyIcons(), Children = GetDifficultyIcons(colours),
}, },
}, },
}, },

View File

@ -129,7 +129,7 @@ namespace osu.Game.Overlays.Direct
AutoSizeAxes = Axes.X, AutoSizeAxes = Axes.X,
Height = 20, Height = 20,
Margin = new MarginPadding { Top = vertical_padding, Bottom = vertical_padding }, Margin = new MarginPadding { Top = vertical_padding, Bottom = vertical_padding },
Children = GetDifficultyIcons(), Children = GetDifficultyIcons(colours),
}, },
}, },
}, },

View File

@ -28,6 +28,7 @@ namespace osu.Game.Overlays.Direct
public readonly BeatmapSetInfo SetInfo; public readonly BeatmapSetInfo SetInfo;
private const double hover_transition_time = 400; private const double hover_transition_time = 400;
private const int maximum_difficulty_icons = 15;
private Container content; private Container content;
@ -138,12 +139,18 @@ namespace osu.Game.Overlays.Direct
}; };
} }
protected List<DifficultyIcon> GetDifficultyIcons() protected List<DifficultyIcon> GetDifficultyIcons(OsuColour colours)
{ {
var icons = new List<DifficultyIcon>(); var icons = new List<DifficultyIcon>();
foreach (var b in SetInfo.Beatmaps.OrderBy(beatmap => beatmap.StarDifficulty)) if (SetInfo.Beatmaps.Count > maximum_difficulty_icons)
icons.Add(new DifficultyIcon(b)); {
foreach (var ruleset in SetInfo.Beatmaps.Select(b => b.Ruleset).Distinct())
icons.Add(new GroupedDifficultyIcon(SetInfo.Beatmaps.FindAll(b => b.Ruleset.Equals(ruleset)), ruleset, this is DirectListPanel ? Color4.White : colours.Gray5));
}
else
foreach (var b in SetInfo.Beatmaps.OrderBy(beatmap => beatmap.StarDifficulty))
icons.Add(new DifficultyIcon(b));
return icons; return icons;
} }

View File

@ -19,6 +19,7 @@ using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Rulesets;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -95,11 +96,11 @@ namespace osu.Game.Screens.Select.Carousel
TextPadding = new MarginPadding { Horizontal = 8, Vertical = 2 }, TextPadding = new MarginPadding { Horizontal = 8, Vertical = 2 },
Status = beatmapSet.Status Status = beatmapSet.Status
}, },
new FillFlowContainer<FilterableDifficultyIcon> new FillFlowContainer<DifficultyIcon>
{ {
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Spacing = new Vector2(3), Spacing = new Vector2(3),
Children = ((CarouselBeatmapSet)Item).Beatmaps.Select(b => new FilterableDifficultyIcon(b)).ToList() ChildrenEnumerable = getDifficultyIcons(),
}, },
} }
} }
@ -108,6 +109,17 @@ namespace osu.Game.Screens.Select.Carousel
}; };
} }
private const int maximum_difficulty_icons = 18;
private IEnumerable<DifficultyIcon> getDifficultyIcons()
{
var beatmaps = ((CarouselBeatmapSet)Item).Beatmaps.ToList();
return beatmaps.Count > maximum_difficulty_icons
? (IEnumerable<DifficultyIcon>)beatmaps.GroupBy(b => b.Beatmap.Ruleset).Select(group => new FilterableGroupedDifficultyIcon(group.ToList(), group.Key))
: beatmaps.Select(b => new FilterableDifficultyIcon(b));
}
public MenuItem[] ContextMenuItems public MenuItem[] ContextMenuItems
{ {
get get
@ -205,5 +217,18 @@ namespace osu.Game.Screens.Select.Carousel
filtered.TriggerChange(); filtered.TriggerChange();
} }
} }
public class FilterableGroupedDifficultyIcon : GroupedDifficultyIcon
{
public FilterableGroupedDifficultyIcon(List<CarouselBeatmap> items, RulesetInfo ruleset)
: base(items.Select(i => i.Beatmap).ToList(), ruleset, Color4.White)
{
items.ForEach(item => item.Filtered.ValueChanged += _ =>
{
// for now, fade the whole group based on the ratio of hidden items.
this.FadeTo(1 - 0.9f * ((float)items.Count(i => i.Filtered.Value) / items.Count), 100);
});
}
}
} }
} }