1
0
mirror of https://github.com/ppy/osu.git synced 2024-10-01 21:17:26 +08:00
osu-lazer/osu.Game/Overlays/Changelog/ChangelogChart.cs

84 lines
2.7 KiB
C#
Raw Normal View History

2018-07-20 01:07:24 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK.Graphics;
using osu.Framework.Allocation;
2018-07-20 01:07:24 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
2018-07-20 01:07:24 +08:00
namespace osu.Game.Overlays.Changelog
{
// maybe look to osu.Game.Screens.Play.SquareGraph for reference later
2018-07-20 03:49:13 +08:00
// placeholder json file: https://api.myjson.com/bins/10ye8a
2018-07-20 01:07:24 +08:00
public class ChangelogChart : BufferedContainer
{
private Box background;
private SpriteText text;
private APIAccess api;
2018-07-20 01:07:24 +08:00
public ChangelogChart()
{
RelativeSizeAxes = Axes.X;
Height = 100;
Children = new Drawable[]
{
background = new Box
2018-07-20 01:07:24 +08:00
{
Colour = StreamColour.STABLE,
RelativeSizeAxes = Axes.Both,
},
text = new SpriteText
2018-07-20 01:07:24 +08:00
{
Text = "Graph Placeholder",
TextSize = 28,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
};
}
public void ShowChart(APIChangelog releaseStream) => fetchAndShowChangelogChart(releaseStream);
private bool isEmpty(APIChangelogChart changelogChart)
{
if (changelogChart != null)
foreach (BuildHistory buildHistory in changelogChart.BuildHistory)
if (buildHistory.UserCount > 0) return false;
return true;
}
private void showChart(APIChangelogChart chartInfo, string updateStreamName)
{
if (!isEmpty(chartInfo))
{
background.Colour = StreamColour.FromStreamName(updateStreamName);
text.Text = "Graph placeholder\n(chart is not empty)";
}
else
{
background.Colour = Color4.Black;
text.Text = "Graph placeholder\n(chart is empty)";
}
}
[BackgroundDependencyLoader]
private void load(APIAccess api)
{
this.api = api;
}
private void fetchAndShowChangelogChart(APIChangelog build)
{
var req = new GetChangelogChartRequest(build.UpdateStream.Name);
req.Success += res => showChart(res, build.UpdateStream.Name);
api.Queue(req);
}
2018-07-20 01:07:24 +08:00
}
}