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