diff --git a/osu.Game.Tests/Visual/Ranking/TestSceneStatisticsPanel.cs b/osu.Game.Tests/Visual/Ranking/TestSceneStatisticsPanel.cs index f92dc0313e..b682ec7265 100644 --- a/osu.Game.Tests/Visual/Ranking/TestSceneStatisticsPanel.cs +++ b/osu.Game.Tests/Visual/Ranking/TestSceneStatisticsPanel.cs @@ -256,6 +256,7 @@ namespace osu.Game.Tests.Visual.Ranking var score = TestResources.CreateTestScoreInfo(); score.Rank = ScoreRank.D; + setUpTaggingRequests(() => score.BeatmapInfo); AddStep("load panel", () => { Child = new PopoverContainer @@ -278,6 +279,7 @@ namespace osu.Game.Tests.Visual.Ranking var score = TestResources.CreateTestScoreInfo(); score.Ruleset = new ManiaRuleset().RulesetInfo; + setUpTaggingRequests(() => score.BeatmapInfo); AddStep("load panel", () => { Child = new PopoverContainer diff --git a/osu.Game.Tests/Visual/Ranking/TestSceneUserTagControl.cs b/osu.Game.Tests/Visual/Ranking/TestSceneUserTagControl.cs index b63f8ca31c..03730c59ee 100644 --- a/osu.Game.Tests/Visual/Ranking/TestSceneUserTagControl.cs +++ b/osu.Game.Tests/Visual/Ranking/TestSceneUserTagControl.cs @@ -28,11 +28,14 @@ namespace osu.Game.Tests.Visual.Ranking private DummyAPIAccess dummyAPI => (DummyAPIAccess)API; + private int writeRequestCount = 0; + [SetUpSteps] public void SetUpSteps() { AddStep("set up network requests", () => { + writeRequestCount = 0; dummyAPI.HandleRequest = request => { switch (request) @@ -77,6 +80,7 @@ namespace osu.Game.Tests.Visual.Ranking case AddBeatmapTagRequest: case RemoveBeatmapTagRequest: { + writeRequestCount++; Scheduler.AddDelayed(request.TriggerSuccess, 500); return true; } @@ -107,6 +111,31 @@ namespace osu.Game.Tests.Visual.Ranking }); } + [Test] + public void TestNotWritable() + { + AddStep("show", () => + { + var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo); + working.BeatmapInfo.OnlineID = 42; + Beatmap.Value = working; + recreateControl(writable: false); + }); + + AddUntilStep("click tag", () => + { + var tag = this.ChildrenOfType().FirstOrDefault(t => t.UserTag.Id == 2); + if (tag == null) + return false; + + InputManager.MoveMouseTo(tag); + InputManager.Click(MouseButton.Left); + return true; + }); + + AddAssert("no vote requests send", () => writeRequestCount, () => Is.Zero); + } + [Test] public void TestTagsDoNotMoveUntilMouseMovesAway() { @@ -148,13 +177,14 @@ namespace osu.Game.Tests.Visual.Ranking UserTagControl.DrawableUserTag getDrawableTagById(long id) => getTagFlow().Single(t => t.UserTag.Id == id); } - private void recreateControl() + private void recreateControl(bool writable = true) { Child = new PopoverContainer { RelativeSizeAxes = Axes.Both, Child = new UserTagControl(Beatmap.Value.BeatmapInfo) { + Writable = writable, Width = 700, Anchor = Anchor.Centre, Origin = Anchor.Centre, diff --git a/osu.Game/Screens/Ranking/Statistics/StatisticsPanel.cs b/osu.Game/Screens/Ranking/Statistics/StatisticsPanel.cs index c33514e343..3c1aec745d 100644 --- a/osu.Game/Screens/Ranking/Statistics/StatisticsPanel.cs +++ b/osu.Game/Screens/Ranking/Statistics/StatisticsPanel.cs @@ -267,6 +267,7 @@ namespace osu.Game.Screens.Ranking.Statistics { yield return new StatisticItem("Tag the beatmap!", () => new UserTagControl(newScore.BeatmapInfo) { + Writable = true, RelativeSizeAxes = Axes.X, Anchor = Anchor.Centre, Origin = Anchor.Centre, @@ -274,12 +275,31 @@ namespace osu.Game.Screens.Ranking.Statistics } else { - yield return new StatisticItem("Tag the beatmap!", () => new OsuTextFlowContainer(cp => cp.Font = OsuFont.GetFont(size: StatisticItem.FONT_SIZE, weight: FontWeight.SemiBold)) + yield return new StatisticItem("Tag the beatmap!", () => new FillFlowContainer { + Children = new CompositeDrawable[] + { + new OsuTextFlowContainer(cp => cp.Font = OsuFont.GetFont(size: StatisticItem.FONT_SIZE, weight: FontWeight.SemiBold)) + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + TextAnchor = Anchor.Centre, + Text = preventTaggingReason, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + }, + new UserTagControl(newScore.BeatmapInfo) + { + Writable = false, + RelativeSizeAxes = Axes.X, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + } + }, RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, - TextAnchor = Anchor.Centre, - Text = preventTaggingReason, + Direction = FillDirection.Vertical, + Spacing = new Vector2(4), }); } } diff --git a/osu.Game/Screens/Ranking/UserTagControl.cs b/osu.Game/Screens/Ranking/UserTagControl.cs index 5618dd2490..1005e7ea2c 100644 --- a/osu.Game/Screens/Ranking/UserTagControl.cs +++ b/osu.Game/Screens/Ranking/UserTagControl.cs @@ -43,7 +43,12 @@ namespace osu.Game.Screens.Ranking private readonly Bindable apiBeatmap = new Bindable(); - private AddNewTagUserTag addNewTagUserTag = null!; + private AddNewTagUserTag? addNewTagUserTag; + + /// + /// Determines whether the user can modify the contained tags + /// + public bool Writable { private get; init; } private InputManager inputManager = null!; @@ -91,12 +96,17 @@ namespace osu.Game.Screens.Ranking AutoSizeAxes = Axes.Y, Direction = FillDirection.Full, Spacing = new Vector2(4), - Child = addNewTagUserTag = new AddNewTagUserTag - { - AvailableTags = { BindTarget = relevantTagsById }, - OnTagSelected = toggleVote, - }, - }, + Children = Writable + ? + [ + addNewTagUserTag = new AddNewTagUserTag + { + AvailableTags = { BindTarget = relevantTagsById }, + OnTagSelected = toggleVote, + } + ] + : [] + } }, }, } @@ -196,7 +206,7 @@ namespace osu.Game.Screens.Ranking case NotifyCollectionChangedAction.Reset: { tagFlow.Clear(); - tagFlow.Add(addNewTagUserTag); + if (Writable) tagFlow.Add(addNewTagUserTag!); break; } } @@ -204,6 +214,9 @@ namespace osu.Game.Screens.Ranking private void toggleVote(UserTag tag) { + if (!Writable) + return; + if (tag.Updating.Value) return;