mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 09:07:52 +08:00
Simplify UserStatus
to be an enumeration type
There were absolutely no gains from having it be a reference type / class, only complications, especially when coming from the serialisation angle.
This commit is contained in:
parent
cb823f367f
commit
d66fa09320
@ -33,7 +33,7 @@ namespace osu.Desktop
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; } = null!;
|
||||
|
||||
private readonly IBindable<UserStatus> status = new Bindable<UserStatus>();
|
||||
private readonly IBindable<UserStatus?> status = new Bindable<UserStatus?>();
|
||||
private readonly IBindable<UserActivity> activity = new Bindable<UserActivity>();
|
||||
|
||||
private readonly Bindable<DiscordRichPresenceMode> privacyMode = new Bindable<DiscordRichPresenceMode>();
|
||||
@ -86,13 +86,13 @@ namespace osu.Desktop
|
||||
if (!client.IsInitialized)
|
||||
return;
|
||||
|
||||
if (status.Value is UserStatusOffline || privacyMode.Value == DiscordRichPresenceMode.Off)
|
||||
if (status.Value == UserStatus.Offline || privacyMode.Value == DiscordRichPresenceMode.Off)
|
||||
{
|
||||
client.ClearPresence();
|
||||
return;
|
||||
}
|
||||
|
||||
if (status.Value is UserStatusOnline && activity.Value != null)
|
||||
if (status.Value == UserStatus.Online && activity.Value != null)
|
||||
{
|
||||
bool hideIdentifiableInformation = privacyMode.Value == DiscordRichPresenceMode.Limited;
|
||||
presence.State = truncate(activity.Value.GetStatus(hideIdentifiableInformation));
|
||||
|
@ -64,7 +64,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
Colour = color ?? "000000",
|
||||
Status =
|
||||
{
|
||||
Value = new UserStatusOnline()
|
||||
Value = UserStatus.Online
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -24,7 +24,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
public partial class TestSceneUserPanel : OsuTestScene
|
||||
{
|
||||
private readonly Bindable<UserActivity> activity = new Bindable<UserActivity>();
|
||||
private readonly Bindable<UserStatus> status = new Bindable<UserStatus>();
|
||||
private readonly Bindable<UserStatus?> status = new Bindable<UserStatus?>();
|
||||
|
||||
private UserGridPanel boundPanel1;
|
||||
private TestUserListPanel boundPanel2;
|
||||
@ -66,7 +66,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
Id = 3103765,
|
||||
CountryCode = CountryCode.JP,
|
||||
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c6.jpg",
|
||||
Status = { Value = new UserStatusOnline() }
|
||||
Status = { Value = UserStatus.Online }
|
||||
}) { Width = 300 },
|
||||
boundPanel1 = new UserGridPanel(new APIUser
|
||||
{
|
||||
@ -99,16 +99,16 @@ namespace osu.Game.Tests.Visual.Online
|
||||
[Test]
|
||||
public void TestUserStatus()
|
||||
{
|
||||
AddStep("online", () => status.Value = new UserStatusOnline());
|
||||
AddStep("do not disturb", () => status.Value = new UserStatusDoNotDisturb());
|
||||
AddStep("offline", () => status.Value = new UserStatusOffline());
|
||||
AddStep("online", () => status.Value = UserStatus.Online);
|
||||
AddStep("do not disturb", () => status.Value = UserStatus.DoNotDisturb);
|
||||
AddStep("offline", () => status.Value = UserStatus.Offline);
|
||||
AddStep("null status", () => status.Value = null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestUserActivity()
|
||||
{
|
||||
AddStep("set online status", () => status.Value = new UserStatusOnline());
|
||||
AddStep("set online status", () => status.Value = UserStatus.Online);
|
||||
|
||||
AddStep("idle", () => activity.Value = null);
|
||||
AddStep("watching replay", () => activity.Value = new UserActivity.WatchingReplay(createScore(@"nats")));
|
||||
@ -127,12 +127,12 @@ namespace osu.Game.Tests.Visual.Online
|
||||
public void TestUserActivityChange()
|
||||
{
|
||||
AddAssert("visit message is visible", () => boundPanel2.LastVisitMessage.IsPresent);
|
||||
AddStep("set online status", () => status.Value = new UserStatusOnline());
|
||||
AddStep("set online status", () => status.Value = UserStatus.Online);
|
||||
AddAssert("visit message is not visible", () => !boundPanel2.LastVisitMessage.IsPresent);
|
||||
AddStep("set choosing activity", () => activity.Value = new UserActivity.ChoosingBeatmap());
|
||||
AddStep("set offline status", () => status.Value = new UserStatusOffline());
|
||||
AddStep("set offline status", () => status.Value = UserStatus.Offline);
|
||||
AddAssert("visit message is visible", () => boundPanel2.LastVisitMessage.IsPresent);
|
||||
AddStep("set online status", () => status.Value = new UserStatusOnline());
|
||||
AddStep("set online status", () => status.Value = UserStatus.Online);
|
||||
AddAssert("visit message is not visible", () => !boundPanel2.LastVisitMessage.IsPresent);
|
||||
}
|
||||
|
||||
|
@ -247,7 +247,7 @@ namespace osu.Game.Online.API
|
||||
userReq.Success += user =>
|
||||
{
|
||||
// todo: save/pull from settings
|
||||
user.Status.Value = new UserStatusOnline();
|
||||
user.Status.Value = UserStatus.Online;
|
||||
|
||||
setLocalUser(user);
|
||||
|
||||
|
@ -43,7 +43,7 @@ namespace osu.Game.Online.API.Requests.Responses
|
||||
set => countryCodeString = value.ToString();
|
||||
}
|
||||
|
||||
public readonly Bindable<UserStatus> Status = new Bindable<UserStatus>();
|
||||
public readonly Bindable<UserStatus?> Status = new Bindable<UserStatus?>();
|
||||
|
||||
public readonly Bindable<UserActivity> Activity = new Bindable<UserActivity>();
|
||||
|
||||
|
@ -148,17 +148,17 @@ namespace osu.Game.Overlays.Login
|
||||
switch (action.NewValue)
|
||||
{
|
||||
case UserAction.Online:
|
||||
api.LocalUser.Value.Status.Value = new UserStatusOnline();
|
||||
api.LocalUser.Value.Status.Value = UserStatus.Online;
|
||||
dropdown.StatusColour = colours.Green;
|
||||
break;
|
||||
|
||||
case UserAction.DoNotDisturb:
|
||||
api.LocalUser.Value.Status.Value = new UserStatusDoNotDisturb();
|
||||
api.LocalUser.Value.Status.Value = UserStatus.DoNotDisturb;
|
||||
dropdown.StatusColour = colours.Red;
|
||||
break;
|
||||
|
||||
case UserAction.AppearOffline:
|
||||
api.LocalUser.Value.Status.Value = new UserStatusOffline();
|
||||
api.LocalUser.Value.Status.Value = UserStatus.Offline;
|
||||
dropdown.StatusColour = colours.Gray7;
|
||||
break;
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
using osuTK;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Graphics;
|
||||
@ -18,7 +19,7 @@ namespace osu.Game.Users
|
||||
{
|
||||
public abstract partial class ExtendedUserPanel : UserPanel
|
||||
{
|
||||
public readonly Bindable<UserStatus> Status = new Bindable<UserStatus>();
|
||||
public readonly Bindable<UserStatus?> Status = new Bindable<UserStatus?>();
|
||||
|
||||
public readonly IBindable<UserActivity> Activity = new Bindable<UserActivity>();
|
||||
|
||||
@ -97,14 +98,14 @@ namespace osu.Game.Users
|
||||
return statusContainer;
|
||||
}
|
||||
|
||||
private void displayStatus(UserStatus status, UserActivity activity = null)
|
||||
private void displayStatus(UserStatus? status, UserActivity activity = null)
|
||||
{
|
||||
if (status != null)
|
||||
{
|
||||
LastVisitMessage.FadeTo(status is UserStatusOffline && User.LastVisit.HasValue ? 1 : 0);
|
||||
LastVisitMessage.FadeTo(status == UserStatus.Offline && User.LastVisit.HasValue ? 1 : 0);
|
||||
|
||||
// Set status message based on activity (if we have one) and status is not offline
|
||||
if (activity != null && !(status is UserStatusOffline))
|
||||
if (activity != null && status != UserStatus.Offline)
|
||||
{
|
||||
statusMessage.Text = activity.GetStatus();
|
||||
statusIcon.FadeColour(activity.GetAppropriateColour(Colours), 500, Easing.OutQuint);
|
||||
@ -112,8 +113,8 @@ namespace osu.Game.Users
|
||||
}
|
||||
|
||||
// Otherwise use only status
|
||||
statusMessage.Text = status.Message;
|
||||
statusIcon.FadeColour(status.GetAppropriateColour(Colours), 500, Easing.OutQuint);
|
||||
statusMessage.Text = status.GetLocalisableDescription();
|
||||
statusIcon.FadeColour(status.Value.GetAppropriateColour(Colours), 500, Easing.OutQuint);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -121,11 +122,11 @@ namespace osu.Game.Users
|
||||
// Fallback to web status if local one is null
|
||||
if (User.IsOnline)
|
||||
{
|
||||
Status.Value = new UserStatusOnline();
|
||||
Status.Value = UserStatus.Online;
|
||||
return;
|
||||
}
|
||||
|
||||
Status.Value = new UserStatusOffline();
|
||||
Status.Value = UserStatus.Offline;
|
||||
}
|
||||
|
||||
protected override bool OnHover(HoverEvent e)
|
||||
|
@ -1,6 +1,8 @@
|
||||
// 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.ComponentModel;
|
||||
using osu.Framework.Localisation;
|
||||
using osuTK.Graphics;
|
||||
using osu.Game.Graphics;
|
||||
@ -8,32 +10,36 @@ using osu.Game.Resources.Localisation.Web;
|
||||
|
||||
namespace osu.Game.Users
|
||||
{
|
||||
public abstract class UserStatus
|
||||
public enum UserStatus
|
||||
{
|
||||
public abstract LocalisableString Message { get; }
|
||||
public abstract Color4 GetAppropriateColour(OsuColour colours);
|
||||
[LocalisableDescription(typeof(UsersStrings), nameof(UsersStrings.StatusOffline))]
|
||||
Offline,
|
||||
|
||||
[Description("Do not disturb")]
|
||||
DoNotDisturb,
|
||||
|
||||
[LocalisableDescription(typeof(UsersStrings), nameof(UsersStrings.StatusOnline))]
|
||||
Online,
|
||||
}
|
||||
|
||||
public class UserStatusOnline : UserStatus
|
||||
public static class UserStatusExtensions
|
||||
{
|
||||
public override LocalisableString Message => UsersStrings.StatusOnline;
|
||||
public override Color4 GetAppropriateColour(OsuColour colours) => colours.GreenLight;
|
||||
}
|
||||
public static Color4 GetAppropriateColour(this UserStatus userStatus, OsuColour colours)
|
||||
{
|
||||
switch (userStatus)
|
||||
{
|
||||
case UserStatus.Offline:
|
||||
return Color4.Black;
|
||||
|
||||
public abstract class UserStatusBusy : UserStatusOnline
|
||||
{
|
||||
public override Color4 GetAppropriateColour(OsuColour colours) => colours.YellowDark;
|
||||
}
|
||||
case UserStatus.DoNotDisturb:
|
||||
return colours.RedDark;
|
||||
|
||||
public class UserStatusOffline : UserStatus
|
||||
{
|
||||
public override LocalisableString Message => UsersStrings.StatusOffline;
|
||||
public override Color4 GetAppropriateColour(OsuColour colours) => Color4.Black;
|
||||
}
|
||||
case UserStatus.Online:
|
||||
return colours.GreenDark;
|
||||
|
||||
public class UserStatusDoNotDisturb : UserStatus
|
||||
{
|
||||
public override LocalisableString Message => "Do not disturb";
|
||||
public override Color4 GetAppropriateColour(OsuColour colours) => colours.RedDark;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(userStatus), userStatus, "Unsupported user status");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user