1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 17:43:05 +08:00

Merge branch 'master' into fix-social-overlay-performance

This commit is contained in:
Dan Balasescu 2019-06-12 20:37:15 +09:00 committed by GitHub
commit 169c18d238
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 199 additions and 43 deletions

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using NUnit.Framework;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Users;
@ -12,10 +13,12 @@ namespace osu.Game.Tests.Visual.Online
[TestFixture]
public class TestSceneUserPanel : OsuTestScene
{
private readonly UserPanel peppy;
public TestSceneUserPanel()
{
UserPanel flyte;
UserPanel peppy;
Add(new FillFlowContainer
{
Anchor = Anchor.Centre,
@ -44,13 +47,31 @@ namespace osu.Game.Tests.Visual.Online
});
flyte.Status.Value = new UserStatusOnline();
peppy.Status.Value = new UserStatusSoloGame();
peppy.Status.Value = null;
}
AddStep(@"spectating", () => { flyte.Status.Value = new UserStatusSpectating(); });
AddStep(@"multiplaying", () => { flyte.Status.Value = new UserStatusMultiplayerGame(); });
AddStep(@"modding", () => { flyte.Status.Value = new UserStatusModding(); });
AddStep(@"offline", () => { flyte.Status.Value = new UserStatusOffline(); });
AddStep(@"null status", () => { flyte.Status.Value = null; });
[Test]
public void UserStatusesTests()
{
AddStep("online", () => { peppy.Status.Value = new UserStatusOnline(); });
AddStep(@"do not disturb", () => { peppy.Status.Value = new UserStatusDoNotDisturb(); });
AddStep(@"offline", () => { peppy.Status.Value = new UserStatusOffline(); });
AddStep(@"null status", () => { peppy.Status.Value = null; });
}
[Test]
public void UserActivitiesTests()
{
Bindable<UserActivity> activity = new Bindable<UserActivity>();
peppy.Activity.BindTo(activity);
AddStep("idle", () => { activity.Value = null; });
AddStep("spectating", () => { activity.Value = new UserActivity.Spectating(); });
AddStep("solo", () => { activity.Value = new UserActivity.SoloGame(null, null); });
AddStep("choosing", () => { activity.Value = new UserActivity.ChoosingBeatmap(); });
AddStep("editing", () => { activity.Value = new UserActivity.Editing(null); });
AddStep("modding", () => { activity.Value = new UserActivity.Modding(); });
}
}
}

View File

@ -37,6 +37,8 @@ namespace osu.Game.Online.API
public Bindable<User> LocalUser { get; } = new Bindable<User>(createGuestUser());
public Bindable<UserActivity> Activity { get; } = new Bindable<UserActivity>();
protected bool HasLogin => authentication.Token.Value != null || (!string.IsNullOrEmpty(ProvidedUsername) && !string.IsNullOrEmpty(password));
private readonly CancellationTokenSource cancellationToken = new CancellationTokenSource();
@ -55,6 +57,12 @@ namespace osu.Game.Online.API
authentication.TokenString = config.Get<string>(OsuSetting.Token);
authentication.Token.ValueChanged += onTokenChanged;
LocalUser.BindValueChanged(u =>
{
u.OldValue?.Activity.UnbindFrom(Activity);
u.NewValue.Activity.BindTo(Activity);
}, true);
var thread = new Thread(run)
{
Name = "APIAccess",

View File

@ -17,6 +17,8 @@ namespace osu.Game.Online.API
Id = 1001,
});
public Bindable<UserActivity> Activity { get; } = new Bindable<UserActivity>();
public bool IsLoggedIn => true;
public string ProvidedUsername => LocalUser.Value.Username;
@ -41,6 +43,15 @@ namespace osu.Game.Online.API
}
}
public DummyAPIAccess()
{
LocalUser.BindValueChanged(u =>
{
u.OldValue?.Activity.UnbindFrom(Activity);
u.NewValue.Activity.BindTo(Activity);
}, true);
}
public virtual void Queue(APIRequest request)
{
}

View File

@ -13,6 +13,11 @@ namespace osu.Game.Online.API
/// </summary>
Bindable<User> LocalUser { get; }
/// <summary>
/// The current user's activity.
/// </summary>
Bindable<UserActivity> Activity { get; }
/// <summary>
/// Returns whether the local user is logged in.
/// </summary>

View File

@ -154,8 +154,9 @@ namespace osu.Game.Overlays.Settings.Sections.General
};
panel.Status.BindTo(api.LocalUser.Value.Status);
panel.Activity.BindTo(api.LocalUser.Value.Activity);
dropdown.Current.ValueChanged += action =>
dropdown.Current.BindValueChanged(action =>
{
switch (action.NewValue)
{
@ -178,9 +179,7 @@ namespace osu.Game.Overlays.Settings.Sections.General
api.Logout();
break;
}
};
dropdown.Current.TriggerChange();
}, true);
break;
}

View File

@ -119,6 +119,7 @@ namespace osu.Game.Overlays
}
panel.Status.BindTo(u.Status);
panel.Activity.BindTo(u.Activity);
return panel;
})
};

View File

@ -24,6 +24,7 @@ using osu.Game.Screens.Edit.Design;
using osuTK.Input;
using System.Collections.Generic;
using osu.Framework;
using osu.Game.Users;
namespace osu.Game.Screens.Edit
{
@ -47,6 +48,8 @@ namespace osu.Game.Screens.Edit
private DependencyContainer dependencies;
private GameHost host;
protected override UserActivity InitialActivity => new UserActivity.Editing(Beatmap.Value.BeatmapInfo);
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
=> dependencies = new DependencyContainer(base.CreateChildDependencies(parent));

View File

@ -15,6 +15,8 @@ using osu.Game.Input.Bindings;
using osu.Game.Rulesets;
using osu.Game.Screens.Menu;
using osu.Game.Overlays;
using osu.Game.Users;
using osu.Game.Online.API;
using osu.Game.Rulesets.Mods;
namespace osu.Game.Screens
@ -52,6 +54,30 @@ namespace osu.Game.Screens
protected new OsuGameBase Game => base.Game as OsuGameBase;
/// <summary>
/// The <see cref="UserActivity"/> to set the user's activity automatically to when this screen is entered
/// <para>This <see cref="Activity"/> will be automatically set to <see cref="InitialActivity"/> for this screen on entering unless
/// <see cref="Activity"/> is manually set before.</para>
/// </summary>
protected virtual UserActivity InitialActivity => null;
private UserActivity activity;
/// <summary>
/// The current <see cref="UserActivity"/> for this screen.
/// </summary>
protected UserActivity Activity
{
get => activity;
set
{
if (value == activity) return;
activity = value;
updateActivity();
}
}
/// <summary>
/// Whether to disallow changes to game-wise Beatmap/Ruleset bindables for this screen (and all children).
/// </summary>
@ -90,6 +116,9 @@ namespace osu.Game.Screens
[Resolved(canBeNull: true)]
private OsuLogo logo { get; set; }
[Resolved(canBeNull: true)]
private IAPIProvider api { get; set; }
protected OsuScreen()
{
Anchor = Anchor.Centre;
@ -123,12 +152,15 @@ namespace osu.Game.Screens
sampleExit?.Play();
applyArrivingDefaults(true);
updateActivity();
base.OnResuming(last);
}
public override void OnSuspending(IScreen next)
{
base.OnSuspending(next);
onSuspendingLogo();
}
@ -138,6 +170,9 @@ namespace osu.Game.Screens
backgroundStack?.Push(localBackground = CreateBackground());
if (activity == null)
Activity = InitialActivity;
base.OnEntering(last);
}
@ -155,6 +190,12 @@ namespace osu.Game.Screens
return false;
}
private void updateActivity()
{
if (api != null)
api.Activity.Value = activity;
}
/// <summary>
/// Fired when this screen was entered or resumed and the logo state is required to be adjusted.
/// </summary>

View File

@ -27,6 +27,7 @@ using osu.Game.Scoring;
using osu.Game.Screens.Ranking;
using osu.Game.Skinning;
using osu.Game.Storyboards.Drawables;
using osu.Game.Users;
namespace osu.Game.Screens.Play
{
@ -34,6 +35,8 @@ namespace osu.Game.Screens.Play
{
protected override bool AllowBackButton => false; // handled by HoldForMenuButton
protected override UserActivity InitialActivity => new UserActivity.SoloGame(Beatmap.Value.BeatmapInfo, Ruleset.Value);
public override float BackgroundParallaxAmount => 0.1f;
public override bool HideOverlaysOnEnter => true;

View File

@ -22,6 +22,7 @@ using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Menu;
using osu.Game.Screens.Play.HUD;
using osu.Game.Screens.Play.PlayerSettings;
using osu.Game.Users;
using osuTK;
using osuTK.Graphics;
@ -42,6 +43,8 @@ namespace osu.Game.Screens.Play
private bool hideOverlays;
public override bool HideOverlaysOnEnter => hideOverlays;
protected override UserActivity InitialActivity => null; //shows the previous screen status
public override bool DisallowExternalBeatmapRulesetChanges => true;
protected override bool PlayResumeSound => false;

View File

@ -7,6 +7,7 @@ using osu.Framework.Graphics.Sprites;
using osu.Framework.Screens;
using osu.Game.Graphics;
using osu.Game.Screens.Play;
using osu.Game.Users;
using osuTK.Input;
namespace osu.Game.Screens.Select
@ -18,6 +19,8 @@ namespace osu.Game.Screens.Select
public override bool AllowExternalScreenChange => true;
protected override UserActivity InitialActivity => new UserActivity.ChoosingBeatmap();
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{

View File

@ -25,6 +25,8 @@ namespace osu.Game.Users
public Bindable<UserStatus> Status = new Bindable<UserStatus>();
public IBindable<UserActivity> Activity = new Bindable<UserActivity>();
//public Team Team;
[JsonProperty(@"profile_colour")]

View File

@ -0,0 +1,68 @@
// 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 osu.Game.Beatmaps;
using osu.Game.Graphics;
using osuTK.Graphics;
namespace osu.Game.Users
{
public abstract class UserActivity
{
public abstract string Status { get; }
public virtual Color4 GetAppropriateColour(OsuColour colours) => colours.GreenDarker;
public class Modding : UserActivity
{
public override string Status => "Modding a map";
public override Color4 GetAppropriateColour(OsuColour colours) => colours.PurpleDark;
}
public class ChoosingBeatmap : UserActivity
{
public override string Status => "Choosing a beatmap";
}
public class MultiplayerGame : UserActivity
{
public override string Status => "Playing with others";
}
public class Editing : UserActivity
{
public BeatmapInfo Beatmap { get; }
public Editing(BeatmapInfo info)
{
Beatmap = info;
}
public override string Status => @"Editing a beatmap";
}
public class SoloGame : UserActivity
{
public BeatmapInfo Beatmap { get; }
public Rulesets.RulesetInfo Ruleset { get; }
public SoloGame(BeatmapInfo info, Rulesets.RulesetInfo ruleset)
{
Beatmap = info;
Ruleset = ruleset;
}
public override string Status => @"Playing alone";
}
public class Spectating : UserActivity
{
public override string Status => @"Spectating a game";
}
public class InLobby : UserActivity
{
public override string Status => @"In a Multiplayer Lobby";
}
}
}

View File

@ -30,6 +30,9 @@ namespace osu.Game.Users
private const float content_padding = 10;
private const float status_height = 30;
[Resolved(canBeNull: true)]
private OsuColour colours { get; set; }
private Container statusBar;
private Box statusBg;
private OsuSpriteText statusMessage;
@ -39,6 +42,8 @@ namespace osu.Game.Users
public readonly Bindable<UserStatus> Status = new Bindable<UserStatus>();
public readonly IBindable<UserActivity> Activity = new Bindable<UserActivity>();
public new Action Action;
protected Action ViewProfile;
@ -54,7 +59,7 @@ namespace osu.Game.Users
}
[BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuColour colours, UserProfileOverlay profile)
private void load(UserProfileOverlay profile)
{
if (colours == null)
throw new ArgumentNullException(nameof(colours));
@ -194,8 +199,8 @@ namespace osu.Game.Users
});
}
Status.ValueChanged += status => displayStatus(status.NewValue);
Status.ValueChanged += status => statusBg.FadeColour(status.NewValue?.GetAppropriateColour(colours) ?? colours.Gray5, 500, Easing.OutQuint);
Status.ValueChanged += status => displayStatus(status.NewValue, Activity.Value);
Activity.ValueChanged += activity => displayStatus(Status.Value, activity.NewValue);
base.Action = ViewProfile = () =>
{
@ -210,7 +215,7 @@ namespace osu.Game.Users
Status.TriggerChange();
}
private void displayStatus(UserStatus status)
private void displayStatus(UserStatus status, UserActivity activity = null)
{
const float transition_duration = 500;
@ -225,8 +230,17 @@ namespace osu.Game.Users
statusBar.ResizeHeightTo(status_height, transition_duration, Easing.OutQuint);
statusBar.FadeIn(transition_duration, Easing.OutQuint);
this.ResizeHeightTo(height, transition_duration, Easing.OutQuint);
}
statusMessage.Text = status.Message;
if (status is UserStatusOnline && activity != null)
{
statusMessage.Text = activity.Status;
statusBg.FadeColour(activity.GetAppropriateColour(colours), 500, Easing.OutQuint);
}
else
{
statusMessage.Text = status?.Message;
statusBg.FadeColour(status?.GetAppropriateColour(colours) ?? colours.Gray5, 500, Easing.OutQuint);
}
}

View File

@ -29,33 +29,7 @@ namespace osu.Game.Users
public override Color4 GetAppropriateColour(OsuColour colours) => colours.Gray7;
}
public class UserStatusSpectating : UserStatusOnline
{
public override string Message => @"Spectating a game";
}
public class UserStatusInLobby : UserStatusOnline
{
public override string Message => @"in Multiplayer Lobby";
}
public class UserStatusSoloGame : UserStatusBusy
{
public override string Message => @"Solo Game";
}
public class UserStatusMultiplayerGame : UserStatusBusy
{
public override string Message => @"Multiplaying";
}
public class UserStatusModding : UserStatusOnline
{
public override string Message => @"Modding a map";
public override Color4 GetAppropriateColour(OsuColour colours) => colours.PurpleDark;
}
public class UserStatusDoNotDisturb : UserStatusBusy
public class UserStatusDoNotDisturb : UserStatus
{
public override string Message => @"Do not disturb";
public override Color4 GetAppropriateColour(OsuColour colours) => colours.RedDark;