2023-09-02 23:09:01 +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.
|
|
|
|
|
|
2023-09-12 13:44:44 +00:00
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Allocation;
|
2023-09-02 23:09:01 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Extensions.LocalisationExtensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
|
using osu.Framework.Localisation;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2023-09-12 13:44:44 +00:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
|
using osuTK.Graphics;
|
2023-09-02 23:09:01 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Mods
|
|
|
|
|
{
|
|
|
|
|
public partial class VerticalAttributeDisplay : Container, IHasCurrentValue<double>
|
|
|
|
|
{
|
|
|
|
|
public Bindable<double> Current
|
|
|
|
|
{
|
|
|
|
|
get => current.Current;
|
|
|
|
|
set => current.Current = value;
|
|
|
|
|
}
|
2023-09-11 07:37:25 +00:00
|
|
|
|
|
2023-09-02 23:09:01 +00:00
|
|
|
|
private readonly BindableWithCurrent<double> current = new BindableWithCurrent<double>();
|
|
|
|
|
|
2023-11-04 15:25:09 +00:00
|
|
|
|
public Bindable<ModEffect> AdjustType = new Bindable<ModEffect>();
|
2023-09-12 13:44:44 +00:00
|
|
|
|
|
2023-09-02 23:09:01 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Text to display in the top area of the display.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public LocalisableString Label { get; protected set; }
|
|
|
|
|
|
2023-09-12 13:44:44 +00:00
|
|
|
|
private EffectCounter counter;
|
|
|
|
|
private OsuSpriteText text;
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private OsuColour colours { get; set; } = null!;
|
|
|
|
|
private void updateTextColor()
|
|
|
|
|
{
|
|
|
|
|
Color4 newColor;
|
2023-11-04 15:25:09 +00:00
|
|
|
|
switch (AdjustType.Value)
|
2023-09-12 13:44:44 +00:00
|
|
|
|
{
|
2023-11-04 15:25:09 +00:00
|
|
|
|
case ModEffect.NotChanged:
|
2023-09-12 13:44:44 +00:00
|
|
|
|
newColor = Color4.White;
|
|
|
|
|
break;
|
|
|
|
|
|
2023-11-04 15:25:09 +00:00
|
|
|
|
case ModEffect.DifficultyReduction:
|
2023-09-12 13:44:44 +00:00
|
|
|
|
newColor = colours.ForModType(ModType.DifficultyReduction);
|
|
|
|
|
break;
|
|
|
|
|
|
2023-11-04 15:25:09 +00:00
|
|
|
|
case ModEffect.DifficultyIncrease:
|
2023-09-12 13:44:44 +00:00
|
|
|
|
newColor = colours.ForModType(ModType.DifficultyIncrease);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2023-11-04 15:25:09 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(AdjustType.Value));
|
2023-09-12 13:44:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
text.Colour = newColor;
|
|
|
|
|
counter.Colour = newColor;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-11 07:37:25 +00:00
|
|
|
|
public VerticalAttributeDisplay(LocalisableString label)
|
2023-09-02 23:09:01 +00:00
|
|
|
|
{
|
|
|
|
|
Label = label;
|
2023-09-12 08:06:42 +00:00
|
|
|
|
|
2023-09-02 23:09:01 +00:00
|
|
|
|
AutoSizeAxes = Axes.X;
|
2023-09-12 08:06:42 +00:00
|
|
|
|
|
|
|
|
|
Origin = Anchor.CentreLeft;
|
|
|
|
|
Anchor = Anchor.CentreLeft;
|
|
|
|
|
|
2023-11-04 15:25:09 +00:00
|
|
|
|
AdjustType.BindValueChanged(_ => updateTextColor());
|
2023-09-12 13:44:44 +00:00
|
|
|
|
|
2023-09-02 23:09:01 +00:00
|
|
|
|
InternalChild = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2023-09-12 13:44:44 +00:00
|
|
|
|
text = new OsuSpriteText
|
2023-09-02 23:09:01 +00:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Text = Label,
|
|
|
|
|
Margin = new MarginPadding { Horizontal = 15 }, // to reserve space for 0.XX value
|
|
|
|
|
Font = OsuFont.Default.With(size: 20, weight: FontWeight.Bold)
|
|
|
|
|
},
|
2023-09-12 13:44:44 +00:00
|
|
|
|
counter = new EffectCounter
|
2023-09-02 23:09:01 +00:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
2023-09-08 19:15:30 +00:00
|
|
|
|
Current = { BindTarget = Current },
|
2023-09-02 23:09:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2023-11-04 15:25:09 +00:00
|
|
|
|
|
|
|
|
|
public static ModEffect CalculateEffect(double oldValue, double newValue)
|
|
|
|
|
{
|
|
|
|
|
if (newValue == oldValue)
|
|
|
|
|
return ModEffect.NotChanged;
|
|
|
|
|
if (newValue < oldValue)
|
|
|
|
|
return ModEffect.DifficultyReduction;
|
|
|
|
|
|
|
|
|
|
return ModEffect.DifficultyIncrease;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum ModEffect
|
|
|
|
|
{
|
|
|
|
|
NotChanged,
|
|
|
|
|
DifficultyReduction,
|
|
|
|
|
DifficultyIncrease,
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-02 23:09:01 +00:00
|
|
|
|
private partial class EffectCounter : RollingCounter<double>
|
|
|
|
|
{
|
|
|
|
|
protected override double RollingDuration => 500;
|
|
|
|
|
|
2023-09-12 13:44:44 +00:00
|
|
|
|
protected override LocalisableString FormatCount(double count) => count.ToLocalisableString("0.0#");
|
2023-09-02 23:09:01 +00:00
|
|
|
|
|
|
|
|
|
protected override OsuSpriteText CreateSpriteText() => new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Font = OsuFont.Default.With(size: 18, weight: FontWeight.SemiBold)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|