1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-17 11:12:55 +08:00
osu-lazer/osu.Game/Screens/Edit/Components/Menus/EditorMenuBar.cs

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

169 lines
5.7 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
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
2018-11-06 17:28:22 +08:00
using osu.Framework.Input.Events;
using osu.Game.Graphics;
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
2018-11-06 17:28:22 +08:00
namespace osu.Game.Screens.Edit.Components.Menus
{
2017-09-06 20:14:29 +08:00
public class EditorMenuBar : OsuMenu
{
2017-09-06 20:14:29 +08:00
public EditorMenuBar()
2017-09-07 19:36:32 +08:00
: base(Direction.Horizontal, true)
{
RelativeSizeAxes = Axes.X;
2018-04-13 17:19:50 +08:00
MaskingContainer.CornerRadius = 0;
ItemsContainer.Padding = new MarginPadding { Left = 100 };
BackgroundColour = Color4Extensions.FromHex("111");
2017-09-06 20:14:29 +08:00
}
2018-04-13 17:19:50 +08:00
2017-09-06 20:14:29 +08:00
protected override Framework.Graphics.UserInterface.Menu CreateSubMenu() => new SubMenu();
2018-04-13 17:19:50 +08:00
2017-09-06 20:14:29 +08:00
protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item) => new DrawableEditorBarMenuItem(item);
2018-04-13 17:19:50 +08:00
2017-09-06 20:14:29 +08:00
private class DrawableEditorBarMenuItem : DrawableOsuMenuItem
{
private BackgroundBox background;
2018-04-13 17:19:50 +08:00
2017-09-06 20:14:29 +08:00
public DrawableEditorBarMenuItem(MenuItem item)
: base(item)
{
Anchor = Anchor.CentreLeft;
Origin = Anchor.CentreLeft;
2018-04-13 17:19:50 +08:00
StateChanged += stateChanged;
}
2018-04-13 17:19:50 +08:00
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
ForegroundColour = colours.BlueLight;
BackgroundColour = Color4.Transparent;
ForegroundColourHover = Color4.White;
BackgroundColourHover = colours.Gray3;
}
2018-04-13 17:19:50 +08:00
public override void SetFlowDirection(Direction direction)
{
AutoSizeAxes = Axes.Both;
}
2018-04-13 17:19:50 +08:00
2017-09-06 20:14:29 +08:00
protected override void UpdateBackgroundColour()
{
2017-09-06 20:14:29 +08:00
if (State == MenuItemState.Selected)
Background.FadeColour(BackgroundColourHover);
2017-09-06 20:14:29 +08:00
else
base.UpdateBackgroundColour();
}
2018-04-13 17:19:50 +08:00
2017-09-06 20:14:29 +08:00
protected override void UpdateForegroundColour()
{
2017-09-06 20:14:29 +08:00
if (State == MenuItemState.Selected)
Foreground.FadeColour(ForegroundColourHover);
2017-09-06 20:14:29 +08:00
else
base.UpdateForegroundColour();
}
2018-04-13 17:19:50 +08:00
private void stateChanged(MenuItemState newState)
{
if (newState == MenuItemState.Selected)
background.Expand();
else
background.Contract();
}
2018-04-13 17:19:50 +08:00
protected override Drawable CreateBackground() => background = new BackgroundBox();
protected override DrawableOsuMenuItem.TextContainer CreateTextContainer() => new TextContainer();
2018-04-13 17:19:50 +08:00
private new class TextContainer : DrawableOsuMenuItem.TextContainer
{
public TextContainer()
{
NormalText.Font = NormalText.Font.With(size: 14);
BoldText.Font = BoldText.Font.With(size: 14);
NormalText.Margin = BoldText.Margin = new MarginPadding { Horizontal = 10, Vertical = MARGIN_VERTICAL };
}
}
2018-04-13 17:19:50 +08:00
private class BackgroundBox : CompositeDrawable
{
private readonly Container innerBackground;
2018-04-13 17:19:50 +08:00
public BackgroundBox()
{
RelativeSizeAxes = Axes.Both;
Masking = true;
InternalChild = innerBackground = new Container
{
RelativeSizeAxes = Axes.Both,
Masking = true,
CornerRadius = 4,
Child = new Box { RelativeSizeAxes = Axes.Both }
};
}
2018-04-13 17:19:50 +08:00
/// <summary>
/// Expands the background such that it doesn't show the bottom corners.
/// </summary>
public void Expand() => innerBackground.Height = 2;
2018-04-13 17:19:50 +08:00
/// <summary>
/// Contracts the background such that it shows the bottom corners.
/// </summary>
public void Contract() => innerBackground.Height = 1;
}
2017-09-06 20:14:29 +08:00
}
2018-04-13 17:19:50 +08:00
2017-09-06 20:14:29 +08:00
private class SubMenu : OsuMenu
{
public SubMenu()
: base(Direction.Vertical)
{
OriginPosition = new Vector2(5, 1);
ItemsContainer.Padding = new MarginPadding { Top = 5, Bottom = 5 };
}
2018-04-13 17:19:50 +08:00
2017-09-06 20:14:29 +08:00
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
2017-09-06 20:14:29 +08:00
BackgroundColour = colours.Gray3;
}
2018-04-13 17:19:50 +08:00
2017-09-06 20:14:29 +08:00
protected override Framework.Graphics.UserInterface.Menu CreateSubMenu() => new SubMenu();
2018-04-13 17:19:50 +08:00
protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item)
2017-09-06 20:14:29 +08:00
{
switch (item)
{
case EditorMenuItemSpacer spacer:
return new DrawableSpacer(spacer);
}
2018-04-13 17:19:50 +08:00
return base.CreateDrawableMenuItem(item);
}
2019-02-28 12:31:40 +08:00
private class DrawableSpacer : DrawableOsuMenuItem
{
public DrawableSpacer(MenuItem item)
: base(item)
{
}
2018-04-13 17:19:50 +08:00
protected override bool OnHover(HoverEvent e) => true;
2019-02-28 12:31:40 +08:00
protected override bool OnClick(ClickEvent e) => true;
}
}
}
}