2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-05 11:16:41 +08:00
|
|
|
|
using System;
|
2017-05-08 10:33:22 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2023-09-28 17:30:38 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2017-02-17 04:05:03 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-10-13 18:14:43 +08:00
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2019-03-27 18:29:27 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2023-09-28 17:30:38 +08:00
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
|
using osu.Framework.Localisation;
|
|
|
|
|
using osu.Game.Configuration;
|
2017-02-17 04:05:03 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2020-01-14 21:22:00 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2017-05-03 14:48:10 +08:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
2023-09-28 17:30:38 +08:00
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-04-18 15:05:58 +08:00
|
|
|
|
namespace osu.Game.Rulesets.UI
|
2017-02-17 04:05:03 +08:00
|
|
|
|
{
|
2021-01-26 18:11:19 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Display the specified mod at a fixed size.
|
|
|
|
|
/// </summary>
|
2017-10-13 18:14:43 +08:00
|
|
|
|
public partial class ModIcon : Container, IHasTooltip
|
2017-02-17 04:05:03 +08:00
|
|
|
|
{
|
2019-11-22 01:34:19 +08:00
|
|
|
|
public readonly BindableBool Selected = new BindableBool();
|
2019-08-07 13:42:43 +08:00
|
|
|
|
|
2023-09-28 15:19:06 +08:00
|
|
|
|
private SpriteIcon modIcon = null!;
|
|
|
|
|
private SpriteText modAcronym = null!;
|
2023-09-28 17:30:38 +08:00
|
|
|
|
private Sprite background = null!;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-09-28 17:30:38 +08:00
|
|
|
|
public static readonly Vector2 MOD_ICON_SIZE = new Vector2(80);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-09-28 15:19:06 +08:00
|
|
|
|
public virtual LocalisableString TooltipText => showTooltip ? ((mod as Mod)?.IconTooltip ?? mod.Name) : string.Empty;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-09-10 11:43:12 +08:00
|
|
|
|
private IMod mod;
|
2023-09-27 18:21:10 +08:00
|
|
|
|
|
2021-01-26 18:11:19 +08:00
|
|
|
|
private readonly bool showTooltip;
|
2023-09-27 18:21:10 +08:00
|
|
|
|
private readonly bool showExtendedInformation;
|
2020-01-14 20:11:32 +08:00
|
|
|
|
|
2021-09-10 11:43:12 +08:00
|
|
|
|
public IMod Mod
|
2020-01-14 20:11:32 +08:00
|
|
|
|
{
|
|
|
|
|
get => mod;
|
2020-01-14 21:22:00 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2023-09-27 18:16:31 +08:00
|
|
|
|
if (mod == value)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-01-14 21:22:00 +08:00
|
|
|
|
mod = value;
|
2021-02-02 20:35:08 +08:00
|
|
|
|
|
|
|
|
|
if (IsLoaded)
|
|
|
|
|
updateMod(value);
|
2020-01-14 21:22:00 +08:00
|
|
|
|
}
|
2020-01-14 20:11:32 +08:00
|
|
|
|
}
|
2019-08-12 20:20:21 +08:00
|
|
|
|
|
2021-02-02 20:35:08 +08:00
|
|
|
|
[Resolved]
|
2023-09-28 15:19:06 +08:00
|
|
|
|
private OsuColour colours { get; set; } = null!;
|
2021-02-02 20:35:08 +08:00
|
|
|
|
|
|
|
|
|
private Color4 backgroundColour;
|
|
|
|
|
|
2023-09-28 15:19:06 +08:00
|
|
|
|
private Sprite extendedBackground = null!;
|
2023-09-27 17:54:47 +08:00
|
|
|
|
|
2023-09-28 15:19:06 +08:00
|
|
|
|
private OsuSpriteText extendedText = null!;
|
2023-09-27 17:54:47 +08:00
|
|
|
|
|
2023-09-28 15:19:06 +08:00
|
|
|
|
private Container extendedContent = null!;
|
2023-09-27 18:03:02 +08:00
|
|
|
|
|
2023-09-28 15:19:06 +08:00
|
|
|
|
private ModSettingChangeTracker? modSettingsChangeTracker;
|
2023-09-27 18:16:31 +08:00
|
|
|
|
|
2021-01-26 18:11:19 +08: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>
|
2023-09-27 18:21:10 +08:00
|
|
|
|
/// <param name="showExtendedInformation">Whether to display a mod's extended information, if available.</param>
|
|
|
|
|
public ModIcon(IMod mod, bool showTooltip = true, bool showExtendedInformation = true)
|
2017-05-03 14:48:10 +08:00
|
|
|
|
{
|
2023-09-28 17:30:38 +08:00
|
|
|
|
// May expand due to expanded content, so autosize here.
|
2023-09-27 18:03:02 +08:00
|
|
|
|
AutoSizeAxes = Axes.X;
|
2023-09-28 17:30:38 +08:00
|
|
|
|
Height = MOD_ICON_SIZE.Y;
|
2023-09-27 18:03:02 +08:00
|
|
|
|
|
2020-01-14 21:22:00 +08:00
|
|
|
|
this.mod = mod ?? throw new ArgumentNullException(nameof(mod));
|
2021-01-26 18:11:19 +08:00
|
|
|
|
this.showTooltip = showTooltip;
|
2023-09-27 18:21:10 +08:00
|
|
|
|
this.showExtendedInformation = showExtendedInformation;
|
2023-09-27 17:54:47 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-09-27 17:54:47 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(TextureStore textures)
|
|
|
|
|
{
|
2017-05-03 18:53:45 +08:00
|
|
|
|
Children = new Drawable[]
|
2017-02-17 04:05:03 +08:00
|
|
|
|
{
|
2023-09-28 17:30:38 +08:00
|
|
|
|
extendedContent = new Container
|
|
|
|
|
{
|
|
|
|
|
Name = "extended content",
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Size = new Vector2(116, MOD_ICON_SIZE.Y),
|
|
|
|
|
X = MOD_ICON_SIZE.X - 22,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
extendedBackground = new Sprite
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
FillMode = FillMode.Fit,
|
|
|
|
|
Texture = textures.Get("Icons/BeatmapDetails/mod-icon-extender"),
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
},
|
|
|
|
|
extendedText = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Font = OsuFont.Default.With(size: 34f, weight: FontWeight.Bold),
|
|
|
|
|
UseFullGlyphHeight = false,
|
|
|
|
|
Text = mod.ExtendedIconInformation,
|
2023-09-28 21:23:45 +08:00
|
|
|
|
X = 6,
|
2023-09-28 17:30:38 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
2023-09-27 18:03:02 +08:00
|
|
|
|
new Container
|
2017-05-03 14:48:10 +08:00
|
|
|
|
{
|
2023-09-27 18:03:02 +08:00
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Name = "main content",
|
2023-09-28 17:30:38 +08:00
|
|
|
|
Size = MOD_ICON_SIZE,
|
2023-09-27 18:03:02 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2023-09-28 17:30:38 +08:00
|
|
|
|
background = new Sprite
|
2023-09-27 18:03:02 +08:00
|
|
|
|
{
|
2023-09-28 17:30:38 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
FillMode = FillMode.Fit,
|
|
|
|
|
Texture = textures.Get("Icons/BeatmapDetails/mod-icon"),
|
2023-09-27 18:03:02 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
2023-09-28 17:30:38 +08:00
|
|
|
|
Origin = Anchor.Centre,
|
2023-09-27 18:03:02 +08:00
|
|
|
|
},
|
|
|
|
|
modAcronym = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
Font = OsuFont.Numeric.With(null, 22f),
|
|
|
|
|
UseFullGlyphHeight = false,
|
|
|
|
|
Text = mod.Acronym
|
|
|
|
|
},
|
|
|
|
|
modIcon = new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Size = new Vector2(45),
|
|
|
|
|
Icon = FontAwesome.Solid.Question
|
|
|
|
|
},
|
|
|
|
|
}
|
2017-05-03 18:53:45 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
2021-02-02 20:35:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
Selected.BindValueChanged(_ => updateColour());
|
2020-01-14 21:22:00 +08:00
|
|
|
|
|
|
|
|
|
updateMod(mod);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-10 11:43:12 +08:00
|
|
|
|
private void updateMod(IMod value)
|
2020-01-14 21:22:00 +08:00
|
|
|
|
{
|
2023-09-27 18:16:31 +08:00
|
|
|
|
modSettingsChangeTracker?.Dispose();
|
|
|
|
|
|
|
|
|
|
if (value is Mod actualMod)
|
|
|
|
|
{
|
|
|
|
|
modSettingsChangeTracker = new ModSettingChangeTracker(new[] { actualMod });
|
2023-09-28 21:18:28 +08:00
|
|
|
|
modSettingsChangeTracker.SettingChanged = _ => updateExtendedInformation();
|
2023-09-27 18:16:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-14 21:22:00 +08:00
|
|
|
|
modAcronym.Text = value.Acronym;
|
|
|
|
|
modIcon.Icon = value.Icon ?? FontAwesome.Solid.Question;
|
|
|
|
|
|
|
|
|
|
if (value.Icon is null)
|
|
|
|
|
{
|
|
|
|
|
modIcon.FadeOut();
|
|
|
|
|
modAcronym.FadeIn();
|
2021-02-02 20:35:08 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
modIcon.FadeIn();
|
|
|
|
|
modAcronym.FadeOut();
|
2020-01-14 21:22:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-12 13:36:50 +08:00
|
|
|
|
backgroundColour = colours.ForModType(value.Type);
|
2021-02-02 20:35:08 +08:00
|
|
|
|
updateColour();
|
2023-09-27 18:03:02 +08:00
|
|
|
|
|
2023-09-28 21:18:28 +08:00
|
|
|
|
updateExtendedInformation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateExtendedInformation()
|
|
|
|
|
{
|
2023-09-27 18:21:10 +08:00
|
|
|
|
bool showExtended = showExtendedInformation && !string.IsNullOrEmpty(mod.ExtendedIconInformation);
|
2023-09-27 18:03:02 +08:00
|
|
|
|
|
2023-09-27 18:21:10 +08:00
|
|
|
|
extendedContent.Alpha = showExtended ? 1 : 0;
|
2023-09-27 18:03:02 +08:00
|
|
|
|
extendedText.Text = mod.ExtendedIconInformation;
|
2017-02-17 04:05:03 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-02-02 20:35:08 +08:00
|
|
|
|
private void updateColour()
|
2017-05-08 10:33:22 +08:00
|
|
|
|
{
|
2023-11-06 23:40:57 +08:00
|
|
|
|
modAcronym.Colour = modIcon.Colour = OsuColour.Gray(84);
|
2023-11-06 18:24:56 +08:00
|
|
|
|
|
2023-09-27 17:54:47 +08:00
|
|
|
|
extendedText.Colour = background.Colour = Selected.Value ? backgroundColour.Lighten(0.2f) : backgroundColour;
|
|
|
|
|
extendedBackground.Colour = Selected.Value ? backgroundColour.Darken(2.4f) : backgroundColour.Darken(2.8f);
|
2017-05-08 10:33:22 +08:00
|
|
|
|
}
|
2023-09-27 18:16:31 +08:00
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
modSettingsChangeTracker?.Dispose();
|
|
|
|
|
}
|
2017-02-17 04:05:03 +08:00
|
|
|
|
}
|
2017-05-05 11:16:41 +08:00
|
|
|
|
}
|