2020-03-04 17:22:56 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2020-01-10 13:33:00 +00:00
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
2020-01-10 14:30:51 +00:00
|
|
|
using osu.Framework.Bindables;
|
2020-01-10 13:33:00 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Game.Graphics;
|
2020-01-10 14:30:51 +00:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2020-01-10 13:33:00 +00:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2020-01-10 14:30:51 +00:00
|
|
|
using osuTK;
|
|
|
|
using System;
|
2020-01-14 04:07:21 +00:00
|
|
|
using System.Collections.Generic;
|
2020-01-14 05:01:51 +00:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2020-02-05 19:59:01 +00:00
|
|
|
using osu.Game.Online.API.Requests;
|
2020-02-27 21:26:45 +00:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2020-01-10 13:33:00 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Rankings
|
|
|
|
{
|
2020-02-10 23:35:23 +00:00
|
|
|
public class SpotlightSelector : VisibilityContainer, IHasCurrentValue<APISpotlight>
|
2020-01-10 13:33:00 +00:00
|
|
|
{
|
2020-02-10 23:35:23 +00:00
|
|
|
private const int duration = 300;
|
|
|
|
|
2020-01-10 13:33:00 +00:00
|
|
|
private readonly Box background;
|
2020-01-10 13:41:17 +00:00
|
|
|
private readonly SpotlightsDropdown dropdown;
|
2020-01-10 13:33:00 +00:00
|
|
|
|
2020-01-14 05:01:51 +00:00
|
|
|
private readonly BindableWithCurrent<APISpotlight> current = new BindableWithCurrent<APISpotlight>();
|
|
|
|
|
|
|
|
public Bindable<APISpotlight> Current
|
|
|
|
{
|
|
|
|
get => current.Current;
|
|
|
|
set => current.Current = value;
|
|
|
|
}
|
2020-01-10 14:30:51 +00:00
|
|
|
|
2020-01-14 04:07:21 +00:00
|
|
|
public IEnumerable<APISpotlight> Spotlights
|
|
|
|
{
|
|
|
|
get => dropdown.Items;
|
|
|
|
set => dropdown.Items = value;
|
|
|
|
}
|
|
|
|
|
2020-02-10 23:35:23 +00:00
|
|
|
protected override bool StartHidden => true;
|
|
|
|
|
2020-01-10 17:46:35 +00:00
|
|
|
private readonly InfoColumn startDateColumn;
|
|
|
|
private readonly InfoColumn endDateColumn;
|
2020-02-05 09:48:29 +00:00
|
|
|
private readonly InfoColumn mapCountColumn;
|
|
|
|
private readonly InfoColumn participantsColumn;
|
2020-02-10 23:35:23 +00:00
|
|
|
private readonly Container content;
|
2020-01-10 14:30:51 +00:00
|
|
|
|
2020-01-10 13:33:00 +00:00
|
|
|
public SpotlightSelector()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X;
|
2020-02-27 21:26:45 +00:00
|
|
|
Height = 155;
|
2020-02-10 23:35:23 +00:00
|
|
|
Add(content = new Container
|
2020-01-10 13:33:00 +00:00
|
|
|
{
|
2020-02-10 23:35:23 +00:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
2020-02-10 22:44:56 +00:00
|
|
|
{
|
2020-02-10 23:35:23 +00:00
|
|
|
background = new Box
|
2020-02-05 10:01:50 +00:00
|
|
|
{
|
2020-02-10 23:35:23 +00:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-03-05 22:09:51 +00:00
|
|
|
Padding = new MarginPadding { Horizontal = UserProfileOverlay.CONTENT_X_MARGIN },
|
2020-02-10 23:35:23 +00:00
|
|
|
Children = new Drawable[]
|
2020-02-10 22:44:56 +00:00
|
|
|
{
|
2020-02-10 23:35:23 +00:00
|
|
|
dropdown = new SpotlightsDropdown
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Current = Current,
|
|
|
|
Depth = -float.MaxValue
|
|
|
|
},
|
|
|
|
new FillFlowContainer
|
2020-02-05 10:01:50 +00:00
|
|
|
{
|
2020-03-15 17:26:33 +00:00
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft,
|
2020-02-10 23:35:23 +00:00
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Horizontal,
|
2020-03-15 17:26:33 +00:00
|
|
|
Spacing = new Vector2(20, 0),
|
2020-02-10 23:35:23 +00:00
|
|
|
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 14:30:51 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-10 22:44:56 +00:00
|
|
|
}
|
2020-02-10 23:35:23 +00:00
|
|
|
}
|
2020-02-05 10:01:50 +00:00
|
|
|
});
|
2020-01-10 13:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2020-02-03 16:44:10 +00:00
|
|
|
private void load(OverlayColourProvider colourProvider)
|
2020-01-10 13:33:00 +00:00
|
|
|
{
|
2020-02-03 16:44:10 +00:00
|
|
|
background.Colour = colourProvider.Dark3;
|
2020-01-10 14:30:51 +00:00
|
|
|
}
|
|
|
|
|
2020-02-05 19:59:01 +00:00
|
|
|
public void ShowInfo(GetSpotlightRankingsResponse response)
|
2020-01-14 05:01:51 +00:00
|
|
|
{
|
2020-02-05 19:59:01 +00: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 14:30:51 +00:00
|
|
|
}
|
|
|
|
|
2020-02-10 23:35:23 +00:00
|
|
|
protected override void PopIn() => content.FadeIn(duration, Easing.OutQuint);
|
|
|
|
|
|
|
|
protected override void PopOut() => content.FadeOut(duration, Easing.OutQuint);
|
|
|
|
|
2020-01-10 17:46:35 +00:00
|
|
|
private string dateToString(DateTimeOffset date) => date.ToString("yyyy-MM-dd");
|
2020-01-10 14:30:51 +00:00
|
|
|
|
2020-01-10 17:46:35 +00:00
|
|
|
private class InfoColumn : FillFlowContainer
|
2020-01-10 14:30:51 +00:00
|
|
|
{
|
|
|
|
public string Value
|
|
|
|
{
|
|
|
|
set => valueText.Text = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
private readonly OsuSpriteText valueText;
|
|
|
|
|
2020-01-10 17:46:35 +00:00
|
|
|
public InfoColumn(string name)
|
2020-01-10 14:30:51 +00:00
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
Direction = FillDirection.Vertical;
|
2020-02-27 21:26:45 +00:00
|
|
|
Padding = new MarginPadding { Vertical = 15 };
|
2020-01-10 14:30:51 +00:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Text = name,
|
|
|
|
Font = OsuFont.GetFont(size: 10),
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.X,
|
2020-02-27 21:26:45 +00:00
|
|
|
Height = 25,
|
2020-01-10 14:30:51 +00:00
|
|
|
Child = valueText = new OsuSpriteText
|
|
|
|
{
|
2020-02-27 21:26:45 +00:00
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Font = OsuFont.GetFont(size: 20, weight: FontWeight.Light),
|
2020-01-10 14:30:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2020-02-03 16:44:10 +00:00
|
|
|
private void load(OverlayColourProvider colourProvider)
|
2020-01-10 14:30:51 +00:00
|
|
|
{
|
2020-02-03 16:44:10 +00:00
|
|
|
valueText.Colour = colourProvider.Content2;
|
2020-01-10 14:30:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-10 13:41:17 +00:00
|
|
|
private class SpotlightsDropdown : OsuDropdown<APISpotlight>
|
|
|
|
{
|
2020-01-10 14:30:51 +00:00
|
|
|
private DropdownMenu menu;
|
|
|
|
|
|
|
|
protected override DropdownMenu CreateMenu() => menu = base.CreateMenu().With(m => m.MaxHeight = 400);
|
|
|
|
|
2020-02-28 12:18:40 +00:00
|
|
|
protected override DropdownHeader CreateHeader() => new SpotlightsDropdownHeader();
|
|
|
|
|
2020-01-10 14:30:51 +00:00
|
|
|
[BackgroundDependencyLoader]
|
2020-02-03 16:44:10 +00:00
|
|
|
private void load(OverlayColourProvider colourProvider)
|
2020-01-10 14:30:51 +00:00
|
|
|
{
|
2020-02-27 21:18:02 +00:00
|
|
|
// osu-web adds a 0.6 opacity container on top of the 0.5 base one when hovering, 0.8 on a single container here matches the resulting colour
|
|
|
|
AccentColour = colourProvider.Background6.Opacity(0.8f);
|
2020-02-03 16:44:10 +00:00
|
|
|
menu.BackgroundColour = colourProvider.Background5;
|
2020-02-27 21:18:02 +00:00
|
|
|
Padding = new MarginPadding { Vertical = 20 };
|
|
|
|
}
|
|
|
|
|
|
|
|
private class SpotlightsDropdownHeader : OsuDropdownHeader
|
|
|
|
{
|
2020-02-27 21:35:02 +00:00
|
|
|
public SpotlightsDropdownHeader()
|
2020-02-27 21:18:02 +00:00
|
|
|
{
|
2020-03-04 17:22:56 +00:00
|
|
|
AutoSizeAxes = Axes.Y;
|
2020-02-27 21:18:02 +00:00
|
|
|
Text.Font = OsuFont.GetFont(size: 15);
|
2020-03-04 17:22:56 +00:00
|
|
|
Text.Padding = new MarginPadding { Vertical = 1.5f }; // osu-web line-height difference compensation
|
2020-02-27 21:18:02 +00:00
|
|
|
Foreground.Padding = new MarginPadding { Horizontal = 10, Vertical = 15 };
|
|
|
|
Margin = Icon.Margin = new MarginPadding(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
|
|
|
{
|
|
|
|
BackgroundColour = colourProvider.Background6.Opacity(0.5f);
|
|
|
|
BackgroundColourHover = colourProvider.Background5;
|
|
|
|
}
|
2020-01-10 14:30:51 +00:00
|
|
|
}
|
2020-01-10 13:41:17 +00:00
|
|
|
}
|
2020-01-10 13:33:00 +00:00
|
|
|
}
|
|
|
|
}
|