1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 05:17:25 +08:00
osu-lazer/osu.Game/Overlays/Rankings/SpotlightSelector.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

215 lines
8.8 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;
2020-02-28 05:26:45 +08:00
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Extensions.LocalisationExtensions;
2021-07-30 20:51:16 +08:00
using osu.Framework.Localisation;
using osu.Game.Resources.Localisation.Web;
namespace osu.Game.Overlays.Rankings
{
public class SpotlightSelector : CompositeDrawable, IHasCurrentValue<APISpotlight>
{
2020-01-14 13:01:51 +08:00
private readonly BindableWithCurrent<APISpotlight> current = new BindableWithCurrent<APISpotlight>();
public readonly Bindable<RankingsSortCriteria> Sort = new Bindable<RankingsSortCriteria>();
2020-01-14 13:01:51 +08:00
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;
}
private readonly Box background;
private readonly SpotlightsDropdown dropdown;
2020-01-11 01:46:35 +08:00
private readonly InfoColumn startDateColumn;
private readonly InfoColumn endDateColumn;
private readonly InfoColumn mapCountColumn;
private readonly InfoColumn participantsColumn;
2020-01-10 22:30:51 +08:00
public SpotlightSelector()
{
RelativeSizeAxes = Axes.X;
2020-07-14 22:34:01 +08:00
AutoSizeAxes = Axes.Y;
InternalChildren = new Drawable[]
{
background = new Box
2020-02-11 06:44:56 +08:00
{
RelativeSizeAxes = Axes.Both,
},
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding { Horizontal = UserProfileOverlay.CONTENT_X_MARGIN },
Child = new FillFlowContainer
{
2020-07-14 22:34:01 +08:00
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new Drawable[]
2020-02-11 06:44:56 +08:00
{
new Container
{
Margin = new MarginPadding { Vertical = 20 },
RelativeSizeAxes = Axes.X,
Height = 40,
Depth = -float.MaxValue,
Child = dropdown = new SpotlightsDropdown
2020-07-14 22:34:01 +08:00
{
RelativeSizeAxes = Axes.X,
Current = Current
}
},
new Container
2020-02-05 18:01:50 +08:00
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
new FillFlowContainer
2020-07-14 22:34:01 +08:00
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(10, 0),
Margin = new MarginPadding { Bottom = 5 },
Children = new Drawable[]
2020-07-15 13:27:46 +08:00
{
2021-07-30 20:51:16 +08:00
startDateColumn = new InfoColumn(RankingsStrings.SpotlightStartDate),
endDateColumn = new InfoColumn(RankingsStrings.SpotlightEndDate),
mapCountColumn = new InfoColumn(RankingsStrings.SpotlightMapCount),
participantsColumn = new InfoColumn(RankingsStrings.SpotlightParticipants)
2020-07-15 13:27:46 +08:00
}
},
new RankingsSortTabControl
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Current = Sort
2020-07-14 22:34:01 +08:00
}
}
2020-01-10 22:30:51 +08:00
}
}
2020-02-11 06:44:56 +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.ToLocalisableString(@"N0");
2022-05-02 20:07:53 +08:00
participantsColumn.Value = response.Spotlight.Participants?.ToLocalisableString(@"N0") ?? default;
2020-01-10 22:30:51 +08:00
}
private LocalisableString dateToString(DateTimeOffset date) => date.ToLocalisableString(@"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
{
2021-07-30 20:51:16 +08:00
public LocalisableString Value
2020-01-10 22:30:51 +08:00
{
set => valueText.Text = value;
}
private readonly OsuSpriteText valueText;
2021-07-30 20:51:16 +08:00
public InfoColumn(LocalisableString name)
2020-01-10 22:30:51 +08:00
{
AutoSizeAxes = Axes.Both;
Direction = FillDirection.Vertical;
2020-02-28 05:26:45 +08:00
Padding = new MarginPadding { Vertical = 15 };
2020-01-10 22:30:51 +08:00
Children = new Drawable[]
{
new OsuSpriteText
{
Text = name,
2020-07-14 22:34:01 +08:00
Font = OsuFont.GetFont(size: 10, weight: FontWeight.Regular),
2020-01-10 22:30:51 +08:00
},
new Container
{
AutoSizeAxes = Axes.X,
2020-02-28 05:26:45 +08:00
Height = 25,
2020-01-10 22:30:51 +08:00
Child = valueText = new OsuSpriteText
{
2020-02-28 05:26:45 +08:00
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.GetFont(size: 20, weight: FontWeight.Light),
2020-01-10 22:30:51 +08:00
}
}
};
}
[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>
{
private OsuDropdownMenu menu;
2020-01-10 22:30:51 +08:00
protected override DropdownMenu CreateMenu() => menu = (OsuDropdownMenu)base.CreateMenu().With(m => m.MaxHeight = 400);
2020-01-10 22:30:51 +08:00
2020-02-28 20:18:40 +08:00
protected override DropdownHeader CreateHeader() => new SpotlightsDropdownHeader();
2020-01-10 22:30:51 +08:00
[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;
menu.HoverColour = colourProvider.Background4;
menu.SelectionColour = colourProvider.Background3;
Padding = new MarginPadding { Vertical = 20 };
}
private class SpotlightsDropdownHeader : OsuDropdownHeader
{
2020-02-28 05:35:02 +08:00
public SpotlightsDropdownHeader()
{
AutoSizeAxes = Axes.Y;
Text.Font = OsuFont.GetFont(size: 15);
Text.Padding = new MarginPadding { Vertical = 1.5f }; // osu-web line-height difference compensation
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);
// 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
BackgroundColourHover = colourProvider.Background6.Opacity(0.8f);
}
2020-01-10 22:30:51 +08:00
}
2020-01-10 21:41:17 +08:00
}
}
}