1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 22:02:54 +08:00
osu-lazer/osu.Game/Overlays/Settings/SidebarButton.cs

129 lines
3.9 KiB
C#
Raw Normal View History

2018-01-05 19:21:19 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2016-12-06 17:56:20 +08:00
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.Shapes;
2016-11-12 14:53:20 +08:00
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
2016-11-12 14:53:20 +08:00
namespace osu.Game.Overlays.Settings
2016-11-12 14:53:20 +08:00
{
public class SidebarButton : OsuButton
2016-11-12 14:53:20 +08:00
{
private readonly SpriteIcon drawableIcon;
private readonly SpriteText headerText;
private readonly Box selectionIndicator;
private readonly Container text;
2017-11-29 23:11:00 +08:00
public new Action<SettingsSection> Action;
2016-11-12 14:53:20 +08:00
private SettingsSection section;
public SettingsSection Section
2016-11-12 14:53:20 +08:00
{
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()
{
BackgroundColour = OsuColour.Gray(60);
Background.Alpha = 0;
2017-02-07 15:15:45 +08:00
Height = Sidebar.DEFAULT_WIDTH;
2016-11-12 14:53:20 +08:00
RelativeSizeAxes = Axes.X;
AddRange(new Drawable[]
2016-11-12 14:53:20 +08:00
{
2017-01-31 18:58:38 +08:00
text = new Container
{
2017-02-07 15:15:45 +08:00
Width = Sidebar.DEFAULT_WIDTH,
RelativeSizeAxes = Axes.Y,
2017-05-21 04:32:15 +08:00
Colour = OsuColour.Gray(0.6f),
Children = new Drawable[]
2016-11-12 14:53:20 +08:00
{
2017-01-31 18:58:38 +08:00
headerText = new OsuSpriteText
{
2017-02-07 15:15:45 +08:00
Position = new Vector2(Sidebar.DEFAULT_WIDTH + 10, 0),
2017-01-31 18:58:38 +08:00
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
drawableIcon = new SpriteIcon
2016-11-12 14:53:20 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(20),
},
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)
{
2017-05-21 04:32:15 +08:00
Action?.Invoke(section);
return base.OnClick(state);
2016-11-12 14:53:20 +08:00
}
protected override bool OnHover(InputState state)
{
Background.FadeTo(0.4f, 200);
2016-11-12 14:53:20 +08:00
return base.OnHover(state);
}
protected override void OnHoverLost(InputState state)
{
Background.FadeTo(0, 200);
2016-11-12 14:53:20 +08:00
base.OnHoverLost(state);
}
}
}