1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-07 16:47:24 +08:00

Merge pull request #22797 from ItsShamed/hud/player-components

Add score player avatar and flag to HUD
This commit is contained in:
Bartłomiej Dach 2023-03-07 20:21:04 +01:00 committed by GitHub
commit 70ce5ada7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 132 additions and 17 deletions

View File

@ -48,7 +48,9 @@ namespace osu.Game.Tests.Skins
// Covers BPM counter.
"Archives/modified-default-20221205.osk",
// Covers judgement counter.
"Archives/modified-default-20230117.osk"
"Archives/modified-default-20230117.osk",
// Covers player avatar and flag.
"Archives/modified-argon-20230305.osk",
};
/// <summary>

View File

@ -39,6 +39,16 @@ namespace osu.Game.Localisation.SkinComponents
/// </summary>
public static LocalisableString TextElementTextDescription => new TranslatableString(getKey(@"text_element_text_description"), "The text to be displayed.");
/// <summary>
/// "Corner radius"
/// </summary>
public static LocalisableString CornerRadius => new TranslatableString(getKey(@"corner_radius"), "Corner radius");
/// <summary>
/// "How rounded the corners should be."
/// </summary>
public static LocalisableString CornerRadiusDescription => new TranslatableString(getKey(@"corner_radius_description"), "How rounded the corners should be.");
private static string getKey(string key) => $"{prefix}:{key}";
}
}

View File

@ -0,0 +1,20 @@
// 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 osu.Framework.Graphics;
using osu.Game.Configuration;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Overlays.Settings
{
/// <summary>
/// A <see cref="SettingsSlider{TValue,TSlider}"/> that displays its value as a percentage by default.
/// Mostly provided for convenience of use with <see cref="SettingSourceAttribute"/>.
/// </summary>
public partial class SettingsPercentageSlider<TValue> : SettingsSlider<TValue>
where TValue : struct, IEquatable<TValue>, IComparable<TValue>, IConvertible
{
protected override Drawable CreateControl() => ((RoundedSliderBar<TValue>)base.CreateControl()).With(sliderBar => sliderBar.DisplayAsPercentage = true);
}
}

View File

@ -7,7 +7,6 @@ using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Localisation;
using osu.Game.Configuration;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Settings;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.Judgements;
@ -33,7 +32,7 @@ namespace osu.Game.Rulesets.Mods
public override string SettingDescription => base.SettingDescription.Replace(MinimumAccuracy.ToString(), MinimumAccuracy.Value.ToString("##%", NumberFormatInfo.InvariantInfo));
[SettingSource("Minimum accuracy", "Trigger a failure if your accuracy goes below this value.", SettingControlType = typeof(SettingsSlider<double, PercentSlider>))]
[SettingSource("Minimum accuracy", "Trigger a failure if your accuracy goes below this value.", SettingControlType = typeof(SettingsPercentageSlider<double>))]
public BindableNumber<double> MinimumAccuracy { get; } = new BindableDouble
{
MinValue = 0.60,
@ -69,12 +68,4 @@ namespace osu.Game.Rulesets.Mods
return scoreProcessor.ComputeAccuracy(score);
}
}
public partial class PercentSlider : RoundedSliderBar<double>
{
public PercentSlider()
{
DisplayAsPercentage = true;
}
}
}

View File

@ -0,0 +1,58 @@
// 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.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Configuration;
using osu.Game.Localisation.SkinComponents;
using osu.Game.Overlays.Settings;
using osu.Game.Skinning;
using osu.Game.Users.Drawables;
using osuTK;
namespace osu.Game.Screens.Play.HUD
{
public partial class PlayerAvatar : CompositeDrawable, ISerialisableDrawable
{
[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.CornerRadius), nameof(SkinnableComponentStrings.CornerRadiusDescription),
SettingControlType = typeof(SettingsPercentageSlider<float>))]
public new BindableFloat CornerRadius { get; set; } = new BindableFloat(0.25f)
{
MinValue = 0,
MaxValue = 0.5f,
Precision = 0.01f
};
private readonly UpdateableAvatar avatar;
private const float default_size = 80f;
public PlayerAvatar()
{
Size = new Vector2(default_size);
InternalChild = avatar = new UpdateableAvatar(isInteractive: false)
{
RelativeSizeAxes = Axes.Both,
Masking = true
};
}
[BackgroundDependencyLoader]
private void load(GameplayState gameplayState)
{
avatar.User = gameplayState.Score.ScoreInfo.User;
}
protected override void LoadComplete()
{
base.LoadComplete();
CornerRadius.BindValueChanged(e => avatar.CornerRadius = e.NewValue * default_size, true);
}
public bool UsesFixedAnchor { get; set; }
}
}

View File

@ -0,0 +1,36 @@
// 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.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Skinning;
using osu.Game.Users.Drawables;
using osuTK;
namespace osu.Game.Screens.Play.HUD
{
public partial class PlayerFlag : CompositeDrawable, ISerialisableDrawable
{
private readonly UpdateableFlag flag;
private const float default_size = 40f;
public PlayerFlag()
{
Size = new Vector2(default_size, default_size / 1.4f);
InternalChild = flag = new UpdateableFlag
{
RelativeSizeAxes = Axes.Both,
};
}
[BackgroundDependencyLoader]
private void load(GameplayState gameplayState)
{
flag.CountryCode = gameplayState.Score.ScoreInfo.User.CountryCode;
}
public bool UsesFixedAnchor { get; set; }
}
}

View File

@ -1,8 +1,6 @@
// 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.
#nullable disable
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
@ -30,14 +28,14 @@ namespace osu.Game.Users.Drawables
/// Perform an action in addition to showing the country ranking.
/// This should be used to perform auxiliary tasks and not as a primary action for clicking a flag (to maintain a consistent UX).
/// </summary>
public Action Action;
public Action? Action;
public UpdateableFlag(CountryCode countryCode = CountryCode.Unknown)
{
CountryCode = countryCode;
}
protected override Drawable CreateDrawable(CountryCode countryCode)
protected override Drawable? CreateDrawable(CountryCode countryCode)
{
if (countryCode == CountryCode.Unknown && !ShowPlaceholderOnUnknown)
return null;
@ -56,8 +54,8 @@ namespace osu.Game.Users.Drawables
};
}
[Resolved(canBeNull: true)]
private RankingsOverlay rankingsOverlay { get; set; }
[Resolved]
private RankingsOverlay? rankingsOverlay { get; set; }
protected override bool OnClick(ClickEvent e)
{