mirror of
https://github.com/ppy/osu.git
synced 2024-12-18 07:22:57 +08:00
Added collection button to result screen
This commit is contained in:
parent
0bc14ba646
commit
3296beb003
64
osu.Game/Screens/Ranking/CollectionButton.cs
Normal file
64
osu.Game/Screens/Ranking/CollectionButton.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
70
osu.Game/Screens/Ranking/CollectionPopover.cs
Normal file
70
osu.Game/Screens/Ranking/CollectionPopover.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -71,23 +71,20 @@ namespace osu.Game.Screens.Ranking
|
|||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours, IAPIProvider api)
|
private void load()
|
||||||
{
|
{
|
||||||
this.api = api;
|
|
||||||
|
|
||||||
updateState();
|
updateState();
|
||||||
|
|
||||||
localUser.BindTo(api.LocalUser);
|
localUser.BindTo(api.LocalUser);
|
||||||
localUser.BindValueChanged(_ => updateEnabled());
|
localUser.BindValueChanged(_ => updateEnabled());
|
||||||
|
|
||||||
Action = () => toggleFavouriteStatus();
|
Action = toggleFavouriteStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
Action = toggleFavouriteStatus;
|
|
||||||
current.BindValueChanged(_ => updateState(), true);
|
current.BindValueChanged(_ => updateState(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ using osu.Framework.Bindables;
|
|||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Cursor;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Input.Bindings;
|
using osu.Framework.Input.Bindings;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
@ -99,7 +100,12 @@ namespace osu.Game.Screens.Ranking
|
|||||||
|
|
||||||
popInSample = audio.Samples.Get(@"UI/overlay-pop-in");
|
popInSample = audio.Samples.Get(@"UI/overlay-pop-in");
|
||||||
|
|
||||||
InternalChild = new GridContainer
|
InternalChild = new PopoverContainer
|
||||||
|
{
|
||||||
|
Depth = -1,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Padding = new MarginPadding(0),
|
||||||
|
Child = new GridContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Content = new[]
|
Content = new[]
|
||||||
@ -157,7 +163,7 @@ namespace osu.Game.Screens.Ranking
|
|||||||
AutoSizeAxes = Axes.Both,
|
AutoSizeAxes = Axes.Both,
|
||||||
Spacing = new Vector2(5),
|
Spacing = new Vector2(5),
|
||||||
Direction = FillDirection.Horizontal
|
Direction = FillDirection.Horizontal
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,6 +173,7 @@ namespace osu.Game.Screens.Ranking
|
|||||||
new Dimension(),
|
new Dimension(),
|
||||||
new Dimension(GridSizeMode.AutoSize)
|
new Dimension(GridSizeMode.AutoSize)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Score != null)
|
if (Score != null)
|
||||||
@ -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.
|
// 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)
|
if (api.IsLoggedIn && Score?.BeatmapInfo?.BeatmapSet != null && Score.BeatmapInfo.BeatmapSet.OnlineID > 0)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user