1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-19 04:35:03 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/Multiplayer/Participants/StateDisplay.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

181 lines
6.6 KiB
C#
Raw Normal View History

// 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.
2021-02-05 14:46:03 +08:00
using System;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
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;
2020-12-25 12:38:11 +08:00
using osu.Game.Online.Multiplayer;
using osu.Game.Online.Rooms;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
{
public partial class StateDisplay : CompositeDrawable
{
private const double fade_time = 50;
private SpriteIcon icon = null!;
private OsuSpriteText text = null!;
private ProgressBar progressBar = null!;
public StateDisplay()
{
AutoSizeAxes = Axes.Both;
Alpha = 0;
}
[BackgroundDependencyLoader]
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[]
{
icon = new SpriteIcon
{
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")
},
}
},
}
};
}
private OsuColour colours = null!;
public void UpdateStatus(MultiplayerUserState state, BeatmapAvailability availability)
{
2021-02-05 14:46:03 +08:00
// 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)
{
2021-02-05 14:46:03 +08:00
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:
case MultiplayerUserState.ReadyForGameplay:
2021-02-05 14:46:03 +08:00
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;
2021-04-07 15:40:24 +08:00
case MultiplayerUserState.Spectating:
text.Text = "spectating";
icon.Icon = FontAwesome.Solid.Binoculars;
2021-04-07 15:40:24 +08:00
icon.Colour = colours.BlueLight;
break;
2021-02-05 14:46:03 +08:00
default:
throw new ArgumentOutOfRangeException(nameof(state), state, null);
}
2021-02-05 14:46:03 +08:00
}
2021-02-05 14:46:03 +08:00
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:
progressBar.FadeIn(fade_time);
progressBar.CurrentTime = availability.DownloadProgress ?? 0;
2021-02-05 14:46:03 +08:00
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;
}
}
}
}