2021-08-18 14:12:16 +08:00
|
|
|
// 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 System;
|
2021-08-18 15:35:18 +08:00
|
|
|
using JetBrains.Annotations;
|
2021-08-18 14:12:16 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
2021-08-20 20:07:51 +08:00
|
|
|
using osu.Game.Beatmaps.Drawables;
|
2021-08-18 14:12:16 +08:00
|
|
|
using osu.Game.Online.API;
|
2021-11-04 17:02:44 +08:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2021-08-18 14:12:16 +08:00
|
|
|
using osu.Game.Online.Rooms;
|
|
|
|
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
|
|
|
using osu.Game.Screens.OnlinePlay.Match.Components;
|
|
|
|
using osuTK;
|
|
|
|
|
2021-08-18 14:16:48 +08:00
|
|
|
namespace osu.Game.Screens.OnlinePlay.Match
|
2021-08-18 14:12:16 +08:00
|
|
|
{
|
2021-08-18 14:16:48 +08:00
|
|
|
public class DrawableMatchRoom : DrawableRoom
|
2021-08-18 14:12:16 +08:00
|
|
|
{
|
2021-08-20 20:07:51 +08:00
|
|
|
public readonly IBindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
|
2021-08-18 14:12:16 +08:00
|
|
|
public Action OnEdit;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private IAPIProvider api { get; set; }
|
|
|
|
|
2021-11-04 17:02:44 +08:00
|
|
|
private readonly IBindable<APIUser> host = new Bindable<APIUser>();
|
2021-08-18 15:35:18 +08:00
|
|
|
private readonly bool allowEdit;
|
2021-08-18 14:12:16 +08:00
|
|
|
|
2021-08-18 15:35:18 +08:00
|
|
|
[CanBeNull]
|
2021-08-18 14:12:16 +08:00
|
|
|
private Drawable editButton;
|
|
|
|
|
2021-08-20 20:07:51 +08:00
|
|
|
private BackgroundSprite background;
|
|
|
|
|
2021-08-18 15:35:18 +08:00
|
|
|
public DrawableMatchRoom(Room room, bool allowEdit = true)
|
2021-08-18 14:12:16 +08:00
|
|
|
: base(room)
|
|
|
|
{
|
2021-08-18 15:35:18 +08:00
|
|
|
this.allowEdit = allowEdit;
|
|
|
|
|
2021-08-18 14:12:16 +08:00
|
|
|
host.BindTo(room.Host);
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2021-08-18 15:35:18 +08:00
|
|
|
if (allowEdit)
|
2021-08-18 14:12:16 +08:00
|
|
|
{
|
2021-08-18 15:35:18 +08:00
|
|
|
ButtonsContainer.Add(editButton = new PurpleTriangleButton
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
Size = new Vector2(100, 1),
|
|
|
|
Text = "Edit",
|
|
|
|
Action = () => OnEdit?.Invoke()
|
|
|
|
});
|
|
|
|
}
|
2021-08-18 14:12:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2021-08-18 15:35:18 +08:00
|
|
|
|
|
|
|
if (editButton != null)
|
|
|
|
host.BindValueChanged(h => editButton.Alpha = h.NewValue?.Equals(api.LocalUser.Value) == true ? 1 : 0, true);
|
2021-08-20 20:07:51 +08:00
|
|
|
|
|
|
|
SelectedItem.BindValueChanged(item => background.Beatmap.Value = item.NewValue?.Beatmap.Value, true);
|
2021-08-18 14:12:16 +08:00
|
|
|
}
|
2021-08-19 14:52:51 +08:00
|
|
|
|
2021-08-20 20:07:51 +08:00
|
|
|
protected override Drawable CreateBackground() => background = new BackgroundSprite();
|
|
|
|
|
|
|
|
private class BackgroundSprite : UpdateableBeatmapBackgroundSprite
|
|
|
|
{
|
|
|
|
protected override double LoadDelay => 0;
|
|
|
|
}
|
2021-08-18 14:12:16 +08:00
|
|
|
}
|
|
|
|
}
|