1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 01:43:15 +08:00

Move SearchTextBox out of SettingsHeader.

This commit is contained in:
Huo Yaoyuan 2017-05-21 04:12:16 +08:00
parent a98f109d73
commit aa409ac1a9
2 changed files with 33 additions and 73 deletions

View File

@ -1,34 +1,16 @@
// 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.Sprites;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using OpenTK.Graphics;
namespace osu.Game.Overlays.Settings
{
public class SettingsHeader : 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 SettingsHeader(Func<float> currentScrollOffset)
{
this.currentScrollOffset = currentScrollOffset;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
@ -37,11 +19,6 @@ namespace osu.Game.Overlays.Settings
Children = new Drawable[]
{
background = new Box
{
Colour = Color4.Black,
RelativeSizeAxes = Axes.Both,
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Y,
@ -53,7 +30,8 @@ namespace osu.Game.Overlays.Settings
{
Text = "settings",
TextSize = 40,
Margin = new MarginPadding {
Margin = new MarginPadding
{
Left = SettingsOverlay.CONTENT_MARGINS,
Top = Toolbar.Toolbar.TOOLTIP_HEIGHT
},
@ -63,45 +41,15 @@ namespace osu.Game.Overlays.Settings
Colour = colours.Pink,
Text = "Change the way osu! behaves",
TextSize = 18,
Margin = new MarginPadding {
Margin = new MarginPadding
{
Left = SettingsOverlay.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

@ -27,20 +27,13 @@ namespace osu.Game.Overlays
private const float sidebar_padding = 10;
private ScrollContainer scrollContainer;
private Sidebar sidebar;
private SidebarButton[] sidebarButtons;
private SettingsSection[] sections;
private SettingsHeader header;
private SettingsFooter footer;
private SearchContainer searchContainer;
private SettingsSectionsContainer sectionsContainer;
private float lastKnownScroll;
private SearchTextBox searchTextBox;
public SettingsOverlay()
{
@ -76,8 +69,8 @@ namespace osu.Game.Overlays
RelativeSizeAxes = Axes.Y,
Width = width,
Margin = new MarginPadding { Left = SIDEBAR_WIDTH },
ExpandableHeader = header = new SettingsHeader(() => sectionsContainer.ScrollContainer.Current),
FixedHeader = new SearchTextBox
ExpandableHeader = new SettingsHeader(),
FixedHeader = searchTextBox = new SearchTextBox
{
RelativeSizeAxes = Axes.X,
Origin = Anchor.TopCentre,
@ -91,7 +84,7 @@ namespace osu.Game.Overlays
Exit = Hide,
},
Sections = sections,
Footer = footer = new SettingsFooter()
Footer = new SettingsFooter()
},
sidebar = new Sidebar
{
@ -101,13 +94,13 @@ namespace osu.Game.Overlays
{
Selected = sections[0] == section,
Section = section,
Action = () => scrollContainer.ScrollIntoView(section),
Action = () => sectionsContainer.ScrollContainer.ScrollIntoView(section),
}
).ToArray()
}
};
//header.SearchTextBox.Current.ValueChanged += newValue => searchContainer.SearchTerm = newValue;
searchTextBox.Current.ValueChanged += newValue => sectionsContainer.SearchContainer.SearchTerm = newValue;
sectionsContainer.Padding = new MarginPadding { Top = game?.Toolbar.DrawHeight ?? 0 };
}
@ -120,7 +113,7 @@ namespace osu.Game.Overlays
sidebar.MoveToX(0, TRANSITION_LENGTH, EasingTypes.OutQuint);
FadeTo(1, TRANSITION_LENGTH / 2);
header.SearchTextBox.HoldFocus = true;
searchTextBox.HoldFocus = true;
}
protected override void PopOut()
@ -131,19 +124,21 @@ namespace osu.Game.Overlays
sidebar.MoveToX(-SIDEBAR_WIDTH, TRANSITION_LENGTH, EasingTypes.OutQuint);
FadeTo(0, TRANSITION_LENGTH / 2);
header.SearchTextBox.HoldFocus = false;
header.SearchTextBox.TriggerFocusLost();
searchTextBox.HoldFocus = false;
searchTextBox.TriggerFocusLost();
}
protected override bool OnFocus(InputState state)
{
header.SearchTextBox.TriggerFocus(state);
searchTextBox.TriggerFocus(state);
return false;
}
private class SettingsSectionsContainer : SectionsContainer
{
public SearchContainer SearchContainer;
private readonly Box headerBackground;
protected override Container<Drawable> CreateScrollContentContainer()
=> SearchContainer = new SearchContainer
{
@ -151,9 +146,26 @@ namespace osu.Game.Overlays
RelativeSizeAxes = Axes.X,
Direction = FillDirection.Vertical,
};
public SettingsSectionsContainer()
{
ScrollContainer.ScrollDraggerVisible = false;
Add(headerBackground = new Box
{
Colour = Color4.Black,
RelativeSizeAxes = Axes.X,
Depth = float.MaxValue
});
}
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
// no null check because the usage of this class is strict
headerBackground.Height = ExpandableHeader.LayoutSize.Y + FixedHeader.LayoutSize.Y;
headerBackground.Y = ExpandableHeader.Y;
headerBackground.Alpha = -ExpandableHeader.Y / ExpandableHeader.LayoutSize.Y * 0.5f;
}
}
}