1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 03:07:26 +08:00
osu-lazer/osu.Game/Overlays/Mods/AdjustedAttributesTooltip.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

143 lines
4.6 KiB
C#
Raw Normal View History

2023-11-24 05:30:18 +08: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-12-13 16:33:39 +08:00
using System;
using System.Linq;
2023-11-24 05:30:18 +08:00
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Utils;
2023-12-13 16:33:39 +08:00
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
2023-11-24 05:30:18 +08:00
using osuTK;
namespace osu.Game.Overlays.Mods
{
public partial class AdjustedAttributesTooltip : VisibilityContainer, ITooltip<AdjustedAttributesTooltip.Data?>
2023-11-24 05:30:18 +08:00
{
2023-12-13 16:33:39 +08:00
private FillFlowContainer attributesFillFlow = null!;
2023-11-24 05:30:18 +08:00
private Container content = null!;
2023-11-24 05:30:18 +08:00
private Data? data;
2023-12-13 16:33:39 +08:00
2023-11-24 05:30:18 +08:00
[Resolved]
private OsuColour colours { get; set; } = null!;
[BackgroundDependencyLoader]
private void load()
{
AutoSizeAxes = Axes.Both;
Masking = true;
CornerRadius = 5;
2023-11-24 05:30:18 +08:00
InternalChildren = new Drawable[]
2023-11-24 05:30:18 +08:00
{
content = new Container
2023-11-24 05:30:18 +08:00
{
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new Box
2023-11-24 05:30:18 +08:00
{
RelativeSizeAxes = Axes.Both,
Colour = colours.Gray3,
2023-11-24 05:30:18 +08:00
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Padding = new MarginPadding { Vertical = 10, Horizontal = 15 },
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new OsuSpriteText
{
Text = "One or more values are being adjusted by mods that change speed.",
},
attributesFillFlow = new FillFlowContainer
{
Direction = FillDirection.Vertical,
AutoSizeAxes = Axes.Both
}
}
}
2023-11-24 05:30:18 +08:00
}
},
};
2023-11-24 05:30:18 +08:00
2023-12-13 16:33:39 +08:00
updateDisplay();
2023-11-24 05:30:18 +08:00
}
2023-12-13 16:33:39 +08:00
private void updateDisplay()
2023-11-24 05:30:18 +08:00
{
2023-12-13 16:33:39 +08:00
attributesFillFlow.Clear();
2023-12-10 06:40:05 +08:00
if (data != null)
{
attemptAdd("CS", bd => bd.CircleSize);
attemptAdd("HP", bd => bd.DrainRate);
attemptAdd("OD", bd => bd.OverallDifficulty);
attemptAdd("AR", bd => bd.ApproachRate);
}
2023-11-24 05:30:18 +08:00
2023-12-13 16:33:39 +08:00
if (attributesFillFlow.Any())
content.Show();
else
content.Hide();
2023-11-24 05:30:18 +08:00
2023-12-13 16:33:39 +08:00
void attemptAdd(string name, Func<BeatmapDifficulty, double> lookup)
{
double originalValue = lookup(data.OriginalDifficulty);
double adjustedValue = lookup(data.AdjustedDifficulty);
2023-12-13 16:33:39 +08:00
if (!Precision.AlmostEquals(originalValue, adjustedValue))
attributesFillFlow.Add(new AttributeDisplay(name, originalValue, adjustedValue));
2023-12-13 16:33:39 +08:00
}
2023-11-24 05:30:18 +08:00
}
2023-12-10 06:51:50 +08:00
public void SetContent(Data? data)
2023-11-24 05:30:18 +08:00
{
if (this.data == data)
return;
this.data = data;
updateDisplay();
2023-11-24 05:30:18 +08:00
}
protected override void PopIn() => this.FadeIn(200, Easing.OutQuint);
protected override void PopOut() => this.FadeOut(200, Easing.OutQuint);
2023-11-24 05:30:18 +08:00
public void Move(Vector2 pos) => Position = pos;
public class Data
{
public BeatmapDifficulty OriginalDifficulty { get; }
public BeatmapDifficulty AdjustedDifficulty { get; }
public Data(BeatmapDifficulty originalDifficulty, BeatmapDifficulty adjustedDifficulty)
{
OriginalDifficulty = originalDifficulty;
AdjustedDifficulty = adjustedDifficulty;
}
}
2023-11-24 05:30:18 +08:00
private partial class AttributeDisplay : CompositeDrawable
{
2023-12-13 16:33:39 +08:00
public AttributeDisplay(string name, double original, double adjusted)
2023-11-24 05:30:18 +08:00
{
AutoSizeAxes = Axes.Both;
2023-12-13 16:33:39 +08:00
InternalChild = new OsuSpriteText
{
2023-12-13 16:33:39 +08:00
Font = OsuFont.Default.With(weight: FontWeight.Bold),
Text = $"{name}: {original:0.0#} → {adjusted:0.0#}"
};
2023-11-24 05:30:18 +08:00
}
}
2023-11-24 05:30:18 +08:00
}
}