2018-04-13 17:19:50 +08:00
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
2018-06-01 17:15:23 +08:00
|
|
|
using System.Collections.Generic;
|
2018-04-13 17:19:50 +08:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Configuration;
|
|
|
|
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.Beatmaps.Drawables;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
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
|
|
|
{
|
|
|
|
public class RoomInspector : Container
|
|
|
|
{
|
|
|
|
private const float transition_duration = 100;
|
|
|
|
|
2018-12-11 18:07:40 +08:00
|
|
|
public readonly Bindable<Room> Room = new Bindable<Room>();
|
|
|
|
|
2018-05-19 13:23:09 +08:00
|
|
|
private readonly MarginPadding contentPadding = new MarginPadding { Horizontal = 20, Vertical = 10 };
|
2018-04-13 17:19:50 +08:00
|
|
|
private readonly Bindable<string> nameBind = new Bindable<string>();
|
|
|
|
private readonly Bindable<User> hostBind = new Bindable<User>();
|
|
|
|
private readonly Bindable<RoomStatus> statusBind = new Bindable<RoomStatus>();
|
|
|
|
private readonly Bindable<GameType> typeBind = new Bindable<GameType>();
|
|
|
|
private readonly Bindable<int?> maxParticipantsBind = new Bindable<int?>();
|
2018-06-01 17:15:23 +08:00
|
|
|
private readonly Bindable<IEnumerable<User>> participantsBind = new Bindable<IEnumerable<User>>();
|
2018-12-13 17:38:03 +08:00
|
|
|
private readonly IBindableCollection<PlaylistItem> playlistBind = new BindableCollection<PlaylistItem>();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-12-06 11:21:30 +08:00
|
|
|
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
|
|
|
|
|
2018-05-19 13:23:09 +08:00
|
|
|
private OsuColour colours;
|
|
|
|
private Box statusStrip;
|
2018-12-06 11:21:30 +08:00
|
|
|
private UpdateableBeatmapBackgroundSprite background;
|
2018-05-29 11:51:56 +08:00
|
|
|
private ParticipantCount participantCount;
|
|
|
|
private FillFlowContainer topFlow, participantsFlow;
|
2018-05-19 13:23:09 +08:00
|
|
|
private OsuSpriteText name, status;
|
2018-05-29 10:45:59 +08:00
|
|
|
private BeatmapTypeInfo beatmapTypeInfo;
|
2018-05-19 12:26:39 +08:00
|
|
|
private ScrollContainer participantsScroll;
|
2018-05-19 13:23:09 +08:00
|
|
|
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; }
|
|
|
|
|
2018-05-19 12:26:39 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2018-05-29 10:33:13 +08:00
|
|
|
private void load(OsuColour colours)
|
2018-05-19 12:26:39 +08:00
|
|
|
{
|
2018-05-19 13:23:09 +08:00
|
|
|
this.colours = colours;
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = OsuColour.FromHex(@"343138"),
|
|
|
|
},
|
|
|
|
topFlow = new FillFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Height = 200,
|
|
|
|
Masking = true,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2018-12-06 11:21:30 +08:00
|
|
|
background = new UpdateableBeatmapBackgroundSprite { RelativeSizeAxes = Axes.Both },
|
2018-04-13 17:19:50 +08:00
|
|
|
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[]
|
|
|
|
{
|
2018-05-29 11:51:56 +08:00
|
|
|
participantCount = new ParticipantCount
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
},
|
|
|
|
name = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
TextSize = 30,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
statusStrip = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Height = 5,
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = OsuColour.FromHex(@"28242d"),
|
|
|
|
},
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Direction = FillDirection.Vertical,
|
2018-05-19 13:23:09 +08:00
|
|
|
LayoutDuration = transition_duration,
|
2018-04-13 17:19:50 +08:00
|
|
|
Padding = contentPadding,
|
|
|
|
Spacing = new Vector2(0f, 5f),
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
status = new OsuSpriteText
|
|
|
|
{
|
|
|
|
TextSize = 14,
|
|
|
|
Font = @"Exo2.0-Bold",
|
|
|
|
},
|
2018-05-29 10:45:59 +08:00
|
|
|
beatmapTypeInfo = new BeatmapTypeInfo(),
|
2018-04-13 17:19:50 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Padding = contentPadding,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
participantInfo = new ParticipantInfo(@"Rank Range "),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
participantsScroll = new OsuScrollContainer
|
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Padding = new MarginPadding { Top = contentPadding.Top, Left = 38, Right = 37 },
|
|
|
|
Children = new[]
|
|
|
|
{
|
|
|
|
participantsFlow = new FillFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
LayoutDuration = transition_duration,
|
|
|
|
Spacing = new Vector2(5f),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2018-12-13 17:38:03 +08:00
|
|
|
playlistBind.ItemsAdded += _ => updatePlaylist();
|
|
|
|
playlistBind.ItemsRemoved += _ => updatePlaylist();
|
|
|
|
|
2018-12-10 12:18:03 +08:00
|
|
|
statusBind.BindValueChanged(displayStatus);
|
|
|
|
participantsBind.BindValueChanged(p => participantsFlow.ChildrenEnumerable = p.Select(u => new UserTile(u)));
|
|
|
|
|
|
|
|
nameBind.BindValueChanged(n => name.Text = n);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-12-07 18:38:46 +08:00
|
|
|
participantInfo.Host.BindTo(hostBind);
|
|
|
|
participantInfo.Participants.BindTo(participantsBind);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-12-07 18:38:46 +08:00
|
|
|
participantCount.Participants.BindTo(participantsBind);
|
|
|
|
participantCount.MaxParticipants.BindTo(maxParticipantsBind);
|
|
|
|
|
|
|
|
beatmapTypeInfo.Type.BindTo(typeBind);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-12-11 18:07:40 +08:00
|
|
|
Room.BindValueChanged(updateRoom, true);
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
|
2018-12-11 18:07:40 +08:00
|
|
|
private Room lastRoom;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-12-11 18:07:40 +08:00
|
|
|
private void updateRoom(Room newRoom)
|
2018-05-19 13:23:09 +08:00
|
|
|
{
|
2018-12-11 18:07:40 +08:00
|
|
|
if (lastRoom != null)
|
|
|
|
{
|
|
|
|
nameBind.UnbindFrom(lastRoom.Name);
|
|
|
|
hostBind.UnbindFrom(lastRoom.Host);
|
|
|
|
statusBind.UnbindFrom(lastRoom.Status);
|
|
|
|
typeBind.UnbindFrom(lastRoom.Type);
|
2018-12-13 17:38:03 +08:00
|
|
|
playlistBind.UnbindFrom(lastRoom.Playlist);
|
2018-12-11 18:07:40 +08:00
|
|
|
maxParticipantsBind.UnbindFrom(lastRoom.MaxParticipants);
|
|
|
|
participantsBind.UnbindFrom(lastRoom.Participants);
|
|
|
|
}
|
2018-05-19 13:23:09 +08:00
|
|
|
|
2018-12-11 18:07:40 +08:00
|
|
|
if (newRoom != null)
|
|
|
|
{
|
|
|
|
nameBind.BindTo(newRoom.Name);
|
|
|
|
hostBind.BindTo(newRoom.Host);
|
|
|
|
statusBind.BindTo(newRoom.Status);
|
|
|
|
typeBind.BindTo(newRoom.Type);
|
2018-12-13 17:38:03 +08:00
|
|
|
playlistBind.BindTo(newRoom.Playlist);
|
2018-12-11 18:07:40 +08:00
|
|
|
maxParticipantsBind.BindTo(newRoom.MaxParticipants);
|
|
|
|
participantsBind.BindTo(newRoom.Participants);
|
2018-05-19 13:23:09 +08:00
|
|
|
|
2018-12-11 18:07:40 +08:00
|
|
|
participantsFlow.FadeIn(transition_duration);
|
|
|
|
participantCount.FadeIn(transition_duration);
|
|
|
|
beatmapTypeInfo.FadeIn(transition_duration);
|
|
|
|
name.FadeIn(transition_duration);
|
|
|
|
participantInfo.FadeIn(transition_duration);
|
|
|
|
}
|
|
|
|
else
|
2018-05-19 13:23:09 +08:00
|
|
|
{
|
2018-05-19 13:51:51 +08:00
|
|
|
participantsFlow.FadeOut(transition_duration);
|
2018-05-29 11:51:56 +08:00
|
|
|
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);
|
2018-05-19 13:23:09 +08:00
|
|
|
|
|
|
|
displayStatus(new RoomStatusNoneSelected());
|
|
|
|
}
|
|
|
|
|
2018-12-11 18:07:40 +08:00
|
|
|
lastRoom = newRoom;
|
|
|
|
}
|
|
|
|
|
2018-12-13 17:38:03 +08:00
|
|
|
private void updatePlaylist()
|
|
|
|
{
|
2018-12-14 11:35:05 +08:00
|
|
|
if (playlistBind.Count == 0)
|
|
|
|
return;
|
|
|
|
|
2018-12-13 17:38:03 +08:00
|
|
|
// For now, only the first playlist item is supported
|
|
|
|
var item = playlistBind.First();
|
|
|
|
|
|
|
|
beatmap.Value = beatmaps.GetWorkingBeatmap(item.Beatmap);
|
|
|
|
background.Beatmap.Value = item.Beatmap;
|
|
|
|
beatmapTypeInfo.Beatmap.Value = item.Beatmap;
|
|
|
|
}
|
|
|
|
|
2018-12-11 18:07:40 +08:00
|
|
|
protected override void UpdateAfterChildren()
|
|
|
|
{
|
|
|
|
base.UpdateAfterChildren();
|
|
|
|
|
|
|
|
participantsScroll.Height = DrawHeight - topFlow.DrawHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void displayStatus(RoomStatus s)
|
|
|
|
{
|
|
|
|
status.Text = s.Message;
|
|
|
|
|
|
|
|
Color4 c = s.GetAppropriateColour(colours);
|
|
|
|
statusStrip.FadeColour(c, transition_duration);
|
|
|
|
status.FadeColour(c, transition_duration);
|
2018-05-19 13:23:09 +08:00
|
|
|
}
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
private class UserTile : Container, 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;
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = OsuColour.FromHex(@"27252d"),
|
|
|
|
},
|
|
|
|
new UpdateableAvatar
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
User = user,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2018-05-19 13:23:09 +08:00
|
|
|
|
|
|
|
private class RoomStatusNoneSelected : RoomStatus
|
|
|
|
{
|
|
|
|
public override string Message => @"No Room Selected";
|
|
|
|
public override Color4 GetAppropriateColour(OsuColour colours) => colours.Gray8;
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
}
|