1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-23 04:02:57 +08:00
osu-lazer/osu.Game/Overlays/Settings/SidebarButton.cs

131 lines
3.8 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2018-04-13 17:19:50 +08:00
using System;
2018-11-20 15:51:59 +08:00
using osuTK;
using osuTK.Graphics;
2018-04-13 17:19:50 +08:00
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
2018-10-02 11:02:47 +08:00
using osu.Framework.Input.Events;
2018-04-13 17:19:50 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Overlays.Settings
{
public class SidebarButton : Button
2018-04-13 17:19:50 +08:00
{
private readonly SpriteIcon drawableIcon;
private readonly SpriteText headerText;
private readonly Box selectionIndicator;
private readonly Container text;
public new Action<SettingsSection> Action;
private SettingsSection section;
2019-02-28 12:31:40 +08:00
2018-04-13 17:19:50 +08:00
public SettingsSection Section
{
get => section;
2018-04-13 17:19:50 +08:00
set
{
section = value;
headerText.Text = value.Header;
drawableIcon.Icon = value.Icon;
}
}
private bool selected;
2019-02-28 12:31:40 +08:00
2018-04-13 17:19:50 +08:00
public bool Selected
{
get => selected;
2018-04-13 17:19:50 +08:00
set
{
selected = value;
2019-04-01 11:16:05 +08:00
2018-04-13 17:19:50 +08:00
if (selected)
{
selectionIndicator.FadeIn(50);
text.FadeColour(Color4.White, 50);
}
else
{
selectionIndicator.FadeOut(50);
text.FadeColour(OsuColour.Gray(0.6f), 50);
}
}
}
public SidebarButton()
{
BackgroundColour = OsuColour.Gray(60);
Background.Alpha = 0;
Height = Sidebar.DEFAULT_WIDTH;
RelativeSizeAxes = Axes.X;
AddRange(new Drawable[]
{
text = new Container
{
Width = Sidebar.DEFAULT_WIDTH,
RelativeSizeAxes = Axes.Y,
Colour = OsuColour.Gray(0.6f),
Children = new Drawable[]
{
headerText = new OsuSpriteText
{
Position = new Vector2(Sidebar.DEFAULT_WIDTH + 10, 0),
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
drawableIcon = new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(20),
},
}
},
selectionIndicator = new Box
{
Alpha = 0,
RelativeSizeAxes = Axes.Y,
Width = 5,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
},
new HoverClickSounds(HoverSampleSet.Loud),
2018-04-13 17:19:50 +08:00
});
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
selectionIndicator.Colour = colours.Yellow;
}
2018-10-02 11:02:47 +08:00
protected override bool OnClick(ClickEvent e)
2018-04-13 17:19:50 +08:00
{
Action?.Invoke(section);
2018-10-02 11:02:47 +08:00
return base.OnClick(e);
2018-04-13 17:19:50 +08:00
}
2018-10-02 11:02:47 +08:00
protected override bool OnHover(HoverEvent e)
2018-04-13 17:19:50 +08:00
{
Background.FadeTo(0.4f, 200);
2018-10-02 11:02:47 +08:00
return base.OnHover(e);
2018-04-13 17:19:50 +08:00
}
2018-10-02 11:02:47 +08:00
protected override void OnHoverLost(HoverLostEvent e)
2018-04-13 17:19:50 +08:00
{
Background.FadeTo(0, 200);
2018-10-02 11:02:47 +08:00
base.OnHoverLost(e);
2018-04-13 17:19:50 +08:00
}
}
}