1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 21:02:55 +08:00

Integrate key binding config with main settings

This commit is contained in:
Dean Herbert 2017-08-16 19:17:42 +09:00
parent 7e21ddb5eb
commit 5ebec53970
5 changed files with 139 additions and 65 deletions

View File

@ -11,7 +11,6 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Input;
@ -106,12 +105,6 @@ namespace osu.Game.Overlays.KeyBinding
}
};
reloadBindings();
}
private void reloadBindings()
{
buttons.Clear();
foreach (var b in bindings)
buttons.Add(new KeyButton(b));
}
@ -149,23 +142,46 @@ namespace osu.Game.Overlays.KeyBinding
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
if (HasFocus && !isModifier(args.Key))
if (args.Key == Key.Delete)
{
bindTarget.KeyBinding.KeyCombination = args.Key == Key.Delete ? Key.Unknown : new KeyCombination(state.Keyboard.Keys);
bindTarget.UpdateKeyCombination(Key.Unknown);
store.Update(bindTarget.KeyBinding);
GetContainingInputManager().ChangeFocus(null);
return true;
}
if (HasFocus)
{
bindTarget.UpdateKeyCombination(state.Keyboard.Keys.ToArray());
if (!isModifier(args.Key))
finalise();
return true;
}
return base.OnKeyDown(state, args);
}
protected override bool OnKeyUp(InputState state, KeyUpEventArgs args)
{
if (HasFocus)
{
finalise();
return true;
}
return base.OnKeyUp(state, args);
}
private void finalise()
{
store.Update(bindTarget.KeyBinding);
GetContainingInputManager().ChangeFocus(null);
}
protected override void OnFocusLost(InputState state)
{
bindTarget.IsBinding = false;
bindTarget = null;
reloadBindings();
pressAKey.FadeOut(300, Easing.OutQuint);
pressAKey.Padding = new MarginPadding { Bottom = -pressAKey.DrawHeight };
@ -197,19 +213,16 @@ namespace osu.Game.Overlays.KeyBinding
get { return isBinding; }
set
{
if (value == isBinding) return;
isBinding = value;
if (value)
if (isBinding)
{
box.FadeColour(Color4.White, transition_time, Easing.OutQuint);
Text.FadeColour(Color4.Black, transition_time, Easing.OutQuint);
}
else
{
box.FadeColour(Color4.Black, transition_time, Easing.OutQuint);
Text.FadeColour(Color4.White, transition_time, Easing.OutQuint);
}
updateHoverState();
}
}
@ -261,25 +274,29 @@ namespace osu.Game.Overlays.KeyBinding
protected override bool OnHover(InputState state)
{
if (isBinding)
return false;
box.FadeColour(hoverColour, transition_time, Easing.OutQuint);
Text.FadeColour(Color4.Black, transition_time, Easing.OutQuint);
if (!isBinding)
updateHoverState();
return base.OnHover(state);
}
protected override void OnHoverLost(InputState state)
{
if (isBinding)
return;
box.FadeColour(Color4.Black, transition_time, Easing.OutQuint);
Text.FadeColour(Color4.White, transition_time, Easing.OutQuint);
if (!isBinding)
updateHoverState();
base.OnHoverLost(state);
}
private void updateHoverState()
{
box.FadeColour(IsHovered ? hoverColour : Color4.Black, transition_time, Easing.OutQuint);
Text.FadeColour(IsHovered ? Color4.Black : Color4.White, transition_time, Easing.OutQuint);
}
public void UpdateKeyCombination(params Key[] newCombination)
{
KeyBinding.KeyCombination = newCombination;
Text.Text = KeyBinding.KeyCombination.ReadableString();
}
}
}
}

View File

@ -2,7 +2,9 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Overlays.Settings;
using osu.Game.Overlays.Settings.Sections;
@ -10,6 +12,8 @@ namespace osu.Game.Overlays
{
public class MainSettings : SettingsOverlay
{
private readonly KeyBindingOverlay keyBindingOverlay;
protected override IEnumerable<SettingsSection> CreateSections() => new SettingsSection[]
{
new GeneralSection(),
@ -17,7 +21,7 @@ namespace osu.Game.Overlays
new GameplaySection(),
new AudioSection(),
new SkinSection(),
new InputSection(),
new InputSection(keyBindingOverlay),
new OnlineSection(),
new MaintenanceSection(),
new DebugSection(),
@ -26,8 +30,51 @@ namespace osu.Game.Overlays
protected override Drawable CreateHeader() => new SettingsHeader("settings", "Change the way osu! behaves");
protected override Drawable CreateFooter() => new SettingsFooter();
public MainSettings() : base(true)
public MainSettings()
: base(true)
{
keyBindingOverlay = new KeyBindingOverlay { Depth = 1 };
keyBindingOverlay.StateChanged += keyBindingOverlay_StateChanged;
}
public override bool AcceptsFocus => keyBindingOverlay.State != Visibility.Visible;
private void keyBindingOverlay_StateChanged(VisibilityContainer container, Visibility visibility)
{
const float hidden_width = 120;
switch (visibility)
{
case Visibility.Visible:
Background.FadeTo(0.9f, 500, Easing.OutQuint);
SectionsContainer.FadeOut(100);
ContentContainer.MoveToX(hidden_width - ContentContainer.DrawWidth, 500, Easing.OutQuint);
break;
case Visibility.Hidden:
Background.FadeTo(0.6f, 500, Easing.OutQuint);
SectionsContainer.FadeIn(500, Easing.OutQuint);
ContentContainer.MoveToX(0, 500, Easing.OutQuint);
break;
}
}
protected override void PopOut()
{
base.PopOut();
keyBindingOverlay.State = Visibility.Hidden;
}
[BackgroundDependencyLoader]
private void load()
{
AddInternal(keyBindingOverlay);
}
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
keyBindingOverlay.Margin = new MarginPadding { Left = ContentContainer.Margin.Left + ContentContainer.DrawWidth + ContentContainer.X };
}
}
}

View File

@ -10,14 +10,15 @@ namespace osu.Game.Overlays.Settings.Sections.Input
{
protected override string Header => "Keyboard";
public KeyboardSettings()
public KeyboardSettings(KeyBindingOverlay keyConfig)
{
Children = new Drawable[]
{
new OsuButton
{
RelativeSizeAxes = Axes.X,
Text = "Key Configuration"
Text = "Key Configuration",
Action = () => keyConfig.ToggleVisibility()
},
};
}

View File

@ -12,12 +12,12 @@ namespace osu.Game.Overlays.Settings.Sections
public override string Header => "Input";
public override FontAwesome Icon => FontAwesome.fa_keyboard_o;
public InputSection()
public InputSection(KeyBindingOverlay keyConfig)
{
Children = new Drawable[]
{
new MouseSettings(),
new KeyboardSettings(),
new KeyboardSettings(keyConfig),
};
}
}

View File

@ -29,6 +29,10 @@ namespace osu.Game.Overlays
private const float sidebar_padding = 10;
protected Container<Drawable> ContentContainer;
protected override Container<Drawable> Content => ContentContainer;
private Sidebar sidebar;
private SidebarButton selectedSidebarButton;
@ -40,6 +44,8 @@ namespace osu.Game.Overlays
private readonly bool showSidebar;
protected Box Background;
protected SettingsOverlay(bool showSidebar)
{
this.showSidebar = showSidebar;
@ -52,40 +58,43 @@ namespace osu.Game.Overlays
[BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuGame game)
{
Children = new Drawable[]
InternalChild = ContentContainer = new Container
{
new Box
Width = width,
RelativeSizeAxes = Axes.Y,
Children = new Drawable[]
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
Alpha = 0.6f,
},
SectionsContainer = new SettingsSectionsContainer
{
RelativeSizeAxes = Axes.Y,
Width = width,
Margin = new MarginPadding { Left = SIDEBAR_WIDTH },
ExpandableHeader = CreateHeader(),
FixedHeader = searchTextBox = new SearchTextBox
Background = new Box
{
RelativeSizeAxes = Axes.X,
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Width = 0.95f,
Margin = new MarginPadding
{
Top = 20,
Bottom = 20
},
Exit = Hide,
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
Alpha = 0.6f,
},
Footer = CreateFooter()
},
SectionsContainer = new SettingsSectionsContainer
{
RelativeSizeAxes = Axes.Both,
ExpandableHeader = CreateHeader(),
FixedHeader = searchTextBox = new SearchTextBox
{
RelativeSizeAxes = Axes.X,
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Width = 0.95f,
Margin = new MarginPadding
{
Top = 20,
Bottom = 20
},
Exit = Hide,
},
Footer = CreateFooter()
},
}
};
if (showSidebar)
{
Add(sidebar = new Sidebar { Width = SIDEBAR_WIDTH });
AddInternal(sidebar = new Sidebar { Width = SIDEBAR_WIDTH });
SectionsContainer.SelectedSection.ValueChanged += section =>
{
@ -136,7 +145,7 @@ namespace osu.Game.Overlays
{
base.PopIn();
SectionsContainer.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint);
ContentContainer.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint);
sidebar?.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint);
this.FadeTo(1, TRANSITION_LENGTH / 2);
@ -147,7 +156,7 @@ namespace osu.Game.Overlays
{
base.PopOut();
SectionsContainer.MoveToX(-width, TRANSITION_LENGTH, Easing.OutQuint);
ContentContainer.MoveToX(-width, TRANSITION_LENGTH, Easing.OutQuint);
sidebar?.MoveToX(-SIDEBAR_WIDTH, TRANSITION_LENGTH, Easing.OutQuint);
this.FadeTo(0, TRANSITION_LENGTH / 2);
@ -170,8 +179,8 @@ namespace osu.Game.Overlays
{
base.UpdateAfterChildren();
SectionsContainer.Margin = new MarginPadding { Left = sidebar?.DrawWidth ?? 0 };
SectionsContainer.Padding = new MarginPadding { Top = getToolbarHeight() };
ContentContainer.Margin = new MarginPadding { Left = sidebar?.DrawWidth ?? 0 };
ContentContainer.Padding = new MarginPadding { Top = getToolbarHeight() };
}
protected class SettingsSectionsContainer : SectionsContainer<SettingsSection>