1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-19 05:22:57 +08:00
osu-lazer/osu.Game/Rulesets/UI/ModIcon.cs

104 lines
2.9 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.Game.Graphics;
2017-05-03 14:48:10 +08:00
using osu.Game.Rulesets.Mods;
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
{
private readonly TextAwesome modIcon;
private readonly TextAwesome background;
2017-02-17 04:05:03 +08:00
2017-05-05 12:22:10 +08:00
private const float icon_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-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;
2017-05-03 18:53:45 +08:00
Children = new Drawable[]
2017-02-17 04:05:03 +08:00
{
2017-05-03 18:53:45 +08:00
background = new TextAwesome
2017-05-03 14:48:10 +08:00
{
2017-05-03 18:53:45 +08:00
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
2017-05-08 10:33:22 +08:00
TextSize = icon_size,
2017-05-03 18:53:45 +08:00
Icon = FontAwesome.fa_osu_mod_bg,
Shadow = true,
},
modIcon = new TextAwesome
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Colour = OsuColour.Gray(84),
2017-05-08 10:33:22 +08:00
TextSize = icon_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
}
}