1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-28 01:47:33 +08:00

Reimplement TestCaseEditorMenuBar.

This commit is contained in:
smoogipooo 2017-08-28 15:32:12 +09:00
parent a5fbeb8959
commit 5dae408ecb
2 changed files with 157 additions and 117 deletions

@ -1 +1 @@
Subproject commit 2cb3e59c8bc7e67edef4dfe7f9c7dfc01db386a7 Subproject commit f6a1df24eeef78e89f2d6e24fe1b43756eaae51e

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Framework.Allocation; using osu.Framework.Allocation;
@ -20,7 +21,7 @@ namespace osu.Desktop.Tests.Visual
{ {
public TestCaseEditorMenuBar() public TestCaseEditorMenuBar()
{ {
Add(new MenuBar Add(new EditorMenuBar
{ {
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
@ -31,162 +32,201 @@ namespace osu.Desktop.Tests.Visual
{ {
Items = new[] Items = new[]
{ {
new EditorContextMenuItem("Clear All Notes"), new EditorMenuItem("Clear All Notes"),
new EditorContextMenuItem("Open Difficulty..."), new EditorMenuItem("Open Difficulty..."),
new EditorContextMenuItem("Save"), new EditorMenuItem("Save"),
new EditorContextMenuItem("Create a new Difficulty..."), new EditorMenuItem("Create a new Difficulty..."),
new EditorContextMenuSpacer(), new EditorMenuSpacer(),
new EditorContextMenuItem("Revert to Saved"), new EditorMenuItem("Revert to Saved"),
new EditorContextMenuItem("Revert to Saved (Full)"), new EditorMenuItem("Revert to Saved (Full)"),
new EditorContextMenuSpacer(), new EditorMenuSpacer(),
new EditorContextMenuItem("Test Beatmap"), new EditorMenuItem("Test Beatmap"),
new EditorContextMenuItem("Open AiMod"), new EditorMenuItem("Open AiMod"),
new EditorContextMenuSpacer(), new EditorMenuSpacer(),
new EditorContextMenuItem("Upload Beatmap..."), new EditorMenuItem("Upload Beatmap..."),
new EditorContextMenuItem("Export Package"), new EditorMenuItem("Export Package"),
new EditorContextMenuItem("Export Map Package"), new EditorMenuItem("Export Map Package"),
new EditorContextMenuItem("Import from..."), new EditorMenuItem("Import from..."),
new EditorContextMenuSpacer(), new EditorMenuSpacer(),
new EditorContextMenuItem("Open Song Folder"), new EditorMenuItem("Open Song Folder"),
new EditorContextMenuItem("Open .osu in Notepad"), new EditorMenuItem("Open .osu in Notepad"),
new EditorContextMenuItem("Open .osb in Notepad"), new EditorMenuItem("Open .osb in Notepad"),
new EditorContextMenuSpacer(), new EditorMenuSpacer(),
new EditorContextMenuItem("Exit"), new EditorMenuItem("Exit"),
} }
}, },
new EditorMenuBarItem("Timing") new EditorMenuBarItem("Timing")
{ {
Items = new[] Items = new[]
{ {
new EditorContextMenuItem("Time Signature"), new EditorMenuItem("Time Signature"),
new EditorContextMenuItem("Metronome Clicks"), new EditorMenuItem("Metronome Clicks"),
new EditorContextMenuSpacer(), new EditorMenuSpacer(),
new EditorContextMenuItem("Add Timing Section"), new EditorMenuItem("Add Timing Section"),
new EditorContextMenuItem("Add Inheriting Section"), new EditorMenuItem("Add Inheriting Section"),
new EditorContextMenuItem("Reset Current Section"), new EditorMenuItem("Reset Current Section"),
new EditorContextMenuItem("Delete Timing Section"), new EditorMenuItem("Delete Timing Section"),
new EditorContextMenuItem("Resnap Current Section"), new EditorMenuItem("Resnap Current Section"),
new EditorContextMenuSpacer(), new EditorMenuSpacer(),
new EditorContextMenuItem("Timing Setup"), new EditorMenuItem("Timing Setup"),
new EditorContextMenuSpacer(), new EditorMenuSpacer(),
new EditorContextMenuItem("Resnap All Notes", MenuItemType.Destructive), new EditorMenuItem("Resnap All Notes", MenuItemType.Destructive),
new EditorContextMenuItem("Move all notes in time...", MenuItemType.Destructive), new EditorMenuItem("Move all notes in time...", MenuItemType.Destructive),
new EditorContextMenuItem("Recalculate Slider Lengths", MenuItemType.Destructive), new EditorMenuItem("Recalculate Slider Lengths", MenuItemType.Destructive),
new EditorContextMenuItem("Delete All Timing Sections", MenuItemType.Destructive), new EditorMenuItem("Delete All Timing Sections", MenuItemType.Destructive),
new EditorContextMenuSpacer(), new EditorMenuSpacer(),
new EditorContextMenuItem("Set Current Position as Preview Point"), new EditorMenuItem("Set Current Position as Preview Point"),
} }
}, },
new EditorMenuBarItem("Testing") new EditorMenuBarItem("Testing")
{ {
Items = new[] Items = new[]
{ {
new EditorContextMenuItem("Item 1"), new EditorMenuItem("Item 1"),
new EditorContextMenuItem("Item 2"), new EditorMenuItem("Item 2"),
new EditorContextMenuItem("Item 3"), new EditorMenuItem("Item 3"),
} }
}, },
} }
}); });
} }
private class EditorMenuBarItem : MenuBarItem private class EditorMenuBar : MenuBar
{ {
private const int fade_duration = 250; protected override DrawableMenuBarItem CreateDrawableMenuBarItem(MenuItem item) => new DrawableEditorMenuBarItem(item);
private const float text_size = 17;
private readonly Container background; private class DrawableEditorMenuBarItem : DrawableMenuBarItem
private Color4 normalColour;
public EditorMenuBarItem(string title)
: base(title)
{ {
Content.Padding = new MarginPadding(8); private const int fade_duration = 250;
private const float text_size = 17;
AddInternal(background = new Container private readonly Container background;
private Color4 normalColour;
public DrawableEditorMenuBarItem(MenuItem item)
: base(item)
{ {
RelativeSizeAxes = Axes.Both, if (!(item is EditorMenuBarItem))
Masking = true, throw new ArgumentException($"{nameof(item)} must be a {nameof(EditorMenuBarItem)}.");
Depth = float.MaxValue,
Alpha = 0, Text.Padding = new MarginPadding(8);
Child = new Container<Box>
AddInternal(background = new Container
{ {
// The following is done so we can have top rounded corners but not bottom corners
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Height = 2,
Masking = true, Masking = true,
CornerRadius = 5, Depth = float.MaxValue,
Child = new Box { RelativeSizeAxes = Axes.Both } Alpha = 0,
Child = new Container<Box>
{
// The following is done so we can have top rounded corners but not bottom corners
RelativeSizeAxes = Axes.Both,
Height = 2,
Masking = true,
CornerRadius = 5,
Child = new Box { RelativeSizeAxes = Axes.Both }
}
});
Menu.OnOpen += menuOpen;
Menu.OnClose += menuClose;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
background.Colour = colours.Gray3;
Text.Colour = normalColour = colours.BlueLight;
}
private void menuOpen()
{
background.FadeIn(fade_duration, Easing.OutQuint);
Text.FadeColour(Color4.White, fade_duration, Easing.OutQuint);
}
private void menuClose()
{
background.FadeOut(fade_duration, Easing.OutQuint);
Text.FadeColour(normalColour, fade_duration, Easing.OutQuint);
}
protected override SpriteText CreateText() => new OsuSpriteText { TextSize = text_size };
protected override Menu CreateMenu() => new EditorMenu();
private class EditorMenu : OsuMenu
{
public EditorMenu()
{
Anchor = Anchor.BottomLeft;
BypassAutoSizeAxes = Axes.Both;
OriginPosition = new Vector2(8, 0);
} }
});
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
background.Colour = colours.Gray3; BackgroundColour = colours.Gray3;
TitleText.Colour = normalColour = colours.BlueLight; }
}
public override void Open() protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item) => new DrawableEditorMenuItem(item);
{
base.Open();
background.FadeIn(fade_duration, Easing.OutQuint); private class DrawableEditorMenuItem : DrawableOsuMenuItem
TitleText.FadeColour(Color4.White, fade_duration, Easing.OutQuint); {
} public override bool HandleInput => !isSpacer;
private readonly bool isSpacer;
public override void Close() public DrawableEditorMenuItem(MenuItem item)
{ : base(item)
base.Close(); {
if (!(item is EditorMenuItem))
throw new ArgumentException($"{nameof(item)} must be a {nameof(EditorMenuItem)}.");
background.FadeOut(fade_duration, Easing.OutQuint); isSpacer = item is EditorMenuSpacer;
TitleText.FadeColour(normalColour, fade_duration, Easing.OutQuint); }
}
protected override SpriteText CreateTitleText() => new OsuSpriteText { TextSize = text_size }; [BackgroundDependencyLoader]
private void load(OsuColour colours)
protected override ContextMenu<ContextMenuItem> CreateContextMenu() => new EditorContextMenu {
{ BackgroundColour = colours.Gray3;
OriginPosition = new Vector2(8, 0) BackgroundColourHover = colours.Gray2;
}; }
} }
}
private class EditorContextMenu : OsuContextMenu<ContextMenuItem>
{
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Menu.Background.Colour = colours.Gray3;
} }
} }
private class EditorContextMenuSpacer : EditorContextMenuItem private class EditorMenuBarItem : MenuItem
{ {
public override bool HandleInput => false; public EditorMenuBarItem(string text)
: base(text)
{
}
}
public EditorContextMenuSpacer() private class EditorMenuItem : OsuMenuItem
{
private const int min_text_length = 40;
public EditorMenuItem(string text, MenuItemType type = MenuItemType.Standard)
: base(text.PadRight(min_text_length), type)
{
}
public EditorMenuItem(string text, MenuItemType type, Action action)
: base(text.PadRight(min_text_length), type, action)
{
}
}
private class EditorMenuSpacer : EditorMenuItem
{
public EditorMenuSpacer()
: base(" ") : base(" ")
{ {
} }
} }
private class EditorContextMenuItem : OsuContextMenuItem
{
private const int min_text_length = 40;
public EditorContextMenuItem(string title, MenuItemType type = MenuItemType.Standard)
: base(title.PadRight(min_text_length), type)
{
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
BackgroundColour = colours.Gray3;
BackgroundColourHover = colours.Gray2;
}
}
} }
} }