1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-17 05:22:54 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/Lounge/Components/DrawableRoom.cs

428 lines
18 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 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;
2021-07-06 19:04:32 +08:00
using osu.Framework.Graphics.Colour;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics.Containers;
2021-07-14 16:46:32 +08:00
using osu.Framework.Graphics.Effects;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
2018-04-13 17:19:50 +08:00
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
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
2018-04-13 17:19:50 +08:00
{
public class DrawableRoom : CompositeDrawable
2018-04-13 17:19:50 +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;
2018-12-06 11:21:30 +08:00
[Resolved]
private BeatmapManager beatmaps { get; set; }
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;
2018-04-13 17:19:50 +08:00
public DrawableRoom(Room room)
{
Room = room;
RelativeSizeAxes = Axes.X;
2021-07-12 13:07:21 +08:00
Height = height;
2021-07-14 16:46:32 +08:00
2018-04-13 17:19:50 +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[]
2018-04-13 17:19:50 +08:00
{
// This resolves internal 1px gaps due to applying the (parenting) corner radius and masking across multiple filling background sprites.
new Box
2018-04-13 17:19:50 +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
2018-04-13 17:19:50 +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
2018-04-13 17:19:50 +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),
Children = new Drawable[]
2021-07-12 14:11:07 +08:00
{
2021-09-08 16:13:12 +08:00
new PlaylistCountPill
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
new StarRatingRangeDisplay
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Scale = new Vector2(0.8f)
}
2021-07-12 14:11:07 +08:00
}
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 }
2018-04-13 17:19:50 +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 =>
{
if (c.NewValue == RoomCategory.Spotlight)
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-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
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,
AutoSizeAxes = Axes.Y
}
}
}
2021-07-12 15:28:22 +08:00
};
}
protected override void LoadComplete()
{
base.LoadComplete();
2021-09-29 19:24:49 +08:00
SelectedItem.BindValueChanged(onSelectedItemChanged, true);
}
2021-07-12 15:28:22 +08:00
2021-09-29 19:24:49 +08:00
private void onSelectedItemChanged(ValueChangedEvent<PlaylistItem> item)
{
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
2021-09-29 19:24:49 +08:00
if (item.NewValue?.Beatmap.Value != null)
{
2021-09-29 19:44:38 +08:00
statusText.Text = "Currently playing ";
beatmapText.AddLink(item.NewValue.Beatmap.Value.GetDisplayTitleRomanisable(),
2021-09-29 19:44:38 +08:00
LinkAction.OpenBeatmap,
item.NewValue.Beatmap.Value.OnlineBeatmapID.ToString(),
creationParameters: s =>
{
s.Truncate = true;
s.RelativeSizeAxes = Axes.X;
});
2021-09-29 19:24:49 +08:00
}
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),
}
};
}
}
2018-04-13 17:19:50 +08:00
}
}