osu/osu.Game/Overlays/MainSettings.cs

152 lines
5.4 KiB
C#
Raw Normal View History

2018-01-05 11:21:19 +00:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
2017-08-10 13:21:22 +00:00
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using osu.Framework.Allocation;
2017-08-10 13:21:22 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2017-08-16 14:20:18 +00:00
using osu.Framework.Input;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
2017-08-10 13:21:22 +00:00
using osu.Game.Overlays.Settings;
using osu.Game.Overlays.Settings.Sections;
2017-08-16 14:20:18 +00:00
using osu.Game.Screens.Ranking;
using OpenTK;
using OpenTK.Graphics;
2017-08-10 13:21:22 +00:00
namespace osu.Game.Overlays
{
public class MainSettings : SettingsOverlay
{
private readonly KeyBindingOverlay keyBindingOverlay;
2017-08-16 14:20:18 +00:00
private BackButton backButton;
2017-08-10 13:21:22 +00:00
protected override IEnumerable<SettingsSection> CreateSections() => new SettingsSection[]
{
new GeneralSection(),
new GraphicsSection(),
new GameplaySection(),
new AudioSection(),
new SkinSection(),
new InputSection(keyBindingOverlay),
2017-08-10 13:21:22 +00:00
new OnlineSection(),
new MaintenanceSection(),
new DebugSection(),
};
protected override Drawable CreateHeader() => new SettingsHeader("settings", "Change the way osu! behaves");
protected override Drawable CreateFooter() => new SettingsFooter();
public MainSettings()
: base(true)
{
2017-08-17 09:11:15 +00:00
keyBindingOverlay = new KeyBindingOverlay
{
Depth = 1,
Anchor = Anchor.TopRight,
};
keyBindingOverlay.StateChanged += keyBindingOverlay_StateChanged;
}
public override bool AcceptsFocus => keyBindingOverlay.State != Visibility.Visible;
private const float hidden_width = 120;
2017-09-04 00:10:04 +00:00
private void keyBindingOverlay_StateChanged(Visibility visibility)
{
switch (visibility)
{
case Visibility.Visible:
Background.FadeTo(0.9f, 300, Easing.OutQuint);
Sidebar?.FadeColour(Color4.DarkGray, 300, Easing.OutQuint);
SectionsContainer.FadeOut(300, Easing.OutQuint);
ContentContainer.MoveToX(hidden_width - WIDTH, 500, Easing.OutQuint);
2017-08-16 14:20:18 +00:00
backButton.Delay(100).FadeIn(100);
break;
case Visibility.Hidden:
Background.FadeTo(0.6f, 500, Easing.OutQuint);
Sidebar?.FadeColour(Color4.White, 300, Easing.OutQuint);
SectionsContainer.FadeIn(500, Easing.OutQuint);
ContentContainer.MoveToX(0, 500, Easing.OutQuint);
2017-08-16 14:20:18 +00:00
backButton.FadeOut(100);
break;
}
}
protected override float ExpandedPosition => keyBindingOverlay.State == Visibility.Visible ? hidden_width - WIDTH : base.ExpandedPosition;
[BackgroundDependencyLoader]
private void load()
{
ContentContainer.Add(keyBindingOverlay);
ContentContainer.Add(backButton = new BackButton
2017-08-16 14:20:18 +00:00
{
Alpha = 0,
Width = hidden_width,
RelativeSizeAxes = Axes.Y,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
2017-08-16 14:20:18 +00:00
Action = () => keyBindingOverlay.Hide()
});
}
2017-08-16 14:20:18 +00:00
private class BackButton : OsuClickableContainer
{
private AspectContainer aspect;
[BackgroundDependencyLoader]
private void load()
{
Children = new Drawable[]
{
aspect = new AspectContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Y,
Children = new Drawable[]
{
new SpriteIcon
2017-08-16 14:20:18 +00:00
{
Anchor = Anchor.Centre,
2017-08-16 14:20:18 +00:00
Origin = Anchor.Centre,
Y = -15,
Size = new Vector2(15),
Shadow = true,
Icon = FontAwesome.fa_chevron_left
2017-08-16 14:20:18 +00:00
},
new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Y = 15,
2017-08-16 14:20:18 +00:00
TextSize = 12,
Font = @"Exo2.0-Bold",
Text = @"back",
},
}
}
};
}
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{
aspect.ScaleTo(0.75f, 2000, Easing.OutQuint);
return base.OnMouseDown(state, args);
}
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
{
aspect.ScaleTo(1, 1000, Easing.OutElastic);
return base.OnMouseUp(state, args);
}
}
2017-08-10 13:21:22 +00:00
}
}