1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-26 03:52:57 +08:00
osu-lazer/osu.Game/Rulesets/UI/ModIcon.cs

113 lines
3.1 KiB
C#
Raw Normal View History

2017-03-08 14:50:52 +08:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
2017-02-17 04:05:03 +08:00
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
2017-02-17 04:05:03 +08:00
using OpenTK.Graphics;
2017-05-08 10:33:22 +08:00
using osu.Framework.Allocation;
2017-02-17 04:05:03 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
2017-02-17 04:05:03 +08:00
using osu.Game.Graphics;
2017-05-03 14:48:10 +08:00
using osu.Game.Rulesets.Mods;
using OpenTK;
2017-02-17 04:05:03 +08:00
2017-04-18 15:05:58 +08:00
namespace osu.Game.Rulesets.UI
2017-02-17 04:05:03 +08:00
{
public class ModIcon : Container, IHasTooltip
2017-02-17 04:05:03 +08:00
{
private readonly SpriteIcon modIcon;
private readonly SpriteIcon background;
2017-02-17 04:05:03 +08:00
2017-11-15 23:15:27 +08:00
private const float size = 80;
2017-02-17 04:05:03 +08:00
public FontAwesome Icon
{
2017-05-03 14:48:10 +08:00
get { return modIcon.Icon; }
set { modIcon.Icon = value; }
}
2017-05-08 10:47:06 +08:00
private readonly ModType type;
2017-05-08 10:33:22 +08:00
2017-12-16 17:16:40 +08:00
public virtual string TooltipText { get; }
2017-05-04 22:29:52 +08:00
public ModIcon(Mod mod)
2017-05-03 14:48:10 +08:00
{
if (mod == null) throw new ArgumentNullException(nameof(mod));
2017-05-08 10:33:22 +08:00
type = mod.Type;
TooltipText = mod.Name;
2017-11-15 23:15:27 +08:00
Size = new Vector2(size);
2017-05-03 18:53:45 +08:00
Children = new Drawable[]
2017-02-17 04:05:03 +08:00
{
background = new SpriteIcon
2017-05-03 14:48:10 +08:00
{
2017-05-03 18:53:45 +08:00
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
2017-11-15 23:15:27 +08:00
Size = new Vector2(size),
2017-05-03 18:53:45 +08:00
Icon = FontAwesome.fa_osu_mod_bg,
2017-11-15 23:15:27 +08:00
Y = -6.5f,
2017-05-03 18:53:45 +08:00
Shadow = true,
},
modIcon = new SpriteIcon
2017-05-03 18:53:45 +08:00
{
2017-11-15 23:15:27 +08:00
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
2017-05-03 18:53:45 +08:00
Colour = OsuColour.Gray(84),
2017-11-15 23:15:27 +08:00
Size = new Vector2(size - 35),
Icon = mod.Icon
2017-05-03 18:53:45 +08:00
},
};
2017-02-17 04:05:03 +08:00
}
2017-05-08 10:33:22 +08:00
private Color4 backgroundColour;
private Color4 highlightedColour;
2017-02-17 04:05:03 +08:00
2017-05-08 10:33:22 +08:00
[BackgroundDependencyLoader]
private void load(OsuColour colours)
2017-02-17 04:05:03 +08:00
{
2017-05-08 10:33:22 +08:00
switch (type)
2017-02-17 04:05:03 +08:00
{
2017-05-08 10:33:22 +08:00
default:
2017-05-03 14:48:10 +08:00
case ModType.DifficultyIncrease:
2017-05-08 10:33:22 +08:00
backgroundColour = colours.Yellow;
highlightedColour = colours.YellowLight;
break;
2017-05-03 14:48:10 +08:00
case ModType.DifficultyReduction:
2017-05-08 10:33:22 +08:00
backgroundColour = colours.Green;
highlightedColour = colours.GreenLight;
break;
2017-05-03 14:48:10 +08:00
case ModType.Special:
2017-05-08 10:33:22 +08:00
backgroundColour = colours.Blue;
highlightedColour = colours.BlueLight;
break;
}
applyStyle();
}
private bool highlighted;
public bool Highlighted
{
get
{
return highlighted;
}
2017-02-17 04:05:03 +08:00
2017-05-08 10:33:22 +08:00
set
{
highlighted = value;
applyStyle();
2017-05-03 14:48:10 +08:00
}
2017-02-17 04:05:03 +08:00
}
2017-05-08 10:33:22 +08:00
private void applyStyle()
{
background.Colour = highlighted ? highlightedColour : backgroundColour;
}
2017-02-17 04:05:03 +08:00
}
}