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

189 lines
5.9 KiB
C#
Raw Normal View History

2019-05-13 16:14:52 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2018-07-17 05:50:22 +08:00
2018-07-20 01:07:24 +08:00
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
2018-07-17 05:50:22 +08:00
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.Requests;
using osu.Game.Online.API.Requests.Responses;
2018-07-17 05:50:22 +08:00
using osu.Game.Overlays.Changelog;
2019-05-12 23:36:05 +08:00
using osuTK.Graphics;
2018-07-17 05:50:22 +08:00
namespace osu.Game.Overlays
{
public class ChangelogOverlay : FullscreenOverlay
2018-07-17 05:50:22 +08:00
{
private ChangelogHeader header;
2019-05-12 23:36:05 +08:00
2019-05-15 17:08:19 +08:00
private BadgeDisplay badges;
2019-05-12 23:36:05 +08:00
private ChangelogContent listing;
private ChangelogContent content;
2018-07-23 00:35:29 +08:00
private ScrollContainer scroll;
2018-07-20 01:07:24 +08:00
2018-07-25 00:41:47 +08:00
private SampleChannel sampleBack;
private float savedScrollPosition;
2018-07-18 00:32:11 +08:00
[BackgroundDependencyLoader]
private void load(AudioManager audio, OsuColour colour)
2018-07-17 05:50:22 +08:00
{
2018-07-18 00:32:11 +08:00
// these possibly need adjusting?
Waves.FirstWaveColour = colour.Violet;
2018-07-18 00:32:11 +08:00
Waves.SecondWaveColour = OsuColour.FromHex(@"8F03BF");
Waves.ThirdWaveColour = OsuColour.FromHex(@"600280");
Waves.FourthWaveColour = OsuColour.FromHex(@"300140");
2018-07-17 05:50:22 +08:00
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
2018-07-22 05:00:05 +08:00
Colour = new Color4(49, 36, 54, 255),
2018-07-17 05:50:22 +08:00
},
scroll = 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(),
2019-05-15 17:08:19 +08:00
badges = new BadgeDisplay(),
listing = new ChangelogContent(),
2018-07-22 19:04:39 +08:00
content = new ChangelogContent()
2018-07-17 05:50:22 +08:00
},
},
},
};
header.ListingSelected += ShowListing;
2019-05-15 17:08:19 +08:00
badges.Selected += ShowBuild;
listing.BuildSelected += ShowBuild;
content.BuildSelected += ShowBuild;
2018-07-17 05:50:22 +08:00
2018-07-25 00:41:47 +08:00
sampleBack = audio.Sample.Get(@"UI/generic-select-soft"); // @"UI/screen-back" feels non-fitting here
}
2018-07-19 01:32:15 +08:00
2018-07-25 00:41:47 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
fetchListing();
2018-07-19 01:32:15 +08:00
}
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
2018-07-25 00:41:47 +08:00
public override bool OnPressed(GlobalAction action)
2018-07-23 02:27:50 +08:00
{
2018-07-25 00:41:47 +08:00
switch (action)
{
case GlobalAction.Back:
if (isAtListing)
{
if (scroll.Current > scroll.GetChildPosInContent(listing))
{
scroll.ScrollTo(0);
sampleBack?.Play();
}
else
State = Visibility.Hidden;
}
2018-07-25 00:41:47 +08:00
else
{
ShowListing();
2018-07-25 00:41:47 +08:00
sampleBack?.Play();
}
2019-05-12 23:36:05 +08:00
2018-07-25 00:41:47 +08:00
return true;
}
2018-07-23 02:27:50 +08:00
2018-07-25 00:41:47 +08:00
return false;
2018-07-20 01:07:24 +08:00
}
private void fetchListing()
2018-07-20 01:07:24 +08:00
{
header.ShowListing();
2018-07-23 04:13:14 +08:00
var req = new GetChangelogRequest();
req.Success += res =>
{
listing.ShowListing(res.Builds);
2019-05-15 17:08:19 +08:00
badges.Populate(res.Streams);
};
API.Queue(req);
2018-07-23 00:35:29 +08:00
}
2019-05-15 17:08:19 +08:00
private bool isAtListing;
public void ShowListing()
{
2019-05-15 17:08:19 +08:00
isAtListing = true;
header.ShowListing();
content.Hide();
2019-05-15 17:08:19 +08:00
badges.SelectNone();
listing.Show();
scroll.ScrollTo(savedScrollPosition);
}
2018-07-23 00:35:29 +08:00
/// <summary>
/// Fetches and shows a specific build from a specific update stream.
/// </summary>
/// <param name="build">Must contain at least <see cref="APIUpdateStream.Name"/> and
/// <see cref="APIChangelogBuild.Version"/>. If <see cref="APIUpdateStream.DisplayName"/> and
/// <see cref="APIChangelogBuild.DisplayVersion"/> are specified, the header will instantly display them.</param>
2019-05-15 17:08:19 +08:00
public void ShowBuild(APIChangelogBuild build)
2018-07-23 00:35:29 +08:00
{
2019-05-15 17:21:06 +08:00
header.ShowBuild(build.UpdateStream.DisplayName, build.DisplayVersion);
2019-05-15 17:08:19 +08:00
badges.SelectUpdateStream(build.UpdateStream.Name);
2019-05-15 17:21:06 +08:00
listing.Hide();
void displayBuild(APIChangelogBuild populatedBuild)
{
content.Show();
2019-05-15 17:21:06 +08:00
content.ShowBuild(populatedBuild);
if (scroll.Current > scroll.GetChildPosInContent(content))
scroll.ScrollTo(content);
2019-05-15 17:21:06 +08:00
2018-07-25 03:19:29 +08:00
if (isAtListing)
savedScrollPosition = scroll.Current;
isAtListing = false;
2019-05-15 17:21:06 +08:00
}
2019-05-15 17:21:06 +08:00
if (build.Versions != null)
displayBuild(build);
else
{
var req = new GetChangelogBuildRequest(build.UpdateStream.Name, build.Version);
req.Success += displayBuild;
API.Queue(req);
}
2018-07-20 01:07:24 +08:00
}
2018-07-17 05:50:22 +08:00
}
}