mirror of
https://github.com/ppy/osu.git
synced 2024-11-13 18:07:25 +08:00
Merge pull request #7242 from EVAST9919/profile-counter-pills
Implement counter pills for UserOverlay
This commit is contained in:
commit
394c1274ee
42
osu.Game.Tests/Visual/Online/TestSceneProfileCounterPill.cs
Normal file
42
osu.Game.Tests/Visual/Online/TestSceneProfileCounterPill.cs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// 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;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Game.Overlays.Profile.Sections;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.Online
|
||||||
|
{
|
||||||
|
public class TestSceneProfileCounterPill : OsuTestScene
|
||||||
|
{
|
||||||
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||||
|
{
|
||||||
|
typeof(CounterPill)
|
||||||
|
};
|
||||||
|
|
||||||
|
private readonly CounterPill pill;
|
||||||
|
private readonly BindableInt value = new BindableInt();
|
||||||
|
|
||||||
|
public TestSceneProfileCounterPill()
|
||||||
|
{
|
||||||
|
Child = pill = new CounterPill
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Current = { BindTarget = value }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestVisibility()
|
||||||
|
{
|
||||||
|
AddStep("Set value to 0", () => value.Value = 0);
|
||||||
|
AddAssert("Check hidden", () => !pill.IsPresent);
|
||||||
|
AddStep("Set value to 10", () => value.Value = 10);
|
||||||
|
AddAssert("Check visible", () => pill.IsPresent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -38,5 +38,15 @@ namespace osu.Game.Overlays.Profile.Sections.Beatmaps
|
|||||||
Anchor = Anchor.TopCentre,
|
Anchor = Anchor.TopCentre,
|
||||||
Origin = Anchor.TopCentre,
|
Origin = Anchor.TopCentre,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
protected override int GetCount(User user) => type switch
|
||||||
|
{
|
||||||
|
BeatmapSetType.Favourite => user.FavouriteBeatmapsetCount,
|
||||||
|
BeatmapSetType.Graveyard => user.GraveyardBeatmapsetCount,
|
||||||
|
BeatmapSetType.Loved => user.LovedBeatmapsetCount,
|
||||||
|
BeatmapSetType.RankedAndApproved => user.RankedAndApprovedBeatmapsetCount,
|
||||||
|
BeatmapSetType.Unranked => user.UnrankedBeatmapsetCount,
|
||||||
|
_ => 0
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
61
osu.Game/Overlays/Profile/Sections/CounterPill.cs
Normal file
61
osu.Game/Overlays/Profile/Sections/CounterPill.cs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
// 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 osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Shapes;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Profile.Sections
|
||||||
|
{
|
||||||
|
public class CounterPill : CircularContainer
|
||||||
|
{
|
||||||
|
private const int duration = 200;
|
||||||
|
|
||||||
|
public readonly BindableInt Current = new BindableInt();
|
||||||
|
|
||||||
|
private readonly OsuSpriteText counter;
|
||||||
|
|
||||||
|
public CounterPill()
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Both;
|
||||||
|
Alpha = 0;
|
||||||
|
Masking = true;
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new Box
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Colour = OsuColour.Gray(0.05f)
|
||||||
|
},
|
||||||
|
counter = new OsuSpriteText
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Margin = new MarginPadding { Horizontal = 10, Vertical = 5 },
|
||||||
|
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
Current.BindValueChanged(onCurrentChanged, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onCurrentChanged(ValueChangedEvent<int> value)
|
||||||
|
{
|
||||||
|
if (value.NewValue == 0)
|
||||||
|
{
|
||||||
|
this.FadeOut(duration, Easing.OutQuint);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
counter.Text = value.NewValue.ToString();
|
||||||
|
this.FadeIn(duration, Easing.OutQuint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -23,6 +23,7 @@ namespace osu.Game.Overlays.Profile.Sections
|
|||||||
private readonly OsuSpriteText missingText;
|
private readonly OsuSpriteText missingText;
|
||||||
private APIRequest<List<TModel>> retrievalRequest;
|
private APIRequest<List<TModel>> retrievalRequest;
|
||||||
private CancellationTokenSource loadCancellation;
|
private CancellationTokenSource loadCancellation;
|
||||||
|
private readonly BindableInt count = new BindableInt();
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private IAPIProvider api { get; set; }
|
private IAPIProvider api { get; set; }
|
||||||
@ -44,11 +45,28 @@ namespace osu.Game.Overlays.Profile.Sections
|
|||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new OsuSpriteText
|
new FillFlowContainer
|
||||||
{
|
{
|
||||||
Text = header,
|
AutoSizeAxes = Axes.Both,
|
||||||
Font = OsuFont.GetFont(size: 20, weight: FontWeight.Bold),
|
Direction = FillDirection.Horizontal,
|
||||||
|
Spacing = new Vector2(5, 0),
|
||||||
Margin = new MarginPadding { Top = 10, Bottom = 10 },
|
Margin = new MarginPadding { Top = 10, Bottom = 10 },
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new OsuSpriteText
|
||||||
|
{
|
||||||
|
Anchor = Anchor.CentreLeft,
|
||||||
|
Origin = Anchor.CentreLeft,
|
||||||
|
Text = header,
|
||||||
|
Font = OsuFont.GetFont(size: 20, weight: FontWeight.Bold),
|
||||||
|
},
|
||||||
|
new CounterPill
|
||||||
|
{
|
||||||
|
Anchor = Anchor.CentreLeft,
|
||||||
|
Origin = Anchor.CentreLeft,
|
||||||
|
Current = { BindTarget = count }
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
ItemsContainer = new FillFlowContainer
|
ItemsContainer = new FillFlowContainer
|
||||||
{
|
{
|
||||||
@ -91,7 +109,10 @@ namespace osu.Game.Overlays.Profile.Sections
|
|||||||
ItemsContainer.Clear();
|
ItemsContainer.Clear();
|
||||||
|
|
||||||
if (e.NewValue != null)
|
if (e.NewValue != null)
|
||||||
|
{
|
||||||
showMore();
|
showMore();
|
||||||
|
count.Value = GetCount(e.NewValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showMore()
|
private void showMore()
|
||||||
@ -124,6 +145,8 @@ namespace osu.Game.Overlays.Profile.Sections
|
|||||||
}, loadCancellation.Token);
|
}, loadCancellation.Token);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
protected virtual int GetCount(User user) => 0;
|
||||||
|
|
||||||
protected abstract APIRequest<List<TModel>> CreateRequest();
|
protected abstract APIRequest<List<TModel>> CreateRequest();
|
||||||
|
|
||||||
protected abstract Drawable CreateDrawableItem(TModel model);
|
protected abstract Drawable CreateDrawableItem(TModel model);
|
||||||
|
@ -32,6 +32,12 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
|
|||||||
protected override APIRequest<List<APILegacyScoreInfo>> CreateRequest() =>
|
protected override APIRequest<List<APILegacyScoreInfo>> CreateRequest() =>
|
||||||
new GetUserScoresRequest(User.Value.Id, type, VisiblePages++, ItemsPerPage);
|
new GetUserScoresRequest(User.Value.Id, type, VisiblePages++, ItemsPerPage);
|
||||||
|
|
||||||
|
protected override int GetCount(User user) => type switch
|
||||||
|
{
|
||||||
|
ScoreType.Firsts => user.ScoresFirstCount,
|
||||||
|
_ => 0
|
||||||
|
};
|
||||||
|
|
||||||
protected override Drawable CreateDrawableItem(APILegacyScoreInfo model)
|
protected override Drawable CreateDrawableItem(APILegacyScoreInfo model)
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
|
@ -126,6 +126,24 @@ namespace osu.Game.Users
|
|||||||
[JsonProperty(@"follower_count")]
|
[JsonProperty(@"follower_count")]
|
||||||
public int FollowerCount;
|
public int FollowerCount;
|
||||||
|
|
||||||
|
[JsonProperty(@"favourite_beatmapset_count")]
|
||||||
|
public int FavouriteBeatmapsetCount;
|
||||||
|
|
||||||
|
[JsonProperty(@"graveyard_beatmapset_count")]
|
||||||
|
public int GraveyardBeatmapsetCount;
|
||||||
|
|
||||||
|
[JsonProperty(@"loved_beatmapset_count")]
|
||||||
|
public int LovedBeatmapsetCount;
|
||||||
|
|
||||||
|
[JsonProperty(@"ranked_and_approved_beatmapset_count")]
|
||||||
|
public int RankedAndApprovedBeatmapsetCount;
|
||||||
|
|
||||||
|
[JsonProperty(@"unranked_beatmapset_count")]
|
||||||
|
public int UnrankedBeatmapsetCount;
|
||||||
|
|
||||||
|
[JsonProperty(@"scores_first_count")]
|
||||||
|
public int ScoresFirstCount;
|
||||||
|
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
private string[] playstyle
|
private string[] playstyle
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user