1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 01:47:24 +08:00
osu-lazer/osu.Game/Overlays/Options/SidebarButton.cs

129 lines
3.9 KiB
C#
Raw Normal View History

2016-12-06 17:56:20 +08:00
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
2016-11-12 14:53:20 +08:00
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Allocation;
2016-11-12 14:53:20 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
2016-11-12 14:53:20 +08:00
namespace osu.Game.Overlays.Options
{
public class SidebarButton : Container
{
private TextAwesome drawableIcon;
private SpriteText headerText;
private Box backgroundBox;
private Box selectionIndicator;
2017-01-31 18:58:38 +08:00
public Container text;
2016-11-12 14:53:20 +08:00
public Action Action;
private OptionsSection section;
public OptionsSection Section
{
get
{
return section;
}
set
{
section = value;
headerText.Text = value.Header;
drawableIcon.Icon = value.Icon;
}
}
private bool selected;
public bool Selected
{
get { return selected; }
set
{
selected = value;
if (selected)
2017-01-31 18:58:38 +08:00
{
2016-11-12 14:53:20 +08:00
selectionIndicator.FadeIn(50);
2017-01-31 18:58:38 +08:00
text.FadeColour(Color4.White, 50);
}
2016-11-12 14:53:20 +08:00
else
2017-01-31 18:58:38 +08:00
{
2016-11-12 14:53:20 +08:00
selectionIndicator.FadeOut(50);
2017-01-31 18:58:38 +08:00
text.FadeColour(OsuColour.Gray(0.6f), 50);
}
2016-11-12 14:53:20 +08:00
}
}
public SidebarButton()
{
2017-01-31 18:58:38 +08:00
Height = Sidebar.default_width;
2016-11-12 14:53:20 +08:00
RelativeSizeAxes = Axes.X;
Children = new Drawable[]
{
backgroundBox = new Box
{
RelativeSizeAxes = Axes.Both,
BlendingMode = BlendingMode.Additive,
Colour = OsuColour.Gray(60),
Alpha = 0,
},
2017-01-31 18:58:38 +08:00
text = new Container
{
2017-01-31 18:58:38 +08:00
Width = Sidebar.default_width,
RelativeSizeAxes = Axes.Y,
Children = new[]
2016-11-12 14:53:20 +08:00
{
2017-01-31 18:58:38 +08:00
headerText = new OsuSpriteText
{
Position = new Vector2(Sidebar.default_width + 10, 0),
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
drawableIcon = new TextAwesome
2016-11-12 14:53:20 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
2016-11-12 14:53:20 +08:00
}
},
selectionIndicator = new Box
{
Alpha = 0,
RelativeSizeAxes = Axes.Y,
Width = 5,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
}
2016-11-12 14:53:20 +08:00
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
2017-01-31 18:58:22 +08:00
selectionIndicator.Colour = colours.Yellow;
}
2016-11-12 14:53:20 +08:00
protected override bool OnClick(InputState state)
{
Action?.Invoke();
backgroundBox.FlashColour(Color4.White, 400);
return true;
}
protected override bool OnHover(InputState state)
{
backgroundBox.FadeTo(0.4f, 200);
return base.OnHover(state);
}
protected override void OnHoverLost(InputState state)
{
backgroundBox.FadeTo(0, 200);
base.OnHoverLost(state);
}
}
}