1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 05:02:56 +08:00
osu-lazer/osu.Game/Overlays/DirectOverlay.cs

209 lines
8.0 KiB
C#
Raw Normal View History

// 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.Collections.Generic;
using System.Linq;
2017-05-19 03:15:49 +08:00
using OpenTK;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
2017-05-22 02:30:10 +08:00
using osu.Framework.Input;
using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds;
using osu.Game.Graphics.Sprites;
using osu.Game.Overlays.Direct;
namespace osu.Game.Overlays
{
public class DirectOverlay : WaveOverlayContainer
{
public static readonly int WIDTH_PADDING = 80;
2017-05-20 06:50:45 +08:00
private const float panel_padding = 10f;
private readonly FilterControl filter;
private readonly FillFlowContainer resultCountsContainer;
private readonly OsuSpriteText resultCountsText;
2017-05-19 03:15:49 +08:00
private readonly FillFlowContainer<DirectPanel> panels;
private IEnumerable<BeatmapSetInfo> beatmapSets;
2017-05-19 03:15:49 +08:00
public IEnumerable<BeatmapSetInfo> BeatmapSets
{
get { return beatmapSets; }
2017-05-19 03:15:49 +08:00
set
{
2017-05-20 07:13:59 +08:00
if (beatmapSets?.Equals(value) ?? false) return;
beatmapSets = value;
2017-05-19 03:15:49 +08:00
recreatePanels(filter.DisplayStyle.Value);
2017-05-19 03:15:49 +08:00
}
}
private ResultCounts resultCounts;
2017-05-19 04:43:39 +08:00
public ResultCounts ResultCounts
{
get { return resultCounts; }
set
{
if (value == ResultCounts) return;
resultCounts = value;
updateResultCounts();
}
2017-05-19 04:43:39 +08:00
}
public DirectOverlay()
{
RelativeSizeAxes = Axes.Both;
// osu!direct colours are not part of the standard palette
FirstWaveColour = OsuColour.FromHex(@"19b0e2");
SecondWaveColour = OsuColour.FromHex(@"2280a2");
ThirdWaveColour = OsuColour.FromHex(@"005774");
FourthWaveColour = OsuColour.FromHex(@"003a4e");
2017-05-20 07:03:07 +08:00
Header header;
Children = new Drawable[]
{
2017-05-20 06:50:45 +08:00
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.FromHex(@"485e74"),
},
new Container
{
RelativeSizeAxes = Axes.Both,
Masking = true,
Children = new[]
{
new Triangles
{
RelativeSizeAxes = Axes.Both,
TriangleScale = 5,
ColourLight = OsuColour.FromHex(@"465b71"),
ColourDark = OsuColour.FromHex(@"3f5265"),
},
},
},
new Container
{
2017-05-19 03:15:49 +08:00
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = Header.HEIGHT + FilterControl.HEIGHT },
Children = new[]
{
new ScrollContainer
{
RelativeSizeAxes = Axes.Both,
ScrollDraggerVisible = false,
2017-05-19 03:15:49 +08:00
Children = new Drawable[]
{
new FillFlowContainer
2017-05-19 03:15:49 +08:00
{
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>
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding { Top = panel_padding, Bottom = panel_padding, Left = WIDTH_PADDING, Right = WIDTH_PADDING },
Spacing = new Vector2(panel_padding),
},
},
2017-05-19 03:15:49 +08:00
},
},
},
},
},
filter = new FilterControl
{
RelativeSizeAxes = Axes.X,
Margin = new MarginPadding { Top = Header.HEIGHT },
},
2017-05-20 06:13:07 +08:00
header = new Header
2017-05-19 03:15:49 +08:00
{
RelativeSizeAxes = Axes.X,
},
};
2017-05-21 00:52:51 +08:00
header.Tabs.Current.ValueChanged += tab => { if (tab != DirectTab.Search) filter.Search.Current.Value = string.Empty; };
2017-05-20 06:13:07 +08:00
2017-05-19 03:15:49 +08:00
filter.Search.Exit = Hide;
2017-05-21 00:52:51 +08:00
filter.Search.Current.ValueChanged += text => { if (text != string.Empty) header.Tabs.Current.Value = DirectTab.Search; };
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;
2017-05-24 02:08:02 +08:00
resultCountsText.Text = pluralize(@"Artist", ResultCounts.Artists) + ", " +
pluralize(@"Song", ResultCounts.Songs) + ", " +
pluralize(@"Tag", ResultCounts.Tags);
}
private string pluralize(string prefix, int value)
{
2017-05-24 01:46:23 +08:00
return $@"{value} {prefix}" + (value == 1 ? string.Empty : @"s");
}
private void recreatePanels(PanelDisplayStyle displayStyle)
{
if (BeatmapSets == null) return;
2017-05-20 07:03:07 +08:00
panels.Children = BeatmapSets.Select(b => displayStyle == PanelDisplayStyle.Grid ? (DirectPanel)new DirectGridPanel(b) { Width = 400 } : new DirectListPanel(b));
}
2017-05-22 02:30:10 +08:00
protected override bool OnFocus(InputState state)
{
filter.Search.TriggerFocus();
return false;
}
protected override void PopIn()
{
base.PopIn();
filter.Search.HoldFocus = true;
}
protected override void PopOut()
{
base.PopOut();
filter.Search.HoldFocus = false;
}
}
}