Implement basic SpotlightSelector component

This commit is contained in:
Andrei Zavatski
2020-01-10 16:33:00 +03:00
parent 08fb68ddfe
commit d48b161662
2 changed files with 95 additions and 0 deletions

View File

@ -0,0 +1,28 @@
// 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 System;
using System.Collections.Generic;
using osu.Game.Overlays.Rankings;
namespace osu.Game.Tests.Visual.Online
{
public class TestSceneRankingsSpotlightSelector : OsuTestScene
{
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(SpotlightSelector),
};
protected override bool UseOnlineAPI => true;
public TestSceneRankingsSpotlightSelector()
{
SpotlightSelector selector;
Add(selector = new SpotlightSelector());
AddStep("Fetch spotlights", selector.FetchSpotlights);
}
}
}

View File

@ -0,0 +1,67 @@
// 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;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
namespace osu.Game.Overlays.Rankings
{
public class SpotlightSelector : Container
{
private readonly Box background;
private readonly OsuDropdown<APISpotlight> dropdown;
private readonly DimmedLoadingLayer loading;
[Resolved]
private IAPIProvider api { get; set; }
public SpotlightSelector()
{
RelativeSizeAxes = Axes.X;
Height = 200;
Children = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both,
},
dropdown = new OsuDropdown<APISpotlight>
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.X,
Width = 0.8f,
Margin = new MarginPadding { Top = 10 }
},
loading = new DimmedLoadingLayer(),
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
background.Colour = colours.GreySeafoam;
dropdown.AccentColour = colours.GreySeafoamDarker;
}
public void FetchSpotlights()
{
loading.Show();
var request = new GetSpotlightsRequest();
request.Success += response =>
{
dropdown.Items = response.Spotlights;
loading.Hide();
};
api.Queue(request);
}
}
}