1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 21:27:24 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/Match/DrawableMatchRoom.cs

65 lines
1.8 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;
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;
using osu.Game.Online.API;
using osu.Game.Online.Rooms;
using osu.Game.Screens.OnlinePlay.Lounge.Components;
using osu.Game.Screens.OnlinePlay.Match.Components;
using osu.Game.Users;
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
{
public Action OnEdit;
[Resolved]
private IAPIProvider api { get; set; }
private readonly IBindable<User> host = new Bindable<User>();
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-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-18 14:12:16 +08:00
}
protected override bool ShouldBeConsideredForInput(Drawable child) => true;
}
}