-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15520 from bdach/beatmap-card/favourite-button
Add favourite button to beatmap card
- Loading branch information
Showing
9 changed files
with
348 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapCardFavouriteButton.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Linq; | ||
using NUnit.Framework; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Graphics.Sprites; | ||
using osu.Framework.Testing; | ||
using osu.Game.Beatmaps.Drawables.Cards.Buttons; | ||
using osu.Game.Online.API; | ||
using osu.Game.Online.API.Requests; | ||
using osu.Game.Online.API.Requests.Responses; | ||
using osu.Game.Overlays; | ||
using osu.Game.Resources.Localisation.Web; | ||
using osuTK; | ||
using osuTK.Input; | ||
|
||
namespace osu.Game.Tests.Visual.Beatmaps | ||
{ | ||
public class TestSceneBeatmapCardFavouriteButton : OsuManualInputManagerTestScene | ||
{ | ||
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API; | ||
|
||
[Cached] | ||
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue); | ||
|
||
[Test] | ||
public void TestInitialState([Values] bool favourited) | ||
{ | ||
APIBeatmapSet beatmapSetInfo = null; | ||
FavouriteButton button = null; | ||
|
||
AddStep("create beatmap set", () => | ||
{ | ||
beatmapSetInfo = CreateAPIBeatmapSet(Ruleset.Value); | ||
beatmapSetInfo.HasFavourited = favourited; | ||
}); | ||
AddStep("create button", () => Child = button = new FavouriteButton(beatmapSetInfo) { Scale = new Vector2(2) }); | ||
|
||
assertCorrectIcon(favourited); | ||
AddAssert("correct tooltip text", () => button.TooltipText == (favourited ? BeatmapsetsStrings.ShowDetailsUnfavourite : BeatmapsetsStrings.ShowDetailsFavourite)); | ||
} | ||
|
||
[Test] | ||
public void TestRequestHandling() | ||
{ | ||
APIBeatmapSet beatmapSetInfo = null; | ||
FavouriteButton button = null; | ||
BeatmapFavouriteAction? lastRequestAction = null; | ||
|
||
AddStep("create beatmap set", () => beatmapSetInfo = CreateAPIBeatmapSet(Ruleset.Value)); | ||
AddStep("create button", () => Child = button = new FavouriteButton(beatmapSetInfo) { Scale = new Vector2(2) }); | ||
|
||
assertCorrectIcon(false); | ||
|
||
AddStep("register request handling", () => dummyAPI.HandleRequest = request => | ||
{ | ||
if (!(request is PostBeatmapFavouriteRequest favouriteRequest)) | ||
return false; | ||
|
||
lastRequestAction = favouriteRequest.Action; | ||
request.TriggerSuccess(); | ||
return true; | ||
}); | ||
|
||
AddStep("click icon", () => | ||
{ | ||
InputManager.MoveMouseTo(button); | ||
InputManager.Click(MouseButton.Left); | ||
}); | ||
AddUntilStep("favourite request sent", () => lastRequestAction == BeatmapFavouriteAction.Favourite); | ||
assertCorrectIcon(true); | ||
|
||
AddStep("click icon", () => | ||
{ | ||
InputManager.MoveMouseTo(button); | ||
InputManager.Click(MouseButton.Left); | ||
}); | ||
AddUntilStep("unfavourite request sent", () => lastRequestAction == BeatmapFavouriteAction.UnFavourite); | ||
assertCorrectIcon(false); | ||
} | ||
|
||
private void assertCorrectIcon(bool favourited) => AddAssert("icon correct", | ||
() => this.ChildrenOfType<SpriteIcon>().Single().Icon.Equals(favourited ? FontAwesome.Solid.Heart : FontAwesome.Regular.Heart)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
osu.Game/Beatmaps/Drawables/Cards/BeatmapSetFavouriteState.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using osu.Game.Beatmaps.Drawables.Cards.Buttons; | ||
using osu.Game.Beatmaps.Drawables.Cards.Statistics; | ||
|
||
namespace osu.Game.Beatmaps.Drawables.Cards | ||
{ | ||
/// <summary> | ||
/// Stores the current favourite state of a beatmap set. | ||
/// Used to coordinate between <see cref="FavouriteButton"/> and <see cref="FavouritesStatistic"/>. | ||
/// </summary> | ||
public readonly struct BeatmapSetFavouriteState | ||
{ | ||
/// <summary> | ||
/// Whether the currently logged-in user has favourited this beatmap. | ||
/// </summary> | ||
public bool Favourited { get; } | ||
|
||
/// <summary> | ||
/// The number of favourites that the beatmap set has received, including the currently logged-in user. | ||
/// </summary> | ||
public int FavouriteCount { get; } | ||
|
||
public BeatmapSetFavouriteState(bool favourited, int favouriteCount) | ||
{ | ||
Favourited = favourited; | ||
FavouriteCount = favouriteCount; | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
osu.Game/Beatmaps/Drawables/Cards/Buttons/BeatmapCardIconButton.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using osu.Framework.Allocation; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Sprites; | ||
using osu.Game.Graphics.Containers; | ||
using osu.Game.Overlays; | ||
using osuTK; | ||
|
||
namespace osu.Game.Beatmaps.Drawables.Cards.Buttons | ||
{ | ||
public abstract class BeatmapCardIconButton : OsuHoverContainer | ||
{ | ||
protected readonly SpriteIcon Icon; | ||
|
||
private float size; | ||
|
||
public new float Size | ||
{ | ||
get => size; | ||
set | ||
{ | ||
size = value; | ||
Icon.Size = new Vector2(size); | ||
} | ||
} | ||
|
||
protected BeatmapCardIconButton() | ||
{ | ||
Add(Icon = new SpriteIcon()); | ||
|
||
AutoSizeAxes = Axes.Both; | ||
Size = 12; | ||
} | ||
|
||
[BackgroundDependencyLoader] | ||
private void load(OverlayColourProvider colourProvider) | ||
{ | ||
Anchor = Origin = Anchor.Centre; | ||
|
||
IdleColour = colourProvider.Light1; | ||
HoverColour = colourProvider.Content1; | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
osu.Game/Beatmaps/Drawables/Cards/Buttons/DownloadButton.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using osu.Framework.Graphics.Sprites; | ||
using osu.Game.Online.API.Requests.Responses; | ||
|
||
namespace osu.Game.Beatmaps.Drawables.Cards.Buttons | ||
{ | ||
public class DownloadButton : BeatmapCardIconButton | ||
{ | ||
public DownloadButton(APIBeatmapSet beatmapSet) | ||
{ | ||
Icon.Icon = FontAwesome.Solid.FileDownload; | ||
} | ||
|
||
// TODO: implement behaviour | ||
} | ||
} |
Oops, something went wrong.