Merge branch 'master' into remove-osu-direct

This commit is contained in:
Bartłomiej Dach
2021-01-06 17:32:12 +01:00
committed by GitHub
5 changed files with 63 additions and 6 deletions

View File

@ -9,6 +9,7 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Game.Configuration;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Users; using osu.Game.Users;
@ -31,13 +32,15 @@ namespace osu.Desktop
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 IBindable<UserActivity> activity = new Bindable<UserActivity>();
private readonly Bindable<DiscordRichPresenceMode> privacyMode = new Bindable<DiscordRichPresenceMode>();
private readonly RichPresence presence = new RichPresence private readonly RichPresence presence = new RichPresence
{ {
Assets = new Assets { LargeImageKey = "osu_logo_lazer", } Assets = new Assets { LargeImageKey = "osu_logo_lazer", }
}; };
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(IAPIProvider provider) private void load(IAPIProvider provider, OsuConfigManager config)
{ {
client = new DiscordRpcClient(client_id) client = new DiscordRpcClient(client_id)
{ {
@ -51,6 +54,8 @@ namespace osu.Desktop
client.OnError += (_, e) => Logger.Log($"An error occurred with Discord RPC Client: {e.Code} {e.Message}", LoggingTarget.Network); client.OnError += (_, e) => Logger.Log($"An error occurred with Discord RPC Client: {e.Code} {e.Message}", LoggingTarget.Network);
config.BindWith(OsuSetting.DiscordRichPresence, privacyMode);
(user = provider.LocalUser.GetBoundCopy()).BindValueChanged(u => (user = provider.LocalUser.GetBoundCopy()).BindValueChanged(u =>
{ {
status.UnbindBindings(); status.UnbindBindings();
@ -63,6 +68,7 @@ namespace osu.Desktop
ruleset.BindValueChanged(_ => updateStatus()); ruleset.BindValueChanged(_ => updateStatus());
status.BindValueChanged(_ => updateStatus()); status.BindValueChanged(_ => updateStatus());
activity.BindValueChanged(_ => updateStatus()); activity.BindValueChanged(_ => updateStatus());
privacyMode.BindValueChanged(_ => updateStatus());
client.Initialize(); client.Initialize();
} }
@ -78,7 +84,7 @@ namespace osu.Desktop
if (!client.IsInitialized) if (!client.IsInitialized)
return; return;
if (status.Value is UserStatusOffline) if (status.Value is UserStatusOffline || privacyMode.Value == DiscordRichPresenceMode.Off)
{ {
client.ClearPresence(); client.ClearPresence();
return; return;
@ -96,7 +102,10 @@ namespace osu.Desktop
} }
// update user information // update user information
presence.Assets.LargeImageText = $"{user.Value.Username}" + (user.Value.Statistics?.Ranks.Global > 0 ? $" (rank #{user.Value.Statistics.Ranks.Global:N0})" : string.Empty); if (privacyMode.Value == DiscordRichPresenceMode.Limited)
presence.Assets.LargeImageText = string.Empty;
else
presence.Assets.LargeImageText = $"{user.Value.Username}" + (user.Value.Statistics?.Ranks.Global > 0 ? $" (rank #{user.Value.Statistics.Ranks.Global:N0})" : string.Empty);
// update ruleset // update ruleset
presence.Assets.SmallImageKey = ruleset.Value.ID <= 3 ? $"mode_{ruleset.Value.ID}" : "mode_custom"; presence.Assets.SmallImageKey = ruleset.Value.ID <= 3 ? $"mode_{ruleset.Value.ID}" : "mode_custom";
@ -137,7 +146,7 @@ namespace osu.Desktop
return edit.Beatmap.ToString(); return edit.Beatmap.ToString();
case UserActivity.InLobby lobby: case UserActivity.InLobby lobby:
return lobby.Room.Name.Value; return privacyMode.Value == DiscordRichPresenceMode.Limited ? string.Empty : lobby.Room.Name.Value;
} }
return string.Empty; return string.Empty;

View File

@ -0,0 +1,17 @@
// 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.ComponentModel;
namespace osu.Game.Configuration
{
public enum DiscordRichPresenceMode
{
Off,
[Description("Hide identifiable information")]
Limited,
Full
}
}

View File

@ -1,4 +1,4 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System; using System;
@ -138,6 +138,8 @@ namespace osu.Game.Configuration
Set(OsuSetting.MenuBackgroundSource, BackgroundSource.Skin); Set(OsuSetting.MenuBackgroundSource, BackgroundSource.Skin);
Set(OsuSetting.SeasonalBackgroundMode, SeasonalBackgroundMode.Sometimes); Set(OsuSetting.SeasonalBackgroundMode, SeasonalBackgroundMode.Sometimes);
Set(OsuSetting.DiscordRichPresence, DiscordRichPresenceMode.Full);
Set(OsuSetting.EditorWaveformOpacity, 1f); Set(OsuSetting.EditorWaveformOpacity, 1f);
} }
@ -266,6 +268,7 @@ namespace osu.Game.Configuration
GameplayDisableWinKey, GameplayDisableWinKey,
SeasonalBackgroundMode, SeasonalBackgroundMode,
EditorWaveformOpacity, EditorWaveformOpacity,
DiscordRichPresence,
AutomaticallyDownloadWhenSpectating, AutomaticallyDownloadWhenSpectating,
} }
} }

View File

@ -0,0 +1,27 @@
// 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.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Configuration;
namespace osu.Game.Overlays.Settings.Sections.Online
{
public class IntegrationSettings : SettingsSubsection
{
protected override string Header => "Integrations";
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
Children = new Drawable[]
{
new SettingsEnumDropdown<DiscordRichPresenceMode>
{
LabelText = "Discord Rich Presence",
Current = config.GetBindable<DiscordRichPresenceMode>(OsuSetting.DiscordRichPresence)
}
};
}
}
}

View File

@ -20,7 +20,8 @@ namespace osu.Game.Overlays.Settings.Sections
{ {
Children = new Drawable[] Children = new Drawable[]
{ {
new WebSettings() new WebSettings(),
new IntegrationSettings()
}; };
} }
} }