mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 06:17:23 +08:00
Check wether a chart is populated; Fixes to graph's colour setting
This commit is contained in:
parent
22af3cd923
commit
ba0430752c
21
osu.Game/Online/API/Requests/GetChangelogChartRequest.cs
Normal file
21
osu.Game/Online/API/Requests/GetChangelogChartRequest.cs
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace osu.Game.Online.API.Requests
|
||||
{
|
||||
public class GetChangelogChartRequest : APIRequest<APIChangelogChart>
|
||||
{
|
||||
private readonly string updateStream;
|
||||
|
||||
public GetChangelogChartRequest() => updateStream = null;
|
||||
|
||||
public GetChangelogChartRequest(string updateStreamName) => updateStream = updateStreamName;
|
||||
|
||||
protected override string Target => $@"changelog/{(!string.IsNullOrEmpty(updateStream) ?
|
||||
updateStream + "/" : "")}chart-config";
|
||||
protected override string Uri => $@"https://houtarouoreki.github.io/fake-api/{Target}"; // for testing
|
||||
}
|
||||
}
|
34
osu.Game/Online/API/Requests/Responses/APIChangelogChart.cs
Normal file
34
osu.Game/Online/API/Requests/Responses/APIChangelogChart.cs
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using osu.Framework.Lists;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace osu.Game.Online.API.Requests.Responses
|
||||
{
|
||||
public class APIChangelogChart
|
||||
{
|
||||
[JsonProperty("build_history")]
|
||||
public List<BuildHistory> BuildHistory { get; set; }
|
||||
|
||||
[JsonProperty("order")]
|
||||
public List<string> Order { get; set; }
|
||||
|
||||
[JsonProperty("stream_name")]
|
||||
public string StreamName { get; set; }
|
||||
}
|
||||
|
||||
public class BuildHistory
|
||||
{
|
||||
[JsonProperty("created_at")]
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
|
||||
[JsonProperty("user_count")]
|
||||
public long UserCount { get; set; }
|
||||
|
||||
[JsonProperty("label")]
|
||||
public string Label { get; set; }
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user