1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:17:51 +08:00

Transform score multiplier display to also show ranked state

This commit is contained in:
Bartłomiej Dach 2024-01-31 15:50:43 +01:00
parent f89923aeae
commit 966093f7ce
No known key found for this signature in database
5 changed files with 105 additions and 55 deletions

View File

@ -119,7 +119,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddAssert("mod multiplier correct", () =>
{
double multiplier = SelectedMods.Value.Aggregate(1d, (m, mod) => m * mod.ScoreMultiplier);
return Precision.AlmostEquals(multiplier, modSelectOverlay.ChildrenOfType<ScoreMultiplierDisplay>().Single().Current.Value);
return Precision.AlmostEquals(multiplier, modSelectOverlay.ChildrenOfType<RankingInformationDisplay>().Single().ModMultiplier.Value);
});
assertCustomisationToggleState(disabled: false, active: false);
AddAssert("setting items created", () => modSelectOverlay.ChildrenOfType<ISettingsItem>().Any());
@ -134,7 +134,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddAssert("mod multiplier correct", () =>
{
double multiplier = SelectedMods.Value.Aggregate(1d, (m, mod) => m * mod.ScoreMultiplier);
return Precision.AlmostEquals(multiplier, modSelectOverlay.ChildrenOfType<ScoreMultiplierDisplay>().Single().Current.Value);
return Precision.AlmostEquals(multiplier, modSelectOverlay.ChildrenOfType<RankingInformationDisplay>().Single().ModMultiplier.Value);
});
assertCustomisationToggleState(disabled: false, active: false);
AddAssert("setting items created", () => modSelectOverlay.ChildrenOfType<ISettingsItem>().Any());
@ -846,7 +846,7 @@ namespace osu.Game.Tests.Visual.UserInterface
InputManager.Click(MouseButton.Left);
});
AddAssert("difficulty multiplier display shows correct value",
() => modSelectOverlay.ChildrenOfType<ScoreMultiplierDisplay>().Single().Current.Value, () => Is.EqualTo(0.1).Within(Precision.DOUBLE_EPSILON));
() => modSelectOverlay.ChildrenOfType<RankingInformationDisplay>().Single().ModMultiplier.Value, () => Is.EqualTo(0.1).Within(Precision.DOUBLE_EPSILON));
// this is highly unorthodox in a test, but because the `ModSettingChangeTracker` machinery heavily leans on events and object disposal and re-creation,
// it is instrumental in the reproduction of the failure scenario that this test is supposed to cover.
@ -856,7 +856,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddStep("reset half time speed to default", () => modSelectOverlay.ChildrenOfType<ModSettingsArea>().Single()
.ChildrenOfType<RevertToDefaultButton<double>>().Single().TriggerClick());
AddUntilStep("difficulty multiplier display shows correct value",
() => modSelectOverlay.ChildrenOfType<ScoreMultiplierDisplay>().Single().Current.Value, () => Is.EqualTo(0.3).Within(Precision.DOUBLE_EPSILON));
() => modSelectOverlay.ChildrenOfType<RankingInformationDisplay>().Single().ModMultiplier.Value, () => Is.EqualTo(0.3).Within(Precision.DOUBLE_EPSILON));
}
private void waitForColumnLoad() => AddUntilStep("all column content loaded", () =>

View File

@ -11,7 +11,7 @@ using osu.Game.Overlays.Mods;
namespace osu.Game.Tests.Visual.UserInterface
{
[TestFixture]
public partial class TestSceneScoreMultiplierDisplay : OsuTestScene
public partial class TestSceneRankingInformationDisplay : OsuTestScene
{
[Cached]
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Green);
@ -19,22 +19,24 @@ namespace osu.Game.Tests.Visual.UserInterface
[Test]
public void TestBasic()
{
ScoreMultiplierDisplay multiplierDisplay = null!;
RankingInformationDisplay onlinePropertiesDisplay = null!;
AddStep("create content", () => Child = multiplierDisplay = new ScoreMultiplierDisplay
AddStep("create content", () => Child = onlinePropertiesDisplay = new RankingInformationDisplay
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre
});
AddStep("set multiplier below 1", () => multiplierDisplay.Current.Value = 0.5);
AddStep("set multiplier to 1", () => multiplierDisplay.Current.Value = 1);
AddStep("set multiplier above 1", () => multiplierDisplay.Current.Value = 1.5);
AddToggleStep("toggle ranked", ranked => onlinePropertiesDisplay.Ranked.Value = ranked);
AddStep("set multiplier below 1", () => onlinePropertiesDisplay.ModMultiplier.Value = 0.5);
AddStep("set multiplier to 1", () => onlinePropertiesDisplay.ModMultiplier.Value = 1);
AddStep("set multiplier above 1", () => onlinePropertiesDisplay.ModMultiplier.Value = 1.5);
AddSliderStep("set multiplier", 0, 2, 1d, multiplier =>
{
if (multiplierDisplay.IsNotNull())
multiplierDisplay.Current.Value = multiplier;
if (onlinePropertiesDisplay.IsNotNull())
onlinePropertiesDisplay.ModMultiplier.Value = multiplier;
});
}
}

View File

@ -49,6 +49,26 @@ namespace osu.Game.Localisation
/// </summary>
public static LocalisableString ScoreMultiplier => new TranslatableString(getKey(@"score_multiplier"), @"Score Multiplier");
/// <summary>
/// "Ranked"
/// </summary>
public static LocalisableString Ranked => new TranslatableString(getKey(@"ranked"), @"Ranked");
/// <summary>
/// "Performance points can be granted for the active mods."
/// </summary>
public static LocalisableString RankedExplanation => new TranslatableString(getKey(@"ranked_explanation"), @"Performance points can be granted for the active mods.");
/// <summary>
/// "Unranked"
/// </summary>
public static LocalisableString Unranked => new TranslatableString(getKey(@"unranked"), @"Unranked");
/// <summary>
/// "Performance points will not be granted due to active mods."
/// </summary>
public static LocalisableString UnrankedExplanation => new TranslatableString(getKey(@"ranked_explanation"), @"Performance points will not be granted due to active mods.");
private static string getKey(string key) => $@"{prefix}:{key}";
}
}

View File

@ -125,7 +125,7 @@ namespace osu.Game.Overlays.Mods
private DeselectAllModsButton deselectAllModsButton = null!;
private Container aboveColumnsContent = null!;
private ScoreMultiplierDisplay? multiplierDisplay;
private RankingInformationDisplay? rankingInformationDisplay;
private BeatmapAttributesDisplay? beatmapAttributesDisplay;
protected ShearedButton BackButton { get; private set; } = null!;
@ -185,7 +185,7 @@ namespace osu.Game.Overlays.Mods
aboveColumnsContent = new Container
{
RelativeSizeAxes = Axes.X,
Height = ScoreMultiplierDisplay.HEIGHT,
Height = RankingInformationDisplay.HEIGHT,
Padding = new MarginPadding { Horizontal = 100 },
Child = SearchTextBox = new ShearedSearchTextBox
{
@ -200,7 +200,7 @@ namespace osu.Game.Overlays.Mods
{
Padding = new MarginPadding
{
Top = ScoreMultiplierDisplay.HEIGHT + PADDING,
Top = RankingInformationDisplay.HEIGHT + PADDING,
Bottom = PADDING
},
RelativeSizeAxes = Axes.Both,
@ -269,7 +269,7 @@ namespace osu.Game.Overlays.Mods
},
Children = new Drawable[]
{
multiplierDisplay = new ScoreMultiplierDisplay
rankingInformationDisplay = new RankingInformationDisplay
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight
@ -315,7 +315,7 @@ namespace osu.Game.Overlays.Mods
SelectedMods.BindValueChanged(_ =>
{
updateMultiplier();
updateRankingInformation();
updateFromExternalSelection();
updateCustomisation();
@ -328,7 +328,7 @@ namespace osu.Game.Overlays.Mods
//
// See https://github.com/ppy/osu/pull/23284#issuecomment-1529056988
modSettingChangeTracker = new ModSettingChangeTracker(SelectedMods.Value);
modSettingChangeTracker.SettingChanged += _ => updateMultiplier();
modSettingChangeTracker.SettingChanged += _ => updateRankingInformation();
}
}, true);
@ -450,9 +450,9 @@ namespace osu.Game.Overlays.Mods
modState.ValidForSelection.Value = modState.Mod.Type != ModType.System && modState.Mod.HasImplementation && IsValidMod.Invoke(modState.Mod);
}
private void updateMultiplier()
private void updateRankingInformation()
{
if (multiplierDisplay == null)
if (rankingInformationDisplay == null)
return;
double multiplier = 1.0;
@ -460,7 +460,8 @@ namespace osu.Game.Overlays.Mods
foreach (var mod in SelectedMods.Value)
multiplier *= mod.ScoreMultiplier;
multiplierDisplay.Current.Value = multiplier;
rankingInformationDisplay.ModMultiplier.Value = multiplier;
rankingInformationDisplay.Ranked.Value = SelectedMods.Value.All(m => m.Ranked);
}
private void updateCustomisation()

View File

@ -6,8 +6,8 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
@ -22,15 +22,13 @@ namespace osu.Game.Overlays.Mods
/// <summary>
/// On the mod select overlay, this provides a local updating view of the aggregate score multiplier coming from mods.
/// </summary>
public partial class ScoreMultiplierDisplay : ModFooterInformationDisplay, IHasCurrentValue<double>
public partial class RankingInformationDisplay : ModFooterInformationDisplay
{
public const float HEIGHT = 42;
public Bindable<double> Current
{
get => current.Current;
set => current.Current = value;
}
public Bindable<double> ModMultiplier = new BindableDouble(1);
public Bindable<bool> Ranked { get; } = new BindableBool(true);
private readonly BindableWithCurrent<double> current = new BindableWithCurrent<double>();
@ -39,16 +37,11 @@ namespace osu.Game.Overlays.Mods
private RollingCounter<double> counter = null!;
private Box flashLayer = null!;
private TextWithTooltip rankedText = null!;
[Resolved]
private OsuColour colours { get; set; } = null!;
public ScoreMultiplierDisplay()
{
Current.Default = 1d;
Current.Value = 1d;
}
[BackgroundDependencyLoader]
private void load()
{
@ -75,13 +68,20 @@ namespace osu.Game.Overlays.Mods
LeftContent.AddRange(new Drawable[]
{
new OsuSpriteText
new Container
{
Width = 50,
RelativeSizeAxes = Axes.Y,
Margin = new MarginPadding(10),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0),
Text = ModSelectOverlayStrings.ScoreMultiplier,
Font = OsuFont.Default.With(size: 17, weight: FontWeight.SemiBold)
Child = rankedText = new TextWithTooltip
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0),
Font = OsuFont.Default.With(size: 17, weight: FontWeight.SemiBold)
}
}
});
@ -97,7 +97,7 @@ namespace osu.Game.Overlays.Mods
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Current = { BindTarget = Current }
Current = { BindTarget = ModMultiplier }
}
});
}
@ -106,30 +106,22 @@ namespace osu.Game.Overlays.Mods
{
base.LoadComplete();
Current.BindValueChanged(e =>
ModMultiplier.BindValueChanged(e =>
{
if (e.NewValue > Current.Default)
if (e.NewValue > ModMultiplier.Default)
{
MainBackground
.FadeColour(colours.ForModType(ModType.DifficultyIncrease), transition_duration, Easing.OutQuint);
counter.FadeColour(ColourProvider.Background5, transition_duration, Easing.OutQuint);
counter.FadeColour(colours.ForModType(ModType.DifficultyIncrease), transition_duration, Easing.OutQuint);
}
else if (e.NewValue < Current.Default)
else if (e.NewValue < ModMultiplier.Default)
{
MainBackground
.FadeColour(colours.ForModType(ModType.DifficultyReduction), transition_duration, Easing.OutQuint);
counter.FadeColour(ColourProvider.Background5, transition_duration, Easing.OutQuint);
counter.FadeColour(colours.ForModType(ModType.DifficultyReduction), transition_duration, Easing.OutQuint);
}
else
{
MainBackground.FadeColour(ColourProvider.Background4, transition_duration, Easing.OutQuint);
counter.FadeColour(Colour4.White, transition_duration, Easing.OutQuint);
}
flashLayer
.FadeOutFromOne()
.FadeTo(0.15f, 60, Easing.OutQuint)
.Then().FadeOut(500, Easing.OutQuint);
flash();
const float move_amount = 4;
if (e.NewValue > e.OldValue)
@ -140,10 +132,43 @@ namespace osu.Game.Overlays.Mods
// required to prevent the counter initially rolling up from 0 to 1
// due to `Current.Value` having a nonstandard default value of 1.
counter.SetCountWithoutRolling(Current.Value);
counter.SetCountWithoutRolling(ModMultiplier.Value);
Ranked.BindValueChanged(e =>
{
flash();
if (e.NewValue)
{
rankedText.Text = ModSelectOverlayStrings.Ranked;
rankedText.TooltipText = ModSelectOverlayStrings.RankedExplanation;
rankedText.FadeColour(Colour4.White, transition_duration, Easing.OutQuint);
FrontBackground.FadeColour(ColourProvider.Background3, transition_duration, Easing.OutQuint);
}
else
{
rankedText.Text = ModSelectOverlayStrings.Unranked;
rankedText.TooltipText = ModSelectOverlayStrings.UnrankedExplanation;
rankedText.FadeColour(ColourProvider.Background5, transition_duration, Easing.OutQuint);
FrontBackground.FadeColour(colours.Orange1, transition_duration, Easing.OutQuint);
}
}, true);
}
private partial class EffectCounter : RollingCounter<double>
private void flash()
{
flashLayer
.FadeOutFromOne()
.FadeTo(0.15f, 60, Easing.OutQuint)
.Then().FadeOut(500, Easing.OutQuint);
}
private partial class TextWithTooltip : OsuSpriteText, IHasTooltip
{
public LocalisableString TooltipText { get; set; }
}
private partial class EffectCounter : RollingCounter<double>, IHasTooltip
{
protected override double RollingDuration => 250;
@ -155,6 +180,8 @@ namespace osu.Game.Overlays.Mods
Origin = Anchor.Centre,
Font = OsuFont.Default.With(size: 17, weight: FontWeight.SemiBold)
};
public LocalisableString TooltipText => ModSelectOverlayStrings.ScoreMultiplier;
}
}
}