mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 06:42:54 +08:00
Merge pull request #11530 from frenzibyte/user-beatmap-downloading-states-2
Add UI state display for multiplayer client's beatmap availability
This commit is contained in:
commit
60cf89b366
@ -7,7 +7,10 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Osu.Mods;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer.Participants;
|
||||
@ -19,16 +22,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
public class TestSceneMultiplayerParticipantsList : MultiplayerTestScene
|
||||
{
|
||||
[SetUp]
|
||||
public new void Setup() => Schedule(() =>
|
||||
{
|
||||
Child = new ParticipantsList
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
Size = new Vector2(380, 0.7f)
|
||||
};
|
||||
});
|
||||
public new void Setup() => Schedule(createNewParticipantsList);
|
||||
|
||||
[Test]
|
||||
public void TestAddUser()
|
||||
@ -75,6 +69,50 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
AddAssert("single panel is for second user", () => this.ChildrenOfType<ParticipantPanel>().Single().User.User == secondUser);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGameStateHasPriorityOverDownloadState()
|
||||
{
|
||||
AddStep("set to downloading map", () => Client.ChangeBeatmapAvailability(BeatmapAvailability.Downloading(0)));
|
||||
checkProgressBarVisibility(true);
|
||||
|
||||
AddStep("make user ready", () => Client.ChangeState(MultiplayerUserState.Results));
|
||||
checkProgressBarVisibility(false);
|
||||
AddUntilStep("ready mark visible", () => this.ChildrenOfType<StateDisplay>().Single().IsPresent);
|
||||
|
||||
AddStep("make user ready", () => Client.ChangeState(MultiplayerUserState.Idle));
|
||||
checkProgressBarVisibility(true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCorrectInitialState()
|
||||
{
|
||||
AddStep("set to downloading map", () => Client.ChangeBeatmapAvailability(BeatmapAvailability.Downloading(0)));
|
||||
AddStep("recreate list", createNewParticipantsList);
|
||||
checkProgressBarVisibility(true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBeatmapDownloadingStates()
|
||||
{
|
||||
AddStep("set to no map", () => Client.ChangeBeatmapAvailability(BeatmapAvailability.NotDownloaded()));
|
||||
AddStep("set to downloading map", () => Client.ChangeBeatmapAvailability(BeatmapAvailability.Downloading(0)));
|
||||
|
||||
checkProgressBarVisibility(true);
|
||||
|
||||
AddRepeatStep("increment progress", () =>
|
||||
{
|
||||
var progress = this.ChildrenOfType<ParticipantPanel>().Single().User.BeatmapAvailability.DownloadProgress ?? 0;
|
||||
Client.ChangeBeatmapAvailability(BeatmapAvailability.Downloading(progress + RNG.NextSingle(0.1f)));
|
||||
}, 25);
|
||||
|
||||
AddAssert("progress bar increased", () => this.ChildrenOfType<ProgressBar>().Single().Current.Value > 0);
|
||||
|
||||
AddStep("set to importing map", () => Client.ChangeBeatmapAvailability(BeatmapAvailability.Importing()));
|
||||
checkProgressBarVisibility(false);
|
||||
|
||||
AddStep("set to available", () => Client.ChangeBeatmapAvailability(BeatmapAvailability.LocallyAvailable()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestToggleReadyState()
|
||||
{
|
||||
@ -122,6 +160,26 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
});
|
||||
|
||||
Client.ChangeUserState(i, (MultiplayerUserState)RNG.Next(0, (int)MultiplayerUserState.Results + 1));
|
||||
|
||||
if (RNG.NextBool())
|
||||
{
|
||||
var beatmapState = (DownloadState)RNG.Next(0, (int)DownloadState.LocallyAvailable + 1);
|
||||
|
||||
switch (beatmapState)
|
||||
{
|
||||
case DownloadState.NotDownloaded:
|
||||
Client.ChangeUserBeatmapAvailability(i, BeatmapAvailability.NotDownloaded());
|
||||
break;
|
||||
|
||||
case DownloadState.Downloading:
|
||||
Client.ChangeUserBeatmapAvailability(i, BeatmapAvailability.Downloading(RNG.NextSingle()));
|
||||
break;
|
||||
|
||||
case DownloadState.Importing:
|
||||
Client.ChangeUserBeatmapAvailability(i, BeatmapAvailability.Importing());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -152,5 +210,14 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
AddStep($"set state: {state}", () => Client.ChangeUserState(0, state));
|
||||
}
|
||||
}
|
||||
|
||||
private void createNewParticipantsList()
|
||||
{
|
||||
Child = new ParticipantsList { Anchor = Anchor.Centre, Origin = Anchor.Centre, RelativeSizeAxes = Axes.Y, Size = new Vector2(380, 0.7f) };
|
||||
}
|
||||
|
||||
private void checkProgressBarVisibility(bool visible) =>
|
||||
AddUntilStep($"progress bar {(visible ? "is" : "is not")}visible", () =>
|
||||
this.ChildrenOfType<ProgressBar>().Single().IsPresent == visible);
|
||||
}
|
||||
}
|
||||
|
@ -40,8 +40,19 @@ namespace osu.Game.Graphics.UserInterface
|
||||
set => CurrentNumber.Value = value;
|
||||
}
|
||||
|
||||
public ProgressBar()
|
||||
private readonly bool allowSeek;
|
||||
|
||||
public override bool HandlePositionalInput => allowSeek;
|
||||
public override bool HandleNonPositionalInput => allowSeek;
|
||||
|
||||
/// <summary>
|
||||
/// Construct a new progress bar.
|
||||
/// </summary>
|
||||
/// <param name="allowSeek">Whether the user should be allowed to click/drag to adjust the value.</param>
|
||||
public ProgressBar(bool allowSeek)
|
||||
{
|
||||
this.allowSeek = allowSeek;
|
||||
|
||||
CurrentNumber.MinValue = 0;
|
||||
CurrentNumber.MaxValue = 1;
|
||||
RelativeSizeAxes = Axes.X;
|
||||
|
@ -239,6 +239,7 @@ namespace osu.Game.Online.Multiplayer
|
||||
newConnection.On(nameof(IMultiplayerClient.MatchStarted), ((IMultiplayerClient)this).MatchStarted);
|
||||
newConnection.On(nameof(IMultiplayerClient.ResultsReady), ((IMultiplayerClient)this).ResultsReady);
|
||||
newConnection.On<int, IEnumerable<APIMod>>(nameof(IMultiplayerClient.UserModsChanged), ((IMultiplayerClient)this).UserModsChanged);
|
||||
newConnection.On<int, BeatmapAvailability>(nameof(IMultiplayerClient.UserBeatmapAvailabilityChanged), ((IMultiplayerClient)this).UserBeatmapAvailabilityChanged);
|
||||
|
||||
newConnection.Closed += ex =>
|
||||
{
|
||||
|
@ -5,6 +5,7 @@ using System;
|
||||
using System.Linq;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Beatmaps;
|
||||
|
||||
namespace osu.Game.Online.Rooms
|
||||
@ -24,19 +25,33 @@ namespace osu.Game.Online.Rooms
|
||||
/// </summary>
|
||||
public IBindable<BeatmapAvailability> Availability => availability;
|
||||
|
||||
private readonly Bindable<BeatmapAvailability> availability = new Bindable<BeatmapAvailability>();
|
||||
private readonly Bindable<BeatmapAvailability> availability = new Bindable<BeatmapAvailability>(BeatmapAvailability.LocallyAvailable());
|
||||
|
||||
public OnlinePlayBeatmapAvailablilityTracker()
|
||||
{
|
||||
State.BindValueChanged(_ => updateAvailability());
|
||||
Progress.BindValueChanged(_ => updateAvailability(), true);
|
||||
}
|
||||
private ScheduledDelegate progressUpdate;
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
SelectedItem.BindValueChanged(item => Model.Value = item.NewValue?.Beatmap.Value.BeatmapSet, true);
|
||||
SelectedItem.BindValueChanged(item =>
|
||||
{
|
||||
// the underlying playlist is regularly cleared for maintenance purposes (things which probably need to be fixed eventually).
|
||||
// to avoid exposing a state change when there may actually be none, ignore all nulls for now.
|
||||
if (item.NewValue == null)
|
||||
return;
|
||||
|
||||
Model.Value = item.NewValue.Beatmap.Value.BeatmapSet;
|
||||
}, true);
|
||||
|
||||
Progress.BindValueChanged(_ =>
|
||||
{
|
||||
// incoming progress changes are going to be at a very high rate.
|
||||
// we don't want to flood the network with this, so rate limit how often we send progress updates.
|
||||
if (progressUpdate?.Completed != false)
|
||||
progressUpdate = Scheduler.AddDelayed(updateAvailability, progressUpdate == null ? 0 : 500);
|
||||
});
|
||||
|
||||
State.BindValueChanged(_ => updateAvailability(), true);
|
||||
}
|
||||
|
||||
protected override bool VerifyDatabasedModel(BeatmapSetInfo databasedSet)
|
||||
|
@ -19,7 +19,7 @@ namespace osu.Game.Overlays.BeatmapListing.Panels
|
||||
public DownloadProgressBar(BeatmapSetInfo beatmapSet)
|
||||
: base(beatmapSet)
|
||||
{
|
||||
AddInternal(progressBar = new InteractionDisabledProgressBar
|
||||
AddInternal(progressBar = new ProgressBar(false)
|
||||
{
|
||||
Height = 0,
|
||||
Alpha = 0,
|
||||
@ -64,11 +64,5 @@ namespace osu.Game.Overlays.BeatmapListing.Panels
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
private class InteractionDisabledProgressBar : ProgressBar
|
||||
{
|
||||
public override bool HandlePositionalInput => false;
|
||||
public override bool HandleNonPositionalInput => false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -428,6 +428,11 @@ namespace osu.Game.Overlays
|
||||
|
||||
private class HoverableProgressBar : ProgressBar
|
||||
{
|
||||
public HoverableProgressBar()
|
||||
: base(true)
|
||||
{
|
||||
}
|
||||
|
||||
protected override bool OnHover(HoverEvent e)
|
||||
{
|
||||
this.ResizeHeightTo(progress_height, 500, Easing.OutQuint);
|
||||
|
@ -49,6 +49,8 @@ namespace osu.Game.Screens.OnlinePlay.Match
|
||||
[Cached]
|
||||
protected OnlinePlayBeatmapAvailablilityTracker BeatmapAvailablilityTracker { get; }
|
||||
|
||||
protected IBindable<BeatmapAvailability> BeatmapAvailability => BeatmapAvailablilityTracker.Availability;
|
||||
|
||||
protected RoomSubScreen()
|
||||
{
|
||||
AddInternal(BeatmapAvailablilityTracker = new OnlinePlayBeatmapAvailablilityTracker
|
||||
|
@ -267,6 +267,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
base.LoadComplete();
|
||||
|
||||
Playlist.BindCollectionChanged(onPlaylistChanged, true);
|
||||
BeatmapAvailability.BindValueChanged(updateBeatmapAvailability, true);
|
||||
UserMods.BindValueChanged(onUserModsChanged);
|
||||
|
||||
client.LoadRequested += onLoadRequested;
|
||||
@ -321,6 +322,19 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
client.ChangeUserMods(mods.NewValue);
|
||||
}
|
||||
|
||||
private void updateBeatmapAvailability(ValueChangedEvent<BeatmapAvailability> availability)
|
||||
{
|
||||
if (client.Room == null)
|
||||
return;
|
||||
|
||||
client.ChangeBeatmapAvailability(availability.NewValue);
|
||||
|
||||
// while this flow is handled server-side, this covers the edge case of the local user being in a ready state and then deleting the current beatmap.
|
||||
if (availability.NewValue != Online.Rooms.BeatmapAvailability.LocallyAvailable()
|
||||
&& client.LocalUser?.State == MultiplayerUserState.Ready)
|
||||
client.ChangeState(MultiplayerUserState.Idle);
|
||||
}
|
||||
|
||||
private void onReadyClick()
|
||||
{
|
||||
Debug.Assert(readyClickOperation == null);
|
||||
|
@ -162,7 +162,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
|
||||
|
||||
const double fade_time = 50;
|
||||
|
||||
userStateDisplay.Status = User.State;
|
||||
userStateDisplay.UpdateStatus(User.State, User.BeatmapAvailability);
|
||||
|
||||
if (Room.Host?.Equals(User) == true)
|
||||
crown.FadeIn(fade_time);
|
||||
|
@ -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.Diagnostics;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
@ -8,83 +10,94 @@ using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
|
||||
{
|
||||
public class StateDisplay : CompositeDrawable
|
||||
{
|
||||
private const double fade_time = 50;
|
||||
|
||||
private SpriteIcon icon;
|
||||
private OsuSpriteText text;
|
||||
private ProgressBar progressBar;
|
||||
|
||||
public StateDisplay()
|
||||
{
|
||||
AutoSizeAxes = Axes.Both;
|
||||
Alpha = 0;
|
||||
}
|
||||
|
||||
private MultiplayerUserState status;
|
||||
|
||||
private OsuSpriteText text;
|
||||
private SpriteIcon icon;
|
||||
|
||||
private const double fade_time = 50;
|
||||
|
||||
public MultiplayerUserState Status
|
||||
{
|
||||
set
|
||||
{
|
||||
if (value == status)
|
||||
return;
|
||||
|
||||
status = value;
|
||||
|
||||
if (IsLoaded)
|
||||
updateStatus();
|
||||
}
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
this.colours = colours;
|
||||
|
||||
InternalChild = new FillFlowContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.CentreRight,
|
||||
Origin = Anchor.CentreRight,
|
||||
Spacing = new Vector2(5),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
text = new OsuSpriteText
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Font = OsuFont.GetFont(weight: FontWeight.Regular, size: 12),
|
||||
Colour = Color4Extensions.FromHex("#DDFFFF")
|
||||
},
|
||||
icon = new SpriteIcon
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Anchor = Anchor.CentreRight,
|
||||
Origin = Anchor.CentreRight,
|
||||
Icon = FontAwesome.Solid.CheckCircle,
|
||||
Size = new Vector2(12),
|
||||
}
|
||||
},
|
||||
new CircularContainer
|
||||
{
|
||||
Masking = true,
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.CentreRight,
|
||||
Origin = Anchor.CentreRight,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
progressBar = new ProgressBar(false)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
BackgroundColour = Color4.Black.Opacity(0.4f),
|
||||
FillColour = colours.Blue,
|
||||
Alpha = 0f,
|
||||
},
|
||||
text = new OsuSpriteText
|
||||
{
|
||||
Padding = new MarginPadding { Horizontal = 5f, Vertical = 1f },
|
||||
Anchor = Anchor.CentreRight,
|
||||
Origin = Anchor.CentreRight,
|
||||
Font = OsuFont.GetFont(weight: FontWeight.Regular, size: 12),
|
||||
Colour = Color4Extensions.FromHex("#DDFFFF")
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
updateStatus();
|
||||
}
|
||||
private OsuColour colours;
|
||||
|
||||
[Resolved]
|
||||
private OsuColour colours { get; set; }
|
||||
|
||||
private void updateStatus()
|
||||
public void UpdateStatus(MultiplayerUserState state, BeatmapAvailability availability)
|
||||
{
|
||||
switch (status)
|
||||
// the only case where the progress bar is used does its own local fade in.
|
||||
// starting by fading out is a sane default.
|
||||
progressBar.FadeOut(fade_time);
|
||||
this.FadeIn(fade_time);
|
||||
|
||||
switch (state)
|
||||
{
|
||||
default:
|
||||
this.FadeOut(fade_time);
|
||||
return;
|
||||
case MultiplayerUserState.Idle:
|
||||
showBeatmapAvailability(availability);
|
||||
break;
|
||||
|
||||
case MultiplayerUserState.Ready:
|
||||
text.Text = "ready";
|
||||
@ -121,9 +134,43 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
|
||||
icon.Icon = FontAwesome.Solid.ArrowAltCircleUp;
|
||||
icon.Colour = colours.BlueLighter;
|
||||
break;
|
||||
}
|
||||
|
||||
this.FadeIn(fade_time);
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(state), state, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void showBeatmapAvailability(BeatmapAvailability availability)
|
||||
{
|
||||
switch (availability.State)
|
||||
{
|
||||
default:
|
||||
this.FadeOut(fade_time);
|
||||
break;
|
||||
|
||||
case DownloadState.NotDownloaded:
|
||||
text.Text = "no map";
|
||||
icon.Icon = FontAwesome.Solid.MinusCircle;
|
||||
icon.Colour = colours.RedLight;
|
||||
break;
|
||||
|
||||
case DownloadState.Downloading:
|
||||
Debug.Assert(availability.DownloadProgress != null);
|
||||
|
||||
progressBar.FadeIn(fade_time);
|
||||
progressBar.CurrentTime = availability.DownloadProgress.Value;
|
||||
|
||||
text.Text = "downloading map";
|
||||
icon.Icon = FontAwesome.Solid.ArrowAltCircleDown;
|
||||
icon.Colour = colours.Blue;
|
||||
break;
|
||||
|
||||
case DownloadState.Importing:
|
||||
text.Text = "importing map";
|
||||
icon.Icon = FontAwesome.Solid.ArrowAltCircleDown;
|
||||
icon.Colour = colours.Yellow;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user