1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 23:07:26 +08:00
osu-lazer/osu.Game/Rulesets/UI/ModIcon.cs
Dean Herbert 0d9ea97828 Allow Rulesets to create a non-FontAwesome icon
This also
- Renames TextAwesome to SpriteIcon.
- Removes the default size of "20" from SpriteIcon (now defaults to the underlying texture size).
2017-08-03 14:36:21 +09:00

105 lines
2.9 KiB
C#

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Rulesets.Mods;
using OpenTK;
namespace osu.Game.Rulesets.UI
{
public class ModIcon : Container
{
private readonly SpriteIcon modIcon;
private readonly SpriteIcon background;
private const float icon_size = 80;
public FontAwesome Icon
{
get { return modIcon.Icon; }
set { modIcon.Icon = value; }
}
private readonly ModType type;
public ModIcon(Mod mod)
{
if (mod == null) throw new ArgumentNullException(nameof(mod));
type = mod.Type;
Children = new Drawable[]
{
background = new SpriteIcon
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Size = new Vector2(icon_size),
Icon = FontAwesome.fa_osu_mod_bg,
Shadow = true,
},
modIcon = new SpriteIcon
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Colour = OsuColour.Gray(84),
Size = new Vector2(icon_size - 35),
Icon = mod.Icon
},
};
}
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;
case ModType.DifficultyReduction:
backgroundColour = colours.Green;
highlightedColour = colours.GreenLight;
break;
case ModType.Special:
backgroundColour = colours.Blue;
highlightedColour = colours.BlueLight;
break;
}
applyStyle();
}
private bool highlighted;
public bool Highlighted
{
get
{
return highlighted;
}
set
{
highlighted = value;
applyStyle();
}
}
private void applyStyle()
{
background.Colour = highlighted ? highlightedColour : backgroundColour;
}
}
}