mirror of
https://github.com/osukey/osukey.git
synced 2025-08-06 16:13:57 +09:00
Merge pull request #4859 from peppy/settings-subpanel
Consolidate settings subpanel logic
This commit is contained in:
@ -3,22 +3,14 @@
|
|||||||
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Sprites;
|
|
||||||
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.Input.Bindings;
|
||||||
using osu.Game.Overlays.KeyBinding;
|
using osu.Game.Overlays.KeyBinding;
|
||||||
using osu.Game.Overlays.Settings;
|
using osu.Game.Overlays.Settings;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Screens.Ranking;
|
|
||||||
using osuTK;
|
|
||||||
|
|
||||||
namespace osu.Game.Overlays
|
namespace osu.Game.Overlays
|
||||||
{
|
{
|
||||||
public class KeyBindingPanel : SettingsPanel
|
public class KeyBindingPanel : SettingsSubPanel
|
||||||
{
|
{
|
||||||
protected override Drawable CreateHeader() => new SettingsHeader("key configuration", "Customise your keys!");
|
protected override Drawable CreateHeader() => new SettingsHeader("key configuration", "Customise your keys!");
|
||||||
|
|
||||||
@ -29,84 +21,6 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
foreach (var ruleset in rulesets.AvailableRulesets)
|
foreach (var ruleset in rulesets.AvailableRulesets)
|
||||||
AddSection(new RulesetBindingsSection(ruleset));
|
AddSection(new RulesetBindingsSection(ruleset));
|
||||||
|
|
||||||
AddInternal(new BackButton
|
|
||||||
{
|
|
||||||
Anchor = Anchor.BottomLeft,
|
|
||||||
Origin = Anchor.BottomLeft,
|
|
||||||
Action = Hide
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public KeyBindingPanel()
|
|
||||||
: 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.Solid.ChevronLeft
|
|
||||||
},
|
|
||||||
new OsuSpriteText
|
|
||||||
{
|
|
||||||
Anchor = Anchor.Centre,
|
|
||||||
Origin = Anchor.Centre,
|
|
||||||
Y = 15,
|
|
||||||
Font = OsuFont.GetFont(size: 12, weight: FontWeight.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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,13 +8,12 @@ using osu.Game.Overlays.Settings;
|
|||||||
using osu.Game.Overlays.Settings.Sections;
|
using osu.Game.Overlays.Settings.Sections;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace osu.Game.Overlays
|
namespace osu.Game.Overlays
|
||||||
{
|
{
|
||||||
public class SettingsOverlay : SettingsPanel
|
public class SettingsOverlay : SettingsPanel
|
||||||
{
|
{
|
||||||
private readonly KeyBindingPanel keyBindingPanel;
|
|
||||||
|
|
||||||
protected override IEnumerable<SettingsSection> CreateSections() => new SettingsSection[]
|
protected override IEnumerable<SettingsSection> CreateSections() => new SettingsSection[]
|
||||||
{
|
{
|
||||||
new GeneralSection(),
|
new GeneralSection(),
|
||||||
@ -22,29 +21,37 @@ namespace osu.Game.Overlays
|
|||||||
new GameplaySection(),
|
new GameplaySection(),
|
||||||
new AudioSection(),
|
new AudioSection(),
|
||||||
new SkinSection(),
|
new SkinSection(),
|
||||||
new InputSection(keyBindingPanel),
|
new InputSection(createSubPanel(new KeyBindingPanel())),
|
||||||
new OnlineSection(),
|
new OnlineSection(),
|
||||||
new MaintenanceSection(),
|
new MaintenanceSection(),
|
||||||
new DebugSection(),
|
new DebugSection(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private readonly List<SettingsSubPanel> subPanels = new List<SettingsSubPanel>();
|
||||||
|
|
||||||
protected override Drawable CreateHeader() => new SettingsHeader("settings", "Change the way osu! behaves");
|
protected override Drawable CreateHeader() => new SettingsHeader("settings", "Change the way osu! behaves");
|
||||||
protected override Drawable CreateFooter() => new SettingsFooter();
|
protected override Drawable CreateFooter() => new SettingsFooter();
|
||||||
|
|
||||||
public SettingsOverlay()
|
public SettingsOverlay()
|
||||||
: base(true)
|
: base(true)
|
||||||
{
|
{
|
||||||
keyBindingPanel = new KeyBindingPanel
|
|
||||||
{
|
|
||||||
Depth = 1,
|
|
||||||
Anchor = Anchor.TopRight,
|
|
||||||
};
|
|
||||||
keyBindingPanel.StateChanged += keyBindingPanelStateChanged;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool AcceptsFocus => keyBindingPanel.State != Visibility.Visible;
|
public override bool AcceptsFocus => subPanels.All(s => s.State != Visibility.Visible);
|
||||||
|
|
||||||
private void keyBindingPanelStateChanged(Visibility visibility)
|
private T createSubPanel<T>(T subPanel)
|
||||||
|
where T : SettingsSubPanel
|
||||||
|
{
|
||||||
|
subPanel.Depth = 1;
|
||||||
|
subPanel.Anchor = Anchor.TopRight;
|
||||||
|
subPanel.StateChanged += subPanelStateChanged;
|
||||||
|
|
||||||
|
subPanels.Add(subPanel);
|
||||||
|
|
||||||
|
return subPanel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void subPanelStateChanged(Visibility visibility)
|
||||||
{
|
{
|
||||||
switch (visibility)
|
switch (visibility)
|
||||||
{
|
{
|
||||||
@ -66,12 +73,13 @@ namespace osu.Game.Overlays
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override float ExpandedPosition => keyBindingPanel.State == Visibility.Visible ? -WIDTH : base.ExpandedPosition;
|
protected override float ExpandedPosition => subPanels.Any(s => s.State == Visibility.Visible) ? -WIDTH : base.ExpandedPosition;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
ContentContainer.Add(keyBindingPanel);
|
foreach (var s in subPanels)
|
||||||
|
ContentContainer.Add(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,6 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
protected const float WIDTH = 400;
|
protected const float WIDTH = 400;
|
||||||
|
|
||||||
private const float sidebar_padding = 10;
|
|
||||||
|
|
||||||
protected Container<Drawable> ContentContainer;
|
protected Container<Drawable> ContentContainer;
|
||||||
|
|
||||||
protected override Container<Drawable> Content => ContentContainer;
|
protected override Container<Drawable> Content => ContentContainer;
|
||||||
|
103
osu.Game/Overlays/SettingsSubPanel.cs
Normal file
103
osu.Game/Overlays/SettingsSubPanel.cs
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
// 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 osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
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.Screens.Ranking;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays
|
||||||
|
{
|
||||||
|
public abstract class SettingsSubPanel : SettingsPanel
|
||||||
|
{
|
||||||
|
protected SettingsSubPanel()
|
||||||
|
: base(true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
AddInternal(new BackButton
|
||||||
|
{
|
||||||
|
Anchor = Anchor.BottomLeft,
|
||||||
|
Origin = Anchor.BottomLeft,
|
||||||
|
Action = Hide
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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.Solid.ChevronLeft
|
||||||
|
},
|
||||||
|
new OsuSpriteText
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Y = 15,
|
||||||
|
Font = OsuFont.GetFont(size: 12, weight: FontWeight.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user