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
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Configuration;
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2018-05-19 13:23:09 +08:00
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2018-04-13 17:19:50 +08:00
|
|
|
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.Framework.Localisation;
|
|
|
|
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;
|
|
|
|
using osu.Game.Users;
|
2018-05-11 07:44:24 +08:00
|
|
|
using OpenTK;
|
|
|
|
using OpenTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-05-11 07:44:24 +08:00
|
|
|
namespace osu.Game.Screens.Multi.Components
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
public class RoomInspector : Container
|
|
|
|
{
|
|
|
|
private const float transition_duration = 100;
|
|
|
|
|
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<BeatmapInfo> beatmapBind = new Bindable<BeatmapInfo>();
|
|
|
|
private readonly Bindable<int?> maxParticipantsBind = new Bindable<int?>();
|
|
|
|
private readonly Bindable<User[]> participantsBind = new Bindable<User[]>();
|
|
|
|
|
2018-05-19 13:23:09 +08:00
|
|
|
private OsuColour colours;
|
|
|
|
private Box statusStrip;
|
|
|
|
private Container coverContainer;
|
|
|
|
private FillFlowContainer topFlow, participantsFlow, participantNumbersFlow, infoPanelFlow;
|
|
|
|
private OsuSpriteText name, status;
|
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
|
|
|
|
|
|
|
private Room room;
|
|
|
|
public Room Room
|
|
|
|
{
|
|
|
|
get { return room; }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (value == room) return;
|
|
|
|
room = value;
|
|
|
|
|
2018-05-19 13:23:09 +08:00
|
|
|
nameBind.UnbindBindings();
|
|
|
|
hostBind.UnbindBindings();
|
|
|
|
statusBind.UnbindBindings();
|
|
|
|
typeBind.UnbindBindings();
|
|
|
|
beatmapBind.UnbindBindings();
|
|
|
|
maxParticipantsBind.UnbindBindings();
|
|
|
|
participantsBind.UnbindBindings();
|
|
|
|
|
|
|
|
if (Room != null)
|
|
|
|
{
|
|
|
|
nameBind.BindTo(Room.Name);
|
|
|
|
hostBind.BindTo(Room.Host);
|
|
|
|
statusBind.BindTo(Room.Status);
|
|
|
|
typeBind.BindTo(Room.Type);
|
|
|
|
beatmapBind.BindTo(Room.Beatmap);
|
|
|
|
maxParticipantsBind.BindTo(Room.MaxParticipants);
|
|
|
|
participantsBind.BindTo(Room.Participants);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateState();
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public RoomInspector()
|
|
|
|
{
|
2018-05-19 12:26:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours, LocalisationEngine localisation)
|
|
|
|
{
|
2018-05-19 13:23:09 +08:00
|
|
|
this.colours = colours;
|
|
|
|
|
2018-05-19 12:26:39 +08:00
|
|
|
ModeTypeInfo modeTypeInfo;
|
2018-05-19 13:23:09 +08:00
|
|
|
OsuSpriteText participants, participantsSlash, maxParticipants, beatmapTitle, beatmapDash, beatmapArtist, beatmapAuthor;
|
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[]
|
|
|
|
{
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.Black,
|
|
|
|
},
|
|
|
|
coverContainer = new Container
|
|
|
|
{
|
|
|
|
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[]
|
|
|
|
{
|
2018-05-19 13:23:09 +08:00
|
|
|
participantNumbersFlow = new FillFlowContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
LayoutDuration = transition_duration,
|
|
|
|
Children = new[]
|
|
|
|
{
|
|
|
|
participants = new OsuSpriteText
|
|
|
|
{
|
|
|
|
TextSize = 30,
|
|
|
|
Font = @"Exo2.0-Bold"
|
|
|
|
},
|
|
|
|
participantsSlash = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Text = @"/",
|
|
|
|
TextSize = 30,
|
|
|
|
Font = @"Exo2.0-Light"
|
|
|
|
},
|
|
|
|
maxParticipants = new OsuSpriteText
|
|
|
|
{
|
|
|
|
TextSize = 30,
|
|
|
|
Font = @"Exo2.0-Light"
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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-19 13:23:09 +08:00
|
|
|
infoPanelFlow = new FillFlowContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
Height = 30,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
LayoutDuration = transition_duration,
|
|
|
|
Spacing = new Vector2(5f, 0f),
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
modeTypeInfo = new ModeTypeInfo(),
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
Margin = new MarginPadding { Left = 5 },
|
|
|
|
Children = new[]
|
|
|
|
{
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Children = new[]
|
|
|
|
{
|
|
|
|
beatmapTitle = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Font = @"Exo2.0-BoldItalic",
|
|
|
|
},
|
|
|
|
beatmapDash = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Font = @"Exo2.0-BoldItalic",
|
|
|
|
},
|
|
|
|
beatmapArtist = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Font = @"Exo2.0-RegularItalic",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
beatmapAuthor = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
TextSize = 14,
|
2018-05-19 12:26:39 +08:00
|
|
|
Colour = colours.Gray9,
|
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-05-19 12:26:39 +08:00
|
|
|
nameBind.ValueChanged += n => name.Text = n;
|
|
|
|
hostBind.ValueChanged += h => participantInfo.Host = h;
|
|
|
|
typeBind.ValueChanged += t => modeTypeInfo.Type = t;
|
2018-05-19 13:23:09 +08:00
|
|
|
statusBind.ValueChanged += displayStatus;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-05-19 12:26:39 +08:00
|
|
|
beatmapBind.ValueChanged += b =>
|
|
|
|
{
|
|
|
|
modeTypeInfo.Beatmap = b;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-05-19 12:26:39 +08:00
|
|
|
if (b != null)
|
|
|
|
{
|
|
|
|
coverContainer.FadeIn(transition_duration);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-05-19 12:26:39 +08:00
|
|
|
LoadComponentAsync(new BeatmapSetCover(b.BeatmapSet)
|
2018-05-19 13:23:09 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
FillMode = FillMode.Fill,
|
|
|
|
OnLoadComplete = d => d.FadeInFromZero(400, Easing.Out),
|
|
|
|
}, coverContainer.Add);
|
2018-05-19 12:26:39 +08:00
|
|
|
|
|
|
|
beatmapTitle.Current = localisation.GetUnicodePreference(b.Metadata.TitleUnicode, b.Metadata.Title);
|
|
|
|
beatmapDash.Text = @" - ";
|
|
|
|
beatmapArtist.Current = localisation.GetUnicodePreference(b.Metadata.ArtistUnicode, b.Metadata.Artist);
|
|
|
|
beatmapAuthor.Text = $"mapped by {b.Metadata.Author}";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
coverContainer.FadeOut(transition_duration);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-05-19 12:26:39 +08:00
|
|
|
beatmapTitle.Current = null;
|
|
|
|
beatmapArtist.Current = null;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-05-19 12:26:39 +08:00
|
|
|
beatmapTitle.Text = "Changing map";
|
|
|
|
beatmapDash.Text = beatmapArtist.Text = beatmapAuthor.Text = string.Empty;
|
|
|
|
}
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-05-19 12:26:39 +08:00
|
|
|
maxParticipantsBind.ValueChanged += m =>
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2018-05-19 12:26:39 +08:00
|
|
|
if (m == null)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2018-05-19 12:26:39 +08:00
|
|
|
participantsSlash.FadeOut(transition_duration);
|
|
|
|
maxParticipants.FadeOut(transition_duration);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
participantsSlash.FadeIn(transition_duration);
|
|
|
|
maxParticipants.FadeIn(transition_duration);
|
|
|
|
maxParticipants.Text = m.ToString();
|
|
|
|
}
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-05-19 12:26:39 +08:00
|
|
|
participantsBind.ValueChanged += p =>
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2018-05-19 12:26:39 +08:00
|
|
|
participants.Text = p.Length.ToString();
|
|
|
|
participantInfo.Participants = p;
|
|
|
|
participantsFlow.ChildrenEnumerable = p.Select(u => new UserTile(u));
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-05-19 13:23:09 +08:00
|
|
|
updateState();
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
|
2018-05-19 12:26:39 +08:00
|
|
|
protected override void UpdateAfterChildren()
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2018-05-19 12:26:39 +08:00
|
|
|
base.UpdateAfterChildren();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-05-19 12:26:39 +08:00
|
|
|
participantsScroll.Height = DrawHeight - topFlow.DrawHeight;
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
|
2018-05-19 13:23:09 +08:00
|
|
|
private void displayStatus(RoomStatus s)
|
|
|
|
{
|
|
|
|
status.Text = s.Message;
|
|
|
|
|
|
|
|
foreach (Drawable d in new Drawable[] { statusStrip, status })
|
|
|
|
d.FadeColour(s.GetAppropriateColour(colours), transition_duration);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateState()
|
|
|
|
{
|
|
|
|
if (Room == null)
|
|
|
|
{
|
|
|
|
foreach (Drawable d in new Drawable[] { coverContainer, participantsFlow, participantNumbersFlow, infoPanelFlow, name, participantInfo })
|
|
|
|
d.FadeOut(transition_duration);
|
|
|
|
|
|
|
|
displayStatus(new RoomStatusNoneSelected());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
foreach (Drawable d in new Drawable[] { participantsFlow, participantNumbersFlow, infoPanelFlow, name, participantInfo })
|
|
|
|
d.FadeIn(transition_duration);
|
|
|
|
|
|
|
|
statusBind.TriggerChange();
|
|
|
|
beatmapBind.TriggerChange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|