mirror of
https://github.com/ppy/osu.git
synced 2024-11-07 21:27:51 +08:00
Merge pull request #22797 from ItsShamed/hud/player-components
Add score player avatar and flag to HUD
This commit is contained in:
commit
70ce5ada7a
BIN
osu.Game.Tests/Resources/Archives/modified-argon-20230305.osk
Normal file
BIN
osu.Game.Tests/Resources/Archives/modified-argon-20230305.osk
Normal file
Binary file not shown.
@ -48,7 +48,9 @@ namespace osu.Game.Tests.Skins
|
|||||||
// Covers BPM counter.
|
// Covers BPM counter.
|
||||||
"Archives/modified-default-20221205.osk",
|
"Archives/modified-default-20221205.osk",
|
||||||
// Covers judgement counter.
|
// Covers judgement counter.
|
||||||
"Archives/modified-default-20230117.osk"
|
"Archives/modified-default-20230117.osk",
|
||||||
|
// Covers player avatar and flag.
|
||||||
|
"Archives/modified-argon-20230305.osk",
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -39,6 +39,16 @@ namespace osu.Game.Localisation.SkinComponents
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static LocalisableString TextElementTextDescription => new TranslatableString(getKey(@"text_element_text_description"), "The text to be displayed.");
|
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}";
|
private static string getKey(string key) => $"{prefix}:{key}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
20
osu.Game/Overlays/Settings/SettingsPercentageSlider.cs
Normal file
20
osu.Game/Overlays/Settings/SettingsPercentageSlider.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
@ -7,7 +7,6 @@ using System.Linq;
|
|||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Localisation;
|
using osu.Framework.Localisation;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Graphics.UserInterface;
|
|
||||||
using osu.Game.Overlays.Settings;
|
using osu.Game.Overlays.Settings;
|
||||||
using osu.Game.Rulesets.Scoring;
|
using osu.Game.Rulesets.Scoring;
|
||||||
using osu.Game.Rulesets.Judgements;
|
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));
|
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
|
public BindableNumber<double> MinimumAccuracy { get; } = new BindableDouble
|
||||||
{
|
{
|
||||||
MinValue = 0.60,
|
MinValue = 0.60,
|
||||||
@ -69,12 +68,4 @@ namespace osu.Game.Rulesets.Mods
|
|||||||
return scoreProcessor.ComputeAccuracy(score);
|
return scoreProcessor.ComputeAccuracy(score);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial class PercentSlider : RoundedSliderBar<double>
|
|
||||||
{
|
|
||||||
public PercentSlider()
|
|
||||||
{
|
|
||||||
DisplayAsPercentage = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
58
osu.Game/Screens/Play/HUD/PlayerAvatar.cs
Normal file
58
osu.Game/Screens/Play/HUD/PlayerAvatar.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
36
osu.Game/Screens/Play/HUD/PlayerFlag.cs
Normal file
36
osu.Game/Screens/Play/HUD/PlayerFlag.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +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.
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
@ -30,14 +28,14 @@ namespace osu.Game.Users.Drawables
|
|||||||
/// Perform an action in addition to showing the country ranking.
|
/// 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).
|
/// This should be used to perform auxiliary tasks and not as a primary action for clicking a flag (to maintain a consistent UX).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Action Action;
|
public Action? Action;
|
||||||
|
|
||||||
public UpdateableFlag(CountryCode countryCode = CountryCode.Unknown)
|
public UpdateableFlag(CountryCode countryCode = CountryCode.Unknown)
|
||||||
{
|
{
|
||||||
CountryCode = countryCode;
|
CountryCode = countryCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Drawable CreateDrawable(CountryCode countryCode)
|
protected override Drawable? CreateDrawable(CountryCode countryCode)
|
||||||
{
|
{
|
||||||
if (countryCode == CountryCode.Unknown && !ShowPlaceholderOnUnknown)
|
if (countryCode == CountryCode.Unknown && !ShowPlaceholderOnUnknown)
|
||||||
return null;
|
return null;
|
||||||
@ -56,8 +54,8 @@ namespace osu.Game.Users.Drawables
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[Resolved(canBeNull: true)]
|
[Resolved]
|
||||||
private RankingsOverlay rankingsOverlay { get; set; }
|
private RankingsOverlay? rankingsOverlay { get; set; }
|
||||||
|
|
||||||
protected override bool OnClick(ClickEvent e)
|
protected override bool OnClick(ClickEvent e)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user