osu/osu.Game/Graphics/UserInterface/SettingsContainer.cs

151 lines
5.1 KiB
C#
Raw Normal View History

2017-05-17 07:36:57 +00:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using OpenTK.Graphics;
2017-05-18 04:09:36 +00:00
using osu.Framework.Allocation;
2017-05-17 07:36:57 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics.Sprites;
2017-05-18 08:39:22 +00:00
namespace osu.Game.Graphics.UserInterface
2017-05-17 07:36:57 +00:00
{
2017-05-18 08:39:22 +00:00
public abstract class SettingsContainer : Container
2017-05-17 07:36:57 +00:00
{
/// <summary>
/// The title of this option.
/// </summary>
public abstract string Title { get; }
2017-05-18 08:39:22 +00:00
private readonly SettingsDropdown content;
2017-05-18 04:09:36 +00:00
private readonly SimpleButton button;
2017-05-17 14:24:52 +00:00
private bool contentIsVisible;
2017-05-17 12:39:26 +00:00
2017-05-18 08:39:22 +00:00
protected SettingsContainer()
2017-05-17 07:36:57 +00:00
{
2017-05-17 12:39:26 +00:00
AutoSizeAxes = Axes.Y;
Width = 250;
2017-05-17 07:36:57 +00:00
Masking = true;
CornerRadius = 5;
BorderColour = Color4.Black;
BorderThickness = 2;
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
Alpha = 0.5f,
},
2017-05-17 12:39:26 +00:00
new FillFlowContainer
2017-05-17 07:36:57 +00:00
{
2017-05-17 12:39:26 +00:00
Direction = FillDirection.Vertical,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
2017-05-17 14:14:09 +00:00
new Container
2017-05-17 12:39:26 +00:00
{
RelativeSizeAxes = Axes.X,
Height = 30,
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Children = new Drawable[]
{
new OsuSpriteText
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
Text = Title,
TextSize = 17,
Font = @"Exo2.0-Bold",
Margin = new MarginPadding { Left = 10 },
},
2017-05-18 04:09:36 +00:00
button = new SimpleButton
2017-05-17 12:39:26 +00:00
{
Origin = Anchor.Centre,
Anchor = Anchor.CentreRight,
Position = new Vector2(-15,0),
Icon = FontAwesome.fa_bars,
Scale = new Vector2(0.7f),
2017-05-17 14:24:52 +00:00
Action = () => triggerContentVisibility(),
2017-05-17 12:39:26 +00:00
},
}
},
2017-05-18 08:39:22 +00:00
content = new SettingsDropdown
2017-05-17 12:39:26 +00:00
{
RelativeSizeAxes = Axes.X,
}
}
2017-05-17 07:36:57 +00:00
},
};
}
2017-05-17 12:39:26 +00:00
2017-05-18 04:09:36 +00:00
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
content.StateChanged += (c, s) => button.FadeColour(s == Visibility.Visible ? colours.Yellow : Color4.White, 200, EasingTypes.OutQuint);
}
2017-05-17 12:39:26 +00:00
public new void Add(Drawable drawable)
{
content.Add(drawable);
}
2017-05-17 14:24:52 +00:00
private void triggerContentVisibility()
{
2017-05-18 04:09:36 +00:00
contentIsVisible = !contentIsVisible;
2017-05-17 14:24:52 +00:00
if (contentIsVisible)
content.Show();
else
content.Hide();
}
2017-05-18 08:39:22 +00:00
private class SettingsDropdown : OverlayContainer
{
private const float transition_duration = 600;
2017-05-18 08:50:15 +00:00
private readonly FillFlowContainer content;
2017-05-18 08:39:22 +00:00
public SettingsDropdown()
{
Children = new Drawable[]
{
content = new FillFlowContainer
{
Direction = FillDirection.Vertical,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Padding = new MarginPadding(15),
Spacing = new Vector2(0, 10),
}
};
}
public new void Add(Drawable drawable)
{
content.Add(drawable);
}
protected override void PopIn()
{
ResizeTo(new Vector2(1, content.Height), transition_duration, EasingTypes.OutQuint);
FadeIn(transition_duration, EasingTypes.OutQuint);
}
protected override void PopOut()
{
ResizeTo(new Vector2(1, 0), transition_duration, EasingTypes.OutQuint);
FadeOut(transition_duration);
}
}
2017-05-17 07:36:57 +00:00
}
}