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
|
|
|
|
|
|
|
|
|
using System;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2019-03-27 10:29:27 +00:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Graphics;
|
2020-01-14 13:22:00 +00:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-04-13 09:19:50 +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;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.UI
|
|
|
|
|
{
|
2021-01-26 10:11:19 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Display the specified mod at a fixed size.
|
|
|
|
|
/// </summary>
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public class ModIcon : Container, IHasTooltip
|
|
|
|
|
{
|
2019-11-21 17:34:19 +00:00
|
|
|
|
public readonly BindableBool Selected = new BindableBool();
|
2019-08-07 05:42:43 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
private readonly SpriteIcon modIcon;
|
2020-01-14 13:22:00 +00:00
|
|
|
|
private readonly SpriteText modAcronym;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
private readonly SpriteIcon background;
|
|
|
|
|
|
|
|
|
|
private const float size = 80;
|
|
|
|
|
|
|
|
|
|
private readonly ModType type;
|
|
|
|
|
|
2021-01-26 10:11:19 +00:00
|
|
|
|
public virtual string TooltipText => showTooltip ? mod.IconTooltip : null;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-01-14 12:11:32 +00:00
|
|
|
|
private Mod mod;
|
2021-01-26 10:11:19 +00:00
|
|
|
|
private readonly bool showTooltip;
|
2020-01-14 12:11:32 +00:00
|
|
|
|
|
|
|
|
|
public Mod Mod
|
|
|
|
|
{
|
|
|
|
|
get => mod;
|
2020-01-14 13:22:00 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
mod = value;
|
|
|
|
|
updateMod(value);
|
|
|
|
|
}
|
2020-01-14 12:11:32 +00:00
|
|
|
|
}
|
2019-08-12 12:20:21 +00:00
|
|
|
|
|
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>
|
|
|
|
|
public ModIcon(Mod mod, bool showTooltip = true)
|
2018-04-13 09:19:50 +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
|
|
|
|
|
|
|
|
|
type = mod.Type;
|
|
|
|
|
|
|
|
|
|
Size = new Vector2(size);
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
background = new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Size = new Vector2(size),
|
2019-03-27 10:29:27 +00:00
|
|
|
|
Icon = OsuIcon.ModBg,
|
2018-04-13 09:19:50 +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
|
|
|
|
|
},
|
2018-04-13 09:19:50 +00:00
|
|
|
|
modIcon = new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
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
|
2018-04-13 09:19:50 +00:00
|
|
|
|
},
|
|
|
|
|
};
|
2020-01-14 13:22:00 +00:00
|
|
|
|
|
|
|
|
|
updateMod(mod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateMod(Mod value)
|
|
|
|
|
{
|
|
|
|
|
modAcronym.Text = value.Acronym;
|
|
|
|
|
modIcon.Icon = value.Icon ?? FontAwesome.Solid.Question;
|
|
|
|
|
|
|
|
|
|
if (value.Icon is null)
|
|
|
|
|
{
|
|
|
|
|
modIcon.FadeOut();
|
|
|
|
|
modAcronym.FadeIn();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
modIcon.FadeIn();
|
|
|
|
|
modAcronym.FadeOut();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Color4 backgroundColour;
|
|
|
|
|
private Color4 highlightedColour;
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
default:
|
|
|
|
|
case ModType.DifficultyIncrease:
|
|
|
|
|
backgroundColour = colours.Yellow;
|
|
|
|
|
highlightedColour = colours.YellowLight;
|
|
|
|
|
break;
|
2019-04-01 03:44:46 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
case ModType.DifficultyReduction:
|
|
|
|
|
backgroundColour = colours.Green;
|
|
|
|
|
highlightedColour = colours.GreenLight;
|
|
|
|
|
break;
|
2019-04-01 03:44:46 +00:00
|
|
|
|
|
2018-07-31 09:00:42 +00:00
|
|
|
|
case ModType.Automation:
|
2018-04-13 09:19:50 +00:00
|
|
|
|
backgroundColour = colours.Blue;
|
|
|
|
|
highlightedColour = colours.BlueLight;
|
|
|
|
|
break;
|
2019-04-01 03:44:46 +00:00
|
|
|
|
|
2018-07-31 09:00:42 +00:00
|
|
|
|
case ModType.Conversion:
|
|
|
|
|
backgroundColour = colours.Purple;
|
|
|
|
|
highlightedColour = colours.PurpleLight;
|
|
|
|
|
break;
|
2019-04-01 03:44:46 +00:00
|
|
|
|
|
2018-07-31 09:00:42 +00:00
|
|
|
|
case ModType.Fun:
|
|
|
|
|
backgroundColour = colours.Pink;
|
|
|
|
|
highlightedColour = colours.PinkLight;
|
|
|
|
|
break;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-09-20 20:47:21 +00:00
|
|
|
|
case ModType.System:
|
2019-08-07 05:42:43 +00:00
|
|
|
|
backgroundColour = colours.Gray6;
|
|
|
|
|
highlightedColour = colours.Gray7;
|
|
|
|
|
modIcon.Colour = colours.Yellow;
|
|
|
|
|
break;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-07 05:42:43 +00:00
|
|
|
|
protected override void LoadComplete()
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-08-07 05:42:43 +00:00
|
|
|
|
base.LoadComplete();
|
2019-11-21 17:37:02 +00:00
|
|
|
|
Selected.BindValueChanged(selected => background.Colour = selected.NewValue ? highlightedColour : backgroundColour, true);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|