Check wether a chart is populated; Fixes to graph's colour setting

This commit is contained in:
HoutarouOreki
2018-07-21 09:45:14 +02:00
parent 22af3cd923
commit ba0430752c
3 changed files with 96 additions and 3 deletions

View File

@ -1,11 +1,15 @@
// 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;
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;
namespace osu.Game.Overlays.Changelog
@ -15,6 +19,8 @@ namespace osu.Game.Overlays.Changelog
public class ChangelogChart : BufferedContainer
{
private Box background;
private SpriteText text;
private APIAccess api;
public ChangelogChart()
{
@ -27,7 +33,7 @@ namespace osu.Game.Overlays.Changelog
Colour = StreamColour.STABLE,
RelativeSizeAxes = Axes.Both,
},
new SpriteText
text = new SpriteText
{
Text = "Graph Placeholder",
TextSize = 28,
@ -37,9 +43,41 @@ namespace osu.Game.Overlays.Changelog
};
}
public void ShowChart(APIChangelog releaseStream)
public void ShowChart(APIChangelog releaseStream) => fetchAndShowChangelogChart(releaseStream);
private bool isEmpty(APIChangelogChart changelogChart)
{
background.Colour = StreamColour.FromStreamName(releaseStream.UpdateStream.Name);
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);
}
}
}