mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 08:49:59 +09:00
use SettingSource to define IconTooltip format
This commit is contained in:
@ -10,7 +10,7 @@ namespace osu.Game.Rulesets.Catch.Mods
|
|||||||
{
|
{
|
||||||
public class CatchModDifficultyAdjust : ModDifficultyAdjust
|
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
|
public BindableNumber<float> CircleSize { get; } = new BindableFloat
|
||||||
{
|
{
|
||||||
Precision = 0.1f,
|
Precision = 0.1f,
|
||||||
@ -20,7 +20,7 @@ namespace osu.Game.Rulesets.Catch.Mods
|
|||||||
Value = 5,
|
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
|
public BindableNumber<float> ApproachRate { get; } = new BindableFloat
|
||||||
{
|
{
|
||||||
Precision = 0.1f,
|
Precision = 0.1f,
|
||||||
@ -30,11 +30,6 @@ namespace osu.Game.Rulesets.Catch.Mods
|
|||||||
Value = 5,
|
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)
|
protected override void TransferSettings(BeatmapDifficulty difficulty)
|
||||||
{
|
{
|
||||||
base.TransferSettings(difficulty);
|
base.TransferSettings(difficulty);
|
||||||
|
@ -10,7 +10,7 @@ namespace osu.Game.Rulesets.Osu.Mods
|
|||||||
{
|
{
|
||||||
public class OsuModDifficultyAdjust : ModDifficultyAdjust
|
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
|
public BindableNumber<float> CircleSize { get; } = new BindableFloat
|
||||||
{
|
{
|
||||||
Precision = 0.1f,
|
Precision = 0.1f,
|
||||||
@ -20,7 +20,7 @@ namespace osu.Game.Rulesets.Osu.Mods
|
|||||||
Value = 5,
|
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
|
public BindableNumber<float> ApproachRate { get; } = new BindableFloat
|
||||||
{
|
{
|
||||||
Precision = 0.1f,
|
Precision = 0.1f,
|
||||||
@ -30,11 +30,6 @@ namespace osu.Game.Rulesets.Osu.Mods
|
|||||||
Value = 5,
|
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)
|
protected override void TransferSettings(BeatmapDifficulty difficulty)
|
||||||
{
|
{
|
||||||
base.TransferSettings(difficulty);
|
base.TransferSettings(difficulty);
|
||||||
|
@ -30,17 +30,26 @@ namespace osu.Game.Configuration
|
|||||||
|
|
||||||
public int? OrderPosition { get; }
|
public int? OrderPosition { get; }
|
||||||
|
|
||||||
|
public string TooltipText { get; }
|
||||||
|
|
||||||
public SettingSourceAttribute(string label, string description = null)
|
public SettingSourceAttribute(string label, string description = null)
|
||||||
{
|
{
|
||||||
Label = label ?? string.Empty;
|
Label = label ?? string.Empty;
|
||||||
Description = description ?? 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)
|
: this(label, description)
|
||||||
{
|
{
|
||||||
OrderPosition = orderPosition;
|
OrderPosition = orderPosition;
|
||||||
|
TooltipText = tooltipText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SettingSourceAttribute(string label, string description, string tooltipText) : this(label, description)
|
||||||
|
{
|
||||||
|
TooltipText = tooltipText;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SettingSourceExtensions
|
public static class SettingSourceExtensions
|
||||||
|
@ -2,8 +2,12 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Game.Configuration;
|
||||||
using osu.Game.IO.Serialization;
|
using osu.Game.IO.Serialization;
|
||||||
using osu.Game.Rulesets.UI;
|
using osu.Game.Rulesets.UI;
|
||||||
|
|
||||||
@ -51,7 +55,35 @@ namespace osu.Game.Rulesets.Mods
|
|||||||
/// are displayed in the tooltip.
|
/// are displayed in the tooltip.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[JsonIgnore]
|
[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>
|
/// <summary>
|
||||||
/// The score multiplier of this mod.
|
/// The score multiplier of this mod.
|
||||||
|
@ -32,7 +32,7 @@ namespace osu.Game.Rulesets.Mods
|
|||||||
|
|
||||||
protected const int LAST_SETTING_ORDER = 2;
|
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
|
public BindableNumber<float> DrainRate { get; } = new BindableFloat
|
||||||
{
|
{
|
||||||
Precision = 0.1f,
|
Precision = 0.1f,
|
||||||
@ -42,7 +42,7 @@ namespace osu.Game.Rulesets.Mods
|
|||||||
Value = 5,
|
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
|
public BindableNumber<float> OverallDifficulty { get; } = new BindableFloat
|
||||||
{
|
{
|
||||||
Precision = 0.1f,
|
Precision = 0.1f,
|
||||||
@ -52,9 +52,6 @@ namespace osu.Game.Rulesets.Mods
|
|||||||
Value = 5,
|
Value = 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
public override string IconTooltip => $"{Name} ({(DrainRate.IsDefault ? $"HP {DrainRate.Value.ToString()}, " : "")}" +
|
|
||||||
$"{(OverallDifficulty.IsDefault ? $"OD {OverallDifficulty.Value.ToString()}, " : "")})";
|
|
||||||
|
|
||||||
private BeatmapDifficulty difficulty;
|
private BeatmapDifficulty difficulty;
|
||||||
|
|
||||||
public void ReadFromDifficulty(BeatmapDifficulty difficulty)
|
public void ReadFromDifficulty(BeatmapDifficulty difficulty)
|
||||||
|
@ -21,7 +21,7 @@ namespace osu.Game.Rulesets.Mods
|
|||||||
|
|
||||||
public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(ModHalfTime)).ToArray();
|
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
|
public override BindableNumber<double> SpeedChange { get; } = new BindableDouble
|
||||||
{
|
{
|
||||||
MinValue = 1.01,
|
MinValue = 1.01,
|
||||||
@ -30,7 +30,5 @@ namespace osu.Game.Rulesets.Mods
|
|||||||
Value = 1.5,
|
Value = 1.5,
|
||||||
Precision = 0.01,
|
Precision = 0.01,
|
||||||
};
|
};
|
||||||
|
|
||||||
public override string IconTooltip => $"{Name}{(SpeedChange.IsDefault ? "" : $" ({SpeedChange.Value}x)")}";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,15 +21,13 @@ namespace osu.Game.Rulesets.Mods
|
|||||||
public override bool Ranked => true;
|
public override bool Ranked => true;
|
||||||
public override Type[] IncompatibleMods => new[] { typeof(ModHardRock), typeof(ModDifficultyAdjust) };
|
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)
|
public Bindable<int> Retries { get; } = new BindableInt(2)
|
||||||
{
|
{
|
||||||
MinValue = 0,
|
MinValue = 0,
|
||||||
MaxValue = 10
|
MaxValue = 10
|
||||||
};
|
};
|
||||||
|
|
||||||
public override string IconTooltip => $"{Name}{(Retries.IsDefault ? "" : $" ({Retries.Value} lives)")}";
|
|
||||||
|
|
||||||
private int retries;
|
private int retries;
|
||||||
|
|
||||||
private BindableNumber<double> health;
|
private BindableNumber<double> health;
|
||||||
|
@ -21,7 +21,7 @@ namespace osu.Game.Rulesets.Mods
|
|||||||
|
|
||||||
public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(ModDoubleTime)).ToArray();
|
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
|
public override BindableNumber<double> SpeedChange { get; } = new BindableDouble
|
||||||
{
|
{
|
||||||
MinValue = 0.5,
|
MinValue = 0.5,
|
||||||
@ -30,7 +30,5 @@ namespace osu.Game.Rulesets.Mods
|
|||||||
Value = 0.75,
|
Value = 0.75,
|
||||||
Precision = 0.01,
|
Precision = 0.01,
|
||||||
};
|
};
|
||||||
|
|
||||||
public override string IconTooltip => $"{Name}{(SpeedChange.IsDefault ? "" : $" ({SpeedChange.Value}x)")}";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user