1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-16 05:52:55 +08:00

Refactor logic to suck a bit less

This commit is contained in:
Dean Herbert 2021-02-05 15:46:03 +09:00
parent d1f9aa52a4
commit 1b6a052798

View File

@ -1,6 +1,7 @@
// 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;
@ -87,85 +88,89 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
public void UpdateStatus(MultiplayerUserState state, BeatmapAvailability availability)
{
if (availability.State != DownloadState.LocallyAvailable)
{
switch (availability.State)
{
case DownloadState.NotDownloaded:
progressBar.FadeOut(fade_time);
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:
progressBar.FadeOut(fade_time);
text.Text = "importing map";
icon.Icon = FontAwesome.Solid.ArrowAltCircleDown;
icon.Colour = colours.Yellow;
break;
}
}
else
{
progressBar.FadeOut(fade_time);
switch (state)
{
default:
this.FadeOut(fade_time);
return;
case MultiplayerUserState.Ready:
text.Text = "ready";
icon.Icon = FontAwesome.Solid.CheckCircle;
icon.Colour = Color4Extensions.FromHex("#AADD00");
break;
case MultiplayerUserState.WaitingForLoad:
text.Text = "loading";
icon.Icon = FontAwesome.Solid.PauseCircle;
icon.Colour = colours.Yellow;
break;
case MultiplayerUserState.Loaded:
text.Text = "loaded";
icon.Icon = FontAwesome.Solid.DotCircle;
icon.Colour = colours.YellowLight;
break;
case MultiplayerUserState.Playing:
text.Text = "playing";
icon.Icon = FontAwesome.Solid.PlayCircle;
icon.Colour = colours.BlueLight;
break;
case MultiplayerUserState.FinishedPlay:
text.Text = "results pending";
icon.Icon = FontAwesome.Solid.ArrowAltCircleUp;
icon.Colour = colours.BlueLighter;
break;
case MultiplayerUserState.Results:
text.Text = "results";
icon.Icon = FontAwesome.Solid.ArrowAltCircleUp;
icon.Colour = colours.BlueLighter;
break;
}
}
// 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)
{
case MultiplayerUserState.Idle:
showBeatmapAvailability(availability);
break;
case MultiplayerUserState.Ready:
text.Text = "ready";
icon.Icon = FontAwesome.Solid.CheckCircle;
icon.Colour = Color4Extensions.FromHex("#AADD00");
break;
case MultiplayerUserState.WaitingForLoad:
text.Text = "loading";
icon.Icon = FontAwesome.Solid.PauseCircle;
icon.Colour = colours.Yellow;
break;
case MultiplayerUserState.Loaded:
text.Text = "loaded";
icon.Icon = FontAwesome.Solid.DotCircle;
icon.Colour = colours.YellowLight;
break;
case MultiplayerUserState.Playing:
text.Text = "playing";
icon.Icon = FontAwesome.Solid.PlayCircle;
icon.Colour = colours.BlueLight;
break;
case MultiplayerUserState.FinishedPlay:
text.Text = "results pending";
icon.Icon = FontAwesome.Solid.ArrowAltCircleUp;
icon.Colour = colours.BlueLighter;
break;
case MultiplayerUserState.Results:
text.Text = "results";
icon.Icon = FontAwesome.Solid.ArrowAltCircleUp;
icon.Colour = colours.BlueLighter;
break;
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;
}
}
}
}