diff --git a/osu.Game/Overlays/OverlayHeaderTabControl.cs b/osu.Game/Overlays/OverlayHeaderTabControl.cs index dfe7e52420..b2c5fb8f2a 100644 --- a/osu.Game/Overlays/OverlayHeaderTabControl.cs +++ b/osu.Game/Overlays/OverlayHeaderTabControl.cs @@ -1,153 +1,28 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using osu.Framework.Graphics; -using osu.Framework.Graphics.Shapes; +using osu.Framework.Allocation; using osu.Framework.Graphics.UserInterface; -using osu.Framework.Input.Events; using osu.Game.Graphics; -using osu.Game.Graphics.Sprites; -using osu.Game.Graphics.UserInterface; -using osuTK; -using osuTK.Graphics; namespace osu.Game.Overlays { - public class OverlayHeaderTabControl : TabControl + public class OverlayHeaderTabControl : OverlayTabControl { - private readonly Box bar; + protected override TabItem CreateTabItem(string value) => new OverlayHeaderTabItem(value); - private Color4 accentColour = Color4.White; - - public Color4 AccentColour + [BackgroundDependencyLoader] + private void load(OsuColour colours) { - get => accentColour; - set - { - if (accentColour == value) - return; - - accentColour = value; - bar.Colour = value; - - foreach (TabItem tabItem in TabContainer) - { - ((HeaderTabItem)tabItem).AccentColour = value; - } - } + AccentColour = colours.Seafoam; } - public new MarginPadding Padding + private class OverlayHeaderTabItem : OverlayTabItem { - get => TabContainer.Padding; - set => TabContainer.Padding = value; - } - - public OverlayHeaderTabControl() - { - TabContainer.Masking = false; - TabContainer.Spacing = new Vector2(15, 0); - - AddInternal(bar = new Box - { - RelativeSizeAxes = Axes.X, - Height = 2, - Anchor = Anchor.BottomLeft, - Origin = Anchor.CentreLeft - }); - } - - protected override Dropdown CreateDropdown() => null; - - protected override TabItem CreateTabItem(string value) => new HeaderTabItem(value) - { - AccentColour = AccentColour - }; - - private class HeaderTabItem : TabItem - { - private readonly OsuSpriteText text; - private readonly ExpandingBar bar; - - private Color4 accentColour; - - public Color4 AccentColour - { - get => accentColour; - set - { - if (accentColour == value) - return; - - accentColour = value; - bar.Colour = value; - - updateState(); - } - } - - public HeaderTabItem(string value) + public OverlayHeaderTabItem(string value) : base(value) { - AutoSizeAxes = Axes.X; - RelativeSizeAxes = Axes.Y; - - Children = new Drawable[] - { - text = new OsuSpriteText - { - Margin = new MarginPadding { Bottom = 10 }, - Origin = Anchor.BottomLeft, - Anchor = Anchor.BottomLeft, - Text = value, - Font = OsuFont.GetFont() - }, - bar = new ExpandingBar - { - Anchor = Anchor.BottomCentre, - ExpandedSize = 7.5f, - CollapsedSize = 0 - }, - new HoverClickSounds() - }; - } - - protected override bool OnHover(HoverEvent e) - { - base.OnHover(e); - - updateState(); - - return true; - } - - protected override void OnHoverLost(HoverLostEvent e) - { - base.OnHoverLost(e); - - updateState(); - } - - protected override void OnActivated() => updateState(); - - protected override void OnDeactivated() => updateState(); - - private void updateState() - { - if (Active.Value || IsHovered) - { - text.FadeColour(Color4.White, 120, Easing.InQuad); - bar.Expand(); - - if (Active.Value) - text.Font = text.Font.With(weight: FontWeight.Bold); - } - else - { - text.FadeColour(AccentColour, 120, Easing.InQuad); - bar.Collapse(); - text.Font = text.Font.With(weight: FontWeight.Medium); - } + Text.Text = value; } } } diff --git a/osu.Game/Overlays/OverlayTabControl.cs b/osu.Game/Overlays/OverlayTabControl.cs new file mode 100644 index 0000000000..8fd53e0f36 --- /dev/null +++ b/osu.Game/Overlays/OverlayTabControl.cs @@ -0,0 +1,153 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.UserInterface; +using osu.Framework.Input.Events; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; +using osu.Game.Graphics.UserInterface; +using osuTK; +using osuTK.Graphics; + +namespace osu.Game.Overlays +{ + public abstract class OverlayTabControl : TabControl + { + private readonly Box bar; + + private Color4 accentColour = Color4.White; + + public Color4 AccentColour + { + get => accentColour; + set + { + if (accentColour == value) + return; + + accentColour = value; + bar.Colour = value; + + foreach (TabItem tabItem in TabContainer) + { + ((OverlayTabItem)tabItem).AccentColour = value; + } + } + } + + public new MarginPadding Padding + { + get => TabContainer.Padding; + set => TabContainer.Padding = value; + } + + protected OverlayTabControl() + { + TabContainer.Masking = false; + TabContainer.Spacing = new Vector2(15, 0); + + AddInternal(bar = new Box + { + RelativeSizeAxes = Axes.X, + Height = 2, + Anchor = Anchor.BottomLeft, + Origin = Anchor.CentreLeft + }); + } + + protected override Dropdown CreateDropdown() => null; + + protected override TabItem CreateTabItem(T value) => new OverlayTabItem(value); + + protected class OverlayTabItem : TabItem + { + private readonly ExpandingBar bar; + + protected readonly OsuSpriteText Text; + + private Color4 accentColour; + + public Color4 AccentColour + { + get => accentColour; + set + { + if (accentColour == value) + return; + + accentColour = value; + bar.Colour = value; + + updateState(); + } + } + + public OverlayTabItem(U value) + : base(value) + { + AutoSizeAxes = Axes.X; + RelativeSizeAxes = Axes.Y; + + Children = new Drawable[] + { + Text = new OsuSpriteText + { + Margin = new MarginPadding { Bottom = 10 }, + Origin = Anchor.BottomLeft, + Anchor = Anchor.BottomLeft, + Font = OsuFont.GetFont(), + }, + bar = new ExpandingBar + { + Anchor = Anchor.BottomCentre, + ExpandedSize = 7.5f, + CollapsedSize = 0 + }, + new HoverClickSounds() + }; + } + + protected override bool OnHover(HoverEvent e) + { + base.OnHover(e); + + if (!Active.Value) + OnActivated(); + + return true; + } + + protected override void OnHoverLost(HoverLostEvent e) + { + base.OnHoverLost(e); + + if (!Active.Value) + OnDeactivated(); + } + + protected override void OnActivated() + { + bar.Expand(); + Text.FadeColour(Color4.White, 120, Easing.InQuad); + Text.Font = Text.Font.With(weight: FontWeight.Bold); + } + + protected override void OnDeactivated() + { + bar.Collapse(); + Text.FadeColour(AccentColour, 120, Easing.InQuad); + Text.Font = Text.Font.With(weight: FontWeight.Medium); + } + + private void updateState() + { + if (Active.Value) + OnActivated(); + else + OnDeactivated(); + } + } + } +} diff --git a/osu.Game/Overlays/Profile/ProfileHeader.cs b/osu.Game/Overlays/Profile/ProfileHeader.cs index 76613c156d..90f51a90a6 100644 --- a/osu.Game/Overlays/Profile/ProfileHeader.cs +++ b/osu.Game/Overlays/Profile/ProfileHeader.cs @@ -34,12 +34,6 @@ namespace osu.Game.Overlays.Profile centreHeaderContainer.DetailsVisible.BindValueChanged(visible => detailHeaderContainer.Expanded = visible.NewValue, true); } - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - TabControl.AccentColour = colours.Seafoam; - } - protected override Drawable CreateBackground() => new Container {