1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 08:07:40 +08:00
osu-lazer/osu.Game/Screens/Multi/Lounge/Components/RoomInspector.cs

323 lines
13 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.
2018-04-13 17:19:50 +08:00
using System;
2018-04-13 17:19:50 +08:00
using osu.Framework.Allocation;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
2018-04-13 17:19:50 +08:00
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
2018-04-13 17:19:50 +08:00
using osu.Game.Online.Multiplayer;
2018-12-10 18:20:41 +08:00
using osu.Game.Screens.Multi.Components;
2018-04-13 17:19:50 +08:00
using osu.Game.Users;
2018-11-20 15:51:59 +08:00
using osuTK;
using osuTK.Graphics;
2018-04-13 17:19:50 +08:00
2018-12-10 18:20:41 +08:00
namespace osu.Game.Screens.Multi.Lounge.Components
2018-04-13 17:19:50 +08:00
{
2019-02-05 18:00:01 +08:00
public class RoomInspector : MultiplayerComposite
2018-04-13 17:19:50 +08:00
{
private const float transition_duration = 100;
private readonly MarginPadding contentPadding = new MarginPadding { Horizontal = 20, Vertical = 10 };
2018-04-13 17:19:50 +08:00
2018-12-26 20:58:14 +08:00
private ParticipantCountDisplay participantCount;
2019-02-07 16:59:14 +08:00
private OsuSpriteText name;
2018-05-29 10:45:59 +08:00
private BeatmapTypeInfo beatmapTypeInfo;
private ParticipantInfo participantInfo;
2018-04-13 17:19:50 +08:00
2018-12-06 11:21:30 +08:00
[Resolved]
private BeatmapManager beatmaps { get; set; }
2019-02-07 16:59:14 +08:00
private readonly Bindable<RoomStatus> status = new Bindable<RoomStatus>(new RoomStatusNoneSelected());
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
2019-02-05 18:00:01 +08:00
InternalChildren = new Drawable[]
2018-04-13 17:19:50 +08:00
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.FromHex(@"343138"),
},
new GridContainer
2018-04-13 17:19:50 +08:00
{
RelativeSizeAxes = Axes.Both,
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.Distributed),
},
Content = new[]
2018-04-13 17:19:50 +08:00
{
new Drawable[]
2018-04-13 17:19:50 +08:00
{
new FillFlowContainer
2018-04-13 17:19:50 +08:00
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new Drawable[]
2018-04-13 17:19:50 +08:00
{
new Container
2018-04-13 17:19:50 +08:00
{
RelativeSizeAxes = Axes.X,
Height = 200,
Masking = true,
Children = new Drawable[]
2018-04-13 17:19:50 +08:00
{
2019-02-05 18:00:01 +08:00
new MultiplayerBackgroundSprite { RelativeSizeAxes = Axes.Both },
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = ColourInfo.GradientVertical(Color4.Black.Opacity(0.5f), Color4.Black.Opacity(0)),
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(20),
Children = new Drawable[]
{
participantCount = new ParticipantCountDisplay
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
},
name = new OsuSpriteText
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Font = OsuFont.GetFont(size: 30),
2019-02-07 16:59:14 +08:00
Current = Name
},
},
},
2018-04-13 17:19:50 +08:00
},
},
2019-02-07 16:59:14 +08:00
new StatusColouredContainer(transition_duration)
{
RelativeSizeAxes = Axes.X,
Height = 5,
2019-02-07 16:59:14 +08:00
Child = new Box { RelativeSizeAxes = Axes.Both }
},
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
2018-04-13 17:19:50 +08:00
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.FromHex(@"28242d"),
},
new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
LayoutDuration = transition_duration,
Padding = contentPadding,
Spacing = new Vector2(0f, 5f),
Children = new Drawable[]
{
2019-02-07 16:59:14 +08:00
new StatusColouredContainer(transition_duration)
{
2019-02-07 16:59:14 +08:00
AutoSizeAxes = Axes.Both,
Child = new StatusText
{
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 14),
2019-02-07 16:59:14 +08:00
}
},
beatmapTypeInfo = new BeatmapTypeInfo(),
},
},
2018-04-13 17:19:50 +08:00
},
},
new Container
2018-04-13 17:19:50 +08:00
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = contentPadding,
Children = new Drawable[]
2018-04-13 17:19:50 +08:00
{
participantInfo = new ParticipantInfo(),
2018-04-13 17:19:50 +08:00
},
},
},
},
},
new Drawable[]
2018-04-13 17:19:50 +08:00
{
2019-02-05 18:00:01 +08:00
new MatchParticipants
2018-04-13 17:19:50 +08:00
{
RelativeSizeAxes = Axes.Both,
}
}
}
}
2018-04-13 17:19:50 +08:00
};
2019-02-07 16:59:14 +08:00
Status.BindValueChanged(_ => updateStatus(), true);
RoomID.BindValueChanged(_ => updateStatus(), true);
2018-04-13 17:19:50 +08:00
}
2019-02-07 16:59:14 +08:00
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
2019-02-07 16:59:14 +08:00
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
2019-02-08 14:44:05 +08:00
dependencies.CacheAs(status, new CacheInfo(nameof(Room.Status), typeof(Room)));
2019-02-07 16:59:14 +08:00
return dependencies;
}
private void updateStatus()
{
if (RoomID.Value == null)
{
2019-02-07 16:59:14 +08:00
status.Value = new RoomStatusNoneSelected();
participantCount.FadeOut(transition_duration);
2018-05-29 10:45:59 +08:00
beatmapTypeInfo.FadeOut(transition_duration);
2018-05-19 13:51:51 +08:00
name.FadeOut(transition_duration);
participantInfo.FadeOut(transition_duration);
}
2019-02-07 16:59:14 +08:00
else
{
2019-02-21 17:56:34 +08:00
status.Value = Status.Value;
2019-02-07 16:59:14 +08:00
participantCount.FadeIn(transition_duration);
beatmapTypeInfo.FadeIn(transition_duration);
name.FadeIn(transition_duration);
participantInfo.FadeIn(transition_duration);
}
}
private class RoomStatusNoneSelected : RoomStatus
{
public override string Message => @"No Room Selected";
public override Color4 GetAppropriateColour(OsuColour colours) => colours.Gray8;
}
2019-02-07 16:59:14 +08:00
private class StatusText : OsuSpriteText
{
2019-02-08 14:44:05 +08:00
[Resolved(typeof(Room), nameof(Room.Status))]
2019-02-07 16:59:14 +08:00
private Bindable<RoomStatus> status { get; set; }
[BackgroundDependencyLoader]
private void load()
{
status.BindValueChanged(s => Text = s.NewValue.Message, true);
2019-02-07 16:59:14 +08:00
}
}
2019-02-05 18:00:01 +08:00
private class MatchParticipants : MultiplayerComposite
2018-04-13 17:19:50 +08:00
{
private readonly FillFlowContainer fill;
public MatchParticipants()
2018-04-13 17:19:50 +08:00
{
Padding = new MarginPadding { Horizontal = 10 };
2018-04-13 17:19:50 +08:00
InternalChild = new ScrollContainer
2018-04-13 17:19:50 +08:00
{
RelativeSizeAxes = Axes.Both,
Child = fill = new FillFlowContainer
2018-04-13 17:19:50 +08:00
{
Spacing = new Vector2(10),
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Full,
}
2018-04-13 17:19:50 +08:00
};
}
2019-02-05 18:00:01 +08:00
[BackgroundDependencyLoader]
private void load()
{
RoomID.BindValueChanged(_ => updateParticipants(), true);
}
[Resolved]
private IAPIProvider api { get; set; }
private GetRoomScoresRequest request;
private void updateParticipants()
{
2019-02-05 18:00:01 +08:00
var roomId = RoomID.Value ?? 0;
request?.Cancel();
// nice little progressive fade
int time = 500;
foreach (var c in fill.Children)
{
c.Delay(500 - time).FadeOut(time, Easing.Out);
time = Math.Max(20, time - 20);
c.Expire();
}
if (roomId == 0) return;
request = new GetRoomScoresRequest(roomId);
request.Success += scores =>
{
2019-02-05 18:00:01 +08:00
if (roomId != RoomID.Value)
return;
fill.Clear();
foreach (var s in scores)
fill.Add(new UserTile(s.User));
fill.FadeInFromZero(1000, Easing.OutQuint);
};
api.Queue(request);
}
protected override void Dispose(bool isDisposing)
{
request?.Cancel();
base.Dispose(isDisposing);
}
private class UserTile : CompositeDrawable, IHasTooltip
{
private readonly User user;
public string TooltipText => user.Username;
public UserTile(User user)
{
this.user = user;
Size = new Vector2(70f);
CornerRadius = 5f;
Masking = true;
InternalChildren = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.FromHex(@"27252d"),
},
new UpdateableAvatar
{
RelativeSizeAxes = Axes.Both,
User = user,
},
};
}
}
}
2018-04-13 17:19:50 +08:00
}
}