1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 18:27:26 +08:00
osu-lazer/osu.Game/Overlays/ChangelogOverlay.cs

157 lines
5.2 KiB
C#
Raw Normal View History

2018-07-17 05:50:22 +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;
using OpenTK.Graphics;
2018-07-20 01:07:24 +08:00
using osu.Framework.Allocation;
2018-07-17 05:50:22 +08: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-19 01:32:15 +08:00
using osu.Game.Input.Bindings;
2018-07-20 01:07:24 +08:00
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
2018-07-17 05:50:22 +08:00
using osu.Game.Overlays.Changelog;
namespace osu.Game.Overlays
{
public class ChangelogOverlay : WaveOverlayContainer
{
2018-07-19 01:32:15 +08:00
private readonly ChangelogHeader header;
public readonly ChangelogStreams Streams;
2018-07-20 01:07:24 +08:00
private APIChangelog changelogEntry;
private APIAccess api;
2018-07-17 05:50:22 +08:00
2018-07-19 01:32:15 +08:00
protected readonly Color4 Purple = new Color4(191, 4, 255, 255);
2018-07-18 00:32:11 +08:00
2018-07-17 05:50:22 +08:00
public ChangelogOverlay()
{
2018-07-18 00:32:11 +08: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-17 05:50:22 +08:00
Anchor = Anchor.TopCentre;
Origin = Anchor.TopCentre;
RelativeSizeAxes = Axes.Both;
Width = 0.85f;
Masking = true;
2018-07-18 00:32:11 +08:00
2018-07-20 01:07:24 +08:00
ChangelogContent content; // told by appveyor to conver to local variable..
2018-07-17 05:50:22 +08: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,
Colour = new Color4(20, 18, 23, 255)
},
2018-07-19 01:32:15 +08:00
new ScrollContainer
2018-07-17 05:50:22 +08: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-19 01:32:15 +08:00
Streams = new ChangelogStreams(),
2018-07-20 01:07:24 +08:00
new ChangelogChart(),
// will need to default to day-sorted content
content = new ChangelogContent(),
2018-07-17 05:50:22 +08:00
},
},
},
};
2018-07-20 03:49:13 +08:00
OnLoadComplete += d => FetchChangelog(); // is i
2018-07-20 01:07:24 +08:00
Streams.OnSelection = () =>
2018-07-18 07:35:06 +08:00
{
2018-07-20 01:07:24 +08:00
if (Streams.SelectedRelease != null)
{
header.ChangelogEntry = Streams.SelectedRelease;
}
header.ShowReleaseStream();
content.ShowBuild(Streams.SelectedRelease);
2018-07-18 07:35:06 +08:00
};
2018-07-20 01:07:24 +08:00
header.OnListingActivated += () =>
{
Streams.SelectedRelease = null;
content.Clear();
// should add listing to content here
if (!Streams.IsHovered)
2018-07-20 06:52:50 +08:00
foreach (StreamBadge item in Streams.BadgesContainer.Children)
item.Activate(true);
2018-07-20 01:07:24 +08:00
else
2018-07-20 06:52:50 +08:00
foreach (StreamBadge item in Streams.BadgesContainer.Children)
item.Deactivate();
2018-07-18 07:35:06 +08:00
};
2018-07-17 05:50:22 +08:00
}
2018-07-18 21:17:20 +08:00
public void ActivateListing() => header.ActivateListing();
2018-07-17 05:50:22 +08:00
// receive input outside our bounds so we can trigger a close event on ourselves.
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => true;
2018-07-19 01:32:15 +08:00
public override bool OnPressed(GlobalAction action)
{
switch (action)
{
case GlobalAction.Back:
2018-07-20 06:52:50 +08:00
if (header.IsListingActivated())
State = Visibility.Hidden;
else
header.ActivateListing();
2018-07-19 01:32:15 +08:00
return true;
}
return false;
}
2018-07-17 05:50:22 +08: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-20 01:07:24 +08:00
[BackgroundDependencyLoader]
private void load(APIAccess api)
{
this.api = api;
}
public void FetchChangelog()
{
var req = new GetChangelogLatestBuildsRequest();
req.Success += res =>
{
2018-07-20 03:49:13 +08:00
Streams.BadgesContainer.Clear();
2018-07-20 01:07:24 +08:00
foreach (APIChangelog item in res)
Streams.BadgesContainer.Add(new StreamBadge(item));
};
api.Queue(req);
}
2018-07-17 05:50:22 +08:00
}
}