osu/osu.Game.Tests/Visual/UserInterface/MenuItems/TestSceneStatefulMenuItem.cs

92 lines
2.8 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
2019-11-08 04:34:27 +00:00
namespace osu.Game.Tests.Visual.UserInterface.MenuItems
{
public class TestSceneStatefulMenuItem : OsuTestScene
{
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(OsuMenu),
2019-11-08 04:34:27 +00:00
typeof(StatefulMenuItem),
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<TestStates>
{
public TestMenuItem(string text, MenuItemType type = MenuItemType.Standard)
2019-11-08 03:55:22 +00:00
: this(text, type, null)
{
}
public TestMenuItem(string text, MenuItemType type, Func<TestStates, TestStates> changeStateFunc)
2019-11-08 03:55:22 +00:00
: 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;
2019-11-08 04:14:23 +00:00
default:
throw new ArgumentOutOfRangeException(nameof(state), state, null);
}
}
}
private enum TestStates
{
State1,
State2,
State3
}
}
}