mirror of
https://github.com/ppy/osu.git
synced 2025-03-15 23:57:25 +08:00
Disallow starting gameplay if there's not enough time in the room
This commit is contained in:
parent
1051584f0f
commit
2c000a9a1d
@ -26,7 +26,7 @@ namespace osu.Game.Tests.Visual
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(RulesetStore rulesets)
|
private void load(RulesetStore rulesets)
|
||||||
{
|
{
|
||||||
Info info = new Info();
|
Info info = new Info(new Room());
|
||||||
Add(info);
|
Add(info);
|
||||||
|
|
||||||
AddStep(@"set name", () => info.Name.Value = @"Room Name?");
|
AddStep(@"set name", () => info.Name.Value = @"Room Name?");
|
||||||
|
@ -52,6 +52,10 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
set => Duration.Value = TimeSpan.FromMinutes(value);
|
set => Duration.Value = TimeSpan.FromMinutes(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only supports retrieval for now
|
||||||
|
[JsonProperty("ends_at")]
|
||||||
|
public Bindable<DateTimeOffset> EndDate = new Bindable<DateTimeOffset>();
|
||||||
|
|
||||||
// Todo: Find a better way to do this (https://github.com/ppy/osu-framework/issues/1930)
|
// Todo: Find a better way to do this (https://github.com/ppy/osu-framework/issues/1930)
|
||||||
[JsonProperty("max_attempts", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
[JsonProperty("max_attempts", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||||
private int? maxAttempts
|
private int? maxAttempts
|
||||||
@ -70,6 +74,7 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
Type.Value = other.Type;
|
Type.Value = other.Type;
|
||||||
MaxParticipants.Value = other.MaxParticipants;
|
MaxParticipants.Value = other.MaxParticipants;
|
||||||
Participants.Value = other.Participants.Value.ToArray();
|
Participants.Value = other.Participants.Value.ToArray();
|
||||||
|
EndDate = other.EndDate;
|
||||||
|
|
||||||
Playlist.Clear();
|
Playlist.Clear();
|
||||||
Playlist.AddRange(other.Playlist);
|
Playlist.AddRange(other.Playlist);
|
||||||
@ -77,5 +82,6 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
|
|
||||||
public bool ShouldSerializeRoomID() => false;
|
public bool ShouldSerializeRoomID() => false;
|
||||||
public bool ShouldSerializeHost() => false;
|
public bool ShouldSerializeHost() => false;
|
||||||
|
public bool ShouldSerializeEndDate() => false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ namespace osu.Game.Screens.Multi.Match.Components
|
|||||||
public readonly Bindable<GameType> Type = new Bindable<GameType>();
|
public readonly Bindable<GameType> Type = new Bindable<GameType>();
|
||||||
public readonly Bindable<IEnumerable<Mod>> Mods = new Bindable<IEnumerable<Mod>>();
|
public readonly Bindable<IEnumerable<Mod>> Mods = new Bindable<IEnumerable<Mod>>();
|
||||||
|
|
||||||
public Info()
|
public Info(Room room)
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
AutoSizeAxes = Axes.Y;
|
AutoSizeAxes = Axes.Y;
|
||||||
@ -106,7 +106,7 @@ namespace osu.Game.Screens.Multi.Match.Components
|
|||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
viewBeatmapButton = new ViewBeatmapButton(),
|
viewBeatmapButton = new ViewBeatmapButton(),
|
||||||
readyButton = new ReadyButton
|
readyButton = new ReadyButton(room)
|
||||||
{
|
{
|
||||||
Action = () => OnStart?.Invoke()
|
Action = () => OnStart?.Invoke()
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Configuration;
|
using osu.Framework.Configuration;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Online.Multiplayer;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Multi.Match.Components
|
namespace osu.Game.Screens.Multi.Match.Components
|
||||||
@ -14,11 +16,19 @@ namespace osu.Game.Screens.Multi.Match.Components
|
|||||||
{
|
{
|
||||||
public readonly IBindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
|
public readonly IBindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
|
||||||
|
|
||||||
|
private readonly Room room;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private IBindableBeatmap gameBeatmap { get; set; }
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private BeatmapManager beatmaps { get; set; }
|
private BeatmapManager beatmaps { get; set; }
|
||||||
|
|
||||||
public ReadyButton()
|
private bool hasBeatmap;
|
||||||
|
|
||||||
|
public ReadyButton(Room room)
|
||||||
{
|
{
|
||||||
|
this.room = room;
|
||||||
RelativeSizeAxes = Axes.Y;
|
RelativeSizeAxes = Axes.Y;
|
||||||
Size = new Vector2(200, 1);
|
Size = new Vector2(200, 1);
|
||||||
|
|
||||||
@ -30,24 +40,43 @@ namespace osu.Game.Screens.Multi.Match.Components
|
|||||||
{
|
{
|
||||||
beatmaps.ItemAdded += beatmapAdded;
|
beatmaps.ItemAdded += beatmapAdded;
|
||||||
|
|
||||||
Beatmap.BindValueChanged(updateEnabledState, true);
|
Beatmap.BindValueChanged(updateBeatmap, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateEnabledState(BeatmapInfo beatmap)
|
private void updateBeatmap(BeatmapInfo beatmap)
|
||||||
{
|
{
|
||||||
if (beatmap?.OnlineBeatmapID == null)
|
hasBeatmap = false;
|
||||||
{
|
|
||||||
Enabled.Value = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Enabled.Value = beatmaps.QueryBeatmap(b => b.OnlineBeatmapID == beatmap.OnlineBeatmapID) != null;
|
if (beatmap?.OnlineBeatmapID == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
hasBeatmap = beatmaps.QueryBeatmap(b => b.OnlineBeatmapID == beatmap.OnlineBeatmapID) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void beatmapAdded(BeatmapSetInfo model, bool existing, bool silent)
|
private void beatmapAdded(BeatmapSetInfo model, bool existing, bool silent)
|
||||||
{
|
{
|
||||||
if (model.Beatmaps.Any(b => b.OnlineBeatmapID == Beatmap.Value.OnlineBeatmapID))
|
if (model.Beatmaps.Any(b => b.OnlineBeatmapID == Beatmap.Value.OnlineBeatmapID))
|
||||||
Schedule(() => Enabled.Value = true);
|
Schedule(() => hasBeatmap = true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Update()
|
||||||
|
{
|
||||||
|
base.Update();
|
||||||
|
|
||||||
|
updateEnabledState();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateEnabledState()
|
||||||
|
{
|
||||||
|
if (gameBeatmap.Value == null)
|
||||||
|
{
|
||||||
|
Enabled.Value = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hasEnoughTime = DateTimeOffset.UtcNow.AddSeconds(30).AddMilliseconds(gameBeatmap.Value.Track.Length) < room.EndDate;
|
||||||
|
|
||||||
|
Enabled.Value = hasBeatmap && hasEnoughTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
|
@ -79,7 +79,7 @@ namespace osu.Game.Screens.Multi.Match
|
|||||||
Content = new[]
|
Content = new[]
|
||||||
{
|
{
|
||||||
new Drawable[] { header = new Components.Header { Depth = -1 } },
|
new Drawable[] { header = new Components.Header { Depth = -1 } },
|
||||||
new Drawable[] { info = new Info { OnStart = onStart } },
|
new Drawable[] { info = new Info(room) { OnStart = onStart } },
|
||||||
new Drawable[]
|
new Drawable[]
|
||||||
{
|
{
|
||||||
new GridContainer
|
new GridContainer
|
||||||
|
Loading…
x
Reference in New Issue
Block a user