1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 01:27:29 +08:00

Merge branch 'master' into epilepsy-warning-volume-restoration

This commit is contained in:
Dean Herbert 2020-10-25 22:22:11 +09:00 committed by GitHub
commit 431054377a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 314 additions and 284 deletions

View File

@ -0,0 +1,65 @@
// 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.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
using osu.Game.Skinning;
using osu.Game.Storyboards;
using osu.Game.Storyboards.Drawables;
using osuTK;
namespace osu.Game.Tests.Visual.Gameplay
{
public class TestSceneDrawableStoryboardSprite : SkinnableTestScene
{
protected override Ruleset CreateRulesetForSkinProvider() => new OsuRuleset();
[Cached]
private Storyboard storyboard { get; set; } = new Storyboard();
[Test]
public void TestSkinSpriteDisallowedByDefault()
{
const string lookup_name = "hitcircleoverlay";
AddStep("allow skin lookup", () => storyboard.UseSkinSprites = false);
AddStep("create sprites", () => SetContents(
() => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
assertSpritesFromSkin(false);
}
[Test]
public void TestAllowLookupFromSkin()
{
const string lookup_name = "hitcircleoverlay";
AddStep("allow skin lookup", () => storyboard.UseSkinSprites = true);
AddStep("create sprites", () => SetContents(
() => createSprite(lookup_name, Anchor.Centre, Vector2.Zero)));
assertSpritesFromSkin(true);
}
private DrawableStoryboardSprite createSprite(string lookupName, Anchor origin, Vector2 initialPosition)
=> new DrawableStoryboardSprite(
new StoryboardSprite(lookupName, origin, initialPosition)
).With(s =>
{
s.LifetimeStart = double.MinValue;
s.LifetimeEnd = double.MaxValue;
});
private void assertSpritesFromSkin(bool fromSkin) =>
AddAssert($"sprites are {(fromSkin ? "from skin" : "from storyboard")}",
() => this.ChildrenOfType<DrawableStoryboardSprite>()
.All(sprite => sprite.ChildrenOfType<SkinnableSprite>().Any() == fromSkin));
}
}

View File

@ -3,14 +3,13 @@
using System;
using System.Collections.Generic;
using osu.Framework.Graphics.Containers;
using osu.Game.Overlays.Dashboard.Friends;
using osu.Framework.Graphics;
using osu.Game.Users;
using osu.Game.Overlays;
using osu.Framework.Allocation;
using NUnit.Framework;
using osu.Game.Online.API;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Overlays;
using osu.Game.Overlays.Dashboard.Friends;
using osu.Game.Users;
namespace osu.Game.Tests.Visual.Online
{
@ -36,7 +35,7 @@ namespace osu.Game.Tests.Visual.Online
[Test]
public void TestOffline()
{
AddStep("Populate", () => display.Users = getUsers());
AddStep("Populate with offline test users", () => display.Users = getUsers());
}
[Test]
@ -80,14 +79,7 @@ namespace osu.Game.Tests.Visual.Online
private class TestFriendDisplay : FriendDisplay
{
public void Fetch()
{
base.APIStateChanged(API, APIState.Online);
}
public override void APIStateChanged(IAPIProvider api, APIState state)
{
}
public void Fetch() => PerformFetch();
}
}
}

View File

@ -32,7 +32,7 @@ namespace osu.Game.Tests.Visual.Online
[Test]
public void TestOnlineStateVisibility()
{
AddStep("set status to online", () => ((DummyAPIAccess)API).State = APIState.Online);
AddStep("set status to online", () => ((DummyAPIAccess)API).SetState(APIState.Online));
AddUntilStep("children are visible", () => onlineView.ViewTarget.IsPresent);
AddUntilStep("loading animation is not visible", () => !onlineView.LoadingSpinner.IsPresent);
@ -41,7 +41,7 @@ namespace osu.Game.Tests.Visual.Online
[Test]
public void TestOfflineStateVisibility()
{
AddStep("set status to offline", () => ((DummyAPIAccess)API).State = APIState.Offline);
AddStep("set status to offline", () => ((DummyAPIAccess)API).SetState(APIState.Offline));
AddUntilStep("children are not visible", () => !onlineView.ViewTarget.IsPresent);
AddUntilStep("loading animation is not visible", () => !onlineView.LoadingSpinner.IsPresent);
@ -50,7 +50,7 @@ namespace osu.Game.Tests.Visual.Online
[Test]
public void TestConnectingStateVisibility()
{
AddStep("set status to connecting", () => ((DummyAPIAccess)API).State = APIState.Connecting);
AddStep("set status to connecting", () => ((DummyAPIAccess)API).SetState(APIState.Connecting));
AddUntilStep("children are not visible", () => !onlineView.ViewTarget.IsPresent);
AddUntilStep("loading animation is visible", () => onlineView.LoadingSpinner.IsPresent);
@ -59,7 +59,7 @@ namespace osu.Game.Tests.Visual.Online
[Test]
public void TestFailingStateVisibility()
{
AddStep("set status to failing", () => ((DummyAPIAccess)API).State = APIState.Failing);
AddStep("set status to failing", () => ((DummyAPIAccess)API).SetState(APIState.Failing));
AddUntilStep("children are not visible", () => !onlineView.ViewTarget.IsPresent);
AddUntilStep("loading animation is visible", () => onlineView.LoadingSpinner.IsPresent);

View File

@ -18,13 +18,13 @@ namespace osu.Game.Tests.Visual.Ranking
Origin = Anchor.Centre,
Children = new Drawable[]
{
new StarRatingDisplay(new BeatmapInfo { StarDifficulty = 1.23 }),
new StarRatingDisplay(new BeatmapInfo { StarDifficulty = 2.34 }),
new StarRatingDisplay(new BeatmapInfo { StarDifficulty = 3.45 }),
new StarRatingDisplay(new BeatmapInfo { StarDifficulty = 4.56 }),
new StarRatingDisplay(new BeatmapInfo { StarDifficulty = 5.67 }),
new StarRatingDisplay(new BeatmapInfo { StarDifficulty = 6.78 }),
new StarRatingDisplay(new BeatmapInfo { StarDifficulty = 10.11 }),
new StarRatingDisplay(new StarDifficulty(1.23, 0)),
new StarRatingDisplay(new StarDifficulty(2.34, 0)),
new StarRatingDisplay(new StarDifficulty(3.45, 0)),
new StarRatingDisplay(new StarDifficulty(4.56, 0)),
new StarRatingDisplay(new StarDifficulty(5.67, 0)),
new StarRatingDisplay(new StarDifficulty(6.78, 0)),
new StarRatingDisplay(new StarDifficulty(10.11, 0)),
}
};
}

View File

@ -63,7 +63,7 @@ namespace osu.Game.Beatmaps
if (checkLocalCache(set, beatmap))
return;
if (api?.State != APIState.Online)
if (api?.State.Value != APIState.Online)
return;
var req = new GetBeatmapRequest(beatmap);

View File

@ -48,6 +48,10 @@ namespace osu.Game.Beatmaps.Formats
switch (section)
{
case Section.General:
handleGeneral(storyboard, line);
return;
case Section.Events:
handleEvents(line);
return;
@ -60,6 +64,18 @@ namespace osu.Game.Beatmaps.Formats
base.ParseLine(storyboard, section, line);
}
private void handleGeneral(Storyboard storyboard, string line)
{
var pair = SplitKeyVal(line);
switch (pair.Key)
{
case "UseSkinSprites":
storyboard.UseSkinSprites = pair.Value == "1";
break;
}
}
private void handleEvents(string line)
{
var depth = 0;

View File

@ -44,6 +44,11 @@ namespace osu.Game.Graphics.UserInterface
// blocking scroll can cause weird behaviour when this layer is used within a ScrollContainer.
case ScrollEvent _:
return false;
// blocking touch events causes the ISourcedFromTouch versions to not be fired, potentially impeding behaviour of drawables *above* the loading layer that may utilise these.
// note that this will not work well if touch handling elements are beneath this loading layer (something to consider for the future).
case TouchEvent _:
return false;
}
return true;

View File

@ -78,26 +78,8 @@ namespace osu.Game.Online.API
private void onTokenChanged(ValueChangedEvent<OAuthToken> e) => config.Set(OsuSetting.Token, config.Get<bool>(OsuSetting.SavePassword) ? authentication.TokenString : string.Empty);
private readonly List<IOnlineComponent> components = new List<IOnlineComponent>();
internal new void Schedule(Action action) => base.Schedule(action);
/// <summary>
/// Register a component to receive API events.
/// Fires <see cref="IOnlineComponent.APIStateChanged"/> once immediately to ensure a correct state.
/// </summary>
/// <param name="component"></param>
public void Register(IOnlineComponent component)
{
Schedule(() => components.Add(component));
component.APIStateChanged(this, state);
}
public void Unregister(IOnlineComponent component)
{
Schedule(() => components.Remove(component));
}
public string AccessToken => authentication.RequestAccessToken();
/// <summary>
@ -109,7 +91,7 @@ namespace osu.Game.Online.API
{
while (!cancellationToken.IsCancellationRequested)
{
switch (State)
switch (State.Value)
{
case APIState.Failing:
//todo: replace this with a ping request.
@ -131,12 +113,12 @@ namespace osu.Game.Online.API
// work to restore a connection...
if (!HasLogin)
{
State = APIState.Offline;
state.Value = APIState.Offline;
Thread.Sleep(50);
continue;
}
State = APIState.Connecting;
state.Value = APIState.Connecting;
// save the username at this point, if the user requested for it to be.
config.Set(OsuSetting.Username, config.Get<bool>(OsuSetting.SaveUsername) ? ProvidedUsername : string.Empty);
@ -162,20 +144,20 @@ namespace osu.Game.Online.API
failureCount = 0;
//we're connected!
State = APIState.Online;
state.Value = APIState.Online;
};
if (!handleRequest(userReq))
{
if (State == APIState.Connecting)
State = APIState.Failing;
if (State.Value == APIState.Connecting)
state.Value = APIState.Failing;
continue;
}
// The Success callback event is fired on the main thread, so we should wait for that to run before proceeding.
// Without this, we will end up circulating this Connecting loop multiple times and queueing up many web requests
// before actually going online.
while (State > APIState.Offline && State < APIState.Online)
while (State.Value > APIState.Offline && State.Value < APIState.Online)
Thread.Sleep(500);
break;
@ -224,7 +206,7 @@ namespace osu.Game.Online.API
public void Login(string username, string password)
{
Debug.Assert(State == APIState.Offline);
Debug.Assert(State.Value == APIState.Offline);
ProvidedUsername = username;
this.password = password;
@ -232,7 +214,7 @@ namespace osu.Game.Online.API
public RegistrationRequest.RegistrationRequestErrors CreateAccount(string email, string username, string password)
{
Debug.Assert(State == APIState.Offline);
Debug.Assert(State.Value == APIState.Offline);
var req = new RegistrationRequest
{
@ -276,7 +258,7 @@ namespace osu.Game.Online.API
req.Perform(this);
// we could still be in initialisation, at which point we don't want to say we're Online yet.
if (IsLoggedIn) State = APIState.Online;
if (IsLoggedIn) state.Value = APIState.Online;
failureCount = 0;
return true;
@ -293,27 +275,12 @@ namespace osu.Game.Online.API
}
}
private APIState state;
private readonly Bindable<APIState> state = new Bindable<APIState>();
public APIState State
{
get => state;
private set
{
if (state == value)
return;
APIState oldState = state;
state = value;
log.Add($@"We just went {state}!");
Schedule(() =>
{
components.ForEach(c => c.APIStateChanged(this, state));
OnStateChange?.Invoke(oldState, state);
});
}
}
/// <summary>
/// The current connectivity state of the API.
/// </summary>
public IBindable<APIState> State => state;
private bool handleWebException(WebException we)
{
@ -343,9 +310,9 @@ namespace osu.Game.Online.API
// we might try again at an api level.
return false;
if (State == APIState.Online)
if (State.Value == APIState.Online)
{
State = APIState.Failing;
state.Value = APIState.Failing;
flushQueue();
}
@ -362,10 +329,6 @@ namespace osu.Game.Online.API
lock (queue) queue.Enqueue(request);
}
public event StateChangeDelegate OnStateChange;
public delegate void StateChangeDelegate(APIState oldState, APIState newState);
private void flushQueue(bool failOldRequests = true)
{
lock (queue)
@ -392,7 +355,7 @@ namespace osu.Game.Online.API
// Scheduled prior to state change such that the state changed event is invoked with the correct user present
Schedule(() => LocalUser.Value = createGuestUser());
State = APIState.Offline;
state.Value = APIState.Offline;
}
private static User createGuestUser() => new GuestUser();

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using osu.Framework.Bindables;
@ -21,34 +20,23 @@ namespace osu.Game.Online.API
public Bindable<UserActivity> Activity { get; } = new Bindable<UserActivity>();
public bool IsLoggedIn => State == APIState.Online;
public bool IsLoggedIn => State.Value == APIState.Online;
public string ProvidedUsername => LocalUser.Value.Username;
public string Endpoint => "http://localhost";
private APIState state = APIState.Online;
private readonly List<IOnlineComponent> components = new List<IOnlineComponent>();
/// <summary>
/// Provide handling logic for an arbitrary API request.
/// </summary>
public Action<APIRequest> HandleRequest;
public APIState State
{
get => state;
set
{
if (state == value)
return;
private readonly Bindable<APIState> state = new Bindable<APIState>(APIState.Online);
state = value;
Scheduler.Add(() => components.ForEach(c => c.APIStateChanged(this, value)));
}
}
/// <summary>
/// The current connectivity state of the API.
/// </summary>
public IBindable<APIState> State => state;
public DummyAPIAccess()
{
@ -72,17 +60,6 @@ namespace osu.Game.Online.API
return Task.CompletedTask;
}
public void Register(IOnlineComponent component)
{
Scheduler.Add(delegate { components.Add(component); });
component.APIStateChanged(this, state);
}
public void Unregister(IOnlineComponent component)
{
Scheduler.Add(delegate { components.Remove(component); });
}
public void Login(string username, string password)
{
LocalUser.Value = new User
@ -91,13 +68,13 @@ namespace osu.Game.Online.API
Id = 1001,
};
State = APIState.Online;
state.Value = APIState.Online;
}
public void Logout()
{
LocalUser.Value = new GuestUser();
State = APIState.Offline;
state.Value = APIState.Offline;
}
public RegistrationRequest.RegistrationRequestErrors CreateAccount(string email, string username, string password)
@ -105,5 +82,7 @@ namespace osu.Game.Online.API
Thread.Sleep(200);
return null;
}
public void SetState(APIState newState) => state.Value = newState;
}
}

View File

@ -11,11 +11,13 @@ namespace osu.Game.Online.API
{
/// <summary>
/// The local user.
/// This is not thread-safe and should be scheduled locally if consumed from a drawable component.
/// </summary>
Bindable<User> LocalUser { get; }
/// <summary>
/// The current user's activity.
/// This is not thread-safe and should be scheduled locally if consumed from a drawable component.
/// </summary>
Bindable<UserActivity> Activity { get; }
@ -35,7 +37,11 @@ namespace osu.Game.Online.API
/// </summary>
string Endpoint { get; }
APIState State { get; }
/// <summary>
/// The current connection state of the API.
/// This is not thread-safe and should be scheduled locally if consumed from a drawable component.
/// </summary>
IBindable<APIState> State { get; }
/// <summary>
/// Queue a new request.
@ -61,18 +67,6 @@ namespace osu.Game.Online.API
/// <param name="request">The request to perform.</param>
Task PerformAsync(APIRequest request);
/// <summary>
/// Register a component to receive state changes.
/// </summary>
/// <param name="component">The component to register.</param>
void Register(IOnlineComponent component);
/// <summary>
/// Unregisters a component to receive state changes.
/// </summary>
/// <param name="component">The component to unregister.</param>
void Unregister(IOnlineComponent component);
/// <summary>
/// Attempt to login using the provided credentials. This is a non-blocking operation.
/// </summary>

View File

@ -1,10 +0,0 @@
// 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.
namespace osu.Game.Online.API
{
public interface IOnlineComponent
{
void APIStateChanged(IAPIProvider api, APIState state);
}
}

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
@ -22,7 +23,7 @@ using osuTK.Graphics;
namespace osu.Game.Online.Leaderboards
{
public abstract class Leaderboard<TScope, TScoreInfo> : Container, IOnlineComponent
public abstract class Leaderboard<TScope, TScoreInfo> : Container
{
private const double fade_duration = 300;
@ -242,16 +243,13 @@ namespace osu.Game.Online.Leaderboards
private ScheduledDelegate pendingUpdateScores;
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
[BackgroundDependencyLoader]
private void load()
{
api?.Register(this);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
api?.Unregister(this);
apiState.BindTo(api.State);
apiState.BindValueChanged(onlineStateChanged, true);
}
public void RefreshScores() => UpdateScores();
@ -260,9 +258,9 @@ namespace osu.Game.Online.Leaderboards
protected abstract bool IsOnlineScope { get; }
public void APIStateChanged(IAPIProvider api, APIState state)
private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
{
switch (state)
switch (state.NewValue)
{
case APIState.Online:
case APIState.Offline:
@ -271,7 +269,7 @@ namespace osu.Game.Online.Leaderboards
break;
}
}
});
protected void UpdateScores()
{

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
@ -14,7 +15,7 @@ namespace osu.Game.Online
/// A <see cref="Container"/> for displaying online content which require a local user to be logged in.
/// Shows its children only when the local user is logged in and supports displaying a placeholder if not.
/// </summary>
public abstract class OnlineViewContainer : Container, IOnlineComponent
public abstract class OnlineViewContainer : Container
{
protected LoadingSpinner LoadingSpinner { get; private set; }
@ -34,8 +35,10 @@ namespace osu.Game.Online
this.placeholderMessage = placeholderMessage;
}
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
[BackgroundDependencyLoader]
private void load()
private void load(IAPIProvider api)
{
InternalChildren = new Drawable[]
{
@ -46,18 +49,14 @@ namespace osu.Game.Online
Alpha = 0,
}
};
apiState.BindTo(api.State);
apiState.BindValueChanged(onlineStateChanged, true);
}
protected override void LoadComplete()
private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
{
base.LoadComplete();
API.Register(this);
}
public virtual void APIStateChanged(IAPIProvider api, APIState state)
{
switch (state)
switch (state.NewValue)
{
case APIState.Offline:
PopContentOut(Content);
@ -79,7 +78,7 @@ namespace osu.Game.Online
placeholder.FadeOut(transform_duration / 2, Easing.OutQuint);
break;
}
}
});
/// <summary>
/// Applies a transform to the online content to make it hidden.
@ -90,11 +89,5 @@ namespace osu.Game.Online
/// Applies a transform to the online content to make it visible.
/// </summary>
protected virtual void PopContentIn(Drawable content) => content.FadeIn(transform_duration, Easing.OutQuint);
protected override void Dispose(bool isDisposing)
{
API?.Unregister(this);
base.Dispose(isDisposing);
}
}
}

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -17,7 +18,7 @@ using osuTK.Graphics;
namespace osu.Game.Overlays
{
public class AccountCreationOverlay : OsuFocusedOverlayContainer, IOnlineComponent
public class AccountCreationOverlay : OsuFocusedOverlayContainer
{
private const float transition_time = 400;
@ -30,10 +31,13 @@ namespace osu.Game.Overlays
Origin = Anchor.Centre;
}
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
[BackgroundDependencyLoader]
private void load(OsuColour colours, IAPIProvider api)
{
api.Register(this);
apiState.BindTo(api.State);
apiState.BindValueChanged(apiStateChanged, true);
Children = new Drawable[]
{
@ -97,9 +101,9 @@ namespace osu.Game.Overlays
this.FadeOut(100);
}
public void APIStateChanged(IAPIProvider api, APIState state)
private void apiStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
{
switch (state)
switch (state.NewValue)
{
case APIState.Offline:
case APIState.Failing:
@ -112,6 +116,6 @@ namespace osu.Game.Overlays
Hide();
break;
}
}
});
}
}

View File

@ -33,9 +33,14 @@ namespace osu.Game.Overlays
{
}
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
[BackgroundDependencyLoader]
private void load()
private void load(IAPIProvider api)
{
apiState.BindTo(api.State);
apiState.BindValueChanged(onlineStateChanged, true);
Children = new Drawable[]
{
new Box
@ -130,13 +135,13 @@ namespace osu.Game.Overlays
}
}
public override void APIStateChanged(IAPIProvider api, APIState state)
private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
{
if (State.Value == Visibility.Hidden)
return;
Header.Current.TriggerChange();
}
});
protected override void Dispose(bool isDisposing)
{

View File

@ -12,7 +12,7 @@ using osuTK.Graphics;
namespace osu.Game.Overlays
{
public abstract class FullscreenOverlay<T> : WaveOverlayContainer, IOnlineComponent, INamedOverlayComponent
public abstract class FullscreenOverlay<T> : WaveOverlayContainer, INamedOverlayComponent
where T : OverlayHeader
{
public virtual string IconTexture => Header?.Title.IconTexture ?? string.Empty;
@ -86,21 +86,5 @@ namespace osu.Game.Overlays
protected virtual void PopOutComplete()
{
}
protected override void LoadComplete()
{
base.LoadComplete();
API.Register(this);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
API?.Unregister(this);
}
public virtual void APIStateChanged(IAPIProvider api, APIState state)
{
}
}
}

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Online.API;
@ -15,7 +16,7 @@ namespace osu.Game.Overlays
/// Automatically performs a data fetch on load.
/// </remarks>
/// <typeparam name="T">The type of the API response.</typeparam>
public abstract class OverlayView<T> : CompositeDrawable, IOnlineComponent
public abstract class OverlayView<T> : CompositeDrawable
where T : class
{
[Resolved]
@ -29,10 +30,13 @@ namespace osu.Game.Overlays
AutoSizeAxes = Axes.Y;
}
protected override void LoadComplete()
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
[BackgroundDependencyLoader]
private void load()
{
base.LoadComplete();
API.Register(this);
apiState.BindTo(API.State);
apiState.BindValueChanged(onlineStateChanged, true);
}
/// <summary>
@ -59,20 +63,19 @@ namespace osu.Game.Overlays
API.Queue(request);
}
public virtual void APIStateChanged(IAPIProvider api, APIState state)
private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
{
switch (state)
switch (state.NewValue)
{
case APIState.Online:
PerformFetch();
break;
}
}
});
protected override void Dispose(bool isDisposing)
{
request?.Cancel();
API?.Unregister(this);
base.Dispose(isDisposing);
}
}

View File

@ -13,6 +13,7 @@ using osu.Game.Online.API;
using osuTK;
using osu.Game.Users;
using System.ComponentModel;
using osu.Framework.Bindables;
using osu.Game.Graphics;
using osuTK.Graphics;
using osu.Framework.Extensions.Color4Extensions;
@ -25,7 +26,7 @@ using Container = osu.Framework.Graphics.Containers.Container;
namespace osu.Game.Overlays.Settings.Sections.General
{
public class LoginSettings : FillFlowContainer, IOnlineComponent
public class LoginSettings : FillFlowContainer
{
private bool bounding = true;
private LoginForm form;
@ -41,6 +42,11 @@ namespace osu.Game.Overlays.Settings.Sections.General
/// </summary>
public Action RequestHide;
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
[Resolved]
private IAPIProvider api { get; set; }
public override RectangleF BoundingBox => bounding ? base.BoundingBox : RectangleF.Empty;
public bool Bounding
@ -61,17 +67,18 @@ namespace osu.Game.Overlays.Settings.Sections.General
Spacing = new Vector2(0f, 5f);
}
[BackgroundDependencyLoader(permitNulls: true)]
private void load(IAPIProvider api)
[BackgroundDependencyLoader]
private void load()
{
api?.Register(this);
apiState.BindTo(api.State);
apiState.BindValueChanged(onlineStateChanged, true);
}
public void APIStateChanged(IAPIProvider api, APIState state) => Schedule(() =>
private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
{
form = null;
switch (state)
switch (state.NewValue)
{
case APIState.Offline:
Children = new Drawable[]
@ -107,7 +114,7 @@ namespace osu.Game.Overlays.Settings.Sections.General
Origin = Anchor.TopCentre,
TextAnchor = Anchor.TopCentre,
AutoSizeAxes = Axes.Both,
Text = state == APIState.Failing ? "Connection is failing, will attempt to reconnect... " : "Attempting to connect... ",
Text = state.NewValue == APIState.Failing ? "Connection is failing, will attempt to reconnect... " : "Attempting to connect... ",
Margin = new MarginPadding { Top = 10, Bottom = 10 },
},
};

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Effects;
@ -14,10 +15,15 @@ using osuTK.Graphics;
namespace osu.Game.Overlays.Toolbar
{
public class ToolbarUserButton : ToolbarOverlayToggleButton, IOnlineComponent
public class ToolbarUserButton : ToolbarOverlayToggleButton
{
private readonly UpdateableAvatar avatar;
[Resolved]
private IAPIProvider api { get; set; }
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
public ToolbarUserButton()
{
AutoSizeAxes = Axes.X;
@ -44,16 +50,17 @@ namespace osu.Game.Overlays.Toolbar
}
[BackgroundDependencyLoader(true)]
private void load(IAPIProvider api, LoginOverlay login)
private void load(LoginOverlay login)
{
api.Register(this);
apiState.BindTo(api.State);
apiState.BindValueChanged(onlineStateChanged, true);
StateContainer = login;
}
public void APIStateChanged(IAPIProvider api, APIState state)
private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
{
switch (state)
switch (state.NewValue)
{
default:
Text = @"Guest";
@ -65,6 +72,6 @@ namespace osu.Game.Overlays.Toolbar
avatar.User = api.LocalUser.Value;
break;
}
}
});
}
}

View File

@ -29,7 +29,7 @@ using osuTK;
namespace osu.Game.Screens.Multi
{
[Cached]
public class Multiplayer : OsuScreen, IOnlineComponent
public class Multiplayer : OsuScreen
{
public override bool CursorVisible => (screenStack.CurrentScreen as IMultiplayerSubScreen)?.CursorVisible ?? true;
@ -146,15 +146,24 @@ namespace osu.Game.Screens.Multi
screenStack.ScreenExited += screenExited;
}
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
[BackgroundDependencyLoader(true)]
private void load(IdleTracker idleTracker)
{
api.Register(this);
apiState.BindTo(api.State);
apiState.BindValueChanged(onlineStateChanged, true);
if (idleTracker != null)
isIdle.BindTo(idleTracker.IsIdle);
}
private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
{
if (state.NewValue != APIState.Online)
Schedule(forcefullyExit);
});
protected override void LoadComplete()
{
base.LoadComplete();
@ -199,12 +208,6 @@ namespace osu.Game.Screens.Multi
Logger.Log($"Polling adjusted (listing: {roomManager.TimeBetweenListingPolls}, selection: {roomManager.TimeBetweenSelectionPolls})");
}
public void APIStateChanged(IAPIProvider api, APIState state)
{
if (state != APIState.Online)
Schedule(forcefullyExit);
}
private void forcefullyExit()
{
// This is temporary since we don't currently have a way to force screens to be exited
@ -371,12 +374,6 @@ namespace osu.Game.Screens.Multi
}
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
api?.Unregister(this);
}
private class MultiplayerWaveContainer : WaveContainer
{
protected override bool StartHidden => true;

View File

@ -7,6 +7,7 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
@ -51,7 +52,7 @@ namespace osu.Game.Screens.Ranking.Expanded
}
[BackgroundDependencyLoader]
private void load()
private void load(BeatmapDifficultyManager beatmapDifficultyManager)
{
var beatmap = score.Beatmap;
var metadata = beatmap.BeatmapSet?.Metadata ?? beatmap.Metadata;
@ -138,7 +139,7 @@ namespace osu.Game.Screens.Ranking.Expanded
Spacing = new Vector2(5, 0),
Children = new Drawable[]
{
new StarRatingDisplay(beatmap)
new StarRatingDisplay(beatmapDifficultyManager.GetDifficulty(beatmap, score.Ruleset, score.Mods))
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft

View File

@ -22,29 +22,30 @@ namespace osu.Game.Screens.Ranking.Expanded
/// </summary>
public class StarRatingDisplay : CompositeDrawable
{
private readonly BeatmapInfo beatmap;
private readonly StarDifficulty difficulty;
/// <summary>
/// Creates a new <see cref="StarRatingDisplay"/>.
/// Creates a new <see cref="StarRatingDisplay"/> using an already computed <see cref="StarDifficulty"/>.
/// </summary>
/// <param name="beatmap">The <see cref="BeatmapInfo"/> to display the star difficulty of.</param>
public StarRatingDisplay(BeatmapInfo beatmap)
/// <param name="starDifficulty">The already computed <see cref="StarDifficulty"/> to display the star difficulty of.</param>
public StarRatingDisplay(StarDifficulty starDifficulty)
{
this.beatmap = beatmap;
AutoSizeAxes = Axes.Both;
difficulty = starDifficulty;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
private void load(OsuColour colours, BeatmapDifficultyManager difficultyManager)
{
var starRatingParts = beatmap.StarDifficulty.ToString("0.00", CultureInfo.InvariantCulture).Split('.');
AutoSizeAxes = Axes.Both;
var starRatingParts = difficulty.Stars.ToString("0.00", CultureInfo.InvariantCulture).Split('.');
string wholePart = starRatingParts[0];
string fractionPart = starRatingParts[1];
string separator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
ColourInfo backgroundColour = beatmap.DifficultyRating == DifficultyRating.ExpertPlus
ColourInfo backgroundColour = difficulty.DifficultyRating == DifficultyRating.ExpertPlus
? ColourInfo.GradientVertical(Color4Extensions.FromHex("#C1C1C1"), Color4Extensions.FromHex("#595959"))
: (ColourInfo)colours.ForDifficultyRating(beatmap.DifficultyRating);
: (ColourInfo)colours.ForDifficultyRating(difficulty.DifficultyRating);
InternalChildren = new Drawable[]
{

View File

@ -39,6 +39,11 @@ namespace osu.Game.Screens.Select
private readonly IBindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
[Resolved]
private BeatmapDifficultyManager difficultyManager { get; set; }
private IBindable<StarDifficulty> beatmapDifficulty;
protected BufferedWedgeInfo Info;
public BeatmapInfoWedge()
@ -88,6 +93,11 @@ namespace osu.Game.Screens.Select
if (beatmap == value) return;
beatmap = value;
beatmapDifficulty?.UnbindAll();
beatmapDifficulty = difficultyManager.GetBindableDifficulty(beatmap.BeatmapInfo);
beatmapDifficulty.BindValueChanged(_ => updateDisplay());
updateDisplay();
}
}
@ -113,7 +123,7 @@ namespace osu.Game.Screens.Select
return;
}
LoadComponentAsync(loadingInfo = new BufferedWedgeInfo(beatmap, ruleset.Value)
LoadComponentAsync(loadingInfo = new BufferedWedgeInfo(beatmap, ruleset.Value, beatmapDifficulty.Value)
{
Shear = -Shear,
Depth = Info?.Depth + 1 ?? 0
@ -141,12 +151,14 @@ namespace osu.Game.Screens.Select
private readonly WorkingBeatmap beatmap;
private readonly RulesetInfo ruleset;
private readonly StarDifficulty starDifficulty;
public BufferedWedgeInfo(WorkingBeatmap beatmap, RulesetInfo userRuleset)
public BufferedWedgeInfo(WorkingBeatmap beatmap, RulesetInfo userRuleset, StarDifficulty difficulty)
: base(pixelSnapping: true)
{
this.beatmap = beatmap;
ruleset = userRuleset ?? beatmap.BeatmapInfo.Ruleset;
starDifficulty = difficulty;
}
[BackgroundDependencyLoader]
@ -190,7 +202,7 @@ namespace osu.Game.Screens.Select
},
},
},
new DifficultyColourBar(beatmapInfo)
new DifficultyColourBar(starDifficulty)
{
RelativeSizeAxes = Axes.Y,
Width = 20,
@ -226,7 +238,7 @@ namespace osu.Game.Screens.Select
Shear = wedged_container_shear,
Children = new[]
{
createStarRatingDisplay(beatmapInfo).With(display =>
createStarRatingDisplay(starDifficulty).With(display =>
{
display.Anchor = Anchor.TopRight;
display.Origin = Anchor.TopRight;
@ -293,8 +305,8 @@ namespace osu.Game.Screens.Select
StatusPill.Hide();
}
private static Drawable createStarRatingDisplay(BeatmapInfo beatmapInfo) => beatmapInfo.StarDifficulty > 0
? new StarRatingDisplay(beatmapInfo)
private static Drawable createStarRatingDisplay(StarDifficulty difficulty) => difficulty.Stars > 0
? new StarRatingDisplay(difficulty)
{
Margin = new MarginPadding { Bottom = 5 }
}
@ -447,11 +459,11 @@ namespace osu.Game.Screens.Select
private class DifficultyColourBar : Container
{
private readonly BeatmapInfo beatmap;
private readonly StarDifficulty difficulty;
public DifficultyColourBar(BeatmapInfo beatmap)
public DifficultyColourBar(StarDifficulty difficulty)
{
this.beatmap = beatmap;
this.difficulty = difficulty;
}
[BackgroundDependencyLoader]
@ -459,7 +471,7 @@ namespace osu.Game.Screens.Select
{
const float full_opacity_ratio = 0.7f;
var difficultyColour = colours.ForDifficultyRating(beatmap.DifficultyRating);
var difficultyColour = colours.ForDifficultyRating(difficulty.DifficultyRating);
Children = new Drawable[]
{

View File

@ -140,7 +140,7 @@ namespace osu.Game.Screens.Select.Carousel
LoadComponentAsync(beatmapContainer, loaded =>
{
// make sure the pooled target hasn't changed.
if (carouselBeatmapSet != Item)
if (beatmapContainer != loaded)
return;
Content.Child = loaded;

View File

@ -15,7 +15,7 @@ using osu.Game.Rulesets;
namespace osu.Game.Screens.Select
{
public class DifficultyRecommender : Component, IOnlineComponent
public class DifficultyRecommender : Component
{
[Resolved]
private IAPIProvider api { get; set; }
@ -28,10 +28,13 @@ namespace osu.Game.Screens.Select
private readonly Dictionary<RulesetInfo, double> recommendedStarDifficulty = new Dictionary<RulesetInfo, double>();
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
[BackgroundDependencyLoader]
private void load()
{
api.Register(this);
apiState.BindTo(api.State);
apiState.BindValueChanged(onlineStateChanged, true);
}
/// <summary>
@ -72,21 +75,14 @@ namespace osu.Game.Screens.Select
});
}
public void APIStateChanged(IAPIProvider api, APIState state)
private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
{
switch (state)
switch (state.NewValue)
{
case APIState.Online:
calculateRecommendedDifficulties();
break;
}
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
api?.Unregister(this);
}
});
}
}

View File

@ -15,6 +15,7 @@ namespace osu.Game.Storyboards.Drawables
{
public class DrawableStoryboard : Container<DrawableStoryboardLayer>
{
[Cached]
public Storyboard Storyboard { get; }
protected override Container<DrawableStoryboardLayer> Content { get; }

View File

@ -2,18 +2,16 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using osuTK;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Animations;
using osu.Framework.Graphics.Textures;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osuTK;
namespace osu.Game.Storyboards.Drawables
{
public class DrawableStoryboardAnimation : TextureAnimation, IFlippable, IVectorScalable
public class DrawableStoryboardAnimation : DrawableAnimation, IFlippable, IVectorScalable
{
public StoryboardAnimation Animation { get; }
@ -115,18 +113,13 @@ namespace osu.Game.Storyboards.Drawables
}
[BackgroundDependencyLoader]
private void load(IBindable<WorkingBeatmap> beatmap, TextureStore textureStore)
private void load(TextureStore textureStore, Storyboard storyboard)
{
for (var frame = 0; frame < Animation.FrameCount; frame++)
for (int frame = 0; frame < Animation.FrameCount; frame++)
{
var framePath = Animation.Path.Replace(".", frame + ".");
string framePath = Animation.Path.Replace(".", frame + ".");
var path = beatmap.Value.BeatmapSetInfo.Files.Find(f => f.Filename.Equals(framePath, StringComparison.OrdinalIgnoreCase))?.FileInfo.StoragePath;
if (path == null)
continue;
var texture = textureStore.Get(path);
AddFrame(texture, Animation.FrameDelay);
AddFrame(storyboard.CreateSpriteFromResourcePath(framePath, textureStore), Animation.FrameDelay);
}
Animation.ApplyTransforms(this);

View File

@ -2,18 +2,16 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using osuTK;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Textures;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osuTK;
namespace osu.Game.Storyboards.Drawables
{
public class DrawableStoryboardSprite : Sprite, IFlippable, IVectorScalable
public class DrawableStoryboardSprite : CompositeDrawable, IFlippable, IVectorScalable
{
public StoryboardSprite Sprite { get; }
@ -111,16 +109,18 @@ namespace osu.Game.Storyboards.Drawables
LifetimeStart = sprite.StartTime;
LifetimeEnd = sprite.EndTime;
AutoSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load(IBindable<WorkingBeatmap> beatmap, TextureStore textureStore)
private void load(TextureStore textureStore, Storyboard storyboard)
{
var path = beatmap.Value.BeatmapSetInfo?.Files?.Find(f => f.Filename.Equals(Sprite.Path, StringComparison.OrdinalIgnoreCase))?.FileInfo.StoragePath;
if (path == null)
return;
var drawable = storyboard.CreateSpriteFromResourcePath(Sprite.Path, textureStore);
if (drawable != null)
InternalChild = drawable;
Texture = textureStore.Get(path);
Sprite.ApplyTransforms(this);
}
}

View File

@ -1,9 +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 osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Game.Beatmaps;
using osu.Game.Skinning;
using osu.Game.Storyboards.Drawables;
namespace osu.Game.Storyboards
@ -15,6 +20,11 @@ namespace osu.Game.Storyboards
public BeatmapInfo BeatmapInfo = new BeatmapInfo();
/// <summary>
/// Whether the storyboard can fall back to skin sprites in case no matching storyboard sprites are found.
/// </summary>
public bool UseSkinSprites { get; set; }
public bool HasDrawable => Layers.Any(l => l.Elements.Any(e => e.IsDrawable));
public double FirstEventTime => Layers.Min(l => l.Elements.FirstOrDefault()?.StartTime ?? 0);
@ -64,5 +74,19 @@ namespace osu.Game.Storyboards
drawable.Width = drawable.Height * (BeatmapInfo.WidescreenStoryboard ? 16 / 9f : 4 / 3f);
return drawable;
}
public Drawable CreateSpriteFromResourcePath(string path, TextureStore textureStore)
{
Drawable drawable = null;
var storyboardPath = BeatmapInfo.BeatmapSet?.Files?.Find(f => f.Filename.Equals(path, StringComparison.OrdinalIgnoreCase))?.FileInfo.StoragePath;
if (storyboardPath != null)
drawable = new Sprite { Texture = textureStore.Get(storyboardPath) };
// if the texture isn't available locally in the beatmap, some storyboards choose to source from the underlying skin lookup hierarchy.
else if (UseSkinSprites)
drawable = new SkinnableSprite(path);
return drawable;
}
}
}