1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-09 02:47:28 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/Lounge/Components/DrawableRoom.cs

565 lines
21 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
2018-05-11 09:48:07 +08:00
using System;
2018-05-22 11:33:41 +08:00
using System.Collections.Generic;
2018-05-11 09:48:07 +08:00
using osu.Framework;
2018-04-13 17:19:50 +08:00
using osu.Framework.Allocation;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
using osu.Framework.Extensions;
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;
using osu.Framework.Graphics.Cursor;
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;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
2018-04-13 17:19:50 +08:00
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
2018-04-13 17:19:50 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
2018-05-11 09:48:07 +08:00
using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Input.Bindings;
using osu.Game.Online.Rooms;
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 : OsuClickableContainer, IStateful<SelectionState>, IFilterable, IHasContextMenu, IHasPopover, IKeyBindingHandler<GlobalAction>
2018-04-13 17:19:50 +08:00
{
2018-05-22 11:07:04 +08:00
public const float SELECTION_BORDER_WIDTH = 4;
2021-07-06 19:04:32 +08:00
private const float corner_radius = 10;
2018-05-28 12:02:15 +08:00
private const float transition_duration = 60;
2021-07-06 19:04:32 +08:00
private const float height = 100;
2018-04-13 17:19:50 +08:00
2021-08-05 20:20:55 +08:00
private static readonly Color4 background_colour = Color4Extensions.FromHex(@"#27302E");
2018-12-04 14:26:06 +08:00
public event Action<SelectionState> StateChanged;
2021-07-06 19:04:32 +08:00
private Drawable selectionBox;
2018-12-13 17:38:03 +08:00
[Resolved(canBeNull: true)]
private LoungeSubScreen loungeScreen { get; set; }
2018-12-06 11:21:30 +08:00
[Resolved]
private BeatmapManager beatmaps { get; set; }
2021-07-12 13:35:08 +08:00
[Resolved(canBeNull: true)]
private Bindable<Room> selectedRoom { get; set; }
[Resolved(canBeNull: true)]
private LoungeSubScreen lounge { get; set; }
2018-04-13 17:19:50 +08:00
public readonly Room Room;
2018-05-11 09:48:07 +08:00
private SelectionState state;
2019-02-28 12:31:40 +08:00
2018-05-11 09:48:07 +08:00
public SelectionState State
{
get => state;
2018-05-11 09:48:07 +08:00
set
{
2021-07-06 17:24:06 +08:00
if (value == state)
return;
2019-02-28 12:31:40 +08:00
2018-05-11 09:48:07 +08:00
state = value;
2021-07-06 17:24:06 +08:00
if (selectionBox != null)
{
if (state == SelectionState.Selected)
selectionBox.FadeIn(transition_duration);
else
selectionBox.FadeOut(transition_duration);
}
2018-05-11 09:48:07 +08:00
StateChanged?.Invoke(State);
}
}
2018-05-22 11:33:41 +08:00
public IEnumerable<string> FilterTerms => new[] { Room.Name.Value };
private bool matchingFilter;
2019-02-28 12:31:40 +08:00
2018-05-22 11:33:41 +08:00
public bool MatchingFilter
{
get => matchingFilter;
2018-05-22 11:33:41 +08:00
set
{
matchingFilter = value;
if (!IsLoaded)
return;
if (matchingFilter)
this.FadeIn(200);
else
Hide();
2018-05-22 11:33:41 +08:00
}
}
2021-08-05 20:02:14 +08:00
private int numberOfAvatars = 7;
2021-07-13 14:10:44 +08:00
public int NumberOfAvatars
{
get => numberOfAvatars;
set
{
numberOfAvatars = value;
if (recentParticipantsList != null)
recentParticipantsList.NumberOfAvatars = value;
}
}
private readonly Bindable<RoomCategory> roomCategory = new Bindable<RoomCategory>();
2021-07-13 14:10:44 +08:00
private RecentParticipantsList recentParticipantsList;
private RoomSpecialCategoryPill specialCategoryPill;
2021-07-13 14:10:44 +08:00
2019-03-28 23:29:07 +08:00
public bool FilteringActive { get; set; }
private PasswordProtectedIcon passwordIcon;
private readonly Bindable<bool> hasPassword = new Bindable<bool>();
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;
2021-07-14 16:46:32 +08:00
CornerRadius = corner_radius + SELECTION_BORDER_WIDTH / 2;
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Colour = Color4.Black.Opacity(40),
Radius = 5,
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
2018-04-13 17:19:50 +08:00
Children = new Drawable[]
{
// This resolves internal 1px gaps due to applying the (parenting) corner radius and masking across multiple filling background sprites.
new BufferedContainer
2018-04-13 17:19:50 +08:00
{
2018-05-11 09:48:07 +08:00
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
2018-04-13 17:19:50 +08:00
{
new Box
{
RelativeSizeAxes = Axes.Both,
2021-08-05 20:20:55 +08:00
Colour = background_colour,
},
2021-08-05 20:01:21 +08:00
new OnlinePlayBackgroundSprite(BeatmapSetCoverType.Cover)
2018-04-13 17:19:50 +08:00
{
RelativeSizeAxes = Axes.Both
2018-04-13 17:19:50 +08:00
},
}
},
new Container
{
Name = @"Room content",
RelativeSizeAxes = Axes.Both,
2021-08-05 20:19:23 +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
{
RelativeSizeAxes = Axes.Both,
Masking = true,
CornerRadius = corner_radius,
Children = new Drawable[]
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 BufferedContainer
2021-07-12 15:30:34 +08:00
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
2021-07-12 13:07:21 +08:00
{
new Box
2021-07-12 13:07:21 +08:00
{
RelativeSizeAxes = Axes.Both,
2021-08-05 20:20:55 +08:00
Colour = background_colour,
},
2021-08-04 12:49:13 +08:00
new OnlinePlayBackgroundSprite(BeatmapSetCoverType.Cover)
{
RelativeSizeAxes = Axes.Both
},
new GridContainer
{
RelativeSizeAxes = Axes.Both,
ColumnDimensions = new[]
2021-07-12 13:07:21 +08:00
{
new Dimension(GridSizeMode.Relative, 0.2f)
},
Content = new[]
{
new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
2021-08-05 20:20:55 +08:00
Colour = background_colour,
},
new Box
{
RelativeSizeAxes = Axes.Both,
2021-08-05 20:20:55 +08:00
Colour = ColourInfo.GradientHorizontal(background_colour, background_colour.Opacity(0.3f))
},
}
}
},
},
},
new Container
{
Name = @"Left details",
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding
{
Left = 20,
Vertical = 5
},
Children = new Drawable[]
{
new FillFlowContainer
2021-07-12 14:11:53 +08:00
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
2021-07-12 14:11:53 +08:00
Children = new Drawable[]
{
new FillFlowContainer
2021-07-12 14:11:53 +08:00
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5),
Children = new Drawable[]
{
new RoomStatusPill
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft
},
specialCategoryPill = new RoomSpecialCategoryPill
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft
},
new EndDateInfo
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft
},
}
2021-07-12 14:11:53 +08:00
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = 3 },
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new RoomNameText(),
new RoomHostText(),
}
}
},
},
new FillFlowContainer
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5),
2018-05-11 09:48:07 +08:00
Children = new Drawable[]
2018-04-13 17:19:50 +08:00
{
new PlaylistCountPill
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
new StarRatingRangeDisplay
2021-07-12 14:11:07 +08:00
{
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
}
}
}
},
new FillFlowContainer
{
Name = "Right content",
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
Padding = new MarginPadding
{
Right = 10,
Vertical = 5
},
Children = new Drawable[]
{
recentParticipantsList = new RecentParticipantsList
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
NumberOfAvatars = NumberOfAvatars
}
}
2018-04-13 17:19:50 +08:00
},
passwordIcon = new PasswordProtectedIcon { Alpha = 0 }
2018-04-13 17:19:50 +08:00
},
},
2018-04-13 17:19:50 +08:00
},
2021-07-06 19:04:32 +08:00
new StatusColouredContainer(transition_duration)
{
RelativeSizeAxes = Axes.Both,
Child = selectionBox = new Container
{
RelativeSizeAxes = Axes.Both,
Alpha = state == SelectionState.Selected ? 1 : 0,
Masking = true,
CornerRadius = corner_radius,
BorderThickness = SELECTION_BORDER_WIDTH,
BorderColour = Color4.White,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
AlwaysPresent = true
}
}
},
2018-04-13 17:19:50 +08:00
};
}
2018-05-22 11:07:04 +08:00
2019-02-05 18:00:01 +08:00
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
return new CachedModelDependencyContainer<Room>(base.CreateChildDependencies(parent))
{
Model = { Value = Room }
};
2019-02-05 18:00:01 +08:00
}
protected override void LoadComplete()
{
base.LoadComplete();
if (matchingFilter)
this.FadeInFromZero(transition_duration);
else
Alpha = 0;
roomCategory.BindTo(Room.Category);
roomCategory.BindValueChanged(c =>
{
if (c.NewValue == RoomCategory.Spotlight)
specialCategoryPill.Show();
else
specialCategoryPill.Hide();
}, true);
hasPassword.BindTo(Room.HasPassword);
hasPassword.BindValueChanged(v => passwordIcon.Alpha = v.NewValue ? 1 : 0, true);
}
2019-02-06 12:52:48 +08:00
public Popover GetPopover() => new PasswordEntryPopover(Room) { JoinRequested = lounge.Join };
public MenuItem[] ContextMenuItems => new MenuItem[]
{
new OsuMenuItem("Create copy", MenuItemType.Standard, () =>
{
lounge?.Open(Room.DeepClone());
})
};
public bool OnPressed(GlobalAction action)
{
if (selectedRoom.Value != Room)
return false;
switch (action)
{
case GlobalAction.Select:
2021-08-04 16:27:44 +08:00
TriggerClick();
return true;
}
return false;
}
public void OnReleased(GlobalAction action)
{
}
2019-02-06 12:52:48 +08:00
protected override bool ShouldBeConsideredForInput(Drawable child) => state == SelectionState.Selected;
protected override bool OnClick(ClickEvent e)
{
if (Room != selectedRoom.Value)
{
selectedRoom.Value = Room;
return true;
}
if (Room.HasPassword.Value)
{
this.ShowPopover();
return true;
}
lounge?.Join(Room, null);
return base.OnClick(e);
}
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-07-12 15:28:22 +08:00
private class RoomHostText : OnlinePlayComposite
{
private LinkFlowContainer hostText;
public RoomHostText()
{
AutoSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load()
{
InternalChild = hostText = new LinkFlowContainer(s => s.Font = OsuFont.GetFont(size: 16))
2021-07-12 15:28:22 +08:00
{
AutoSizeAxes = Axes.Both
};
}
protected override void LoadComplete()
{
base.LoadComplete();
Host.BindValueChanged(host =>
{
hostText.Clear();
if (host.NewValue != null)
{
hostText.AddText("hosted by ");
hostText.AddUserLink(host.NewValue);
}
}, true);
}
}
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),
}
};
}
}
public class PasswordEntryPopover : OsuPopover
{
2021-07-12 17:29:50 +08:00
private readonly Room room;
public Action<Room, string> JoinRequested;
public PasswordEntryPopover(Room room)
2021-07-12 17:29:50 +08:00
{
this.room = room;
}
private OsuPasswordTextBox passwordTextbox;
2021-07-12 17:29:50 +08:00
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
2021-07-12 17:29:50 +08:00
Child = new FillFlowContainer
{
2021-07-12 17:29:50 +08:00
Margin = new MarginPadding(10),
Spacing = new Vector2(5),
AutoSizeAxes = Axes.Both,
2021-07-12 17:29:50 +08:00
Direction = FillDirection.Horizontal,
Children = new Drawable[]
{
2021-07-12 17:29:50 +08:00
passwordTextbox = new OsuPasswordTextBox
{
2021-07-12 17:29:50 +08:00
Width = 200,
},
2021-07-12 17:29:50 +08:00
new TriangleButton
{
2021-07-12 17:29:50 +08:00
Width = 80,
Text = "Join Room",
Action = () => JoinRequested?.Invoke(room, passwordTextbox.Text)
2021-07-12 17:29:50 +08:00
}
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
Schedule(() => GetContainingInputManager().ChangeFocus(passwordTextbox));
passwordTextbox.OnCommit += (_, __) => JoinRequested?.Invoke(room, passwordTextbox.Text);
}
}
2018-04-13 17:19:50 +08:00
}
}