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

130 lines
4.0 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 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.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.Settings
2016-11-12 14:53:20 +08:00
{
public class SidebarButton : Container
{
private readonly TextAwesome drawableIcon;
private readonly SpriteText headerText;
private readonly Box backgroundBox;
private readonly Box selectionIndicator;
private readonly Container text;
2016-11-12 14:53:20 +08:00
public Action Action;
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()
{
2017-02-07 15:15:45 +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-02-07 15:15:45 +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
{
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 TextAwesome
2016-11-12 14:53:20 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
TextSize = 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)
{
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);
}
}
}