Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add visual component for assigning user tags to beatmaps #32221

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions osu.Game.Tests/Visual/Ranking/TestSceneUserTagControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// 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.Linq;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Screens.Ranking;

namespace osu.Game.Tests.Visual.Ranking
{
public partial class TestSceneUserTagControl : OsuTestScene
{
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;

[SetUpSteps]
public void SetUpSteps()
{
AddStep("set up working beatmap", () =>
{
Beatmap.Value.BeatmapInfo.OnlineID = 42;
});
AddStep("set up network requests", () =>
{
dummyAPI.HandleRequest = request =>
{
switch (request)
{
case ListTagsRequest listTagsRequest:
{
Scheduler.AddDelayed(() => listTagsRequest.TriggerSuccess(new APITagCollection
{
Tags =
[
new APITag { Id = 1, Name = "tech", Description = "Tests uncommon skills.", },
new APITag { Id = 2, Name = "alt", Description = "Colloquial term for maps which use rhythms that encourage the player to alternate notes. Typically distinct from burst or stream maps.", },
new APITag { Id = 3, Name = "aim", Description = "Category for difficulty relating to cursor movement.", },
new APITag { Id = 4, Name = "tap", Description = "Category for difficulty relating to tapping input.", },
]
}), 500);
return true;
}

case GetBeatmapSetRequest getBeatmapSetRequest:
{
var beatmapSet = CreateAPIBeatmapSet(Beatmap.Value.BeatmapInfo);
beatmapSet.Beatmaps.Single().TopTags =
[
new APIBeatmapTag { TagId = 3, VoteCount = 9 },
];
Scheduler.AddDelayed(() => getBeatmapSetRequest.TriggerSuccess(beatmapSet), 500);
return true;
}

case AddBeatmapTagRequest:
case RemoveBeatmapTagRequest:
{
Scheduler.AddDelayed(request.TriggerSuccess, 500);
return true;
}
}

return false;
};
});
AddStep("create control", () =>
{
Child = new PopoverContainer
{
RelativeSizeAxes = Axes.Both,
Child = new UserTagControl
{
Width = 500,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}
};
});
}
}
}
16 changes: 16 additions & 0 deletions osu.Game/Beatmaps/APIBeatmapTag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 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 Newtonsoft.Json;

namespace osu.Game.Beatmaps
{
public class APIBeatmapTag
{
[JsonProperty("tag_id")]
public long TagId { get; set; }

[JsonProperty("count")]
public int VoteCount { get; set; }
}
}
13 changes: 7 additions & 6 deletions osu.Game/Configuration/SessionStatics.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// 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;
using osu.Game.Graphics.UserInterface;
using osu.Game.Input;
Expand All @@ -27,11 +25,12 @@ protected override void InitialiseDefaults()
SetDefault(Static.FeaturedArtistDisclaimerShownOnce, false);
SetDefault(Static.LastHoverSoundPlaybackTime, (double?)null);
SetDefault(Static.LastModSelectPanelSamplePlaybackTime, (double?)null);
SetDefault<APISeasonalBackgrounds>(Static.SeasonalBackgrounds, null);
SetDefault<APISeasonalBackgrounds?>(Static.SeasonalBackgrounds, null);
SetDefault(Static.TouchInputActive, RuntimeInfo.IsMobile);
SetDefault<ScoreInfo>(Static.LastLocalUserScore, null);
SetDefault<ScoreInfo>(Static.LastAppliedOffsetScore, null);
SetDefault<UserActivity>(Static.UserOnlineActivity, null);
SetDefault<ScoreInfo?>(Static.LastLocalUserScore, null);
SetDefault<ScoreInfo?>(Static.LastAppliedOffsetScore, null);
SetDefault<UserActivity?>(Static.UserOnlineActivity, null);
SetDefault<APITag[]?>(Static.AllBeatmapTags, null);
}

/// <summary>
Expand Down Expand Up @@ -99,5 +98,7 @@ public enum Static
/// The activity for the current user to broadcast to other players.
/// </summary>
UserOnlineActivity,

AllBeatmapTags,
}
}
31 changes: 31 additions & 0 deletions osu.Game/Online/API/Requests/AddBeatmapTagRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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.Globalization;
using System.Net.Http;
using osu.Framework.IO.Network;

namespace osu.Game.Online.API.Requests
{
public class AddBeatmapTagRequest : APIRequest
{
public int BeatmapID { get; }
public long TagID { get; }

public AddBeatmapTagRequest(int beatmapID, long tagID)
{
BeatmapID = beatmapID;
TagID = tagID;
}

protected override WebRequest CreateWebRequest()
{
var req = base.CreateWebRequest();
req.Method = HttpMethod.Post;
req.AddParameter(@"tag_id", TagID.ToString(CultureInfo.InvariantCulture), RequestParameterType.Query);
return req;
}

protected override string Target => $@"beatmaps/{BeatmapID}/tags";
}
}
12 changes: 12 additions & 0 deletions osu.Game/Online/API/Requests/ListTagsRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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 osu.Game.Online.API.Requests.Responses;

namespace osu.Game.Online.API.Requests
{
public class ListTagsRequest : APIRequest<APITagCollection>
{
protected override string Target => "tags";
}
}
29 changes: 29 additions & 0 deletions osu.Game/Online/API/Requests/RemoveBeatmapTagRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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.Net.Http;
using osu.Framework.IO.Network;

namespace osu.Game.Online.API.Requests
{
public class RemoveBeatmapTagRequest : APIRequest
{
public int BeatmapID { get; }
public long TagID { get; }

public RemoveBeatmapTagRequest(int beatmapID, long tagID)
{
BeatmapID = beatmapID;
TagID = tagID;
}

protected override WebRequest CreateWebRequest()
{
var req = base.CreateWebRequest();
req.Method = HttpMethod.Delete;
return req;
}

protected override string Target => $@"beatmaps/{BeatmapID}/tags/{TagID}";
}
}
6 changes: 6 additions & 0 deletions osu.Game/Online/API/Requests/Responses/APIBeatmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ private double hitLengthInSeconds
[JsonProperty(@"failtimes")]
public APIFailTimes? FailTimes { get; set; }

[JsonProperty(@"top_tag_ids")]
public APIBeatmapTag[]? TopTags { get; set; }

[JsonProperty(@"current_user_tag_ids")]
public long[]? OwnTagIds { get; set; }

[JsonProperty(@"max_combo")]
public int? MaxCombo { get; set; }

Expand Down
19 changes: 19 additions & 0 deletions osu.Game/Online/API/Requests/Responses/APITag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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 Newtonsoft.Json;

namespace osu.Game.Online.API.Requests.Responses
{
public class APITag
{
[JsonProperty("id")]
public long Id { get; set; }

[JsonProperty("name")]
public string Name { get; set; } = string.Empty;

[JsonProperty("description")]
public string Description { get; set; } = string.Empty;
}
}
14 changes: 14 additions & 0 deletions osu.Game/Online/API/Requests/Responses/APITagCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 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 Newtonsoft.Json;

namespace osu.Game.Online.API.Requests.Responses
{
public class APITagCollection
{
[JsonProperty("tags")]
public APITag[] Tags { get; set; } = Array.Empty<APITag>();
}
}
Loading