1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 17:47:29 +08:00

Add OptionsHeader class

Makes search textbox anchor correctly. Also improves visual styling.
This commit is contained in:
Dean Herbert 2017-05-11 14:55:25 +09:00
parent df48204403
commit ec67b617ae
3 changed files with 137 additions and 44 deletions

View File

@ -0,0 +1,108 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Screens.Select;
using OpenTK.Graphics;
namespace osu.Game.Overlays.Options
{
public class OptionsHeader : Container
{
public SearchTextBox SearchTextBox;
private Box background;
private readonly Func<float> currentScrollOffset;
public Action Exit;
/// <param name="currentScrollOffset">A reference to the current scroll position of the ScrollContainer we are contained within.</param>
public OptionsHeader(Func<float> currentScrollOffset)
{
this.currentScrollOffset = currentScrollOffset;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Children = new Drawable[]
{
background = new Box
{
Colour = Color4.Black,
RelativeSizeAxes = Axes.Both,
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new OsuSpriteText
{
Text = "settings",
TextSize = 40,
Margin = new MarginPadding {
Left = OptionsOverlay.CONTENT_MARGINS,
Top = Toolbar.Toolbar.TOOLTIP_HEIGHT
},
},
new OsuSpriteText
{
Colour = colours.Pink,
Text = "Change the way osu! behaves",
TextSize = 18,
Margin = new MarginPadding {
Left = OptionsOverlay.CONTENT_MARGINS,
Bottom = 30
},
},
SearchTextBox = new SearchTextBox
{
RelativeSizeAxes = Axes.X,
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Width = 0.95f,
Margin = new MarginPadding {
Top = 20,
Bottom = 20
},
Exit = () => Exit(),
},
}
}
};
}
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
// the point at which we will start anchoring to the top.
float anchorOffset = SearchTextBox.Y;
float scrollPosition = currentScrollOffset();
// we want to anchor the search field to the top of the screen when scrolling.
Margin = new MarginPadding { Top = Math.Max(0, scrollPosition - anchorOffset) };
// we don't want the header to scroll when scrolling beyond the upper extent.
Y = Math.Min(0, scrollPosition);
// we get darker as scroll progresses
background.Alpha = Math.Min(1, scrollPosition / anchorOffset) * 0.5f;
}
}
}

View File

@ -10,10 +10,7 @@ using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites;
using osu.Game.Overlays.Options;
using System;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Overlays.Options.Sections;
using osu.Game.Screens.Select;
using osu.Framework.Input;
namespace osu.Game.Overlays
@ -35,8 +32,11 @@ namespace osu.Game.Overlays
private SidebarButton[] sidebarButtons;
private OptionsSection[] sections;
private OptionsHeader header;
private OptionsFooter footer;
private SearchContainer searchContainer;
private SearchTextBox searchTextBox;
private float lastKnownScroll;
@ -47,7 +47,7 @@ namespace osu.Game.Overlays
}
[BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuGame game, OsuColour colours)
private void load(OsuGame game)
{
sections = new OptionsSection[]
{
@ -75,45 +75,20 @@ namespace osu.Game.Overlays
RelativeSizeAxes = Axes.Y,
Width = width,
Margin = new MarginPadding { Left = SIDEBAR_WIDTH },
Children = new[]
Children = new Drawable[]
{
new FillFlowContainer
searchContainer = new SearchContainer
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new OsuSpriteText
{
Text = "settings",
TextSize = 40,
Margin = new MarginPadding { Left = CONTENT_MARGINS, Top = Toolbar.Toolbar.TOOLTIP_HEIGHT },
},
new OsuSpriteText
{
Colour = colours.Pink,
Text = "Change the way osu! behaves",
TextSize = 18,
Margin = new MarginPadding { Left = CONTENT_MARGINS, Bottom = 30 },
},
searchTextBox = new SearchTextBox
{
Width = width - CONTENT_MARGINS * 2,
Margin = new MarginPadding { Left = CONTENT_MARGINS },
Exit = () => Hide(),
},
searchContainer = new SearchContainer
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Direction = FillDirection.Vertical,
Children = sections,
},
new OptionsFooter()
}
}
Children = sections,
},
footer = new OptionsFooter(),
header = new OptionsHeader(() => scrollContainer.Current)
{
Exit = Hide,
},
}
},
sidebar = new Sidebar
@ -130,11 +105,20 @@ namespace osu.Game.Overlays
}
};
searchTextBox.Current.ValueChanged += newValue => searchContainer.SearchTerm = newValue;
header.SearchTextBox.Current.ValueChanged += newValue => searchContainer.SearchTerm = newValue;
scrollContainer.Padding = new MarginPadding { Top = game?.Toolbar.DrawHeight ?? 0 };
}
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
//we need to update these manually because we can't put the OptionsHeader inside the SearchContainer (due to its anchoring).
searchContainer.Y = header.DrawHeight;
footer.Y = searchContainer.Y + searchContainer.DrawHeight;
}
protected override void Update()
{
base.Update();
@ -172,7 +156,7 @@ namespace osu.Game.Overlays
sidebar.MoveToX(0, TRANSITION_LENGTH, EasingTypes.OutQuint);
FadeTo(1, TRANSITION_LENGTH / 2);
searchTextBox.HoldFocus = true;
header.SearchTextBox.HoldFocus = true;
}
protected override void PopOut()
@ -183,13 +167,13 @@ namespace osu.Game.Overlays
sidebar.MoveToX(-SIDEBAR_WIDTH, TRANSITION_LENGTH, EasingTypes.OutQuint);
FadeTo(0, TRANSITION_LENGTH / 2);
searchTextBox.HoldFocus = false;
searchTextBox.TriggerFocusLost();
header.SearchTextBox.HoldFocus = false;
header.SearchTextBox.TriggerFocusLost();
}
protected override bool OnFocus(InputState state)
{
searchTextBox.TriggerFocus(state);
header.SearchTextBox.TriggerFocus(state);
return false;
}
}

View File

@ -78,6 +78,7 @@
<Compile Include="Overlays\Music\FilterControl.cs" />
<Compile Include="Overlays\Music\PlaylistItem.cs" />
<Compile Include="Overlays\Music\PlaylistList.cs" />
<Compile Include="Overlays\Options\OptionsHeader.cs" />
<Compile Include="Overlays\Options\Sections\Audio\MainMenuOptions.cs" />
<Compile Include="Overlays\Toolbar\ToolbarChatButton.cs" />
<Compile Include="Rulesets\Beatmaps\BeatmapConverter.cs" />