Skip to content

Commit

Permalink
Merge pull request #2155 from andy840119/move-message-container-into-…
Browse files Browse the repository at this point in the history
…part-of-tooltip

Move message container into part of tooltip.
  • Loading branch information
andy840119 authored Dec 17, 2023
2 parents affd087 + f68113f commit 4beac86
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 159 deletions.

This file was deleted.

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;
Expand All @@ -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 osu.Game.Rulesets.Karaoke/Graphics/Containers/MessageContainer.cs

This file was deleted.

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;
Expand All @@ -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,
Expand All @@ -29,7 +32,7 @@ public IssuesToolTip()
};
}

private Issue[] lastIssues = Array.Empty<Issue>();
private Issue[]? lastIssues;

public override void SetContent(Issue[] issues)
{
Expand All @@ -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,
};
}
}
}
}

0 comments on commit 4beac86

Please sign in to comment.