2018-06-06 11:29:52 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2018-12-03 19:50:40 +08:00
|
|
|
|
using System;
|
2018-06-06 11:53:24 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2018-06-06 16:38:43 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
2018-06-06 11:29:52 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Game.Graphics;
|
2018-06-06 11:53:24 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2018-06-06 13:38:09 +08:00
|
|
|
|
using osu.Game.Online.Multiplayer;
|
2018-06-06 16:20:03 +08:00
|
|
|
|
using osu.Game.Overlays.SearchableList;
|
2018-11-26 15:29:56 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-06-06 11:29:52 +08:00
|
|
|
|
|
2018-12-03 16:54:10 +08:00
|
|
|
|
namespace osu.Game.Screens.Multi.Components
|
2018-06-06 11:29:52 +08:00
|
|
|
|
{
|
2018-06-07 10:30:17 +08:00
|
|
|
|
public class RoomSettingsOverlay : FocusedOverlayContainer
|
2018-06-06 11:29:52 +08:00
|
|
|
|
{
|
2018-08-25 06:11:52 +08:00
|
|
|
|
private const float transition_duration = 350;
|
2018-06-06 16:20:03 +08:00
|
|
|
|
private const float field_padding = 45;
|
2018-06-06 11:29:52 +08:00
|
|
|
|
|
2018-12-03 19:50:40 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Invoked when room settings were applied.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Action Applied;
|
|
|
|
|
|
2018-06-06 16:38:43 +08:00
|
|
|
|
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?>();
|
2018-06-06 13:38:09 +08:00
|
|
|
|
|
2018-06-06 16:38:43 +08:00
|
|
|
|
private readonly Container content;
|
2018-12-06 17:16:17 +08:00
|
|
|
|
|
2018-06-07 11:39:16 +08:00
|
|
|
|
private readonly OsuSpriteText typeLabel;
|
2018-06-06 13:38:09 +08:00
|
|
|
|
|
2018-08-14 22:31:20 +08:00
|
|
|
|
protected readonly OsuTextBox NameField, MaxParticipantsField;
|
|
|
|
|
protected readonly RoomAvailabilityPicker AvailabilityPicker;
|
|
|
|
|
protected readonly GameTypePicker TypePicker;
|
|
|
|
|
protected readonly TriangleButton ApplyButton;
|
2018-06-07 10:30:17 +08:00
|
|
|
|
|
2018-12-04 14:25:41 +08:00
|
|
|
|
public RoomSettingsOverlay()
|
2018-06-06 11:29:52 +08:00
|
|
|
|
{
|
2018-06-06 15:27:53 +08:00
|
|
|
|
Masking = true;
|
|
|
|
|
|
|
|
|
|
Child = content = new Container
|
2018-06-06 11:29:52 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
RelativePositionAxes = Axes.Y,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = OsuColour.FromHex(@"28242d"),
|
|
|
|
|
},
|
2018-06-06 11:53:24 +08:00
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2018-06-06 16:20:03 +08:00
|
|
|
|
Padding = new MarginPadding { Top = 35, Bottom = 75, Horizontal = SearchableListOverlay.WIDTH_PADDING },
|
2018-06-06 11:53:24 +08:00
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
new SectionContainer
|
|
|
|
|
{
|
2018-06-06 16:20:03 +08:00
|
|
|
|
Padding = new MarginPadding { Right = field_padding / 2 },
|
2018-06-06 11:53:24 +08:00
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
2018-06-06 12:29:36 +08:00
|
|
|
|
new Section("ROOM NAME")
|
|
|
|
|
{
|
2018-08-14 22:31:20 +08:00
|
|
|
|
Child = NameField = new SettingsTextBox
|
2018-06-07 11:25:16 +08:00
|
|
|
|
{
|
2018-06-07 11:51:27 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2018-08-14 22:36:46 +08:00
|
|
|
|
TabbableContentContainer = this,
|
2018-06-07 11:25:16 +08:00
|
|
|
|
OnCommit = (sender, text) => apply(),
|
|
|
|
|
},
|
2018-06-06 12:29:36 +08:00
|
|
|
|
},
|
2018-06-06 13:25:08 +08:00
|
|
|
|
new Section("ROOM VISIBILITY")
|
|
|
|
|
{
|
2018-08-14 22:31:20 +08:00
|
|
|
|
Child = AvailabilityPicker = new RoomAvailabilityPicker(),
|
2018-06-06 13:25:08 +08:00
|
|
|
|
},
|
2018-06-06 13:06:33 +08:00
|
|
|
|
new Section("GAME TYPE")
|
|
|
|
|
{
|
2018-06-07 11:39:16 +08:00
|
|
|
|
Child = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Spacing = new Vector2(7),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2018-08-14 22:31:20 +08:00
|
|
|
|
TypePicker = new GameTypePicker
|
2018-06-07 11:39:16 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
},
|
|
|
|
|
typeLabel = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
TextSize = 14,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-06-06 13:06:33 +08:00
|
|
|
|
},
|
2018-06-06 11:53:24 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
new SectionContainer
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Origin = Anchor.TopRight,
|
2018-06-06 16:20:03 +08:00
|
|
|
|
Padding = new MarginPadding { Left = field_padding / 2 },
|
2018-06-06 11:53:24 +08:00
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
2018-06-06 12:29:36 +08:00
|
|
|
|
new Section("MAX PARTICIPANTS")
|
|
|
|
|
{
|
2018-08-25 06:19:16 +08:00
|
|
|
|
Child = MaxParticipantsField = new SettingsNumberTextBox
|
2018-06-07 11:25:16 +08:00
|
|
|
|
{
|
2018-06-07 11:51:27 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2018-08-14 22:36:46 +08:00
|
|
|
|
TabbableContentContainer = this,
|
2018-12-06 17:16:17 +08:00
|
|
|
|
Alpha = 0.2f,
|
|
|
|
|
ReadOnly = true,
|
2018-06-07 11:25:16 +08:00
|
|
|
|
OnCommit = (sender, text) => apply(),
|
|
|
|
|
},
|
2018-06-06 12:29:36 +08:00
|
|
|
|
},
|
|
|
|
|
new Section("PASSWORD (OPTIONAL)")
|
|
|
|
|
{
|
2018-08-14 23:08:00 +08:00
|
|
|
|
Child = new SettingsPasswordTextBox
|
2018-06-07 11:25:16 +08:00
|
|
|
|
{
|
2018-06-07 11:51:27 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2018-08-14 22:36:46 +08:00
|
|
|
|
TabbableContentContainer = this,
|
2018-06-07 11:25:16 +08:00
|
|
|
|
OnCommit = (sender, text) => apply(),
|
2018-12-05 16:01:14 +08:00
|
|
|
|
Alpha = 0.2f,
|
|
|
|
|
ReadOnly = true,
|
2018-06-07 11:25:16 +08:00
|
|
|
|
},
|
2018-06-06 12:29:36 +08:00
|
|
|
|
},
|
2018-06-06 11:53:24 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-08-14 22:31:20 +08:00
|
|
|
|
ApplyButton = new ApplySettingsButton
|
2018-06-06 11:53:24 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
|
Size = new Vector2(230, 35),
|
|
|
|
|
Margin = new MarginPadding { Bottom = 20 },
|
2018-06-07 11:25:16 +08:00
|
|
|
|
Action = apply,
|
2018-06-06 11:53:24 +08:00
|
|
|
|
},
|
2018-06-06 11:29:52 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
2018-06-06 16:38:43 +08:00
|
|
|
|
|
2018-08-14 22:31:20 +08:00
|
|
|
|
TypePicker.Current.ValueChanged += t => typeLabel.Text = t.Name;
|
2018-06-07 11:39:16 +08:00
|
|
|
|
|
2018-08-14 22:31:20 +08:00
|
|
|
|
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();
|
2018-06-06 16:38:43 +08:00
|
|
|
|
|
2018-12-05 16:01:14 +08:00
|
|
|
|
AvailabilityPicker.DisabledItems = new[]
|
|
|
|
|
{
|
|
|
|
|
RoomAvailability.FriendsOnly,
|
|
|
|
|
RoomAvailability.InviteOnly
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TypePicker.DisabledItems = new GameType[]
|
|
|
|
|
{
|
|
|
|
|
new GameTypeTag(),
|
|
|
|
|
new GameTypeVersus(),
|
|
|
|
|
new GameTypeTagTeam(),
|
|
|
|
|
new GameTypeTeamVersus(),
|
|
|
|
|
};
|
|
|
|
|
|
2018-12-04 14:25:41 +08:00
|
|
|
|
Room = new Room();
|
2018-06-06 11:29:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-07 11:39:16 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
typeLabel.Colour = colours.Yellow;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 14:25:41 +08:00
|
|
|
|
private Room room;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The room which settings are being applied to.
|
|
|
|
|
/// </summary>
|
2018-12-04 17:18:17 +08:00
|
|
|
|
public virtual Room Room
|
2018-12-04 14:25:41 +08:00
|
|
|
|
{
|
|
|
|
|
get => room;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (room == value)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-12-10 12:48:10 +08:00
|
|
|
|
if (room != null)
|
|
|
|
|
{
|
|
|
|
|
nameBind.UnbindFrom(room.Name);
|
|
|
|
|
availabilityBind.UnbindFrom(room.Availability);
|
|
|
|
|
typeBind.UnbindFrom(room.Type);
|
|
|
|
|
maxParticipantsBind.UnbindFrom(room.MaxParticipants);
|
|
|
|
|
}
|
2018-12-04 14:25:41 +08:00
|
|
|
|
|
2018-12-10 12:48:10 +08:00
|
|
|
|
room = value;
|
2018-12-04 14:25:41 +08:00
|
|
|
|
|
|
|
|
|
if (room != null)
|
|
|
|
|
{
|
|
|
|
|
nameBind.BindTo(room.Name);
|
|
|
|
|
availabilityBind.BindTo(room.Availability);
|
|
|
|
|
typeBind.BindTo(room.Type);
|
|
|
|
|
maxParticipantsBind.BindTo(room.MaxParticipants);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-06 11:29:52 +08:00
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
2018-06-06 16:38:43 +08:00
|
|
|
|
// reapply the rooms values if the overlay was completely closed
|
|
|
|
|
if (content.Y == -1)
|
|
|
|
|
{
|
|
|
|
|
nameBind.TriggerChange();
|
|
|
|
|
availabilityBind.TriggerChange();
|
|
|
|
|
typeBind.TriggerChange();
|
|
|
|
|
maxParticipantsBind.TriggerChange();
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-06 15:27:53 +08:00
|
|
|
|
content.MoveToY(0, transition_duration, Easing.OutQuint);
|
2018-06-06 11:29:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
2018-06-06 15:27:53 +08:00
|
|
|
|
content.MoveToY(-1, transition_duration, Easing.InSine);
|
2018-06-06 11:29:52 +08:00
|
|
|
|
}
|
2018-06-06 11:53:24 +08:00
|
|
|
|
|
2018-06-07 11:25:16 +08:00
|
|
|
|
private void apply()
|
|
|
|
|
{
|
2018-08-25 06:27:16 +08:00
|
|
|
|
nameBind.Value = NameField.Text;
|
|
|
|
|
availabilityBind.Value = AvailabilityPicker.Current.Value;
|
|
|
|
|
typeBind.Value = TypePicker.Current.Value;
|
|
|
|
|
|
|
|
|
|
if (int.TryParse(MaxParticipantsField.Text, out int max))
|
|
|
|
|
maxParticipantsBind.Value = max;
|
|
|
|
|
else
|
|
|
|
|
maxParticipantsBind.Value = null;
|
2018-06-07 11:25:16 +08:00
|
|
|
|
|
2018-12-03 19:50:40 +08:00
|
|
|
|
Applied?.Invoke();
|
2018-06-07 11:25:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-06 12:29:36 +08:00
|
|
|
|
private class SettingsTextBox : OsuTextBox
|
|
|
|
|
{
|
|
|
|
|
protected override Color4 BackgroundUnfocused => Color4.Black;
|
|
|
|
|
protected override Color4 BackgroundFocused => Color4.Black;
|
2018-08-14 23:08:00 +08:00
|
|
|
|
}
|
2018-06-06 12:29:36 +08:00
|
|
|
|
|
2018-08-25 06:19:16 +08:00
|
|
|
|
private class SettingsNumberTextBox : SettingsTextBox
|
|
|
|
|
{
|
|
|
|
|
protected override bool CanAddCharacter(char character) => char.IsNumber(character);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-14 23:08:00 +08:00
|
|
|
|
private class SettingsPasswordTextBox : OsuPasswordTextBox
|
|
|
|
|
{
|
|
|
|
|
protected override Color4 BackgroundUnfocused => Color4.Black;
|
|
|
|
|
protected override Color4 BackgroundFocused => Color4.Black;
|
2018-06-06 12:29:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-06 11:53:24 +08:00
|
|
|
|
private class SectionContainer : FillFlowContainer<Section>
|
|
|
|
|
{
|
|
|
|
|
public SectionContainer()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2018-06-06 16:20:03 +08:00
|
|
|
|
Width = 0.5f;
|
2018-06-06 11:53:24 +08:00
|
|
|
|
Direction = FillDirection.Vertical;
|
2018-06-06 16:20:03 +08:00
|
|
|
|
Spacing = new Vector2(field_padding);
|
2018-06-06 11:53:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class Section : Container
|
|
|
|
|
{
|
|
|
|
|
private readonly Container content;
|
|
|
|
|
|
|
|
|
|
protected override Container<Drawable> Content => content;
|
|
|
|
|
|
|
|
|
|
public Section(string title)
|
|
|
|
|
{
|
2018-06-06 12:29:36 +08:00
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
2018-06-06 11:53:24 +08:00
|
|
|
|
|
|
|
|
|
InternalChild = new FillFlowContainer
|
|
|
|
|
{
|
2018-06-06 12:29:36 +08:00
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2018-06-06 11:53:24 +08:00
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Spacing = new Vector2(5),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
TextSize = 12,
|
|
|
|
|
Font = @"Exo2.0-Bold",
|
|
|
|
|
Text = title.ToUpper(),
|
|
|
|
|
},
|
|
|
|
|
content = new Container
|
|
|
|
|
{
|
2018-06-06 12:29:36 +08:00
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2018-06-06 11:53:24 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-14 22:31:20 +08:00
|
|
|
|
private class ApplySettingsButton : TriangleButton
|
2018-06-06 11:53:24 +08:00
|
|
|
|
{
|
2018-08-14 22:31:20 +08:00
|
|
|
|
public ApplySettingsButton()
|
2018-06-06 11:53:24 +08:00
|
|
|
|
{
|
|
|
|
|
Text = "Apply";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
BackgroundColour = colours.Yellow;
|
2018-06-06 15:32:04 +08:00
|
|
|
|
Triangles.ColourLight = colours.YellowLight;
|
|
|
|
|
Triangles.ColourDark = colours.YellowDark;
|
2018-06-06 11:53:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-06 11:29:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|