2021-08-18 11:53:17 +00:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Audio.Sample;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Extensions;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
using osu.Framework.Input.Bindings;
|
|
|
|
using osu.Framework.Input.Events;
|
2021-09-14 05:44:32 +00:00
|
|
|
using osu.Game.Extensions;
|
2021-09-14 05:10:55 +00:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2021-08-18 11:53:17 +00: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;
|
|
|
|
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.OnlinePlay.Lounge
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// A <see cref="DrawableRoom"/> with lounge-specific interactions such as selection and hover sounds.
|
|
|
|
/// </summary>
|
|
|
|
public class DrawableLoungeRoom : DrawableRoom, IFilterable, IHasContextMenu, IHasPopover, IKeyBindingHandler<GlobalAction>
|
|
|
|
{
|
|
|
|
private const float transition_duration = 60;
|
|
|
|
private const float selection_border_width = 4;
|
|
|
|
|
2021-08-19 07:49:08 +00:00
|
|
|
public readonly Bindable<Room> SelectedRoom = new Bindable<Room>();
|
2021-08-18 11:53:17 +00:00
|
|
|
|
|
|
|
[Resolved(canBeNull: true)]
|
2021-08-19 07:49:08 +00:00
|
|
|
private LoungeSubScreen lounge { get; set; }
|
2021-08-18 11:53:17 +00:00
|
|
|
|
|
|
|
private Sample sampleSelect;
|
|
|
|
private Sample sampleJoin;
|
|
|
|
private Drawable selectionBox;
|
|
|
|
|
|
|
|
public DrawableLoungeRoom(Room room)
|
|
|
|
: base(room)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(AudioManager audio)
|
|
|
|
{
|
|
|
|
sampleSelect = audio.Samples.Get($@"UI/{HoverSampleSet.Default.GetDescription()}-select");
|
|
|
|
sampleJoin = audio.Samples.Get($@"UI/{HoverSampleSet.Submit.GetDescription()}-select");
|
|
|
|
|
|
|
|
AddRangeInternal(new Drawable[]
|
|
|
|
{
|
|
|
|
new StatusColouredContainer(transition_duration)
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Child = selectionBox = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2021-08-18 12:09:34 +00:00
|
|
|
Alpha = 0,
|
2021-08-18 11:53:17 +00:00
|
|
|
Masking = true,
|
|
|
|
CornerRadius = CORNER_RADIUS,
|
|
|
|
BorderThickness = selection_border_width,
|
|
|
|
BorderColour = Color4.White,
|
|
|
|
Child = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Alpha = 0,
|
|
|
|
AlwaysPresent = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new HoverSounds()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2021-09-08 08:30:13 +00:00
|
|
|
Alpha = matchingFilter ? 1 : 0;
|
|
|
|
selectionBox.Alpha = SelectedRoom.Value == Room ? 1 : 0;
|
2021-08-18 11:53:17 +00:00
|
|
|
|
2021-09-08 08:30:13 +00:00
|
|
|
SelectedRoom.BindValueChanged(updateSelectedRoom);
|
2021-08-18 11:53:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateSelectedRoom(ValueChangedEvent<Room> selected)
|
|
|
|
{
|
|
|
|
if (selected.NewValue == Room)
|
|
|
|
selectionBox.FadeIn(transition_duration);
|
|
|
|
else
|
|
|
|
selectionBox.FadeOut(transition_duration);
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool FilteringActive { get; set; }
|
|
|
|
|
|
|
|
public IEnumerable<string> FilterTerms => new[] { Room.Name.Value };
|
|
|
|
|
|
|
|
private bool matchingFilter;
|
|
|
|
|
|
|
|
public bool MatchingFilter
|
|
|
|
{
|
|
|
|
get => matchingFilter;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
matchingFilter = value;
|
|
|
|
|
|
|
|
if (!IsLoaded)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (matchingFilter)
|
|
|
|
this.FadeIn(200);
|
|
|
|
else
|
|
|
|
Hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-12 18:36:11 +00:00
|
|
|
public Popover GetPopover() => new PasswordEntryPopover(Room);
|
2021-08-18 11:53:17 +00:00
|
|
|
|
|
|
|
public MenuItem[] ContextMenuItems => new MenuItem[]
|
|
|
|
{
|
|
|
|
new OsuMenuItem("Create copy", MenuItemType.Standard, () =>
|
|
|
|
{
|
|
|
|
lounge?.Open(Room.DeepClone());
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
2021-08-18 11:53:17 +00:00
|
|
|
{
|
2021-08-19 07:49:08 +00:00
|
|
|
if (SelectedRoom.Value != Room)
|
2021-08-18 11:53:17 +00:00
|
|
|
return false;
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
switch (e.Action)
|
2021-08-18 11:53:17 +00:00
|
|
|
{
|
|
|
|
case GlobalAction.Select:
|
|
|
|
TriggerClick();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
|
2021-08-18 11:53:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-08-19 07:49:08 +00:00
|
|
|
protected override bool ShouldBeConsideredForInput(Drawable child) => SelectedRoom.Value == Room || child is HoverSounds;
|
2021-08-18 11:53:17 +00:00
|
|
|
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
{
|
2021-08-19 07:49:08 +00:00
|
|
|
if (Room != SelectedRoom.Value)
|
2021-08-18 11:53:17 +00:00
|
|
|
{
|
|
|
|
sampleSelect?.Play();
|
2021-08-19 07:49:08 +00:00
|
|
|
SelectedRoom.Value = Room;
|
2021-08-18 11:53:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Room.HasPassword.Value)
|
|
|
|
{
|
|
|
|
sampleJoin?.Play();
|
|
|
|
this.ShowPopover();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
sampleJoin?.Play();
|
|
|
|
lounge?.Join(Room, null);
|
2021-08-20 09:14:59 +00:00
|
|
|
return true;
|
2021-08-18 11:53:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public class PasswordEntryPopover : OsuPopover
|
|
|
|
{
|
|
|
|
private readonly Room room;
|
|
|
|
|
2021-09-12 18:36:11 +00:00
|
|
|
[Resolved(canBeNull: true)]
|
|
|
|
private LoungeSubScreen lounge { get; set; }
|
2021-08-18 11:53:17 +00:00
|
|
|
|
|
|
|
public PasswordEntryPopover(Room room)
|
|
|
|
{
|
|
|
|
this.room = room;
|
|
|
|
}
|
|
|
|
|
|
|
|
private OsuPasswordTextBox passwordTextbox;
|
2021-09-07 20:54:21 +00:00
|
|
|
private TriangleButton joinButton;
|
2021-09-14 05:10:55 +00:00
|
|
|
private OsuSpriteText errorText;
|
2021-09-17 11:52:13 +00:00
|
|
|
private Sample sampleJoinFail;
|
2021-08-18 11:53:17 +00:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2021-09-17 11:52:13 +00:00
|
|
|
private void load(OsuColour colours, AudioManager audio)
|
2021-08-18 11:53:17 +00:00
|
|
|
{
|
2021-09-14 05:19:55 +00:00
|
|
|
Child = new FillFlowContainer
|
2021-08-18 11:53:17 +00:00
|
|
|
{
|
|
|
|
Margin = new MarginPadding(10),
|
2021-09-14 05:19:55 +00:00
|
|
|
Spacing = new Vector2(5),
|
2021-08-18 11:53:17 +00:00
|
|
|
AutoSizeAxes = Axes.Both,
|
2021-09-14 05:19:55 +00:00
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Children = new Drawable[]
|
2021-08-18 11:53:17 +00:00
|
|
|
{
|
2021-09-14 05:19:55 +00:00
|
|
|
new FillFlowContainer
|
2021-08-18 11:53:17 +00:00
|
|
|
{
|
2021-09-14 05:19:55 +00:00
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Spacing = new Vector2(5),
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
2021-09-08 00:05:24 +00:00
|
|
|
{
|
2021-09-14 05:19:55 +00:00
|
|
|
passwordTextbox = new OsuPasswordTextBox
|
|
|
|
{
|
|
|
|
Width = 200,
|
|
|
|
PlaceholderText = "password",
|
|
|
|
},
|
|
|
|
joinButton = new TriangleButton
|
2021-09-14 05:10:55 +00:00
|
|
|
{
|
2021-09-14 05:19:55 +00:00
|
|
|
Width = 80,
|
|
|
|
Text = "Join Room",
|
2021-09-14 05:10:55 +00:00
|
|
|
}
|
2021-09-14 05:19:55 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
errorText = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Colour = colours.Red,
|
|
|
|
},
|
2021-08-18 11:53:17 +00:00
|
|
|
}
|
|
|
|
};
|
2021-09-08 00:05:24 +00:00
|
|
|
|
2021-09-17 11:52:13 +00:00
|
|
|
sampleJoinFail = audio.Samples.Get(@"UI/password-fail");
|
|
|
|
|
2021-09-12 18:36:11 +00:00
|
|
|
joinButton.Action = () => lounge?.Join(room, passwordTextbox.Text, null, joinFailed);
|
2021-09-08 00:05:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void joinFailed(string error)
|
|
|
|
{
|
|
|
|
passwordTextbox.Text = string.Empty;
|
|
|
|
|
2021-09-17 09:23:36 +00:00
|
|
|
GetContainingInputManager().ChangeFocus(passwordTextbox);
|
|
|
|
|
2021-09-14 05:10:55 +00:00
|
|
|
errorText.Text = error;
|
2021-09-14 05:44:32 +00:00
|
|
|
errorText
|
|
|
|
.FadeIn()
|
|
|
|
.FlashColour(Color4.White, 200)
|
|
|
|
.Delay(1000)
|
|
|
|
.FadeOutFromOne(1000, Easing.In);
|
|
|
|
|
|
|
|
Body.Shake();
|
2021-09-17 11:52:13 +00:00
|
|
|
|
|
|
|
Schedule(() => { sampleJoinFail?.Play(); });
|
2021-08-18 11:53:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
Schedule(() => GetContainingInputManager().ChangeFocus(passwordTextbox));
|
2021-09-12 18:36:11 +00:00
|
|
|
passwordTextbox.OnCommit += (_, __) => lounge?.Join(room, passwordTextbox.Text, null, joinFailed);
|
2021-08-18 11:53:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|