2020-12-22 06:52:47 +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;
|
|
|
|
using System.Collections.Specialized;
|
|
|
|
using Humanizer;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2021-02-22 08:14:00 +00:00
|
|
|
using osu.Framework.Localisation;
|
2020-12-22 06:52:47 +00:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2020-12-25 04:38:11 +00:00
|
|
|
using osu.Game.Online.Rooms;
|
2020-12-22 06:52:47 +00:00
|
|
|
using osu.Game.Overlays;
|
2020-12-25 15:50:00 +00:00
|
|
|
using osu.Game.Screens.OnlinePlay.Match.Components;
|
2020-12-22 06:52:47 +00:00
|
|
|
using osuTK;
|
|
|
|
|
2020-12-25 15:50:00 +00:00
|
|
|
namespace osu.Game.Screens.OnlinePlay.Playlists
|
2020-12-22 06:52:47 +00:00
|
|
|
{
|
2021-08-17 08:14:21 +00:00
|
|
|
public class PlaylistsRoomSettingsOverlay : RoomSettingsOverlay
|
2020-12-22 06:52:47 +00:00
|
|
|
{
|
|
|
|
public Action EditPlaylist;
|
|
|
|
|
2021-08-05 05:00:35 +00:00
|
|
|
private MatchSettings settings;
|
|
|
|
|
|
|
|
protected override OsuButton SubmitButton => settings.ApplyButton;
|
|
|
|
|
2021-08-05 05:14:07 +00:00
|
|
|
protected override bool IsLoading => settings.IsLoading; // should probably be replaced with an OngoingOperationTracker.
|
|
|
|
|
2021-08-19 07:40:27 +00:00
|
|
|
public PlaylistsRoomSettingsOverlay(Room room)
|
|
|
|
: base(room)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-08-05 05:21:51 +00:00
|
|
|
protected override void SelectBeatmap() => settings.SelectBeatmap();
|
2021-08-05 05:00:35 +00:00
|
|
|
|
2021-08-19 07:40:27 +00:00
|
|
|
protected override OnlinePlayComposite CreateSettings(Room room) => settings = new MatchSettings(room)
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
RelativePositionAxes = Axes.Y,
|
|
|
|
EditPlaylist = () => EditPlaylist?.Invoke()
|
|
|
|
};
|
2020-12-22 06:52:47 +00:00
|
|
|
|
2020-12-25 16:12:33 +00:00
|
|
|
protected class MatchSettings : OnlinePlayComposite
|
2020-12-22 06:52:47 +00:00
|
|
|
{
|
|
|
|
private const float disabled_alpha = 0.2f;
|
|
|
|
|
|
|
|
public Action EditPlaylist;
|
|
|
|
|
2021-02-02 08:57:23 +00:00
|
|
|
public OsuTextBox NameField, MaxParticipantsField, MaxAttemptsField;
|
2020-12-22 06:52:47 +00:00
|
|
|
public OsuDropdown<TimeSpan> DurationField;
|
|
|
|
public RoomAvailabilityPicker AvailabilityPicker;
|
|
|
|
public TriangleButton ApplyButton;
|
|
|
|
|
2021-08-05 05:14:07 +00:00
|
|
|
public bool IsLoading => loadingLayer.State.Value == Visibility.Visible;
|
|
|
|
|
2020-12-22 06:52:47 +00:00
|
|
|
public OsuSpriteText ErrorText;
|
|
|
|
|
|
|
|
private LoadingLayer loadingLayer;
|
|
|
|
private DrawableRoomPlaylist playlist;
|
|
|
|
private OsuSpriteText playlistLength;
|
|
|
|
|
2021-08-05 05:21:51 +00:00
|
|
|
private PurpleTriangleButton editPlaylistButton;
|
|
|
|
|
2020-12-22 06:52:47 +00:00
|
|
|
[Resolved(CanBeNull = true)]
|
|
|
|
private IRoomManager manager { get; set; }
|
|
|
|
|
2021-08-19 07:40:27 +00:00
|
|
|
private readonly Room room;
|
|
|
|
|
|
|
|
public MatchSettings(Room room)
|
|
|
|
{
|
|
|
|
this.room = room;
|
|
|
|
}
|
2020-12-22 06:52:47 +00:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2021-10-13 20:50:19 +00:00
|
|
|
private void load(OverlayColourProvider colourProvider, OsuColour colours)
|
2020-12-22 06:52:47 +00:00
|
|
|
{
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
2021-01-04 13:42:39 +00:00
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2021-10-13 20:50:19 +00:00
|
|
|
Colour = colourProvider.Background4
|
2021-01-04 13:42:39 +00:00
|
|
|
},
|
|
|
|
new GridContainer
|
2020-12-22 06:52:47 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2021-01-04 13:42:39 +00:00
|
|
|
RowDimensions = new[]
|
2020-12-22 06:52:47 +00:00
|
|
|
{
|
2021-07-05 15:52:39 +00:00
|
|
|
new Dimension(),
|
2021-01-04 13:42:39 +00:00
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
},
|
|
|
|
Content = new[]
|
|
|
|
{
|
|
|
|
new Drawable[]
|
2020-12-22 06:52:47 +00:00
|
|
|
{
|
2021-01-04 13:42:39 +00:00
|
|
|
new OsuScrollContainer
|
2020-12-22 06:52:47 +00:00
|
|
|
{
|
2021-01-04 13:42:39 +00:00
|
|
|
Padding = new MarginPadding
|
2020-12-22 06:52:47 +00:00
|
|
|
{
|
2021-01-04 13:42:39 +00:00
|
|
|
Horizontal = OsuScreen.HORIZONTAL_OVERFLOW_PADDING,
|
|
|
|
Vertical = 10
|
|
|
|
},
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new[]
|
|
|
|
{
|
|
|
|
new Container
|
2020-12-22 06:52:47 +00:00
|
|
|
{
|
2021-01-04 13:42:39 +00:00
|
|
|
Padding = new MarginPadding { Horizontal = WaveOverlayContainer.WIDTH_PADDING },
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Children = new Drawable[]
|
2020-12-22 06:52:47 +00:00
|
|
|
{
|
2021-01-04 13:42:39 +00:00
|
|
|
new SectionContainer
|
2020-12-22 06:52:47 +00:00
|
|
|
{
|
2021-01-04 13:42:39 +00:00
|
|
|
Padding = new MarginPadding { Right = FIELD_PADDING / 2 },
|
|
|
|
Children = new[]
|
2020-12-22 06:52:47 +00:00
|
|
|
{
|
2021-01-04 13:42:39 +00:00
|
|
|
new Section("Room name")
|
2020-12-22 06:52:47 +00:00
|
|
|
{
|
2021-01-04 13:42:39 +00:00
|
|
|
Child = NameField = new SettingsTextBox
|
2020-12-22 06:52:47 +00:00
|
|
|
{
|
2021-01-04 13:42:39 +00:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
TabbableContentContainer = this,
|
|
|
|
LengthLimit = 100
|
|
|
|
},
|
|
|
|
},
|
|
|
|
new Section("Duration")
|
|
|
|
{
|
|
|
|
Child = DurationField = new DurationDropdown
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Items = new[]
|
2020-12-22 06:52:47 +00:00
|
|
|
{
|
2021-01-04 13:42:39 +00:00
|
|
|
TimeSpan.FromMinutes(30),
|
|
|
|
TimeSpan.FromHours(1),
|
|
|
|
TimeSpan.FromHours(2),
|
|
|
|
TimeSpan.FromHours(4),
|
|
|
|
TimeSpan.FromHours(8),
|
|
|
|
TimeSpan.FromHours(12),
|
|
|
|
//TimeSpan.FromHours(16),
|
|
|
|
TimeSpan.FromHours(24),
|
|
|
|
TimeSpan.FromDays(3),
|
|
|
|
TimeSpan.FromDays(7)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2021-02-02 08:57:23 +00:00
|
|
|
new Section("Allowed attempts (across all playlist items)")
|
2021-01-04 13:42:39 +00:00
|
|
|
{
|
2021-02-02 08:57:23 +00:00
|
|
|
Child = MaxAttemptsField = new SettingsNumberTextBox
|
2021-01-04 13:42:39 +00:00
|
|
|
{
|
2021-02-02 08:57:23 +00:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
TabbableContentContainer = this,
|
|
|
|
PlaceholderText = "Unlimited",
|
2021-01-04 13:42:39 +00:00
|
|
|
},
|
|
|
|
},
|
2021-02-02 08:57:23 +00:00
|
|
|
new Section("Room visibility")
|
2021-01-04 13:42:39 +00:00
|
|
|
{
|
|
|
|
Alpha = disabled_alpha,
|
2021-02-02 08:57:23 +00:00
|
|
|
Child = AvailabilityPicker = new RoomAvailabilityPicker
|
2021-01-04 13:42:39 +00:00
|
|
|
{
|
2021-02-02 08:57:23 +00:00
|
|
|
Enabled = { Value = false }
|
2020-12-22 06:52:47 +00:00
|
|
|
},
|
|
|
|
},
|
2021-01-04 13:42:39 +00:00
|
|
|
new Section("Max participants")
|
|
|
|
{
|
|
|
|
Alpha = disabled_alpha,
|
|
|
|
Child = MaxParticipantsField = new SettingsNumberTextBox
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
TabbableContentContainer = this,
|
|
|
|
ReadOnly = true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
new Section("Password (optional)")
|
2020-12-22 06:52:47 +00:00
|
|
|
{
|
2021-01-04 13:42:39 +00:00
|
|
|
Alpha = disabled_alpha,
|
|
|
|
Child = new SettingsPasswordTextBox
|
2020-12-22 06:52:47 +00:00
|
|
|
{
|
2021-01-04 13:42:39 +00:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
TabbableContentContainer = this,
|
|
|
|
ReadOnly = true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
new SectionContainer
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
Padding = new MarginPadding { Left = FIELD_PADDING / 2 },
|
|
|
|
Children = new[]
|
|
|
|
{
|
|
|
|
new Section("Playlist")
|
|
|
|
{
|
|
|
|
Child = new GridContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2021-08-18 08:28:20 +00:00
|
|
|
Height = 448,
|
2021-01-04 13:42:39 +00:00
|
|
|
Content = new[]
|
2020-12-22 06:52:47 +00:00
|
|
|
{
|
2021-01-04 13:42:39 +00:00
|
|
|
new Drawable[]
|
2020-12-22 06:52:47 +00:00
|
|
|
{
|
2021-01-04 13:42:39 +00:00
|
|
|
playlist = new DrawableRoomPlaylist(true, true) { RelativeSizeAxes = Axes.Both }
|
|
|
|
},
|
|
|
|
new Drawable[]
|
|
|
|
{
|
|
|
|
playlistLength = new OsuSpriteText
|
2020-12-22 06:52:47 +00:00
|
|
|
{
|
2021-01-04 13:42:39 +00:00
|
|
|
Margin = new MarginPadding { Vertical = 5 },
|
|
|
|
Colour = colours.Yellow,
|
|
|
|
Font = OsuFont.GetFont(size: 12),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new Drawable[]
|
|
|
|
{
|
2021-08-05 05:21:51 +00:00
|
|
|
editPlaylistButton = new PurpleTriangleButton
|
2020-12-22 06:52:47 +00:00
|
|
|
{
|
2021-01-04 13:42:39 +00:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Height = 40,
|
|
|
|
Text = "Edit playlist",
|
|
|
|
Action = () => EditPlaylist?.Invoke()
|
2020-12-22 06:52:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2021-01-04 13:42:39 +00:00
|
|
|
RowDimensions = new[]
|
|
|
|
{
|
|
|
|
new Dimension(),
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
}
|
|
|
|
}
|
2020-12-22 06:52:47 +00:00
|
|
|
},
|
|
|
|
},
|
2021-01-04 13:42:39 +00:00
|
|
|
},
|
2020-12-22 06:52:47 +00:00
|
|
|
},
|
2021-01-04 13:42:39 +00:00
|
|
|
}
|
2020-12-22 06:52:47 +00:00
|
|
|
},
|
2021-01-04 13:42:39 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
new Drawable[]
|
|
|
|
{
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
Y = 2,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Children = new Drawable[]
|
2020-12-22 06:52:47 +00:00
|
|
|
{
|
2021-01-04 13:42:39 +00:00
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2021-10-13 20:50:19 +00:00
|
|
|
Colour = colourProvider.Background5
|
2021-01-04 13:42:39 +00:00
|
|
|
},
|
|
|
|
new FillFlowContainer
|
2020-12-22 06:52:47 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2021-01-04 13:42:39 +00:00
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Spacing = new Vector2(0, 20),
|
|
|
|
Margin = new MarginPadding { Vertical = 20 },
|
|
|
|
Padding = new MarginPadding { Horizontal = OsuScreen.HORIZONTAL_OVERFLOW_PADDING },
|
2020-12-22 06:52:47 +00:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2021-01-04 13:42:39 +00:00
|
|
|
ApplyButton = new CreateRoomButton
|
2020-12-22 06:52:47 +00:00
|
|
|
{
|
2021-01-04 13:42:39 +00:00
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
Size = new Vector2(230, 55),
|
|
|
|
Enabled = { Value = false },
|
|
|
|
Action = apply,
|
2020-12-22 06:52:47 +00:00
|
|
|
},
|
2021-01-04 13:42:39 +00:00
|
|
|
ErrorText = new OsuSpriteText
|
2020-12-22 06:52:47 +00:00
|
|
|
{
|
2021-01-04 13:42:39 +00:00
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
Alpha = 0,
|
|
|
|
Depth = 1,
|
|
|
|
Colour = colours.RedDark
|
2020-12-22 06:52:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-04 13:42:39 +00:00
|
|
|
}
|
2020-12-22 06:52:47 +00:00
|
|
|
}
|
|
|
|
},
|
2021-01-04 13:42:39 +00:00
|
|
|
loadingLayer = new LoadingLayer(true)
|
2020-12-22 06:52:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
RoomName.BindValueChanged(name => NameField.Text = name.NewValue, true);
|
|
|
|
Availability.BindValueChanged(availability => AvailabilityPicker.Current.Value = availability.NewValue, true);
|
|
|
|
MaxParticipants.BindValueChanged(count => MaxParticipantsField.Text = count.NewValue?.ToString(), true);
|
2021-02-03 13:02:40 +00:00
|
|
|
MaxAttempts.BindValueChanged(count => MaxAttemptsField.Text = count.NewValue?.ToString(), true);
|
2020-12-22 06:52:47 +00:00
|
|
|
Duration.BindValueChanged(duration => DurationField.Current.Value = duration.NewValue ?? TimeSpan.FromMinutes(30), true);
|
|
|
|
|
|
|
|
playlist.Items.BindTo(Playlist);
|
|
|
|
Playlist.BindCollectionChanged(onPlaylistChanged, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
ApplyButton.Enabled.Value = hasValidSettings;
|
|
|
|
}
|
|
|
|
|
2021-08-05 05:21:51 +00:00
|
|
|
public void SelectBeatmap() => editPlaylistButton.TriggerClick();
|
|
|
|
|
2020-12-22 06:52:47 +00:00
|
|
|
private void onPlaylistChanged(object sender, NotifyCollectionChangedEventArgs e) =>
|
|
|
|
playlistLength.Text = $"Length: {Playlist.GetTotalDuration()}";
|
|
|
|
|
|
|
|
private bool hasValidSettings => RoomID.Value == null && NameField.Text.Length > 0 && Playlist.Count > 0;
|
|
|
|
|
|
|
|
private void apply()
|
|
|
|
{
|
|
|
|
if (!ApplyButton.Enabled.Value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
hideError();
|
|
|
|
|
|
|
|
RoomName.Value = NameField.Text;
|
|
|
|
Availability.Value = AvailabilityPicker.Current.Value;
|
|
|
|
|
|
|
|
if (int.TryParse(MaxParticipantsField.Text, out int max))
|
|
|
|
MaxParticipants.Value = max;
|
|
|
|
else
|
|
|
|
MaxParticipants.Value = null;
|
|
|
|
|
2021-02-02 08:57:23 +00:00
|
|
|
if (int.TryParse(MaxAttemptsField.Text, out max))
|
|
|
|
MaxAttempts.Value = max;
|
|
|
|
else
|
|
|
|
MaxAttempts.Value = null;
|
|
|
|
|
2020-12-22 06:52:47 +00:00
|
|
|
Duration.Value = DurationField.Current.Value;
|
|
|
|
|
2021-08-19 07:40:27 +00:00
|
|
|
manager?.CreateRoom(room, onSuccess, onError);
|
2020-12-22 06:52:47 +00:00
|
|
|
|
|
|
|
loadingLayer.Show();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void hideError() => ErrorText.FadeOut(50);
|
|
|
|
|
|
|
|
private void onSuccess(Room room) => loadingLayer.Hide();
|
|
|
|
|
|
|
|
private void onError(string text)
|
|
|
|
{
|
|
|
|
ErrorText.Text = text;
|
|
|
|
ErrorText.FadeIn(50);
|
|
|
|
|
|
|
|
loadingLayer.Hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class CreateRoomButton : TriangleButton
|
|
|
|
{
|
|
|
|
public CreateRoomButton()
|
|
|
|
{
|
|
|
|
Text = "Create";
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
{
|
|
|
|
BackgroundColour = colours.Yellow;
|
|
|
|
Triangles.ColourLight = colours.YellowLight;
|
|
|
|
Triangles.ColourDark = colours.YellowDark;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class DurationDropdown : OsuDropdown<TimeSpan>
|
|
|
|
{
|
|
|
|
public DurationDropdown()
|
|
|
|
{
|
|
|
|
Menu.MaxHeight = 100;
|
|
|
|
}
|
|
|
|
|
2021-02-22 08:14:00 +00:00
|
|
|
protected override LocalisableString GenerateItemText(TimeSpan item) => item.Humanize();
|
2020-12-22 06:52:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|