mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Use CMC for all of multiplayer
This commit is contained in:
@ -22,43 +22,53 @@ namespace osu.Game.Screens.Multi.Match.Components
|
||||
{
|
||||
private const float transition_duration = 350;
|
||||
private const float field_padding = 45;
|
||||
private const float disabled_alpha = 0.2f;
|
||||
|
||||
private readonly RoomBindings bindings = new RoomBindings();
|
||||
protected MatchSettings Settings { get; private set; }
|
||||
|
||||
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;
|
||||
|
||||
protected readonly OsuSpriteText ErrorText;
|
||||
|
||||
private readonly ProcessingOverlay processingOverlay;
|
||||
|
||||
private readonly Room room;
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private IRoomManager manager { get; set; }
|
||||
|
||||
public MatchSettingsOverlay(Room room)
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
this.room = room;
|
||||
|
||||
bindings.Room = room;
|
||||
|
||||
Masking = true;
|
||||
|
||||
Child = content = new Container
|
||||
Child = Settings = new MatchSettings
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
RelativePositionAxes = Axes.Y,
|
||||
Children = new Drawable[]
|
||||
RelativePositionAxes = Axes.Y
|
||||
};
|
||||
}
|
||||
|
||||
protected override void PopIn()
|
||||
{
|
||||
Settings.MoveToY(0, transition_duration, Easing.OutQuint);
|
||||
}
|
||||
|
||||
protected override void PopOut()
|
||||
{
|
||||
Settings.MoveToY(-1, transition_duration, Easing.InSine);
|
||||
}
|
||||
|
||||
protected class MatchSettings : MultiplayerComposite
|
||||
{
|
||||
private const float disabled_alpha = 0.2f;
|
||||
|
||||
public OsuTextBox NameField, MaxParticipantsField;
|
||||
public OsuDropdown<TimeSpan> DurationField;
|
||||
public RoomAvailabilityPicker AvailabilityPicker;
|
||||
public GameTypePicker TypePicker;
|
||||
public TriangleButton ApplyButton;
|
||||
|
||||
public OsuSpriteText ErrorText;
|
||||
|
||||
private OsuSpriteText typeLabel;
|
||||
private ProcessingOverlay processingOverlay;
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private IRoomManager manager { get; set; }
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
@ -111,7 +121,10 @@ namespace osu.Game.Screens.Multi.Match.Components
|
||||
new Section("Room visibility")
|
||||
{
|
||||
Alpha = disabled_alpha,
|
||||
Child = AvailabilityPicker = new RoomAvailabilityPicker(),
|
||||
Child = AvailabilityPicker = new RoomAvailabilityPicker
|
||||
{
|
||||
Enabled = { Value = false }
|
||||
},
|
||||
},
|
||||
new Section("Game type")
|
||||
{
|
||||
@ -127,10 +140,12 @@ namespace osu.Game.Screens.Multi.Match.Components
|
||||
TypePicker = new GameTypePicker
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Enabled = { Value = false }
|
||||
},
|
||||
typeLabel = new OsuSpriteText
|
||||
{
|
||||
TextSize = 14,
|
||||
Colour = colours.Yellow
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -151,7 +166,8 @@ namespace osu.Game.Screens.Multi.Match.Components
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
TabbableContentContainer = this,
|
||||
OnCommit = (sender, text) => apply(),
|
||||
ReadOnly = true,
|
||||
OnCommit = (sender, text) => apply()
|
||||
},
|
||||
},
|
||||
new Section("Duration")
|
||||
@ -177,10 +193,11 @@ namespace osu.Game.Screens.Multi.Match.Components
|
||||
new Section("Password (optional)")
|
||||
{
|
||||
Alpha = disabled_alpha,
|
||||
Child = PasswordField = new SettingsPasswordTextBox
|
||||
Child = new SettingsPasswordTextBox
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
TabbableContentContainer = this,
|
||||
ReadOnly = true,
|
||||
OnCommit = (sender, text) => apply()
|
||||
},
|
||||
},
|
||||
@ -222,6 +239,7 @@ namespace osu.Game.Screens.Multi.Match.Components
|
||||
Anchor = Anchor.BottomCentre,
|
||||
Origin = Anchor.BottomCentre,
|
||||
Size = new Vector2(230, 55),
|
||||
Enabled = { Value = false },
|
||||
Action = apply,
|
||||
},
|
||||
ErrorText = new OsuSpriteText
|
||||
@ -229,7 +247,8 @@ namespace osu.Game.Screens.Multi.Match.Components
|
||||
Anchor = Anchor.BottomCentre,
|
||||
Origin = Anchor.BottomCentre,
|
||||
Alpha = 0,
|
||||
Depth = 1
|
||||
Depth = 1,
|
||||
Colour = colours.RedDark
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -239,80 +258,58 @@ namespace osu.Game.Screens.Multi.Match.Components
|
||||
}
|
||||
},
|
||||
processingOverlay = new ProcessingOverlay { Alpha = 0 }
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
TypePicker.Current.ValueChanged += t => typeLabel.Text = t.Name;
|
||||
TypePicker.Current.ValueChanged += t => typeLabel.Text = t.Name;
|
||||
|
||||
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);
|
||||
}
|
||||
Name.BindValueChanged(n => NameField.Text = n, true);
|
||||
Availability.BindValueChanged(a => AvailabilityPicker.Current.Value = a, true);
|
||||
Type.BindValueChanged(t => TypePicker.Current.Value = t, true);
|
||||
MaxParticipants.BindValueChanged(m => MaxParticipantsField.Text = m?.ToString(), true);
|
||||
Duration.BindValueChanged(d => DurationField.Current.Value = d, true);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
typeLabel.Colour = colours.Yellow;
|
||||
ErrorText.Colour = colours.RedDark;
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
MaxParticipantsField.ReadOnly = true;
|
||||
PasswordField.ReadOnly = true;
|
||||
AvailabilityPicker.Enabled.Value = false;
|
||||
TypePicker.Enabled.Value = false;
|
||||
ApplyButton.Enabled.Value = false;
|
||||
}
|
||||
ApplyButton.Enabled.Value = hasValidSettings;
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
private bool hasValidSettings => RoomID.Value == null && NameField.Text.Length > 0 && Playlist.Count > 0;
|
||||
|
||||
ApplyButton.Enabled.Value = hasValidSettings;
|
||||
}
|
||||
|
||||
private bool hasValidSettings => bindings.Room.RoomID.Value == null && NameField.Text.Length > 0 && bindings.Playlist.Count > 0;
|
||||
private void apply()
|
||||
{
|
||||
hideError();
|
||||
|
||||
protected override void PopIn()
|
||||
{
|
||||
content.MoveToY(0, transition_duration, Easing.OutQuint);
|
||||
}
|
||||
Name.Value = NameField.Text;
|
||||
Availability.Value = AvailabilityPicker.Current.Value;
|
||||
Type.Value = TypePicker.Current.Value;
|
||||
|
||||
protected override void PopOut()
|
||||
{
|
||||
content.MoveToY(-1, transition_duration, Easing.InSine);
|
||||
}
|
||||
if (int.TryParse(MaxParticipantsField.Text, out int max))
|
||||
MaxParticipants.Value = max;
|
||||
else
|
||||
MaxParticipants.Value = null;
|
||||
|
||||
private void apply()
|
||||
{
|
||||
hideError();
|
||||
Duration.Value = DurationField.Current.Value;
|
||||
|
||||
bindings.Name.Value = NameField.Text;
|
||||
bindings.Availability.Value = AvailabilityPicker.Current.Value;
|
||||
bindings.Type.Value = TypePicker.Current.Value;
|
||||
manager?.CreateRoom(Room, onSuccess, onError);
|
||||
|
||||
if (int.TryParse(MaxParticipantsField.Text, out int max))
|
||||
bindings.MaxParticipants.Value = max;
|
||||
else
|
||||
bindings.MaxParticipants.Value = null;
|
||||
processingOverlay.Show();
|
||||
}
|
||||
|
||||
bindings.Duration.Value = DurationField.Current.Value;
|
||||
private void hideError() => ErrorText.FadeOut(50);
|
||||
|
||||
manager?.CreateRoom(room, onSuccess, onError);
|
||||
private void onSuccess(Room room) => processingOverlay.Hide();
|
||||
|
||||
processingOverlay.Show();
|
||||
}
|
||||
private void onError(string text)
|
||||
{
|
||||
ErrorText.Text = text;
|
||||
ErrorText.FadeIn(50);
|
||||
|
||||
private void hideError() => ErrorText.FadeOut(50);
|
||||
|
||||
private void onSuccess(Room room) => processingOverlay.Hide();
|
||||
|
||||
private void onError(string text)
|
||||
{
|
||||
ErrorText.Text = text;
|
||||
ErrorText.FadeIn(50);
|
||||
|
||||
processingOverlay.Hide();
|
||||
processingOverlay.Hide();
|
||||
}
|
||||
}
|
||||
|
||||
private class SettingsTextBox : OsuTextBox
|
||||
|
Reference in New Issue
Block a user