-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25226 from frenzibyte/gameplay-hud-redesign/counters
- Loading branch information
Showing
16 changed files
with
555 additions
and
54 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// 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.Bindables; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Containers; | ||
using osu.Framework.Graphics.Sprites; | ||
using osu.Framework.Localisation; | ||
using osu.Game.Configuration; | ||
using osu.Game.Skinning; | ||
using osuTK; | ||
|
||
namespace osu.Game.Screens.Play.HUD | ||
{ | ||
public partial class ArgonAccuracyCounter : GameplayAccuracyCounter, ISerialisableDrawable | ||
{ | ||
protected override double RollingDuration => 500; | ||
protected override Easing RollingEasing => Easing.OutQuint; | ||
|
||
[SettingSource("Wireframe opacity", "Controls the opacity of the wire frames behind the digits.")] | ||
public BindableFloat WireframeOpacity { get; } = new BindableFloat(0.25f) | ||
{ | ||
Precision = 0.01f, | ||
MinValue = 0, | ||
MaxValue = 1, | ||
}; | ||
|
||
public bool UsesFixedAnchor { get; set; } | ||
|
||
protected override IHasText CreateText() => new ArgonAccuracyTextComponent | ||
{ | ||
WireframeOpacity = { BindTarget = WireframeOpacity }, | ||
}; | ||
|
||
private partial class ArgonAccuracyTextComponent : CompositeDrawable, IHasText | ||
{ | ||
private readonly ArgonCounterTextComponent wholePart; | ||
private readonly ArgonCounterTextComponent fractionPart; | ||
|
||
public IBindable<float> WireframeOpacity { get; } = new BindableFloat(); | ||
|
||
public LocalisableString Text | ||
{ | ||
get => wholePart.Text; | ||
set | ||
{ | ||
string[] split = value.ToString().Replace("%", string.Empty).Split("."); | ||
|
||
wholePart.Text = split[0]; | ||
fractionPart.Text = "." + split[1]; | ||
} | ||
} | ||
|
||
public ArgonAccuracyTextComponent() | ||
{ | ||
AutoSizeAxes = Axes.Both; | ||
|
||
InternalChild = new FillFlowContainer | ||
{ | ||
AutoSizeAxes = Axes.Both, | ||
Direction = FillDirection.Horizontal, | ||
Children = new Drawable[] | ||
{ | ||
new Container | ||
{ | ||
AutoSizeAxes = Axes.Both, | ||
Child = wholePart = new ArgonCounterTextComponent(Anchor.TopRight, "ACCURACY") | ||
{ | ||
RequiredDisplayDigits = { Value = 3 }, | ||
WireframeOpacity = { BindTarget = WireframeOpacity } | ||
} | ||
}, | ||
fractionPart = new ArgonCounterTextComponent(Anchor.TopLeft) | ||
{ | ||
Margin = new MarginPadding { Top = 12f * 2f + 4f }, // +4 to account for the extra spaces above the digits. | ||
WireframeOpacity = { BindTarget = WireframeOpacity }, | ||
Scale = new Vector2(0.5f), | ||
}, | ||
new ArgonCounterTextComponent(Anchor.TopLeft) | ||
{ | ||
Text = @"%", | ||
Margin = new MarginPadding { Top = 12f }, | ||
WireframeOpacity = { BindTarget = WireframeOpacity } | ||
}, | ||
} | ||
}; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 System; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Sprites; | ||
using osu.Framework.Localisation; | ||
using osu.Game.Configuration; | ||
using osu.Game.Rulesets.Scoring; | ||
using osuTK; | ||
using osuTK.Graphics; | ||
|
||
namespace osu.Game.Screens.Play.HUD | ||
{ | ||
public partial class ArgonComboCounter : ComboCounter | ||
{ | ||
private ArgonCounterTextComponent text = null!; | ||
|
||
protected override double RollingDuration => 500; | ||
protected override Easing RollingEasing => Easing.OutQuint; | ||
|
||
[SettingSource("Wireframe opacity", "Controls the opacity of the wire frames behind the digits.")] | ||
public BindableFloat WireframeOpacity { get; } = new BindableFloat(0.25f) | ||
{ | ||
Precision = 0.01f, | ||
MinValue = 0, | ||
MaxValue = 1, | ||
}; | ||
|
||
[BackgroundDependencyLoader] | ||
private void load(ScoreProcessor scoreProcessor) | ||
{ | ||
Current.BindTo(scoreProcessor.Combo); | ||
Current.BindValueChanged(combo => | ||
{ | ||
bool wasIncrease = combo.NewValue > combo.OldValue; | ||
bool wasMiss = combo.OldValue > 1 && combo.NewValue == 0; | ||
float newScale = Math.Clamp(text.NumberContainer.Scale.X * (wasIncrease ? 1.1f : 0.8f), 0.6f, 1.4f); | ||
float duration = wasMiss ? 2000 : 500; | ||
text.NumberContainer | ||
.ScaleTo(new Vector2(newScale)) | ||
.ScaleTo(Vector2.One, duration, Easing.OutQuint); | ||
if (wasMiss) | ||
text.FlashColour(Color4.Red, duration, Easing.OutQuint); | ||
}); | ||
} | ||
|
||
protected override LocalisableString FormatCount(int count) => $@"{count}x"; | ||
|
||
protected override IHasText CreateText() => text = new ArgonCounterTextComponent(Anchor.TopLeft, "COMBO") | ||
{ | ||
WireframeOpacity = { BindTarget = WireframeOpacity }, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
// 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.Linq; | ||
using System.Threading.Tasks; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Containers; | ||
using osu.Framework.Graphics.Sprites; | ||
using osu.Framework.Localisation; | ||
using osu.Framework.Text; | ||
using osu.Game.Graphics; | ||
using osu.Game.Graphics.Sprites; | ||
using osu.Game.Skinning; | ||
using osuTK; | ||
|
||
namespace osu.Game.Screens.Play.HUD | ||
{ | ||
public partial class ArgonCounterTextComponent : CompositeDrawable, IHasText | ||
{ | ||
private readonly ArgonCounterSpriteText wireframesPart; | ||
private readonly ArgonCounterSpriteText textPart; | ||
private readonly OsuSpriteText labelText; | ||
|
||
public IBindable<float> WireframeOpacity { get; } = new BindableFloat(); | ||
public Bindable<int> RequiredDisplayDigits { get; } = new BindableInt(); | ||
|
||
public Container NumberContainer { get; private set; } | ||
|
||
public LocalisableString Text | ||
{ | ||
get => textPart.Text; | ||
set | ||
{ | ||
int remainingCount = RequiredDisplayDigits.Value - value.ToString().Count(char.IsDigit); | ||
string remainingText = remainingCount > 0 ? new string('#', remainingCount) : string.Empty; | ||
|
||
wireframesPart.Text = remainingText + value; | ||
textPart.Text = value; | ||
} | ||
} | ||
|
||
public ArgonCounterTextComponent(Anchor anchor, LocalisableString? label = null) | ||
{ | ||
Anchor = anchor; | ||
Origin = anchor; | ||
AutoSizeAxes = Axes.Both; | ||
|
||
InternalChild = new FillFlowContainer | ||
{ | ||
AutoSizeAxes = Axes.Both, | ||
Direction = FillDirection.Vertical, | ||
Children = new Drawable[] | ||
{ | ||
labelText = new OsuSpriteText | ||
{ | ||
Alpha = label != null ? 1 : 0, | ||
Text = label.GetValueOrDefault(), | ||
Font = OsuFont.Torus.With(size: 12, weight: FontWeight.Bold), | ||
Margin = new MarginPadding { Left = 2.5f }, | ||
}, | ||
NumberContainer = new Container | ||
{ | ||
AutoSizeAxes = Axes.Both, | ||
Children = new[] | ||
{ | ||
wireframesPart = new ArgonCounterSpriteText(wireframesLookup) | ||
{ | ||
Anchor = anchor, | ||
Origin = anchor, | ||
}, | ||
textPart = new ArgonCounterSpriteText(textLookup) | ||
{ | ||
Anchor = anchor, | ||
Origin = anchor, | ||
}, | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
private string textLookup(char c) | ||
{ | ||
switch (c) | ||
{ | ||
case '.': | ||
return @"dot"; | ||
|
||
case '%': | ||
return @"percentage"; | ||
|
||
default: | ||
return c.ToString(); | ||
} | ||
} | ||
|
||
private string wireframesLookup(char c) | ||
{ | ||
if (c == '.') return @"dot"; | ||
|
||
return @"wireframes"; | ||
} | ||
|
||
[BackgroundDependencyLoader] | ||
private void load(OsuColour colours) | ||
{ | ||
labelText.Colour = colours.Blue0; | ||
} | ||
|
||
protected override void LoadComplete() | ||
{ | ||
base.LoadComplete(); | ||
WireframeOpacity.BindValueChanged(v => wireframesPart.Alpha = v.NewValue, true); | ||
} | ||
|
||
private partial class ArgonCounterSpriteText : OsuSpriteText | ||
{ | ||
private readonly Func<char, string> getLookup; | ||
|
||
private GlyphStore glyphStore = null!; | ||
|
||
protected override char FixedWidthReferenceCharacter => '5'; | ||
|
||
public ArgonCounterSpriteText(Func<char, string> getLookup) | ||
{ | ||
this.getLookup = getLookup; | ||
|
||
Shadow = false; | ||
UseFullGlyphHeight = false; | ||
} | ||
|
||
[BackgroundDependencyLoader] | ||
private void load(ISkinSource skin) | ||
{ | ||
Spacing = new Vector2(-2f, 0f); | ||
Font = new FontUsage(@"argon-counter", 1); | ||
glyphStore = new GlyphStore(skin, getLookup); | ||
} | ||
|
||
protected override TextBuilder CreateTextBuilder(ITexturedGlyphLookupStore store) => base.CreateTextBuilder(glyphStore); | ||
|
||
private class GlyphStore : ITexturedGlyphLookupStore | ||
{ | ||
private readonly ISkin skin; | ||
private readonly Func<char, string> getLookup; | ||
|
||
public GlyphStore(ISkin skin, Func<char, string> getLookup) | ||
{ | ||
this.skin = skin; | ||
this.getLookup = getLookup; | ||
} | ||
|
||
public ITexturedCharacterGlyph? Get(string fontName, char character) | ||
{ | ||
string lookup = getLookup(character); | ||
var texture = skin.GetTexture($"{fontName}-{lookup}"); | ||
|
||
if (texture == null) | ||
return null; | ||
|
||
return new TexturedCharacterGlyph(new CharacterGlyph(character, 0, 0, texture.Width, texture.Height, null), texture, 0.125f); | ||
} | ||
|
||
public Task<ITexturedCharacterGlyph?> GetAsync(string fontName, char character) => Task.Run(() => Get(fontName, character)); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.