mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 05:22:54 +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 },
|
||||
};
|
||||
|
||||
Add(overlay = new TestRoomSettingsOverlay
|
||||
Add(overlay = new TestRoomSettingsOverlay(new Room())
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Height = 0.75f,
|
||||
@ -84,6 +84,11 @@ namespace osu.Game.Tests.Visual
|
||||
|
||||
private class TestRoomSettingsOverlay : RoomSettingsOverlay
|
||||
{
|
||||
public TestRoomSettingsOverlay(Room room)
|
||||
: base(room)
|
||||
{
|
||||
}
|
||||
|
||||
public string CurrentName
|
||||
{
|
||||
get => NameField.Text;
|
||||
|
@ -29,12 +29,18 @@ namespace osu.Game.Online.Multiplayer
|
||||
[JsonProperty("playlist")]
|
||||
public readonly BindableCollection<PlaylistItem> Playlist = new BindableCollection<PlaylistItem>();
|
||||
|
||||
[JsonProperty("duration")]
|
||||
public readonly Bindable<int> Duration = new Bindable<int>(100);
|
||||
[JsonIgnore]
|
||||
public readonly Bindable<TimeSpan> Duration = new Bindable<TimeSpan>(TimeSpan.FromMinutes(30));
|
||||
|
||||
[JsonIgnore]
|
||||
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)
|
||||
[JsonProperty("max_attempts", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
private int? maxAttempts
|
||||
|
@ -1,6 +1,8 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using Humanizer;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Configuration;
|
||||
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<int?> maxParticipantsBind = new Bindable<int?>();
|
||||
private readonly IBindableCollection<PlaylistItem> playlistBind = new BindableCollection<PlaylistItem>();
|
||||
private readonly Bindable<TimeSpan> durationBind = new Bindable<TimeSpan>();
|
||||
|
||||
private readonly Container content;
|
||||
|
||||
private readonly OsuSpriteText typeLabel;
|
||||
|
||||
protected readonly OsuTextBox NameField, MaxParticipantsField;
|
||||
protected readonly OsuDropdown<TimeSpan> DurationField;
|
||||
protected readonly RoomAvailabilityPicker AvailabilityPicker;
|
||||
protected readonly GameTypePicker TypePicker;
|
||||
protected readonly TriangleButton ApplyButton;
|
||||
protected readonly OsuPasswordTextBox PasswordField;
|
||||
|
||||
[Resolved]
|
||||
private readonly Room room;
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private RoomManager manager { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private Room room { get; set; }
|
||||
|
||||
public RoomSettingsOverlay()
|
||||
public RoomSettingsOverlay(Room room)
|
||||
{
|
||||
this.room = room;
|
||||
|
||||
Masking = true;
|
||||
|
||||
Child = content = new Container
|
||||
@ -121,6 +126,26 @@ namespace osu.Game.Screens.Multi.Match.Components
|
||||
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)")
|
||||
{
|
||||
Child = PasswordField = new SettingsPasswordTextBox
|
||||
@ -151,6 +176,7 @@ namespace osu.Game.Screens.Multi.Match.Components
|
||||
availabilityBind.ValueChanged += a => AvailabilityPicker.Current.Value = a;
|
||||
typeBind.ValueChanged += t => TypePicker.Current.Value = t;
|
||||
maxParticipantsBind.ValueChanged += m => MaxParticipantsField.Text = m?.ToString();
|
||||
durationBind.ValueChanged += d => DurationField.Current.Value = d;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
@ -163,6 +189,7 @@ namespace osu.Game.Screens.Multi.Match.Components
|
||||
availabilityBind.BindTo(room.Availability);
|
||||
typeBind.BindTo(room.Type);
|
||||
maxParticipantsBind.BindTo(room.MaxParticipants);
|
||||
durationBind.BindTo(room.Duration);
|
||||
|
||||
MaxParticipantsField.ReadOnly = true;
|
||||
PasswordField.ReadOnly = true;
|
||||
@ -210,7 +237,7 @@ namespace osu.Game.Screens.Multi.Match.Components
|
||||
else
|
||||
maxParticipantsBind.Value = null;
|
||||
|
||||
manager.CreateRoom(room);
|
||||
manager?.CreateRoom(room);
|
||||
}
|
||||
|
||||
private class SettingsTextBox : OsuTextBox
|
||||
@ -291,5 +318,18 @@ namespace osu.Game.Screens.Multi.Match.Components
|
||||
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,
|
||||
Padding = new MarginPadding { Top = Components.Header.HEIGHT },
|
||||
Child = settings = new RoomSettingsOverlay
|
||||
Child = settings = new RoomSettingsOverlay(room)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Height = 0.9f,
|
||||
|
Loading…
Reference in New Issue
Block a user