1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 15:07:44 +08:00

Refactor colour selection.

This commit is contained in:
Dean Herbert 2017-05-08 11:33:22 +09:00
parent df4a737c9b
commit 2f4fad9d41
2 changed files with 46 additions and 32 deletions

View File

@ -55,7 +55,7 @@ namespace osu.Game.Overlays.Mods
iconsContainer.RotateTo(Selected ? 5f : 0f, 300, EasingTypes.OutElastic);
iconsContainer.ScaleTo(Selected ? 1.1f : 1f, 300, EasingTypes.OutElastic);
foregroundIcon.Colour = Selected ? SelectedColour : ButtonColour;
foregroundIcon.Highlighted = Selected;
if (mod != null)
displayMod(SelectedMod ?? Mods[0]);
@ -64,12 +64,6 @@ namespace osu.Game.Overlays.Mods
public bool Selected => selectedIndex != -1;
private Color4 buttonColour;
public Color4 ButtonColour
{
get { return buttonColour; }
set { buttonColour = value; }
}
private Color4 selectedColour;
public Color4 SelectedColour
@ -198,8 +192,6 @@ namespace osu.Game.Overlays.Mods
AutoSizeAxes = Axes.Both,
});
}
buttonColour = foregroundIcon.Colour;
}
public ModButton(Mod mod)

View File

@ -3,6 +3,7 @@
using System;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
@ -17,65 +18,86 @@ namespace osu.Game.Rulesets.UI
private const float icon_size = 80;
public new Color4 Colour
{
get { return background.Colour; }
set { background.Colour = value; }
}
public FontAwesome Icon
{
get { return modIcon.Icon; }
set { modIcon.Icon = value; }
}
private ModType type;
public ModIcon(Mod mod)
{
if (mod == null) throw new ArgumentNullException(nameof(mod));
type = mod.Type;
Children = new Drawable[]
{
background = new TextAwesome
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
TextSize = icon_size,
Icon = FontAwesome.fa_osu_mod_bg,
Colour = getBackgroundColourFromMod(mod),
Shadow = true,
TextSize = 20
},
modIcon = new TextAwesome
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Colour = OsuColour.Gray(84),
TextSize = 20,
TextSize = icon_size - 35,
Icon = mod.Icon
},
};
reapplySize();
}
private void reapplySize()
{
background.TextSize = icon_size;
modIcon.TextSize = icon_size - 35;
}
private Color4 backgroundColour;
private Color4 highlightedColour;
private Color4 getBackgroundColourFromMod(Mod mod)
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
switch (mod.Type)
switch (type)
{
default:
case ModType.DifficultyIncrease:
return OsuColour.FromHex(@"ffcc22");
backgroundColour = colours.Yellow;
highlightedColour = colours.YellowLight;
break;
case ModType.DifficultyReduction:
return OsuColour.FromHex(@"88b300");
backgroundColour = colours.Green;
highlightedColour = colours.GreenLight;
break;
case ModType.Special:
return OsuColour.FromHex(@"66ccff");
default: return Color4.White;
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;
}
}
}