mirror of https://github.com/ppy/osu
use SettingSource to define IconTooltip format
This commit is contained in:
parent
7a0a633ef9
commit
5a6d8f1932
|
@ -10,7 +10,7 @@ namespace osu.Game.Rulesets.Catch.Mods
|
|||
{
|
||||
public class CatchModDifficultyAdjust : ModDifficultyAdjust
|
||||
{
|
||||
[SettingSource("Circle Size", "Override a beatmap's set CS.", FIRST_SETTING_ORDER - 1)]
|
||||
[SettingSource("Circle Size", "Override a beatmap's set CS.", "CS {0}", FIRST_SETTING_ORDER - 1)]
|
||||
public BindableNumber<float> CircleSize { get; } = new BindableFloat
|
||||
{
|
||||
Precision = 0.1f,
|
||||
|
@ -20,7 +20,7 @@ public class CatchModDifficultyAdjust : ModDifficultyAdjust
|
|||
Value = 5,
|
||||
};
|
||||
|
||||
[SettingSource("Approach Rate", "Override a beatmap's set AR.", LAST_SETTING_ORDER + 1)]
|
||||
[SettingSource("Approach Rate", "Override a beatmap's set AR.", "AR {0}", LAST_SETTING_ORDER + 1)]
|
||||
public BindableNumber<float> ApproachRate { get; } = new BindableFloat
|
||||
{
|
||||
Precision = 0.1f,
|
||||
|
@ -30,11 +30,6 @@ public class CatchModDifficultyAdjust : ModDifficultyAdjust
|
|||
Value = 5,
|
||||
};
|
||||
|
||||
public override string IconTooltip => ($"{Name} ({(CircleSize.IsDefault ? "" : $"CS {CircleSize.Value}, ")}" +
|
||||
$"{(DrainRate.IsDefault ? "" : $"HP {DrainRate.Value}, ")}" +
|
||||
$"{(OverallDifficulty.IsDefault ? "" : $"OD {OverallDifficulty.Value}, ")}" +
|
||||
$"{(ApproachRate.IsDefault ? "" : $"AR {ApproachRate.Value}")}").TrimEnd(new char[] { ',', ' ' }) + ")";
|
||||
|
||||
protected override void TransferSettings(BeatmapDifficulty difficulty)
|
||||
{
|
||||
base.TransferSettings(difficulty);
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace osu.Game.Rulesets.Osu.Mods
|
|||
{
|
||||
public class OsuModDifficultyAdjust : ModDifficultyAdjust
|
||||
{
|
||||
[SettingSource("Circle Size", "Override a beatmap's set CS.", FIRST_SETTING_ORDER - 1)]
|
||||
[SettingSource("Circle Size", "Override a beatmap's set CS.", "CS {0}", FIRST_SETTING_ORDER - 1)]
|
||||
public BindableNumber<float> CircleSize { get; } = new BindableFloat
|
||||
{
|
||||
Precision = 0.1f,
|
||||
|
@ -20,7 +20,7 @@ public class OsuModDifficultyAdjust : ModDifficultyAdjust
|
|||
Value = 5,
|
||||
};
|
||||
|
||||
[SettingSource("Approach Rate", "Override a beatmap's set AR.", LAST_SETTING_ORDER + 1)]
|
||||
[SettingSource("Approach Rate", "Override a beatmap's set AR.", "AR {0}", LAST_SETTING_ORDER + 1)]
|
||||
public BindableNumber<float> ApproachRate { get; } = new BindableFloat
|
||||
{
|
||||
Precision = 0.1f,
|
||||
|
@ -30,11 +30,6 @@ public class OsuModDifficultyAdjust : ModDifficultyAdjust
|
|||
Value = 5,
|
||||
};
|
||||
|
||||
public override string IconTooltip => ($"{Name} ({(CircleSize.IsDefault ? "" : $"CS {CircleSize.Value}, ")}" +
|
||||
$"{(DrainRate.IsDefault ? "" : $"HP {DrainRate.Value}, ")}" +
|
||||
$"{(OverallDifficulty.IsDefault ? "" : $"OD {OverallDifficulty.Value}, ")}" +
|
||||
$"{(ApproachRate.IsDefault ? "" : $"AR {ApproachRate.Value}")}").TrimEnd(new char[] { ',', ' ' }) + ")";
|
||||
|
||||
protected override void TransferSettings(BeatmapDifficulty difficulty)
|
||||
{
|
||||
base.TransferSettings(difficulty);
|
||||
|
|
|
@ -30,17 +30,26 @@ public class SettingSourceAttribute : Attribute
|
|||
|
||||
public int? OrderPosition { get; }
|
||||
|
||||
public string TooltipText { get; }
|
||||
|
||||
public SettingSourceAttribute(string label, string description = null)
|
||||
{
|
||||
Label = label ?? string.Empty;
|
||||
Description = description ?? string.Empty;
|
||||
}
|
||||
|
||||
public SettingSourceAttribute(string label, string description, int orderPosition)
|
||||
public SettingSourceAttribute(string label, string description, string tooltipText, int orderPosition)
|
||||
: this(label, description)
|
||||
{
|
||||
OrderPosition = orderPosition;
|
||||
TooltipText = tooltipText;
|
||||
}
|
||||
|
||||
public SettingSourceAttribute(string label, string description, string tooltipText) : this(label, description)
|
||||
{
|
||||
TooltipText = tooltipText;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class SettingSourceExtensions
|
||||
|
|
|
@ -2,8 +2,12 @@
|
|||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
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;
|
||||
|
||||
|
@ -51,7 +55,35 @@ public abstract class Mod : IMod, IJsonSerializable
|
|||
/// are displayed in the tooltip.
|
||||
/// </remarks>
|
||||
[JsonIgnore]
|
||||
public virtual string IconTooltip => Name;
|
||||
public virtual string IconTooltip
|
||||
{
|
||||
get
|
||||
{
|
||||
List<string> attributes = new List<string>();
|
||||
foreach ((SettingSourceAttribute attr, System.Reflection.PropertyInfo property) in this.GetOrderedSettingsSourceProperties())
|
||||
{
|
||||
// use TooltipText from SettingSource if available, but fall back to Label, which has to be provided
|
||||
string tooltipText = attr.TooltipText ?? attr.Label + " {0}";
|
||||
object bindableObj = property.GetValue(this);
|
||||
if (bindableObj is BindableInt bindableInt && !bindableInt.IsDefault)
|
||||
{
|
||||
attributes.Add(string.Format(tooltipText, bindableInt.Value));
|
||||
continue;
|
||||
}
|
||||
if (bindableObj is BindableFloat bindableFloat && !bindableFloat.IsDefault)
|
||||
{
|
||||
attributes.Add(string.Format(tooltipText, bindableFloat.Value));
|
||||
continue;
|
||||
}
|
||||
if (bindableObj is BindableDouble bindableDouble && !bindableDouble.IsDefault)
|
||||
{
|
||||
attributes.Add(string.Format(tooltipText, bindableDouble.Value));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return $"{Name}{(attributes.Any() ? $" ({string.Join(", ", attributes)})" : "")}";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The score multiplier of this mod.
|
||||
|
|
|
@ -32,7 +32,7 @@ public abstract class ModDifficultyAdjust : Mod, IApplicableToDifficulty
|
|||
|
||||
protected const int LAST_SETTING_ORDER = 2;
|
||||
|
||||
[SettingSource("HP Drain", "Override a beatmap's set HP.", FIRST_SETTING_ORDER)]
|
||||
[SettingSource("HP Drain", "Override a beatmap's set HP.", "HP {0}", FIRST_SETTING_ORDER)]
|
||||
public BindableNumber<float> DrainRate { get; } = new BindableFloat
|
||||
{
|
||||
Precision = 0.1f,
|
||||
|
@ -42,7 +42,7 @@ public abstract class ModDifficultyAdjust : Mod, IApplicableToDifficulty
|
|||
Value = 5,
|
||||
};
|
||||
|
||||
[SettingSource("Accuracy", "Override a beatmap's set OD.", LAST_SETTING_ORDER)]
|
||||
[SettingSource("Accuracy", "Override a beatmap's set OD.", "OD {0}", LAST_SETTING_ORDER)]
|
||||
public BindableNumber<float> OverallDifficulty { get; } = new BindableFloat
|
||||
{
|
||||
Precision = 0.1f,
|
||||
|
@ -52,9 +52,6 @@ public abstract class ModDifficultyAdjust : Mod, IApplicableToDifficulty
|
|||
Value = 5,
|
||||
};
|
||||
|
||||
public override string IconTooltip => $"{Name} ({(DrainRate.IsDefault ? $"HP {DrainRate.Value.ToString()}, " : "")}" +
|
||||
$"{(OverallDifficulty.IsDefault ? $"OD {OverallDifficulty.Value.ToString()}, " : "")})";
|
||||
|
||||
private BeatmapDifficulty difficulty;
|
||||
|
||||
public void ReadFromDifficulty(BeatmapDifficulty difficulty)
|
||||
|
|
|
@ -21,7 +21,7 @@ public abstract class ModDoubleTime : ModRateAdjust
|
|||
|
||||
public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(ModHalfTime)).ToArray();
|
||||
|
||||
[SettingSource("Speed increase", "The actual increase to apply")]
|
||||
[SettingSource("Speed increase", "The actual increase to apply", "{0}x")]
|
||||
public override BindableNumber<double> SpeedChange { get; } = new BindableDouble
|
||||
{
|
||||
MinValue = 1.01,
|
||||
|
@ -30,7 +30,5 @@ public abstract class ModDoubleTime : ModRateAdjust
|
|||
Value = 1.5,
|
||||
Precision = 0.01,
|
||||
};
|
||||
|
||||
public override string IconTooltip => $"{Name}{(SpeedChange.IsDefault ? "" : $" ({SpeedChange.Value}x)")}";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,15 +21,13 @@ public abstract class ModEasy : Mod, IApplicableToDifficulty, IApplicableFailOve
|
|||
public override bool Ranked => true;
|
||||
public override Type[] IncompatibleMods => new[] { typeof(ModHardRock), typeof(ModDifficultyAdjust) };
|
||||
|
||||
[SettingSource("Extra Lives", "Number of extra lives")]
|
||||
[SettingSource("Extra Lives", "Number of extra lives", "{0} lives")]
|
||||
public Bindable<int> Retries { get; } = new BindableInt(2)
|
||||
{
|
||||
MinValue = 0,
|
||||
MaxValue = 10
|
||||
};
|
||||
|
||||
public override string IconTooltip => $"{Name}{(Retries.IsDefault ? "" : $" ({Retries.Value} lives)")}";
|
||||
|
||||
private int retries;
|
||||
|
||||
private BindableNumber<double> health;
|
||||
|
|
|
@ -21,7 +21,7 @@ public abstract class ModHalfTime : ModRateAdjust
|
|||
|
||||
public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(ModDoubleTime)).ToArray();
|
||||
|
||||
[SettingSource("Speed decrease", "The actual decrease to apply")]
|
||||
[SettingSource("Speed decrease", "The actual decrease to apply", "{0}x")]
|
||||
public override BindableNumber<double> SpeedChange { get; } = new BindableDouble
|
||||
{
|
||||
MinValue = 0.5,
|
||||
|
@ -30,7 +30,5 @@ public abstract class ModHalfTime : ModRateAdjust
|
|||
Value = 0.75,
|
||||
Precision = 0.01,
|
||||
};
|
||||
|
||||
public override string IconTooltip => $"{Name}{(SpeedChange.IsDefault ? "" : $" ({SpeedChange.Value}x)")}";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue