-
Notifications
You must be signed in to change notification settings - Fork 16
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 #2155 from andy840119/move-message-container-into-…
…part-of-tooltip Move message container into part of tooltip.
- Loading branch information
Showing
4 changed files
with
83 additions
and
159 deletions.
There are no files selected for viewing
72 changes: 0 additions & 72 deletions
72
osu.Game.Rulesets.Karaoke.Tests/Graphics/TestSceneMessageContainer.cs
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using NUnit.Framework; | ||
using osu.Framework.Graphics; | ||
using osu.Game.Rulesets.Edit.Checks.Components; | ||
using osu.Game.Rulesets.Karaoke.Screens.Edit.Components.Issues; | ||
using osu.Game.Rulesets.Karaoke.Tests.Helper; | ||
using osu.Game.Tests.Visual; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Tests.Screens.Edit.Components.Issues; | ||
|
@@ -26,16 +28,25 @@ public void SetUp() => Schedule(() => | |
}); | ||
|
||
[Test] | ||
public void TestValidLyric() | ||
public void TestTooltipWithoutIssue() | ||
{ | ||
setTooltip("valid lyric"); | ||
AddStep("Test tooltip with no issue.", () => | ||
{ | ||
toolTip.SetContent(Array.Empty<Issue>()); | ||
}); | ||
} | ||
|
||
private void setTooltip(string testName, params Issue[] issues) | ||
[Test] | ||
public void TestTooltipWithIssue() | ||
{ | ||
AddStep(testName, () => | ||
var availableIssues = TestCaseCheckHelper.CreateAllAvailableIssues(); | ||
|
||
foreach (var (check, issues) in availableIssues) | ||
{ | ||
toolTip.SetContent(issues); | ||
}); | ||
AddStep($"Check {check.Metadata.Description} has {issues.Length} issues.", () => | ||
{ | ||
toolTip.SetContent(issues); | ||
}); | ||
} | ||
} | ||
} |
62 changes: 0 additions & 62 deletions
62
osu.Game.Rulesets.Karaoke/Graphics/Containers/MessageContainer.cs
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,12 +1,15 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using System.ComponentModel; | ||
using System.Collections.Generic; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Extensions.Color4Extensions; | ||
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.Rulesets.Edit.Checks.Components; | ||
using osu.Game.Rulesets.Karaoke.Graphics.Containers; | ||
using osu.Game.Rulesets.Karaoke.Graphics.Cursor; | ||
using osuTK; | ||
using osuTK.Graphics; | ||
|
@@ -15,11 +18,11 @@ namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Components.Issues; | |
|
||
public partial class IssuesToolTip : BackgroundToolTip<Issue[]> | ||
{ | ||
private readonly MessageContainer invalidMessage; | ||
private readonly MessageTextFlowContainer invalidMessage; | ||
|
||
public IssuesToolTip() | ||
{ | ||
Child = invalidMessage = new MessageContainer(s => s.Font = s.Font.With(size: 14)) | ||
Child = invalidMessage = new MessageTextFlowContainer | ||
{ | ||
Width = 300, | ||
AutoSizeAxes = Axes.Y, | ||
|
@@ -29,7 +32,7 @@ public IssuesToolTip() | |
}; | ||
} | ||
|
||
private Issue[] lastIssues = Array.Empty<Issue>(); | ||
private Issue[]? lastIssues; | ||
|
||
public override void SetContent(Issue[] issues) | ||
{ | ||
|
@@ -41,23 +44,67 @@ public override void SetContent(Issue[] issues) | |
// clear exist warning. | ||
invalidMessage.Clear(); | ||
|
||
foreach (var issue in issues) | ||
// show no problem message | ||
if (issues.Length == 0) | ||
{ | ||
invalidMessage.AddSuccessParagraph("Seems no issue in this lyric."); | ||
} | ||
else | ||
{ | ||
switch (issue) | ||
foreach (var issue in issues) | ||
{ | ||
// print normal message | ||
case Issue: | ||
invalidMessage.AddAlertParagraph(issue.Template.GetMessage()); | ||
break; | ||
|
||
// Should throw exception because every issue message should be printed. | ||
default: | ||
throw new InvalidEnumArgumentException(nameof(issue)); | ||
invalidMessage.AddIssueParagraph(issue); | ||
} | ||
} | ||
} | ||
|
||
// show no problem message | ||
if (issues.Length == 0) | ||
invalidMessage.AddSuccessParagraph("Seems no issue in this lyric."); | ||
private partial class MessageTextFlowContainer : OsuTextFlowContainer | ||
{ | ||
private const int font_size = 14; | ||
|
||
[Resolved] | ||
private OsuColour colours { get; set; } = null!; | ||
|
||
public MessageTextFlowContainer() | ||
: base(s => s.Font = s.Font.With(size: font_size)) | ||
{ | ||
} | ||
|
||
public void AddIssueParagraph(Issue issue) | ||
{ | ||
NewParagraph(); | ||
|
||
AddPart(new IssueIconTextPart(issue)); | ||
AddText($" {issue}"); | ||
} | ||
|
||
public void AddSuccessParagraph(string text) | ||
{ | ||
NewParagraph(); | ||
AddIcon(FontAwesome.Solid.Check, icon => | ||
{ | ||
icon.Colour = colours.Green; | ||
}); | ||
AddText($" {text}"); | ||
} | ||
|
||
private class IssueIconTextPart : TextPart | ||
{ | ||
private readonly Issue issue; | ||
|
||
public IssueIconTextPart(Issue issue) | ||
{ | ||
this.issue = issue; | ||
} | ||
|
||
protected override IEnumerable<Drawable> CreateDrawablesFor(TextFlowContainer textFlowContainer) | ||
{ | ||
yield return new IssueIcon | ||
{ | ||
Size = new Vector2(font_size), | ||
Issue = issue, | ||
}; | ||
} | ||
} | ||
} | ||
} |