1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 19:57:24 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/Multiplayer/Match/BeatmapSelectionControl.cs

102 lines
3.1 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Bindings;
using osu.Framework.Screens;
using osu.Game.Input.Bindings;
using osu.Game.Online.API;
using osu.Game.Screens.OnlinePlay.Match.Components;
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
{
public class BeatmapSelectionControl : RoomSubScreenComposite, IKeyBindingHandler<GlobalAction>
{
[Resolved]
2020-12-25 12:38:11 +08:00
private MultiplayerMatchSubScreen matchSubScreen { get; set; }
[Resolved]
private IAPIProvider api { get; set; }
private Container beatmapPanelContainer;
private Button selectButton;
public BeatmapSelectionControl()
{
AutoSizeAxes = Axes.Y;
}
[BackgroundDependencyLoader]
private void load()
{
InternalChild = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
beatmapPanelContainer = new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y
},
selectButton = new PurpleTriangleButton
{
RelativeSizeAxes = Axes.X,
Height = 40,
Text = "Select beatmap",
2020-12-25 12:38:11 +08:00
Action = () => matchSubScreen.Push(new MultiplayerMatchSongSelect()),
Alpha = 0
}
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
SelectedItem.BindValueChanged(_ => updateBeatmap(), true);
Host.BindValueChanged(host =>
{
if (RoomID.Value == null || host.NewValue?.Equals(api.LocalUser.Value) == true)
selectButton.Show();
else
selectButton.Hide();
}, true);
}
private void updateBeatmap()
{
if (SelectedItem.Value == null)
beatmapPanelContainer.Clear();
else
beatmapPanelContainer.Child = new DrawableRoomPlaylistItem(SelectedItem.Value, false, false);
}
public bool OnPressed(GlobalAction action)
{
// only handle keyboard input if there is no current selection.
if (SelectedItem.Value != null)
return false;
switch (action)
{
case GlobalAction.Select:
2021-08-05 12:22:59 +08:00
selectButton.TriggerClick();
return true;
}
return false;
}
public void OnReleased(GlobalAction action)
{
}
}
}