1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-14 05:47:20 +08:00

Merge branch 'master' into disabled-button-sfx

This commit is contained in:
Dean Herbert 2022-11-03 20:27:41 +09:00
commit 1edde8f73c
13 changed files with 424 additions and 56 deletions

View File

@ -10,10 +10,12 @@ using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Testing;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
@ -37,14 +39,20 @@ namespace osu.Game.Tests.Visual.Online
private CommentsContainer commentsContainer = null!;
private readonly ManualResetEventSlim requestLock = new ManualResetEventSlim();
[BackgroundDependencyLoader]
private void load()
{
base.Content.AddRange(new Drawable[]
{
content = new OsuScrollContainer
new PopoverContainer
{
RelativeSizeAxes = Axes.Both
RelativeSizeAxes = Axes.Both,
Child = content = new OsuScrollContainer
{
RelativeSizeAxes = Axes.Both
}
},
dialogOverlay
});
@ -80,8 +88,6 @@ namespace osu.Game.Tests.Visual.Online
});
}
private readonly ManualResetEventSlim deletionPerformed = new ManualResetEventSlim();
[Test]
public void TestDeletion()
{
@ -105,7 +111,7 @@ namespace osu.Game.Tests.Visual.Online
});
AddStep("Setup request handling", () =>
{
deletionPerformed.Reset();
requestLock.Reset();
dummyAPI.HandleRequest = request =>
{
@ -138,7 +144,7 @@ namespace osu.Game.Tests.Visual.Online
Task.Run(() =>
{
deletionPerformed.Wait(10000);
requestLock.Wait(10000);
req.TriggerSuccess(cb);
});
@ -149,7 +155,7 @@ namespace osu.Game.Tests.Visual.Online
AddAssert("Loading spinner shown", () => commentsContainer.ChildrenOfType<LoadingSpinner>().Any(d => d.IsPresent));
AddStep("Complete request", () => deletionPerformed.Set());
AddStep("Complete request", () => requestLock.Set());
AddUntilStep("Comment is deleted locally", () => this.ChildrenOfType<DrawableComment>().Single(x => x.Comment.Id == 1).WasDeleted);
}
@ -204,6 +210,74 @@ namespace osu.Game.Tests.Visual.Online
});
}
[Test]
public void TestReport()
{
const string report_text = "I don't like this comment";
DrawableComment? targetComment = null;
CommentReportRequest? request = null;
addTestComments();
AddUntilStep("Comment exists", () =>
{
var comments = this.ChildrenOfType<DrawableComment>();
targetComment = comments.SingleOrDefault(x => x.Comment.Id == 2);
return targetComment != null;
});
AddStep("Setup request handling", () =>
{
requestLock.Reset();
dummyAPI.HandleRequest = r =>
{
if (!(r is CommentReportRequest req))
return false;
Task.Run(() =>
{
request = req;
requestLock.Wait(10000);
req.TriggerSuccess();
});
return true;
};
});
AddStep("Click the button", () =>
{
var btn = targetComment.ChildrenOfType<OsuSpriteText>().Single(x => x.Text == "Report");
InputManager.MoveMouseTo(btn);
InputManager.Click(MouseButton.Left);
});
AddStep("Try to report", () =>
{
var btn = this.ChildrenOfType<ReportCommentPopover>().Single().ChildrenOfType<RoundedButton>().Single();
InputManager.MoveMouseTo(btn);
InputManager.Click(MouseButton.Left);
});
AddWaitStep("Wait", 3);
AddAssert("Nothing happened", () => this.ChildrenOfType<ReportCommentPopover>().Any());
AddStep("Set report data", () =>
{
var field = this.ChildrenOfType<OsuTextBox>().Single();
field.Current.Value = report_text;
var reason = this.ChildrenOfType<OsuEnumDropdown<CommentReportReason>>().Single();
reason.Current.Value = CommentReportReason.Other;
});
AddStep("Try to report", () =>
{
var btn = this.ChildrenOfType<ReportCommentPopover>().Single().ChildrenOfType<RoundedButton>().Single();
InputManager.MoveMouseTo(btn);
InputManager.Click(MouseButton.Left);
});
AddWaitStep("Wait", 3);
AddAssert("Overlay closed", () => !this.ChildrenOfType<ReportCommentPopover>().Any());
AddAssert("Loading spinner shown", () => targetComment.ChildrenOfType<LoadingSpinner>().Any(d => d.IsPresent));
AddStep("Complete request", () => requestLock.Set());
AddUntilStep("Request sent", () => request != null);
AddAssert("Request is correct", () => request != null && request.CommentID == 2 && request.Comment == report_text && request.Reason == CommentReportReason.Other);
}
private void addTestComments()
{
AddStep("set up response", () =>

View File

@ -0,0 +1,46 @@
// 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.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Testing;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays.Comments;
using osu.Game.Tests.Visual.UserInterface;
using osuTK;
namespace osu.Game.Tests.Visual.Online
{
public class TestSceneCommentReportButton : ThemeComparisonTestScene
{
[SetUpSteps]
public void SetUpSteps()
{
AddStep("setup API", () => ((DummyAPIAccess)API).HandleRequest += req =>
{
switch (req)
{
case CommentReportRequest report:
Scheduler.AddDelayed(report.TriggerSuccess, 1000);
return true;
}
return false;
});
}
protected override Drawable CreateContent() => new PopoverContainer
{
RelativeSizeAxes = Axes.Both,
Child = new CommentReportButton(new Comment { User = new APIUser { Username = "Someone" } })
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(2f),
}.With(b => Schedule(b.ShowPopover)),
};
}
}

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
@ -32,7 +31,6 @@ using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Rulesets.Taiko;
using osu.Game.Scoring;
using osu.Game.Screens.Play;
using osu.Game.Screens.Select;
@ -538,36 +536,6 @@ namespace osu.Game.Tests.Visual.SongSelect
AddUntilStep("selection shown on wedge", () => songSelect!.CurrentBeatmapDetailsBeatmap.BeatmapInfo.MatchesOnlineID(target));
}
[Test]
public void TestRulesetChangeResetsMods()
{
createSongSelect();
changeRuleset(0);
changeMods(new OsuModHardRock());
int actionIndex = 0;
int modChangeIndex = 0;
int rulesetChangeIndex = 0;
AddStep("change ruleset", () =>
{
SelectedMods.ValueChanged += onModChange;
songSelect!.Ruleset.ValueChanged += onRulesetChange;
Ruleset.Value = new TaikoRuleset().RulesetInfo;
SelectedMods.ValueChanged -= onModChange;
songSelect!.Ruleset.ValueChanged -= onRulesetChange;
});
AddAssert("mods changed before ruleset", () => modChangeIndex < rulesetChangeIndex);
AddAssert("empty mods", () => !SelectedMods.Value.Any());
void onModChange(ValueChangedEvent<IReadOnlyList<Mod>> e) => modChangeIndex = actionIndex++;
void onRulesetChange(ValueChangedEvent<RulesetInfo> e) => rulesetChangeIndex = actionIndex++;
}
[Test]
public void TestModsRetainedBetweenSongSelect()
{

View File

@ -17,6 +17,7 @@ using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Mods;
using osu.Game.Overlays.Settings;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Catch.Mods;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Mods;
@ -338,26 +339,36 @@ namespace osu.Game.Tests.Visual.UserInterface
}
[Test]
public void TestRulesetChanges()
public void TestCommonModsMaintainedOnRulesetChange()
{
createScreen();
changeRuleset(0);
var noFailMod = new OsuRuleset().GetModsFor(ModType.DifficultyReduction).FirstOrDefault(m => m is OsuModNoFail);
AddStep("set mods externally", () => { SelectedMods.Value = new[] { noFailMod }; });
AddStep("select relax mod", () => SelectedMods.Value = new[] { Ruleset.Value.CreateInstance().CreateMod<ModRelax>() });
changeRuleset(0);
AddAssert("ensure mod still selected", () => SelectedMods.Value.SingleOrDefault() is OsuModRelax);
AddAssert("ensure mods still selected", () => SelectedMods.Value.SingleOrDefault(m => m is OsuModNoFail) != null);
changeRuleset(2);
AddAssert("catch variant selected", () => SelectedMods.Value.SingleOrDefault() is CatchModRelax);
changeRuleset(3);
AddAssert("no mod selected", () => SelectedMods.Value.Count == 0);
}
AddAssert("ensure mods not selected", () => SelectedMods.Value.Count == 0);
[Test]
public void TestUncommonModsDiscardedOnRulesetChange()
{
createScreen();
changeRuleset(0);
AddAssert("ensure mods not selected", () => SelectedMods.Value.Count == 0);
AddStep("select single tap mod", () => SelectedMods.Value = new[] { new OsuModSingleTap() });
changeRuleset(0);
AddAssert("ensure mod still selected", () => SelectedMods.Value.SingleOrDefault() is OsuModSingleTap);
changeRuleset(3);
AddAssert("no mod selected", () => SelectedMods.Value.Count == 0);
}
[Test]

View File

@ -0,0 +1,38 @@
// 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;
using osu.Game.Overlays.Comments;
namespace osu.Game.Online.API.Requests
{
public class CommentReportRequest : APIRequest
{
public readonly long CommentID;
public readonly CommentReportReason Reason;
public readonly string Comment;
public CommentReportRequest(long commentID, CommentReportReason reason, string comment)
{
CommentID = commentID;
Reason = reason;
Comment = comment;
}
protected override WebRequest CreateWebRequest()
{
var req = base.CreateWebRequest();
req.Method = HttpMethod.Post;
req.AddParameter(@"reportable_type", @"comment");
req.AddParameter(@"reportable_id", $"{CommentID}");
req.AddParameter(@"reason", Reason.ToString());
req.AddParameter(@"comments", Comment);
return req;
}
protected override string Target => @"reports";
}
}

View File

@ -616,11 +616,16 @@ namespace osu.Game
return;
}
var previouslySelectedMods = SelectedMods.Value.ToArray();
if (!SelectedMods.Disabled)
SelectedMods.Value = Array.Empty<Mod>();
AvailableMods.Value = dict;
if (!SelectedMods.Disabled)
SelectedMods.Value = previouslySelectedMods.Select(m => instance.CreateModFromAcronym(m.Acronym)).Where(m => m != null).ToArray();
void revertRulesetChange() => Ruleset.Value = r.OldValue?.Available == true ? r.OldValue : RulesetStore.AvailableRulesets.First();
}

View File

@ -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.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Online.API.Requests.Responses;
@ -12,7 +10,7 @@ namespace osu.Game.Overlays.Changelog
{
public class ChangelogContent : FillFlowContainer
{
public Action<APIChangelogBuild> BuildSelected;
public Action<APIChangelogBuild>? BuildSelected;
public void SelectBuild(APIChangelogBuild build) => BuildSelected?.Invoke(build);

View File

@ -0,0 +1,91 @@
// 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.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Resources.Localisation.Web;
using osuTK;
namespace osu.Game.Overlays.Comments
{
public class CommentReportButton : CompositeDrawable, IHasPopover
{
private readonly Comment comment;
private LinkFlowContainer link = null!;
private LoadingSpinner loading = null!;
[Resolved]
private IAPIProvider api { get; set; } = null!;
[Resolved]
private OverlayColourProvider? colourProvider { get; set; }
public CommentReportButton(Comment comment)
{
this.comment = comment;
}
[BackgroundDependencyLoader]
private void load()
{
AutoSizeAxes = Axes.Both;
InternalChildren = new Drawable[]
{
link = new LinkFlowContainer(s => s.Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold))
{
AutoSizeAxes = Axes.Both,
},
loading = new LoadingSpinner
{
Size = new Vector2(12f),
}
};
link.AddLink(UsersStrings.ReportButtonText, this.ShowPopover);
}
private void report(CommentReportReason reason, string comments)
{
var request = new CommentReportRequest(comment.Id, reason, comments);
link.Hide();
loading.Show();
request.Success += () => Schedule(() =>
{
loading.Hide();
link.Clear(true);
link.AddText(UsersStrings.ReportThanks, s => s.Colour = colourProvider?.Content2 ?? Colour4.White);
link.Show();
this.FadeOut(2000, Easing.InQuint).Expire();
});
request.Failure += _ => Schedule(() =>
{
loading.Hide();
link.Show();
});
api.Queue(request);
}
public Popover GetPopover() => new ReportCommentPopover(comment)
{
Action = report
};
}
}

View File

@ -0,0 +1,26 @@
// 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.Framework.Localisation;
using osu.Game.Resources.Localisation.Web;
namespace osu.Game.Overlays.Comments
{
public enum CommentReportReason
{
[LocalisableDescription(typeof(UsersStrings), nameof(UsersStrings.ReportOptionsInsults))]
Insults,
[LocalisableDescription(typeof(UsersStrings), nameof(UsersStrings.ReportOptionsSpam))]
Spam,
[LocalisableDescription(typeof(UsersStrings), nameof(UsersStrings.ReportOptionsUnwantedContent))]
UnwantedContent,
[LocalisableDescription(typeof(UsersStrings), nameof(UsersStrings.ReportOptionsNonsense))]
Nonsense,
[LocalisableDescription(typeof(UsersStrings), nameof(UsersStrings.ReportOptionsOther))]
Other
}
}

View File

@ -31,6 +31,7 @@ using osu.Game.Resources.Localisation.Web;
namespace osu.Game.Overlays.Comments
{
[Cached]
public class DrawableComment : CompositeDrawable
{
private const int avatar_size = 40;
@ -331,12 +332,12 @@ namespace osu.Game.Overlays.Comments
makeDeleted();
actionsContainer.AddLink("Copy link", copyUrl);
actionsContainer.AddArbitraryDrawable(new Container { Width = 10 });
actionsContainer.AddArbitraryDrawable(Empty().With(d => d.Width = 10));
if (Comment.UserId.HasValue && Comment.UserId.Value == api.LocalUser.Value.Id)
{
actionsContainer.AddLink("Delete", deleteComment);
}
else
actionsContainer.AddArbitraryDrawable(new CommentReportButton(Comment));
if (Comment.IsTopLevel)
{

View File

@ -0,0 +1,111 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Resources.Localisation.Web;
using osuTK;
namespace osu.Game.Overlays.Comments
{
public class ReportCommentPopover : OsuPopover
{
public Action<CommentReportReason, string>? Action;
private readonly Comment? comment;
private OsuEnumDropdown<CommentReportReason> reasonDropdown = null!;
private OsuTextBox commentsTextBox = null!;
private RoundedButton submitButton = null!;
public ReportCommentPopover(Comment? comment)
{
this.comment = comment;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Child = new ReverseChildIDFillFlowContainer<Drawable>
{
Direction = FillDirection.Vertical,
Width = 500,
AutoSizeAxes = Axes.Y,
Spacing = new Vector2(7),
Children = new Drawable[]
{
new SpriteIcon
{
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Icon = FontAwesome.Solid.ExclamationTriangle,
Size = new Vector2(36),
},
new OsuSpriteText
{
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Text = ReportStrings.CommentTitle(comment?.User?.Username ?? comment?.LegacyName ?? @"Someone"),
Font = OsuFont.Torus.With(size: 25),
Margin = new MarginPadding { Bottom = 10 }
},
new OsuSpriteText
{
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Text = UsersStrings.ReportReason,
},
new Container
{
RelativeSizeAxes = Axes.X,
Height = 40,
Child = reasonDropdown = new OsuEnumDropdown<CommentReportReason>
{
RelativeSizeAxes = Axes.X
}
},
new OsuSpriteText
{
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Text = UsersStrings.ReportComments,
},
commentsTextBox = new OsuTextBox
{
RelativeSizeAxes = Axes.X,
PlaceholderText = UsersStrings.ReportPlaceholder,
},
submitButton = new RoundedButton
{
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Width = 200,
BackgroundColour = colours.Red3,
Text = UsersStrings.ReportActionsSend,
Action = () =>
{
Action?.Invoke(reasonDropdown.Current.Value, commentsTextBox.Text);
this.HidePopover();
},
Margin = new MarginPadding { Bottom = 5, Top = 10 },
}
}
};
commentsTextBox.Current.BindValueChanged(e =>
{
submitButton.Enabled.Value = !string.IsNullOrWhiteSpace(e.NewValue);
}, true);
}
}
}

View File

@ -6,6 +6,7 @@
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online;
@ -45,7 +46,7 @@ namespace osu.Game.Overlays
Children = new Drawable[]
{
Header.With(h => h.Depth = float.MinValue),
content = new Container
content = new PopoverContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y

View File

@ -502,8 +502,6 @@ namespace osu.Game.Screens.Select
if (transferRulesetValue())
{
Mods.Value = Array.Empty<Mod>();
// transferRulesetValue() may trigger a re-filter. If the current selection does not match the new ruleset, we want to switch away from it.
// The default logic on WorkingBeatmap change is to switch to a matching ruleset (see workingBeatmapChanged()), but we don't want that here.
// We perform an early selection attempt and clear out the beatmap selection to avoid a second ruleset change (revert).