2019-01-24 17:43:03 +09: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.
|
2018-05-22 00:07:04 -03:00
|
|
|
|
|
2020-12-29 08:20:43 +01:00
|
|
|
|
using System;
|
2021-08-12 19:48:15 +09:00
|
|
|
|
using System.Collections.Generic;
|
2024-01-15 14:30:27 +09:00
|
|
|
|
using System.Diagnostics;
|
2020-07-09 17:28:22 +09:00
|
|
|
|
using System.Linq;
|
2019-02-08 15:20:11 +09:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 19:04:31 +09:00
|
|
|
|
using osu.Framework.Bindables;
|
2021-07-17 22:31:47 +09:00
|
|
|
|
using osu.Framework.Extensions;
|
2025-03-04 15:29:13 +09:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2018-05-22 00:07:04 -03:00
|
|
|
|
using osu.Framework.Graphics;
|
2025-03-04 15:29:13 +09:00
|
|
|
|
using osu.Framework.Graphics.Colour;
|
2018-05-22 00:07:04 -03:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-08-28 18:47:34 +02:00
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2025-03-04 15:29:13 +09:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2021-08-12 19:48:15 +09:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2018-10-02 12:02:47 +09:00
|
|
|
|
using osu.Framework.Input.Events;
|
2021-08-13 17:39:09 +09:00
|
|
|
|
using osu.Framework.Logging;
|
2018-05-22 00:24:39 -03:00
|
|
|
|
using osu.Framework.Screens;
|
2021-08-12 19:48:15 +09:00
|
|
|
|
using osu.Framework.Threading;
|
2024-01-15 14:30:27 +09:00
|
|
|
|
using osu.Game.Configuration;
|
2018-12-26 21:10:31 +09:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-08-13 17:39:09 +09:00
|
|
|
|
using osu.Game.Input;
|
2022-03-09 15:38:00 +09:00
|
|
|
|
using osu.Game.Online.API;
|
2020-12-25 13:38:11 +09:00
|
|
|
|
using osu.Game.Online.Rooms;
|
2020-07-10 16:33:45 +09:00
|
|
|
|
using osu.Game.Overlays;
|
2021-08-12 19:48:15 +09:00
|
|
|
|
using osu.Game.Rulesets;
|
2020-12-25 16:50:00 +01:00
|
|
|
|
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
|
|
|
|
using osu.Game.Screens.OnlinePlay.Match;
|
2020-11-08 13:21:21 +01:00
|
|
|
|
using osu.Game.Users;
|
2021-07-14 18:55:01 +09:00
|
|
|
|
using osuTK;
|
2025-03-04 15:29:13 +09:00
|
|
|
|
using osuTK.Graphics;
|
2018-05-22 00:07:04 -03:00
|
|
|
|
|
2020-12-25 16:50:00 +01:00
|
|
|
|
namespace osu.Game.Screens.OnlinePlay.Lounge
|
2018-05-22 00:07:04 -03:00
|
|
|
|
{
|
2020-08-15 13:06:16 -07:00
|
|
|
|
[Cached]
|
2025-01-23 16:19:09 +09:00
|
|
|
|
[Cached(typeof(IOnlinePlayLounge))]
|
|
|
|
|
public abstract partial class LoungeSubScreen : OnlinePlaySubScreen, IOnlinePlayLounge
|
2018-05-22 00:07:04 -03:00
|
|
|
|
{
|
2019-01-25 19:32:37 +09:00
|
|
|
|
public override string Title => "Lounge";
|
2019-01-25 17:44:33 +09:00
|
|
|
|
|
2021-08-20 21:40:35 +09:00
|
|
|
|
protected override BackgroundScreen CreateBackground() => new LoungeBackgroundScreen
|
|
|
|
|
{
|
2025-03-04 15:05:12 +09:00
|
|
|
|
SelectedRoom = { BindTarget = roomListing.SelectedRoom }
|
2021-08-20 21:40:35 +09:00
|
|
|
|
};
|
2021-08-19 18:19:31 +09:00
|
|
|
|
|
2020-11-08 13:21:21 +01:00
|
|
|
|
protected override UserActivity InitialActivity => new UserActivity.SearchingForLobby();
|
|
|
|
|
|
2021-07-14 18:55:01 +09:00
|
|
|
|
protected Container<OsuButton> Buttons { get; } = new Container<OsuButton>
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
AutoSizeAxes = Axes.Both
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-11 12:40:58 +09:00
|
|
|
|
[Resolved]
|
2024-11-21 20:26:44 +09:00
|
|
|
|
private MusicController music { get; set; } = null!;
|
2020-07-10 16:33:45 +09:00
|
|
|
|
|
2020-12-28 22:54:52 +01:00
|
|
|
|
[Resolved(CanBeNull = true)]
|
2024-11-21 20:26:44 +09:00
|
|
|
|
private OngoingOperationTracker? ongoingOperationTracker { get; set; }
|
2020-12-29 08:20:43 +01:00
|
|
|
|
|
2021-08-12 19:48:15 +09:00
|
|
|
|
[Resolved]
|
2024-11-21 20:26:44 +09:00
|
|
|
|
private IBindable<RulesetInfo> ruleset { get; set; } = null!;
|
2021-08-12 19:48:15 +09:00
|
|
|
|
|
2022-03-09 15:38:00 +09:00
|
|
|
|
[Resolved]
|
2024-11-21 20:26:44 +09:00
|
|
|
|
private IAPIProvider api { get; set; } = null!;
|
2020-06-05 20:52:27 +09:00
|
|
|
|
|
2024-11-21 20:26:44 +09:00
|
|
|
|
[Resolved(CanBeNull = true)]
|
|
|
|
|
private IdleTracker? idleTracker { get; set; }
|
2021-08-13 22:24:01 +09:00
|
|
|
|
|
2024-01-15 14:30:27 +09:00
|
|
|
|
[Resolved]
|
2024-11-21 20:26:44 +09:00
|
|
|
|
protected OsuConfigManager Config { get; private set; } = null!;
|
|
|
|
|
|
2025-02-12 18:35:35 +09:00
|
|
|
|
private IDisposable? joiningRoomOperation;
|
2024-01-15 14:30:27 +09:00
|
|
|
|
|
2024-11-21 20:26:44 +09:00
|
|
|
|
private readonly Bindable<FilterCriteria?> filter = new Bindable<FilterCriteria?>();
|
2025-02-12 18:35:35 +09:00
|
|
|
|
private readonly Bindable<bool> hasListingResults = new Bindable<bool>();
|
2021-08-13 17:39:09 +09:00
|
|
|
|
private readonly IBindable<bool> operationInProgress = new Bindable<bool>();
|
|
|
|
|
private readonly IBindable<bool> isIdle = new BindableBool();
|
2025-03-04 15:05:12 +09:00
|
|
|
|
private RoomListing roomListing = null!;
|
2025-03-04 14:40:33 +09:00
|
|
|
|
private LoungeListingPoller listingPoller = null!;
|
2024-11-21 20:26:44 +09:00
|
|
|
|
private PopoverContainer popoverContainer = null!;
|
|
|
|
|
private LoadingLayer loadingLayer = null!;
|
|
|
|
|
private SearchTextBox searchTextBox = null!;
|
2024-12-11 13:01:11 +09:00
|
|
|
|
|
|
|
|
|
protected Dropdown<RoomModeFilter> StatusDropdown { get; private set; } = null!;
|
2021-07-12 18:54:17 +09:00
|
|
|
|
|
2021-08-13 18:11:52 +09:00
|
|
|
|
[BackgroundDependencyLoader(true)]
|
2024-11-21 20:26:44 +09:00
|
|
|
|
private void load()
|
2018-05-22 00:07:04 -03:00
|
|
|
|
{
|
2025-03-04 15:29:13 +09:00
|
|
|
|
Masking = true;
|
|
|
|
|
|
2021-08-19 04:23:02 +03:00
|
|
|
|
const float controls_area_height = 25f;
|
|
|
|
|
|
2021-08-13 18:11:52 +09:00
|
|
|
|
if (idleTracker != null)
|
|
|
|
|
isIdle.BindTo(idleTracker.IsIdle);
|
|
|
|
|
|
2025-03-04 15:29:13 +09:00
|
|
|
|
Color4 bg = Color4Extensions.FromHex("#070405");
|
|
|
|
|
|
2021-07-14 18:24:30 +09:00
|
|
|
|
InternalChildren = new Drawable[]
|
2018-05-22 00:07:04 -03:00
|
|
|
|
{
|
2025-03-04 14:40:33 +09:00
|
|
|
|
listingPoller = new LoungeListingPoller
|
2025-02-12 18:35:35 +09:00
|
|
|
|
{
|
|
|
|
|
RoomsReceived = onListingReceived,
|
|
|
|
|
Filter = { BindTarget = filter }
|
|
|
|
|
},
|
2021-08-28 18:47:34 +02:00
|
|
|
|
popoverContainer = new PopoverContainer
|
2018-05-22 00:07:04 -03:00
|
|
|
|
{
|
2021-08-19 05:09:49 +03:00
|
|
|
|
Name = @"Rooms area",
|
2018-05-22 00:07:04 -03:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2021-07-14 18:24:30 +09:00
|
|
|
|
Padding = new MarginPadding
|
2018-05-22 00:07:04 -03:00
|
|
|
|
{
|
2021-08-19 04:23:02 +03:00
|
|
|
|
Horizontal = WaveOverlayContainer.WIDTH_PADDING,
|
|
|
|
|
Top = Header.HEIGHT + controls_area_height + 20,
|
2021-07-14 17:46:45 +09:00
|
|
|
|
},
|
2025-03-04 15:05:12 +09:00
|
|
|
|
Child = roomListing = new RoomListing
|
2021-07-14 17:46:45 +09:00
|
|
|
|
{
|
2021-07-14 18:24:30 +09:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2025-02-12 21:57:18 +09:00
|
|
|
|
Filter = { BindTarget = filter },
|
|
|
|
|
}
|
2021-08-19 04:23:02 +03:00
|
|
|
|
},
|
|
|
|
|
loadingLayer = new LoadingLayer(true),
|
2025-03-04 15:29:13 +09:00
|
|
|
|
new Container
|
2021-08-19 04:23:02 +03:00
|
|
|
|
{
|
2025-03-04 15:29:13 +09:00
|
|
|
|
Name = "Header area",
|
2021-08-19 04:23:02 +03:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Children = new Drawable[]
|
2021-07-14 17:46:45 +09:00
|
|
|
|
{
|
2025-03-04 15:29:13 +09:00
|
|
|
|
new Box
|
2018-05-22 00:07:04 -03:00
|
|
|
|
{
|
2025-03-04 15:29:13 +09:00
|
|
|
|
Colour = ColourInfo.GradientVertical(bg, bg.Opacity(0.75f)),
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Height = 0.8f,
|
|
|
|
|
},
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
Colour = ColourInfo.GradientVertical(bg.Opacity(0.75f), bg.Opacity(0)),
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
RelativePositionAxes = Axes.Both,
|
|
|
|
|
Y = 0.8f,
|
|
|
|
|
// Intentionally taller than the header for a more gradual fade
|
|
|
|
|
Height = 0.5f,
|
2021-07-14 17:46:45 +09:00
|
|
|
|
},
|
2025-03-04 15:29:13 +09:00
|
|
|
|
new FillFlowContainer
|
2018-05-22 00:07:04 -03:00
|
|
|
|
{
|
2025-03-04 15:29:13 +09:00
|
|
|
|
Name = @"Header area flow",
|
2021-08-19 04:23:02 +03:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2025-03-04 15:29:13 +09:00
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Padding = new MarginPadding { Horizontal = WaveOverlayContainer.WIDTH_PADDING },
|
|
|
|
|
Direction = FillDirection.Vertical,
|
2021-08-19 04:23:02 +03:00
|
|
|
|
Children = new Drawable[]
|
2021-08-12 19:48:15 +09:00
|
|
|
|
{
|
2025-03-04 15:29:13 +09:00
|
|
|
|
new Container
|
2021-08-12 19:48:15 +09:00
|
|
|
|
{
|
2025-03-04 15:29:13 +09:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = Header.HEIGHT,
|
|
|
|
|
Child = searchTextBox = new BasicSearchTextBox
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Width = 0.6f,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
new Container
|
2021-07-14 17:46:45 +09:00
|
|
|
|
{
|
2025-03-04 15:29:13 +09:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = controls_area_height,
|
|
|
|
|
Children = new Drawable[]
|
2021-07-14 17:46:45 +09:00
|
|
|
|
{
|
2025-03-04 15:29:13 +09:00
|
|
|
|
Buttons.WithChild(CreateNewRoomButton().With(d =>
|
|
|
|
|
{
|
|
|
|
|
d.Anchor = Anchor.BottomLeft;
|
|
|
|
|
d.Origin = Anchor.BottomLeft;
|
|
|
|
|
d.Size = new Vector2(150, 37.5f);
|
|
|
|
|
d.Action = () => Open();
|
|
|
|
|
})),
|
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Spacing = new Vector2(10),
|
|
|
|
|
ChildrenEnumerable = CreateFilterControls().Select(f => f.With(d =>
|
|
|
|
|
{
|
|
|
|
|
d.Anchor = Anchor.TopRight;
|
|
|
|
|
d.Origin = Anchor.TopRight;
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-14 18:55:01 +09:00
|
|
|
|
}
|
2025-03-04 15:29:13 +09:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
2021-08-13 14:27:28 +09:00
|
|
|
|
},
|
2018-05-22 00:07:04 -03:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-05 20:52:27 +09:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2021-08-12 19:48:15 +09:00
|
|
|
|
searchTextBox.Current.BindValueChanged(_ => updateFilterDebounced());
|
|
|
|
|
ruleset.BindValueChanged(_ => UpdateFilter());
|
2021-08-13 18:17:18 +09:00
|
|
|
|
isIdle.BindValueChanged(_ => updatePollingRate(this.IsCurrentScreen()), true);
|
2020-12-28 21:39:11 +01:00
|
|
|
|
|
2020-12-29 08:20:43 +01:00
|
|
|
|
if (ongoingOperationTracker != null)
|
2020-12-28 22:54:52 +01:00
|
|
|
|
{
|
2021-01-08 22:23:38 +01:00
|
|
|
|
operationInProgress.BindTo(ongoingOperationTracker.InProgress);
|
2021-08-17 17:18:23 +09:00
|
|
|
|
operationInProgress.BindValueChanged(_ => updateLoadingLayer());
|
2020-12-28 22:54:52 +01:00
|
|
|
|
}
|
2021-08-12 19:48:15 +09:00
|
|
|
|
|
2025-02-12 18:35:35 +09:00
|
|
|
|
hasListingResults.BindValueChanged(_ => updateLoadingLayer());
|
|
|
|
|
|
|
|
|
|
filter.BindValueChanged(_ =>
|
|
|
|
|
{
|
2025-03-04 15:05:12 +09:00
|
|
|
|
roomListing.Rooms.Clear();
|
2025-02-12 18:35:35 +09:00
|
|
|
|
hasListingResults.Value = false;
|
2025-03-04 14:40:33 +09:00
|
|
|
|
listingPoller.PollImmediately();
|
2025-02-12 18:35:35 +09:00
|
|
|
|
});
|
2021-08-17 17:18:23 +09:00
|
|
|
|
|
2021-08-12 19:48:15 +09:00
|
|
|
|
updateFilter();
|
2020-06-05 20:52:27 +09:00
|
|
|
|
}
|
|
|
|
|
|
2025-02-12 18:35:35 +09:00
|
|
|
|
private void onListingReceived(Room[] result)
|
|
|
|
|
{
|
2025-03-04 15:05:12 +09:00
|
|
|
|
Dictionary<long, Room> localRoomsById = roomListing.Rooms.ToDictionary(r => r.RoomID!.Value);
|
2025-02-12 18:35:35 +09:00
|
|
|
|
Dictionary<long, Room> resultRoomsById = result.ToDictionary(r => r.RoomID!.Value);
|
|
|
|
|
|
|
|
|
|
// Remove all local rooms no longer in the result set.
|
2025-03-04 15:05:12 +09:00
|
|
|
|
roomListing.Rooms.RemoveAll(r => !resultRoomsById.ContainsKey(r.RoomID!.Value));
|
2025-02-12 18:35:35 +09:00
|
|
|
|
|
|
|
|
|
// Add or update local rooms with the result set.
|
|
|
|
|
foreach (var r in result)
|
|
|
|
|
{
|
|
|
|
|
if (localRoomsById.TryGetValue(r.RoomID!.Value, out Room? existingRoom))
|
|
|
|
|
existingRoom.CopyFrom(r);
|
|
|
|
|
else
|
2025-03-04 15:05:12 +09:00
|
|
|
|
roomListing.Rooms.Add(r);
|
2025-02-12 18:35:35 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hasListingResults.Value = true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-12 19:48:15 +09:00
|
|
|
|
#region Filtering
|
|
|
|
|
|
2021-08-17 09:36:43 +09:00
|
|
|
|
public void UpdateFilter() => Scheduler.AddOnce(updateFilter);
|
2021-08-12 19:48:15 +09:00
|
|
|
|
|
2024-11-21 20:26:44 +09:00
|
|
|
|
private ScheduledDelegate? scheduledFilterUpdate;
|
2021-08-12 19:48:15 +09:00
|
|
|
|
|
|
|
|
|
private void updateFilterDebounced()
|
|
|
|
|
{
|
|
|
|
|
scheduledFilterUpdate?.Cancel();
|
|
|
|
|
scheduledFilterUpdate = Scheduler.AddDelayed(UpdateFilter, 200);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateFilter()
|
|
|
|
|
{
|
|
|
|
|
scheduledFilterUpdate?.Cancel();
|
|
|
|
|
filter.Value = CreateFilterCriteria();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual FilterCriteria CreateFilterCriteria() => new FilterCriteria
|
|
|
|
|
{
|
|
|
|
|
SearchString = searchTextBox.Current.Value,
|
|
|
|
|
Ruleset = ruleset.Value,
|
2024-12-11 13:01:11 +09:00
|
|
|
|
Mode = StatusDropdown.Current.Value
|
2021-08-12 19:48:15 +09:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
protected virtual IEnumerable<Drawable> CreateFilterControls()
|
2018-05-22 00:24:39 -03:00
|
|
|
|
{
|
2024-12-11 13:01:11 +09:00
|
|
|
|
StatusDropdown = new SlimEnumDropdown<RoomModeFilter>
|
2021-08-12 19:48:15 +09:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.None,
|
|
|
|
|
Width = 160,
|
|
|
|
|
};
|
|
|
|
|
|
2024-12-11 13:01:11 +09:00
|
|
|
|
StatusDropdown.Current.BindValueChanged(_ => UpdateFilter());
|
2021-08-12 19:48:15 +09:00
|
|
|
|
|
2024-12-11 13:01:11 +09:00
|
|
|
|
yield return StatusDropdown;
|
2018-05-22 00:24:39 -03:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-12 19:48:15 +09:00
|
|
|
|
#endregion
|
|
|
|
|
|
2022-04-22 00:52:44 +09:00
|
|
|
|
public override void OnEntering(ScreenTransitionEvent e)
|
2018-05-22 00:24:39 -03:00
|
|
|
|
{
|
2022-04-22 00:52:44 +09:00
|
|
|
|
base.OnEntering(e);
|
2020-02-06 14:22:01 +09:00
|
|
|
|
onReturning();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 00:52:44 +09:00
|
|
|
|
public override void OnResuming(ScreenTransitionEvent e)
|
2020-02-06 14:22:01 +09:00
|
|
|
|
{
|
2022-04-22 00:52:44 +09:00
|
|
|
|
base.OnResuming(e);
|
2020-02-06 14:22:01 +09:00
|
|
|
|
|
2024-11-21 20:26:44 +09:00
|
|
|
|
music.EnsurePlayingSomething();
|
2020-07-10 16:33:45 +09:00
|
|
|
|
|
2020-02-06 14:22:01 +09:00
|
|
|
|
onReturning();
|
2025-01-22 21:44:45 +09:00
|
|
|
|
|
|
|
|
|
// Poll for any newly-created rooms (including potentially the user's own).
|
2025-03-04 14:40:33 +09:00
|
|
|
|
listingPoller.PollImmediately();
|
2020-02-06 14:22:01 +09:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 00:52:44 +09:00
|
|
|
|
public override bool OnExiting(ScreenExitEvent e)
|
2018-05-22 00:24:39 -03:00
|
|
|
|
{
|
2021-07-17 22:31:47 +09:00
|
|
|
|
onLeaving();
|
2022-04-22 00:52:44 +09:00
|
|
|
|
return base.OnExiting(e);
|
2019-01-25 17:44:33 +09:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 00:52:44 +09:00
|
|
|
|
public override void OnSuspending(ScreenTransitionEvent e)
|
2019-01-25 17:44:33 +09:00
|
|
|
|
{
|
2021-07-17 22:31:47 +09:00
|
|
|
|
onLeaving();
|
2022-04-22 00:52:44 +09:00
|
|
|
|
base.OnSuspending(e);
|
2021-07-17 22:31:47 +09:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-12 19:48:15 +09:00
|
|
|
|
protected override void OnFocus(FocusEvent e)
|
|
|
|
|
{
|
|
|
|
|
searchTextBox.TakeFocus();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-17 22:31:47 +09:00
|
|
|
|
private void onReturning()
|
|
|
|
|
{
|
2021-08-13 18:17:18 +09:00
|
|
|
|
updatePollingRate(true);
|
2021-08-12 19:48:15 +09:00
|
|
|
|
searchTextBox.HoldFocus = true;
|
2021-07-17 22:31:47 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onLeaving()
|
|
|
|
|
{
|
2021-08-13 18:17:18 +09:00
|
|
|
|
updatePollingRate(false);
|
2021-08-12 19:48:15 +09:00
|
|
|
|
searchTextBox.HoldFocus = false;
|
2021-07-12 18:54:17 +09:00
|
|
|
|
|
|
|
|
|
// ensure any password prompt is dismissed.
|
2021-08-28 18:47:34 +02:00
|
|
|
|
popoverContainer.HidePopover();
|
2018-05-22 00:24:39 -03:00
|
|
|
|
}
|
|
|
|
|
|
2025-01-22 21:44:45 +09:00
|
|
|
|
public void Join(Room room, string? password, Action<Room>? onSuccess = null, Action<string>? onFailure = null) => Schedule(() =>
|
2018-12-26 21:10:31 +09:00
|
|
|
|
{
|
2021-03-26 14:49:02 +09:00
|
|
|
|
if (joiningRoomOperation != null)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-12-29 08:20:43 +01:00
|
|
|
|
joiningRoomOperation = ongoingOperationTracker?.BeginOperation();
|
2020-06-05 20:52:27 +09:00
|
|
|
|
|
2025-01-25 19:27:21 +09:00
|
|
|
|
JoinInternal(room, password, r =>
|
2018-12-26 21:10:31 +09:00
|
|
|
|
{
|
2019-02-05 19:00:01 +09:00
|
|
|
|
Open(room);
|
2020-12-29 08:20:43 +01:00
|
|
|
|
joiningRoomOperation?.Dispose();
|
|
|
|
|
joiningRoomOperation = null;
|
2021-09-07 16:54:21 -04:00
|
|
|
|
onSuccess?.Invoke(room);
|
|
|
|
|
}, error =>
|
2020-06-05 20:52:27 +09:00
|
|
|
|
{
|
2020-12-29 08:20:43 +01:00
|
|
|
|
joiningRoomOperation?.Dispose();
|
|
|
|
|
joiningRoomOperation = null;
|
2021-09-07 16:54:21 -04:00
|
|
|
|
onFailure?.Invoke(error);
|
2020-06-05 20:52:27 +09:00
|
|
|
|
});
|
2021-07-23 02:23:37 +09:00
|
|
|
|
});
|
2018-12-26 21:10:31 +09:00
|
|
|
|
|
2025-01-25 19:27:21 +09:00
|
|
|
|
protected abstract void JoinInternal(Room room, string? password, Action<Room> onSuccess, Action<string> onFailure);
|
2025-01-22 21:44:45 +09:00
|
|
|
|
|
2025-01-25 19:27:21 +09:00
|
|
|
|
public void OpenCopy(Room room)
|
2022-03-09 15:38:00 +09:00
|
|
|
|
{
|
2024-11-13 16:28:39 +09:00
|
|
|
|
Debug.Assert(room.RoomID != null);
|
2022-03-09 15:38:00 +09:00
|
|
|
|
|
|
|
|
|
if (joiningRoomOperation != null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
joiningRoomOperation = ongoingOperationTracker?.BeginOperation();
|
|
|
|
|
|
2024-11-13 16:28:39 +09:00
|
|
|
|
var req = new GetRoomRequest(room.RoomID.Value);
|
2022-03-09 15:38:00 +09:00
|
|
|
|
|
|
|
|
|
req.Success += r =>
|
|
|
|
|
{
|
|
|
|
|
// ID must be unset as we use this as a marker for whether this is a client-side (not-yet-created) room or not.
|
2024-11-13 16:28:39 +09:00
|
|
|
|
r.RoomID = null;
|
2022-03-09 15:38:00 +09:00
|
|
|
|
|
2022-03-15 11:30:57 +09:00
|
|
|
|
// Null out dates because end date is not supported client-side and the settings overlay will populate a duration.
|
2024-11-13 20:20:14 +09:00
|
|
|
|
r.EndDate = null;
|
|
|
|
|
r.Duration = null;
|
2022-03-15 11:30:57 +09:00
|
|
|
|
|
2022-03-09 15:38:00 +09:00
|
|
|
|
Open(r);
|
|
|
|
|
|
|
|
|
|
joiningRoomOperation?.Dispose();
|
|
|
|
|
joiningRoomOperation = null;
|
|
|
|
|
};
|
|
|
|
|
|
2022-03-09 16:47:47 +09:00
|
|
|
|
req.Failure += exception =>
|
2022-03-09 15:38:00 +09:00
|
|
|
|
{
|
2022-03-09 16:47:47 +09:00
|
|
|
|
Logger.Error(exception, "Couldn't create a copy of this room.");
|
2022-03-09 15:38:00 +09:00
|
|
|
|
joiningRoomOperation?.Dispose();
|
|
|
|
|
joiningRoomOperation = null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
api.Queue(req);
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-27 13:39:16 +09:00
|
|
|
|
public abstract void Close(Room room);
|
2025-01-23 16:19:09 +09:00
|
|
|
|
|
2018-12-26 20:21:30 +09:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Push a room as a new subscreen.
|
|
|
|
|
/// </summary>
|
2021-08-03 20:02:31 +09:00
|
|
|
|
/// <param name="room">An optional template to use when creating the room.</param>
|
2024-11-21 20:26:44 +09:00
|
|
|
|
public void Open(Room? room = null) => Schedule(() =>
|
2018-12-04 15:26:06 +09:00
|
|
|
|
{
|
2018-12-11 19:07:40 +09:00
|
|
|
|
// Handles the case where a room is clicked 3 times in quick succession
|
2019-01-23 20:52:00 +09:00
|
|
|
|
if (!this.IsCurrentScreen())
|
2018-12-04 15:26:06 +09:00
|
|
|
|
return;
|
|
|
|
|
|
2021-08-03 20:02:31 +09:00
|
|
|
|
OpenNewRoom(room ?? CreateNewRoom());
|
2021-07-23 02:23:37 +09:00
|
|
|
|
});
|
|
|
|
|
|
2025-02-12 21:48:59 +09:00
|
|
|
|
protected virtual void OpenNewRoom(Room room) => this.Push(CreateRoomSubScreen(room));
|
2020-12-20 23:36:56 +09:00
|
|
|
|
|
2025-03-04 14:40:33 +09:00
|
|
|
|
public void RefreshRooms() => listingPoller.PollImmediately();
|
2024-11-07 14:58:06 +01:00
|
|
|
|
|
2021-08-13 17:39:09 +09:00
|
|
|
|
private void updateLoadingLayer()
|
|
|
|
|
{
|
2025-02-12 18:35:35 +09:00
|
|
|
|
if (operationInProgress.Value || !hasListingResults.Value)
|
2021-08-13 17:39:09 +09:00
|
|
|
|
loadingLayer.Show();
|
|
|
|
|
else
|
|
|
|
|
loadingLayer.Hide();
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-13 18:17:18 +09:00
|
|
|
|
private void updatePollingRate(bool isCurrentScreen)
|
2021-08-13 17:39:09 +09:00
|
|
|
|
{
|
2021-08-13 18:17:18 +09:00
|
|
|
|
if (!isCurrentScreen)
|
2025-03-04 14:40:33 +09:00
|
|
|
|
listingPoller.TimeBetweenPolls.Value = 0;
|
2021-08-13 17:39:09 +09:00
|
|
|
|
else
|
2025-03-04 14:40:33 +09:00
|
|
|
|
listingPoller.TimeBetweenPolls.Value = isIdle.Value ? 120000 : 15000;
|
2021-08-13 17:39:09 +09:00
|
|
|
|
|
2025-03-04 14:40:33 +09:00
|
|
|
|
Logger.Log($"Polling adjusted (listing: {listingPoller.TimeBetweenPolls.Value})");
|
2021-08-13 17:39:09 +09:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-14 18:55:01 +09:00
|
|
|
|
protected abstract OsuButton CreateNewRoomButton();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a new room.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>The created <see cref="Room"/>.</returns>
|
|
|
|
|
protected abstract Room CreateNewRoom();
|
|
|
|
|
|
2020-12-21 00:21:30 +09:00
|
|
|
|
protected abstract RoomSubScreen CreateRoomSubScreen(Room room);
|
2018-05-22 00:07:04 -03:00
|
|
|
|
}
|
|
|
|
|
}
|