1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 17:47:29 +08:00
osu-lazer/osu.Game/Overlays/Changelog/ChangelogHeader.cs

128 lines
3.8 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.Linq;
2018-07-17 05:50:22 +08:00
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.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Game.Graphics;
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 : OverlayHeader
2018-07-17 05:50:22 +08:00
{
2019-05-21 12:34:35 +08:00
public readonly Bindable<APIChangelogBuild> Current = new Bindable<APIChangelogBuild>();
public Action ListingSelected;
2018-07-17 05:50:22 +08:00
public UpdateStreamBadgeArea Streams;
private const string listing_string = "Listing";
public ChangelogHeader()
{
TabControl.AddItem(listing_string);
TabControl.Current.ValueChanged += e =>
{
if (e.NewValue == listing_string)
ListingSelected?.Invoke();
};
2019-05-21 12:34:35 +08:00
Current.ValueChanged += showBuild;
Streams.Current.ValueChanged += e =>
{
if (e.NewValue?.LatestBuild != null && e.NewValue != Current.Value?.UpdateStream)
Current.Value = e.NewValue.LatestBuild;
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
TabControl.AccentColour = colours.Violet;
}
2018-07-20 01:07:24 +08:00
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)
TabControl.RemoveItem(e.OldValue.ToString());
2019-05-21 12:34:35 +08:00
if (e.NewValue != null)
{
TabControl.AddItem(e.NewValue.ToString());
TabControl.Current.Value = e.NewValue.ToString();
Streams.Current.Value = Streams.Items.FirstOrDefault(s => s.Name == e.NewValue.UpdateStream.Name);
2019-05-21 12:34:35 +08:00
title.Version = e.NewValue.UpdateStream.DisplayName;
}
else
{
2019-05-21 12:34:35 +08:00
TabControl.Current.Value = listing_string;
Streams.Current.Value = null;
2019-05-21 12:34:35 +08:00
title.Version = null;
}
}
protected override Drawable CreateBackground() => new HeaderBackground();
2019-05-13 16:32:49 +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[]
{
Streams = new UpdateStreamBadgeArea(),
}
};
2018-07-17 05:50:22 +08:00
protected override ScreenTitle CreateTitle() => title = new ChangelogHeaderTitle();
public class HeaderBackground : Sprite
2018-07-17 05:50:22 +08:00
{
public HeaderBackground()
{
RelativeSizeAxes = Axes.Both;
FillMode = FillMode.Fill;
}
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
Texture = textures.Get(@"Headers/changelog");
}
2018-07-17 05:50:22 +08:00
}
private class ChangelogHeaderTitle : ScreenTitle
2018-07-17 05:50:22 +08:00
{
public string Version
{
set => Section = value ?? listing_string;
}
public ChangelogHeaderTitle()
{
Title = "Changelog";
Version = null;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
AccentColour = colours.Violet;
}
protected override Drawable CreateIcon() => new ScreenTitleIcon(@"Icons/changelog");
2018-07-17 05:50:22 +08:00
}
}
}