mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 22:12:53 +08:00
Clean up ready button logic into using MultiplayerBeatmapTracker
This commit is contained in:
parent
80f7db8db3
commit
59ae50b0e5
@ -1,77 +1,29 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Game.Beatmaps;
|
|
||||||
using osu.Game.Graphics;
|
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Game.Online;
|
||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
|
|
||||||
namespace osu.Game.Screens.OnlinePlay.Components
|
namespace osu.Game.Screens.OnlinePlay.Components
|
||||||
{
|
{
|
||||||
public abstract class ReadyButton : TriangleButton
|
public abstract class ReadyButton : TriangleButton
|
||||||
{
|
{
|
||||||
public readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
|
|
||||||
|
|
||||||
public new readonly BindableBool Enabled = new BindableBool();
|
public new readonly BindableBool Enabled = new BindableBool();
|
||||||
|
|
||||||
[Resolved]
|
private IBindable<BeatmapAvailability> availability;
|
||||||
protected IBindable<WorkingBeatmap> GameBeatmap { get; private set; }
|
|
||||||
|
|
||||||
[Resolved]
|
|
||||||
private BeatmapManager beatmaps { get; set; }
|
|
||||||
|
|
||||||
private bool hasBeatmap;
|
|
||||||
|
|
||||||
private IBindable<WeakReference<BeatmapSetInfo>> managerUpdated;
|
|
||||||
private IBindable<WeakReference<BeatmapSetInfo>> managerRemoved;
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours)
|
private void load(MultiplayerBeatmapTracker beatmapTracker)
|
||||||
{
|
{
|
||||||
managerUpdated = beatmaps.ItemUpdated.GetBoundCopy();
|
availability = beatmapTracker.Availability.GetBoundCopy();
|
||||||
managerUpdated.BindValueChanged(beatmapUpdated);
|
|
||||||
managerRemoved = beatmaps.ItemRemoved.GetBoundCopy();
|
|
||||||
managerRemoved.BindValueChanged(beatmapRemoved);
|
|
||||||
|
|
||||||
SelectedItem.BindValueChanged(item => updateSelectedItem(item.NewValue), true);
|
availability.BindValueChanged(_ => updateState());
|
||||||
|
Enabled.BindValueChanged(_ => updateState(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSelectedItem(PlaylistItem _) => Scheduler.AddOnce(updateBeatmapState);
|
private void updateState() => base.Enabled.Value = availability.Value.State == DownloadState.LocallyAvailable && Enabled.Value;
|
||||||
private void beatmapUpdated(ValueChangedEvent<WeakReference<BeatmapSetInfo>> _) => Scheduler.AddOnce(updateBeatmapState);
|
|
||||||
private void beatmapRemoved(ValueChangedEvent<WeakReference<BeatmapSetInfo>> _) => Scheduler.AddOnce(updateBeatmapState);
|
|
||||||
|
|
||||||
private void updateBeatmapState()
|
|
||||||
{
|
|
||||||
int? beatmapId = SelectedItem.Value?.Beatmap.Value?.OnlineBeatmapID;
|
|
||||||
string checksum = SelectedItem.Value?.Beatmap.Value?.MD5Hash;
|
|
||||||
|
|
||||||
if (beatmapId == null || checksum == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var databasedBeatmap = beatmaps.QueryBeatmap(b => b.OnlineBeatmapID == beatmapId && b.MD5Hash == checksum);
|
|
||||||
|
|
||||||
hasBeatmap = databasedBeatmap?.BeatmapSet?.DeletePending == false;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Update()
|
|
||||||
{
|
|
||||||
base.Update();
|
|
||||||
|
|
||||||
updateEnabledState();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateEnabledState()
|
|
||||||
{
|
|
||||||
if (GameBeatmap.Value == null || SelectedItem.Value == null)
|
|
||||||
{
|
|
||||||
base.Enabled.Value = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
base.Enabled.Value = hasBeatmap && Enabled.Value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,11 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Online.Rooms;
|
|
||||||
using osu.Game.Screens.OnlinePlay.Playlists;
|
using osu.Game.Screens.OnlinePlay.Playlists;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
@ -20,7 +18,6 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
|
|||||||
public const float HEIGHT = 50;
|
public const float HEIGHT = 50;
|
||||||
|
|
||||||
public Action OnStart;
|
public Action OnStart;
|
||||||
public readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
|
|
||||||
|
|
||||||
private readonly Drawable background;
|
private readonly Drawable background;
|
||||||
|
|
||||||
@ -37,7 +34,6 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
|
|||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Size = new Vector2(600, 50),
|
Size = new Vector2(600, 50),
|
||||||
SelectedItem = { BindTarget = SelectedItem },
|
|
||||||
Action = () => OnStart?.Invoke()
|
Action = () => OnStart?.Invoke()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -3,13 +3,11 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Online.Rooms;
|
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||||
@ -18,8 +16,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
{
|
{
|
||||||
public const float HEIGHT = 50;
|
public const float HEIGHT = 50;
|
||||||
|
|
||||||
public readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
|
|
||||||
|
|
||||||
public Action OnReadyClick
|
public Action OnReadyClick
|
||||||
{
|
{
|
||||||
set => readyButton.OnReadyClick = value;
|
set => readyButton.OnReadyClick = value;
|
||||||
@ -41,7 +37,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Size = new Vector2(600, 50),
|
Size = new Vector2(600, 50),
|
||||||
SelectedItem = { BindTarget = SelectedItem }
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ using osu.Game.Graphics;
|
|||||||
using osu.Game.Graphics.Backgrounds;
|
using osu.Game.Graphics.Backgrounds;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
using osu.Game.Online.Rooms;
|
|
||||||
using osu.Game.Screens.OnlinePlay.Components;
|
using osu.Game.Screens.OnlinePlay.Components;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
@ -21,8 +20,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
{
|
{
|
||||||
public class MultiplayerReadyButton : MultiplayerRoomComposite
|
public class MultiplayerReadyButton : MultiplayerRoomComposite
|
||||||
{
|
{
|
||||||
public Bindable<PlaylistItem> SelectedItem => button.SelectedItem;
|
|
||||||
|
|
||||||
public Action OnReadyClick
|
public Action OnReadyClick
|
||||||
{
|
{
|
||||||
set => button.Action = value;
|
set => button.Action = value;
|
||||||
|
@ -53,7 +53,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
InternalChildren = new Drawable[]
|
AddRangeInternal(new Drawable[]
|
||||||
{
|
{
|
||||||
new GridContainer
|
new GridContainer
|
||||||
{
|
{
|
||||||
@ -161,7 +161,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
{
|
{
|
||||||
new MultiplayerMatchFooter
|
new MultiplayerMatchFooter
|
||||||
{
|
{
|
||||||
SelectedItem = { BindTarget = SelectedItem },
|
|
||||||
OnReadyClick = onReadyClick
|
OnReadyClick = onReadyClick
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -177,7 +176,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
State = { Value = client.Room == null ? Visibility.Visible : Visibility.Hidden }
|
State = { Value = client.Room == null ? Visibility.Visible : Visibility.Hidden }
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
using osu.Game.Screens.OnlinePlay.Components;
|
using osu.Game.Screens.OnlinePlay.Components;
|
||||||
@ -15,6 +16,9 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
|||||||
[Resolved(typeof(Room), nameof(Room.EndDate))]
|
[Resolved(typeof(Room), nameof(Room.EndDate))]
|
||||||
private Bindable<DateTimeOffset?> endDate { get; set; }
|
private Bindable<DateTimeOffset?> endDate { get; set; }
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private IBindable<WorkingBeatmap> gameBeatmap { get; set; }
|
||||||
|
|
||||||
public PlaylistsReadyButton()
|
public PlaylistsReadyButton()
|
||||||
{
|
{
|
||||||
Text = "Start";
|
Text = "Start";
|
||||||
@ -32,7 +36,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
|||||||
{
|
{
|
||||||
base.Update();
|
base.Update();
|
||||||
|
|
||||||
Enabled.Value = endDate.Value != null && DateTimeOffset.UtcNow.AddSeconds(30).AddMilliseconds(GameBeatmap.Value.Track.Length) < endDate.Value;
|
Enabled.Value = endDate.Value != null && DateTimeOffset.UtcNow.AddSeconds(30).AddMilliseconds(gameBeatmap.Value.Track.Length) < endDate.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
InternalChildren = new Drawable[]
|
AddRangeInternal(new Drawable[]
|
||||||
{
|
{
|
||||||
new GridContainer
|
new GridContainer
|
||||||
{
|
{
|
||||||
@ -173,7 +173,6 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
|||||||
new Footer
|
new Footer
|
||||||
{
|
{
|
||||||
OnStart = onStart,
|
OnStart = onStart,
|
||||||
SelectedItem = { BindTarget = SelectedItem }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -189,7 +188,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
|||||||
EditPlaylist = () => this.Push(new MatchSongSelect()),
|
EditPlaylist = () => this.Push(new MatchSongSelect()),
|
||||||
State = { Value = roomId.Value == null ? Visibility.Visible : Visibility.Hidden }
|
State = { Value = roomId.Value == null ? Visibility.Visible : Visibility.Hidden }
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
|
Loading…
Reference in New Issue
Block a user