mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 15:47:26 +08:00
Implement duration
This commit is contained in:
parent
279891ae08
commit
cc68cf2f95
@ -35,7 +35,7 @@ namespace osu.Game.Tests.Visual
|
|||||||
MaxParticipants = { Value = 10 },
|
MaxParticipants = { Value = 10 },
|
||||||
};
|
};
|
||||||
|
|
||||||
Add(overlay = new TestRoomSettingsOverlay
|
Add(overlay = new TestRoomSettingsOverlay(new Room())
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Height = 0.75f,
|
Height = 0.75f,
|
||||||
@ -84,6 +84,11 @@ namespace osu.Game.Tests.Visual
|
|||||||
|
|
||||||
private class TestRoomSettingsOverlay : RoomSettingsOverlay
|
private class TestRoomSettingsOverlay : RoomSettingsOverlay
|
||||||
{
|
{
|
||||||
|
public TestRoomSettingsOverlay(Room room)
|
||||||
|
: base(room)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public string CurrentName
|
public string CurrentName
|
||||||
{
|
{
|
||||||
get => NameField.Text;
|
get => NameField.Text;
|
||||||
|
@ -29,12 +29,18 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
[JsonProperty("playlist")]
|
[JsonProperty("playlist")]
|
||||||
public readonly BindableCollection<PlaylistItem> Playlist = new BindableCollection<PlaylistItem>();
|
public readonly BindableCollection<PlaylistItem> Playlist = new BindableCollection<PlaylistItem>();
|
||||||
|
|
||||||
[JsonProperty("duration")]
|
[JsonIgnore]
|
||||||
public readonly Bindable<int> Duration = new Bindable<int>(100);
|
public readonly Bindable<TimeSpan> Duration = new Bindable<TimeSpan>(TimeSpan.FromMinutes(30));
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public readonly Bindable<int?> MaxAttempts = new Bindable<int?>();
|
public readonly Bindable<int?> MaxAttempts = new Bindable<int?>();
|
||||||
|
|
||||||
|
[JsonProperty("duration")]
|
||||||
|
private int duration
|
||||||
|
{
|
||||||
|
get => (int)Duration.Value.TotalMinutes;
|
||||||
|
set => Duration.Value = TimeSpan.FromMinutes(value);
|
||||||
|
}
|
||||||
// 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
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
// 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 Humanizer;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Configuration;
|
using osu.Framework.Configuration;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
@ -26,25 +28,28 @@ namespace osu.Game.Screens.Multi.Match.Components
|
|||||||
private readonly Bindable<GameType> typeBind = new Bindable<GameType>();
|
private readonly Bindable<GameType> typeBind = new Bindable<GameType>();
|
||||||
private readonly Bindable<int?> maxParticipantsBind = new Bindable<int?>();
|
private readonly Bindable<int?> maxParticipantsBind = new Bindable<int?>();
|
||||||
private readonly IBindableCollection<PlaylistItem> playlistBind = new BindableCollection<PlaylistItem>();
|
private readonly IBindableCollection<PlaylistItem> playlistBind = new BindableCollection<PlaylistItem>();
|
||||||
|
private readonly Bindable<TimeSpan> durationBind = new Bindable<TimeSpan>();
|
||||||
|
|
||||||
private readonly Container content;
|
private readonly Container content;
|
||||||
|
|
||||||
private readonly OsuSpriteText typeLabel;
|
private readonly OsuSpriteText typeLabel;
|
||||||
|
|
||||||
protected readonly OsuTextBox NameField, MaxParticipantsField;
|
protected readonly OsuTextBox NameField, MaxParticipantsField;
|
||||||
|
protected readonly OsuDropdown<TimeSpan> DurationField;
|
||||||
protected readonly RoomAvailabilityPicker AvailabilityPicker;
|
protected readonly RoomAvailabilityPicker AvailabilityPicker;
|
||||||
protected readonly GameTypePicker TypePicker;
|
protected readonly GameTypePicker TypePicker;
|
||||||
protected readonly TriangleButton ApplyButton;
|
protected readonly TriangleButton ApplyButton;
|
||||||
protected readonly OsuPasswordTextBox PasswordField;
|
protected readonly OsuPasswordTextBox PasswordField;
|
||||||
|
|
||||||
[Resolved]
|
private readonly Room room;
|
||||||
|
|
||||||
|
[Resolved(CanBeNull = true)]
|
||||||
private RoomManager manager { get; set; }
|
private RoomManager manager { get; set; }
|
||||||
|
|
||||||
[Resolved]
|
public RoomSettingsOverlay(Room room)
|
||||||
private Room room { get; set; }
|
|
||||||
|
|
||||||
public RoomSettingsOverlay()
|
|
||||||
{
|
{
|
||||||
|
this.room = room;
|
||||||
|
|
||||||
Masking = true;
|
Masking = true;
|
||||||
|
|
||||||
Child = content = new Container
|
Child = content = new Container
|
||||||
@ -121,6 +126,26 @@ namespace osu.Game.Screens.Multi.Match.Components
|
|||||||
OnCommit = (sender, text) => apply(),
|
OnCommit = (sender, text) => apply(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
new Section("DURATION")
|
||||||
|
{
|
||||||
|
Child = DurationField = new DurationDropdown
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
Items = new[]
|
||||||
|
{
|
||||||
|
TimeSpan.FromMinutes(30),
|
||||||
|
TimeSpan.FromHours(1),
|
||||||
|
TimeSpan.FromHours(2),
|
||||||
|
TimeSpan.FromHours(4),
|
||||||
|
TimeSpan.FromHours(8),
|
||||||
|
TimeSpan.FromHours(12),
|
||||||
|
TimeSpan.FromHours(16),
|
||||||
|
TimeSpan.FromHours(24),
|
||||||
|
TimeSpan.FromDays(3),
|
||||||
|
TimeSpan.FromDays(7)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
new Section("PASSWORD (OPTIONAL)")
|
new Section("PASSWORD (OPTIONAL)")
|
||||||
{
|
{
|
||||||
Child = PasswordField = new SettingsPasswordTextBox
|
Child = PasswordField = new SettingsPasswordTextBox
|
||||||
@ -151,6 +176,7 @@ namespace osu.Game.Screens.Multi.Match.Components
|
|||||||
availabilityBind.ValueChanged += a => AvailabilityPicker.Current.Value = a;
|
availabilityBind.ValueChanged += a => AvailabilityPicker.Current.Value = a;
|
||||||
typeBind.ValueChanged += t => TypePicker.Current.Value = t;
|
typeBind.ValueChanged += t => TypePicker.Current.Value = t;
|
||||||
maxParticipantsBind.ValueChanged += m => MaxParticipantsField.Text = m?.ToString();
|
maxParticipantsBind.ValueChanged += m => MaxParticipantsField.Text = m?.ToString();
|
||||||
|
durationBind.ValueChanged += d => DurationField.Current.Value = d;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
@ -163,6 +189,7 @@ namespace osu.Game.Screens.Multi.Match.Components
|
|||||||
availabilityBind.BindTo(room.Availability);
|
availabilityBind.BindTo(room.Availability);
|
||||||
typeBind.BindTo(room.Type);
|
typeBind.BindTo(room.Type);
|
||||||
maxParticipantsBind.BindTo(room.MaxParticipants);
|
maxParticipantsBind.BindTo(room.MaxParticipants);
|
||||||
|
durationBind.BindTo(room.Duration);
|
||||||
|
|
||||||
MaxParticipantsField.ReadOnly = true;
|
MaxParticipantsField.ReadOnly = true;
|
||||||
PasswordField.ReadOnly = true;
|
PasswordField.ReadOnly = true;
|
||||||
@ -210,7 +237,7 @@ namespace osu.Game.Screens.Multi.Match.Components
|
|||||||
else
|
else
|
||||||
maxParticipantsBind.Value = null;
|
maxParticipantsBind.Value = null;
|
||||||
|
|
||||||
manager.CreateRoom(room);
|
manager?.CreateRoom(room);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SettingsTextBox : OsuTextBox
|
private class SettingsTextBox : OsuTextBox
|
||||||
@ -291,5 +318,18 @@ namespace osu.Game.Screens.Multi.Match.Components
|
|||||||
Triangles.ColourDark = colours.YellowDark;
|
Triangles.ColourDark = colours.YellowDark;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class DurationDropdown : OsuDropdown<TimeSpan>
|
||||||
|
{
|
||||||
|
public DurationDropdown()
|
||||||
|
{
|
||||||
|
Menu.MaxHeight = 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string GenerateItemText(TimeSpan item)
|
||||||
|
{
|
||||||
|
return item.Humanize();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ namespace osu.Game.Screens.Multi.Match
|
|||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Padding = new MarginPadding { Top = Components.Header.HEIGHT },
|
Padding = new MarginPadding { Top = Components.Header.HEIGHT },
|
||||||
Child = settings = new RoomSettingsOverlay
|
Child = settings = new RoomSettingsOverlay(room)
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Height = 0.9f,
|
Height = 0.9f,
|
||||||
|
Loading…
Reference in New Issue
Block a user