mirror of https://github.com/ppy/osu
Use bindables the whole way
This commit is contained in:
parent
58a3480b6a
commit
a131875a7b
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace osu.Game.Online.API.Requests.Responses
|
||||
{
|
||||
public class APIChangelogBuild
|
||||
public class APIChangelogBuild : IEquatable<APIChangelogBuild>
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public long Id { get; set; }
|
||||
|
@ -42,6 +42,8 @@ public class VersionNatigation
|
|||
public APIChangelogBuild Previous { get; set; }
|
||||
}
|
||||
|
||||
public bool Equals(APIChangelogBuild other) => this.Id == other?.Id;
|
||||
|
||||
public override string ToString() => $"{UpdateStream.DisplayName} {DisplayVersion}";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,13 +25,7 @@ public class APIUpdateStream : IEquatable<APIUpdateStream>
|
|||
[JsonProperty("latest_build")]
|
||||
public APIChangelogBuild LatestBuild { get; set; }
|
||||
|
||||
public bool Equals(APIUpdateStream other)
|
||||
{
|
||||
if (ReferenceEquals(null, other)) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
|
||||
return Id == other.Id;
|
||||
}
|
||||
public bool Equals(APIUpdateStream other) => this.Id == other?.Id;
|
||||
|
||||
public ColourInfo Colour
|
||||
{
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
|
@ -17,6 +18,8 @@ namespace osu.Game.Overlays.Changelog
|
|||
{
|
||||
public class ChangelogHeader : OverlayHeader
|
||||
{
|
||||
public readonly Bindable<APIChangelogBuild> Current = new Bindable<APIChangelogBuild>();
|
||||
|
||||
public Action ListingSelected;
|
||||
|
||||
private const string listing_string = "Listing";
|
||||
|
@ -29,6 +32,8 @@ public ChangelogHeader()
|
|||
if (e.NewValue == listing_string)
|
||||
ListingSelected?.Invoke();
|
||||
};
|
||||
|
||||
Current.ValueChanged += showBuild;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
|
@ -37,35 +42,24 @@ private void load(OsuColour colours)
|
|||
TabControl.AccentColour = colours.Violet;
|
||||
}
|
||||
|
||||
private APIChangelogBuild displayedBuild;
|
||||
|
||||
private ChangelogHeaderTitle title;
|
||||
|
||||
public void ShowBuild(APIChangelogBuild build)
|
||||
private void showBuild(ValueChangedEvent<APIChangelogBuild> e)
|
||||
{
|
||||
hideBuildTab();
|
||||
if (e.OldValue != null)
|
||||
TabControl.RemoveItem(e.OldValue.ToString());
|
||||
|
||||
displayedBuild = build;
|
||||
|
||||
TabControl.AddItem(build.ToString());
|
||||
TabControl.Current.Value = build.ToString();
|
||||
|
||||
title.Version = build.UpdateStream.DisplayName;
|
||||
}
|
||||
|
||||
public void ShowListing()
|
||||
{
|
||||
hideBuildTab();
|
||||
|
||||
title.Version = null;
|
||||
}
|
||||
|
||||
private void hideBuildTab()
|
||||
{
|
||||
if (displayedBuild != null)
|
||||
if (e.NewValue != null)
|
||||
{
|
||||
TabControl.RemoveItem(displayedBuild.ToString());
|
||||
displayedBuild = null;
|
||||
TabControl.AddItem(e.NewValue.ToString());
|
||||
TabControl.Current.Value = e.NewValue.ToString();
|
||||
|
||||
title.Version = e.NewValue.UpdateStream.DisplayName;
|
||||
}
|
||||
else
|
||||
{
|
||||
TabControl.Current.Value = listing_string;
|
||||
title.Version = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
|
@ -32,6 +34,23 @@ public class ChangelogOverlay : FullscreenOverlay
|
|||
|
||||
private List<APIChangelogBuild> builds;
|
||||
|
||||
public readonly Bindable<APIChangelogBuild> Current = new Bindable<APIChangelogBuild>();
|
||||
|
||||
public void ShowListing() => Current.Value = null;
|
||||
|
||||
/// <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>
|
||||
public void ShowBuild([NotNull] APIChangelogBuild build)
|
||||
{
|
||||
if (build == null) throw new ArgumentNullException(nameof(build));
|
||||
|
||||
Current.Value = build;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(AudioManager audio, OsuColour colour)
|
||||
{
|
||||
|
@ -73,22 +92,30 @@ private void load(AudioManager audio, OsuColour colour)
|
|||
},
|
||||
};
|
||||
|
||||
// todo: better
|
||||
badges.Current.ValueChanged += e =>
|
||||
{
|
||||
if (e.NewValue?.LatestBuild != null)
|
||||
if (e.NewValue != null)
|
||||
ShowBuild(e.NewValue.LatestBuild);
|
||||
};
|
||||
|
||||
sampleBack = audio.Sample.Get(@"UI/generic-select-soft");
|
||||
}
|
||||
|
||||
protected override void PopIn()
|
||||
{
|
||||
base.PopIn();
|
||||
header.Current.BindTo(Current);
|
||||
|
||||
if (!initialFetchPerformed)
|
||||
fetchListing();
|
||||
Current.BindValueChanged(e =>
|
||||
{
|
||||
if (e.NewValue != null)
|
||||
{
|
||||
badges.Current.Value = e.NewValue.UpdateStream;
|
||||
|
||||
loadContent(new ChangelogSingleBuild(e.NewValue));
|
||||
}
|
||||
else
|
||||
{
|
||||
badges.Current.Value = null;
|
||||
loadContent(new ChangelogListing(builds));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public override bool OnPressed(GlobalAction action)
|
||||
|
@ -96,13 +123,13 @@ public override bool OnPressed(GlobalAction action)
|
|||
switch (action)
|
||||
{
|
||||
case GlobalAction.Back:
|
||||
if (content.Child is ChangelogListing)
|
||||
if (Current.Value == null)
|
||||
{
|
||||
State = Visibility.Hidden;
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowListing();
|
||||
Current.Value = null;
|
||||
sampleBack?.Play();
|
||||
}
|
||||
|
||||
|
@ -112,34 +139,12 @@ public override bool OnPressed(GlobalAction action)
|
|||
return false;
|
||||
}
|
||||
|
||||
public void ShowListing()
|
||||
protected override void PopIn()
|
||||
{
|
||||
if (content.Children.FirstOrDefault() is ChangelogListing)
|
||||
return;
|
||||
base.PopIn();
|
||||
|
||||
header.ShowListing();
|
||||
badges.Current.Value = null;
|
||||
loadContent(new ChangelogListing(builds));
|
||||
}
|
||||
|
||||
/// <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>
|
||||
public void ShowBuild(APIChangelogBuild build)
|
||||
{
|
||||
if (build == null)
|
||||
{
|
||||
ShowListing();
|
||||
return;
|
||||
}
|
||||
|
||||
header.ShowBuild(build);
|
||||
badges.Current.Value = build.UpdateStream;
|
||||
|
||||
loadContent(new ChangelogSingleBuild(build));
|
||||
if (!initialFetchPerformed)
|
||||
fetchListing();
|
||||
}
|
||||
|
||||
private bool initialFetchPerformed;
|
||||
|
@ -158,7 +163,7 @@ private void fetchListing()
|
|||
builds = res.Builds;
|
||||
badges.Populate(res.Streams);
|
||||
|
||||
ShowListing();
|
||||
Current.TriggerChange();
|
||||
};
|
||||
req.Failure += _ => initialFetchPerformed = false;
|
||||
|
||||
|
|
Loading…
Reference in New Issue