1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 10:22:56 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/Lounge/Components/DrawableRoom.cs

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

471 lines
19 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
2022-06-17 15:37:17 +08:00
#nullable disable
using System.Collections.Generic;
using System.Threading;
2017-05-22 11:07:15 +08:00
using osu.Framework.Allocation;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
using osu.Framework.Extensions;
2017-05-22 11:07:15 +08:00
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
2021-07-06 19:04:32 +08:00
using osu.Framework.Graphics.Colour;
2017-05-22 11:07:15 +08:00
using osu.Framework.Graphics.Containers;
2021-07-14 16:46:32 +08:00
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
2017-07-26 12:22:46 +08:00
using osu.Game.Beatmaps;
using osu.Game.Database;
2017-05-22 11:07:15 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
2017-05-22 11:07:15 +08:00
using osu.Game.Graphics.Sprites;
2021-09-29 19:24:49 +08:00
using osu.Game.Online.Chat;
using osu.Game.Online.Rooms;
using osu.Game.Overlays;
using osu.Game.Screens.OnlinePlay.Components;
2018-11-20 15:51:59 +08:00
using osuTK;
using osuTK.Graphics;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Screens.OnlinePlay.Lounge.Components
2017-05-22 11:07:15 +08:00
{
public class DrawableRoom : CompositeDrawable
2017-05-22 11:07:15 +08:00
{
protected const float CORNER_RADIUS = 10;
2021-07-06 19:04:32 +08:00
private const float height = 100;
2018-04-13 17:19:50 +08:00
public readonly Room Room;
protected Container ButtonsContainer { get; private set; }
2021-08-18 14:12:16 +08:00
private readonly Bindable<MatchType> roomType = new Bindable<MatchType>();
private readonly Bindable<RoomCategory> roomCategory = new Bindable<RoomCategory>();
2021-08-18 14:12:16 +08:00
private readonly Bindable<bool> hasPassword = new Bindable<bool>();
private DrawableRoomParticipantsList drawableRoomParticipantsList;
private RoomSpecialCategoryPill specialCategoryPill;
private PasswordProtectedIcon passwordIcon;
private EndDateInfo endDateInfo;
2021-09-08 16:13:12 +08:00
private DelayedLoadWrapper wrapper;
2017-05-22 23:44:58 +08:00
public DrawableRoom(Room room)
2017-05-22 11:07:15 +08:00
{
2017-05-23 00:05:18 +08:00
Room = room;
2018-04-13 17:19:50 +08:00
2017-05-22 11:07:15 +08:00
RelativeSizeAxes = Axes.X;
2021-07-12 13:07:21 +08:00
Height = height;
2021-07-14 16:46:32 +08:00
2017-05-22 11:07:15 +08:00
Masking = true;
CornerRadius = CORNER_RADIUS;
2021-07-14 16:46:32 +08:00
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Colour = Color4.Black.Opacity(40),
Radius = 5,
};
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colours)
{
2021-09-08 23:39:54 +08:00
ButtonsContainer = new Container
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X
};
2021-08-19 14:52:51 +08:00
InternalChildren = new[]
2017-05-22 11:07:15 +08:00
{
// This resolves internal 1px gaps due to applying the (parenting) corner radius and masking across multiple filling background sprites.
new Box
2017-05-22 12:01:55 +08:00
{
2018-05-11 09:48:07 +08:00
RelativeSizeAxes = Axes.Both,
Colour = colours.Background5,
},
2021-08-19 14:52:51 +08:00
CreateBackground().With(d =>
{
2021-08-19 14:52:51 +08:00
d.RelativeSizeAxes = Axes.Both;
}),
2021-09-08 16:13:12 +08:00
wrapper = new DelayedLoadWrapper(() =>
new Container
{
2021-09-08 16:13:12 +08:00
Name = @"Room content",
RelativeSizeAxes = Axes.Both,
2021-09-08 16:13:12 +08:00
// This negative padding resolves 1px gaps between this background and the background above.
Padding = new MarginPadding { Left = 20, Vertical = -0.5f },
Child = new Container
2017-05-22 11:07:15 +08:00
{
2021-09-08 16:13:12 +08:00
RelativeSizeAxes = Axes.Both,
Masking = true,
CornerRadius = CORNER_RADIUS,
Children = new Drawable[]
2021-07-12 15:30:34 +08:00
{
2021-09-08 16:13:12 +08:00
new GridContainer
2021-07-12 13:07:21 +08:00
{
2021-09-08 16:13:12 +08:00
RelativeSizeAxes = Axes.Both,
ColumnDimensions = new[]
{
2021-09-08 16:13:12 +08:00
new Dimension(GridSizeMode.Relative, 0.2f)
},
Content = new[]
{
new Drawable[]
{
2021-09-08 16:13:12 +08:00
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colours.Background5,
},
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = ColourInfo.GradientHorizontal(colours.Background5, colours.Background5.Opacity(0.3f))
},
}
}
},
2021-09-08 16:13:12 +08:00
new Container
{
2021-09-08 16:13:12 +08:00
Name = @"Left details",
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding
2021-07-12 14:11:53 +08:00
{
2021-09-08 16:13:12 +08:00
Left = 20,
Vertical = 5
},
Children = new Drawable[]
{
new FillFlowContainer
2021-07-12 14:11:53 +08:00
{
2021-09-29 19:44:38 +08:00
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
2021-09-08 16:13:12 +08:00
Direction = FillDirection.Vertical,
Children = new Drawable[]
2021-07-12 14:11:53 +08:00
{
2021-09-08 16:13:12 +08:00
new FillFlowContainer
{
2021-09-08 16:13:12 +08:00
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5),
Children = new Drawable[]
{
2021-09-08 16:13:12 +08:00
new RoomStatusPill
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft
},
specialCategoryPill = new RoomSpecialCategoryPill
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft
},
endDateInfo = new EndDateInfo
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
}
},
new FillFlowContainer
{
2021-09-29 19:44:38 +08:00
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
2021-09-08 16:13:12 +08:00
Padding = new MarginPadding { Top = 3 },
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
2021-09-08 16:13:12 +08:00
new RoomNameText(),
2021-09-29 19:24:49 +08:00
new RoomStatusText()
2021-09-08 16:13:12 +08:00
}
}
2021-07-12 14:11:53 +08:00
},
},
2021-09-08 16:13:12 +08:00
new FillFlowContainer
2017-05-22 11:07:15 +08:00
{
2021-09-08 16:13:12 +08:00
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5),
ChildrenEnumerable = CreateBottomDetails()
2021-07-06 19:04:32 +08:00
}
}
},
2021-09-08 16:13:12 +08:00
new FillFlowContainer
{
2021-09-08 16:13:12 +08:00
Name = "Right content",
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
Spacing = new Vector2(5),
Padding = new MarginPadding
{
2021-09-08 16:13:12 +08:00
Right = 10,
Vertical = 20,
},
2021-09-08 16:13:12 +08:00
Children = new Drawable[]
{
2021-09-08 23:39:54 +08:00
ButtonsContainer,
drawableRoomParticipantsList = new DrawableRoomParticipantsList
2021-09-08 16:13:12 +08:00
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
NumberOfCircles = NumberOfAvatars
}
}
2021-09-08 16:13:12 +08:00
},
passwordIcon = new PasswordProtectedIcon { Alpha = 0 }
2017-05-22 11:07:15 +08:00
},
},
2021-09-08 16:13:12 +08:00
}, 0)
{
RelativeSizeAxes = Axes.Both,
}
};
2019-02-05 18:00:01 +08:00
}
protected override void LoadComplete()
{
base.LoadComplete();
2021-09-08 16:13:12 +08:00
wrapper.DelayedLoadComplete += _ =>
{
wrapper.FadeInFromZero(200);
2021-09-08 16:13:12 +08:00
roomCategory.BindTo(Room.Category);
roomCategory.BindValueChanged(c =>
{
2022-05-27 19:18:46 +08:00
if (c.NewValue > RoomCategory.Normal)
2021-09-08 16:13:12 +08:00
specialCategoryPill.Show();
else
specialCategoryPill.Hide();
}, true);
2021-09-08 16:13:12 +08:00
roomType.BindTo(Room.Type);
roomType.BindValueChanged(t =>
{
endDateInfo.Alpha = t.NewValue == MatchType.Playlists ? 1 : 0;
}, true);
hasPassword.BindTo(Room.HasPassword);
hasPassword.BindValueChanged(v => passwordIcon.Alpha = v.NewValue ? 1 : 0, true);
};
}
2019-02-06 12:52:48 +08:00
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
return new CachedModelDependencyContainer<Room>(base.CreateChildDependencies(parent))
{
Model = { Value = Room }
};
}
2019-02-06 12:52:48 +08:00
private int numberOfAvatars = 7;
public int NumberOfAvatars
{
get => numberOfAvatars;
set
{
numberOfAvatars = value;
if (drawableRoomParticipantsList != null)
drawableRoomParticipantsList.NumberOfCircles = value;
}
}
2021-08-19 14:52:51 +08:00
protected virtual Drawable CreateBackground() => new OnlinePlayBackgroundSprite();
2021-12-07 19:36:39 +08:00
protected virtual IEnumerable<Drawable> CreateBottomDetails()
{
2021-12-07 19:36:39 +08:00
var pills = new List<Drawable>();
if (Room.Type.Value != MatchType.Playlists)
{
2021-12-07 19:36:39 +08:00
pills.AddRange(new OnlinePlayComposite[]
{
new MatchTypePill(),
new QueueModePill(),
});
}
2021-12-07 19:36:39 +08:00
pills.AddRange(new Drawable[]
{
new PlaylistCountPill
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
new StarRatingRangeDisplay
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Scale = new Vector2(0.8f)
}
});
return pills;
}
2021-07-12 15:28:22 +08:00
private class RoomNameText : OsuSpriteText
2019-02-06 12:52:48 +08:00
{
2020-12-25 12:38:11 +08:00
[Resolved(typeof(Room), nameof(Online.Rooms.Room.Name))]
2019-02-06 12:52:48 +08:00
private Bindable<string> name { get; set; }
2021-07-12 15:28:22 +08:00
public RoomNameText()
{
Font = OsuFont.GetFont(size: 28);
2021-07-12 15:28:22 +08:00
}
2019-02-06 12:52:48 +08:00
[BackgroundDependencyLoader]
private void load()
{
Current = name;
}
}
2021-09-29 19:24:49 +08:00
private class RoomStatusText : OnlinePlayComposite
2021-07-12 15:28:22 +08:00
{
2021-09-29 19:24:49 +08:00
[Resolved]
private OsuColour colours { get; set; }
2021-07-12 15:28:22 +08:00
[Resolved]
private BeatmapLookupCache beatmapLookupCache { get; set; }
2021-09-29 19:44:38 +08:00
private SpriteText statusText;
private LinkFlowContainer beatmapText;
2021-09-29 19:24:49 +08:00
public RoomStatusText()
2021-07-12 15:28:22 +08:00
{
2021-09-29 19:44:38 +08:00
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Width = 0.5f;
2021-07-12 15:28:22 +08:00
}
[BackgroundDependencyLoader]
private void load()
{
2021-09-29 19:44:38 +08:00
InternalChild = new GridContainer
2021-09-29 19:24:49 +08:00
{
2021-09-29 19:44:38 +08:00
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
},
2021-09-30 11:01:26 +08:00
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize)
},
2021-09-29 19:44:38 +08:00
Content = new[]
{
new Drawable[]
{
statusText = new OsuSpriteText
{
Font = OsuFont.Default.With(size: 16),
Colour = colours.Lime1
},
beatmapText = new LinkFlowContainer(s =>
{
s.Font = OsuFont.Default.With(size: 16);
s.Colour = colours.Lime1;
})
{
RelativeSizeAxes = Axes.X,
// workaround to ensure only the first line of text shows, emulating truncation (but without ellipsis at the end).
// TODO: remove when text/link flow can support truncation with ellipsis natively.
Height = 16,
Masking = true
2021-09-29 19:44:38 +08:00
}
}
}
2021-07-12 15:28:22 +08:00
};
}
protected override void LoadComplete()
{
base.LoadComplete();
CurrentPlaylistItem.BindValueChanged(onSelectedItemChanged, true);
2021-09-29 19:24:49 +08:00
}
2021-07-12 15:28:22 +08:00
private CancellationTokenSource beatmapLookupCancellation;
2021-09-29 19:24:49 +08:00
private void onSelectedItemChanged(ValueChangedEvent<PlaylistItem> item)
{
beatmapLookupCancellation?.Cancel();
2021-09-29 19:44:38 +08:00
beatmapText.Clear();
2021-09-29 19:24:49 +08:00
if (Type.Value == MatchType.Playlists)
2021-07-12 15:28:22 +08:00
{
statusText.Text = "Ready to play";
2021-09-29 19:24:49 +08:00
return;
}
2021-07-12 15:28:22 +08:00
var beatmap = item.NewValue?.Beatmap;
if (beatmap == null)
return;
var cancellationSource = beatmapLookupCancellation = new CancellationTokenSource();
beatmapLookupCache.GetBeatmapAsync(beatmap.OnlineID, cancellationSource.Token)
.ContinueWith(task => Schedule(() =>
{
if (cancellationSource.IsCancellationRequested)
return;
var retrievedBeatmap = task.GetResultSafely();
statusText.Text = "Currently playing ";
if (retrievedBeatmap != null)
{
beatmapText.AddLink(retrievedBeatmap.GetDisplayTitleRomanisable(),
LinkAction.OpenBeatmap,
retrievedBeatmap.OnlineID.ToString(),
creationParameters: s => s.Truncate = true);
}
else
beatmapText.AddText("unknown beatmap");
}), cancellationSource.Token);
2021-07-12 15:28:22 +08:00
}
}
public class PasswordProtectedIcon : CompositeDrawable
{
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Anchor = Anchor.TopRight;
Origin = Anchor.TopRight;
Size = new Vector2(32);
InternalChildren = new Drawable[]
{
new Box
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopCentre,
Colour = colours.Gray5,
Rotation = 45,
RelativeSizeAxes = Axes.Both,
Width = 2,
},
new SpriteIcon
{
Icon = FontAwesome.Solid.Lock,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Margin = new MarginPadding(6),
Size = new Vector2(14),
}
};
}
}
2017-05-22 11:07:15 +08:00
}
}