1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-30 15:02:56 +08:00
osu-lazer/osu.Game/Overlays/Changelog/ChangelogHeader.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

129 lines
4.0 KiB
C#
Raw Normal View History

2019-05-17 10:43:36 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2019-05-13 16:14:52 +08:00
// See the LICENCE file in the repository root for full licence text.
2018-07-17 05:50:22 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
2019-05-21 12:34:35 +08:00
using osu.Framework.Bindables;
2018-07-17 05:50:22 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
2021-07-18 01:35:54 +08:00
using osu.Framework.Localisation;
2021-07-18 02:23:12 +08:00
using osu.Game.Localisation;
using osu.Game.Online.API.Requests.Responses;
2021-07-18 01:35:54 +08:00
using osu.Game.Resources.Localisation.Web;
2018-07-17 05:50:22 +08:00
namespace osu.Game.Overlays.Changelog
{
public class ChangelogHeader : BreadcrumbControlOverlayHeader
2018-07-17 05:50:22 +08:00
{
public readonly Bindable<APIChangelogBuild> Build = new Bindable<APIChangelogBuild>();
2019-05-21 12:34:35 +08:00
public Action ListingSelected;
2018-07-17 05:50:22 +08:00
public ChangelogUpdateStreamControl Streams;
public static LocalisableString ListingString => LayoutStrings.HeaderChangelogIndex;
private readonly Bindable<APIUpdateStream> currentStream = new Bindable<APIUpdateStream>();
private Box streamsBackground;
public ChangelogHeader()
{
2021-07-18 01:35:54 +08:00
TabControl.AddItem(ListingString);
Current.ValueChanged += e =>
{
2021-07-18 01:35:54 +08:00
if (e.NewValue == ListingString)
ListingSelected?.Invoke();
};
2019-05-21 12:34:35 +08:00
Build.ValueChanged += showBuild;
currentStream.ValueChanged += e =>
{
if (e.NewValue?.LatestBuild != null && !e.NewValue.Equals(Build.Value?.UpdateStream))
Build.Value = e.NewValue.LatestBuild;
};
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
streamsBackground.Colour = colourProvider.Background5;
}
2019-05-21 12:34:35 +08:00
private void showBuild(ValueChangedEvent<APIChangelogBuild> e)
{
2019-05-21 12:34:35 +08:00
if (e.OldValue != null)
2020-01-21 11:00:12 +08:00
TabControl.RemoveItem(e.OldValue.ToString());
2019-05-21 12:34:35 +08:00
if (e.NewValue != null)
{
2020-01-21 11:00:12 +08:00
TabControl.AddItem(e.NewValue.ToString());
Current.Value = e.NewValue.ToString();
updateCurrentStream();
2019-05-21 12:34:35 +08:00
}
else
{
2021-07-18 01:35:54 +08:00
Current.Value = ListingString;
currentStream.Value = null;
}
}
protected override Drawable CreateBackground() => new OverlayHeaderBackground(@"Headers/changelog");
2019-05-13 16:32:49 +08:00
2021-11-06 22:20:29 +08:00
protected override Drawable CreateContent() => new Container
{
2021-11-06 22:20:29 +08:00
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
2018-07-17 05:50:22 +08:00
{
2021-11-06 22:20:29 +08:00
streamsBackground = new Box
{
2021-11-06 22:20:29 +08:00
RelativeSizeAxes = Axes.Both
},
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding
{
2021-11-06 22:20:29 +08:00
Horizontal = 65,
Vertical = 20
},
2021-11-06 22:20:29 +08:00
Child = Streams = new ChangelogUpdateStreamControl { Current = currentStream },
}
2021-11-06 22:20:29 +08:00
}
};
2018-07-17 05:50:22 +08:00
protected override OverlayTitle CreateTitle() => new ChangelogHeaderTitle();
public void Populate(List<APIUpdateStream> streams)
{
Streams.Populate(streams);
updateCurrentStream();
}
private void updateCurrentStream()
{
if (Build.Value == null)
return;
currentStream.Value = Streams.Items.FirstOrDefault(s => s.Name == Build.Value.UpdateStream.Name);
}
private class ChangelogHeaderTitle : OverlayTitle
2018-07-17 05:50:22 +08:00
{
public ChangelogHeaderTitle()
{
2021-08-03 15:34:21 +08:00
Title = PageTitleStrings.MainChangelogControllerDefault;
Description = NamedOverlayComponentStrings.ChangelogDescription;
IconTexture = "Icons/Hexacons/devtools";
}
2018-07-17 05:50:22 +08:00
}
}
}