2017-02-07 12:59:30 +08:00
|
|
|
|
// 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;
|
2017-01-13 12:49:05 +08:00
|
|
|
|
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;
|
2017-01-31 17:53:52 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2016-11-12 14:53:20 +08:00
|
|
|
|
|
2017-05-15 09:55:29 +08:00
|
|
|
|
namespace osu.Game.Overlays.Settings
|
2016-11-12 14:53:20 +08:00
|
|
|
|
{
|
|
|
|
|
public class SidebarButton : Container
|
|
|
|
|
{
|
2017-03-23 12:41:50 +08:00
|
|
|
|
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;
|
|
|
|
|
|
2017-05-15 09:55:29 +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()
|
|
|
|
|
{
|
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[]
|
|
|
|
|
{
|
2017-01-13 12:49:05 +08:00
|
|
|
|
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-13 12:49:05 +08:00
|
|
|
|
{
|
2017-02-07 15:15:45 +08:00
|
|
|
|
Width = Sidebar.DEFAULT_WIDTH,
|
2017-01-13 12:49:05 +08:00
|
|
|
|
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,
|
|
|
|
|
},
|
2017-01-13 12:49:05 +08:00
|
|
|
|
drawableIcon = new TextAwesome
|
2016-11-12 14:53:20 +08:00
|
|
|
|
{
|
2017-01-13 12:49:05 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2017-03-20 12:48:06 +08:00
|
|
|
|
TextSize = 20
|
2017-01-13 12:49:05 +08:00
|
|
|
|
},
|
2016-11-12 14:53:20 +08:00
|
|
|
|
}
|
2017-01-13 12:49:05 +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
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-13 12:49:05 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
2017-01-31 18:58:22 +08:00
|
|
|
|
selectionIndicator.Colour = colours.Yellow;
|
2017-01-13 12:49:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|