2019-01-24 08:43:03 +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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2017-05-05 03:16:41 +00:00
|
|
|
|
using System;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK.Graphics;
|
2017-05-08 02:33:22 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2017-02-16 20:05:03 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-10-13 10:14:43 +00:00
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2019-03-27 10:29:27 +00:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2017-02-16 20:05:03 +00:00
|
|
|
|
using osu.Game.Graphics;
|
2020-01-14 13:22:00 +00:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2017-05-03 06:48:10 +00:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
2019-08-07 05:42:43 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2022-07-12 05:36:50 +00:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2021-06-25 17:10:04 +00:00
|
|
|
|
using osu.Framework.Localisation;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-04-18 07:05:58 +00:00
|
|
|
|
namespace osu.Game.Rulesets.UI
|
2017-02-16 20:05:03 +00:00
|
|
|
|
{
|
2021-01-26 10:11:19 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Display the specified mod at a fixed size.
|
|
|
|
|
/// </summary>
|
2017-10-13 10:14:43 +00:00
|
|
|
|
public class ModIcon : Container, IHasTooltip
|
2017-02-16 20:05:03 +00:00
|
|
|
|
{
|
2019-11-21 17:34:19 +00:00
|
|
|
|
public readonly BindableBool Selected = new BindableBool();
|
2019-08-07 05:42:43 +00:00
|
|
|
|
|
2017-08-03 05:36:21 +00:00
|
|
|
|
private readonly SpriteIcon modIcon;
|
2020-01-14 13:22:00 +00:00
|
|
|
|
private readonly SpriteText modAcronym;
|
2017-08-03 05:36:21 +00:00
|
|
|
|
private readonly SpriteIcon background;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-11-15 15:15:27 +00:00
|
|
|
|
private const float size = 80;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-09-10 03:43:12 +00:00
|
|
|
|
public virtual LocalisableString TooltipText => showTooltip ? ((mod as Mod)?.IconTooltip ?? mod.Name) : null;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-09-10 03:43:12 +00:00
|
|
|
|
private IMod mod;
|
2021-01-26 10:11:19 +00:00
|
|
|
|
private readonly bool showTooltip;
|
2020-01-14 12:11:32 +00:00
|
|
|
|
|
2021-09-10 03:43:12 +00:00
|
|
|
|
public IMod Mod
|
2020-01-14 12:11:32 +00:00
|
|
|
|
{
|
|
|
|
|
get => mod;
|
2020-01-14 13:22:00 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
mod = value;
|
2021-02-02 12:35:08 +00:00
|
|
|
|
|
|
|
|
|
if (IsLoaded)
|
|
|
|
|
updateMod(value);
|
2020-01-14 13:22:00 +00:00
|
|
|
|
}
|
2020-01-14 12:11:32 +00:00
|
|
|
|
}
|
2019-08-12 12:20:21 +00:00
|
|
|
|
|
2021-02-02 12:35:08 +00:00
|
|
|
|
[Resolved]
|
|
|
|
|
private OsuColour colours { get; set; }
|
|
|
|
|
|
|
|
|
|
private Color4 backgroundColour;
|
|
|
|
|
|
2021-01-26 10:11:19 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Construct a new instance.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="mod">The mod to be displayed</param>
|
|
|
|
|
/// <param name="showTooltip">Whether a tooltip describing the mod should display on hover.</param>
|
2021-09-10 03:43:12 +00:00
|
|
|
|
public ModIcon(IMod mod, bool showTooltip = true)
|
2017-05-03 06:48:10 +00:00
|
|
|
|
{
|
2020-01-14 13:22:00 +00:00
|
|
|
|
this.mod = mod ?? throw new ArgumentNullException(nameof(mod));
|
2021-01-26 10:11:19 +00:00
|
|
|
|
this.showTooltip = showTooltip;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-11-15 15:15:27 +00:00
|
|
|
|
Size = new Vector2(size);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-05-03 10:53:45 +00:00
|
|
|
|
Children = new Drawable[]
|
2017-02-16 20:05:03 +00:00
|
|
|
|
{
|
2017-08-03 05:36:21 +00:00
|
|
|
|
background = new SpriteIcon
|
2017-05-03 06:48:10 +00:00
|
|
|
|
{
|
2017-05-03 10:53:45 +00:00
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
2017-11-15 15:15:27 +00:00
|
|
|
|
Size = new Vector2(size),
|
2019-03-27 10:29:27 +00:00
|
|
|
|
Icon = OsuIcon.ModBg,
|
2017-05-03 10:53:45 +00:00
|
|
|
|
Shadow = true,
|
|
|
|
|
},
|
2020-01-14 13:22:00 +00:00
|
|
|
|
modAcronym = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Colour = OsuColour.Gray(84),
|
|
|
|
|
Alpha = 0,
|
2020-01-16 09:58:47 +00:00
|
|
|
|
Font = OsuFont.Numeric.With(null, 22f),
|
2020-01-14 13:22:00 +00:00
|
|
|
|
UseFullGlyphHeight = false,
|
|
|
|
|
Text = mod.Acronym
|
|
|
|
|
},
|
2017-08-03 05:36:21 +00:00
|
|
|
|
modIcon = new SpriteIcon
|
2017-05-03 10:53:45 +00:00
|
|
|
|
{
|
2017-11-15 15:15:27 +00:00
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
2017-05-03 10:53:45 +00:00
|
|
|
|
Colour = OsuColour.Gray(84),
|
2020-01-16 09:58:47 +00:00
|
|
|
|
Size = new Vector2(45),
|
2020-01-14 13:22:00 +00:00
|
|
|
|
Icon = FontAwesome.Solid.Question
|
2017-05-03 10:53:45 +00:00
|
|
|
|
},
|
|
|
|
|
};
|
2021-02-02 12:35:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
Selected.BindValueChanged(_ => updateColour());
|
2020-01-14 13:22:00 +00:00
|
|
|
|
|
|
|
|
|
updateMod(mod);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-10 03:43:12 +00:00
|
|
|
|
private void updateMod(IMod value)
|
2020-01-14 13:22:00 +00:00
|
|
|
|
{
|
|
|
|
|
modAcronym.Text = value.Acronym;
|
|
|
|
|
modIcon.Icon = value.Icon ?? FontAwesome.Solid.Question;
|
|
|
|
|
|
|
|
|
|
if (value.Icon is null)
|
|
|
|
|
{
|
|
|
|
|
modIcon.FadeOut();
|
|
|
|
|
modAcronym.FadeIn();
|
2021-02-02 12:35:08 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
modIcon.FadeIn();
|
|
|
|
|
modAcronym.FadeOut();
|
2020-01-14 13:22:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-12 05:36:50 +00:00
|
|
|
|
backgroundColour = colours.ForModType(value.Type);
|
2021-02-02 12:35:08 +00:00
|
|
|
|
updateColour();
|
2017-02-16 20:05:03 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-02-02 12:35:08 +00:00
|
|
|
|
private void updateColour()
|
2017-05-08 02:33:22 +00:00
|
|
|
|
{
|
2022-07-12 05:36:50 +00:00
|
|
|
|
background.Colour = Selected.Value ? backgroundColour.Lighten(0.2f) : backgroundColour;
|
2017-05-08 02:33:22 +00:00
|
|
|
|
}
|
2017-02-16 20:05:03 +00:00
|
|
|
|
}
|
2017-05-05 03:16:41 +00:00
|
|
|
|
}
|