1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-17 19:43:21 +08:00
osu-lazer/osu.Game/Overlays/Changelog/ChangelogHeader.cs

136 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;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API.Requests.Responses;
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 UpdateStreamBadgeArea Streams;
private const string listing_string = "listing";
private Box streamsBackground;
public ChangelogHeader()
{
2020-01-21 11:00:12 +08:00
TabControl.AddItem(listing_string);
Current.ValueChanged += e =>
{
if (e.NewValue == listing_string)
ListingSelected?.Invoke();
};
2019-05-21 12:34:35 +08:00
Build.ValueChanged += showBuild;
Streams.Current.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;
}
private ChangelogHeaderTitle title;
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
title.Version = e.NewValue.UpdateStream.DisplayName;
}
else
{
Current.Value = listing_string;
Streams.Current.Value = null;
2019-05-21 12:34:35 +08:00
title.Version = null;
}
}
protected override Drawable CreateBackground() => new OverlayHeaderBackground(@"Headers/changelog");
2019-05-13 16:32:49 +08:00
2019-12-27 11:36:41 +08:00
protected override Drawable CreateContent() => new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
2018-07-17 05:50:22 +08:00
Children = new Drawable[]
{
streamsBackground = new Box
{
RelativeSizeAxes = Axes.Both
},
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding
{
2020-02-29 07:21:52 +08:00
Horizontal = 65,
Vertical = 20
},
Child = Streams = new UpdateStreamBadgeArea()
}
}
};
2018-07-17 05:50:22 +08:00
protected override ScreenTitle CreateTitle() => title = new ChangelogHeaderTitle();
public void Populate(List<APIUpdateStream> streams)
{
Streams.Populate(streams);
updateCurrentStream();
}
private void updateCurrentStream()
{
if (Build.Value == null)
return;
Streams.Current.Value = Streams.Items.FirstOrDefault(s => s.Name == Build.Value.UpdateStream.Name);
}
private class ChangelogHeaderTitle : ScreenTitle
2018-07-17 05:50:22 +08:00
{
public string Version
{
set => Section = value ?? listing_string;
}
public ChangelogHeaderTitle()
{
2019-12-27 02:03:39 +08:00
Title = "changelog";
Version = null;
}
2019-08-11 15:15:44 +08:00
protected override Drawable CreateIcon() => new ScreenTitleTextureIcon(@"Icons/changelog");
2018-07-17 05:50:22 +08:00
}
}
}