Cleanup bindable handling

This commit is contained in:
smoogipoo
2018-12-22 14:01:06 +09:00
parent 1cb69c3478
commit f1a9a352fc
13 changed files with 269 additions and 269 deletions

View File

@ -27,9 +27,9 @@ namespace osu.Game.Screens.Multi.Match.Components
{
public const float HEIGHT = 200;
public readonly Bindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
public readonly IBindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
public readonly IBindable<GameType> Type = new Bindable<GameType>();
public readonly Bindable<IEnumerable<Mod>> Mods = new Bindable<IEnumerable<Mod>>();
public readonly IBindable<IEnumerable<Mod>> Mods = new Bindable<IEnumerable<Mod>>();
private readonly Box tabStrip;
@ -116,11 +116,11 @@ namespace osu.Game.Screens.Multi.Match.Components
beatmapTypeInfo.Beatmap.BindTo(Beatmap);
beatmapTypeInfo.Type.BindTo(Type);
modDisplay.Current.BindTo(Mods);
background.Beatmap.BindTo(Beatmap);
Mods.BindValueChanged(m => modDisplay.Current.Value = m, true);
beatmapButton.Action = () => OnRequestSelectBeatmap?.Invoke();
background.Beatmap.BindTo(Beatmap);
}
[BackgroundDependencyLoader]

View File

@ -26,11 +26,11 @@ namespace osu.Game.Screens.Multi.Match.Components
private OsuColour colours;
public readonly Bindable<string> Name = new Bindable<string>();
public readonly Bindable<RoomAvailability> Availability = new Bindable<RoomAvailability>();
public readonly Bindable<RoomStatus> Status = new Bindable<RoomStatus>();
public readonly Bindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
public readonly Bindable<DateTimeOffset> EndDate = new Bindable<DateTimeOffset>();
public readonly IBindable<string> Name = new Bindable<string>();
public readonly IBindable<RoomAvailability> Availability = new Bindable<RoomAvailability>();
public readonly IBindable<RoomStatus> Status = new Bindable<RoomStatus>();
public readonly IBindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
public readonly IBindable<DateTimeOffset> EndDate = new Bindable<DateTimeOffset>();
public Info(Room room)
{

View File

@ -15,14 +15,8 @@ namespace osu.Game.Screens.Multi.Match.Components
{
public class Participants : CompositeDrawable
{
public readonly Bindable<IEnumerable<User>> Users = new Bindable<IEnumerable<User>>();
public readonly Bindable<int?> MaxParticipants = new Bindable<int?>();
public new MarginPadding Padding
{
get => base.Padding;
set => base.Padding = value;
}
public readonly IBindable<IEnumerable<User>> Users = new Bindable<IEnumerable<User>>();
public readonly IBindable<int?> MaxParticipants = new Bindable<int?>();
public Participants()
{

View File

@ -4,7 +4,6 @@
using System;
using Humanizer;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -24,12 +23,7 @@ namespace osu.Game.Screens.Multi.Match.Components
private const float transition_duration = 350;
private const float field_padding = 45;
private readonly Bindable<string> nameBind = new Bindable<string>();
private readonly Bindable<RoomAvailability> availabilityBind = new Bindable<RoomAvailability>();
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 RoomBindings bindings = new RoomBindings();
private readonly Container content;
@ -51,6 +45,8 @@ namespace osu.Game.Screens.Multi.Match.Components
{
this.room = room;
bindings.Room = room;
Masking = true;
Child = content = new Container
@ -189,11 +185,11 @@ namespace osu.Game.Screens.Multi.Match.Components
TypePicker.Current.ValueChanged += t => typeLabel.Text = t.Name;
nameBind.ValueChanged += n => NameField.Text = n;
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;
bindings.Name.BindValueChanged(n => NameField.Text = n, true);
bindings.Availability.BindValueChanged(a => AvailabilityPicker.Current.Value = a, true);
bindings.Type.BindValueChanged(t => TypePicker.Current.Value = t, true);
bindings.MaxParticipants.BindValueChanged(m => MaxParticipantsField.Text = m?.ToString(), true);
bindings.Duration.BindValueChanged(d => DurationField.Current.Value = d, true);
}
[BackgroundDependencyLoader]
@ -201,13 +197,6 @@ namespace osu.Game.Screens.Multi.Match.Components
{
typeLabel.Colour = colours.Yellow;
nameBind.BindTo(room.Name);
playlistBind.BindTo(room.Playlist);
availabilityBind.BindTo(room.Availability);
typeBind.BindTo(room.Type);
maxParticipantsBind.BindTo(room.MaxParticipants);
durationBind.BindTo(room.Duration);
MaxParticipantsField.ReadOnly = true;
PasswordField.ReadOnly = true;
AvailabilityPicker.ReadOnly.Value = true;
@ -222,19 +211,10 @@ namespace osu.Game.Screens.Multi.Match.Components
ApplyButton.Enabled.Value = hasValidSettings;
}
private bool hasValidSettings => NameField.Text.Length > 0 && playlistBind.Count > 0;
private bool hasValidSettings => NameField.Text.Length > 0 && bindings.Playlist.Count > 0;
protected override void PopIn()
{
// reapply the rooms values if the overlay was completely closed
if (content.Y == -1)
{
nameBind.TriggerChange();
availabilityBind.TriggerChange();
typeBind.TriggerChange();
maxParticipantsBind.TriggerChange();
}
content.MoveToY(0, transition_duration, Easing.OutQuint);
}
@ -245,16 +225,16 @@ namespace osu.Game.Screens.Multi.Match.Components
private void apply()
{
nameBind.Value = NameField.Text;
availabilityBind.Value = AvailabilityPicker.Current.Value;
typeBind.Value = TypePicker.Current.Value;
bindings.Name.Value = NameField.Text;
bindings.Availability.Value = AvailabilityPicker.Current.Value;
bindings.Type.Value = TypePicker.Current.Value;
if (int.TryParse(MaxParticipantsField.Text, out int max))
maxParticipantsBind.Value = max;
bindings.MaxParticipants.Value = max;
else
maxParticipantsBind.Value = null;
bindings.MaxParticipants.Value = null;
durationBind.Value = DurationField.Current.Value;
bindings.Duration.Value = DurationField.Current.Value;
manager?.CreateRoom(room);
}