Add edit button to DrawableRoomPlaylistItem

This commit is contained in:
Dan Balasescu 2021-12-10 01:08:54 +09:00
parent 4d1c06c061
commit 048a495115
3 changed files with 65 additions and 1 deletions

View File

@ -255,6 +255,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
p.AllowDeletion = true; p.AllowDeletion = true;
p.AllowShowingResults = true; p.AllowShowingResults = true;
p.AllowEditing = true;
}); });
} }

View File

@ -33,6 +33,11 @@ namespace osu.Game.Screens.OnlinePlay
/// </summary> /// </summary>
public Action<PlaylistItem> RequestResults; public Action<PlaylistItem> RequestResults;
/// <summary>
/// Invoked when an item requests to be edited.
/// </summary>
public Action<PlaylistItem> RequestEdit;
private bool allowReordering; private bool allowReordering;
/// <summary> /// <summary>
@ -104,6 +109,24 @@ namespace osu.Game.Screens.OnlinePlay
} }
} }
private bool allowEditing;
/// <summary>
/// Whether to allow items to be edited.
/// If <c>true</c>, requests to edit items may be satisfied via <see cref="RequestEdit"/>.
/// </summary>
public bool AllowEditing
{
get => allowEditing;
set
{
allowEditing = value;
foreach (var item in ListContainer.OfType<DrawableRoomPlaylistItem>())
item.AllowEditing = value;
}
}
private bool showItemOwners; private bool showItemOwners;
/// <summary> /// <summary>
@ -135,12 +158,14 @@ namespace osu.Game.Screens.OnlinePlay
{ {
d.SelectedItem.BindTarget = SelectedItem; d.SelectedItem.BindTarget = SelectedItem;
d.RequestDeletion = i => RequestDeletion?.Invoke(i); d.RequestDeletion = i => RequestDeletion?.Invoke(i);
d.RequestResults = i => RequestResults?.Invoke(i);
d.RequestEdit = i => RequestEdit?.Invoke(i);
d.AllowReordering = AllowReordering; d.AllowReordering = AllowReordering;
d.AllowDeletion = AllowDeletion; d.AllowDeletion = AllowDeletion;
d.AllowSelection = AllowSelection; d.AllowSelection = AllowSelection;
d.AllowShowingResults = AllowShowingResults; d.AllowShowingResults = AllowShowingResults;
d.AllowEditing = AllowEditing;
d.ShowItemOwner = ShowItemOwners; d.ShowItemOwner = ShowItemOwners;
d.RequestResults = i => RequestResults?.Invoke(i);
}); });
protected virtual DrawableRoomPlaylistItem CreateDrawablePlaylistItem(PlaylistItem item) => new DrawableRoomPlaylistItem(item); protected virtual DrawableRoomPlaylistItem CreateDrawablePlaylistItem(PlaylistItem item) => new DrawableRoomPlaylistItem(item);

View File

@ -51,6 +51,11 @@ namespace osu.Game.Screens.OnlinePlay
/// </summary> /// </summary>
public Action<PlaylistItem> RequestResults; public Action<PlaylistItem> RequestResults;
/// <summary>
/// Invoked when this item requests to be edited.
/// </summary>
public Action<PlaylistItem> RequestEdit;
/// <summary> /// <summary>
/// The currently-selected item, used to show a border around this item. /// The currently-selected item, used to show a border around this item.
/// May be updated by this item if <see cref="AllowSelection"/> is <c>true</c>. /// May be updated by this item if <see cref="AllowSelection"/> is <c>true</c>.
@ -74,6 +79,7 @@ namespace osu.Game.Screens.OnlinePlay
private FillFlowContainer buttonsFlow; private FillFlowContainer buttonsFlow;
private UpdateableAvatar ownerAvatar; private UpdateableAvatar ownerAvatar;
private Drawable showResultsButton; private Drawable showResultsButton;
private Drawable editButton;
private Drawable removeButton; private Drawable removeButton;
private PanelBackground panelBackground; private PanelBackground panelBackground;
private FillFlowContainer mainFillFlow; private FillFlowContainer mainFillFlow;
@ -213,6 +219,23 @@ namespace osu.Game.Screens.OnlinePlay
} }
} }
private bool allowEditing;
/// <summary>
/// Whether this item can be edited.
/// </summary>
public bool AllowEditing
{
get => allowEditing;
set
{
allowEditing = value;
if (editButton != null)
editButton.Alpha = value ? 1 : 0;
}
}
private bool showItemOwner; private bool showItemOwner;
/// <summary> /// <summary>
@ -416,6 +439,13 @@ namespace osu.Game.Screens.OnlinePlay
TooltipText = "View results" TooltipText = "View results"
}, },
Item.Beatmap.Value == null ? Empty() : new PlaylistDownloadButton(Item), Item.Beatmap.Value == null ? Empty() : new PlaylistDownloadButton(Item),
editButton = new PlaylistEditButton
{
Size = new Vector2(30, 30),
Alpha = AllowEditing ? 1 : 0,
Action = () => RequestEdit?.Invoke(Item),
TooltipText = "Edit"
},
removeButton = new PlaylistRemoveButton removeButton = new PlaylistRemoveButton
{ {
Size = new Vector2(30, 30), Size = new Vector2(30, 30),
@ -432,6 +462,14 @@ namespace osu.Game.Screens.OnlinePlay
return true; return true;
} }
public class PlaylistEditButton : GrayButton
{
public PlaylistEditButton()
: base(FontAwesome.Solid.Edit)
{
}
}
public class PlaylistRemoveButton : GrayButton public class PlaylistRemoveButton : GrayButton
{ {
public PlaylistRemoveButton() public PlaylistRemoveButton()