mirror of
https://github.com/ppy/osu.git
synced 2025-03-20 05:07:19 +08:00
Make IAPIProvider read-only bindables into IBindables
This commit is contained in:
parent
8a01e567a1
commit
206bf3713e
@ -26,7 +26,7 @@ namespace osu.Desktop
|
||||
[Resolved]
|
||||
private IBindable<RulesetInfo> ruleset { get; set; }
|
||||
|
||||
private Bindable<User> user;
|
||||
private IBindable<User> user;
|
||||
|
||||
private readonly IBindable<UserStatus> status = new Bindable<UserStatus>();
|
||||
private readonly IBindable<UserActivity> activity = new Bindable<UserActivity>();
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Screens.Menu;
|
||||
using osu.Game.Users;
|
||||
|
||||
@ -16,7 +17,7 @@ namespace osu.Game.Tests.Visual.Menus
|
||||
|
||||
AddStep("toggle support", () =>
|
||||
{
|
||||
API.LocalUser.Value = new User
|
||||
((DummyAPIAccess)API).LocalUser.Value = new User
|
||||
{
|
||||
Username = API.LocalUser.Value.Username,
|
||||
Id = API.LocalUser.Value.Id + 1,
|
||||
|
@ -14,7 +14,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
{
|
||||
private readonly Container userPanelArea;
|
||||
|
||||
private Bindable<User> localUser;
|
||||
private IBindable<User> localUser;
|
||||
|
||||
public TestSceneAccountCreationOverlay()
|
||||
{
|
||||
|
@ -6,6 +6,7 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Chat;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Users;
|
||||
@ -18,6 +19,8 @@ namespace osu.Game.Tests.Visual.Online
|
||||
[Cached(typeof(IChannelPostTarget))]
|
||||
private PostTarget postTarget { get; set; }
|
||||
|
||||
private DummyAPIAccess api => (DummyAPIAccess)API;
|
||||
|
||||
public TestSceneNowPlayingCommand()
|
||||
{
|
||||
Add(postTarget = new PostTarget());
|
||||
@ -26,7 +29,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
[Test]
|
||||
public void TestGenericActivity()
|
||||
{
|
||||
AddStep("Set activity", () => API.Activity.Value = new UserActivity.InLobby(null));
|
||||
AddStep("Set activity", () => api.Activity.Value = new UserActivity.InLobby(null));
|
||||
|
||||
AddStep("Run command", () => Add(new NowPlayingCommand()));
|
||||
|
||||
@ -36,7 +39,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
[Test]
|
||||
public void TestEditActivity()
|
||||
{
|
||||
AddStep("Set activity", () => API.Activity.Value = new UserActivity.Editing(new BeatmapInfo()));
|
||||
AddStep("Set activity", () => api.Activity.Value = new UserActivity.Editing(new BeatmapInfo()));
|
||||
|
||||
AddStep("Run command", () => Add(new NowPlayingCommand()));
|
||||
|
||||
@ -46,7 +49,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
[Test]
|
||||
public void TestPlayActivity()
|
||||
{
|
||||
AddStep("Set activity", () => API.Activity.Value = new UserActivity.SoloGame(new BeatmapInfo(), new RulesetInfo()));
|
||||
AddStep("Set activity", () => api.Activity.Value = new UserActivity.SoloGame(new BeatmapInfo(), new RulesetInfo()));
|
||||
|
||||
AddStep("Run command", () => Add(new NowPlayingCommand()));
|
||||
|
||||
@ -57,7 +60,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
[TestCase(false)]
|
||||
public void TestLinkPresence(bool hasOnlineId)
|
||||
{
|
||||
AddStep("Set activity", () => API.Activity.Value = new UserActivity.InLobby(null));
|
||||
AddStep("Set activity", () => api.Activity.Value = new UserActivity.InLobby(null));
|
||||
|
||||
AddStep("Set beatmap", () => Beatmap.Value = new DummyWorkingBeatmap(Audio, null)
|
||||
{
|
||||
|
@ -39,11 +39,15 @@ namespace osu.Game.Online.API
|
||||
|
||||
private string password;
|
||||
|
||||
public Bindable<User> LocalUser { get; } = new Bindable<User>(createGuestUser());
|
||||
public IBindable<User> LocalUser => localUser;
|
||||
public IBindableList<User> Friends => friends;
|
||||
public IBindable<UserActivity> Activity => activity;
|
||||
|
||||
public BindableList<User> Friends { get; } = new BindableList<User>();
|
||||
private Bindable<User> localUser { get; } = new Bindable<User>(createGuestUser());
|
||||
|
||||
public Bindable<UserActivity> Activity { get; } = new Bindable<UserActivity>();
|
||||
private BindableList<User> friends { get; } = new BindableList<User>();
|
||||
|
||||
private Bindable<UserActivity> activity { get; } = new Bindable<UserActivity>();
|
||||
|
||||
protected bool HasLogin => authentication.Token.Value != null || (!string.IsNullOrEmpty(ProvidedUsername) && !string.IsNullOrEmpty(password));
|
||||
|
||||
@ -63,10 +67,10 @@ namespace osu.Game.Online.API
|
||||
authentication.TokenString = config.Get<string>(OsuSetting.Token);
|
||||
authentication.Token.ValueChanged += onTokenChanged;
|
||||
|
||||
LocalUser.BindValueChanged(u =>
|
||||
localUser.BindValueChanged(u =>
|
||||
{
|
||||
u.OldValue?.Activity.UnbindFrom(Activity);
|
||||
u.NewValue.Activity.BindTo(Activity);
|
||||
u.OldValue?.Activity.UnbindFrom(activity);
|
||||
u.NewValue.Activity.BindTo(activity);
|
||||
}, true);
|
||||
|
||||
var thread = new Thread(run)
|
||||
@ -138,10 +142,10 @@ namespace osu.Game.Online.API
|
||||
var userReq = new GetUserRequest();
|
||||
userReq.Success += u =>
|
||||
{
|
||||
LocalUser.Value = u;
|
||||
localUser.Value = u;
|
||||
|
||||
// todo: save/pull from settings
|
||||
LocalUser.Value.Status.Value = new UserStatusOnline();
|
||||
localUser.Value.Status.Value = new UserStatusOnline();
|
||||
|
||||
failureCount = 0;
|
||||
|
||||
@ -343,7 +347,7 @@ namespace osu.Game.Online.API
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool IsLoggedIn => LocalUser.Value.Id > 1;
|
||||
public bool IsLoggedIn => localUser.Value.Id > 1;
|
||||
|
||||
public void Queue(APIRequest request)
|
||||
{
|
||||
@ -376,8 +380,8 @@ namespace osu.Game.Online.API
|
||||
// Scheduled prior to state change such that the state changed event is invoked with the correct user and their friends present
|
||||
Schedule(() =>
|
||||
{
|
||||
LocalUser.Value = createGuestUser();
|
||||
Friends.Clear();
|
||||
localUser.Value = createGuestUser();
|
||||
friends.Clear();
|
||||
});
|
||||
|
||||
state.Value = APIState.Offline;
|
||||
|
@ -93,5 +93,9 @@ namespace osu.Game.Online.API
|
||||
}
|
||||
|
||||
public void SetState(APIState newState) => state.Value = newState;
|
||||
|
||||
IBindable<User> IAPIProvider.LocalUser => LocalUser;
|
||||
IBindableList<User> IAPIProvider.Friends => Friends;
|
||||
IBindable<UserActivity> IAPIProvider.Activity => Activity;
|
||||
}
|
||||
}
|
||||
|
@ -13,19 +13,19 @@ namespace osu.Game.Online.API
|
||||
/// The local user.
|
||||
/// This is not thread-safe and should be scheduled locally if consumed from a drawable component.
|
||||
/// </summary>
|
||||
Bindable<User> LocalUser { get; }
|
||||
IBindable<User> LocalUser { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The user's friends.
|
||||
/// This is not thread-safe and should be scheduled locally if consumed from a drawable component.
|
||||
/// </summary>
|
||||
BindableList<User> Friends { get; }
|
||||
IBindableList<User> Friends { 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; }
|
||||
IBindable<UserActivity> Activity { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve the OAuth access token.
|
||||
|
@ -51,7 +51,6 @@ using osu.Game.Screens.Select;
|
||||
using osu.Game.Updater;
|
||||
using osu.Game.Utils;
|
||||
using LogLevel = osu.Framework.Logging.LogLevel;
|
||||
using osu.Game.Users;
|
||||
using System.IO;
|
||||
|
||||
namespace osu.Game
|
||||
@ -976,7 +975,7 @@ namespace osu.Game
|
||||
if (newScreen is IOsuScreen newOsuScreen)
|
||||
{
|
||||
OverlayActivationMode.BindTo(newOsuScreen.OverlayActivationMode);
|
||||
((IBindable<UserActivity>)API.Activity).BindTo(newOsuScreen.Activity);
|
||||
API.Activity.BindTo(newOsuScreen.Activity);
|
||||
|
||||
MusicController.AllowRateAdjustments = newOsuScreen.AllowRateAdjustments;
|
||||
|
||||
|
@ -26,7 +26,7 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
|
||||
private PostBeatmapFavouriteRequest request;
|
||||
private LoadingLayer loading;
|
||||
|
||||
private readonly Bindable<User> localUser = new Bindable<User>();
|
||||
private readonly IBindable<User> localUser = new Bindable<User>();
|
||||
|
||||
public string TooltipText
|
||||
{
|
||||
|
@ -26,7 +26,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
|
||||
public readonly Bindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
|
||||
private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
|
||||
private readonly Bindable<BeatmapLeaderboardScope> scope = new Bindable<BeatmapLeaderboardScope>(BeatmapLeaderboardScope.Global);
|
||||
private readonly Bindable<User> user = new Bindable<User>();
|
||||
private readonly IBindable<User> user = new Bindable<User>();
|
||||
|
||||
private readonly Box background;
|
||||
private readonly ScoreTable scoreTable;
|
||||
|
@ -25,7 +25,7 @@ namespace osu.Game.Overlays.Comments
|
||||
public readonly Bindable<CommentsSortCriteria> Sort = new Bindable<CommentsSortCriteria>();
|
||||
public readonly BindableBool ShowDeleted = new BindableBool();
|
||||
|
||||
protected readonly Bindable<User> User = new Bindable<User>();
|
||||
protected readonly IBindable<User> User = new Bindable<User>();
|
||||
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; }
|
||||
|
@ -22,7 +22,7 @@ namespace osu.Game.Screens.Backgrounds
|
||||
|
||||
private int currentDisplay;
|
||||
private const int background_count = 7;
|
||||
private Bindable<User> user;
|
||||
private IBindable<User> user;
|
||||
private Bindable<Skin> skin;
|
||||
private Bindable<BackgroundSource> mode;
|
||||
private Bindable<IntroSequence> introSequence;
|
||||
|
@ -147,7 +147,7 @@ namespace osu.Game.Screens.Menu
|
||||
if (nextScreen != null)
|
||||
LoadComponentAsync(nextScreen);
|
||||
|
||||
currentUser.BindTo(api.LocalUser);
|
||||
((IBindable<User>)currentUser).BindTo(api.LocalUser);
|
||||
}
|
||||
|
||||
public override void OnEntering(IScreen last)
|
||||
|
@ -12,7 +12,7 @@ namespace osu.Game.Screens.Menu
|
||||
{
|
||||
internal class MenuLogoVisualisation : LogoVisualisation
|
||||
{
|
||||
private Bindable<User> user;
|
||||
private IBindable<User> user;
|
||||
private Bindable<Skin> skin;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
|
@ -35,7 +35,7 @@ namespace osu.Game.Screens.Menu
|
||||
private const double box_fade_in_time = 65;
|
||||
private const int box_width = 200;
|
||||
|
||||
private Bindable<User> user;
|
||||
private IBindable<User> user;
|
||||
private Bindable<Skin> skin;
|
||||
|
||||
[Resolved]
|
||||
|
Loading…
x
Reference in New Issue
Block a user