1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 04:47:24 +08:00

Split argon score sprite text and update combo counter design

This commit is contained in:
Salman Ahmed 2023-11-07 01:59:00 +03:00
parent 7c1c62ba8a
commit 0dbba13686
3 changed files with 167 additions and 111 deletions

View File

@ -2,28 +2,36 @@
// 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.Sprites;
using osu.Framework.Localisation;
using osu.Game.Graphics.Sprites;
using osu.Game.Configuration;
using osu.Game.Rulesets.Scoring;
namespace osu.Game.Screens.Play.HUD
{
public partial class ArgonComboCounter : ComboCounter
{
[SettingSource("Wireframe opacity", "Controls the opacity of the wire frames behind the digits.")]
public BindableFloat WireframeOpacity { get; } = new BindableFloat(0.4f)
{
Precision = 0.01f,
MinValue = 0,
MaxValue = 1,
};
[BackgroundDependencyLoader]
private void load(ScoreProcessor scoreProcessor)
{
Current.BindTo(scoreProcessor.Combo);
}
protected override OsuSpriteText CreateSpriteText()
=> base.CreateSpriteText().With(s => s.Font = FontUsage.Default.With(size: 36f));
protected override LocalisableString FormatCount(int count) => $@"{count}x";
protected override LocalisableString FormatCount(int count)
protected override IHasText CreateText() => new ArgonCounterTextComponent(Anchor.TopLeft, "COMBO")
{
return $@"{count}x";
}
WireframeOpacity = { BindTarget = WireframeOpacity },
};
}
}

View File

@ -0,0 +1,152 @@
// 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 LocalisableString? label;
private readonly ArgonCounterSpriteText wireframesPart;
private readonly ArgonCounterSpriteText textPart;
public IBindable<int> RequiredDisplayDigits { get; } = new BindableInt();
public IBindable<float> WireframeOpacity { get; } = new BindableFloat();
public LocalisableString Text
{
get => textPart.Text;
set
{
wireframesPart.Text = new string('#', Math.Max(value.ToString().Count(char.IsDigit), RequiredDisplayDigits.Value));
textPart.Text = value;
}
}
public ArgonCounterTextComponent(Anchor anchor, LocalisableString? label = null)
{
Anchor = anchor;
Origin = anchor;
this.label = label;
wireframesPart = new ArgonCounterSpriteText(@"wireframes")
{
Anchor = anchor,
Origin = anchor,
};
textPart = new ArgonCounterSpriteText
{
Anchor = anchor,
Origin = anchor,
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
AutoSizeAxes = Axes.Both;
InternalChild = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new OsuSpriteText
{
Alpha = label != null ? 1 : 0,
Text = label.GetValueOrDefault(),
Font = OsuFont.Torus.With(size: 12, weight: FontWeight.Bold),
Colour = colours.Blue0,
Margin = new MarginPadding { Left = 2.5f },
},
new Container
{
AutoSizeAxes = Axes.Both,
Children = new[]
{
wireframesPart,
textPart,
}
}
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
WireframeOpacity.BindValueChanged(v => wireframesPart.Alpha = v.NewValue, true);
}
private partial class ArgonCounterSpriteText : OsuSpriteText
{
private readonly string? glyphLookupOverride;
private GlyphStore glyphStore = null!;
protected override char FixedWidthReferenceCharacter => '5';
public ArgonCounterSpriteText(string? glyphLookupOverride = null)
{
this.glyphLookupOverride = glyphLookupOverride;
Shadow = false;
UseFullGlyphHeight = false;
}
[BackgroundDependencyLoader]
private void load(ISkinSource skin)
{
// todo: rename font
Font = new FontUsage(@"argon-score", 1, fixedWidth: true);
Spacing = new Vector2(-2, 0);
glyphStore = new GlyphStore(skin, glyphLookupOverride);
}
protected override TextBuilder CreateTextBuilder(ITexturedGlyphLookupStore store) => base.CreateTextBuilder(glyphStore);
private class GlyphStore : ITexturedGlyphLookupStore
{
private readonly ISkin skin;
private readonly string? glyphLookupOverride;
public GlyphStore(ISkin skin, string? glyphLookupOverride)
{
this.skin = skin;
this.glyphLookupOverride = glyphLookupOverride;
}
public ITexturedCharacterGlyph? Get(string fontName, char character)
{
string lookup = glyphLookupOverride ?? character.ToString();
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));
}
}
}
}

View File

@ -1,20 +1,13 @@
// 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.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.LocalisationExtensions;
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.Configuration;
using osu.Game.Graphics.Sprites;
using osu.Game.Skinning;
using osuTK;
namespace osu.Game.Screens.Play.HUD
{
@ -32,107 +25,10 @@ namespace osu.Game.Screens.Play.HUD
protected override LocalisableString FormatCount(long count) => count.ToLocalisableString();
protected override IHasText CreateText() => new ArgonScoreTextComponent
protected override IHasText CreateText() => new ArgonCounterTextComponent(Anchor.TopRight)
{
RequiredDisplayDigits = { BindTarget = RequiredDisplayDigits },
WireframeOpacity = { BindTarget = WireframeOpacity },
};
private partial class ArgonScoreTextComponent : CompositeDrawable, IHasText
{
private readonly ArgonScoreSpriteText wireframesPart;
private readonly ArgonScoreSpriteText textPart;
public IBindable<int> RequiredDisplayDigits { get; } = new BindableInt();
public IBindable<float> WireframeOpacity { get; } = new BindableFloat();
public LocalisableString Text
{
get => textPart.Text;
set
{
wireframesPart.Text = new string('#', Math.Max(value.ToString().Length, RequiredDisplayDigits.Value));
textPart.Text = value;
}
}
public ArgonScoreTextComponent()
{
AutoSizeAxes = Axes.Both;
InternalChildren = new[]
{
wireframesPart = new ArgonScoreSpriteText(@"wireframes")
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
},
textPart = new ArgonScoreSpriteText
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
},
};
}
protected override void LoadComplete()
{
base.LoadComplete();
WireframeOpacity.BindValueChanged(v => wireframesPart.Alpha = v.NewValue, true);
}
private partial class ArgonScoreSpriteText : OsuSpriteText
{
private readonly string? glyphLookupOverride;
private GlyphStore glyphStore = null!;
protected override char FixedWidthReferenceCharacter => '5';
public ArgonScoreSpriteText(string? glyphLookupOverride = null)
{
this.glyphLookupOverride = glyphLookupOverride;
Shadow = false;
UseFullGlyphHeight = false;
}
[BackgroundDependencyLoader]
private void load(ISkinSource skin)
{
Font = new FontUsage(@"argon-score", 1, fixedWidth: true);
Spacing = new Vector2(-2, 0);
glyphStore = new GlyphStore(skin, glyphLookupOverride);
}
protected override TextBuilder CreateTextBuilder(ITexturedGlyphLookupStore store) => base.CreateTextBuilder(glyphStore);
private class GlyphStore : ITexturedGlyphLookupStore
{
private readonly ISkin skin;
private readonly string? glyphLookupOverride;
public GlyphStore(ISkin skin, string? glyphLookupOverride)
{
this.skin = skin;
this.glyphLookupOverride = glyphLookupOverride;
}
public ITexturedCharacterGlyph? Get(string fontName, char character)
{
string lookup = glyphLookupOverride ?? character.ToString();
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));
}
}
}
}
}