2020-02-14 14:01:45 +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;
|
2020-07-10 18:37:27 +08:00
|
|
|
using System.Collections.Generic;
|
2020-02-14 14:01:45 +08:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2020-02-14 14:36:47 +08:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2020-02-14 14:01:45 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Colour;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osu.Framework.Threading;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Beatmaps.Drawables;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2020-02-15 15:56:11 +08:00
|
|
|
using osu.Game.Online;
|
2020-02-14 14:01:45 +08:00
|
|
|
using osu.Game.Online.Chat;
|
|
|
|
using osu.Game.Online.Multiplayer;
|
2020-04-21 15:03:18 +08:00
|
|
|
using osu.Game.Overlays.BeatmapListing.Panels;
|
2020-02-14 14:01:45 +08:00
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
using osu.Game.Screens.Play.HUD;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Multi
|
|
|
|
{
|
2020-02-14 14:36:47 +08:00
|
|
|
public class DrawableRoomPlaylistItem : OsuRearrangeableListItem<PlaylistItem>
|
2020-02-14 14:01:45 +08:00
|
|
|
{
|
|
|
|
public Action<PlaylistItem> RequestDeletion;
|
|
|
|
|
2020-02-14 15:55:05 +08:00
|
|
|
public readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
|
|
|
|
|
2020-02-14 14:01:45 +08:00
|
|
|
private Container maskingContainer;
|
|
|
|
private Container difficultyIconContainer;
|
|
|
|
private LinkFlowContainer beatmapText;
|
|
|
|
private LinkFlowContainer authorText;
|
|
|
|
private ModDisplay modDisplay;
|
|
|
|
|
|
|
|
private readonly Bindable<BeatmapInfo> beatmap = new Bindable<BeatmapInfo>();
|
|
|
|
private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
|
|
|
|
private readonly BindableList<Mod> requiredMods = new BindableList<Mod>();
|
|
|
|
|
2020-07-10 18:37:27 +08:00
|
|
|
public readonly PlaylistItem Item;
|
|
|
|
|
2020-02-14 14:01:45 +08:00
|
|
|
private readonly bool allowEdit;
|
|
|
|
private readonly bool allowSelection;
|
|
|
|
|
2020-02-20 17:32:28 +08:00
|
|
|
protected override bool ShouldBeConsideredForInput(Drawable child) => allowEdit || !allowSelection || SelectedItem.Value == Model;
|
2020-02-15 15:47:55 +08:00
|
|
|
|
2020-02-14 14:01:45 +08:00
|
|
|
public DrawableRoomPlaylistItem(PlaylistItem item, bool allowEdit, bool allowSelection)
|
|
|
|
: base(item)
|
|
|
|
{
|
2020-07-10 18:37:27 +08:00
|
|
|
Item = item;
|
|
|
|
|
|
|
|
// TODO: edit support should be moved out into a derived class
|
2020-02-14 14:01:45 +08:00
|
|
|
this.allowEdit = allowEdit;
|
|
|
|
this.allowSelection = allowSelection;
|
|
|
|
|
|
|
|
beatmap.BindTo(item.Beatmap);
|
|
|
|
ruleset.BindTo(item.Ruleset);
|
|
|
|
requiredMods.BindTo(item.RequiredMods);
|
2020-09-08 15:36:36 +08:00
|
|
|
|
|
|
|
ShowDragHandle.Value = allowEdit;
|
2020-02-14 14:01:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
{
|
2020-02-14 14:36:47 +08:00
|
|
|
if (!allowEdit)
|
|
|
|
HandleColour = HandleColour.Opacity(0);
|
|
|
|
|
|
|
|
maskingContainer.BorderColour = colours.Yellow;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2020-02-14 20:17:07 +08:00
|
|
|
SelectedItem.BindValueChanged(selected => maskingContainer.BorderThickness = selected.NewValue == Model ? 5 : 0, true);
|
2020-02-14 15:55:05 +08:00
|
|
|
|
2020-02-14 14:36:47 +08:00
|
|
|
beatmap.BindValueChanged(_ => scheduleRefresh());
|
|
|
|
ruleset.BindValueChanged(_ => scheduleRefresh());
|
|
|
|
|
2020-02-17 14:06:14 +08:00
|
|
|
requiredMods.CollectionChanged += (_, __) => scheduleRefresh();
|
2020-02-14 14:36:47 +08:00
|
|
|
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
2020-02-14 15:55:05 +08:00
|
|
|
private ScheduledDelegate scheduledRefresh;
|
|
|
|
|
|
|
|
private void scheduleRefresh()
|
|
|
|
{
|
|
|
|
scheduledRefresh?.Cancel();
|
|
|
|
scheduledRefresh = Schedule(refresh);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void refresh()
|
|
|
|
{
|
2020-09-30 23:53:25 +08:00
|
|
|
difficultyIconContainer.Child = new DifficultyIcon(beatmap.Value, ruleset.Value, requiredMods) { Size = new Vector2(32) };
|
2020-02-14 15:55:05 +08:00
|
|
|
|
|
|
|
beatmapText.Clear();
|
2020-07-10 18:37:27 +08:00
|
|
|
beatmapText.AddLink(Item.Beatmap.ToString(), LinkAction.OpenBeatmap, Item.Beatmap.Value.OnlineBeatmapID.ToString());
|
2020-02-14 15:55:05 +08:00
|
|
|
|
|
|
|
authorText.Clear();
|
|
|
|
|
2020-07-10 18:37:27 +08:00
|
|
|
if (Item.Beatmap?.Value?.Metadata?.Author != null)
|
2020-02-14 15:55:05 +08:00
|
|
|
{
|
|
|
|
authorText.AddText("mapped by ");
|
2020-07-10 18:37:27 +08:00
|
|
|
authorText.AddUserLink(Item.Beatmap.Value?.Metadata.Author);
|
2020-02-14 15:55:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
modDisplay.Current.Value = requiredMods.ToArray();
|
|
|
|
}
|
|
|
|
|
2020-02-14 14:36:47 +08:00
|
|
|
protected override Drawable CreateContent() => maskingContainer = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Height = 50,
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = 10,
|
|
|
|
Children = new Drawable[]
|
2020-02-14 14:01:45 +08:00
|
|
|
{
|
2020-02-14 14:36:47 +08:00
|
|
|
new Box // A transparent box that forces the border to be drawn if the panel background is opaque
|
2020-02-14 14:01:45 +08:00
|
|
|
{
|
2020-02-14 14:36:47 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Alpha = 0,
|
|
|
|
AlwaysPresent = true
|
|
|
|
},
|
|
|
|
new PanelBackground
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Beatmap = { BindTarget = beatmap }
|
|
|
|
},
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Padding = new MarginPadding { Left = 8 },
|
|
|
|
Spacing = new Vector2(8, 0),
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Children = new Drawable[]
|
2020-02-14 14:01:45 +08:00
|
|
|
{
|
2020-02-14 14:36:47 +08:00
|
|
|
difficultyIconContainer = new Container
|
2020-02-14 14:01:45 +08:00
|
|
|
{
|
2020-02-14 14:36:47 +08:00
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
2020-02-14 14:01:45 +08:00
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
},
|
2020-02-14 14:36:47 +08:00
|
|
|
new FillFlowContainer
|
2020-02-14 14:01:45 +08:00
|
|
|
{
|
2020-02-14 14:36:47 +08:00
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Vertical,
|
2020-02-14 14:01:45 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2020-02-14 14:36:47 +08:00
|
|
|
beatmapText = new LinkFlowContainer { AutoSizeAxes = Axes.Both },
|
2020-02-14 14:01:45 +08:00
|
|
|
new FillFlowContainer
|
|
|
|
{
|
2020-02-14 14:36:47 +08:00
|
|
|
AutoSizeAxes = Axes.Both,
|
2020-02-14 14:01:45 +08:00
|
|
|
Direction = FillDirection.Horizontal,
|
2020-04-04 02:30:02 +08:00
|
|
|
Spacing = new Vector2(15, 0),
|
2020-02-14 14:01:45 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2020-02-14 14:36:47 +08:00
|
|
|
authorText = new LinkFlowContainer { AutoSizeAxes = Axes.Both },
|
|
|
|
modDisplay = new ModDisplay
|
2020-02-14 14:01:45 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2020-02-14 14:36:47 +08:00
|
|
|
Scale = new Vector2(0.4f),
|
|
|
|
DisplayUnrankedText = false,
|
|
|
|
ExpansionMode = ExpansionMode.AlwaysExpanded
|
2020-02-14 14:01:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-02-14 14:36:47 +08:00
|
|
|
}
|
2020-02-14 14:01:45 +08:00
|
|
|
},
|
2020-07-10 19:32:47 +08:00
|
|
|
new FillFlowContainer
|
2020-02-14 14:36:47 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
2020-07-10 18:37:27 +08:00
|
|
|
Direction = FillDirection.Horizontal,
|
2020-02-14 14:36:47 +08:00
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
X = -18,
|
2020-07-10 18:37:27 +08:00
|
|
|
ChildrenEnumerable = CreateButtons()
|
2020-02-14 14:36:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2020-02-14 14:01:45 +08:00
|
|
|
|
2020-07-10 18:37:27 +08:00
|
|
|
protected virtual IEnumerable<Drawable> CreateButtons() =>
|
|
|
|
new Drawable[]
|
|
|
|
{
|
|
|
|
new PlaylistDownloadButton(Item)
|
|
|
|
{
|
|
|
|
Size = new Vector2(50, 30)
|
|
|
|
},
|
|
|
|
new IconButton
|
|
|
|
{
|
|
|
|
Icon = FontAwesome.Solid.MinusSquare,
|
|
|
|
Alpha = allowEdit ? 1 : 0,
|
|
|
|
Action = () => RequestDeletion?.Invoke(Model),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-02-14 14:01:45 +08:00
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
{
|
|
|
|
if (allowSelection)
|
2020-02-14 15:55:05 +08:00
|
|
|
SelectedItem.Value = Model;
|
2020-02-14 14:01:45 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-21 15:03:18 +08:00
|
|
|
private class PlaylistDownloadButton : BeatmapPanelDownloadButton
|
2020-02-15 15:56:11 +08:00
|
|
|
{
|
2020-06-02 13:04:51 +08:00
|
|
|
private readonly PlaylistItem playlistItem;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private BeatmapManager beatmapManager { get; set; }
|
|
|
|
|
|
|
|
public PlaylistDownloadButton(PlaylistItem playlistItem)
|
|
|
|
: base(playlistItem.Beatmap.Value.BeatmapSet)
|
2020-02-15 15:56:11 +08:00
|
|
|
{
|
2020-06-02 13:04:51 +08:00
|
|
|
this.playlistItem = playlistItem;
|
2020-02-15 15:56:11 +08:00
|
|
|
Alpha = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
State.BindValueChanged(stateChanged, true);
|
2020-06-02 13:04:51 +08:00
|
|
|
FinishTransforms(true);
|
2020-02-15 15:56:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void stateChanged(ValueChangedEvent<DownloadState> state)
|
|
|
|
{
|
2020-06-02 13:04:51 +08:00
|
|
|
switch (state.NewValue)
|
|
|
|
{
|
|
|
|
case DownloadState.LocallyAvailable:
|
|
|
|
// Perform a local query of the beatmap by beatmap checksum, and reset the state if not matching.
|
|
|
|
if (beatmapManager.QueryBeatmap(b => b.MD5Hash == playlistItem.Beatmap.Value.MD5Hash) == null)
|
|
|
|
State.Value = DownloadState.NotDownloaded;
|
|
|
|
else
|
|
|
|
this.FadeTo(0, 500);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
this.FadeTo(1, 500);
|
|
|
|
break;
|
|
|
|
}
|
2020-02-15 15:56:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-14 14:01:45 +08:00
|
|
|
// For now, this is the same implementation as in PanelBackground, but supports a beatmap info rather than a working beatmap
|
|
|
|
private class PanelBackground : Container // todo: should be a buffered container (https://github.com/ppy/osu-framework/issues/3222)
|
|
|
|
{
|
|
|
|
public readonly Bindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
|
|
|
|
|
|
|
|
public PanelBackground()
|
|
|
|
{
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
new UpdateableBeatmapBackgroundSprite
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
FillMode = FillMode.Fill,
|
|
|
|
Beatmap = { BindTarget = Beatmap }
|
|
|
|
},
|
2020-02-27 12:32:23 +08:00
|
|
|
new FillFlowContainer
|
2020-02-14 14:01:45 +08:00
|
|
|
{
|
|
|
|
Depth = -1,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-02-27 12:32:23 +08:00
|
|
|
Direction = FillDirection.Horizontal,
|
2020-02-14 14:01:45 +08:00
|
|
|
// This makes the gradient not be perfectly horizontal, but diagonal at a ~40° angle
|
|
|
|
Shear = new Vector2(0.8f, 0),
|
|
|
|
Alpha = 0.5f,
|
|
|
|
Children = new[]
|
|
|
|
{
|
|
|
|
// The left half with no gradient applied
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.Black,
|
|
|
|
Width = 0.4f,
|
|
|
|
},
|
|
|
|
// Piecewise-linear gradient with 3 segments to make it appear smoother
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = ColourInfo.GradientHorizontal(Color4.Black, new Color4(0f, 0f, 0f, 0.9f)),
|
|
|
|
Width = 0.05f,
|
|
|
|
},
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = ColourInfo.GradientHorizontal(new Color4(0f, 0f, 0f, 0.9f), new Color4(0f, 0f, 0f, 0.1f)),
|
|
|
|
Width = 0.2f,
|
|
|
|
},
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = ColourInfo.GradientHorizontal(new Color4(0f, 0f, 0f, 0.1f), new Color4(0, 0, 0, 0)),
|
|
|
|
Width = 0.05f,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|