1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-11 06:32:53 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/Match/DrawableMatchRoom.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

91 lines
2.7 KiB
C#
Raw Normal View History

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;
using osu.Game.Beatmaps.Drawables;
2021-08-18 14:12:16 +08:00
using osu.Game.Online.API;
using osu.Game.Online.Rooms;
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
{
public Action? OnEdit;
2021-08-18 14:12:16 +08:00
public new required Bindable<PlaylistItem?> SelectedItem
{
get => selectedItem;
set => selectedItem.Current = value;
}
2021-08-18 14:12:16 +08:00
[Resolved]
private IAPIProvider api { get; set; } = null!;
2021-08-18 14:12:16 +08:00
private readonly BindableWithCurrent<PlaylistItem?> selectedItem = new BindableWithCurrent<PlaylistItem?>();
2021-08-18 15:35:18 +08:00
private readonly bool allowEdit;
private Drawable? editButton;
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;
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
{
ButtonsContainer.Add(editButton = new PurpleRoundedButton
2021-08-18 15:35:18 +08:00
{
RelativeSizeAxes = Axes.Y,
Size = new Vector2(100, 1),
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
protected override UpdateableBeatmapBackgroundSprite CreateBackground() => base.CreateBackground().With(d =>
{
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
}
}