mirror of
https://github.com/osukey/osukey.git
synced 2025-05-28 00:47:28 +09:00
Resign ChangelogChart and disable its references
This commit is contained in:
parent
46134ed63d
commit
fba817b4e1
@ -1,156 +0,0 @@
|
||||
// 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.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Colour;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
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;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace osu.Game.Overlays.Changelog
|
||||
{
|
||||
public class ChangelogChart : Container
|
||||
{
|
||||
private const float height = 100;
|
||||
private const float transition_duration = 300;
|
||||
|
||||
// why make the child buffered? https://streamable.com/swbdj
|
||||
private readonly Container container;
|
||||
private readonly Box background;
|
||||
private APIAccess api;
|
||||
|
||||
public ChangelogChart()
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
Child = container = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = height,
|
||||
};
|
||||
}
|
||||
|
||||
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 = null)
|
||||
{
|
||||
if (!isEmpty(chartInfo))
|
||||
{
|
||||
container.MoveToY(0, transition_duration, Easing.InOutQuad).FadeIn(transition_duration);
|
||||
if (string.IsNullOrEmpty(updateStreamName))
|
||||
plotCharts(chartInfo);
|
||||
else
|
||||
plotChart(chartInfo, StreamColour.FromStreamName(updateStreamName));
|
||||
}
|
||||
else
|
||||
container.MoveToY(-height, transition_duration, Easing.InOutQuad).FadeOut(transition_duration);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(APIAccess api)
|
||||
{
|
||||
this.api = api;
|
||||
}
|
||||
|
||||
public void ShowUpdateStream(string updateStream)
|
||||
{
|
||||
var req = new GetChangelogChartRequest(updateStream);
|
||||
req.Success += res => showChart(res, updateStream);
|
||||
api.Queue(req);
|
||||
}
|
||||
|
||||
public void ShowAllUpdateStreams()
|
||||
{
|
||||
var req = new GetChangelogChartRequest();
|
||||
req.Success += res => showChart(res);
|
||||
api.Queue(req);
|
||||
}
|
||||
|
||||
// this could probably be combined with isEmpty, todo
|
||||
private float getMaxUserCount(APIChangelogChart changelogChartInfo)
|
||||
{
|
||||
var maxUserCount = 0l;
|
||||
foreach (BuildHistory build in changelogChartInfo.BuildHistory)
|
||||
{
|
||||
if (build.UserCount > maxUserCount)
|
||||
maxUserCount = build.UserCount;
|
||||
}
|
||||
return maxUserCount;
|
||||
}
|
||||
|
||||
private List<float> clearUpDips(List<BuildHistory> buildHistories, float maxUserCount)
|
||||
{
|
||||
var buildHistory = new List<float>();
|
||||
foreach (BuildHistory build in buildHistories)
|
||||
{
|
||||
if (build.UserCount / maxUserCount > 0.2f)
|
||||
buildHistory.Add(build.UserCount);
|
||||
}
|
||||
return buildHistory;
|
||||
}
|
||||
|
||||
private void plotChart(APIChangelogChart changelogChartInfo, ColourInfo colour)
|
||||
{
|
||||
var maxUserCount = getMaxUserCount(changelogChartInfo);
|
||||
|
||||
container.Child = new BarGraph
|
||||
{
|
||||
Colour = colour,
|
||||
Values = clearUpDips(changelogChartInfo.BuildHistory, maxUserCount),
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Direction = BarDirection.BottomToTop,
|
||||
};
|
||||
}
|
||||
|
||||
private void plotCharts(APIChangelogChart changelogChartInfo)
|
||||
{
|
||||
var maxUserCount = getMaxUserCount(changelogChartInfo);
|
||||
|
||||
var releaseStreams = new Dictionary<string, List<float>>(changelogChartInfo.Order.Count);
|
||||
var highestUserCounts = new Dictionary<string, float>(changelogChartInfo.Order.Count);
|
||||
|
||||
foreach (string updateStream in changelogChartInfo.Order)
|
||||
{
|
||||
releaseStreams.Add(updateStream, new List<float>());
|
||||
highestUserCounts.Add(updateStream, 0);
|
||||
}
|
||||
|
||||
foreach (BuildHistory build in changelogChartInfo.BuildHistory)
|
||||
{
|
||||
releaseStreams[build.Label].Add(build.UserCount);
|
||||
if (highestUserCounts[build.Label] < build.UserCount)
|
||||
highestUserCounts[build.Label] = build.UserCount;
|
||||
}
|
||||
|
||||
container.Clear();
|
||||
|
||||
foreach (KeyValuePair<string, List<float>> releaseStream in releaseStreams)
|
||||
{
|
||||
var barGraph = new BarGraph
|
||||
{
|
||||
Colour = StreamColour.FromStreamName(releaseStream.Key),
|
||||
Values = releaseStream.Value,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Direction = BarDirection.BottomToTop,
|
||||
//Height = highestUserCounts[releaseStream.Key] / maxUserCount,
|
||||
};
|
||||
container.Add(barGraph);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ namespace osu.Game.Overlays
|
||||
{
|
||||
private readonly ChangelogHeader header;
|
||||
private readonly ChangelogBadges badges;
|
||||
private readonly ChangelogChart chart;
|
||||
//private readonly ChangelogChart chart;
|
||||
private readonly ChangelogContent listing;
|
||||
private readonly ChangelogContent content;
|
||||
|
||||
@ -85,7 +85,7 @@ namespace osu.Game.Overlays
|
||||
{
|
||||
header = new ChangelogHeader(),
|
||||
badges = new ChangelogBadges(),
|
||||
chart = new ChangelogChart(),
|
||||
//chart = new ChangelogChart(),
|
||||
listing = new ChangelogContent(),
|
||||
content = new ChangelogContent()
|
||||
},
|
||||
@ -162,7 +162,6 @@ namespace osu.Game.Overlays
|
||||
isAtListing = true;
|
||||
var req = new GetChangelogRequest();
|
||||
badges.SelectNone();
|
||||
chart.ShowAllUpdateStreams();
|
||||
req.Success += listing.ShowListing;
|
||||
api.Queue(req);
|
||||
}
|
||||
@ -176,7 +175,7 @@ namespace osu.Game.Overlays
|
||||
content.Hide();
|
||||
listing.Show();
|
||||
badges.SelectNone();
|
||||
chart.ShowAllUpdateStreams();
|
||||
//chart.ShowAllUpdateStreams();
|
||||
listing.Show();
|
||||
scroll.ScrollTo(savedScrollPosition);
|
||||
}
|
||||
@ -184,7 +183,12 @@ namespace osu.Game.Overlays
|
||||
/// <summary>
|
||||
/// Fetches and shows a specific build from a specific update stream.
|
||||
/// </summary>
|
||||
public void FetchAndShowBuild(APIChangelog build, bool sentByBadges = false)
|
||||
/// <param name="build">Must contain at least <see cref="APIChangelog.UpdateStream.Name"/> and
|
||||
/// <see cref="APIChangelog.Version"/>. If <see cref="APIChangelog.UpdateStream.DisplayName"/> and
|
||||
/// <see cref="APIChangelog.DisplayVersion"/> are specified, the header will instantly display them.</param>
|
||||
/// <param name="updateBadges">Whether to update badges. Should be set to false in case
|
||||
/// the function is called by selecting a badge, to avoid an infinite loop.</param>
|
||||
public void FetchAndShowBuild(APIChangelog build, bool updateBadges = true)
|
||||
{
|
||||
var req = new GetChangelogBuildRequest(build.UpdateStream.Name, build.Version);
|
||||
|
||||
@ -193,17 +197,17 @@ namespace osu.Game.Overlays
|
||||
else
|
||||
req.Success += res => header.ShowBuild(res.UpdateStream.DisplayName, res.DisplayVersion);
|
||||
|
||||
if (!sentByBadges)
|
||||
if (updateBadges)
|
||||
badges.SelectUpdateStream(build.UpdateStream.Name);
|
||||
|
||||
chart.ShowUpdateStream(build.UpdateStream.Name);
|
||||
//chart.ShowUpdateStream(build.UpdateStream.Name);
|
||||
req.Success += apiChangelog =>
|
||||
{
|
||||
listing.Hide();
|
||||
content.Show();
|
||||
content.ShowBuild(apiChangelog);
|
||||
if (scroll.Current > scroll.GetChildPosInContent(content))
|
||||
scroll.ScrollTo(chart);
|
||||
scroll.ScrollTo(content);
|
||||
if (isAtListing)
|
||||
savedScrollPosition = scroll.Current;
|
||||
isAtListing = false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user