From 20d6eceecff465a37d8c6f9a602ec3fe48ad40bb Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 7 Nov 2019 16:03:35 +0900 Subject: [PATCH 01/16] Move DrawableOsuMenuItem out of OsuMenu --- .../UserInterface/DrawableOsuMenuItem.cs | 133 ++++++++++++++++++ osu.Game/Graphics/UserInterface/OsuMenu.cs | 123 ---------------- 2 files changed, 133 insertions(+), 123 deletions(-) create mode 100644 osu.Game/Graphics/UserInterface/DrawableOsuMenuItem.cs diff --git a/osu.Game/Graphics/UserInterface/DrawableOsuMenuItem.cs b/osu.Game/Graphics/UserInterface/DrawableOsuMenuItem.cs new file mode 100644 index 0000000000..efa0b3d69c --- /dev/null +++ b/osu.Game/Graphics/UserInterface/DrawableOsuMenuItem.cs @@ -0,0 +1,133 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Framework.Audio; +using osu.Framework.Audio.Sample; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.UserInterface; +using osu.Framework.Input.Events; +using osu.Game.Graphics.Sprites; +using osuTK.Graphics; + +namespace osu.Game.Graphics.UserInterface +{ + public class DrawableOsuMenuItem : Menu.DrawableMenuItem + { + private const int margin_horizontal = 17; + private const int text_size = 17; + private const int transition_length = 80; + public const int MARGIN_VERTICAL = 4; + + private SampleChannel sampleClick; + private SampleChannel sampleHover; + + private TextContainer text; + + public DrawableOsuMenuItem(MenuItem item) + : base(item) + { + } + + [BackgroundDependencyLoader] + private void load(AudioManager audio) + { + sampleHover = audio.Samples.Get(@"UI/generic-hover"); + sampleClick = audio.Samples.Get(@"UI/generic-select"); + + BackgroundColour = Color4.Transparent; + BackgroundColourHover = OsuColour.FromHex(@"172023"); + + updateTextColour(); + } + + private void updateTextColour() + { + switch ((Item as OsuMenuItem)?.Type) + { + default: + case MenuItemType.Standard: + text.Colour = Color4.White; + break; + + case MenuItemType.Destructive: + text.Colour = Color4.Red; + break; + + case MenuItemType.Highlighted: + text.Colour = OsuColour.FromHex(@"ffcc22"); + break; + } + } + + protected override bool OnHover(HoverEvent e) + { + sampleHover.Play(); + text.BoldText.FadeIn(transition_length, Easing.OutQuint); + text.NormalText.FadeOut(transition_length, Easing.OutQuint); + return base.OnHover(e); + } + + protected override void OnHoverLost(HoverLostEvent e) + { + text.BoldText.FadeOut(transition_length, Easing.OutQuint); + text.NormalText.FadeIn(transition_length, Easing.OutQuint); + base.OnHoverLost(e); + } + + protected override bool OnClick(ClickEvent e) + { + sampleClick.Play(); + return base.OnClick(e); + } + + protected sealed override Drawable CreateContent() => text = CreateTextContainer(); + protected virtual TextContainer CreateTextContainer() => new TextContainer(); + + protected class TextContainer : Container, IHasText + { + public string Text + { + get => NormalText.Text; + set + { + NormalText.Text = value; + BoldText.Text = value; + } + } + + public readonly SpriteText NormalText; + public readonly SpriteText BoldText; + + public TextContainer() + { + Anchor = Anchor.CentreLeft; + Origin = Anchor.CentreLeft; + + AutoSizeAxes = Axes.Both; + + Children = new Drawable[] + { + NormalText = new OsuSpriteText + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Font = OsuFont.GetFont(size: text_size), + Margin = new MarginPadding { Horizontal = margin_horizontal, Vertical = MARGIN_VERTICAL }, + }, + BoldText = new OsuSpriteText + { + AlwaysPresent = true, + Alpha = 0, + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold), + Margin = new MarginPadding { Horizontal = margin_horizontal, Vertical = MARGIN_VERTICAL }, + } + }; + } + } + } +} diff --git a/osu.Game/Graphics/UserInterface/OsuMenu.cs b/osu.Game/Graphics/UserInterface/OsuMenu.cs index c4c6950eb1..be642e6afb 100644 --- a/osu.Game/Graphics/UserInterface/OsuMenu.cs +++ b/osu.Game/Graphics/UserInterface/OsuMenu.cs @@ -1,18 +1,12 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using osu.Framework.Allocation; -using osu.Framework.Audio; -using osu.Framework.Audio.Sample; using osuTK.Graphics; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; -using osu.Framework.Input.Events; using osu.Game.Graphics.Containers; -using osu.Game.Graphics.Sprites; using osuTK; namespace osu.Game.Graphics.UserInterface @@ -53,122 +47,5 @@ namespace osu.Game.Graphics.UserInterface { Anchor = Direction == Direction.Horizontal ? Anchor.BottomLeft : Anchor.TopRight }; - - protected class DrawableOsuMenuItem : DrawableMenuItem - { - private const int margin_horizontal = 17; - private const int text_size = 17; - private const int transition_length = 80; - public const int MARGIN_VERTICAL = 4; - - private SampleChannel sampleClick; - private SampleChannel sampleHover; - - private TextContainer text; - - public DrawableOsuMenuItem(MenuItem item) - : base(item) - { - } - - [BackgroundDependencyLoader] - private void load(AudioManager audio) - { - sampleHover = audio.Samples.Get(@"UI/generic-hover"); - sampleClick = audio.Samples.Get(@"UI/generic-select"); - - BackgroundColour = Color4.Transparent; - BackgroundColourHover = OsuColour.FromHex(@"172023"); - - updateTextColour(); - } - - private void updateTextColour() - { - switch ((Item as OsuMenuItem)?.Type) - { - default: - case MenuItemType.Standard: - text.Colour = Color4.White; - break; - - case MenuItemType.Destructive: - text.Colour = Color4.Red; - break; - - case MenuItemType.Highlighted: - text.Colour = OsuColour.FromHex(@"ffcc22"); - break; - } - } - - protected override bool OnHover(HoverEvent e) - { - sampleHover.Play(); - text.BoldText.FadeIn(transition_length, Easing.OutQuint); - text.NormalText.FadeOut(transition_length, Easing.OutQuint); - return base.OnHover(e); - } - - protected override void OnHoverLost(HoverLostEvent e) - { - text.BoldText.FadeOut(transition_length, Easing.OutQuint); - text.NormalText.FadeIn(transition_length, Easing.OutQuint); - base.OnHoverLost(e); - } - - protected override bool OnClick(ClickEvent e) - { - sampleClick.Play(); - return base.OnClick(e); - } - - protected sealed override Drawable CreateContent() => text = CreateTextContainer(); - protected virtual TextContainer CreateTextContainer() => new TextContainer(); - - protected class TextContainer : Container, IHasText - { - public string Text - { - get => NormalText.Text; - set - { - NormalText.Text = value; - BoldText.Text = value; - } - } - - public readonly SpriteText NormalText; - public readonly SpriteText BoldText; - - public TextContainer() - { - Anchor = Anchor.CentreLeft; - Origin = Anchor.CentreLeft; - - AutoSizeAxes = Axes.Both; - - Children = new Drawable[] - { - NormalText = new OsuSpriteText - { - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - Font = OsuFont.GetFont(size: text_size), - Margin = new MarginPadding { Horizontal = margin_horizontal, Vertical = MARGIN_VERTICAL }, - }, - BoldText = new OsuSpriteText - { - AlwaysPresent = true, - Alpha = 0, - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold), - Margin = new MarginPadding { Horizontal = margin_horizontal, Vertical = MARGIN_VERTICAL }, - } - }; - } - } - } } } From 29672c48e126bb39829426f4174be8207e0f0bc6 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 7 Nov 2019 16:04:13 +0900 Subject: [PATCH 02/16] Make simple OsuMenuItem ctor invoke the complex one --- osu.Game/Graphics/UserInterface/OsuMenuItem.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/OsuMenuItem.cs b/osu.Game/Graphics/UserInterface/OsuMenuItem.cs index b7aa666302..0fe41937ce 100644 --- a/osu.Game/Graphics/UserInterface/OsuMenuItem.cs +++ b/osu.Game/Graphics/UserInterface/OsuMenuItem.cs @@ -11,9 +11,8 @@ namespace osu.Game.Graphics.UserInterface public readonly MenuItemType Type; public OsuMenuItem(string text, MenuItemType type = MenuItemType.Standard) - : base(text) + : this(text, type, null) { - Type = type; } public OsuMenuItem(string text, MenuItemType type, Action action) From c3a3b4091bfd92841521822191b1caea5f6730fb Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 7 Nov 2019 22:26:35 +0900 Subject: [PATCH 03/16] Add basic implementation of a toggleable menu item --- .../UserInterface/TestSceneToggleMenuItem.cs | 33 ++++++++++ .../UserInterface/DrawableOsuMenuItem.cs | 8 +-- .../UserInterface/DrawableToggleMenuItem.cs | 60 +++++++++++++++++++ osu.Game/Graphics/UserInterface/OsuMenu.cs | 11 +++- .../Graphics/UserInterface/ToggleMenuItem.cs | 25 ++++++++ 5 files changed, 132 insertions(+), 5 deletions(-) create mode 100644 osu.Game.Tests/Visual/UserInterface/TestSceneToggleMenuItem.cs create mode 100644 osu.Game/Graphics/UserInterface/DrawableToggleMenuItem.cs create mode 100644 osu.Game/Graphics/UserInterface/ToggleMenuItem.cs diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneToggleMenuItem.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneToggleMenuItem.cs new file mode 100644 index 0000000000..97257b5226 --- /dev/null +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneToggleMenuItem.cs @@ -0,0 +1,33 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Collections.Generic; +using osu.Framework.Graphics; +using osu.Game.Graphics.UserInterface; + +namespace osu.Game.Tests.Visual.UserInterface +{ + public class TestSceneToggleMenuItem : OsuTestScene + { + public override IReadOnlyList RequiredTypes => new[] + { + typeof(OsuMenu), + typeof(ToggleMenuItem), + typeof(DrawableToggleMenuItem) + }; + + public TestSceneToggleMenuItem() + { + Add(new OsuMenu(Direction.Vertical, true) + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Items = new[] + { + new ToggleMenuItem("Toggle"), + } + }); + } + } +} diff --git a/osu.Game/Graphics/UserInterface/DrawableOsuMenuItem.cs b/osu.Game/Graphics/UserInterface/DrawableOsuMenuItem.cs index efa0b3d69c..591ed3df83 100644 --- a/osu.Game/Graphics/UserInterface/DrawableOsuMenuItem.cs +++ b/osu.Game/Graphics/UserInterface/DrawableOsuMenuItem.cs @@ -16,10 +16,10 @@ namespace osu.Game.Graphics.UserInterface { public class DrawableOsuMenuItem : Menu.DrawableMenuItem { - private const int margin_horizontal = 17; + public const int MARGIN_HORIZONTAL = 17; + public const int MARGIN_VERTICAL = 4; private const int text_size = 17; private const int transition_length = 80; - public const int MARGIN_VERTICAL = 4; private SampleChannel sampleClick; private SampleChannel sampleHover; @@ -115,7 +115,7 @@ namespace osu.Game.Graphics.UserInterface Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, Font = OsuFont.GetFont(size: text_size), - Margin = new MarginPadding { Horizontal = margin_horizontal, Vertical = MARGIN_VERTICAL }, + Margin = new MarginPadding { Horizontal = MARGIN_HORIZONTAL, Vertical = MARGIN_VERTICAL }, }, BoldText = new OsuSpriteText { @@ -124,7 +124,7 @@ namespace osu.Game.Graphics.UserInterface Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold), - Margin = new MarginPadding { Horizontal = margin_horizontal, Vertical = MARGIN_VERTICAL }, + Margin = new MarginPadding { Horizontal = MARGIN_HORIZONTAL, Vertical = MARGIN_VERTICAL }, } }; } diff --git a/osu.Game/Graphics/UserInterface/DrawableToggleMenuItem.cs b/osu.Game/Graphics/UserInterface/DrawableToggleMenuItem.cs new file mode 100644 index 0000000000..cf0f154486 --- /dev/null +++ b/osu.Game/Graphics/UserInterface/DrawableToggleMenuItem.cs @@ -0,0 +1,60 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Bindables; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Sprites; +using osuTK; + +namespace osu.Game.Graphics.UserInterface +{ + public class DrawableToggleMenuItem : DrawableOsuMenuItem + { + protected new ToggleMenuItem Item => (ToggleMenuItem)base.Item; + + public DrawableToggleMenuItem(ToggleMenuItem item) + : base(item) + { + } + + protected override TextContainer CreateTextContainer() => new ToggleTextContainer + { + State = { BindTarget = Item.State } + }; + + private class ToggleTextContainer : TextContainer + { + public readonly Bindable State = new Bindable(); + + private readonly SpriteIcon checkmark; + + public ToggleTextContainer() + { + Add(checkmark = new SpriteIcon + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Icon = FontAwesome.Solid.Check, + Size = new Vector2(10), + Margin = new MarginPadding { Horizontal = MARGIN_HORIZONTAL }, + AlwaysPresent = true, + }); + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + State.BindValueChanged(state => checkmark.Alpha = state.NewValue ? 1 : 0, true); + } + + protected override void Update() + { + base.Update(); + + // Todo: This is bad. This can maybe be done better with a refactor of DrawableOsuMenuItem. + checkmark.X = BoldText.DrawWidth + 10; + } + } + } +} diff --git a/osu.Game/Graphics/UserInterface/OsuMenu.cs b/osu.Game/Graphics/UserInterface/OsuMenu.cs index be642e6afb..da32a2c861 100644 --- a/osu.Game/Graphics/UserInterface/OsuMenu.cs +++ b/osu.Game/Graphics/UserInterface/OsuMenu.cs @@ -39,7 +39,16 @@ namespace osu.Game.Graphics.UserInterface } } - protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item) => new DrawableOsuMenuItem(item); + protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item) + { + switch (item) + { + case ToggleMenuItem toggle: + return new DrawableToggleMenuItem(toggle); + } + + return new DrawableOsuMenuItem(item); + } protected override ScrollContainer CreateScrollContainer(Direction direction) => new OsuScrollContainer(direction); diff --git a/osu.Game/Graphics/UserInterface/ToggleMenuItem.cs b/osu.Game/Graphics/UserInterface/ToggleMenuItem.cs new file mode 100644 index 0000000000..7b2bb32f47 --- /dev/null +++ b/osu.Game/Graphics/UserInterface/ToggleMenuItem.cs @@ -0,0 +1,25 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using osu.Framework.Bindables; + +namespace osu.Game.Graphics.UserInterface +{ + public class ToggleMenuItem : OsuMenuItem + { + public readonly BindableBool State = new BindableBool(); + + public ToggleMenuItem(string text, MenuItemType type = MenuItemType.Standard) + : this(text, type, null) + { + } + + public ToggleMenuItem(string text, MenuItemType type, Action action) + : base(text, type) + { + Action.Value = () => State.Toggle(); + State.BindValueChanged(state => action?.Invoke(state.NewValue)); + } + } +} From 4fe69dbc896d77fd1efea4c469254fdbb3563fe0 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 8 Nov 2019 11:13:53 +0900 Subject: [PATCH 04/16] Fix context menu sub-menu display --- osu.Game/Graphics/UserInterface/OsuContextMenu.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game/Graphics/UserInterface/OsuContextMenu.cs b/osu.Game/Graphics/UserInterface/OsuContextMenu.cs index cea8427296..4b629080e1 100644 --- a/osu.Game/Graphics/UserInterface/OsuContextMenu.cs +++ b/osu.Game/Graphics/UserInterface/OsuContextMenu.cs @@ -6,6 +6,7 @@ using osu.Framework.Allocation; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Effects; +using osu.Framework.Graphics.UserInterface; namespace osu.Game.Graphics.UserInterface { @@ -35,5 +36,7 @@ namespace osu.Game.Graphics.UserInterface protected override void AnimateOpen() => this.FadeIn(fade_duration, Easing.OutQuint); protected override void AnimateClose() => this.FadeOut(fade_duration, Easing.OutQuint); + + protected override Menu CreateSubMenu() => new OsuContextMenu(); } } From ce08d664a52fef8633accc8f11b53ecb7d758906 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 8 Nov 2019 11:15:03 +0900 Subject: [PATCH 05/16] Abstract statefulness of new menu item type --- .../TestSceneStatefulMenuItem.cs | 90 +++++++++++++++++++ .../UserInterface/TestSceneToggleMenuItem.cs | 33 ------- ...enuItem.cs => DrawableStatefulMenuItem.cs} | 44 +++++---- osu.Game/Graphics/UserInterface/OsuMenu.cs | 4 +- .../UserInterface/StatefulMenuItem.cs | 56 ++++++++++++ .../Graphics/UserInterface/ToggleMenuItem.cs | 11 ++- 6 files changed, 181 insertions(+), 57 deletions(-) create mode 100644 osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs delete mode 100644 osu.Game.Tests/Visual/UserInterface/TestSceneToggleMenuItem.cs rename osu.Game/Graphics/UserInterface/{DrawableToggleMenuItem.cs => DrawableStatefulMenuItem.cs} (51%) create mode 100644 osu.Game/Graphics/UserInterface/StatefulMenuItem.cs diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs new file mode 100644 index 0000000000..fbb35ba09f --- /dev/null +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs @@ -0,0 +1,90 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Collections.Generic; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Sprites; +using osu.Game.Graphics.UserInterface; + +namespace osu.Game.Tests.Visual.UserInterface +{ + public class TestSceneStatefulMenuItem : OsuTestScene + { + public override IReadOnlyList RequiredTypes => new[] + { + typeof(OsuMenu), + typeof(ToggleMenuItem), + typeof(DrawableStatefulMenuItem) + }; + + public TestSceneStatefulMenuItem() + { + Add(new OsuMenu(Direction.Vertical, true) + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Items = new[] + { + new TestMenuItem("First", MenuItemType.Standard, getNextState), + new TestMenuItem("Second", MenuItemType.Standard, getNextState) { State = { Value = TestStates.State2 } }, + new TestMenuItem("Third", MenuItemType.Standard, getNextState) { State = { Value = TestStates.State3 } }, + } + }); + } + + private TestStates getNextState(TestStates state) + { + switch (state) + { + case TestStates.State1: + return TestStates.State2; + + case TestStates.State2: + return TestStates.State3; + + case TestStates.State3: + return TestStates.State1; + } + + return TestStates.State1; + } + + private class TestMenuItem : StatefulMenuItem + { + public TestMenuItem(string text, MenuItemType type = MenuItemType.Standard) + : base(text, type) + { + } + + public TestMenuItem(string text, MenuItemType type, Func changeStateFunc) + : base(text, type, changeStateFunc) + { + } + + public override IconUsage? GetIconForState(TestStates state) + { + switch (state) + { + case TestStates.State1: + return FontAwesome.Solid.DiceOne; + + case TestStates.State2: + return FontAwesome.Solid.DiceTwo; + + case TestStates.State3: + return FontAwesome.Solid.DiceThree; + } + + return null; + } + } + + private enum TestStates + { + State1, + State2, + State3 + } + } +} diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneToggleMenuItem.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneToggleMenuItem.cs deleted file mode 100644 index 97257b5226..0000000000 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneToggleMenuItem.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using System; -using System.Collections.Generic; -using osu.Framework.Graphics; -using osu.Game.Graphics.UserInterface; - -namespace osu.Game.Tests.Visual.UserInterface -{ - public class TestSceneToggleMenuItem : OsuTestScene - { - public override IReadOnlyList RequiredTypes => new[] - { - typeof(OsuMenu), - typeof(ToggleMenuItem), - typeof(DrawableToggleMenuItem) - }; - - public TestSceneToggleMenuItem() - { - Add(new OsuMenu(Direction.Vertical, true) - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Items = new[] - { - new ToggleMenuItem("Toggle"), - } - }); - } - } -} diff --git a/osu.Game/Graphics/UserInterface/DrawableToggleMenuItem.cs b/osu.Game/Graphics/UserInterface/DrawableStatefulMenuItem.cs similarity index 51% rename from osu.Game/Graphics/UserInterface/DrawableToggleMenuItem.cs rename to osu.Game/Graphics/UserInterface/DrawableStatefulMenuItem.cs index cf0f154486..3dc99f2dbe 100644 --- a/osu.Game/Graphics/UserInterface/DrawableToggleMenuItem.cs +++ b/osu.Game/Graphics/UserInterface/DrawableStatefulMenuItem.cs @@ -8,33 +8,33 @@ using osuTK; namespace osu.Game.Graphics.UserInterface { - public class DrawableToggleMenuItem : DrawableOsuMenuItem + public class DrawableStatefulMenuItem : DrawableOsuMenuItem { - protected new ToggleMenuItem Item => (ToggleMenuItem)base.Item; + protected new StatefulMenuItem Item => (StatefulMenuItem)base.Item; - public DrawableToggleMenuItem(ToggleMenuItem item) + public DrawableStatefulMenuItem(StatefulMenuItem item) : base(item) { } - protected override TextContainer CreateTextContainer() => new ToggleTextContainer - { - State = { BindTarget = Item.State } - }; + protected override TextContainer CreateTextContainer() => new ToggleTextContainer(Item); private class ToggleTextContainer : TextContainer { - public readonly Bindable State = new Bindable(); + private readonly StatefulMenuItem menuItem; + private readonly Bindable state; + private readonly SpriteIcon stateIcon; - private readonly SpriteIcon checkmark; - - public ToggleTextContainer() + public ToggleTextContainer(StatefulMenuItem menuItem) { - Add(checkmark = new SpriteIcon + this.menuItem = menuItem; + + state = menuItem.State.GetBoundCopy(); + + Add(stateIcon = new SpriteIcon { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, - Icon = FontAwesome.Solid.Check, Size = new Vector2(10), Margin = new MarginPadding { Horizontal = MARGIN_HORIZONTAL }, AlwaysPresent = true, @@ -44,8 +44,7 @@ namespace osu.Game.Graphics.UserInterface protected override void LoadComplete() { base.LoadComplete(); - - State.BindValueChanged(state => checkmark.Alpha = state.NewValue ? 1 : 0, true); + state.BindValueChanged(updateState, true); } protected override void Update() @@ -53,7 +52,20 @@ namespace osu.Game.Graphics.UserInterface base.Update(); // Todo: This is bad. This can maybe be done better with a refactor of DrawableOsuMenuItem. - checkmark.X = BoldText.DrawWidth + 10; + stateIcon.X = BoldText.DrawWidth + 10; + } + + private void updateState(ValueChangedEvent state) + { + var icon = menuItem.GetIconForState(state.NewValue); + + if (icon == null) + stateIcon.Alpha = 0; + else + { + stateIcon.Alpha = 1; + stateIcon.Icon = icon.Value; + } } } } diff --git a/osu.Game/Graphics/UserInterface/OsuMenu.cs b/osu.Game/Graphics/UserInterface/OsuMenu.cs index da32a2c861..e7bf4f66ee 100644 --- a/osu.Game/Graphics/UserInterface/OsuMenu.cs +++ b/osu.Game/Graphics/UserInterface/OsuMenu.cs @@ -43,8 +43,8 @@ namespace osu.Game.Graphics.UserInterface { switch (item) { - case ToggleMenuItem toggle: - return new DrawableToggleMenuItem(toggle); + case StatefulMenuItem stateful: + return new DrawableStatefulMenuItem(stateful); } return new DrawableOsuMenuItem(item); diff --git a/osu.Game/Graphics/UserInterface/StatefulMenuItem.cs b/osu.Game/Graphics/UserInterface/StatefulMenuItem.cs new file mode 100644 index 0000000000..ede2c9df48 --- /dev/null +++ b/osu.Game/Graphics/UserInterface/StatefulMenuItem.cs @@ -0,0 +1,56 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using osu.Framework.Bindables; +using osu.Framework.Graphics.Sprites; + +namespace osu.Game.Graphics.UserInterface +{ + public abstract class StatefulMenuItem : OsuMenuItem + { + public readonly Bindable State = new Bindable(); + + protected StatefulMenuItem(string text, MenuItemType type = MenuItemType.Standard) + : this(text, type, null) + { + } + + protected StatefulMenuItem(string text, MenuItemType type, Func changeStateFunc) + : base(text, type) + { + Action.Value = () => State.Value = changeStateFunc?.Invoke(State.Value) ?? State.Value; + } + + public abstract IconUsage? GetIconForState(object state); + } + + public abstract class StatefulMenuItem : StatefulMenuItem + where T : struct + { + public new readonly Bindable State = new Bindable(); + + protected StatefulMenuItem(string text, MenuItemType type = MenuItemType.Standard) + : this(text, type, null) + { + } + + protected StatefulMenuItem(string text, MenuItemType type, Func changeStateFunc) + : base(text, type, o => changeStateFunc?.Invoke((T)o) ?? o) + { + base.State.BindValueChanged(state => + { + if (state.NewValue == null) + base.State.Value = default(T); + + State.Value = (T)base.State.Value; + }, true); + + State.BindValueChanged(state => base.State.Value = state.NewValue); + } + + public sealed override IconUsage? GetIconForState(object state) => GetIconForState((T)state); + + public abstract IconUsage? GetIconForState(T state); + } +} diff --git a/osu.Game/Graphics/UserInterface/ToggleMenuItem.cs b/osu.Game/Graphics/UserInterface/ToggleMenuItem.cs index 7b2bb32f47..a0ed745c5a 100644 --- a/osu.Game/Graphics/UserInterface/ToggleMenuItem.cs +++ b/osu.Game/Graphics/UserInterface/ToggleMenuItem.cs @@ -2,24 +2,23 @@ // See the LICENCE file in the repository root for full licence text. using System; -using osu.Framework.Bindables; +using osu.Framework.Graphics.Sprites; namespace osu.Game.Graphics.UserInterface { - public class ToggleMenuItem : OsuMenuItem + public class ToggleMenuItem : StatefulMenuItem { - public readonly BindableBool State = new BindableBool(); - public ToggleMenuItem(string text, MenuItemType type = MenuItemType.Standard) : this(text, type, null) { } public ToggleMenuItem(string text, MenuItemType type, Action action) - : base(text, type) + : base(text, type, value => !value) { - Action.Value = () => State.Toggle(); State.BindValueChanged(state => action?.Invoke(state.NewValue)); } + + public override IconUsage? GetIconForState(bool state) => state ? (IconUsage?)FontAwesome.Solid.Check : null; } } From 30f877c4ab7751066bd6a0ca2dc45178de355b69 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 8 Nov 2019 12:47:42 +0900 Subject: [PATCH 06/16] Implement a three-state menu item --- .../TestSceneThreeStateMenuItem.cs | 35 ++++++++++++ .../UserInterface/ThreeStateMenuItem.cs | 53 +++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 osu.Game.Tests/Visual/UserInterface/TestSceneThreeStateMenuItem.cs create mode 100644 osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneThreeStateMenuItem.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneThreeStateMenuItem.cs new file mode 100644 index 0000000000..caa07e7b60 --- /dev/null +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneThreeStateMenuItem.cs @@ -0,0 +1,35 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Collections.Generic; +using osu.Framework.Graphics; +using osu.Game.Graphics.UserInterface; + +namespace osu.Game.Tests.Visual.UserInterface +{ + public class TestSceneThreeStateMenuItem : OsuTestScene + { + public override IReadOnlyList RequiredTypes => new[] + { + typeof(OsuMenu), + typeof(ThreeStateMenuItem), + typeof(DrawableStatefulMenuItem) + }; + + public TestSceneThreeStateMenuItem() + { + Add(new OsuMenu(Direction.Vertical, true) + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Items = new[] + { + new ThreeStateMenuItem("First"), + new ThreeStateMenuItem("Second") { State = { Value = ThreeStates.Indeterminate } }, + new ThreeStateMenuItem("Third") { State = { Value = ThreeStates.Enabled } }, + } + }); + } + } +} diff --git a/osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs b/osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs new file mode 100644 index 0000000000..107bfe208b --- /dev/null +++ b/osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs @@ -0,0 +1,53 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics.Sprites; + +namespace osu.Game.Graphics.UserInterface +{ + public class ThreeStateMenuItem : StatefulMenuItem + { + public ThreeStateMenuItem(string text, MenuItemType type = MenuItemType.Standard) + : base(text, type, getNextState) + { + } + + public override IconUsage? GetIconForState(ThreeStates state) + { + switch (state) + { + case ThreeStates.Indeterminate: + return FontAwesome.Regular.Circle; + + case ThreeStates.Enabled: + return FontAwesome.Solid.Check; + } + + return null; + } + + private static ThreeStates getNextState(ThreeStates state) + { + switch (state) + { + case ThreeStates.Disabled: + return ThreeStates.Enabled; + + case ThreeStates.Indeterminate: + return ThreeStates.Enabled; + + case ThreeStates.Enabled: + return ThreeStates.Disabled; + } + + return ThreeStates.Disabled; + } + } + + public enum ThreeStates + { + Disabled, + Indeterminate, + Enabled + } +} From 0a15a13fabd66d5676dfd12e1117772a31ae605a Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 8 Nov 2019 12:55:22 +0900 Subject: [PATCH 07/16] Reorder parameters --- .../TestSceneStatefulMenuItem.cs | 4 ++-- .../UserInterface/StatefulMenuItem.cs | 20 +++++++++++-------- .../UserInterface/ThreeStateMenuItem.cs | 8 +++++++- .../Graphics/UserInterface/ToggleMenuItem.cs | 3 +-- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs index fbb35ba09f..00678a6ab4 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs @@ -53,12 +53,12 @@ namespace osu.Game.Tests.Visual.UserInterface private class TestMenuItem : StatefulMenuItem { public TestMenuItem(string text, MenuItemType type = MenuItemType.Standard) - : base(text, type) + : this(text, type, null) { } public TestMenuItem(string text, MenuItemType type, Func changeStateFunc) - : base(text, type, changeStateFunc) + : base(text, changeStateFunc, type) { } diff --git a/osu.Game/Graphics/UserInterface/StatefulMenuItem.cs b/osu.Game/Graphics/UserInterface/StatefulMenuItem.cs index ede2c9df48..b5f9a3d635 100644 --- a/osu.Game/Graphics/UserInterface/StatefulMenuItem.cs +++ b/osu.Game/Graphics/UserInterface/StatefulMenuItem.cs @@ -11,15 +11,19 @@ namespace osu.Game.Graphics.UserInterface { public readonly Bindable State = new Bindable(); - protected StatefulMenuItem(string text, MenuItemType type = MenuItemType.Standard) - : this(text, type, null) + protected StatefulMenuItem(string text, Func changeStateFunc, MenuItemType type = MenuItemType.Standard) + : this(text, changeStateFunc, type, null) { } - protected StatefulMenuItem(string text, MenuItemType type, Func changeStateFunc) + protected StatefulMenuItem(string text, Func changeStateFunc, MenuItemType type, Action action) : base(text, type) { - Action.Value = () => State.Value = changeStateFunc?.Invoke(State.Value) ?? State.Value; + Action.Value = () => + { + State.Value = changeStateFunc?.Invoke(State.Value) ?? State.Value; + action?.Invoke(State.Value); + }; } public abstract IconUsage? GetIconForState(object state); @@ -30,13 +34,13 @@ namespace osu.Game.Graphics.UserInterface { public new readonly Bindable State = new Bindable(); - protected StatefulMenuItem(string text, MenuItemType type = MenuItemType.Standard) - : this(text, type, null) + protected StatefulMenuItem(string text, Func changeStateFunc, MenuItemType type = MenuItemType.Standard) + : this(text, changeStateFunc, type, null) { } - protected StatefulMenuItem(string text, MenuItemType type, Func changeStateFunc) - : base(text, type, o => changeStateFunc?.Invoke((T)o) ?? o) + protected StatefulMenuItem(string text, Func changeStateFunc, MenuItemType type, Action action) + : base(text, o => changeStateFunc?.Invoke((T)o) ?? o, type, o => action?.Invoke((T)o)) { base.State.BindValueChanged(state => { diff --git a/osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs b/osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs index 107bfe208b..d41a95daa1 100644 --- a/osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs +++ b/osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using osu.Framework.Graphics.Sprites; namespace osu.Game.Graphics.UserInterface @@ -8,7 +9,12 @@ namespace osu.Game.Graphics.UserInterface public class ThreeStateMenuItem : StatefulMenuItem { public ThreeStateMenuItem(string text, MenuItemType type = MenuItemType.Standard) - : base(text, type, getNextState) + : this(text, type, null) + { + } + + public ThreeStateMenuItem(string text, MenuItemType type, Action action) + : base(text, getNextState, type, action) { } diff --git a/osu.Game/Graphics/UserInterface/ToggleMenuItem.cs b/osu.Game/Graphics/UserInterface/ToggleMenuItem.cs index a0ed745c5a..f5a442b317 100644 --- a/osu.Game/Graphics/UserInterface/ToggleMenuItem.cs +++ b/osu.Game/Graphics/UserInterface/ToggleMenuItem.cs @@ -14,9 +14,8 @@ namespace osu.Game.Graphics.UserInterface } public ToggleMenuItem(string text, MenuItemType type, Action action) - : base(text, type, value => !value) + : base(text, value => !value, type, action) { - State.BindValueChanged(state => action?.Invoke(state.NewValue)); } public override IconUsage? GetIconForState(bool state) => state ? (IconUsage?)FontAwesome.Solid.Check : null; From 011bf095166d88d560087bbf83d07567309c585f Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 8 Nov 2019 13:14:23 +0900 Subject: [PATCH 08/16] Add xmldocs and cleanup --- .../TestSceneStatefulMenuItem.cs | 5 ++- .../UserInterface/StatefulMenuItem.cs | 45 +++++++++++++++++++ .../UserInterface/ThreeStateMenuItem.cs | 45 +++++++++++++++++-- .../Graphics/UserInterface/ToggleMenuItem.cs | 14 ++++++ 4 files changed, 104 insertions(+), 5 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs index 00678a6ab4..d010abc862 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs @@ -74,9 +74,10 @@ namespace osu.Game.Tests.Visual.UserInterface case TestStates.State3: return FontAwesome.Solid.DiceThree; - } - return null; + default: + throw new ArgumentOutOfRangeException(nameof(state), state, null); + } } } diff --git a/osu.Game/Graphics/UserInterface/StatefulMenuItem.cs b/osu.Game/Graphics/UserInterface/StatefulMenuItem.cs index b5f9a3d635..0d7b36e51b 100644 --- a/osu.Game/Graphics/UserInterface/StatefulMenuItem.cs +++ b/osu.Game/Graphics/UserInterface/StatefulMenuItem.cs @@ -7,15 +7,34 @@ using osu.Framework.Graphics.Sprites; namespace osu.Game.Graphics.UserInterface { + /// + /// An which contains and displays a state. + /// public abstract class StatefulMenuItem : OsuMenuItem { + /// + /// The current state that should be displayed. + /// public readonly Bindable State = new Bindable(); + /// + /// Creates a new . + /// + /// The text to display. + /// A function that mutates a state to another state after this is pressed. + /// The type of action which this performs. protected StatefulMenuItem(string text, Func changeStateFunc, MenuItemType type = MenuItemType.Standard) : this(text, changeStateFunc, type, null) { } + /// + /// Creates a new . + /// + /// The text to display. + /// A function that mutates a state to another state after this is pressed. + /// The type of action which this performs. + /// A delegate to be invoked when this is pressed. protected StatefulMenuItem(string text, Func changeStateFunc, MenuItemType type, Action action) : base(text, type) { @@ -26,19 +45,40 @@ namespace osu.Game.Graphics.UserInterface }; } + /// + /// Retrieves the icon to be displayed for a state. + /// + /// The state to retrieve the relevant icon for. + /// The icon to be displayed for . public abstract IconUsage? GetIconForState(object state); } public abstract class StatefulMenuItem : StatefulMenuItem where T : struct { + /// + /// The current state that should be displayed. + /// public new readonly Bindable State = new Bindable(); + /// + /// Creates a new . + /// + /// The text to display. + /// A function that mutates a state to another state after this is pressed. + /// The type of action which this performs. protected StatefulMenuItem(string text, Func changeStateFunc, MenuItemType type = MenuItemType.Standard) : this(text, changeStateFunc, type, null) { } + /// + /// Creates a new . + /// + /// The text to display. + /// A function that mutates a state to another state after this is pressed. + /// The type of action which this performs. + /// A delegate to be invoked when this is pressed. protected StatefulMenuItem(string text, Func changeStateFunc, MenuItemType type, Action action) : base(text, o => changeStateFunc?.Invoke((T)o) ?? o, type, o => action?.Invoke((T)o)) { @@ -55,6 +95,11 @@ namespace osu.Game.Graphics.UserInterface public sealed override IconUsage? GetIconForState(object state) => GetIconForState((T)state); + /// + /// Retrieves the icon to be displayed for a state. + /// + /// The state to retrieve the relevant icon for. + /// The icon to be displayed for . public abstract IconUsage? GetIconForState(T state); } } diff --git a/osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs b/osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs index d41a95daa1..e33c68bebd 100644 --- a/osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs +++ b/osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs @@ -6,15 +6,41 @@ using osu.Framework.Graphics.Sprites; namespace osu.Game.Graphics.UserInterface { + /// + /// An with three possible states. + /// public class ThreeStateMenuItem : StatefulMenuItem { + /// + /// Creates a new . + /// + /// The text to display. + /// The type of action which this performs. public ThreeStateMenuItem(string text, MenuItemType type = MenuItemType.Standard) : this(text, type, null) { } + /// + /// Creates a new . + /// + /// The text to display. + /// The type of action which this performs. + /// A delegate to be invoked when this is pressed. public ThreeStateMenuItem(string text, MenuItemType type, Action action) - : base(text, getNextState, type, action) + : this(text, getNextState, type, action) + { + } + + /// + /// Creates a new . + /// + /// The text to display. + /// A function that mutates a state to another state after this is pressed. + /// The type of action which this performs. + /// A delegate to be invoked when this is pressed. + protected ThreeStateMenuItem(string text, Func changeStateFunc, MenuItemType type, Action action) + : base(text, changeStateFunc, type, action) { } @@ -44,16 +70,29 @@ namespace osu.Game.Graphics.UserInterface case ThreeStates.Enabled: return ThreeStates.Disabled; - } - return ThreeStates.Disabled; + default: + throw new ArgumentOutOfRangeException(nameof(state), state, null); + } } } public enum ThreeStates { + /// + /// The current state is disabled. + /// Disabled, + + /// + /// The current state is a combination of and . + /// The state becomes if the is pressed. + /// Indeterminate, + + /// + /// The current state is enabled. + /// Enabled } } diff --git a/osu.Game/Graphics/UserInterface/ToggleMenuItem.cs b/osu.Game/Graphics/UserInterface/ToggleMenuItem.cs index f5a442b317..f9ff9859dd 100644 --- a/osu.Game/Graphics/UserInterface/ToggleMenuItem.cs +++ b/osu.Game/Graphics/UserInterface/ToggleMenuItem.cs @@ -6,13 +6,27 @@ using osu.Framework.Graphics.Sprites; namespace osu.Game.Graphics.UserInterface { + /// + /// An which displays an enabled or disabled state. + /// public class ToggleMenuItem : StatefulMenuItem { + /// + /// Creates a new . + /// + /// The text to display. + /// The type of action which this performs. public ToggleMenuItem(string text, MenuItemType type = MenuItemType.Standard) : this(text, type, null) { } + /// + /// Creates a new . + /// + /// The text to display. + /// The type of action which this performs. + /// A delegate to be invoked when this is pressed. public ToggleMenuItem(string text, MenuItemType type, Action action) : base(text, value => !value, type, action) { From a2c265c1478f1b33937d8da76343eabd688046ad Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 8 Nov 2019 13:16:09 +0900 Subject: [PATCH 09/16] Separate ThreeStates into its own file --- .../UserInterface/ThreeStateMenuItem.cs | 19 ------------- .../Graphics/UserInterface/ThreeStates.cs | 27 +++++++++++++++++++ 2 files changed, 27 insertions(+), 19 deletions(-) create mode 100644 osu.Game/Graphics/UserInterface/ThreeStates.cs diff --git a/osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs b/osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs index e33c68bebd..ebb6436196 100644 --- a/osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs +++ b/osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs @@ -76,23 +76,4 @@ namespace osu.Game.Graphics.UserInterface } } } - - public enum ThreeStates - { - /// - /// The current state is disabled. - /// - Disabled, - - /// - /// The current state is a combination of and . - /// The state becomes if the is pressed. - /// - Indeterminate, - - /// - /// The current state is enabled. - /// - Enabled - } } diff --git a/osu.Game/Graphics/UserInterface/ThreeStates.cs b/osu.Game/Graphics/UserInterface/ThreeStates.cs new file mode 100644 index 0000000000..f099250937 --- /dev/null +++ b/osu.Game/Graphics/UserInterface/ThreeStates.cs @@ -0,0 +1,27 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +namespace osu.Game.Graphics.UserInterface +{ + /// + /// An on/off state with an extra indeterminate state. + /// + public enum ThreeStates + { + /// + /// The current state is disabled. + /// + Disabled, + + /// + /// The current state is a combination of and . + /// The state becomes if the is pressed. + /// + Indeterminate, + + /// + /// The current state is enabled. + /// + Enabled + } +} From e574aa0e94ee16366a7c4086f2eb80042edb494f Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 8 Nov 2019 13:33:15 +0900 Subject: [PATCH 10/16] Add toggle menu item test --- .../UserInterface/TestSceneToggleMenuItem.cs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 osu.Game.Tests/Visual/UserInterface/TestSceneToggleMenuItem.cs diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneToggleMenuItem.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneToggleMenuItem.cs new file mode 100644 index 0000000000..2abda56a28 --- /dev/null +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneToggleMenuItem.cs @@ -0,0 +1,34 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Collections.Generic; +using osu.Framework.Graphics; +using osu.Game.Graphics.UserInterface; + +namespace osu.Game.Tests.Visual.UserInterface +{ + public class TestSceneToggleMenuItem : OsuTestScene + { + public override IReadOnlyList RequiredTypes => new[] + { + typeof(OsuMenu), + typeof(ToggleMenuItem), + typeof(DrawableStatefulMenuItem) + }; + + public TestSceneToggleMenuItem() + { + Add(new OsuMenu(Direction.Vertical, true) + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Items = new[] + { + new ToggleMenuItem("First"), + new ToggleMenuItem("Second") { State = { Value = true } } + } + }); + } + } +} From 92d8526370e8cdc166460b30c58e0d47c4cc2654 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 8 Nov 2019 13:34:27 +0900 Subject: [PATCH 11/16] Adjust test namespaces --- .../{ => MenuItems}/TestSceneStatefulMenuItem.cs | 4 ++-- .../{ => MenuItems}/TestSceneThreeStateMenuItem.cs | 2 +- .../UserInterface/{ => MenuItems}/TestSceneToggleMenuItem.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename osu.Game.Tests/Visual/UserInterface/{ => MenuItems}/TestSceneStatefulMenuItem.cs (96%) rename osu.Game.Tests/Visual/UserInterface/{ => MenuItems}/TestSceneThreeStateMenuItem.cs (95%) rename osu.Game.Tests/Visual/UserInterface/{ => MenuItems}/TestSceneToggleMenuItem.cs (94%) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs b/osu.Game.Tests/Visual/UserInterface/MenuItems/TestSceneStatefulMenuItem.cs similarity index 96% rename from osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs rename to osu.Game.Tests/Visual/UserInterface/MenuItems/TestSceneStatefulMenuItem.cs index d010abc862..95e9aea97f 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs +++ b/osu.Game.Tests/Visual/UserInterface/MenuItems/TestSceneStatefulMenuItem.cs @@ -7,14 +7,14 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; using osu.Game.Graphics.UserInterface; -namespace osu.Game.Tests.Visual.UserInterface +namespace osu.Game.Tests.Visual.UserInterface.MenuItems { public class TestSceneStatefulMenuItem : OsuTestScene { public override IReadOnlyList RequiredTypes => new[] { typeof(OsuMenu), - typeof(ToggleMenuItem), + typeof(StatefulMenuItem), typeof(DrawableStatefulMenuItem) }; diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneThreeStateMenuItem.cs b/osu.Game.Tests/Visual/UserInterface/MenuItems/TestSceneThreeStateMenuItem.cs similarity index 95% rename from osu.Game.Tests/Visual/UserInterface/TestSceneThreeStateMenuItem.cs rename to osu.Game.Tests/Visual/UserInterface/MenuItems/TestSceneThreeStateMenuItem.cs index caa07e7b60..e035e43630 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneThreeStateMenuItem.cs +++ b/osu.Game.Tests/Visual/UserInterface/MenuItems/TestSceneThreeStateMenuItem.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using osu.Framework.Graphics; using osu.Game.Graphics.UserInterface; -namespace osu.Game.Tests.Visual.UserInterface +namespace osu.Game.Tests.Visual.UserInterface.MenuItems { public class TestSceneThreeStateMenuItem : OsuTestScene { diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneToggleMenuItem.cs b/osu.Game.Tests/Visual/UserInterface/MenuItems/TestSceneToggleMenuItem.cs similarity index 94% rename from osu.Game.Tests/Visual/UserInterface/TestSceneToggleMenuItem.cs rename to osu.Game.Tests/Visual/UserInterface/MenuItems/TestSceneToggleMenuItem.cs index 2abda56a28..92875740cf 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneToggleMenuItem.cs +++ b/osu.Game.Tests/Visual/UserInterface/MenuItems/TestSceneToggleMenuItem.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using osu.Framework.Graphics; using osu.Game.Graphics.UserInterface; -namespace osu.Game.Tests.Visual.UserInterface +namespace osu.Game.Tests.Visual.UserInterface.MenuItems { public class TestSceneToggleMenuItem : OsuTestScene { From ce4843be22ff62e95362da8a2f24530c1fb9b91c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 11 Nov 2019 18:42:32 +0900 Subject: [PATCH 12/16] Move tests to parent namespace for now --- .../UserInterface/{MenuItems => }/TestSceneStatefulMenuItem.cs | 2 +- .../{MenuItems => }/TestSceneThreeStateMenuItem.cs | 2 +- .../UserInterface/{MenuItems => }/TestSceneToggleMenuItem.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename osu.Game.Tests/Visual/UserInterface/{MenuItems => }/TestSceneStatefulMenuItem.cs (98%) rename osu.Game.Tests/Visual/UserInterface/{MenuItems => }/TestSceneThreeStateMenuItem.cs (95%) rename osu.Game.Tests/Visual/UserInterface/{MenuItems => }/TestSceneToggleMenuItem.cs (94%) diff --git a/osu.Game.Tests/Visual/UserInterface/MenuItems/TestSceneStatefulMenuItem.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs similarity index 98% rename from osu.Game.Tests/Visual/UserInterface/MenuItems/TestSceneStatefulMenuItem.cs rename to osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs index 95e9aea97f..fd30da39e6 100644 --- a/osu.Game.Tests/Visual/UserInterface/MenuItems/TestSceneStatefulMenuItem.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs @@ -7,7 +7,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; using osu.Game.Graphics.UserInterface; -namespace osu.Game.Tests.Visual.UserInterface.MenuItems +namespace osu.Game.Tests.Visual.UserInterface { public class TestSceneStatefulMenuItem : OsuTestScene { diff --git a/osu.Game.Tests/Visual/UserInterface/MenuItems/TestSceneThreeStateMenuItem.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneThreeStateMenuItem.cs similarity index 95% rename from osu.Game.Tests/Visual/UserInterface/MenuItems/TestSceneThreeStateMenuItem.cs rename to osu.Game.Tests/Visual/UserInterface/TestSceneThreeStateMenuItem.cs index e035e43630..caa07e7b60 100644 --- a/osu.Game.Tests/Visual/UserInterface/MenuItems/TestSceneThreeStateMenuItem.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneThreeStateMenuItem.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using osu.Framework.Graphics; using osu.Game.Graphics.UserInterface; -namespace osu.Game.Tests.Visual.UserInterface.MenuItems +namespace osu.Game.Tests.Visual.UserInterface { public class TestSceneThreeStateMenuItem : OsuTestScene { diff --git a/osu.Game.Tests/Visual/UserInterface/MenuItems/TestSceneToggleMenuItem.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneToggleMenuItem.cs similarity index 94% rename from osu.Game.Tests/Visual/UserInterface/MenuItems/TestSceneToggleMenuItem.cs rename to osu.Game.Tests/Visual/UserInterface/TestSceneToggleMenuItem.cs index 92875740cf..2abda56a28 100644 --- a/osu.Game.Tests/Visual/UserInterface/MenuItems/TestSceneToggleMenuItem.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneToggleMenuItem.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using osu.Framework.Graphics; using osu.Game.Graphics.UserInterface; -namespace osu.Game.Tests.Visual.UserInterface.MenuItems +namespace osu.Game.Tests.Visual.UserInterface { public class TestSceneToggleMenuItem : OsuTestScene { From bed62e0d2f2b62d19a76bfb051c04263900706c8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 11 Nov 2019 18:56:18 +0900 Subject: [PATCH 13/16] Rename ThreeState -> TernaryState and add basic tests --- .../UserInterface/TestSceneTernaryMenuItem.cs | 65 +++++++++++++++++++ .../TestSceneThreeStateMenuItem.cs | 35 ---------- .../{ThreeStates.cs => TernaryState.cs} | 14 ++-- .../UserInterface/ThreeStateMenuItem.cs | 28 ++++---- 4 files changed, 86 insertions(+), 56 deletions(-) create mode 100644 osu.Game.Tests/Visual/UserInterface/TestSceneTernaryMenuItem.cs delete mode 100644 osu.Game.Tests/Visual/UserInterface/TestSceneThreeStateMenuItem.cs rename osu.Game/Graphics/UserInterface/{ThreeStates.cs => TernaryState.cs} (56%) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneTernaryMenuItem.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneTernaryMenuItem.cs new file mode 100644 index 0000000000..fdb8c330c5 --- /dev/null +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneTernaryMenuItem.cs @@ -0,0 +1,65 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Collections.Generic; +using osu.Framework.Bindables; +using osu.Framework.Graphics; +using osu.Game.Graphics.UserInterface; +using osuTK.Input; + +namespace osu.Game.Tests.Visual.UserInterface +{ + public class TestSceneTernaryMenuItem : ManualInputManagerTestScene + { + private readonly OsuMenu menu; + + public override IReadOnlyList RequiredTypes => new[] + { + typeof(OsuMenu), + typeof(ThreeStateMenuItem), + typeof(DrawableStatefulMenuItem) + }; + + private readonly Bindable state = new Bindable(TernaryState.Indeterminate); + + public TestSceneTernaryMenuItem() + { + Add(menu = new OsuMenu(Direction.Vertical, true) + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Items = new[] + { + new ThreeStateMenuItem("First"), + new ThreeStateMenuItem("Second") { State = { BindTarget = state } }, + new ThreeStateMenuItem("Third") { State = { Value = TernaryState.True } }, + } + }); + + checkState(TernaryState.Indeterminate); + + click(); + checkState(TernaryState.True); + + click(); + checkState(TernaryState.False); + + click(); + checkState(TernaryState.True); + + click(); + checkState(TernaryState.False); + } + + private void click() => + AddStep("click", () => + { + InputManager.MoveMouseTo(menu.ScreenSpaceDrawQuad.Centre); + InputManager.Click(MouseButton.Left); + }); + + private void checkState(TernaryState expected) + => AddAssert($"state is {expected}", () => state.Value == expected); + } +} diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneThreeStateMenuItem.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneThreeStateMenuItem.cs deleted file mode 100644 index caa07e7b60..0000000000 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneThreeStateMenuItem.cs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using System; -using System.Collections.Generic; -using osu.Framework.Graphics; -using osu.Game.Graphics.UserInterface; - -namespace osu.Game.Tests.Visual.UserInterface -{ - public class TestSceneThreeStateMenuItem : OsuTestScene - { - public override IReadOnlyList RequiredTypes => new[] - { - typeof(OsuMenu), - typeof(ThreeStateMenuItem), - typeof(DrawableStatefulMenuItem) - }; - - public TestSceneThreeStateMenuItem() - { - Add(new OsuMenu(Direction.Vertical, true) - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Items = new[] - { - new ThreeStateMenuItem("First"), - new ThreeStateMenuItem("Second") { State = { Value = ThreeStates.Indeterminate } }, - new ThreeStateMenuItem("Third") { State = { Value = ThreeStates.Enabled } }, - } - }); - } - } -} diff --git a/osu.Game/Graphics/UserInterface/ThreeStates.cs b/osu.Game/Graphics/UserInterface/TernaryState.cs similarity index 56% rename from osu.Game/Graphics/UserInterface/ThreeStates.cs rename to osu.Game/Graphics/UserInterface/TernaryState.cs index f099250937..784122e35c 100644 --- a/osu.Game/Graphics/UserInterface/ThreeStates.cs +++ b/osu.Game/Graphics/UserInterface/TernaryState.cs @@ -6,22 +6,22 @@ namespace osu.Game.Graphics.UserInterface /// /// An on/off state with an extra indeterminate state. /// - public enum ThreeStates + public enum TernaryState { /// - /// The current state is disabled. + /// The current state is false. /// - Disabled, + False, /// - /// The current state is a combination of and . - /// The state becomes if the is pressed. + /// The current state is a combination of and . + /// The state becomes if the is pressed. /// Indeterminate, /// - /// The current state is enabled. + /// The current state is true. /// - Enabled + True } } diff --git a/osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs b/osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs index ebb6436196..c5b9edf3c4 100644 --- a/osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs +++ b/osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs @@ -9,7 +9,7 @@ namespace osu.Game.Graphics.UserInterface /// /// An with three possible states. /// - public class ThreeStateMenuItem : StatefulMenuItem + public class ThreeStateMenuItem : StatefulMenuItem { /// /// Creates a new . @@ -27,7 +27,7 @@ namespace osu.Game.Graphics.UserInterface /// The text to display. /// The type of action which this performs. /// A delegate to be invoked when this is pressed. - public ThreeStateMenuItem(string text, MenuItemType type, Action action) + public ThreeStateMenuItem(string text, MenuItemType type, Action action) : this(text, getNextState, type, action) { } @@ -39,37 +39,37 @@ namespace osu.Game.Graphics.UserInterface /// A function that mutates a state to another state after this is pressed. /// The type of action which this performs. /// A delegate to be invoked when this is pressed. - protected ThreeStateMenuItem(string text, Func changeStateFunc, MenuItemType type, Action action) + protected ThreeStateMenuItem(string text, Func changeStateFunc, MenuItemType type, Action action) : base(text, changeStateFunc, type, action) { } - public override IconUsage? GetIconForState(ThreeStates state) + public override IconUsage? GetIconForState(TernaryState state) { switch (state) { - case ThreeStates.Indeterminate: - return FontAwesome.Regular.Circle; + case TernaryState.Indeterminate: + return FontAwesome.Solid.DotCircle; - case ThreeStates.Enabled: + case TernaryState.True: return FontAwesome.Solid.Check; } return null; } - private static ThreeStates getNextState(ThreeStates state) + private static TernaryState getNextState(TernaryState state) { switch (state) { - case ThreeStates.Disabled: - return ThreeStates.Enabled; + case TernaryState.False: + return TernaryState.True; - case ThreeStates.Indeterminate: - return ThreeStates.Enabled; + case TernaryState.Indeterminate: + return TernaryState.True; - case ThreeStates.Enabled: - return ThreeStates.Disabled; + case TernaryState.True: + return TernaryState.False; default: throw new ArgumentOutOfRangeException(nameof(state), state, null); From 82cc6aa0c5b2b251a229808b0a6494ba684a7cbb Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 11 Nov 2019 19:00:14 +0900 Subject: [PATCH 14/16] Remove unused constructor --- .../Visual/UserInterface/TestSceneStatefulMenuItem.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs index fd30da39e6..bd7f73c6d8 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs @@ -52,11 +52,6 @@ namespace osu.Game.Tests.Visual.UserInterface private class TestMenuItem : StatefulMenuItem { - public TestMenuItem(string text, MenuItemType type = MenuItemType.Standard) - : this(text, type, null) - { - } - public TestMenuItem(string text, MenuItemType type, Func changeStateFunc) : base(text, changeStateFunc, type) { From 54da8e4035cd3b033eee59839e5c7428a297d25d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 11 Nov 2019 19:09:38 +0900 Subject: [PATCH 15/16] Combine similar tests --- .../TestSceneStatefulMenuItem.cs | 81 ++++++++++++++++--- .../UserInterface/TestSceneTernaryMenuItem.cs | 65 --------------- 2 files changed, 70 insertions(+), 76 deletions(-) delete mode 100644 osu.Game.Tests/Visual/UserInterface/TestSceneTernaryMenuItem.cs diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs index bd7f73c6d8..1eff30d15e 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs @@ -3,33 +3,92 @@ using System; using System.Collections.Generic; +using NUnit.Framework; +using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; using osu.Game.Graphics.UserInterface; +using osuTK.Input; namespace osu.Game.Tests.Visual.UserInterface { - public class TestSceneStatefulMenuItem : OsuTestScene + public class TestSceneStatefulMenuItem : ManualInputManagerTestScene { public override IReadOnlyList RequiredTypes => new[] { typeof(OsuMenu), typeof(StatefulMenuItem), - typeof(DrawableStatefulMenuItem) + typeof(ThreeStateMenuItem), + typeof(DrawableStatefulMenuItem), }; - public TestSceneStatefulMenuItem() + [Test] + public void TestTernaryMenuItem() { - Add(new OsuMenu(Direction.Vertical, true) + OsuMenu menu = null; + + Bindable state = new Bindable(TernaryState.Indeterminate); + + AddStep("create menu", () => { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Items = new[] + state.Value = TernaryState.Indeterminate; + + Child = menu = new OsuMenu(Direction.Vertical, true) { - new TestMenuItem("First", MenuItemType.Standard, getNextState), - new TestMenuItem("Second", MenuItemType.Standard, getNextState) { State = { Value = TestStates.State2 } }, - new TestMenuItem("Third", MenuItemType.Standard, getNextState) { State = { Value = TestStates.State3 } }, - } + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Items = new[] + { + new ThreeStateMenuItem("First"), + new ThreeStateMenuItem("Second") { State = { BindTarget = state } }, + new ThreeStateMenuItem("Third") { State = { Value = TernaryState.True } }, + } + }; + }); + + checkState(TernaryState.Indeterminate); + + click(); + checkState(TernaryState.True); + + click(); + checkState(TernaryState.False); + + click(); + checkState(TernaryState.True); + + click(); + checkState(TernaryState.False); + + AddStep("change state via bindable", () => state.Value = TernaryState.True); + + void click() => + AddStep("click", () => + { + InputManager.MoveMouseTo(menu.ScreenSpaceDrawQuad.Centre); + InputManager.Click(MouseButton.Left); + }); + + void checkState(TernaryState expected) + => AddAssert($"state is {expected}", () => state.Value == expected); + } + + [Test] + public void TestCustomState() + { + AddStep("create menu", () => + { + Child = new OsuMenu(Direction.Vertical, true) + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Items = new[] + { + new TestMenuItem("First", MenuItemType.Standard, getNextState), + new TestMenuItem("Second", MenuItemType.Standard, getNextState) { State = { Value = TestStates.State2 } }, + new TestMenuItem("Third", MenuItemType.Standard, getNextState) { State = { Value = TestStates.State3 } }, + } + }; }); } diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneTernaryMenuItem.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneTernaryMenuItem.cs deleted file mode 100644 index fdb8c330c5..0000000000 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneTernaryMenuItem.cs +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using System; -using System.Collections.Generic; -using osu.Framework.Bindables; -using osu.Framework.Graphics; -using osu.Game.Graphics.UserInterface; -using osuTK.Input; - -namespace osu.Game.Tests.Visual.UserInterface -{ - public class TestSceneTernaryMenuItem : ManualInputManagerTestScene - { - private readonly OsuMenu menu; - - public override IReadOnlyList RequiredTypes => new[] - { - typeof(OsuMenu), - typeof(ThreeStateMenuItem), - typeof(DrawableStatefulMenuItem) - }; - - private readonly Bindable state = new Bindable(TernaryState.Indeterminate); - - public TestSceneTernaryMenuItem() - { - Add(menu = new OsuMenu(Direction.Vertical, true) - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Items = new[] - { - new ThreeStateMenuItem("First"), - new ThreeStateMenuItem("Second") { State = { BindTarget = state } }, - new ThreeStateMenuItem("Third") { State = { Value = TernaryState.True } }, - } - }); - - checkState(TernaryState.Indeterminate); - - click(); - checkState(TernaryState.True); - - click(); - checkState(TernaryState.False); - - click(); - checkState(TernaryState.True); - - click(); - checkState(TernaryState.False); - } - - private void click() => - AddStep("click", () => - { - InputManager.MoveMouseTo(menu.ScreenSpaceDrawQuad.Centre); - InputManager.Click(MouseButton.Left); - }); - - private void checkState(TernaryState expected) - => AddAssert($"state is {expected}", () => state.Value == expected); - } -} From 5bb65d0716ad1f0520b152e3ab14701b1f998fd8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 12 Nov 2019 10:18:25 +0900 Subject: [PATCH 16/16] Rename button class --- .../TestSceneStatefulMenuItem.cs | 8 +++--- .../Graphics/UserInterface/TernaryState.cs | 2 +- ...ateMenuItem.cs => TernaryStateMenuItem.cs} | 26 +++++++++---------- 3 files changed, 18 insertions(+), 18 deletions(-) rename osu.Game/Graphics/UserInterface/{ThreeStateMenuItem.cs => TernaryStateMenuItem.cs} (69%) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs index 1eff30d15e..2ada5b927b 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs @@ -18,7 +18,7 @@ namespace osu.Game.Tests.Visual.UserInterface { typeof(OsuMenu), typeof(StatefulMenuItem), - typeof(ThreeStateMenuItem), + typeof(TernaryStateMenuItem), typeof(DrawableStatefulMenuItem), }; @@ -39,9 +39,9 @@ namespace osu.Game.Tests.Visual.UserInterface Origin = Anchor.Centre, Items = new[] { - new ThreeStateMenuItem("First"), - new ThreeStateMenuItem("Second") { State = { BindTarget = state } }, - new ThreeStateMenuItem("Third") { State = { Value = TernaryState.True } }, + new TernaryStateMenuItem("First"), + new TernaryStateMenuItem("Second") { State = { BindTarget = state } }, + new TernaryStateMenuItem("Third") { State = { Value = TernaryState.True } }, } }; }); diff --git a/osu.Game/Graphics/UserInterface/TernaryState.cs b/osu.Game/Graphics/UserInterface/TernaryState.cs index 784122e35c..d4de28044f 100644 --- a/osu.Game/Graphics/UserInterface/TernaryState.cs +++ b/osu.Game/Graphics/UserInterface/TernaryState.cs @@ -15,7 +15,7 @@ namespace osu.Game.Graphics.UserInterface /// /// The current state is a combination of and . - /// The state becomes if the is pressed. + /// The state becomes if the is pressed. /// Indeterminate, diff --git a/osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs b/osu.Game/Graphics/UserInterface/TernaryStateMenuItem.cs similarity index 69% rename from osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs rename to osu.Game/Graphics/UserInterface/TernaryStateMenuItem.cs index c5b9edf3c4..2d9e2106d4 100644 --- a/osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs +++ b/osu.Game/Graphics/UserInterface/TernaryStateMenuItem.cs @@ -9,37 +9,37 @@ namespace osu.Game.Graphics.UserInterface /// /// An with three possible states. /// - public class ThreeStateMenuItem : StatefulMenuItem + public class TernaryStateMenuItem : StatefulMenuItem { /// - /// Creates a new . + /// Creates a new . /// /// The text to display. - /// The type of action which this performs. - public ThreeStateMenuItem(string text, MenuItemType type = MenuItemType.Standard) + /// The type of action which this performs. + public TernaryStateMenuItem(string text, MenuItemType type = MenuItemType.Standard) : this(text, type, null) { } /// - /// Creates a new . + /// Creates a new . /// /// The text to display. - /// The type of action which this performs. - /// A delegate to be invoked when this is pressed. - public ThreeStateMenuItem(string text, MenuItemType type, Action action) + /// The type of action which this performs. + /// A delegate to be invoked when this is pressed. + public TernaryStateMenuItem(string text, MenuItemType type, Action action) : this(text, getNextState, type, action) { } /// - /// Creates a new . + /// Creates a new . /// /// The text to display. - /// A function that mutates a state to another state after this is pressed. - /// The type of action which this performs. - /// A delegate to be invoked when this is pressed. - protected ThreeStateMenuItem(string text, Func changeStateFunc, MenuItemType type, Action action) + /// A function that mutates a state to another state after this is pressed. + /// The type of action which this performs. + /// A delegate to be invoked when this is pressed. + protected TernaryStateMenuItem(string text, Func changeStateFunc, MenuItemType type, Action action) : base(text, changeStateFunc, type, action) { }