2019-11-08 10:15:03 +08:00
|
|
|
// 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-11 17:42:32 +08:00
|
|
|
namespace osu.Game.Tests.Visual.UserInterface
|
2019-11-08 10:15:03 +08:00
|
|
|
{
|
|
|
|
public class TestSceneStatefulMenuItem : OsuTestScene
|
|
|
|
{
|
|
|
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
|
|
|
{
|
|
|
|
typeof(OsuMenu),
|
2019-11-08 12:34:27 +08:00
|
|
|
typeof(StatefulMenuItem),
|
2019-11-08 10:15:03 +08:00
|
|
|
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, Func<TestStates, TestStates> changeStateFunc)
|
2019-11-08 11:55:22 +08:00
|
|
|
: base(text, changeStateFunc, type)
|
2019-11-08 10:15:03 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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 12:14:23 +08:00
|
|
|
default:
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(state), state, null);
|
|
|
|
}
|
2019-11-08 10:15:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private enum TestStates
|
|
|
|
{
|
|
|
|
State1,
|
|
|
|
State2,
|
|
|
|
State3
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|