Refactor settings item "warning" text to allow non-warning state

This commit is contained in:
Dean Herbert 2022-05-31 14:01:42 +09:00
parent 7caf4c1ac1
commit 53844d3df1
8 changed files with 57 additions and 53 deletions

View File

@ -6,6 +6,7 @@ using NUnit.Framework;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Settings; using osu.Game.Overlays.Settings;
@ -83,7 +84,7 @@ namespace osu.Game.Tests.Visual.Settings
AddStep("clear label", () => textBox.LabelText = default); AddStep("clear label", () => textBox.LabelText = default);
AddAssert("default value button centre aligned to control size", () => Precision.AlmostEquals(restoreDefaultValueButton.Parent.DrawHeight, control.DrawHeight, 1)); AddAssert("default value button centre aligned to control size", () => Precision.AlmostEquals(restoreDefaultValueButton.Parent.DrawHeight, control.DrawHeight, 1));
AddStep("set warning text", () => textBox.WarningText = "This is some very important warning text! Hopefully it doesn't break the alignment of the default value indicator..."); AddStep("set warning text", () => textBox.SetWarningText("This is some very important warning text! Hopefully it doesn't break the alignment of the default value indicator..."));
AddAssert("default value button centre aligned to control size", () => Precision.AlmostEquals(restoreDefaultValueButton.Parent.DrawHeight, control.DrawHeight, 1)); AddAssert("default value button centre aligned to control size", () => Precision.AlmostEquals(restoreDefaultValueButton.Parent.DrawHeight, control.DrawHeight, 1));
} }
@ -129,16 +130,18 @@ namespace osu.Game.Tests.Visual.Settings
SettingsNumberBox numberBox = null; SettingsNumberBox numberBox = null;
AddStep("create settings item", () => Child = numberBox = new SettingsNumberBox()); AddStep("create settings item", () => Child = numberBox = new SettingsNumberBox());
AddAssert("warning text not created", () => !numberBox.ChildrenOfType<SettingsNoticeText>().Any()); AddAssert("warning text not created", () => !numberBox.ChildrenOfType<LinkFlowContainer>().Any());
AddStep("set warning text", () => numberBox.WarningText = "this is a warning!"); AddStep("set warning text", () => numberBox.SetWarningText("this is a warning!"));
AddAssert("warning text created", () => numberBox.ChildrenOfType<SettingsNoticeText>().Single().Alpha == 1); AddAssert("warning text created", () => numberBox.ChildrenOfType<LinkFlowContainer>().Single().Alpha == 1);
AddStep("unset warning text", () => numberBox.WarningText = default); AddStep("unset warning text", () => numberBox.ClearWarningText());
AddAssert("warning text hidden", () => numberBox.ChildrenOfType<SettingsNoticeText>().Single().Alpha == 0); AddAssert("warning text hidden", () => !numberBox.ChildrenOfType<LinkFlowContainer>().Any());
AddStep("set warning text again", () => numberBox.WarningText = "another warning!"); AddStep("set warning text again", () => numberBox.SetWarningText("another warning!"));
AddAssert("warning text shown again", () => numberBox.ChildrenOfType<SettingsNoticeText>().Single().Alpha == 1); AddAssert("warning text shown again", () => numberBox.ChildrenOfType<LinkFlowContainer>().Single().Alpha == 1);
AddStep("set non warning text", () => numberBox.SetWarningText("you did good!", false));
} }
} }
} }

View File

@ -226,7 +226,7 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
{ {
if (windowModeDropdown.Current.Value != WindowMode.Fullscreen) if (windowModeDropdown.Current.Value != WindowMode.Fullscreen)
{ {
windowModeDropdown.WarningText = GraphicsSettingsStrings.NotFullscreenNote; windowModeDropdown.SetWarningText(GraphicsSettingsStrings.NotFullscreenNote);
return; return;
} }
@ -234,15 +234,15 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
{ {
case FullscreenCapability.Unknown: case FullscreenCapability.Unknown:
if (host.Window is WindowsWindow) if (host.Window is WindowsWindow)
windowModeDropdown.WarningText = LayoutSettingsStrings.CheckingForFullscreenCapabilities; windowModeDropdown.SetWarningText(LayoutSettingsStrings.CheckingForFullscreenCapabilities);
break; break;
case FullscreenCapability.Capable: case FullscreenCapability.Capable:
windowModeDropdown.WarningText = LayoutSettingsStrings.OsuIsRunningExclusiveFullscreen; windowModeDropdown.SetWarningText(LayoutSettingsStrings.OsuIsRunningExclusiveFullscreen, false);
break; break;
case FullscreenCapability.Incapable: case FullscreenCapability.Incapable:
windowModeDropdown.WarningText = LayoutSettingsStrings.UnableToRunExclusiveFullscreen; windowModeDropdown.SetWarningText(LayoutSettingsStrings.UnableToRunExclusiveFullscreen);
break; break;
} }
} }

View File

@ -48,7 +48,16 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
frameLimiterDropdown.Current.BindValueChanged(limit => frameLimiterDropdown.Current.BindValueChanged(limit =>
{ {
frameLimiterDropdown.WarningText = limit.NewValue == FrameSync.Unlimited ? GraphicsSettingsStrings.UnlimitedFramesNote : default; switch (limit.NewValue)
{
case FrameSync.Unlimited:
frameLimiterDropdown.SetWarningText(GraphicsSettingsStrings.UnlimitedFramesNote);
break;
default:
frameLimiterDropdown.ClearWarningText();
break;
}
}, true); }, true);
} }
} }

View File

@ -117,9 +117,9 @@ namespace osu.Game.Overlays.Settings.Sections.Input
if (RuntimeInfo.OS != RuntimeInfo.Platform.Windows) if (RuntimeInfo.OS != RuntimeInfo.Platform.Windows)
{ {
if (highPrecision.NewValue) if (highPrecision.NewValue)
highPrecisionMouse.WarningText = MouseSettingsStrings.HighPrecisionPlatformWarning; highPrecisionMouse.SetWarningText(MouseSettingsStrings.HighPrecisionPlatformWarning);
else else
highPrecisionMouse.WarningText = null; highPrecisionMouse.ClearWarningText();
} }
}, true); }, true);
} }

View File

@ -11,6 +11,7 @@ using osu.Framework.Localisation;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Framework.Threading; using osu.Framework.Threading;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osuTK; using osuTK;
using osu.Game.Localisation; using osu.Game.Localisation;
@ -95,11 +96,13 @@ namespace osu.Game.Overlays.Settings.Sections.Input
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
Text = TabletSettingsStrings.NoTabletDetected, Text = TabletSettingsStrings.NoTabletDetected,
}, },
new SettingsNoticeText(colours) new LinkFlowContainer(cp => cp.Colour = colours.Yellow)
{ {
TextAnchor = Anchor.TopCentre, TextAnchor = Anchor.TopCentre,
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
}.With(t => }.With(t =>
{ {
if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows || RuntimeInfo.OS == RuntimeInfo.Platform.Linux) if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows || RuntimeInfo.OS == RuntimeInfo.Platform.Linux)

View File

@ -61,7 +61,10 @@ namespace osu.Game.Overlays.Settings.Sections.UserInterface
user.BindValueChanged(u => user.BindValueChanged(u =>
{ {
backgroundSourceDropdown.WarningText = u.NewValue?.IsSupporter != true ? UserInterfaceStrings.NotSupporterNote : default; if (u.NewValue?.IsSupporter != true)
backgroundSourceDropdown.SetWarningText(UserInterfaceStrings.NotSupporterNote);
else
backgroundSourceDropdown.ClearWarningText();
}, true); }, true);
} }
} }

View File

@ -70,27 +70,32 @@ namespace osu.Game.Overlays.Settings
} }
/// <summary> /// <summary>
/// Text to be displayed at the bottom of this <see cref="SettingsItem{T}"/>. /// Clear any warning text.
/// </summary>
public void ClearWarningText()
{
warningText?.Expire();
warningText = null;
}
/// <summary>
/// Set the text to be displayed at the bottom of this <see cref="SettingsItem{T}"/>.
/// Generally used to recommend the user change their setting as the current one is considered sub-optimal. /// Generally used to recommend the user change their setting as the current one is considered sub-optimal.
/// </summary> /// </summary>
public LocalisableString? WarningText /// <param name="text">The text to display.</param>
/// <param name="isWarning">Whether the text is in a warning state. Will decide how this is visually represented.</param>
public void SetWarningText(LocalisableString text, bool isWarning = true)
{ {
set ClearWarningText();
// construct lazily for cases where the label is not needed (may be provided by the Control).
FlowContent.Add(warningText = new LinkFlowContainer(cp => cp.Colour = isWarning ? colours.Yellow : colours.Green)
{ {
bool hasValue = value != default; RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
if (warningText == null) Margin = new MarginPadding { Bottom = 5 },
{ Text = text,
if (!hasValue) });
return;
// construct lazily for cases where the label is not needed (may be provided by the Control).
FlowContent.Add(warningText = new SettingsNoticeText(colours) { Margin = new MarginPadding { Bottom = 5 } });
}
warningText.Alpha = hasValue ? 1 : 0;
warningText.Text = value ?? default;
}
} }
public virtual Bindable<T> Current public virtual Bindable<T> Current

View File

@ -1,19 +0,0 @@
// 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.Graphics;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
namespace osu.Game.Overlays.Settings
{
public class SettingsNoticeText : LinkFlowContainer
{
public SettingsNoticeText(OsuColour colours)
: base(s => s.Colour = colours.Yellow)
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
}
}
}