1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 06:33:32 +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.

79 lines
2.3 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.
2022-06-17 15:37:17 +08:00
#nullable disable
2021-08-18 14:12:16 +08:00
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.Beatmaps.Drawables;
2021-08-18 14:12:16 +08:00
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
2021-08-18 14:12:16 +08:00
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 readonly IBindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
2021-08-18 14:12:16 +08:00
public Action OnEdit;
[Resolved]
private IAPIProvider api { get; set; }
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;
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
{
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
if (editButton != null)
host.BindValueChanged(h => editButton.Alpha = h.NewValue?.Equals(api.LocalUser.Value) == true ? 1 : 0, true);
SelectedItem.BindValueChanged(item => background.Beatmap.Value = item.NewValue?.Beatmap, true);
2021-08-18 14:12:16 +08:00
}
2021-08-19 14:52:51 +08:00
protected override Drawable CreateBackground() => background = new BackgroundSprite();
private partial class BackgroundSprite : UpdateableBeatmapBackgroundSprite
{
protected override double LoadDelay => 0;
}
2021-08-18 14:12:16 +08:00
}
}