From 1bfe5a18cb94de911bb6ecf445abc8d32fe254ca Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 13 Jul 2023 13:46:50 +0900 Subject: [PATCH 1/7] Rename `RestoreDefaultValueButton` to `RevertToDefaultButton` Because I can't find it every time I search. --- .../Settings/TestSceneKeyBindingPanel.cs | 10 +++--- ...n.cs => TestSceneRevertToDefaultButton.cs} | 10 +++--- .../Visual/Settings/TestSceneSettingsItem.cs | 34 +++++++++---------- .../TestSceneModSelectOverlay.cs | 2 +- ...alueButton.cs => RevertToDefaultButton.cs} | 4 +-- .../Settings/Sections/Input/KeyBindingRow.cs | 2 +- osu.Game/Overlays/Settings/SettingsItem.cs | 2 +- 7 files changed, 32 insertions(+), 32 deletions(-) rename osu.Game.Tests/Visual/Settings/{TestSceneRestoreDefaultValueButton.cs => TestSceneRevertToDefaultButton.cs} (82%) rename osu.Game/Overlays/{RestoreDefaultValueButton.cs => RevertToDefaultButton.cs} (97%) diff --git a/osu.Game.Tests/Visual/Settings/TestSceneKeyBindingPanel.cs b/osu.Game.Tests/Visual/Settings/TestSceneKeyBindingPanel.cs index da48086717..449ca0f258 100644 --- a/osu.Game.Tests/Visual/Settings/TestSceneKeyBindingPanel.cs +++ b/osu.Game.Tests/Visual/Settings/TestSceneKeyBindingPanel.cs @@ -195,16 +195,16 @@ public void TestSingleBindingResetButton() InputManager.ReleaseKey(Key.P); }); - AddUntilStep("restore button shown", () => settingsKeyBindingRow.ChildrenOfType>().First().Alpha > 0); + AddUntilStep("restore button shown", () => settingsKeyBindingRow.ChildrenOfType>().First().Alpha > 0); AddStep("click reset button for bindings", () => { - var resetButton = settingsKeyBindingRow.ChildrenOfType>().First(); + var resetButton = settingsKeyBindingRow.ChildrenOfType>().First(); resetButton.TriggerClick(); }); - AddUntilStep("restore button hidden", () => settingsKeyBindingRow.ChildrenOfType>().First().Alpha == 0); + AddUntilStep("restore button hidden", () => settingsKeyBindingRow.ChildrenOfType>().First().Alpha == 0); AddAssert("binding cleared", () => settingsKeyBindingRow.ChildrenOfType().ElementAt(0).KeyBinding.KeyCombination.Equals(settingsKeyBindingRow.Defaults.ElementAt(0))); @@ -225,7 +225,7 @@ public void TestResetAllBindingsButton() InputManager.ReleaseKey(Key.P); }); - AddUntilStep("restore button shown", () => settingsKeyBindingRow.ChildrenOfType>().First().Alpha > 0); + AddUntilStep("restore button shown", () => settingsKeyBindingRow.ChildrenOfType>().First().Alpha > 0); AddStep("click reset button for bindings", () => { @@ -234,7 +234,7 @@ public void TestResetAllBindingsButton() resetButton.TriggerClick(); }); - AddUntilStep("restore button hidden", () => settingsKeyBindingRow.ChildrenOfType>().First().Alpha == 0); + AddUntilStep("restore button hidden", () => settingsKeyBindingRow.ChildrenOfType>().First().Alpha == 0); AddAssert("binding cleared", () => settingsKeyBindingRow.ChildrenOfType().ElementAt(0).KeyBinding.KeyCombination.Equals(settingsKeyBindingRow.Defaults.ElementAt(0))); diff --git a/osu.Game.Tests/Visual/Settings/TestSceneRestoreDefaultValueButton.cs b/osu.Game.Tests/Visual/Settings/TestSceneRevertToDefaultButton.cs similarity index 82% rename from osu.Game.Tests/Visual/Settings/TestSceneRestoreDefaultValueButton.cs rename to osu.Game.Tests/Visual/Settings/TestSceneRevertToDefaultButton.cs index 6e52881f5e..609283edfc 100644 --- a/osu.Game.Tests/Visual/Settings/TestSceneRestoreDefaultValueButton.cs +++ b/osu.Game.Tests/Visual/Settings/TestSceneRevertToDefaultButton.cs @@ -15,7 +15,7 @@ namespace osu.Game.Tests.Visual.Settings { - public partial class TestSceneRestoreDefaultValueButton : OsuTestScene + public partial class TestSceneRevertToDefaultButton : OsuTestScene { [Resolved] private OsuColour colours { get; set; } @@ -31,7 +31,7 @@ public partial class TestSceneRestoreDefaultValueButton : OsuTestScene [Test] public void TestBasic() { - RestoreDefaultValueButton restoreDefaultValueButton = null; + RevertToDefaultButton revertToDefaultButton = null; AddStep("create button", () => Child = new Container { @@ -43,7 +43,7 @@ public void TestBasic() RelativeSizeAxes = Axes.Both, Colour = colours.GreySeaFoam }, - restoreDefaultValueButton = new RestoreDefaultValueButton + revertToDefaultButton = new RevertToDefaultButton { Anchor = Anchor.Centre, Origin = Anchor.Centre, @@ -55,8 +55,8 @@ public void TestBasic() AddSliderStep("set scale", 1, 4, 1, scale => { this.scale = scale; - if (restoreDefaultValueButton != null) - restoreDefaultValueButton.Scale = new Vector2(scale); + if (revertToDefaultButton != null) + revertToDefaultButton.Scale = new Vector2(scale); }); AddToggleStep("toggle default state", state => current.Value = state ? default : 1); AddToggleStep("toggle disabled state", state => current.Disabled = state); diff --git a/osu.Game.Tests/Visual/Settings/TestSceneSettingsItem.cs b/osu.Game.Tests/Visual/Settings/TestSceneSettingsItem.cs index 384508f375..ec0ad685c5 100644 --- a/osu.Game.Tests/Visual/Settings/TestSceneSettingsItem.cs +++ b/osu.Game.Tests/Visual/Settings/TestSceneSettingsItem.cs @@ -23,7 +23,7 @@ public partial class TestSceneSettingsItem : OsuTestScene public void TestRestoreDefaultValueButtonVisibility() { SettingsTextBox textBox = null; - RestoreDefaultValueButton restoreDefaultValueButton = null; + RevertToDefaultButton revertToDefaultButton = null; AddStep("create settings item", () => { @@ -33,22 +33,22 @@ public void TestRestoreDefaultValueButtonVisibility() }; }); AddUntilStep("wait for loaded", () => textBox.IsLoaded); - AddStep("retrieve restore default button", () => restoreDefaultValueButton = textBox.ChildrenOfType>().Single()); + AddStep("retrieve restore default button", () => revertToDefaultButton = textBox.ChildrenOfType>().Single()); - AddAssert("restore button hidden", () => restoreDefaultValueButton.Alpha == 0); + AddAssert("restore button hidden", () => revertToDefaultButton.Alpha == 0); AddStep("change value from default", () => textBox.Current.Value = "non-default"); - AddUntilStep("restore button shown", () => restoreDefaultValueButton.Alpha > 0); + AddUntilStep("restore button shown", () => revertToDefaultButton.Alpha > 0); AddStep("restore default", () => textBox.Current.SetDefault()); - AddUntilStep("restore button hidden", () => restoreDefaultValueButton.Alpha == 0); + AddUntilStep("restore button hidden", () => revertToDefaultButton.Alpha == 0); } [Test] public void TestSetAndClearLabelText() { SettingsTextBox textBox = null; - RestoreDefaultValueButton restoreDefaultValueButton = null; + RevertToDefaultButton revertToDefaultButton = null; OsuTextBox control = null; AddStep("create settings item", () => @@ -61,25 +61,25 @@ public void TestSetAndClearLabelText() AddUntilStep("wait for loaded", () => textBox.IsLoaded); AddStep("retrieve components", () => { - restoreDefaultValueButton = textBox.ChildrenOfType>().Single(); + revertToDefaultButton = textBox.ChildrenOfType>().Single(); control = textBox.ChildrenOfType().Single(); }); - AddStep("set non-default value", () => restoreDefaultValueButton.Current.Value = "non-default"); - AddAssert("default value button centre aligned to control size", () => Precision.AlmostEquals(restoreDefaultValueButton.Parent.DrawHeight, control.DrawHeight, 1)); + AddStep("set non-default value", () => revertToDefaultButton.Current.Value = "non-default"); + AddAssert("default value button centre aligned to control size", () => Precision.AlmostEquals(revertToDefaultButton.Parent.DrawHeight, control.DrawHeight, 1)); AddStep("set label", () => textBox.LabelText = "label text"); AddAssert("default value button centre aligned to label size", () => { var label = textBox.ChildrenOfType().Single(spriteText => spriteText.Text == "label text"); - return Precision.AlmostEquals(restoreDefaultValueButton.Parent.DrawHeight, label.DrawHeight, 1); + return Precision.AlmostEquals(revertToDefaultButton.Parent.DrawHeight, label.DrawHeight, 1); }); 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(revertToDefaultButton.Parent.DrawHeight, control.DrawHeight, 1)); AddStep("set warning text", () => textBox.SetNoticeText("This is some very important warning text! Hopefully it doesn't break the alignment of the default value indicator...", true)); - 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(revertToDefaultButton.Parent.DrawHeight, control.DrawHeight, 1)); } /// @@ -92,7 +92,7 @@ public void TestRestoreDefaultValueButtonPrecision(float initialValue) { BindableFloat current = null; SettingsSlider sliderBar = null; - RestoreDefaultValueButton restoreDefaultValueButton = null; + RevertToDefaultButton revertToDefaultButton = null; AddStep("create settings item", () => { @@ -107,15 +107,15 @@ public void TestRestoreDefaultValueButtonPrecision(float initialValue) }; }); AddUntilStep("wait for loaded", () => sliderBar.IsLoaded); - AddStep("retrieve restore default button", () => restoreDefaultValueButton = sliderBar.ChildrenOfType>().Single()); + AddStep("retrieve restore default button", () => revertToDefaultButton = sliderBar.ChildrenOfType>().Single()); - AddAssert("restore button hidden", () => restoreDefaultValueButton.Alpha == 0); + AddAssert("restore button hidden", () => revertToDefaultButton.Alpha == 0); AddStep("change value to next closest", () => sliderBar.Current.Value += current.Precision * 0.6f); - AddUntilStep("restore button shown", () => restoreDefaultValueButton.Alpha > 0); + AddUntilStep("restore button shown", () => revertToDefaultButton.Alpha > 0); AddStep("restore default", () => sliderBar.Current.SetDefault()); - AddUntilStep("restore button hidden", () => restoreDefaultValueButton.Alpha == 0); + AddUntilStep("restore button hidden", () => revertToDefaultButton.Alpha == 0); } [Test] diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneModSelectOverlay.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneModSelectOverlay.cs index 4cb6899ebc..ad79865ad9 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneModSelectOverlay.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneModSelectOverlay.cs @@ -793,7 +793,7 @@ public void TestModMultiplierUpdates() AddStep("open customisation area", () => modSelectOverlay.CustomisationButton!.TriggerClick()); AddStep("reset half time speed to default", () => modSelectOverlay.ChildrenOfType().Single() - .ChildrenOfType>().Single().TriggerClick()); + .ChildrenOfType>().Single().TriggerClick()); AddUntilStep("difficulty multiplier display shows correct value", () => modSelectOverlay.ChildrenOfType().Single().Current.Value, () => Is.EqualTo(0.7)); } diff --git a/osu.Game/Overlays/RestoreDefaultValueButton.cs b/osu.Game/Overlays/RevertToDefaultButton.cs similarity index 97% rename from osu.Game/Overlays/RestoreDefaultValueButton.cs rename to osu.Game/Overlays/RevertToDefaultButton.cs index 97c66fdf02..fcd8b74009 100644 --- a/osu.Game/Overlays/RestoreDefaultValueButton.cs +++ b/osu.Game/Overlays/RevertToDefaultButton.cs @@ -22,7 +22,7 @@ namespace osu.Game.Overlays { - public partial class RestoreDefaultValueButton : OsuClickableContainer, IHasCurrentValue + public partial class RevertToDefaultButton : OsuClickableContainer, IHasCurrentValue { public override bool IsPresent => base.IsPresent || Scheduler.HasPendingTasks; @@ -58,7 +58,7 @@ public Bindable Current private CircularContainer circle = null!; private Box background = null!; - public RestoreDefaultValueButton() + public RevertToDefaultButton() : base(HoverSampleSet.Button) { } diff --git a/osu.Game/Overlays/Settings/Sections/Input/KeyBindingRow.cs b/osu.Game/Overlays/Settings/Sections/Input/KeyBindingRow.cs index 725925c8cf..1e2283b58b 100644 --- a/osu.Game/Overlays/Settings/Sections/Input/KeyBindingRow.cs +++ b/osu.Game/Overlays/Settings/Sections/Input/KeyBindingRow.cs @@ -103,7 +103,7 @@ private void load(OverlayColourProvider colourProvider) { RelativeSizeAxes = Axes.Y, Width = SettingsPanel.CONTENT_MARGINS, - Child = new RestoreDefaultValueButton + Child = new RevertToDefaultButton { Current = isDefault, Action = RestoreDefaults, diff --git a/osu.Game/Overlays/Settings/SettingsItem.cs b/osu.Game/Overlays/Settings/SettingsItem.cs index 5f4bb9d57f..9085b6c911 100644 --- a/osu.Game/Overlays/Settings/SettingsItem.cs +++ b/osu.Game/Overlays/Settings/SettingsItem.cs @@ -217,7 +217,7 @@ private void load() // intentionally done before LoadComplete to avoid overhead. if (ShowsDefaultIndicator) { - defaultValueIndicatorContainer.Add(new RestoreDefaultValueButton + defaultValueIndicatorContainer.Add(new RevertToDefaultButton { Current = controlWithCurrent.Current, Anchor = Anchor.Centre, From 94201579f6d6307308cb9823a308d9bd9c6db5cc Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 13 Jul 2023 14:26:01 +0900 Subject: [PATCH 2/7] Update design of "revert to default" button I keep getting feedback that the old design looked like anything *but* a button to revert defaults. Including people clicking it expecting opposite behaviour. This is intended to be a temporary design until we get the full new UI components online (where this is moved to the right-hand-side). --- .../TestSceneRevertToDefaultButton.cs | 13 ++- osu.Game/Overlays/RevertToDefaultButton.cs | 85 +++++++++---------- 2 files changed, 44 insertions(+), 54 deletions(-) diff --git a/osu.Game.Tests/Visual/Settings/TestSceneRevertToDefaultButton.cs b/osu.Game.Tests/Visual/Settings/TestSceneRevertToDefaultButton.cs index 609283edfc..bfef120358 100644 --- a/osu.Game.Tests/Visual/Settings/TestSceneRevertToDefaultButton.cs +++ b/osu.Game.Tests/Visual/Settings/TestSceneRevertToDefaultButton.cs @@ -1,15 +1,12 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; -using osu.Game.Graphics; using osu.Game.Overlays; using osuTK; @@ -17,11 +14,11 @@ namespace osu.Game.Tests.Visual.Settings { public partial class TestSceneRevertToDefaultButton : OsuTestScene { - [Resolved] - private OsuColour colours { get; set; } - private float scale = 1; + [Cached] + private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple); + private readonly Bindable current = new Bindable { Default = default, @@ -31,7 +28,7 @@ public partial class TestSceneRevertToDefaultButton : OsuTestScene [Test] public void TestBasic() { - RevertToDefaultButton revertToDefaultButton = null; + RevertToDefaultButton revertToDefaultButton = null!; AddStep("create button", () => Child = new Container { @@ -41,7 +38,7 @@ public void TestBasic() new Box { RelativeSizeAxes = Axes.Both, - Colour = colours.GreySeaFoam + Colour = colourProvider.Background2, }, revertToDefaultButton = new RevertToDefaultButton { diff --git a/osu.Game/Overlays/RevertToDefaultButton.cs b/osu.Game/Overlays/RevertToDefaultButton.cs index fcd8b74009..48491c5d9c 100644 --- a/osu.Game/Overlays/RevertToDefaultButton.cs +++ b/osu.Game/Overlays/RevertToDefaultButton.cs @@ -1,24 +1,20 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Allocation; using osu.Framework.Bindables; -using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.LocalisationExtensions; +using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; using osu.Framework.Input.Events; using osu.Framework.Localisation; -using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.UserInterface; -using osuTK; using osu.Game.Localisation; +using osuTK; namespace osu.Game.Overlays { @@ -31,11 +27,17 @@ public partial class RevertToDefaultButton : OsuClickableContainer, IHasCurre // this is intentionally not using BindableWithCurrent, as it can use the wrong IsDefault implementation when passed a BindableNumber. // using GetBoundCopy() ensures that the received bindable is of the exact same type as the source bindable and uses the proper IsDefault implementation. - private Bindable current; + private Bindable? current; + + private SpriteIcon icon = null!; + private Circle circle = null!; + + [Resolved] + private OverlayColourProvider colours { get; set; } = null!; public Bindable Current { - get => current; + get => current.AsNonNull(); set { current?.UnbindAll(); @@ -50,43 +52,37 @@ public Bindable Current } } - [Resolved] - private OsuColour colours { get; set; } - - private const float size = 4; - - private CircularContainer circle = null!; - private Box background = null!; - public RevertToDefaultButton() : base(HoverSampleSet.Button) { } [BackgroundDependencyLoader] - private void load(OsuColour colour) + private void load() { // size intentionally much larger than actual drawn content, so that the button is easier to click. - Size = new Vector2(3 * size); + Size = new Vector2(14); - Add(circle = new CircularContainer + AddRange(new Drawable[] { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Size = new Vector2(size), - Masking = true, - Child = background = new Box + circle = new Circle { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, RelativeSizeAxes = Axes.Both, - Colour = colour.Lime1 + }, + icon = new SpriteIcon + { + Icon = FontAwesome.Solid.Undo, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(8), } }); - Alpha = 0f; - Action += () => { - if (!current.Disabled) + if (current?.Disabled == false) current.SetDefault(); }; } @@ -120,28 +116,25 @@ private void updateState() if (current == null) return; - Enabled.Value = !Current.Disabled; + Enabled.Value = !current.Disabled; - if (!Current.Disabled) + this.FadeTo(current.Disabled ? 0.2f : (Current.IsDefault ? 0 : 1), fade_duration, Easing.OutQuint); + + if (IsHovered && Enabled.Value) { - this.FadeTo(Current.IsDefault ? 0 : 1, fade_duration, Easing.OutQuint); - background.FadeColour(IsHovered ? colours.Lime0 : colours.Lime1, fade_duration, Easing.OutQuint); - circle.TweenEdgeEffectTo(new EdgeEffectParameters - { - Colour = (IsHovered ? colours.Lime1 : colours.Lime3).Opacity(0.4f), - Radius = IsHovered ? 8 : 4, - Type = EdgeEffectType.Glow - }, fade_duration, Easing.OutQuint); + icon.RotateTo(-40, 500, Easing.OutQuint); + + icon.FadeColour(colours.Light1, 300, Easing.OutQuint); + circle.FadeColour(colours.Background2, 300, Easing.OutQuint); + this.ScaleTo(1.2f, 300, Easing.OutQuint); } else { - background.FadeColour(colours.Lime3, fade_duration, Easing.OutQuint); - circle.TweenEdgeEffectTo(new EdgeEffectParameters - { - Colour = colours.Lime3.Opacity(0.1f), - Radius = 2, - Type = EdgeEffectType.Glow - }, fade_duration, Easing.OutQuint); + icon.RotateTo(0, 100, Easing.OutQuint); + + icon.FadeColour(colours.Colour0, 100, Easing.OutQuint); + circle.FadeColour(colours.Background3, 100, Easing.OutQuint); + this.ScaleTo(1f, 100, Easing.OutQuint); } } } From eeb50e27007dcf5076b4a0a99ad0e44d7226b8cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 13 Jul 2023 21:45:06 +0200 Subject: [PATCH 3/7] Do not rely on `OverlayColourProvider` presence --- osu.Game/Overlays/RevertToDefaultButton.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/osu.Game/Overlays/RevertToDefaultButton.cs b/osu.Game/Overlays/RevertToDefaultButton.cs index 48491c5d9c..28433f1669 100644 --- a/osu.Game/Overlays/RevertToDefaultButton.cs +++ b/osu.Game/Overlays/RevertToDefaultButton.cs @@ -11,6 +11,7 @@ using osu.Framework.Graphics.UserInterface; using osu.Framework.Input.Events; using osu.Framework.Localisation; +using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.UserInterface; using osu.Game.Localisation; @@ -33,7 +34,10 @@ public partial class RevertToDefaultButton : OsuClickableContainer, IHasCurre private Circle circle = null!; [Resolved] - private OverlayColourProvider colours { get; set; } = null!; + private OsuColour colours { get; set; } = null!; + + [Resolved] + private OverlayColourProvider? colourProvider { get; set; } public Bindable Current { @@ -124,16 +128,16 @@ private void updateState() { icon.RotateTo(-40, 500, Easing.OutQuint); - icon.FadeColour(colours.Light1, 300, Easing.OutQuint); - circle.FadeColour(colours.Background2, 300, Easing.OutQuint); + icon.FadeColour(colourProvider?.Light1 ?? colours.YellowLight, 300, Easing.OutQuint); + circle.FadeColour(colourProvider?.Background2 ?? colours.Gray6, 300, Easing.OutQuint); this.ScaleTo(1.2f, 300, Easing.OutQuint); } else { icon.RotateTo(0, 100, Easing.OutQuint); - icon.FadeColour(colours.Colour0, 100, Easing.OutQuint); - circle.FadeColour(colours.Background3, 100, Easing.OutQuint); + icon.FadeColour(colourProvider?.Colour0 ?? colours.Yellow, 100, Easing.OutQuint); + circle.FadeColour(colourProvider?.Background3 ?? colours.Gray3, 100, Easing.OutQuint); this.ScaleTo(1f, 100, Easing.OutQuint); } } From 6b9dabbd3c776800f10e0ccad7253fda22edec5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 13 Jul 2023 21:54:28 +0200 Subject: [PATCH 4/7] Rewrite test scene to show non-themed and themed variants --- .../TestSceneRevertToDefaultButton.cs | 51 ++++++++----------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/osu.Game.Tests/Visual/Settings/TestSceneRevertToDefaultButton.cs b/osu.Game.Tests/Visual/Settings/TestSceneRevertToDefaultButton.cs index bfef120358..0e31757396 100644 --- a/osu.Game.Tests/Visual/Settings/TestSceneRevertToDefaultButton.cs +++ b/osu.Game.Tests/Visual/Settings/TestSceneRevertToDefaultButton.cs @@ -2,58 +2,49 @@ // See the LICENCE file in the repository root for full licence text. using NUnit.Framework; -using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Shapes; +using osu.Framework.Testing; using osu.Game.Overlays; +using osu.Game.Tests.Visual.UserInterface; using osuTK; namespace osu.Game.Tests.Visual.Settings { - public partial class TestSceneRevertToDefaultButton : OsuTestScene + public partial class TestSceneRevertToDefaultButton : ThemeComparisonTestScene { private float scale = 1; - [Cached] - private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple); - private readonly Bindable current = new Bindable { Default = default, Value = 1, }; - [Test] - public void TestBasic() + protected override Drawable CreateContent() => new Container { - RevertToDefaultButton revertToDefaultButton = null!; - - AddStep("create button", () => Child = new Container + AutoSizeAxes = Axes.Both, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Child = new RevertToDefaultButton { - RelativeSizeAxes = Axes.Both, - Children = new Drawable[] - { - new Box - { - RelativeSizeAxes = Axes.Both, - Colour = colourProvider.Background2, - }, - revertToDefaultButton = new RevertToDefaultButton - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Scale = new Vector2(scale), - Current = current, - } - } - }); + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Scale = new Vector2(scale), + Current = current, + } + }; + + [Test] + public void TestStates() + { + CreateThemedContent(OverlayColourScheme.Purple); AddSliderStep("set scale", 1, 4, 1, scale => { this.scale = scale; - if (revertToDefaultButton != null) - revertToDefaultButton.Scale = new Vector2(scale); + foreach (var revertToDefaultButton in this.ChildrenOfType>()) + revertToDefaultButton.Parent!.Scale = new Vector2(scale); }); AddToggleStep("toggle default state", state => current.Value = state ? default : 1); AddToggleStep("toggle disabled state", state => current.Disabled = state); From 3ca767b7a26564e8ed07903a689cb9660585261f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 13 Jul 2023 21:58:55 +0200 Subject: [PATCH 5/7] Remove outdated comment --- osu.Game/Overlays/RevertToDefaultButton.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Overlays/RevertToDefaultButton.cs b/osu.Game/Overlays/RevertToDefaultButton.cs index 28433f1669..94d56971e0 100644 --- a/osu.Game/Overlays/RevertToDefaultButton.cs +++ b/osu.Game/Overlays/RevertToDefaultButton.cs @@ -64,7 +64,6 @@ public RevertToDefaultButton() [BackgroundDependencyLoader] private void load() { - // size intentionally much larger than actual drawn content, so that the button is easier to click. Size = new Vector2(14); AddRange(new Drawable[] From 9cc2150b5a37dfb0ecf940f31489dbf20c157384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 13 Jul 2023 22:00:21 +0200 Subject: [PATCH 6/7] Fix mixed `[cC]urrent` usage --- osu.Game/Overlays/RevertToDefaultButton.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Overlays/RevertToDefaultButton.cs b/osu.Game/Overlays/RevertToDefaultButton.cs index 94d56971e0..c43d233fc1 100644 --- a/osu.Game/Overlays/RevertToDefaultButton.cs +++ b/osu.Game/Overlays/RevertToDefaultButton.cs @@ -121,7 +121,7 @@ private void updateState() Enabled.Value = !current.Disabled; - this.FadeTo(current.Disabled ? 0.2f : (Current.IsDefault ? 0 : 1), fade_duration, Easing.OutQuint); + this.FadeTo(current.Disabled ? 0.2f : (current.IsDefault ? 0 : 1), fade_duration, Easing.OutQuint); if (IsHovered && Enabled.Value) { From e7dbe3c9380b664dc1a67ad8b36eeabd6cd4a131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 13 Jul 2023 22:28:26 +0200 Subject: [PATCH 7/7] Fix broken test --- .../Visual/Settings/TestSceneRevertToDefaultButton.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Settings/TestSceneRevertToDefaultButton.cs b/osu.Game.Tests/Visual/Settings/TestSceneRevertToDefaultButton.cs index 0e31757396..d081f663ba 100644 --- a/osu.Game.Tests/Visual/Settings/TestSceneRevertToDefaultButton.cs +++ b/osu.Game.Tests/Visual/Settings/TestSceneRevertToDefaultButton.cs @@ -39,7 +39,7 @@ public partial class TestSceneRevertToDefaultButton : ThemeComparisonTestScene [Test] public void TestStates() { - CreateThemedContent(OverlayColourScheme.Purple); + AddStep("create content", () => CreateThemedContent(OverlayColourScheme.Purple)); AddSliderStep("set scale", 1, 4, 1, scale => { this.scale = scale;