1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 15:53:00 +08:00
osu-lazer/osu.Game.Tests/Visual/UserInterface/TestSceneContextMenu.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

140 lines
5.3 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.
2018-04-13 17:19:50 +08:00
2021-08-06 19:59:26 +08:00
using System.Collections.Generic;
using System.Linq;
2018-03-02 14:34:31 +08:00
using NUnit.Framework;
2017-09-18 21:32:49 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
2019-03-25 00:02:36 +08:00
using osu.Game.Graphics.Cursor;
2017-09-18 21:32:49 +08:00
using osu.Game.Graphics.UserInterface;
2018-11-20 15:51:59 +08:00
using osuTK;
using osuTK.Graphics;
2018-04-13 17:19:50 +08:00
2019-03-25 00:02:36 +08:00
namespace osu.Game.Tests.Visual.UserInterface
2017-09-18 21:32:49 +08:00
{
2018-03-02 14:34:31 +08:00
[TestFixture]
public partial class TestSceneContextMenu : OsuTestScene
2017-09-18 21:32:49 +08:00
{
private const int start_time = 0;
private const int duration = 1000;
2018-04-13 17:19:50 +08:00
2017-09-18 21:32:49 +08:00
private readonly Container container;
2018-04-13 17:19:50 +08:00
public TestSceneContextMenu()
2017-09-18 21:32:49 +08:00
{
Add(new OsuContextMenuContainer
2017-09-18 21:32:49 +08:00
{
RelativeSizeAxes = Axes.Both,
2017-09-18 21:32:49 +08:00
Children = new Drawable[]
{
container = new MyContextMenuContainer
2017-09-18 21:32:49 +08:00
{
Size = new Vector2(200),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Green,
}
},
new AnotherContextMenuContainer
2017-09-18 21:32:49 +08:00
{
Size = new Vector2(200),
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Red,
}
2017-09-18 21:32:49 +08:00
}
}
});
}
2018-04-13 17:19:50 +08:00
2017-09-18 21:32:49 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
2018-04-13 17:19:50 +08:00
2017-09-18 21:32:49 +08:00
// Move box along a square trajectory
container.Loop(c => c
2019-02-28 12:31:40 +08:00
.MoveTo(new Vector2(0, 100), duration).Then()
.MoveTo(new Vector2(100, 100), duration).Then()
.MoveTo(new Vector2(100, 0), duration).Then()
.MoveTo(Vector2.Zero, duration)
2017-09-18 21:32:49 +08:00
);
}
2018-04-13 17:19:50 +08:00
2021-08-06 19:59:26 +08:00
private static MenuItem[] makeMenu()
2017-09-18 21:32:49 +08:00
{
2021-08-06 19:59:26 +08:00
return new MenuItem[]
2017-09-18 21:32:49 +08:00
{
new OsuMenuItem(@"Some option"),
new OsuMenuItem(@"Highlighted option", MenuItemType.Highlighted),
new OsuMenuItem(@"Another option"),
2021-08-06 19:59:26 +08:00
new OsuMenuItem(@"Nested option >")
{
Items = new MenuItem[]
{
new OsuMenuItem(@"Sub-One"),
new OsuMenuItem(@"Sub-Two"),
new OsuMenuItem(@"Sub-Three"),
new OsuMenuItem(@"Sub-Nested option >")
{
Items = new MenuItem[]
{
new OsuMenuItem(@"Double Sub-One"),
new OsuMenuItem(@"Double Sub-Two"),
new OsuMenuItem(@"Double Sub-Three"),
new OsuMenuItem(@"Sub-Sub-Nested option >")
{
Items = new MenuItem[]
{
new OsuMenuItem(@"Too Deep One"),
new OsuMenuItem(@"Too Deep Two"),
new OsuMenuItem(@"Too Deep Three"),
}
}
}
}
}
},
2017-09-18 21:32:49 +08:00
new OsuMenuItem(@"Choose me please"),
new OsuMenuItem(@"And me too"),
new OsuMenuItem(@"Trying to fill"),
new OsuMenuItem(@"Destructive option", MenuItemType.Destructive),
};
}
2018-04-13 17:19:50 +08:00
2021-08-06 19:59:26 +08:00
private partial class MyContextMenuContainer : Container, IHasContextMenu
{
public MenuItem[] ContextMenuItems => makeMenu();
}
2017-09-18 21:32:49 +08:00
private partial class AnotherContextMenuContainer : Container, IHasContextMenu
{
2021-08-06 19:59:26 +08:00
public MenuItem[] ContextMenuItems
2017-09-18 21:32:49 +08:00
{
2021-08-06 19:59:26 +08:00
get
{
List<MenuItem> items = makeMenu().ToList();
items.AddRange(new MenuItem[]
{
new OsuMenuItem(@"Change width", MenuItemType.Highlighted, () => this.ResizeWidthTo(Width * 2, 100, Easing.OutQuint)),
new OsuMenuItem(@"Change height", MenuItemType.Highlighted, () => this.ResizeHeightTo(Height * 2, 100, Easing.OutQuint)),
new OsuMenuItem(@"Change width back", MenuItemType.Destructive, () => this.ResizeWidthTo(Width / 2, 100, Easing.OutQuint)),
new OsuMenuItem(@"Change height back", MenuItemType.Destructive, () => this.ResizeHeightTo(Height / 2, 100, Easing.OutQuint)),
});
return items.ToArray();
}
}
2017-09-18 21:32:49 +08:00
}
}
}