mirror of
https://github.com/ppy/osu.git
synced 2025-02-24 12:42:54 +08:00
Show count of beatmaps in collections in manage dialog
This commit is contained in:
parent
7c1ccefa4a
commit
63e0768207
@ -2,6 +2,7 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
@ -13,6 +14,7 @@ using osu.Framework.Input.Events;
|
|||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
@ -25,7 +27,7 @@ namespace osu.Game.Collections
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class DrawableCollectionListItem : OsuRearrangeableListItem<Live<BeatmapCollection>>
|
public partial class DrawableCollectionListItem : OsuRearrangeableListItem<Live<BeatmapCollection>>
|
||||||
{
|
{
|
||||||
private const float item_height = 35;
|
private const float item_height = 45;
|
||||||
private const float button_width = item_height * 0.75f;
|
private const float button_width = item_height * 0.75f;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -81,12 +83,10 @@ namespace osu.Game.Collections
|
|||||||
Padding = new MarginPadding { Right = collection.IsManaged ? button_width : 0 },
|
Padding = new MarginPadding { Right = collection.IsManaged ? button_width : 0 },
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
textBox = new ItemTextBox
|
textBox = new ItemTextBox(collection)
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.X,
|
||||||
Size = Vector2.One,
|
Height = item_height
|
||||||
CornerRadius = item_height / 2,
|
|
||||||
PlaceholderText = collection.IsManaged ? string.Empty : "Create a new collection"
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -117,11 +117,64 @@ namespace osu.Game.Collections
|
|||||||
{
|
{
|
||||||
protected override float LeftRightPadding => item_height / 2;
|
protected override float LeftRightPadding => item_height / 2;
|
||||||
|
|
||||||
|
private const float count_text_size = 12;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private RealmAccess realm { get; set; } = null!;
|
||||||
|
|
||||||
|
private readonly Live<BeatmapCollection> collection;
|
||||||
|
|
||||||
|
private OsuSpriteText countText = null!;
|
||||||
|
|
||||||
|
private IDisposable? itemCountSubscription;
|
||||||
|
|
||||||
|
public ItemTextBox(Live<BeatmapCollection> collection)
|
||||||
|
{
|
||||||
|
this.collection = collection;
|
||||||
|
|
||||||
|
CornerRadius = item_height / 2;
|
||||||
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours)
|
private void load(OsuColour colours)
|
||||||
{
|
{
|
||||||
BackgroundUnfocused = colours.GreySeaFoamDarker.Darken(0.5f);
|
BackgroundUnfocused = colours.GreySeaFoamDarker.Darken(0.5f);
|
||||||
BackgroundFocused = colours.GreySeaFoam;
|
BackgroundFocused = colours.GreySeaFoam;
|
||||||
|
|
||||||
|
if (collection.IsManaged)
|
||||||
|
{
|
||||||
|
TextContainer.Height *= (Height - count_text_size) / Height;
|
||||||
|
TextContainer.Margin = new MarginPadding { Bottom = count_text_size };
|
||||||
|
|
||||||
|
TextContainer.Add(countText = new OsuSpriteText
|
||||||
|
{
|
||||||
|
Anchor = Anchor.BottomLeft,
|
||||||
|
Origin = Anchor.TopLeft,
|
||||||
|
Depth = float.MinValue,
|
||||||
|
Font = OsuFont.Default.With(size: count_text_size, weight: FontWeight.SemiBold),
|
||||||
|
Margin = new MarginPadding { Top = 2, Left = 2 },
|
||||||
|
Colour = colours.Yellow
|
||||||
|
});
|
||||||
|
|
||||||
|
itemCountSubscription = realm.SubscribeToPropertyChanged<BeatmapCollection, IList<string>>(r => r.Find<BeatmapCollection>(collection.ID), c => c.BeatmapMD5Hashes, items =>
|
||||||
|
{
|
||||||
|
countText.Text = items.Count == 1
|
||||||
|
// Intentionally not localised until we have proper support for this (see https://github.com/ppy/osu-framework/pull/4918
|
||||||
|
// but also in this case we want support for formatting a number within a string).
|
||||||
|
? $"{items.Count:#,0} beatmap"
|
||||||
|
: $"{items.Count:#,0} beatmaps";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PlaceholderText = "Create a new collection";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool isDisposing)
|
||||||
|
{
|
||||||
|
base.Dispose(isDisposing);
|
||||||
|
itemCountSubscription?.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user