1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 13:27:23 +08:00

General refactorings from PR review

This commit is contained in:
smoogipoo 2021-08-16 13:09:04 +09:00
parent 81f9442471
commit b6a2020c59
3 changed files with 18 additions and 17 deletions

View File

@ -15,8 +15,8 @@ namespace osu.Game.Screens.OnlinePlay.Components
/// </summary>
public class ListingPollingComponent : RoomPollingComponent
{
public IBindable<bool> HasPolledOnce => hasPolledOnce;
private readonly Bindable<bool> hasPolledOnce = new Bindable<bool>();
public IBindable<bool> InitialRoomsReceived => initialRoomsReceived;
private readonly Bindable<bool> initialRoomsReceived = new Bindable<bool>();
[Resolved]
private Bindable<FilterCriteria> currentFilter { get; set; }
@ -30,7 +30,7 @@ namespace osu.Game.Screens.OnlinePlay.Components
currentFilter.BindValueChanged(_ =>
{
RoomManager.ClearRooms();
hasPolledOnce.Value = false;
initialRoomsReceived.Value = false;
if (IsLoaded)
PollImmediately();
@ -60,7 +60,7 @@ namespace osu.Game.Screens.OnlinePlay.Components
foreach (var incoming in result)
RoomManager.AddOrUpdateRoom(incoming);
hasPolledOnce.Value = true;
initialRoomsReceived.Value = true;
tcs.SetResult(true);
};

View File

@ -45,6 +45,8 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
AutoSizeAxes = Axes.Both
};
protected ListingPollingComponent ListingPollingComponent { get; private set; }
[Resolved]
private Bindable<Room> selectedRoom { get; set; }
@ -72,7 +74,6 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
private RoomsContainer roomsContainer;
private SearchTextBox searchTextBox;
private Dropdown<RoomStatusFilter> statusDropdown;
private ListingPollingComponent listingPollingComponent;
[BackgroundDependencyLoader(true)]
private void load([CanBeNull] IdleTracker idleTracker)
@ -86,7 +87,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
InternalChildren = new Drawable[]
{
listingPollingComponent = CreatePollingComponent(),
ListingPollingComponent = CreatePollingComponent(),
loadingLayer = new LoadingLayer(true),
new Container
{
@ -186,7 +187,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
searchTextBox.Current.BindValueChanged(_ => updateFilterDebounced());
ruleset.BindValueChanged(_ => UpdateFilter());
listingPollingComponent.HasPolledOnce.BindValueChanged(_ => updateLoadingLayer());
ListingPollingComponent.InitialRoomsReceived.BindValueChanged(_ => updateLoadingLayer());
isIdle.BindValueChanged(_ => updatePollingRate(this.IsCurrentScreen()), true);
@ -337,7 +338,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
private void updateLoadingLayer()
{
if (operationInProgress.Value || !listingPollingComponent.HasPolledOnce.Value)
if (operationInProgress.Value || !ListingPollingComponent.InitialRoomsReceived.Value)
loadingLayer.Show();
else
loadingLayer.Hide();
@ -346,11 +347,11 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
private void updatePollingRate(bool isCurrentScreen)
{
if (!isCurrentScreen)
listingPollingComponent.TimeBetweenPolls.Value = 0;
ListingPollingComponent.TimeBetweenPolls.Value = 0;
else
listingPollingComponent.TimeBetweenPolls.Value = isIdle.Value ? 120000 : 15000;
ListingPollingComponent.TimeBetweenPolls.Value = isIdle.Value ? 120000 : 15000;
Logger.Log($"Polling adjusted (listing: {listingPollingComponent.TimeBetweenPolls.Value})");
Logger.Log($"Polling adjusted (listing: {ListingPollingComponent.TimeBetweenPolls.Value})");
}
protected abstract OsuButton CreateNewRoomButton();

View File

@ -25,7 +25,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
[Resolved]
private MultiplayerClient client { get; set; }
private MultiplayerListingPollingComponent listingPollingComponent;
private MultiplayerListingPollingComponent multiplayerListingPollingComponent => (MultiplayerListingPollingComponent)ListingPollingComponent;
private readonly IBindable<bool> isConnected = new Bindable<bool>();
@ -34,8 +34,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
base.LoadComplete();
isConnected.BindTo(client.IsConnected);
isConnected.BindValueChanged(c => Scheduler.AddOnce(() => listingPollingComponent.AllowPolling = c.NewValue));
listingPollingComponent.AllowPolling = isConnected.Value;
isConnected.BindValueChanged(c => Scheduler.AddOnce(() => multiplayerListingPollingComponent.AllowPolling = c.NewValue));
multiplayerListingPollingComponent.AllowPolling = isConnected.Value;
}
public override void OnResuming(IScreen last)
@ -47,7 +47,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
if (last is MultiplayerMatchSubScreen match)
{
RoomManager.RemoveRoom(match.Room);
listingPollingComponent.PollImmediately();
multiplayerListingPollingComponent.PollImmediately();
}
}
@ -69,7 +69,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
protected override RoomSubScreen CreateRoomSubScreen(Room room) => new MultiplayerMatchSubScreen(room);
protected override ListingPollingComponent CreatePollingComponent() => listingPollingComponent = new MultiplayerListingPollingComponent();
protected override ListingPollingComponent CreatePollingComponent() => new MultiplayerListingPollingComponent();
protected override void OpenNewRoom(Room room)
{
@ -104,7 +104,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
}
}
protected override Task Poll() => !AllowPolling ? Task.CompletedTask : base.Poll();
protected override Task Poll() => AllowPolling ? base.Poll() : Task.CompletedTask;
}
}
}