2017-08-28 16:55:50 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2017-09-06 20:14:29 +08:00
|
|
|
|
using osu.Framework.Input;
|
2017-08-28 16:55:50 +08:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
2017-10-04 18:37:17 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
2017-10-04 18:36:55 +08:00
|
|
|
|
using osu.Game.Screens.Edit.Screens;
|
2017-08-28 16:55:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit.Menus
|
|
|
|
|
{
|
2017-09-06 20:14:29 +08:00
|
|
|
|
public class EditorMenuBar : OsuMenu
|
2017-08-28 16:55:50 +08:00
|
|
|
|
{
|
2017-10-04 18:37:17 +08:00
|
|
|
|
public readonly Bindable<EditorScreenMode> Mode = new Bindable<EditorScreenMode>();
|
2017-10-02 08:24:25 +08:00
|
|
|
|
|
|
|
|
|
private readonly ScreenSelectionTabControl tabControl;
|
|
|
|
|
|
2017-09-06 20:14:29 +08:00
|
|
|
|
public EditorMenuBar()
|
2017-09-07 19:36:32 +08:00
|
|
|
|
: base(Direction.Horizontal, true)
|
2017-08-28 16:55:50 +08:00
|
|
|
|
{
|
2017-09-27 20:53:33 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
|
|
|
|
|
ItemsContainer.Padding = new MarginPadding { Left = 100 };
|
2017-09-27 21:15:11 +08:00
|
|
|
|
BackgroundColour = OsuColour.FromHex("111");
|
2017-09-27 20:53:33 +08:00
|
|
|
|
|
|
|
|
|
AddRangeInternal(new Drawable[]
|
|
|
|
|
{
|
2017-10-02 08:24:25 +08:00
|
|
|
|
tabControl = new ScreenSelectionTabControl
|
2017-09-27 21:01:53 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomRight,
|
|
|
|
|
Origin = Anchor.BottomRight,
|
|
|
|
|
X = -15
|
|
|
|
|
}
|
2017-09-27 20:53:33 +08:00
|
|
|
|
});
|
2017-10-02 08:24:25 +08:00
|
|
|
|
|
2017-10-04 18:37:17 +08:00
|
|
|
|
tabControl.Current.BindTo(Mode);
|
2017-10-02 08:24:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
tabControl.Current.TriggerChange();
|
2017-09-06 20:14:29 +08:00
|
|
|
|
}
|
2017-08-28 16:55:50 +08:00
|
|
|
|
|
2017-09-06 20:14:29 +08:00
|
|
|
|
protected override Framework.Graphics.UserInterface.Menu CreateSubMenu() => new SubMenu();
|
2017-08-28 16:55:50 +08:00
|
|
|
|
|
2017-09-06 20:14:29 +08:00
|
|
|
|
protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item) => new DrawableEditorBarMenuItem(item);
|
2017-08-28 16:55:50 +08:00
|
|
|
|
|
2017-09-06 20:14:29 +08:00
|
|
|
|
private class DrawableEditorBarMenuItem : DrawableOsuMenuItem
|
|
|
|
|
{
|
2017-09-29 14:10:24 +08:00
|
|
|
|
private BackgroundBox background;
|
2017-09-27 20:53:33 +08:00
|
|
|
|
|
2017-09-06 20:14:29 +08:00
|
|
|
|
public DrawableEditorBarMenuItem(MenuItem item)
|
2017-08-28 16:55:50 +08:00
|
|
|
|
: base(item)
|
|
|
|
|
{
|
2017-09-27 20:53:33 +08:00
|
|
|
|
Anchor = Anchor.CentreLeft;
|
|
|
|
|
Origin = Anchor.CentreLeft;
|
2017-09-29 14:10:24 +08:00
|
|
|
|
|
|
|
|
|
StateChanged += stateChanged;
|
2017-09-27 20:53:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-29 14:09:56 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
2017-09-27 20:53:33 +08:00
|
|
|
|
{
|
2017-09-29 14:09:56 +08:00
|
|
|
|
ForegroundColour = colours.BlueLight;
|
|
|
|
|
BackgroundColour = Color4.Transparent;
|
|
|
|
|
ForegroundColourHover = Color4.White;
|
|
|
|
|
BackgroundColourHover = colours.Gray3;
|
2017-08-28 16:55:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-29 14:09:56 +08:00
|
|
|
|
public override void SetFlowDirection(Direction direction)
|
2017-08-28 16:55:50 +08:00
|
|
|
|
{
|
2017-09-29 14:09:56 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both;
|
2017-08-28 16:55:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-06 20:14:29 +08:00
|
|
|
|
protected override void UpdateBackgroundColour()
|
2017-08-28 16:55:50 +08:00
|
|
|
|
{
|
2017-09-06 20:14:29 +08:00
|
|
|
|
if (State == MenuItemState.Selected)
|
2017-09-29 14:09:56 +08:00
|
|
|
|
Background.FadeColour(BackgroundColourHover);
|
2017-09-06 20:14:29 +08:00
|
|
|
|
else
|
|
|
|
|
base.UpdateBackgroundColour();
|
2017-08-28 16:55:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-06 20:14:29 +08:00
|
|
|
|
protected override void UpdateForegroundColour()
|
2017-08-28 16:55:50 +08:00
|
|
|
|
{
|
2017-09-06 20:14:29 +08:00
|
|
|
|
if (State == MenuItemState.Selected)
|
2017-09-29 14:09:56 +08:00
|
|
|
|
Foreground.FadeColour(ForegroundColourHover);
|
2017-09-06 20:14:29 +08:00
|
|
|
|
else
|
|
|
|
|
base.UpdateForegroundColour();
|
2017-08-28 16:55:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-29 14:10:24 +08:00
|
|
|
|
private void stateChanged(MenuItemState newState)
|
2017-09-27 20:53:33 +08:00
|
|
|
|
{
|
2017-09-29 14:10:24 +08:00
|
|
|
|
if (newState == MenuItemState.Selected)
|
|
|
|
|
background.Expand();
|
|
|
|
|
else
|
|
|
|
|
background.Contract();
|
2017-09-27 20:53:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-29 14:10:24 +08:00
|
|
|
|
protected override Drawable CreateBackground() => background = new BackgroundBox();
|
2017-09-27 20:53:33 +08:00
|
|
|
|
protected override DrawableOsuMenuItem.TextContainer CreateTextContainer() => new TextContainer();
|
|
|
|
|
|
|
|
|
|
private new class TextContainer : DrawableOsuMenuItem.TextContainer
|
|
|
|
|
{
|
|
|
|
|
public TextContainer()
|
|
|
|
|
{
|
|
|
|
|
NormalText.TextSize = BoldText.TextSize = 14;
|
|
|
|
|
NormalText.Margin = BoldText.Margin = new MarginPadding { Horizontal = 10, Vertical = MARGIN_VERTICAL };
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-29 14:10:24 +08:00
|
|
|
|
|
|
|
|
|
private class BackgroundBox : CompositeDrawable
|
|
|
|
|
{
|
|
|
|
|
private readonly Container innerBackground;
|
|
|
|
|
|
|
|
|
|
public BackgroundBox()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
Masking = true;
|
|
|
|
|
InternalChild = innerBackground = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Masking = true,
|
|
|
|
|
CornerRadius = 4,
|
|
|
|
|
Child = new Box { RelativeSizeAxes = Axes.Both }
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Expands the background such that it doesn't show the bottom corners.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Expand() => innerBackground.Height = 2;
|
|
|
|
|
|
|
|
|
|
/// <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
|
|
|
|
}
|
2017-08-28 16:55: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 };
|
|
|
|
|
}
|
2017-08-28 16:55:50 +08:00
|
|
|
|
|
2017-09-06 20:14:29 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
2017-08-28 16:55:50 +08:00
|
|
|
|
{
|
2017-09-06 20:14:29 +08:00
|
|
|
|
BackgroundColour = colours.Gray3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override Framework.Graphics.UserInterface.Menu CreateSubMenu() => new SubMenu();
|
|
|
|
|
|
|
|
|
|
protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item) => new DrawableSubMenuItem(item);
|
|
|
|
|
|
|
|
|
|
private class DrawableSubMenuItem : DrawableOsuMenuItem
|
|
|
|
|
{
|
|
|
|
|
public DrawableSubMenuItem(MenuItem item)
|
|
|
|
|
: base(item)
|
2017-08-28 16:55:50 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-06 20:14:29 +08:00
|
|
|
|
protected override bool OnHover(InputState state)
|
2017-08-28 16:55:50 +08:00
|
|
|
|
{
|
2017-09-07 22:06:35 +08:00
|
|
|
|
if (Item is EditorMenuItemSpacer)
|
2017-09-06 20:14:29 +08:00
|
|
|
|
return true;
|
|
|
|
|
return base.OnHover(state);
|
2017-08-28 16:55:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-06 20:14:29 +08:00
|
|
|
|
protected override bool OnClick(InputState state)
|
2017-08-28 16:55:50 +08:00
|
|
|
|
{
|
2017-09-07 22:06:35 +08:00
|
|
|
|
if (Item is EditorMenuItemSpacer)
|
2017-09-06 20:14:29 +08:00
|
|
|
|
return true;
|
|
|
|
|
return base.OnClick(state);
|
2017-08-28 16:55:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|