1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-19 02:22:56 +08:00
osu-lazer/osu.Game/Overlays/Rankings/SpotlightSelector.cs

174 lines
6.3 KiB
C#
Raw Normal View History

// 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;
2020-01-10 22:30:51 +08:00
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
2020-01-10 22:30:51 +08:00
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API.Requests.Responses;
2020-01-10 22:30:51 +08:00
using osuTK;
using System;
using System.Collections.Generic;
2020-01-14 13:01:51 +08:00
using osu.Framework.Graphics.UserInterface;
using osu.Game.Online.API.Requests;
namespace osu.Game.Overlays.Rankings
{
public class SpotlightSelector : VisibilityContainer, IHasCurrentValue<APISpotlight>
{
private const int duration = 300;
private readonly Box background;
2020-01-10 21:41:17 +08:00
private readonly SpotlightsDropdown dropdown;
2020-01-14 13:01:51 +08:00
private readonly BindableWithCurrent<APISpotlight> current = new BindableWithCurrent<APISpotlight>();
public Bindable<APISpotlight> Current
{
get => current.Current;
set => current.Current = value;
}
2020-01-10 22:30:51 +08:00
public IEnumerable<APISpotlight> Spotlights
{
get => dropdown.Items;
set => dropdown.Items = value;
}
protected override bool StartHidden => true;
2020-01-11 01:46:35 +08:00
private readonly InfoColumn startDateColumn;
private readonly InfoColumn endDateColumn;
private readonly InfoColumn mapCountColumn;
private readonly InfoColumn participantsColumn;
private readonly Container content;
2020-01-10 22:30:51 +08:00
public SpotlightSelector()
{
RelativeSizeAxes = Axes.X;
2020-02-11 06:44:56 +08:00
Height = 100;
Add(content = new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
2020-02-11 06:44:56 +08:00
{
background = new Box
2020-02-05 18:01:50 +08:00
{
RelativeSizeAxes = Axes.Both,
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Horizontal = UserProfileOverlay.CONTENT_X_MARGIN, Vertical = 10 },
Children = new Drawable[]
2020-02-11 06:44:56 +08:00
{
dropdown = new SpotlightsDropdown
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.X,
Current = Current,
Depth = -float.MaxValue
},
new FillFlowContainer
2020-02-05 18:01:50 +08:00
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(15, 0),
Children = new Drawable[]
{
startDateColumn = new InfoColumn(@"Start Date"),
endDateColumn = new InfoColumn(@"End Date"),
mapCountColumn = new InfoColumn(@"Map Count"),
participantsColumn = new InfoColumn(@"Participants")
}
2020-01-10 22:30:51 +08:00
}
}
2020-02-11 06:44:56 +08:00
}
}
2020-02-05 18:01:50 +08:00
});
}
[BackgroundDependencyLoader]
2020-02-04 00:44:10 +08:00
private void load(OverlayColourProvider colourProvider)
{
2020-02-04 00:44:10 +08:00
background.Colour = colourProvider.Dark3;
2020-01-10 22:30:51 +08:00
}
public void ShowInfo(GetSpotlightRankingsResponse response)
2020-01-14 13:01:51 +08:00
{
startDateColumn.Value = dateToString(response.Spotlight.StartDate);
endDateColumn.Value = dateToString(response.Spotlight.EndDate);
mapCountColumn.Value = response.BeatmapSets.Count.ToString();
participantsColumn.Value = response.Spotlight.Participants?.ToString("N0");
2020-01-10 22:30:51 +08:00
}
protected override void PopIn() => content.FadeIn(duration, Easing.OutQuint);
protected override void PopOut() => content.FadeOut(duration, Easing.OutQuint);
2020-01-11 01:46:35 +08:00
private string dateToString(DateTimeOffset date) => date.ToString("yyyy-MM-dd");
2020-01-10 22:30:51 +08:00
2020-01-11 01:46:35 +08:00
private class InfoColumn : FillFlowContainer
2020-01-10 22:30:51 +08:00
{
public string Value
{
set => valueText.Text = value;
}
private readonly OsuSpriteText valueText;
2020-01-11 01:46:35 +08:00
public InfoColumn(string name)
2020-01-10 22:30:51 +08:00
{
AutoSizeAxes = Axes.Both;
Direction = FillDirection.Vertical;
Children = new Drawable[]
{
new OsuSpriteText
{
Text = name,
Font = OsuFont.GetFont(size: 10),
},
new Container
{
AutoSizeAxes = Axes.X,
Height = 20,
Child = valueText = new OsuSpriteText
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Font = OsuFont.GetFont(size: 18, weight: FontWeight.Light),
}
}
};
}
[BackgroundDependencyLoader]
2020-02-04 00:44:10 +08:00
private void load(OverlayColourProvider colourProvider)
2020-01-10 22:30:51 +08:00
{
2020-02-04 00:44:10 +08:00
valueText.Colour = colourProvider.Content2;
2020-01-10 22:30:51 +08:00
}
}
2020-01-10 21:41:17 +08:00
private class SpotlightsDropdown : OsuDropdown<APISpotlight>
{
2020-01-10 22:30:51 +08:00
private DropdownMenu menu;
protected override DropdownMenu CreateMenu() => menu = base.CreateMenu().With(m => m.MaxHeight = 400);
[BackgroundDependencyLoader]
2020-02-04 00:44:10 +08:00
private void load(OverlayColourProvider colourProvider)
2020-01-10 22:30:51 +08:00
{
2020-02-04 00:44:10 +08:00
menu.BackgroundColour = colourProvider.Background5;
AccentColour = colourProvider.Background6;
2020-01-10 22:30:51 +08:00
}
2020-01-10 21:41:17 +08:00
}
}
}