1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-17 09:39:04 +08:00

Added collection button to result screen

This commit is contained in:
Layendan 2024-07-20 11:49:46 -07:00 committed by Dean Herbert
parent 0bc14ba646
commit 3296beb003
No known key found for this signature in database
4 changed files with 201 additions and 58 deletions

View File

@ -0,0 +1,64 @@
// 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.
#nullable disable
using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using osuTK;
namespace osu.Game.Screens.Ranking
{
public partial class CollectionButton : OsuAnimatedButton, IHasPopover
{
private readonly Box background;
private readonly BeatmapInfo beatmapInfo;
public CollectionButton(BeatmapInfo beatmapInfo)
{
this.beatmapInfo = beatmapInfo;
Size = new Vector2(50, 30);
Children = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both,
Depth = float.MaxValue
},
new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(13),
Icon = FontAwesome.Solid.Book,
},
};
TooltipText = "collections";
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
background.Colour = colours.Green;
Action = this.ShowPopover;
}
// use Content for tracking input as some buttons might be temporarily hidden with DisappearToBottom, and they become hidden by moving Content away from screen.
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Content.ReceivePositionalInputAt(screenSpacePos);
public Popover GetPopover() => new CollectionPopover(beatmapInfo);
}
}

View File

@ -0,0 +1,70 @@
// 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.
#nullable disable
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Input.Events;
using osu.Game.Beatmaps;
using osu.Game.Collections;
using osu.Game.Database;
using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2;
namespace osu.Game.Screens.Ranking
{
public partial class CollectionPopover : OsuPopover
{
private OsuMenu menu;
private readonly BeatmapInfo beatmapInfo;
[Resolved]
private RealmAccess realm { get; set; } = null!;
[Resolved]
private ManageCollectionsDialog? manageCollectionsDialog { get; set; }
public CollectionPopover(BeatmapInfo beatmapInfo) : base(false)
{
this.beatmapInfo = beatmapInfo;
}
[BackgroundDependencyLoader]
private void load()
{
Margin = new MarginPadding(5);
Body.CornerRadius = 4;
Children = new[]
{
menu = new OsuMenu(Direction.Vertical, true)
{
Items = items,
},
};
}
protected override void OnFocusLost(FocusLostEvent e)
{
base.OnFocusLost(e);
Hide();
}
private OsuMenuItem[] items
{
get
{
var collectionItems = realm.Realm.All<BeatmapCollection>()
.OrderBy(c => c.Name)
.AsEnumerable()
.Select(c => new CollectionToggleMenuItem(c.ToLive(realm), beatmapInfo)).Cast<OsuMenuItem>().ToList();
if (manageCollectionsDialog != null)
collectionItems.Add(new OsuMenuItem("Manage...", MenuItemType.Standard, manageCollectionsDialog.Show));
return collectionItems.ToArray();
}
}
}
}

View File

@ -71,23 +71,20 @@ namespace osu.Game.Screens.Ranking
}
[BackgroundDependencyLoader]
private void load(OsuColour colours, IAPIProvider api)
private void load()
{
this.api = api;
updateState();
localUser.BindTo(api.LocalUser);
localUser.BindValueChanged(_ => updateEnabled());
Action = () => toggleFavouriteStatus();
Action = toggleFavouriteStatus;
}
protected override void LoadComplete()
{
base.LoadComplete();
Action = toggleFavouriteStatus;
current.BindValueChanged(_ => updateState(), true);
}

View File

@ -12,6 +12,7 @@ using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
@ -99,73 +100,79 @@ namespace osu.Game.Screens.Ranking
popInSample = audio.Samples.Get(@"UI/overlay-pop-in");
InternalChild = new GridContainer
InternalChild = new PopoverContainer
{
Depth = -1,
RelativeSizeAxes = Axes.Both,
Content = new[]
Padding = new MarginPadding(0),
Child = new GridContainer
{
new Drawable[]
RelativeSizeAxes = Axes.Both,
Content = new[]
{
VerticalScrollContent = new VerticalScrollContainer
new Drawable[]
{
RelativeSizeAxes = Axes.Both,
ScrollbarVisible = false,
Child = new Container
VerticalScrollContent = new VerticalScrollContainer
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
StatisticsPanel = createStatisticsPanel().With(panel =>
{
panel.RelativeSizeAxes = Axes.Both;
panel.Score.BindTarget = SelectedScore;
}),
ScorePanelList = new ScorePanelList
{
RelativeSizeAxes = Axes.Both,
SelectedScore = { BindTarget = SelectedScore },
PostExpandAction = () => StatisticsPanel.ToggleVisibility()
},
detachedPanelContainer = new Container<ScorePanel>
{
RelativeSizeAxes = Axes.Both
},
}
}
},
},
new[]
{
bottomPanel = new Container
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X,
Height = TwoLayerButton.SIZE_EXTENDED.Y,
Alpha = 0,
Children = new Drawable[]
{
new Box
ScrollbarVisible = false,
Child = new Container
{
RelativeSizeAxes = Axes.Both,
Colour = Color4Extensions.FromHex("#333")
},
buttons = new FillFlowContainer
Children = new Drawable[]
{
StatisticsPanel = createStatisticsPanel().With(panel =>
{
panel.RelativeSizeAxes = Axes.Both;
panel.Score.BindTarget = SelectedScore;
}),
ScorePanelList = new ScorePanelList
{
RelativeSizeAxes = Axes.Both,
SelectedScore = { BindTarget = SelectedScore },
PostExpandAction = () => StatisticsPanel.ToggleVisibility()
},
detachedPanelContainer = new Container<ScorePanel>
{
RelativeSizeAxes = Axes.Both
},
}
}
},
},
new[]
{
bottomPanel = new Container
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X,
Height = TwoLayerButton.SIZE_EXTENDED.Y,
Alpha = 0,
Children = new Drawable[]
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
Spacing = new Vector2(5),
Direction = FillDirection.Horizontal
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4Extensions.FromHex("#333")
},
buttons = new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
Spacing = new Vector2(5),
Direction = FillDirection.Horizontal
},
}
}
}
},
RowDimensions = new[]
{
new Dimension(),
new Dimension(GridSizeMode.AutoSize)
}
},
RowDimensions = new[]
{
new Dimension(),
new Dimension(GridSizeMode.AutoSize)
}
};
@ -205,6 +212,11 @@ namespace osu.Game.Screens.Ranking
});
}
if (Score?.BeatmapInfo != null)
{
buttons.Add(new CollectionButton(Score.BeatmapInfo) { Width = 75 });
}
// Do not render if user is not logged in or the mapset does not have a valid online ID.
if (api.IsLoggedIn && Score?.BeatmapInfo?.BeatmapSet != null && Score.BeatmapInfo.BeatmapSet.OnlineID > 0)
{