mirror of
https://github.com/osukey/osukey.git
synced 2025-05-17 11:37:32 +09:00
Merge pull request #22241 from stanriders/refactor-levelbadge
Refactor `LevelBadge` to use `LevelInfo`
This commit is contained in:
commit
0c5a436754
@ -6,6 +6,7 @@ using osu.Framework.Bindables;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
using osu.Game.Overlays.Profile.Header.Components;
|
using osu.Game.Overlays.Profile.Header.Components;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
@ -15,6 +16,8 @@ namespace osu.Game.Overlays.Profile.Header
|
|||||||
{
|
{
|
||||||
public readonly Bindable<UserProfileData?> User = new Bindable<UserProfileData?>();
|
public readonly Bindable<UserProfileData?> User = new Bindable<UserProfileData?>();
|
||||||
|
|
||||||
|
private LevelBadge levelBadge = null!;
|
||||||
|
|
||||||
public CentreHeaderContainer()
|
public CentreHeaderContainer()
|
||||||
{
|
{
|
||||||
Height = 60;
|
Height = 60;
|
||||||
@ -62,12 +65,11 @@ namespace osu.Game.Overlays.Profile.Header
|
|||||||
Margin = new MarginPadding { Right = UserProfileOverlay.CONTENT_X_MARGIN },
|
Margin = new MarginPadding { Right = UserProfileOverlay.CONTENT_X_MARGIN },
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new LevelBadge
|
levelBadge = new LevelBadge
|
||||||
{
|
{
|
||||||
Anchor = Anchor.CentreRight,
|
Anchor = Anchor.CentreRight,
|
||||||
Origin = Anchor.CentreRight,
|
Origin = Anchor.CentreRight,
|
||||||
Size = new Vector2(40),
|
Size = new Vector2(40)
|
||||||
User = { BindTarget = User }
|
|
||||||
},
|
},
|
||||||
new Container
|
new Container
|
||||||
{
|
{
|
||||||
@ -86,5 +88,17 @@ namespace osu.Game.Overlays.Profile.Header
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
|
User.BindValueChanged(user => updateDisplay(user.NewValue?.User), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateDisplay(APIUser? user)
|
||||||
|
{
|
||||||
|
levelBadge.LevelInfo.Value = user?.Statistics?.Level;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,14 +11,14 @@ using osu.Framework.Graphics.Textures;
|
|||||||
using osu.Framework.Localisation;
|
using osu.Framework.Localisation;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
|
||||||
using osu.Game.Resources.Localisation.Web;
|
using osu.Game.Resources.Localisation.Web;
|
||||||
|
using osu.Game.Users;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Profile.Header.Components
|
namespace osu.Game.Overlays.Profile.Header.Components
|
||||||
{
|
{
|
||||||
public partial class LevelBadge : CompositeDrawable, IHasTooltip
|
public partial class LevelBadge : CompositeDrawable, IHasTooltip
|
||||||
{
|
{
|
||||||
public readonly Bindable<UserProfileData?> User = new Bindable<UserProfileData?>();
|
public readonly Bindable<UserStatistics.LevelInfo?> LevelInfo = new Bindable<UserStatistics.LevelInfo?>();
|
||||||
|
|
||||||
public LocalisableString TooltipText { get; private set; }
|
public LocalisableString TooltipText { get; private set; }
|
||||||
|
|
||||||
@ -47,13 +47,18 @@ namespace osu.Game.Overlays.Profile.Header.Components
|
|||||||
Font = OsuFont.GetFont(size: 20)
|
Font = OsuFont.GetFont(size: 20)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
User.BindValueChanged(user => updateLevel(user.NewValue?.User));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateLevel(APIUser? user)
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
string level = user?.Statistics?.Level.Current.ToString() ?? "0";
|
base.LoadComplete();
|
||||||
|
|
||||||
|
LevelInfo.BindValueChanged(level => updateLevel(level.NewValue), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateLevel(UserStatistics.LevelInfo? levelInfo)
|
||||||
|
{
|
||||||
|
string level = levelInfo?.Current.ToString() ?? "0";
|
||||||
levelText.Text = level;
|
levelText.Text = level;
|
||||||
TooltipText = UsersStrings.ShowStatsLevel(level);
|
TooltipText = UsersStrings.ShowStatsLevel(level);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user