mirror of
https://github.com/ppy/osu.git
synced 2024-12-05 10:33:22 +08:00
Merge pull request #8351 from tybug/show-mod-settings-tooltip
Show customised mod setting values in tooltip
This commit is contained in:
commit
de969c07ea
@ -1,6 +1,7 @@
|
||||
// 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 System.Linq;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Configuration;
|
||||
@ -30,6 +31,22 @@ namespace osu.Game.Rulesets.Catch.Mods
|
||||
Value = 5,
|
||||
};
|
||||
|
||||
public override string SettingDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
string circleSize = CircleSize.IsDefault ? string.Empty : $"CS {CircleSize.Value:N1}";
|
||||
string approachRate = ApproachRate.IsDefault ? string.Empty : $"AR {ApproachRate.Value:N1}";
|
||||
|
||||
return string.Join(", ", new[]
|
||||
{
|
||||
circleSize,
|
||||
base.SettingDescription,
|
||||
approachRate
|
||||
}.Where(s => !string.IsNullOrEmpty(s)));
|
||||
}
|
||||
}
|
||||
|
||||
protected override void TransferSettings(BeatmapDifficulty difficulty)
|
||||
{
|
||||
base.TransferSettings(difficulty);
|
||||
|
@ -1,6 +1,7 @@
|
||||
// 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 System.Linq;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Configuration;
|
||||
@ -30,6 +31,22 @@ namespace osu.Game.Rulesets.Osu.Mods
|
||||
Value = 5,
|
||||
};
|
||||
|
||||
public override string SettingDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
string circleSize = CircleSize.IsDefault ? string.Empty : $"CS {CircleSize.Value:N1}";
|
||||
string approachRate = ApproachRate.IsDefault ? string.Empty : $"AR {ApproachRate.Value:N1}";
|
||||
|
||||
return string.Join(", ", new[]
|
||||
{
|
||||
circleSize,
|
||||
base.SettingDescription,
|
||||
approachRate
|
||||
}.Where(s => !string.IsNullOrEmpty(s)));
|
||||
}
|
||||
}
|
||||
|
||||
protected override void TransferSettings(BeatmapDifficulty difficulty)
|
||||
{
|
||||
base.TransferSettings(difficulty);
|
||||
|
@ -2,9 +2,15 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.IO.Serialization;
|
||||
using osu.Game.Rulesets.UI;
|
||||
|
||||
namespace osu.Game.Rulesets.Mods
|
||||
{
|
||||
@ -42,6 +48,51 @@ namespace osu.Game.Rulesets.Mods
|
||||
[JsonIgnore]
|
||||
public virtual string Description => string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The tooltip to display for this mod when used in a <see cref="ModIcon"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Differs from <see cref="Name"/>, as the value of attributes (AR, CS, etc) changeable via the mod
|
||||
/// are displayed in the tooltip.
|
||||
/// </remarks>
|
||||
[JsonIgnore]
|
||||
public string IconTooltip
|
||||
{
|
||||
get
|
||||
{
|
||||
string description = SettingDescription;
|
||||
|
||||
return string.IsNullOrEmpty(description) ? Name : $"{Name} ({description})";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The description of editable settings of a mod to use in the <see cref="IconTooltip"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Parentheses are added to the tooltip, surrounding the value of this property. If this property is <c>string.Empty</c>,
|
||||
/// the tooltip will not have parentheses.
|
||||
/// </remarks>
|
||||
public virtual string SettingDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
var tooltipTexts = new List<string>();
|
||||
|
||||
foreach ((SettingSourceAttribute attr, PropertyInfo property) in this.GetOrderedSettingsSourceProperties())
|
||||
{
|
||||
object bindableObj = property.GetValue(this);
|
||||
|
||||
if ((bindableObj as IHasDefaultValue)?.IsDefault == true)
|
||||
continue;
|
||||
|
||||
tooltipTexts.Add($"{attr.Label} {bindableObj}");
|
||||
}
|
||||
|
||||
return string.Join(", ", tooltipTexts.Where(s => !string.IsNullOrEmpty(s)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The score multiplier of this mod.
|
||||
/// </summary>
|
||||
|
@ -7,6 +7,7 @@ using osu.Framework.Graphics.Sprites;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Configuration;
|
||||
using System.Linq;
|
||||
|
||||
namespace osu.Game.Rulesets.Mods
|
||||
{
|
||||
@ -52,6 +53,21 @@ namespace osu.Game.Rulesets.Mods
|
||||
Value = 5,
|
||||
};
|
||||
|
||||
public override string SettingDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
string drainRate = DrainRate.IsDefault ? string.Empty : $"HP {DrainRate.Value:N1}";
|
||||
string overallDifficulty = OverallDifficulty.IsDefault ? string.Empty : $"OD {OverallDifficulty.Value:N1}";
|
||||
|
||||
return string.Join(", ", new[]
|
||||
{
|
||||
drainRate,
|
||||
overallDifficulty
|
||||
}.Where(s => !string.IsNullOrEmpty(s)));
|
||||
}
|
||||
}
|
||||
|
||||
private BeatmapDifficulty difficulty;
|
||||
|
||||
public void ReadFromDifficulty(BeatmapDifficulty difficulty)
|
||||
@ -79,7 +95,7 @@ namespace osu.Game.Rulesets.Mods
|
||||
|
||||
/// <summary>
|
||||
/// Transfer a setting from <see cref="BeatmapDifficulty"/> to a configuration bindable.
|
||||
/// Only performs the transfer if the user it not currently overriding..
|
||||
/// Only performs the transfer if the user is not currently overriding.
|
||||
/// </summary>
|
||||
protected void TransferSetting<T>(BindableNumber<T> bindable, T beatmapDefault)
|
||||
where T : struct, IComparable<T>, IConvertible, IEquatable<T>
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using Humanizer;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Beatmaps;
|
||||
@ -28,6 +29,8 @@ namespace osu.Game.Rulesets.Mods
|
||||
MaxValue = 10
|
||||
};
|
||||
|
||||
public override string SettingDescription => Retries.IsDefault ? string.Empty : $"{"lives".ToQuantity(Retries.Value)}";
|
||||
|
||||
private int retries;
|
||||
|
||||
private BindableNumber<double> health;
|
||||
|
@ -15,5 +15,7 @@ namespace osu.Game.Rulesets.Mods
|
||||
{
|
||||
track.AddAdjustment(AdjustableProperty.Tempo, SpeedChange);
|
||||
}
|
||||
|
||||
public override string SettingDescription => SpeedChange.IsDefault ? string.Empty : $"{SpeedChange.Value:N2}x";
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,8 @@ namespace osu.Game.Rulesets.Mods
|
||||
[SettingSource("Final rate", "The final speed to ramp to")]
|
||||
public abstract BindableNumber<double> FinalRate { get; }
|
||||
|
||||
public override string SettingDescription => $"{InitialRate.Value:N2}x to {FinalRate.Value:N2}x";
|
||||
|
||||
private double finalRateTime;
|
||||
private double beginRampTime;
|
||||
|
||||
|
@ -28,7 +28,7 @@ namespace osu.Game.Rulesets.UI
|
||||
|
||||
private readonly ModType type;
|
||||
|
||||
public virtual string TooltipText { get; }
|
||||
public virtual string TooltipText => mod.IconTooltip;
|
||||
|
||||
private Mod mod;
|
||||
|
||||
@ -48,8 +48,6 @@ namespace osu.Game.Rulesets.UI
|
||||
|
||||
type = mod.Type;
|
||||
|
||||
TooltipText = mod.Name;
|
||||
|
||||
Size = new Vector2(size);
|
||||
|
||||
Children = new Drawable[]
|
||||
|
Loading…
Reference in New Issue
Block a user