osu/osu.Game/Rulesets/UI/ModIcon.cs

106 lines
3.0 KiB
C#
Raw Normal View History

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