1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 02:42:54 +08:00

Flatten DrawableRoomPlaylistWithResults into base class

This commit is contained in:
Dan Balasescu 2021-12-09 01:17:25 +09:00
parent 26f6c5e5a5
commit be2dbf42c3
4 changed files with 66 additions and 74 deletions

View File

@ -21,6 +21,11 @@ namespace osu.Game.Screens.OnlinePlay
/// </summary>
public Action<PlaylistItem> DeletionRequested;
/// <summary>
/// Invoked to request showing the results for an item.
/// </summary>
public Action<PlaylistItem> ShowResultsRequested;
private bool allowReordering;
public bool AllowReordering
@ -63,6 +68,20 @@ namespace osu.Game.Screens.OnlinePlay
}
}
private bool allowShowingResults;
public bool AllowShowingResults
{
get => allowShowingResults;
set
{
allowShowingResults = value;
foreach (var item in ListContainer.OfType<DrawableRoomPlaylistItem>())
item.AllowShowingResults = value;
}
}
private bool showItemOwners;
public bool ShowItemOwners
@ -94,7 +113,9 @@ namespace osu.Game.Screens.OnlinePlay
AllowReordering = AllowReordering,
AllowDeletion = AllowDeletion,
AllowSelection = AllowSelection,
AllowShowingResults = AllowShowingResults,
ShowItemOwner = ShowItemOwners,
ShowResultsRequested = i => ShowResultsRequested?.Invoke(i)
};
}
}

View File

@ -41,6 +41,7 @@ namespace osu.Game.Screens.OnlinePlay
public const float ICON_HEIGHT = 34;
public Action<PlaylistItem> RequestDeletion;
public Action<PlaylistItem> ShowResultsRequested;
public readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
@ -53,6 +54,7 @@ namespace osu.Game.Screens.OnlinePlay
private FillFlowContainer buttonsFlow;
private UpdateableAvatar ownerAvatar;
private Drawable removeButton;
private Drawable showResultsButton;
private readonly IBindable<bool> valid = new Bindable<bool>();
@ -177,6 +179,20 @@ namespace osu.Game.Screens.OnlinePlay
}
}
private bool allowShowingResults;
public bool AllowShowingResults
{
get => allowShowingResults;
set
{
allowShowingResults = value;
if (showResultsButton != null)
showResultsButton.Alpha = value ? 1 : 0;
}
}
private bool showItemOwner;
public bool ShowItemOwner
@ -230,7 +246,7 @@ namespace osu.Game.Screens.OnlinePlay
modDisplay.Current.Value = requiredMods.ToArray();
buttonsFlow.Clear();
buttonsFlow.ChildrenEnumerable = CreateButtons();
buttonsFlow.ChildrenEnumerable = createButtons();
difficultyIconContainer.FadeInFromZero(500, Easing.OutQuint);
mainFillFlow.FadeInFromZero(500, Easing.OutQuint);
@ -344,7 +360,7 @@ namespace osu.Game.Screens.OnlinePlay
Margin = new MarginPadding { Horizontal = 8 },
AutoSizeAxes = Axes.Both,
Spacing = new Vector2(5),
ChildrenEnumerable = CreateButtons().Select(button => button.With(b =>
ChildrenEnumerable = createButtons().Select(button => button.With(b =>
{
b.Anchor = Anchor.Centre;
b.Origin = Anchor.Centre;
@ -367,9 +383,14 @@ namespace osu.Game.Screens.OnlinePlay
};
}
protected virtual IEnumerable<Drawable> CreateButtons() =>
private IEnumerable<Drawable> createButtons() =>
new[]
{
showResultsButton = new ShowResultsButton
{
Action = () => ShowResultsRequested?.Invoke(Item),
Alpha = AllowShowingResults ? 1 : 0,
},
Item.Beatmap.Value == null ? Empty() : new PlaylistDownloadButton(Item),
removeButton = new PlaylistRemoveButton
{
@ -454,6 +475,23 @@ namespace osu.Game.Screens.OnlinePlay
}
}
private class ShowResultsButton : IconButton
{
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Icon = FontAwesome.Solid.ChartPie;
TooltipText = "View results";
Add(new Box
{
RelativeSizeAxes = Axes.Both,
Depth = float.MaxValue,
Colour = colours.Gray4,
});
}
}
// 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)
{

View File

@ -1,69 +0,0 @@
// 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;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.Rooms;
namespace osu.Game.Screens.OnlinePlay
{
public class DrawableRoomPlaylistWithResults : DrawableRoomPlaylist
{
public Action<PlaylistItem> RequestShowResults;
private readonly bool showItemOwner;
public DrawableRoomPlaylistWithResults(bool showItemOwner = false)
: base(false, true, showItemOwner)
{
this.showItemOwner = showItemOwner;
}
protected override OsuRearrangeableListItem<PlaylistItem> CreateOsuDrawable(PlaylistItem item) =>
new DrawableRoomPlaylistItemWithResults(item, false, true, showItemOwner)
{
RequestShowResults = () => RequestShowResults(item),
SelectedItem = { BindTarget = SelectedItem },
};
private class DrawableRoomPlaylistItemWithResults : DrawableRoomPlaylistItem
{
public Action RequestShowResults;
public DrawableRoomPlaylistItemWithResults(PlaylistItem item, bool allowEdit, bool allowSelection, bool showItemOwner)
: base(item, allowEdit, allowSelection, showItemOwner)
{
}
protected override IEnumerable<Drawable> CreateButtons() =>
base.CreateButtons().Prepend(new FilledIconButton
{
Icon = FontAwesome.Solid.ChartPie,
Action = () => RequestShowResults?.Invoke(),
TooltipText = "View results"
});
private class FilledIconButton : IconButton
{
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Add(new Box
{
RelativeSizeAxes = Axes.Both,
Depth = float.MaxValue,
Colour = colours.Gray4,
});
}
}
}
}
}

View File

@ -88,12 +88,14 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
new Drawable[] { new OverlinedPlaylistHeader(), },
new Drawable[]
{
new DrawableRoomPlaylistWithResults
new DrawableRoomPlaylist
{
RelativeSizeAxes = Axes.Both,
Items = { BindTarget = Room.Playlist },
SelectedItem = { BindTarget = SelectedItem },
RequestShowResults = item =>
AllowSelection = true,
AllowShowingResults = true,
ShowResultsRequested = item =>
{
Debug.Assert(RoomId.Value != null);
ParentScreen?.Push(new PlaylistsResultsScreen(null, RoomId.Value.Value, item, false));