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;
|
2024-11-13 16:32:32 +08:00
|
|
|
using System.ComponentModel;
|
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;
|
|
|
|
using osu.Game.Online.Rooms;
|
2022-01-28 12:53:48 +08:00
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2021-08-18 14:12:16 +08:00
|
|
|
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 partial class DrawableMatchRoom : DrawableRoom
|
2021-08-18 14:12:16 +08:00
|
|
|
{
|
2024-11-12 00:38:31 +08:00
|
|
|
public Action? OnEdit;
|
2021-08-18 14:12:16 +08:00
|
|
|
|
2024-11-12 19:32:59 +08:00
|
|
|
public new required Bindable<PlaylistItem?> SelectedItem
|
|
|
|
{
|
|
|
|
get => selectedItem;
|
|
|
|
set => selectedItem.Current = value;
|
|
|
|
}
|
|
|
|
|
2021-08-18 14:12:16 +08:00
|
|
|
[Resolved]
|
2024-11-12 00:38:31 +08:00
|
|
|
private IAPIProvider api { get; set; } = null!;
|
2021-08-18 14:12:16 +08:00
|
|
|
|
2024-11-12 19:32:59 +08:00
|
|
|
private readonly BindableWithCurrent<PlaylistItem?> selectedItem = new BindableWithCurrent<PlaylistItem?>();
|
2021-08-18 15:35:18 +08:00
|
|
|
private readonly bool allowEdit;
|
2024-11-12 00:38:31 +08:00
|
|
|
private Drawable? editButton;
|
2021-08-20 20:07:51 +08:00
|
|
|
|
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;
|
|
|
|
|
2024-11-12 00:38:31 +08:00
|
|
|
base.SelectedItem.BindTo(SelectedItem);
|
2021-08-18 14:12:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2021-08-18 15:35:18 +08:00
|
|
|
if (allowEdit)
|
2021-08-18 14:12:16 +08:00
|
|
|
{
|
2022-11-24 15:26:57 +08:00
|
|
|
ButtonsContainer.Add(editButton = new PurpleRoundedButton
|
2021-08-18 15:35:18 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
Size = new Vector2(100, 1),
|
2022-01-28 12:53:48 +08:00
|
|
|
Text = CommonStrings.ButtonsEdit,
|
2021-08-18 15:35:18 +08:00
|
|
|
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
|
|
|
|
2024-11-13 16:32:32 +08:00
|
|
|
Room.PropertyChanged += onRoomPropertyChanged;
|
|
|
|
updateRoomHost();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
|
|
|
{
|
|
|
|
if (e.PropertyName == nameof(Room.Host))
|
|
|
|
updateRoomHost();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateRoomHost()
|
|
|
|
{
|
2021-08-18 15:35:18 +08:00
|
|
|
if (editButton != null)
|
2024-11-13 16:32:32 +08:00
|
|
|
editButton.Alpha = Room.Host?.Equals(api.LocalUser.Value) == true ? 1 : 0;
|
2021-08-18 14:12:16 +08:00
|
|
|
}
|
2021-08-19 14:52:51 +08:00
|
|
|
|
2024-11-12 00:38:31 +08:00
|
|
|
protected override UpdateableBeatmapBackgroundSprite CreateBackground() => base.CreateBackground().With(d =>
|
2021-08-20 20:07:51 +08:00
|
|
|
{
|
2024-11-12 00:38:31 +08:00
|
|
|
d.BackgroundLoadDelay = 0;
|
|
|
|
});
|
2024-11-13 16:32:32 +08:00
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
Room.PropertyChanged -= onRoomPropertyChanged;
|
|
|
|
}
|
2021-08-18 14:12:16 +08:00
|
|
|
}
|
|
|
|
}
|