Add setting to allow automatically downloading during a spectating session

This commit is contained in:
Dean Herbert
2020-10-28 19:03:01 +09:00
parent 9807089834
commit 93fd913876
3 changed files with 46 additions and 2 deletions

View File

@ -42,6 +42,8 @@ namespace osu.Game.Configuration
Set(OsuSetting.Username, string.Empty); Set(OsuSetting.Username, string.Empty);
Set(OsuSetting.Token, string.Empty); Set(OsuSetting.Token, string.Empty);
Set(OsuSetting.AutomaticallyDownloadWhenSpectating, false);
Set(OsuSetting.SavePassword, false).ValueChanged += enabled => Set(OsuSetting.SavePassword, false).ValueChanged += enabled =>
{ {
if (enabled.NewValue) Set(OsuSetting.SaveUsername, true); if (enabled.NewValue) Set(OsuSetting.SaveUsername, true);
@ -239,5 +241,6 @@ namespace osu.Game.Configuration
HitLighting, HitLighting,
MenuBackgroundSource, MenuBackgroundSource,
GameplayDisableWinKey, GameplayDisableWinKey,
AutomaticallyDownloadWhenSpectating,
} }
} }

View File

@ -27,6 +27,12 @@ namespace osu.Game.Overlays.Settings.Sections.Online
Keywords = new[] { "no-video" }, Keywords = new[] { "no-video" },
Current = config.GetBindable<bool>(OsuSetting.PreferNoVideo) Current = config.GetBindable<bool>(OsuSetting.PreferNoVideo)
}, },
new SettingsCheckbox
{
LabelText = "Automatically download beatmaps when spectating",
Keywords = new[] { "spectator" },
Current = config.GetBindable<bool>(OsuSetting.AutomaticallyDownloadWhenSpectating),
},
}; };
} }
} }

View File

@ -7,12 +7,14 @@ using System.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
@ -20,6 +22,7 @@ using osu.Game.Online.API;
using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests;
using osu.Game.Online.Spectator; using osu.Game.Online.Spectator;
using osu.Game.Overlays.BeatmapListing.Panels; using osu.Game.Overlays.BeatmapListing.Panels;
using osu.Game.Overlays.Settings;
using osu.Game.Replays; using osu.Game.Replays;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
@ -69,13 +72,17 @@ namespace osu.Game.Screens.Play
private TriangleButton watchButton; private TriangleButton watchButton;
private SettingsCheckbox automaticDownload;
private BeatmapSetInfo onlineBeatmap;
public Spectator([NotNull] User targetUser) public Spectator([NotNull] User targetUser)
{ {
this.targetUser = targetUser ?? throw new ArgumentNullException(nameof(targetUser)); this.targetUser = targetUser ?? throw new ArgumentNullException(nameof(targetUser));
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours, OsuConfigManager config)
{ {
InternalChild = new Container InternalChild = new Container
{ {
@ -141,6 +148,13 @@ namespace osu.Game.Screens.Play
}, },
} }
}, },
automaticDownload = new SettingsCheckbox
{
LabelText = "Automatically download beatmaps",
Current = config.GetBindable<bool>(OsuSetting.AutomaticallyDownloadWhenSpectating),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
watchButton = new PurpleTriangleButton watchButton = new PurpleTriangleButton
{ {
Text = "Start Watching", Text = "Start Watching",
@ -167,6 +181,8 @@ namespace osu.Game.Screens.Play
managerUpdated = beatmaps.ItemUpdated.GetBoundCopy(); managerUpdated = beatmaps.ItemUpdated.GetBoundCopy();
managerUpdated.BindValueChanged(beatmapUpdated); managerUpdated.BindValueChanged(beatmapUpdated);
automaticDownload.Current.BindValueChanged(_ => checkForAutomaticDownload());
} }
private void beatmapUpdated(ValueChangedEvent<WeakReference<BeatmapSetInfo>> beatmap) private void beatmapUpdated(ValueChangedEvent<WeakReference<BeatmapSetInfo>> beatmap)
@ -246,7 +262,9 @@ namespace osu.Game.Screens.Play
var resolvedBeatmap = beatmaps.QueryBeatmap(b => b.OnlineBeatmapID == state.BeatmapID); var resolvedBeatmap = beatmaps.QueryBeatmap(b => b.OnlineBeatmapID == state.BeatmapID);
if (resolvedBeatmap == null) if (resolvedBeatmap == null)
{
return; return;
}
if (replay == null) if (replay == null)
return; return;
@ -277,6 +295,7 @@ namespace osu.Game.Screens.Play
if (state?.BeatmapID == null) if (state?.BeatmapID == null)
{ {
beatmapPanelContainer.Clear(); beatmapPanelContainer.Clear();
onlineBeatmap = null;
return; return;
} }
@ -286,12 +305,28 @@ namespace osu.Game.Screens.Play
if (state != this.state) if (state != this.state)
return; return;
beatmapPanelContainer.Child = new GridBeatmapPanel(res.ToBeatmapSet(rulesets)); onlineBeatmap = res.ToBeatmapSet(rulesets);
beatmapPanelContainer.Child = new GridBeatmapPanel(onlineBeatmap);
checkForAutomaticDownload();
}); });
api.Queue(req); api.Queue(req);
} }
private void checkForAutomaticDownload()
{
if (onlineBeatmap == null)
return;
if (!automaticDownload.Current.Value)
return;
if (beatmaps.IsAvailableLocally(onlineBeatmap))
return;
beatmaps.Download(onlineBeatmap);
}
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
{ {
base.Dispose(isDisposing); base.Dispose(isDisposing);