mirror of
https://github.com/ppy/osu.git
synced 2025-03-11 15:27:20 +08:00
Decouple editor main menu items from DrawableOsuMenuItem
It didn't ever really make sense for it to be sharing the implementation details of that (e.g. colouring of primary/dangerous actions), and with the hotkey display things got outright hacky, so I'm decoupling it entirely.
This commit is contained in:
parent
3acc5fe5a0
commit
0c4f5bcdaa
@ -13,6 +13,7 @@ using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Screens.Edit;
|
||||
using osu.Game.Screens.Edit.Components.Menus;
|
||||
using osu.Game.Storyboards;
|
||||
using osu.Game.Tests.Beatmaps.IO;
|
||||
using osuTK.Input;
|
||||
@ -60,7 +61,7 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
beatmapSetHashBefore = Beatmap.Value.BeatmapSetInfo.Hash;
|
||||
});
|
||||
|
||||
AddStep("click File", () => this.ChildrenOfType<DrawableOsuMenuItem>().First().TriggerClick());
|
||||
AddStep("click File", () => this.ChildrenOfType<EditorMenuBar.DrawableEditorBarMenuItem>().First().TriggerClick());
|
||||
|
||||
if (i == 11)
|
||||
{
|
||||
@ -107,7 +108,7 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
EditorBeatmap.EndChange();
|
||||
});
|
||||
|
||||
AddStep("click File", () => this.ChildrenOfType<DrawableOsuMenuItem>().First().TriggerClick());
|
||||
AddStep("click File", () => this.ChildrenOfType<EditorMenuBar.DrawableEditorBarMenuItem>().First().TriggerClick());
|
||||
|
||||
AddStep("click delete", () => getDeleteMenuItem().TriggerClick());
|
||||
AddUntilStep("wait for dialog", () => DialogOverlay.CurrentDialog != null);
|
||||
|
@ -23,10 +23,10 @@ namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
public const int MARGIN_HORIZONTAL = 10;
|
||||
public const int MARGIN_VERTICAL = 4;
|
||||
private const int text_size = 17;
|
||||
private const int transition_length = 80;
|
||||
public const int TEXT_SIZE = 17;
|
||||
public const int TRANSITION_LENGTH = 80;
|
||||
|
||||
protected TextContainer Text { get; private set; }
|
||||
private TextContainer text;
|
||||
private HotkeyDisplay hotkey;
|
||||
private HoverClickSounds hoverClickSounds;
|
||||
|
||||
@ -84,15 +84,15 @@ namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
default:
|
||||
case MenuItemType.Standard:
|
||||
Text.Colour = Color4.White;
|
||||
text.Colour = Color4.White;
|
||||
break;
|
||||
|
||||
case MenuItemType.Destructive:
|
||||
Text.Colour = Color4.Red;
|
||||
text.Colour = Color4.Red;
|
||||
break;
|
||||
|
||||
case MenuItemType.Highlighted:
|
||||
Text.Colour = Color4Extensions.FromHex(@"ffcc22");
|
||||
text.Colour = Color4Extensions.FromHex(@"ffcc22");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
// the gist of it is that while the hotkey display is not in the text / "content" that determines sizing
|
||||
// (because it cannot be, because we want the hotkey display to align to the *right* and not the left),
|
||||
// enough padding to fit the hotkey with _its_ spacing is added as padding of the text to compensate.
|
||||
Text.Padding = new MarginPadding { Right = hotkey.Alpha > 0 || showChevron ? hotkey.DrawWidth + 15 : 0 };
|
||||
text.Padding = new MarginPadding { Right = hotkey.Alpha > 0 || showChevron ? hotkey.DrawWidth + 15 : 0 };
|
||||
}
|
||||
|
||||
protected override bool OnHover(HoverEvent e)
|
||||
@ -130,17 +130,17 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
if (IsHovered && IsActionable)
|
||||
{
|
||||
Text.BoldText.FadeIn(transition_length, Easing.OutQuint);
|
||||
Text.NormalText.FadeOut(transition_length, Easing.OutQuint);
|
||||
text.BoldText.FadeIn(TRANSITION_LENGTH, Easing.OutQuint);
|
||||
text.NormalText.FadeOut(TRANSITION_LENGTH, Easing.OutQuint);
|
||||
}
|
||||
else
|
||||
{
|
||||
Text.BoldText.FadeOut(transition_length, Easing.OutQuint);
|
||||
Text.NormalText.FadeIn(transition_length, Easing.OutQuint);
|
||||
text.BoldText.FadeOut(TRANSITION_LENGTH, Easing.OutQuint);
|
||||
text.NormalText.FadeIn(TRANSITION_LENGTH, Easing.OutQuint);
|
||||
}
|
||||
}
|
||||
|
||||
protected sealed override Drawable CreateContent() => Text = CreateTextContainer();
|
||||
protected sealed override Drawable CreateContent() => text = CreateTextContainer();
|
||||
protected virtual TextContainer CreateTextContainer() => new TextContainer();
|
||||
|
||||
protected partial class TextContainer : Container, IHasText
|
||||
@ -192,7 +192,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
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: text_size),
|
||||
Font = OsuFont.GetFont(size: TEXT_SIZE),
|
||||
},
|
||||
BoldText = new OsuSpriteText
|
||||
{
|
||||
@ -200,7 +200,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
Alpha = 0,
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold),
|
||||
Font = OsuFont.GetFont(size: TEXT_SIZE, weight: FontWeight.Bold),
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -7,7 +7,10 @@ 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;
|
||||
using osuTK;
|
||||
@ -78,8 +81,11 @@ namespace osu.Game.Screens.Edit.Components.Menus
|
||||
|
||||
protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item) => new DrawableEditorBarMenuItem(item);
|
||||
|
||||
private partial class DrawableEditorBarMenuItem : DrawableOsuMenuItem
|
||||
internal partial class DrawableEditorBarMenuItem : DrawableMenuItem
|
||||
{
|
||||
private HoverClickSounds hoverClickSounds = null!;
|
||||
private TextContainer text = null!;
|
||||
|
||||
public DrawableEditorBarMenuItem(MenuItem item)
|
||||
: base(item)
|
||||
{
|
||||
@ -92,7 +98,8 @@ namespace osu.Game.Screens.Edit.Components.Menus
|
||||
BackgroundColour = colourProvider.Background2;
|
||||
ForegroundColourHover = colourProvider.Content1;
|
||||
BackgroundColourHover = colourProvider.Background1;
|
||||
Text.CheckboxContainer.Alpha = 0;
|
||||
|
||||
AddInternal(hoverClickSounds = new HoverClickSounds());
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
@ -101,6 +108,36 @@ namespace osu.Game.Screens.Edit.Components.Menus
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void UpdateBackgroundColour()
|
||||
@ -119,16 +156,56 @@ namespace osu.Game.Screens.Edit.Components.Menus
|
||||
base.UpdateForegroundColour();
|
||||
}
|
||||
|
||||
protected override DrawableOsuMenuItem.TextContainer CreateTextContainer() => new TextContainer();
|
||||
protected sealed override Drawable CreateContent() => text = new TextContainer();
|
||||
}
|
||||
|
||||
private new partial class TextContainer : DrawableOsuMenuItem.TextContainer
|
||||
private partial class TextContainer : Container, IHasText
|
||||
{
|
||||
public LocalisableString Text
|
||||
{
|
||||
public TextContainer()
|
||||
get => NormalText.Text;
|
||||
set
|
||||
{
|
||||
NormalText.Font = OsuFont.TorusAlternate;
|
||||
BoldText.Font = OsuFont.TorusAlternate.With(weight: FontWeight.Bold);
|
||||
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),
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private partial class SubMenu : OsuMenu
|
||||
|
Loading…
x
Reference in New Issue
Block a user