Move scores counter logic to a better place

This commit is contained in:
Andrei Zavatski 2020-09-08 00:04:14 +03:00
parent f88b2509f8
commit 1bc41bcfd7
2 changed files with 16 additions and 15 deletions

View File

@ -1,7 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Users; using osu.Game.Users;
@ -13,7 +12,7 @@ namespace osu.Game.Overlays.Profile.Sections
private readonly string headerText; private readonly string headerText;
private readonly CounterVisibilityState counterVisibilityState; private readonly CounterVisibilityState counterVisibilityState;
private PaginatedContainerHeader header; protected PaginatedContainerHeader Header;
protected PaginatedContainerWithHeader(Bindable<User> user, string headerText, CounterVisibilityState counterVisibilityState, string missing = "") protected PaginatedContainerWithHeader(Bindable<User> user, string headerText, CounterVisibilityState counterVisibilityState, string missing = "")
: base(user, missing) : base(user, missing)
@ -22,23 +21,12 @@ namespace osu.Game.Overlays.Profile.Sections
this.counterVisibilityState = counterVisibilityState; this.counterVisibilityState = counterVisibilityState;
} }
protected override Drawable CreateHeaderContent => header = new PaginatedContainerHeader(headerText, counterVisibilityState); protected override Drawable CreateHeaderContent => Header = new PaginatedContainerHeader(headerText, counterVisibilityState);
protected override void OnUserChanged(User user) protected override void OnUserChanged(User user)
{ {
base.OnUserChanged(user); base.OnUserChanged(user);
header.Current.Value = GetCount(user); Header.Current.Value = GetCount(user);
}
protected override void OnItemsReceived(List<TModel> items)
{
base.OnItemsReceived(items);
if (counterVisibilityState == CounterVisibilityState.VisibleWhenZero)
{
header.Current.Value = items.Count;
header.Current.TriggerChange();
}
} }
protected virtual int GetCount(User user) => 0; protected virtual int GetCount(User user) => 0;

View File

@ -44,6 +44,19 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
} }
} }
protected override void OnItemsReceived(List<APILegacyScoreInfo> items)
{
base.OnItemsReceived(items);
if (type == ScoreType.Recent)
{
var count = items.Count;
Header.Current.Value = count == 0 ? 0 : -1;
Header.Current.TriggerChange();
}
}
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);