// 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) : this(text, type, null) { } public TestMenuItem(string text, MenuItemType type, Func changeStateFunc) : base(text, changeStateFunc, type) { } 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; default: throw new ArgumentOutOfRangeException(nameof(state), state, null); } } } private enum TestStates { State1, State2, State3 } } }