Merge pull request #4203 from EVAST9919/keybindings-settings-groups

Use sidebar in key bindings overlay
This commit is contained in:
Dan Balasescu 2019-02-05 12:11:29 +09:00 committed by GitHub
commit e33277bd76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 87 additions and 97 deletions

View File

@ -9,7 +9,7 @@ namespace osu.Game.Overlays.KeyBinding
{
public class GlobalKeyBindingsSection : SettingsSection
{
public override FontAwesome Icon => FontAwesome.fa_osu_hot;
public override FontAwesome Icon => FontAwesome.fa_globe;
public override string Header => "Global";
public GlobalKeyBindingsSection(GlobalActionContainer manager)

View File

@ -9,7 +9,7 @@ namespace osu.Game.Overlays.KeyBinding
{
public class RulesetBindingsSection : SettingsSection
{
public override FontAwesome Icon => FontAwesome.fa_osu_hot;
public override FontAwesome Icon => (ruleset.CreateInstance().CreateIcon() as SpriteIcon)?.Icon ?? FontAwesome.fa_osu_hot;
public override string Header => ruleset.Name;
private readonly RulesetInfo ruleset;

View File

@ -3,10 +3,17 @@
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Input.Bindings;
using osu.Game.Overlays.KeyBinding;
using osu.Game.Overlays.Settings;
using osu.Game.Rulesets;
using osu.Game.Screens.Ranking;
using osuTK;
namespace osu.Game.Overlays
{
@ -21,11 +28,85 @@ private void load(RulesetStore rulesets, GlobalActionContainer global)
foreach (var ruleset in rulesets.AvailableRulesets)
AddSection(new RulesetBindingsSection(ruleset));
AddInternal(new BackButton
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Action = Hide
});
}
public KeyBindingOverlay()
: base(false)
: base(true)
{
}
private class BackButton : OsuClickableContainer, IKeyBindingHandler<GlobalAction>
{
private AspectContainer aspect;
[BackgroundDependencyLoader]
private void load()
{
Size = new Vector2(Sidebar.DEFAULT_WIDTH);
Children = new Drawable[]
{
aspect = new AspectContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Y,
Children = new Drawable[]
{
new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Y = -15,
Size = new Vector2(15),
Shadow = true,
Icon = FontAwesome.fa_chevron_left
},
new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Y = 15,
TextSize = 12,
Font = @"Exo2.0-Bold",
Text = @"back",
},
}
}
};
}
protected override bool OnMouseDown(MouseDownEvent e)
{
aspect.ScaleTo(0.75f, 2000, Easing.OutQuint);
return base.OnMouseDown(e);
}
protected override bool OnMouseUp(MouseUpEvent e)
{
aspect.ScaleTo(1, 1000, Easing.OutElastic);
return base.OnMouseUp(e);
}
public bool OnPressed(GlobalAction action)
{
switch (action)
{
case GlobalAction.Back:
Click();
return true;
}
return false;
}
public bool OnReleased(GlobalAction action) => false;
}
}
}

View File

@ -1,28 +1,19 @@
// 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.
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Input.Bindings;
using osu.Game.Overlays.Settings;
using osu.Game.Overlays.Settings.Sections;
using osu.Game.Screens.Ranking;
using osuTK;
using osuTK.Graphics;
using System.Collections.Generic;
namespace osu.Game.Overlays
{
public class MainSettings : SettingsOverlay
{
private readonly KeyBindingOverlay keyBindingOverlay;
private BackButton backButton;
protected override IEnumerable<SettingsSection> CreateSections() => new SettingsSection[]
{
@ -53,8 +44,6 @@ public MainSettings()
public override bool AcceptsFocus => keyBindingOverlay.State != Visibility.Visible;
private const float hidden_width = 120;
private void keyBindingOverlay_StateChanged(Visibility visibility)
{
switch (visibility)
@ -64,9 +53,7 @@ private void keyBindingOverlay_StateChanged(Visibility visibility)
Sidebar?.FadeColour(Color4.DarkGray, 300, Easing.OutQuint);
SectionsContainer.FadeOut(300, Easing.OutQuint);
ContentContainer.MoveToX(hidden_width - WIDTH, 500, Easing.OutQuint);
backButton.Delay(100).FadeIn(100);
ContentContainer.MoveToX(-WIDTH, 500, Easing.OutQuint);
break;
case Visibility.Hidden:
Background.FadeTo(0.6f, 500, Easing.OutQuint);
@ -74,94 +61,16 @@ private void keyBindingOverlay_StateChanged(Visibility visibility)
SectionsContainer.FadeIn(500, Easing.OutQuint);
ContentContainer.MoveToX(0, 500, Easing.OutQuint);
backButton.FadeOut(100);
break;
}
}
protected override float ExpandedPosition => keyBindingOverlay.State == Visibility.Visible ? hidden_width - WIDTH : base.ExpandedPosition;
protected override float ExpandedPosition => keyBindingOverlay.State == Visibility.Visible ? -WIDTH : base.ExpandedPosition;
[BackgroundDependencyLoader]
private void load()
{
ContentContainer.Add(keyBindingOverlay);
ContentContainer.Add(backButton = new BackButton
{
Alpha = 0,
Width = hidden_width,
RelativeSizeAxes = Axes.Y,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Action = () => keyBindingOverlay.Hide()
});
}
private class BackButton : OsuClickableContainer, IKeyBindingHandler<GlobalAction>
{
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
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Y = -15,
Size = new Vector2(15),
Shadow = true,
Icon = FontAwesome.fa_chevron_left
},
new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Y = 15,
TextSize = 12,
Font = @"Exo2.0-Bold",
Text = @"back",
},
}
}
};
}
protected override bool OnMouseDown(MouseDownEvent e)
{
aspect.ScaleTo(0.75f, 2000, Easing.OutQuint);
return base.OnMouseDown(e);
}
protected override bool OnMouseUp(MouseUpEvent e)
{
aspect.ScaleTo(1, 1000, Easing.OutElastic);
return base.OnMouseUp(e);
}
public bool OnPressed(GlobalAction action)
{
switch (action)
{
case GlobalAction.Back:
Click();
return true;
}
return false;
}
public bool OnReleased(GlobalAction action) => false;
}
}
}