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

Make result counts scroll with the panels

This commit is contained in:
DrabWeb 2017-05-23 14:34:34 -03:00
parent bdab545ca4
commit 4f17a4fe91
3 changed files with 69 additions and 65 deletions

View File

@ -23,9 +23,9 @@ namespace osu.Desktop.VisualTests.Tests
Add(direct = new DirectOverlay()); Add(direct = new DirectOverlay());
newBeatmaps(); newBeatmaps();
direct.ResultCounts = new ResultCounts(1, 432, 3);
AddStep(@"Toggle", direct.ToggleVisibility); AddStep(@"toggle", direct.ToggleVisibility);
AddStep(@"result counts", () => direct.ResultCounts = new ResultCounts(1, 4, 13));
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]

View File

@ -12,7 +12,6 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using Container = osu.Framework.Graphics.Containers.Container; using Container = osu.Framework.Graphics.Containers.Container;
@ -23,34 +22,16 @@ namespace osu.Game.Overlays.Direct
{ {
public static readonly float HEIGHT = 35 + 32 + 30 + padding * 2; // search + mode toggle buttons + sort tabs + padding public static readonly float HEIGHT = 35 + 32 + 30 + padding * 2; // search + mode toggle buttons + sort tabs + padding
/// <summary>
/// The height of the content below the filter control (tab strip + result count text).
/// </summary>
public static readonly float LOWER_HEIGHT = 21;
private const float padding = 10; private const float padding = 10;
private readonly Box tabStrip; private readonly Box tabStrip;
private readonly FillFlowContainer<RulesetToggleButton> modeButtons; private readonly FillFlowContainer<RulesetToggleButton> modeButtons;
private readonly FillFlowContainer resultCountsContainer;
private readonly OsuSpriteText resultCountsText;
public readonly SearchTextBox Search; public readonly SearchTextBox Search;
public readonly SortTabControl SortTabs; public readonly SortTabControl SortTabs;
public readonly OsuEnumDropdown<RankStatus> RankStatusDropdown; public readonly OsuEnumDropdown<RankStatus> RankStatusDropdown;
public readonly Bindable<PanelDisplayStyle> DisplayStyle = new Bindable<PanelDisplayStyle>(); public readonly Bindable<PanelDisplayStyle> DisplayStyle = new Bindable<PanelDisplayStyle>();
private ResultCounts resultCounts;
public ResultCounts ResultCounts
{
get { return resultCounts; }
set
{
resultCounts = value;
updateResultCounts();
}
}
protected override bool InternalContains(Vector2 screenSpacePos) => base.InternalContains(screenSpacePos) || RankStatusDropdown.Contains(screenSpacePos); protected override bool InternalContains(Vector2 screenSpacePos) => base.InternalContains(screenSpacePos) || RankStatusDropdown.Contains(screenSpacePos);
public FilterControl() public FilterControl()
@ -127,41 +108,17 @@ namespace osu.Game.Overlays.Direct
}, },
}, },
}, },
resultCountsContainer = new FillFlowContainer
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.TopLeft,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Margin = new MarginPadding { Left = DirectOverlay.WIDTH_PADDING, Top = 6 },
Children = new Drawable[]
{
new OsuSpriteText
{
Text = @"Found ",
TextSize = 15,
},
resultCountsText = new OsuSpriteText
{
TextSize = 15,
Font = @"Exo2.0-Bold",
},
}
},
}; };
RankStatusDropdown.Current.Value = RankStatus.RankedApproved; RankStatusDropdown.Current.Value = RankStatus.RankedApproved;
SortTabs.Current.Value = SortCriteria.Title; SortTabs.Current.Value = SortCriteria.Title;
SortTabs.Current.TriggerChange(); SortTabs.Current.TriggerChange();
updateResultCounts();
} }
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
private void load(OsuGame game, RulesetDatabase rulesets, OsuColour colours) private void load(OsuGame game, RulesetDatabase rulesets, OsuColour colours)
{ {
tabStrip.Colour = colours.Yellow; tabStrip.Colour = colours.Yellow;
resultCountsContainer.Colour = colours.Yellow;
RankStatusDropdown.AccentColour = colours.BlueDark; RankStatusDropdown.AccentColour = colours.BlueDark;
var b = new Bindable<RulesetInfo>(); //backup bindable incase the game is null var b = new Bindable<RulesetInfo>(); //backup bindable incase the game is null
@ -171,21 +128,6 @@ namespace osu.Game.Overlays.Direct
} }
} }
private void updateResultCounts()
{
resultCountsContainer.FadeTo(ResultCounts == null ? 0 : 1, 200, EasingTypes.Out);
if (resultCounts == null) return;
resultCountsText.Text = pluralize(@"Artist", ResultCounts?.Artists ?? 0) + ", " +
pluralize(@"Song", ResultCounts?.Songs ?? 0) + ", " +
pluralize(@"Tag", ResultCounts?.Tags ?? 0);
}
private string pluralize(string prefix, int value)
{
return $@"{value} {prefix}" + (value == 1 ? string.Empty : @"s");
}
private class DirectSearchTextBox : SearchTextBox private class DirectSearchTextBox : SearchTextBox
{ {
protected override Color4 BackgroundUnfocused => backgroundColour; protected override Color4 BackgroundUnfocused => backgroundColour;

View File

@ -4,6 +4,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenTK; using OpenTK;
using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
@ -11,6 +12,7 @@ using osu.Framework.Input;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds; using osu.Game.Graphics.Backgrounds;
using osu.Game.Graphics.Sprites;
using osu.Game.Overlays.Direct; using osu.Game.Overlays.Direct;
namespace osu.Game.Overlays namespace osu.Game.Overlays
@ -21,6 +23,8 @@ namespace osu.Game.Overlays
private const float panel_padding = 10f; private const float panel_padding = 10f;
private readonly FilterControl filter; private readonly FilterControl filter;
private readonly FillFlowContainer resultCountsContainer;
private readonly OsuSpriteText resultCountsText;
private readonly FillFlowContainer<DirectPanel> panels; private readonly FillFlowContainer<DirectPanel> panels;
private IEnumerable<BeatmapSetInfo> beatmapSets; private IEnumerable<BeatmapSetInfo> beatmapSets;
@ -36,10 +40,17 @@ namespace osu.Game.Overlays
} }
} }
private ResultCounts resultCounts;
public ResultCounts ResultCounts public ResultCounts ResultCounts
{ {
get { return filter.ResultCounts; } get { return resultCounts; }
set { filter.ResultCounts = value; } set
{
if (value == ResultCounts) return;
resultCounts = value;
updateResultCounts();
}
} }
public DirectOverlay() public DirectOverlay()
@ -88,17 +99,45 @@ namespace osu.Game.Overlays
ScrollDraggerVisible = false, ScrollDraggerVisible = false,
Children = new Drawable[] Children = new Drawable[]
{ {
new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
resultCountsContainer = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Margin = new MarginPadding { Left = WIDTH_PADDING, Top = 6 },
Children = new Drawable[]
{
new OsuSpriteText
{
Text = @"Found ",
TextSize = 15,
},
resultCountsText = new OsuSpriteText
{
TextSize = 15,
Font = @"Exo2.0-Bold",
},
}
},
panels = new FillFlowContainer<DirectPanel> panels = new FillFlowContainer<DirectPanel>
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Padding = new MarginPadding { Top = FilterControl.LOWER_HEIGHT + panel_padding, Bottom = panel_padding, Left = WIDTH_PADDING, Right = WIDTH_PADDING }, Padding = new MarginPadding { Top = panel_padding, Bottom = panel_padding, Left = WIDTH_PADDING, Right = WIDTH_PADDING },
Spacing = new Vector2(panel_padding), Spacing = new Vector2(panel_padding),
}, },
}, },
}, },
}, },
}, },
},
},
filter = new FilterControl filter = new FilterControl
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
@ -115,6 +154,29 @@ namespace osu.Game.Overlays
filter.Search.Exit = Hide; filter.Search.Exit = Hide;
filter.Search.Current.ValueChanged += text => { if (text != string.Empty) header.Tabs.Current.Value = DirectTab.Search; }; filter.Search.Current.ValueChanged += text => { if (text != string.Empty) header.Tabs.Current.Value = DirectTab.Search; };
filter.DisplayStyle.ValueChanged += recreatePanels; filter.DisplayStyle.ValueChanged += recreatePanels;
updateResultCounts();
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
resultCountsContainer.Colour = colours.Yellow;
}
private void updateResultCounts()
{
resultCountsContainer.FadeTo(ResultCounts == null ? 0f : 1f, 200, EasingTypes.Out);
if (ResultCounts == null) return;
resultCountsText.Text = pluralize(@"Artist", ResultCounts?.Artists ?? 0) + ", " +
pluralize(@"Song", ResultCounts?.Songs ?? 0) + ", " +
pluralize(@"Tag", ResultCounts?.Tags ?? 0);
}
private string pluralize(string prefix, int value)
{
return $@"{value} {prefix}" + (value == 1 ? string.Empty : @"s");
} }
private void recreatePanels(PanelDisplayStyle displayStyle) private void recreatePanels(PanelDisplayStyle displayStyle)