mirror of
https://github.com/osukey/osukey.git
synced 2025-06-05 12:57:39 +09:00
Implement auto countdown timers
Change to using TimeSpan
This commit is contained in:
parent
04f4e81852
commit
d0fee53e1f
@ -239,7 +239,9 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
/// <param name="password">The new password, if any.</param>
|
/// <param name="password">The new password, if any.</param>
|
||||||
/// <param name="matchType">The type of the match, if any.</param>
|
/// <param name="matchType">The type of the match, if any.</param>
|
||||||
/// <param name="queueMode">The new queue mode, if any.</param>
|
/// <param name="queueMode">The new queue mode, if any.</param>
|
||||||
public Task ChangeSettings(Optional<string> name = default, Optional<string> password = default, Optional<MatchType> matchType = default, Optional<QueueMode> queueMode = default)
|
/// <param name="autoStartDuration">The new auto-start countdown duration, if any.</param>
|
||||||
|
public Task ChangeSettings(Optional<string> name = default, Optional<string> password = default, Optional<MatchType> matchType = default, Optional<QueueMode> queueMode = default,
|
||||||
|
Optional<TimeSpan> autoStartDuration = default)
|
||||||
{
|
{
|
||||||
if (Room == null)
|
if (Room == null)
|
||||||
throw new InvalidOperationException("Must be joined to a match to change settings.");
|
throw new InvalidOperationException("Must be joined to a match to change settings.");
|
||||||
@ -250,6 +252,7 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
Password = password.GetOr(Room.Settings.Password),
|
Password = password.GetOr(Room.Settings.Password),
|
||||||
MatchType = matchType.GetOr(Room.Settings.MatchType),
|
MatchType = matchType.GetOr(Room.Settings.MatchType),
|
||||||
QueueMode = queueMode.GetOr(Room.Settings.QueueMode),
|
QueueMode = queueMode.GetOr(Room.Settings.QueueMode),
|
||||||
|
AutoStartDuration = autoStartDuration.GetOr(Room.Settings.AutoStartDuration),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,9 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
[Key(4)]
|
[Key(4)]
|
||||||
public QueueMode QueueMode { get; set; } = QueueMode.HostOnly;
|
public QueueMode QueueMode { get; set; } = QueueMode.HostOnly;
|
||||||
|
|
||||||
|
[Key(5)]
|
||||||
|
public TimeSpan AutoStartDuration { get; set; }
|
||||||
|
|
||||||
public bool Equals(MultiplayerRoomSettings? other)
|
public bool Equals(MultiplayerRoomSettings? other)
|
||||||
{
|
{
|
||||||
if (ReferenceEquals(this, other)) return true;
|
if (ReferenceEquals(this, other)) return true;
|
||||||
@ -37,13 +40,15 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
&& Name.Equals(other.Name, StringComparison.Ordinal)
|
&& Name.Equals(other.Name, StringComparison.Ordinal)
|
||||||
&& PlaylistItemId == other.PlaylistItemId
|
&& PlaylistItemId == other.PlaylistItemId
|
||||||
&& MatchType == other.MatchType
|
&& MatchType == other.MatchType
|
||||||
&& QueueMode == other.QueueMode;
|
&& QueueMode == other.QueueMode
|
||||||
|
&& AutoStartDuration == other.AutoStartDuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString() => $"Name:{Name}"
|
public override string ToString() => $"Name:{Name}"
|
||||||
+ $" Password:{(string.IsNullOrEmpty(Password) ? "no" : "yes")}"
|
+ $" Password:{(string.IsNullOrEmpty(Password) ? "no" : "yes")}"
|
||||||
+ $" Type:{MatchType}"
|
+ $" Type:{MatchType}"
|
||||||
+ $" Item:{PlaylistItemId}"
|
+ $" Item:{PlaylistItemId}"
|
||||||
+ $" Queue:{QueueMode}";
|
+ $" Queue:{QueueMode}"
|
||||||
|
+ $" Start:{AutoStartDuration}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,16 @@ namespace osu.Game.Online.Rooms
|
|||||||
set => QueueMode.Value = value;
|
set => QueueMode.Value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Cached]
|
||||||
|
public readonly Bindable<TimeSpan> AutoStartDuration = new Bindable<TimeSpan>();
|
||||||
|
|
||||||
|
[JsonProperty("start_duration")]
|
||||||
|
private ushort autoStartDuration
|
||||||
|
{
|
||||||
|
get => (ushort)AutoStartDuration.Value.TotalSeconds;
|
||||||
|
set => AutoStartDuration.Value = TimeSpan.FromSeconds(value);
|
||||||
|
}
|
||||||
|
|
||||||
[Cached]
|
[Cached]
|
||||||
public readonly Bindable<int?> MaxParticipants = new Bindable<int?>();
|
public readonly Bindable<int?> MaxParticipants = new Bindable<int?>();
|
||||||
|
|
||||||
@ -172,6 +182,7 @@ namespace osu.Game.Online.Rooms
|
|||||||
EndDate.Value = other.EndDate.Value;
|
EndDate.Value = other.EndDate.Value;
|
||||||
UserScore.Value = other.UserScore.Value;
|
UserScore.Value = other.UserScore.Value;
|
||||||
QueueMode.Value = other.QueueMode.Value;
|
QueueMode.Value = other.QueueMode.Value;
|
||||||
|
AutoStartDuration.Value = other.AutoStartDuration.Value;
|
||||||
DifficultyRange.Value = other.DifficultyRange.Value;
|
DifficultyRange.Value = other.DifficultyRange.Value;
|
||||||
PlaylistItemStats.Value = other.PlaylistItemStats.Value;
|
PlaylistItemStats.Value = other.PlaylistItemStats.Value;
|
||||||
CurrentPlaylistItem.Value = other.CurrentPlaylistItem.Value;
|
CurrentPlaylistItem.Value = other.CurrentPlaylistItem.Value;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// 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 System;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
@ -21,6 +22,7 @@ using osu.Game.Online.Rooms;
|
|||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Screens.OnlinePlay.Match.Components;
|
using osu.Game.Screens.OnlinePlay.Match.Components;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
using Container = osu.Framework.Graphics.Containers.Container;
|
||||||
|
|
||||||
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||||
{
|
{
|
||||||
@ -64,6 +66,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
|
|
||||||
public OsuSpriteText ErrorText;
|
public OsuSpriteText ErrorText;
|
||||||
|
|
||||||
|
private OsuEnumDropdown<StartMode> startModeDropdown;
|
||||||
private OsuSpriteText typeLabel;
|
private OsuSpriteText typeLabel;
|
||||||
private LoadingLayer loadingLayer;
|
private LoadingLayer loadingLayer;
|
||||||
|
|
||||||
@ -204,6 +207,18 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
RelativeSizeAxes = Axes.X
|
RelativeSizeAxes = Axes.X
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
new Section("Auto start")
|
||||||
|
{
|
||||||
|
Child = new Container
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
Height = 40,
|
||||||
|
Child = startModeDropdown = new OsuEnumDropdown<StartMode>
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -327,6 +342,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
RoomID.BindValueChanged(roomId => playlistContainer.Alpha = roomId.NewValue == null ? 1 : 0, true);
|
RoomID.BindValueChanged(roomId => playlistContainer.Alpha = roomId.NewValue == null ? 1 : 0, true);
|
||||||
Password.BindValueChanged(password => PasswordTextBox.Text = password.NewValue ?? string.Empty, true);
|
Password.BindValueChanged(password => PasswordTextBox.Text = password.NewValue ?? string.Empty, true);
|
||||||
QueueMode.BindValueChanged(mode => QueueModeDropdown.Current.Value = mode.NewValue, true);
|
QueueMode.BindValueChanged(mode => QueueModeDropdown.Current.Value = mode.NewValue, true);
|
||||||
|
AutoStartDuration.BindValueChanged(duration => startModeDropdown.Current.Value = (StartMode)(int)duration.NewValue.TotalSeconds, true);
|
||||||
|
|
||||||
operationInProgress.BindTo(ongoingOperationTracker.InProgress);
|
operationInProgress.BindTo(ongoingOperationTracker.InProgress);
|
||||||
operationInProgress.BindValueChanged(v =>
|
operationInProgress.BindValueChanged(v =>
|
||||||
@ -363,6 +379,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
Debug.Assert(applyingSettingsOperation == null);
|
Debug.Assert(applyingSettingsOperation == null);
|
||||||
applyingSettingsOperation = ongoingOperationTracker.BeginOperation();
|
applyingSettingsOperation = ongoingOperationTracker.BeginOperation();
|
||||||
|
|
||||||
|
TimeSpan autoStartDuration = TimeSpan.FromSeconds((int)startModeDropdown.Current.Value);
|
||||||
|
|
||||||
// If the client is already in a room, update via the client.
|
// If the client is already in a room, update via the client.
|
||||||
// Otherwise, update the room directly in preparation for it to be submitted to the API on match creation.
|
// Otherwise, update the room directly in preparation for it to be submitted to the API on match creation.
|
||||||
if (client.Room != null)
|
if (client.Room != null)
|
||||||
@ -371,7 +389,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
name: NameField.Text,
|
name: NameField.Text,
|
||||||
password: PasswordTextBox.Text,
|
password: PasswordTextBox.Text,
|
||||||
matchType: TypePicker.Current.Value,
|
matchType: TypePicker.Current.Value,
|
||||||
queueMode: QueueModeDropdown.Current.Value)
|
queueMode: QueueModeDropdown.Current.Value,
|
||||||
|
autoStartDuration: autoStartDuration)
|
||||||
.ContinueWith(t => Schedule(() =>
|
.ContinueWith(t => Schedule(() =>
|
||||||
{
|
{
|
||||||
if (t.IsCompletedSuccessfully)
|
if (t.IsCompletedSuccessfully)
|
||||||
@ -387,6 +406,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
room.Type.Value = TypePicker.Current.Value;
|
room.Type.Value = TypePicker.Current.Value;
|
||||||
room.Password.Value = PasswordTextBox.Current.Value;
|
room.Password.Value = PasswordTextBox.Current.Value;
|
||||||
room.QueueMode.Value = QueueModeDropdown.Current.Value;
|
room.QueueMode.Value = QueueModeDropdown.Current.Value;
|
||||||
|
room.AutoStartDuration.Value = autoStartDuration;
|
||||||
|
|
||||||
if (int.TryParse(MaxParticipantsField.Text, out int max))
|
if (int.TryParse(MaxParticipantsField.Text, out int max))
|
||||||
room.MaxParticipants.Value = max;
|
room.MaxParticipants.Value = max;
|
||||||
@ -452,5 +472,23 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
Triangles.ColourDark = colours.YellowDark;
|
Triangles.ColourDark = colours.YellowDark;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private enum StartMode
|
||||||
|
{
|
||||||
|
[Description("Off")]
|
||||||
|
Off = 0,
|
||||||
|
|
||||||
|
[Description("30 seconds")]
|
||||||
|
Seconds_30 = 30,
|
||||||
|
|
||||||
|
[Description("1 minute")]
|
||||||
|
Seconds_60 = 60,
|
||||||
|
|
||||||
|
[Description("3 minutes")]
|
||||||
|
Seconds_180 = 180,
|
||||||
|
|
||||||
|
[Description("5 minutes")]
|
||||||
|
Seconds_300 = 300
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
clickOperation = ongoingOperationTracker.BeginOperation();
|
clickOperation = ongoingOperationTracker.BeginOperation();
|
||||||
|
|
||||||
// Ensure the current user becomes ready before being able to do anything else (start match, stop countdown, unready).
|
// Ensure the current user becomes ready before being able to do anything else (start match, stop countdown, unready).
|
||||||
if (!isReady() || !Client.IsHost)
|
if (!isReady() || !Client.IsHost || Room.Settings.AutoStartDuration != TimeSpan.Zero)
|
||||||
{
|
{
|
||||||
toggleReady();
|
toggleReady();
|
||||||
return;
|
return;
|
||||||
@ -183,7 +183,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
int newCountReady = Room.Users.Count(u => u.State == MultiplayerUserState.Ready);
|
int newCountReady = Room.Users.Count(u => u.State == MultiplayerUserState.Ready);
|
||||||
int newCountTotal = Room.Users.Count(u => u.State != MultiplayerUserState.Spectating);
|
int newCountTotal = Room.Users.Count(u => u.State != MultiplayerUserState.Spectating);
|
||||||
|
|
||||||
if (Room.Countdown != null)
|
if (Room.Countdown != null || Room.Settings.AutoStartDuration != TimeSpan.Zero)
|
||||||
countdownButton.Alpha = 0;
|
countdownButton.Alpha = 0;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -81,6 +81,9 @@ namespace osu.Game.Screens.OnlinePlay
|
|||||||
[Resolved(typeof(Room))]
|
[Resolved(typeof(Room))]
|
||||||
protected Bindable<QueueMode> QueueMode { get; private set; }
|
protected Bindable<QueueMode> QueueMode { get; private set; }
|
||||||
|
|
||||||
|
[Resolved(typeof(Room))]
|
||||||
|
protected Bindable<TimeSpan> AutoStartDuration { get; private set; }
|
||||||
|
|
||||||
[Resolved(CanBeNull = true)]
|
[Resolved(CanBeNull = true)]
|
||||||
private IBindable<PlaylistItem> subScreenSelectedItem { get; set; }
|
private IBindable<PlaylistItem> subScreenSelectedItem { get; set; }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user