2022-02-20 14:48:33 +00:00
|
|
|
// 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.Extensions.LocalisationExtensions;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2022-02-20 15:02:46 +00:00
|
|
|
using osu.Framework.Localisation;
|
2022-02-20 14:48:33 +00:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2022-02-20 15:02:46 +00:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2022-02-20 14:48:33 +00:00
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Mods
|
|
|
|
{
|
|
|
|
public class DifficultyMultiplierDisplay : CompositeDrawable, IHasCurrentValue<double>
|
|
|
|
{
|
2022-04-05 09:25:27 +00:00
|
|
|
public const float HEIGHT = 42;
|
|
|
|
|
2022-02-20 14:48:33 +00:00
|
|
|
public Bindable<double> Current
|
|
|
|
{
|
|
|
|
get => current.Current;
|
|
|
|
set => current.Current = value;
|
|
|
|
}
|
|
|
|
|
2022-02-20 15:02:46 +00:00
|
|
|
private readonly BindableNumberWithCurrent<double> current = new BindableNumberWithCurrent<double>(1)
|
|
|
|
{
|
2022-03-07 21:55:55 +00:00
|
|
|
Precision = 0.01
|
2022-02-20 15:02:46 +00:00
|
|
|
};
|
2022-02-20 14:48:33 +00:00
|
|
|
|
|
|
|
private readonly Box underlayBackground;
|
|
|
|
private readonly Box contentBackground;
|
|
|
|
private readonly FillFlowContainer multiplierFlow;
|
2022-02-20 15:02:46 +00:00
|
|
|
private readonly MultiplierCounter multiplierCounter;
|
2022-02-20 14:48:33 +00:00
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OverlayColourProvider colourProvider { get; set; }
|
|
|
|
|
2022-03-07 21:55:55 +00:00
|
|
|
private const float multiplier_value_area_width = 56;
|
2022-02-20 14:48:33 +00:00
|
|
|
private const float transition_duration = 200;
|
|
|
|
|
|
|
|
public DifficultyMultiplierDisplay()
|
|
|
|
{
|
2022-04-05 09:25:27 +00:00
|
|
|
Height = HEIGHT;
|
2022-02-20 14:48:33 +00:00
|
|
|
AutoSizeAxes = Axes.X;
|
|
|
|
|
|
|
|
InternalChild = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = ModPanel.CORNER_RADIUS,
|
|
|
|
Shear = new Vector2(ModPanel.SHEAR_X, 0),
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
underlayBackground = new Box
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2022-03-07 21:55:55 +00:00
|
|
|
Width = multiplier_value_area_width + ModPanel.CORNER_RADIUS
|
2022-02-20 14:48:33 +00:00
|
|
|
},
|
|
|
|
new GridContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
ColumnDimensions = new[]
|
|
|
|
{
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
2022-03-07 21:55:55 +00:00
|
|
|
new Dimension(GridSizeMode.Absolute, multiplier_value_area_width)
|
2022-02-20 14:48:33 +00:00
|
|
|
},
|
|
|
|
Content = new[]
|
|
|
|
{
|
|
|
|
new Drawable[]
|
|
|
|
{
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = ModPanel.CORNER_RADIUS,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
contentBackground = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
},
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Margin = new MarginPadding { Horizontal = 18 },
|
|
|
|
Shear = new Vector2(-ModPanel.SHEAR_X, 0),
|
|
|
|
Text = "Difficulty Multiplier",
|
|
|
|
Font = OsuFont.Default.With(size: 17, weight: FontWeight.SemiBold)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
multiplierFlow = new FillFlowContainer
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Shear = new Vector2(-ModPanel.SHEAR_X, 0),
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Spacing = new Vector2(2, 0),
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2022-02-20 15:02:46 +00:00
|
|
|
multiplierCounter = new MultiplierCounter
|
2022-02-20 14:48:33 +00:00
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
2022-02-20 15:02:46 +00:00
|
|
|
Current = { BindTarget = Current }
|
2022-02-20 14:48:33 +00:00
|
|
|
},
|
|
|
|
new SpriteIcon
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Icon = FontAwesome.Solid.Times,
|
|
|
|
Size = new Vector2(7),
|
|
|
|
Margin = new MarginPadding { Top = 1 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
contentBackground.Colour = colourProvider.Background4;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2022-04-05 09:25:27 +00:00
|
|
|
|
2022-02-20 14:48:33 +00:00
|
|
|
current.BindValueChanged(_ => updateState(), true);
|
2022-04-05 09:25:27 +00:00
|
|
|
|
2022-03-07 22:11:20 +00:00
|
|
|
// required to prevent the counter initially rolling up from 0 to 1
|
|
|
|
// due to `Current.Value` having a nonstandard default value of 1.
|
|
|
|
multiplierCounter.SetCountWithoutRolling(Current.Value);
|
2022-02-20 14:48:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateState()
|
|
|
|
{
|
|
|
|
if (Current.IsDefault)
|
|
|
|
{
|
|
|
|
underlayBackground.FadeColour(colourProvider.Background3, transition_duration, Easing.OutQuint);
|
|
|
|
multiplierFlow.FadeColour(Colour4.White, transition_duration, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var backgroundColour = Current.Value < 1
|
|
|
|
? colours.ForModType(ModType.DifficultyReduction)
|
|
|
|
: colours.ForModType(ModType.DifficultyIncrease);
|
|
|
|
|
|
|
|
underlayBackground.FadeColour(backgroundColour, transition_duration, Easing.OutQuint);
|
|
|
|
multiplierFlow.FadeColour(colourProvider.Background5, transition_duration, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
}
|
2022-02-20 15:02:46 +00:00
|
|
|
|
|
|
|
private class MultiplierCounter : RollingCounter<double>
|
|
|
|
{
|
|
|
|
protected override double RollingDuration => 500;
|
|
|
|
|
2022-03-07 21:55:55 +00:00
|
|
|
protected override LocalisableString FormatCount(double count) => count.ToLocalisableString(@"N2");
|
2022-02-20 15:02:46 +00:00
|
|
|
|
|
|
|
protected override OsuSpriteText CreateSpriteText() => new OsuSpriteText
|
|
|
|
{
|
|
|
|
Font = OsuFont.Default.With(size: 17, weight: FontWeight.SemiBold)
|
|
|
|
};
|
|
|
|
}
|
2022-02-20 14:48:33 +00:00
|
|
|
}
|
|
|
|
}
|