osu/osu.Game/Overlays/ChangelogOverlay.cs

162 lines
5.4 KiB
C#
Raw Normal View History

2018-07-16 21:50:22 +00: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;
using OpenTK.Graphics;
2018-07-19 17:07:24 +00:00
using osu.Framework.Allocation;
2018-07-16 21:50:22 +00:00
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
2018-07-18 17:32:15 +00:00
using osu.Game.Input.Bindings;
2018-07-19 17:07:24 +00:00
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
2018-07-16 21:50:22 +00:00
using osu.Game.Overlays.Changelog;
2018-07-22 18:27:50 +00:00
using System;
2018-07-16 21:50:22 +00:00
namespace osu.Game.Overlays
{
public class ChangelogOverlay : WaveOverlayContainer
{
2018-07-18 17:32:15 +00:00
private readonly ChangelogHeader header;
2018-07-22 16:35:29 +00:00
private readonly ChangelogBadges badges;
private readonly ChangelogChart chart;
2018-07-22 16:35:29 +00:00
private readonly ChangelogContent content;
private readonly Color4 purple = new Color4(191, 4, 255, 255);
2018-07-19 17:07:24 +00:00
private APIAccess api;
2018-07-16 21:50:22 +00:00
2018-07-22 16:35:29 +00:00
private bool isAtListing;
2018-07-17 16:32:11 +00:00
2018-07-16 21:50:22 +00:00
public ChangelogOverlay()
{
2018-07-17 16:32:11 +00:00
// these possibly need adjusting?
Waves.FirstWaveColour = OsuColour.FromHex(@"bf04ff");
Waves.SecondWaveColour = OsuColour.FromHex(@"8F03BF");
Waves.ThirdWaveColour = OsuColour.FromHex(@"600280");
Waves.FourthWaveColour = OsuColour.FromHex(@"300140");
2018-07-16 21:50:22 +00:00
Anchor = Anchor.TopCentre;
Origin = Anchor.TopCentre;
RelativeSizeAxes = Axes.Both;
Width = 0.85f;
Masking = true;
2018-07-17 16:32:11 +00:00
2018-07-16 21:50:22 +00:00
EdgeEffect = new EdgeEffectParameters
{
Colour = Color4.Black.Opacity(0),
Type = EdgeEffectType.Shadow,
Radius = 3,
Offset = new Vector2(0f, 1f),
};
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
2018-07-21 21:00:05 +00:00
Colour = new Color4(49, 36, 54, 255),
2018-07-16 21:50:22 +00:00
},
2018-07-18 17:32:15 +00:00
new ScrollContainer
2018-07-16 21:50:22 +00:00
{
RelativeSizeAxes = Axes.Both,
ScrollbarVisible = false,
Child = new ReverseChildIDFillFlowContainer<Drawable>
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
header = new ChangelogHeader(),
2018-07-22 16:35:29 +00:00
badges = new ChangelogBadges(),
chart = new ChangelogChart(),
2018-07-22 11:04:39 +00:00
content = new ChangelogContent()
2018-07-16 21:50:22 +00:00
},
},
},
};
2018-07-22 18:27:50 +00:00
badges.Selected += onBuildSelected;
2018-07-22 16:35:29 +00:00
// content.ShowListing();
// if (!Streams.IsHovered)
// foreach (StreamBadge item in Streams.BadgesContainer.Children)
// item.Activate(true);
// else
// foreach (StreamBadge item in Streams.BadgesContainer.Children)
// item.Deactivate();
2018-07-16 21:50:22 +00:00
}
// receive input outside our bounds so we can trigger a close event on ourselves.
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => true;
2018-07-18 17:32:15 +00:00
public override bool OnPressed(GlobalAction action)
{
switch (action)
{
case GlobalAction.Back:
2018-07-22 16:35:29 +00:00
if (isAtListing)
2018-07-19 22:52:50 +00:00
State = Visibility.Hidden;
else
2018-07-22 16:35:29 +00:00
FetchAndShowListing();
2018-07-18 17:32:15 +00:00
return true;
}
return false;
}
2018-07-16 21:50:22 +00:00
protected override void PopIn()
{
base.PopIn();
FadeEdgeEffectTo(0.25f, WaveContainer.APPEAR_DURATION, Easing.In);
}
protected override void PopOut()
{
base.PopOut();
FadeEdgeEffectTo(0, WaveContainer.DISAPPEAR_DURATION, Easing.Out);
}
2018-07-19 17:07:24 +00:00
2018-07-22 18:27:50 +00:00
private void onBuildSelected(string updateStream, string version, EventArgs e)
{
FetchAndShowBuild(updateStream, version);
}
2018-07-19 17:07:24 +00:00
[BackgroundDependencyLoader]
private void load(APIAccess api)
{
this.api = api;
}
2018-07-22 16:35:29 +00:00
/// <summary>
/// Fetches and shows changelog listing.
/// </summary>
public void FetchAndShowListing()
2018-07-19 17:07:24 +00:00
{
var req = new GetChangelogLatestBuildsRequest();
2018-07-22 16:35:29 +00:00
header.ShowListing();
badges.SelectNone();
chart.ShowAllUpdateStreams();
req.Success += content.ShowListing;
api.Queue(req);
}
/// <summary>
/// Fetches and shows a specific build from a specific update stream.
/// </summary>
/// <param name="sentByBadges">If true, will select fetched build's update stream badge.</param>
public void FetchAndShowBuild(string updateStream, string version)
{
var req = new GetChangelogBuildRequest(updateStream, version);
header.ShowBuild(updateStream, version);
2018-07-22 18:27:50 +00:00
badges.SelectUpdateStream(updateStream);
2018-07-22 16:35:29 +00:00
chart.ShowUpdateStream(updateStream);
req.Success += content.ShowBuild;
2018-07-19 17:07:24 +00:00
api.Queue(req);
}
2018-07-16 21:50:22 +00:00
}
}