mirror of
https://github.com/ppy/osu.git
synced 2025-03-04 05:22:54 +08:00
Expose as IBindable from IAPIProvider, writes via config
This commit is contained in:
parent
7ca3a6fc26
commit
b54d959263
@ -29,9 +29,7 @@ namespace osu.Game.Tests.Visual.Menus
|
|||||||
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
|
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
|
||||||
|
|
||||||
private LoginOverlay loginOverlay = null!;
|
private LoginOverlay loginOverlay = null!;
|
||||||
|
private OsuConfigManager localConfig = null!;
|
||||||
[Resolved]
|
|
||||||
private OsuConfigManager configManager { get; set; } = null!;
|
|
||||||
|
|
||||||
[Cached(typeof(LocalUserStatisticsProvider))]
|
[Cached(typeof(LocalUserStatisticsProvider))]
|
||||||
private readonly TestSceneUserPanel.TestUserStatisticsProvider statisticsProvider = new TestSceneUserPanel.TestUserStatisticsProvider();
|
private readonly TestSceneUserPanel.TestUserStatisticsProvider statisticsProvider = new TestSceneUserPanel.TestUserStatisticsProvider();
|
||||||
@ -39,6 +37,8 @@ namespace osu.Game.Tests.Visual.Menus
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
|
Dependencies.Cache(localConfig = new OsuConfigManager(LocalStorage));
|
||||||
|
|
||||||
Child = loginOverlay = new LoginOverlay
|
Child = loginOverlay = new LoginOverlay
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
@ -49,6 +49,7 @@ namespace osu.Game.Tests.Visual.Menus
|
|||||||
[SetUpSteps]
|
[SetUpSteps]
|
||||||
public void SetUpSteps()
|
public void SetUpSteps()
|
||||||
{
|
{
|
||||||
|
AddStep("reset online state", () => localConfig.SetValue(OsuSetting.UserOnlineStatus, UserStatus.Online));
|
||||||
AddStep("show login overlay", () => loginOverlay.Show());
|
AddStep("show login overlay", () => loginOverlay.Show());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +90,7 @@ namespace osu.Game.Tests.Visual.Menus
|
|||||||
AddStep("clear handler", () => dummyAPI.HandleRequest = null);
|
AddStep("clear handler", () => dummyAPI.HandleRequest = null);
|
||||||
|
|
||||||
assertDropdownState(UserAction.Online);
|
assertDropdownState(UserAction.Online);
|
||||||
AddStep("change user state", () => dummyAPI.Status.Value = UserStatus.DoNotDisturb);
|
AddStep("change user state", () => localConfig.SetValue(OsuSetting.UserOnlineStatus, UserStatus.DoNotDisturb));
|
||||||
assertDropdownState(UserAction.DoNotDisturb);
|
assertDropdownState(UserAction.DoNotDisturb);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,31 +189,31 @@ namespace osu.Game.Tests.Visual.Menus
|
|||||||
public void TestUncheckingRememberUsernameClearsIt()
|
public void TestUncheckingRememberUsernameClearsIt()
|
||||||
{
|
{
|
||||||
AddStep("logout", () => API.Logout());
|
AddStep("logout", () => API.Logout());
|
||||||
AddStep("set username", () => configManager.SetValue(OsuSetting.Username, "test_user"));
|
AddStep("set username", () => localConfig.SetValue(OsuSetting.Username, "test_user"));
|
||||||
AddStep("set remember password", () => configManager.SetValue(OsuSetting.SavePassword, true));
|
AddStep("set remember password", () => localConfig.SetValue(OsuSetting.SavePassword, true));
|
||||||
AddStep("uncheck remember username", () =>
|
AddStep("uncheck remember username", () =>
|
||||||
{
|
{
|
||||||
InputManager.MoveMouseTo(loginOverlay.ChildrenOfType<SettingsCheckbox>().First());
|
InputManager.MoveMouseTo(loginOverlay.ChildrenOfType<SettingsCheckbox>().First());
|
||||||
InputManager.Click(MouseButton.Left);
|
InputManager.Click(MouseButton.Left);
|
||||||
});
|
});
|
||||||
AddAssert("remember username off", () => configManager.Get<bool>(OsuSetting.SaveUsername), () => Is.False);
|
AddAssert("remember username off", () => localConfig.Get<bool>(OsuSetting.SaveUsername), () => Is.False);
|
||||||
AddAssert("remember password off", () => configManager.Get<bool>(OsuSetting.SavePassword), () => Is.False);
|
AddAssert("remember password off", () => localConfig.Get<bool>(OsuSetting.SavePassword), () => Is.False);
|
||||||
AddAssert("username cleared", () => configManager.Get<string>(OsuSetting.Username), () => Is.Empty);
|
AddAssert("username cleared", () => localConfig.Get<string>(OsuSetting.Username), () => Is.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestUncheckingRememberPasswordClearsToken()
|
public void TestUncheckingRememberPasswordClearsToken()
|
||||||
{
|
{
|
||||||
AddStep("logout", () => API.Logout());
|
AddStep("logout", () => API.Logout());
|
||||||
AddStep("set token", () => configManager.SetValue(OsuSetting.Token, "test_token"));
|
AddStep("set token", () => localConfig.SetValue(OsuSetting.Token, "test_token"));
|
||||||
AddStep("set remember password", () => configManager.SetValue(OsuSetting.SavePassword, true));
|
AddStep("set remember password", () => localConfig.SetValue(OsuSetting.SavePassword, true));
|
||||||
AddStep("uncheck remember token", () =>
|
AddStep("uncheck remember token", () =>
|
||||||
{
|
{
|
||||||
InputManager.MoveMouseTo(loginOverlay.ChildrenOfType<SettingsCheckbox>().Last());
|
InputManager.MoveMouseTo(loginOverlay.ChildrenOfType<SettingsCheckbox>().Last());
|
||||||
InputManager.Click(MouseButton.Left);
|
InputManager.Click(MouseButton.Left);
|
||||||
});
|
});
|
||||||
AddAssert("remember password off", () => configManager.Get<bool>(OsuSetting.SavePassword), () => Is.False);
|
AddAssert("remember password off", () => localConfig.Get<bool>(OsuSetting.SavePassword), () => Is.False);
|
||||||
AddAssert("token cleared", () => configManager.Get<string>(OsuSetting.Token), () => Is.Empty);
|
AddAssert("token cleared", () => localConfig.Get<string>(OsuSetting.Token), () => Is.Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -443,7 +443,12 @@ namespace osu.Game.Configuration
|
|||||||
EditorShowSpeedChanges,
|
EditorShowSpeedChanges,
|
||||||
TouchDisableGameplayTaps,
|
TouchDisableGameplayTaps,
|
||||||
ModSelectTextSearchStartsActive,
|
ModSelectTextSearchStartsActive,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The status for the current user to broadcast to other players.
|
||||||
|
/// </summary>
|
||||||
UserOnlineStatus,
|
UserOnlineStatus,
|
||||||
|
|
||||||
MultiplayerRoomFilter,
|
MultiplayerRoomFilter,
|
||||||
HideCountryFlags,
|
HideCountryFlags,
|
||||||
EditorTimelineShowTimingChanges,
|
EditorTimelineShowTimingChanges,
|
||||||
|
@ -60,7 +60,7 @@ namespace osu.Game.Online.API
|
|||||||
|
|
||||||
public IBindable<APIUser> LocalUser => localUser;
|
public IBindable<APIUser> LocalUser => localUser;
|
||||||
public IBindableList<APIRelation> Friends => friends;
|
public IBindableList<APIRelation> Friends => friends;
|
||||||
public Bindable<UserStatus> Status { get; } = new Bindable<UserStatus>(UserStatus.Online);
|
public IBindable<UserStatus> Status => configStatus;
|
||||||
public IBindable<UserActivity> Activity => activity;
|
public IBindable<UserActivity> Activity => activity;
|
||||||
|
|
||||||
public INotificationsClient NotificationsClient { get; }
|
public INotificationsClient NotificationsClient { get; }
|
||||||
@ -75,8 +75,8 @@ namespace osu.Game.Online.API
|
|||||||
|
|
||||||
protected bool HasLogin => authentication.Token.Value != null || (!string.IsNullOrEmpty(ProvidedUsername) && !string.IsNullOrEmpty(password));
|
protected bool HasLogin => authentication.Token.Value != null || (!string.IsNullOrEmpty(ProvidedUsername) && !string.IsNullOrEmpty(password));
|
||||||
|
|
||||||
|
private readonly Bindable<UserStatus> configStatus = new Bindable<UserStatus>();
|
||||||
private readonly CancellationTokenSource cancellationToken = new CancellationTokenSource();
|
private readonly CancellationTokenSource cancellationToken = new CancellationTokenSource();
|
||||||
|
|
||||||
private readonly Logger log;
|
private readonly Logger log;
|
||||||
|
|
||||||
public APIAccess(OsuGameBase game, OsuConfigManager config, EndpointConfiguration endpointConfiguration, string versionHash)
|
public APIAccess(OsuGameBase game, OsuConfigManager config, EndpointConfiguration endpointConfiguration, string versionHash)
|
||||||
@ -108,7 +108,7 @@ namespace osu.Game.Online.API
|
|||||||
authentication.TokenString = config.Get<string>(OsuSetting.Token);
|
authentication.TokenString = config.Get<string>(OsuSetting.Token);
|
||||||
authentication.Token.ValueChanged += onTokenChanged;
|
authentication.Token.ValueChanged += onTokenChanged;
|
||||||
|
|
||||||
config.BindWith(OsuSetting.UserOnlineStatus, Status);
|
config.BindWith(OsuSetting.UserOnlineStatus, configStatus);
|
||||||
|
|
||||||
if (HasLogin)
|
if (HasLogin)
|
||||||
{
|
{
|
||||||
@ -591,7 +591,9 @@ namespace osu.Game.Online.API
|
|||||||
password = null;
|
password = null;
|
||||||
SecondFactorCode = null;
|
SecondFactorCode = null;
|
||||||
authentication.Clear();
|
authentication.Clear();
|
||||||
Status.Value = UserStatus.Online;
|
|
||||||
|
// Reset the status to be broadcast on the next login, in case multiple players share the same system.
|
||||||
|
configStatus.Value = UserStatus.Online;
|
||||||
|
|
||||||
// Scheduled prior to state change such that the state changed event is invoked with the correct user and their friends present
|
// Scheduled prior to state change such that the state changed event is invoked with the correct user and their friends present
|
||||||
Schedule(() =>
|
Schedule(() =>
|
||||||
|
@ -28,7 +28,7 @@ namespace osu.Game.Online.API
|
|||||||
|
|
||||||
public BindableList<APIRelation> Friends { get; } = new BindableList<APIRelation>();
|
public BindableList<APIRelation> Friends { get; } = new BindableList<APIRelation>();
|
||||||
|
|
||||||
public Bindable<UserStatus> Status { get; } = new Bindable<UserStatus>(UserStatus.Online);
|
public IBindable<UserStatus> Status { get; } = new Bindable<UserStatus>(UserStatus.Online);
|
||||||
|
|
||||||
public Bindable<UserActivity?> Activity { get; } = new Bindable<UserActivity?>();
|
public Bindable<UserActivity?> Activity { get; } = new Bindable<UserActivity?>();
|
||||||
|
|
||||||
|
@ -25,12 +25,12 @@ namespace osu.Game.Online.API
|
|||||||
IBindableList<APIRelation> Friends { get; }
|
IBindableList<APIRelation> Friends { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The current user's status.
|
/// The status for the current user that's broadcast to other players.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Bindable<UserStatus> Status { get; }
|
IBindable<UserStatus> Status { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The current user's activity.
|
/// The activity for the current user that's broadcast to other players.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
IBindable<UserActivity?> Activity { get; }
|
IBindable<UserActivity?> Activity { get; }
|
||||||
|
|
||||||
|
@ -37,7 +37,6 @@ namespace osu.Game.Online.Metadata
|
|||||||
private IHubClientConnector? connector;
|
private IHubClientConnector? connector;
|
||||||
private Bindable<int> lastQueueId = null!;
|
private Bindable<int> lastQueueId = null!;
|
||||||
private IBindable<APIUser> localUser = null!;
|
private IBindable<APIUser> localUser = null!;
|
||||||
|
|
||||||
private IBindable<UserStatus> userStatus = null!;
|
private IBindable<UserStatus> userStatus = null!;
|
||||||
private IBindable<UserActivity?> userActivity = null!;
|
private IBindable<UserActivity?> userActivity = null!;
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Primitives;
|
using osu.Framework.Graphics.Primitives;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
@ -37,12 +38,15 @@ namespace osu.Game.Overlays.Login
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Action? RequestHide;
|
public Action? RequestHide;
|
||||||
|
|
||||||
private readonly Bindable<UserStatus> status = new Bindable<UserStatus>();
|
|
||||||
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
|
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
|
||||||
|
private readonly Bindable<UserStatus> configUserStatus = new Bindable<UserStatus>();
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private IAPIProvider api { get; set; } = null!;
|
private IAPIProvider api { get; set; } = null!;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private OsuConfigManager config { get; set; } = null!;
|
||||||
|
|
||||||
public override RectangleF BoundingBox => bounding ? base.BoundingBox : RectangleF.Empty;
|
public override RectangleF BoundingBox => bounding ? base.BoundingBox : RectangleF.Empty;
|
||||||
|
|
||||||
public bool Bounding
|
public bool Bounding
|
||||||
@ -65,11 +69,11 @@ namespace osu.Game.Overlays.Login
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
|
config.BindWith(OsuSetting.UserOnlineStatus, configUserStatus);
|
||||||
|
configUserStatus.BindValueChanged(e => updateDropdownCurrent(e.NewValue), true);
|
||||||
|
|
||||||
apiState.BindTo(api.State);
|
apiState.BindTo(api.State);
|
||||||
apiState.BindValueChanged(onlineStateChanged, true);
|
apiState.BindValueChanged(onlineStateChanged, true);
|
||||||
|
|
||||||
status.BindTo(api.Status);
|
|
||||||
status.BindValueChanged(e => updateDropdownCurrent(e.NewValue), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
|
private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
|
||||||
@ -148,23 +152,23 @@ namespace osu.Game.Overlays.Login
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
updateDropdownCurrent(status.Value);
|
updateDropdownCurrent(configUserStatus.Value);
|
||||||
dropdown.Current.BindValueChanged(action =>
|
dropdown.Current.BindValueChanged(action =>
|
||||||
{
|
{
|
||||||
switch (action.NewValue)
|
switch (action.NewValue)
|
||||||
{
|
{
|
||||||
case UserAction.Online:
|
case UserAction.Online:
|
||||||
status.Value = UserStatus.Online;
|
configUserStatus.Value = UserStatus.Online;
|
||||||
dropdown.StatusColour = colours.Green;
|
dropdown.StatusColour = colours.Green;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case UserAction.DoNotDisturb:
|
case UserAction.DoNotDisturb:
|
||||||
status.Value = UserStatus.DoNotDisturb;
|
configUserStatus.Value = UserStatus.DoNotDisturb;
|
||||||
dropdown.StatusColour = colours.Red;
|
dropdown.StatusColour = colours.Red;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case UserAction.AppearOffline:
|
case UserAction.AppearOffline:
|
||||||
status.Value = UserStatus.Offline;
|
configUserStatus.Value = UserStatus.Offline;
|
||||||
dropdown.StatusColour = colours.Gray7;
|
dropdown.StatusColour = colours.Gray7;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user