Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add style options to dynamic skin elements #31100

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions osu.Game/Screens/Play/HUD/BPMCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@

using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Localisation.SkinComponents;
using osu.Game.Skinning;
using osuTK;

Expand All @@ -20,17 +23,26 @@ public partial class BPMCounter : RollingCounter<double>, ISerialisableDrawable
{
protected override double RollingDuration => 375;

[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.Font), nameof(SkinnableComponentStrings.FontDescription))]
public Bindable<Typeface> Font { get; } = new Bindable<Typeface>(Typeface.Venera);

[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.Colour), nameof(SkinnableComponentStrings.ColourDescription))]
public BindableColour4 TextColour { get; } = new BindableColour4(Color4Extensions.FromHex(@"ddffff"));

[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.ShowLabel), nameof(SkinnableComponentStrings.ShowLabelDescription))]
public Bindable<bool> ShowLabel { get; } = new BindableBool(true);

[Resolved]
private IBindable<WorkingBeatmap> beatmap { get; set; } = null!;

[Resolved]
private IGameplayClock gameplayClock { get; set; } = null!;

[BackgroundDependencyLoader]
private void load(OsuColour colour)
private void load()
{
Colour = colour.BlueLighter;
Current.Value = DisplayedCount = 0;
TextColour.BindValueChanged(c => Colour = TextColour.Value, true);
}

protected override void Update()
Expand All @@ -49,7 +61,11 @@ protected override LocalisableString FormatCount(double count)
return $@"{count:0}";
}

protected override IHasText CreateText() => new TextComponent();
protected override IHasText CreateText() => new TextComponent
{
ShowLabel = { BindTarget = ShowLabel },
Font = { BindTarget = Font },
};

private partial class TextComponent : CompositeDrawable, IHasText
{
Expand All @@ -59,7 +75,11 @@ public LocalisableString Text
set => text.Text = value;
}

public Bindable<bool> ShowLabel { get; } = new BindableBool();
public Bindable<Typeface> Font { get; } = new Bindable<Typeface>();

private readonly OsuSpriteText text;
private readonly OsuSpriteText label;

public TextComponent()
{
Expand All @@ -77,7 +97,7 @@ public TextComponent()
Origin = Anchor.BottomLeft,
Font = OsuFont.Numeric.With(size: 16, fixedWidth: true)
},
new OsuSpriteText
label = new OsuSpriteText
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Expand All @@ -88,6 +108,28 @@ public TextComponent()
}
};
}

protected override void LoadComplete()
{
base.LoadComplete();

ShowLabel.BindValueChanged(s =>
{
label.Alpha = s.NewValue ? 1 : 0;
}, true);

Font.BindValueChanged(typeface =>
{
// We only have bold weight for venera, so let's force that.
FontWeight fontWeight = typeface.NewValue == Typeface.Venera ? FontWeight.Bold : FontWeight.Regular;

FontUsage f = OsuFont.GetFont(typeface.NewValue, weight: fontWeight);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In master this particular piece of code is copied once. This PR adds four more copies. That's definitely past the threshold of "not sure if it's fine to copy this logic" - it's not.

This can probably go live in OsuFont itself. Compare:

if ((family == GetFamilyString(Typeface.Torus) || family == GetFamilyString(Typeface.TorusAlternate)) && weight == FontWeight.Medium)
// torus doesn't have a medium; fallback to regular.
weight = FontWeight.Regular;


// Fixed width looks better on venera only in my opinion.
text.Font = f.With(size: 16, fixedWidth: typeface.NewValue == Typeface.Venera);
label.Font = f.With(size: 8);
}, true);
}
}

public bool UsesFixedAnchor { get; set; }
Expand Down
65 changes: 55 additions & 10 deletions osu.Game/Screens/Play/HUD/ClicksPerSecond/ClicksPerSecondCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
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.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Localisation.SkinComponents;
using osu.Game.Skinning;
using osuTK;

Expand All @@ -19,19 +23,23 @@ public partial class ClicksPerSecondCounter : RollingCounter<int>, ISerialisable
[Resolved]
private ClicksPerSecondController controller { get; set; } = null!;

[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.Font), nameof(SkinnableComponentStrings.FontDescription))]
public Bindable<Typeface> Font { get; } = new Bindable<Typeface>(Typeface.Venera);

[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.Colour), nameof(SkinnableComponentStrings.ColourDescription))]
public BindableColour4 TextColour { get; } = new BindableColour4(Color4Extensions.FromHex(@"ddffff"));

[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.ShowLabel), nameof(SkinnableComponentStrings.ShowLabelDescription))]
public Bindable<bool> ShowLabel { get; } = new BindableBool(true);

protected override double RollingDuration => 175;

public bool UsesFixedAnchor { get; set; }

public ClicksPerSecondCounter()
{
Current.Value = 0;
}

[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Colour = colours.BlueLighter;
TextColour.BindValueChanged(c => Colour = TextColour.Value, true);
}

protected override void Update()
Expand All @@ -41,7 +49,11 @@ protected override void Update()
Current.Value = controller.Value;
}

protected override IHasText CreateText() => new TextComponent();
protected override IHasText CreateText() => new TextComponent
{
ShowLabel = { BindTarget = ShowLabel },
Font = { BindTarget = Font },
};

private partial class TextComponent : CompositeDrawable, IHasText
{
Expand All @@ -51,7 +63,14 @@ public LocalisableString Text
set => text.Text = value;
}

public Bindable<bool> ShowLabel { get; } = new BindableBool();
public Bindable<Typeface> Font { get; } = new Bindable<Typeface>();

private readonly FillFlowContainer labelContainer;

private readonly OsuSpriteText text;
private readonly OsuSpriteText clickLabel;
private readonly OsuSpriteText secLabel;

public TextComponent()
{
Expand All @@ -69,22 +88,22 @@ public TextComponent()
Origin = Anchor.BottomLeft,
Font = OsuFont.Numeric.With(size: 16, fixedWidth: true)
},
new FillFlowContainer
labelContainer = new FillFlowContainer
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Direction = FillDirection.Vertical,
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new OsuSpriteText
clickLabel = new OsuSpriteText
{
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
Font = OsuFont.Numeric.With(size: 6, fixedWidth: false),
Text = @"clicks",
},
new OsuSpriteText
secLabel = new OsuSpriteText
{
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
Expand All @@ -97,6 +116,32 @@ public TextComponent()
}
};
}

protected override void LoadComplete()
{
base.LoadComplete();

ShowLabel.BindValueChanged(s =>
{
labelContainer.Alpha = s.NewValue ? 1 : 0;
}, true);

Font.BindValueChanged(typeface =>
{
// We only have bold weight for venera, so let's force that.
FontWeight fontWeight = typeface.NewValue == Typeface.Venera ? FontWeight.Bold : FontWeight.Regular;

FontUsage f = OsuFont.GetFont(typeface.NewValue, weight: fontWeight);

// align baseline with fonts that aren't venera
secLabel.Padding = new MarginPadding { Bottom = typeface.NewValue == Typeface.Venera ? 3f : 2f };

// Fixed width looks better on venera only in my opinion.
text.Font = f.With(size: 16, fixedWidth: typeface.NewValue == Typeface.Venera);
clickLabel.Font = f.With(size: 6, fixedWidth: false);
secLabel.Font = f.With(size: 6, fixedWidth: false);
}, true);
}
}
}
}
62 changes: 56 additions & 6 deletions osu.Game/Screens/Play/HUD/LongestComboCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,44 @@
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
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.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Localisation.SkinComponents;
using osu.Game.Rulesets.Scoring;
using osuTK;

namespace osu.Game.Screens.Play.HUD
{
public partial class LongestComboCounter : ComboCounter
{
[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.Font), nameof(SkinnableComponentStrings.FontDescription))]
public Bindable<Typeface> Font { get; } = new Bindable<Typeface>(Typeface.Venera);

[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.Colour), nameof(SkinnableComponentStrings.ColourDescription))]
public BindableColour4 TextColour { get; } = new BindableColour4(Color4Extensions.FromHex(@"ffffdd"));

[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.ShowLabel), nameof(SkinnableComponentStrings.ShowLabelDescription))]
public Bindable<bool> ShowLabel { get; } = new BindableBool(true);

[BackgroundDependencyLoader]
private void load(OsuColour colours, ScoreProcessor scoreProcessor)
private void load(ScoreProcessor scoreProcessor)
{
Colour = colours.YellowLighter;
TextColour.BindValueChanged(c => Colour = TextColour.Value, true);
Current.BindTo(scoreProcessor.HighestCombo);
}

protected override IHasText CreateText() => new TextComponent();
protected override IHasText CreateText() => new TextComponent
{
ShowLabel = { BindTarget = ShowLabel },
Font = { BindTarget = Font },
};

private partial class TextComponent : CompositeDrawable, IHasText
{
Expand All @@ -32,7 +49,14 @@ public LocalisableString Text
set => text.Text = $"{value}x";
}

public Bindable<bool> ShowLabel { get; } = new BindableBool();
public Bindable<Typeface> Font { get; } = new Bindable<Typeface>();

private readonly FillFlowContainer labelContainer;

private readonly OsuSpriteText text;
private readonly OsuSpriteText longestLabel;
private readonly OsuSpriteText comboLabel;

public TextComponent()
{
Expand All @@ -50,22 +74,22 @@ public TextComponent()
Origin = Anchor.BottomLeft,
Font = OsuFont.Numeric.With(size: 20)
},
new FillFlowContainer
labelContainer = new FillFlowContainer
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Direction = FillDirection.Vertical,
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new OsuSpriteText
longestLabel = new OsuSpriteText
{
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
Font = OsuFont.Numeric.With(size: 8),
Text = @"longest",
},
new OsuSpriteText
comboLabel = new OsuSpriteText
{
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
Expand All @@ -78,6 +102,32 @@ public TextComponent()
}
};
}

protected override void LoadComplete()
{
base.LoadComplete();

ShowLabel.BindValueChanged(s =>
{
labelContainer.Alpha = s.NewValue ? 1 : 0;
}, true);

Font.BindValueChanged(typeface =>
{
// We only have bold weight for venera, so let's force that.
FontWeight fontWeight = typeface.NewValue == Typeface.Venera ? FontWeight.Bold : FontWeight.Regular;

FontUsage f = OsuFont.GetFont(typeface.NewValue, weight: fontWeight);

// align baseline with fonts that aren't venera
comboLabel.Padding = new MarginPadding { Bottom = typeface.NewValue == Typeface.Venera ? 3f : 1f };

// Fixed width looks better on venera only in my opinion.
text.Font = f.With(size: 16, fixedWidth: typeface.NewValue == Typeface.Venera);
longestLabel.Font = f.With(size: 6, fixedWidth: false);
comboLabel.Font = f.With(size: 6, fixedWidth: false);
}, true);
}
}
}
}
Loading