1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 19:07:25 +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.

283 lines
9.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.Graphics;
2023-07-14 15:55:12 +08:00
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
2018-11-20 15:51:59 +08:00
using osuTK;
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 partial class EditorMenuBar : OsuMenu
{
2023-07-14 15:55:12 +08:00
private const float heading_area = 114;
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();
ContentContainer.Margin = new MarginPadding { Left = heading_area };
ContentContainer.Masking = true;
}
[BackgroundDependencyLoader]
2023-07-14 15:55:12 +08:00
private void load(OverlayColourProvider colourProvider, TextureStore textures)
{
BackgroundColour = colourProvider.Background3;
2023-07-14 15:55:12 +08:00
TextFlowContainer text;
AddRangeInternal(new[]
{
new Container
{
RelativeSizeAxes = Axes.Y,
Width = heading_area,
Padding = new MarginPadding(8),
Children = new Drawable[]
{
new SpriteIcon
2023-07-14 15:55:12 +08:00
{
Size = new Vector2(26),
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
2023-12-27 22:55:19 +08:00
Icon = OsuIcon.EditCircle,
2023-07-14 15:55:12 +08:00
},
text = new TextFlowContainer
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
AutoSizeAxes = Axes.Both,
}
}
},
});
2023-07-19 14:01:20 +08:00
text.AddText(@"osu!", t => t.Font = OsuFont.TorusAlternate);
text.AddText(@"editor", t =>
2023-07-14 15:55:12 +08:00
{
t.Font = OsuFont.TorusAlternate;
t.Colour = colourProvider.Highlight1;
});
2017-09-06 20:14:29 +08:00
}
2018-04-13 17:19:50 +08:00
protected override Framework.Graphics.UserInterface.Menu CreateSubMenu() => new SubMenu
{
MaxHeight = MaxHeight,
};
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
internal partial class DrawableEditorBarMenuItem : DrawableMenuItem
2017-09-06 20:14:29 +08:00
{
private HoverClickSounds hoverClickSounds = null!;
private TextContainer text = null!;
2017-09-06 20:14:29 +08:00
public DrawableEditorBarMenuItem(MenuItem item)
: base(item)
{
}
2018-04-13 17:19:50 +08:00
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
ForegroundColour = colourProvider.Light3;
BackgroundColour = colourProvider.Background2;
ForegroundColourHover = colourProvider.Content1;
BackgroundColourHover = colourProvider.Background1;
AddInternal(hoverClickSounds = new HoverClickSounds());
}
2018-04-13 17:19:50 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
Foreground.Anchor = Anchor.CentreLeft;
Foreground.Origin = Anchor.CentreLeft;
Item.Action.BindDisabledChanged(_ => updateState(), true);
}
protected override bool OnHover(HoverEvent e)
{
updateState();
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
updateState();
base.OnHoverLost(e);
}
private void updateState()
{
hoverClickSounds.Enabled.Value = IsActionable;
Alpha = IsActionable ? 1 : 0.2f;
if (IsHovered && IsActionable)
{
text.BoldText.FadeIn(DrawableOsuMenuItem.TRANSITION_LENGTH, Easing.OutQuint);
text.NormalText.FadeOut(DrawableOsuMenuItem.TRANSITION_LENGTH, Easing.OutQuint);
}
else
{
text.BoldText.FadeOut(DrawableOsuMenuItem.TRANSITION_LENGTH, Easing.OutQuint);
text.NormalText.FadeIn(DrawableOsuMenuItem.TRANSITION_LENGTH, Easing.OutQuint);
}
}
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
protected sealed override Drawable CreateContent() => text = new TextContainer();
}
2018-04-13 17:19:50 +08:00
private partial class TextContainer : Container, IHasText
{
public LocalisableString Text
{
get => NormalText.Text;
set
{
NormalText.Text = value;
BoldText.Text = value;
}
}
public readonly SpriteText NormalText;
public readonly SpriteText BoldText;
public TextContainer()
{
AutoSizeAxes = Axes.Both;
Child = new Container
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
Padding = new MarginPadding { Horizontal = 17, Vertical = DrawableOsuMenuItem.MARGIN_VERTICAL, },
Children = new Drawable[]
{
NormalText = new OsuSpriteText
{
AlwaysPresent = true, // ensures that the menu item does not change width when switching between normal and bold text.
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.GetFont(size: DrawableOsuMenuItem.TEXT_SIZE),
},
BoldText = new OsuSpriteText
{
AlwaysPresent = true, // ensures that the menu item does not change width when switching between normal and bold text.
Alpha = 0,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.GetFont(size: DrawableOsuMenuItem.TEXT_SIZE, weight: FontWeight.Bold),
}
}
};
}
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 partial class SubMenu : OsuMenu
{
public SubMenu()
: base(Direction.Vertical)
{
ItemsContainer.Padding = new MarginPadding();
MaskingContainer.CornerRadius = 0;
2017-09-06 20:14:29 +08:00
}
2018-04-13 17:19:50 +08:00
2017-09-06 20:14:29 +08:00
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
BackgroundColour = colourProvider.Background2;
2017-09-06 20:14:29 +08:00
}
2018-04-13 17:19:50 +08:00
protected override Framework.Graphics.UserInterface.Menu CreateSubMenu() => new SubMenu
{
MaxHeight = MaxHeight,
};
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 OsuMenuItemSpacer spacer:
return new DrawableSpacer(spacer);
case StatefulMenuItem stateful:
return new EditorStatefulMenuItem(stateful);
default:
return new EditorMenuItem(item);
}
}
private partial class EditorStatefulMenuItem : DrawableStatefulMenuItem
{
public EditorStatefulMenuItem(StatefulMenuItem item)
: base(item)
{
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
BackgroundColour = colourProvider.Background2;
BackgroundColourHover = colourProvider.Background1;
Foreground.Padding = new MarginPadding { Vertical = 2 };
}
}
private partial class EditorMenuItem : DrawableOsuMenuItem
{
public EditorMenuItem(MenuItem item)
: base(item)
{
}
2018-04-13 17:19:50 +08:00
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
BackgroundColour = colourProvider.Background2;
BackgroundColourHover = colourProvider.Background1;
Foreground.Padding = new MarginPadding { Vertical = 2 };
}
}
}
}
}