mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 01:43:20 +08:00
Refactor OverlayHeader hierarchy
This commit is contained in:
parent
178a72f9b8
commit
30edd80c8c
@ -22,7 +22,6 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||
{
|
||||
typeof(OverlayHeader),
|
||||
typeof(ControllableOverlayHeader<>),
|
||||
typeof(TabControlOverlayHeader<>),
|
||||
typeof(BreadcrumbControlOverlayHeader),
|
||||
typeof(TestNoControlHeader),
|
||||
@ -139,9 +138,9 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
public TestBreadcrumbControlHeader(OverlayColourScheme colourScheme)
|
||||
: base(colourScheme)
|
||||
{
|
||||
BreadcrumbControl.AddItem("tab1");
|
||||
BreadcrumbControl.AddItem("tab2");
|
||||
BreadcrumbControl.Current.Value = "tab2";
|
||||
TabControl.AddItem("tab1");
|
||||
TabControl.AddItem("tab2");
|
||||
TabControl.Current.Value = "tab2";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
@ -75,6 +76,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
dropdown.AccentColour = value;
|
||||
foreach (var i in TabContainer.Children.OfType<IHasAccentColour>())
|
||||
i.AccentColour = value;
|
||||
InternalChildren.OfType<IHasAccentColour>().ForEach(c => c.AccentColour = value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
// 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.
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Game.Graphics;
|
||||
@ -9,23 +8,15 @@ using osu.Game.Graphics.UserInterface;
|
||||
|
||||
namespace osu.Game.Overlays
|
||||
{
|
||||
public abstract class BreadcrumbControlOverlayHeader : ControllableOverlayHeader<string>
|
||||
public abstract class BreadcrumbControlOverlayHeader : TabControlOverlayHeader<string>
|
||||
{
|
||||
protected OverlayHeaderBreadcrumbControl BreadcrumbControl;
|
||||
|
||||
protected override TabControl<string> CreateTabControl() => BreadcrumbControl = new OverlayHeaderBreadcrumbControl();
|
||||
protected override OsuTabControl<string> CreateTabControl() => new OverlayHeaderBreadcrumbControl();
|
||||
|
||||
protected BreadcrumbControlOverlayHeader(OverlayColourScheme colourScheme)
|
||||
: base(colourScheme)
|
||||
{
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
BreadcrumbControl.AccentColour = colours.ForOverlayElement(ColourScheme, 1, 0.75f);
|
||||
}
|
||||
|
||||
public class OverlayHeaderBreadcrumbControl : BreadcrumbControl<string>
|
||||
{
|
||||
public OverlayHeaderBreadcrumbControl()
|
||||
|
@ -28,8 +28,8 @@ namespace osu.Game.Overlays.Changelog
|
||||
public ChangelogHeader()
|
||||
: base(OverlayColourScheme.Purple)
|
||||
{
|
||||
BreadcrumbControl.AddItem(listing_string);
|
||||
BreadcrumbControl.Current.ValueChanged += e =>
|
||||
TabControl.AddItem(listing_string);
|
||||
TabControl.Current.ValueChanged += e =>
|
||||
{
|
||||
if (e.NewValue == listing_string)
|
||||
ListingSelected?.Invoke();
|
||||
@ -49,12 +49,12 @@ namespace osu.Game.Overlays.Changelog
|
||||
private void showBuild(ValueChangedEvent<APIChangelogBuild> e)
|
||||
{
|
||||
if (e.OldValue != null)
|
||||
BreadcrumbControl.RemoveItem(e.OldValue.ToString());
|
||||
TabControl.RemoveItem(e.OldValue.ToString());
|
||||
|
||||
if (e.NewValue != null)
|
||||
{
|
||||
BreadcrumbControl.AddItem(e.NewValue.ToString());
|
||||
BreadcrumbControl.Current.Value = e.NewValue.ToString();
|
||||
TabControl.AddItem(e.NewValue.ToString());
|
||||
TabControl.Current.Value = e.NewValue.ToString();
|
||||
|
||||
Streams.Current.Value = Streams.Items.FirstOrDefault(s => s.Name == e.NewValue.UpdateStream.Name);
|
||||
|
||||
@ -62,7 +62,7 @@ namespace osu.Game.Overlays.Changelog
|
||||
}
|
||||
else
|
||||
{
|
||||
BreadcrumbControl.Current.Value = listing_string;
|
||||
TabControl.Current.Value = listing_string;
|
||||
Streams.Current.Value = null;
|
||||
title.Version = null;
|
||||
}
|
||||
|
@ -1,49 +0,0 @@
|
||||
// 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.
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Game.Graphics;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Overlays
|
||||
{
|
||||
/// <summary>
|
||||
/// <see cref="OverlayHeader"/> which contains <see cref="TabControl{T}"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of item to be represented by tabs in <see cref="TabControl{T}"/>.</typeparam>
|
||||
public abstract class ControllableOverlayHeader<T> : OverlayHeader
|
||||
{
|
||||
private readonly Box controlBackground;
|
||||
|
||||
protected ControllableOverlayHeader(OverlayColourScheme colourScheme)
|
||||
: base(colourScheme)
|
||||
{
|
||||
HeaderInfo.Add(new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
controlBackground = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4.Gray,
|
||||
},
|
||||
CreateTabControl().With(control => control.Margin = new MarginPadding { Left = UserProfileOverlay.CONTENT_X_MARGIN })
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
controlBackground.Colour = colours.ForOverlayElement(ColourScheme, 0.2f, 0.2f);
|
||||
}
|
||||
|
||||
protected abstract TabControl<T> CreateTabControl();
|
||||
}
|
||||
}
|
@ -25,9 +25,9 @@ namespace osu.Game.Overlays.News
|
||||
public NewsHeader()
|
||||
: base(OverlayColourScheme.Purple)
|
||||
{
|
||||
BreadcrumbControl.AddItem(front_page_string);
|
||||
TabControl.AddItem(front_page_string);
|
||||
|
||||
BreadcrumbControl.Current.ValueChanged += e =>
|
||||
TabControl.Current.ValueChanged += e =>
|
||||
{
|
||||
if (e.NewValue == front_page_string)
|
||||
ShowFrontPage?.Invoke();
|
||||
@ -39,18 +39,18 @@ namespace osu.Game.Overlays.News
|
||||
private void showPost(ValueChangedEvent<string> e)
|
||||
{
|
||||
if (e.OldValue != null)
|
||||
BreadcrumbControl.RemoveItem(e.OldValue);
|
||||
TabControl.RemoveItem(e.OldValue);
|
||||
|
||||
if (e.NewValue != null)
|
||||
{
|
||||
BreadcrumbControl.AddItem(e.NewValue);
|
||||
BreadcrumbControl.Current.Value = e.NewValue;
|
||||
TabControl.AddItem(e.NewValue);
|
||||
TabControl.Current.Value = e.NewValue;
|
||||
|
||||
title.IsReadingPost = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
BreadcrumbControl.Current.Value = front_page_string;
|
||||
TabControl.Current.Value = front_page_string;
|
||||
title.IsReadingPost = false;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Input.Events;
|
||||
@ -15,13 +16,7 @@ namespace osu.Game.Overlays
|
||||
{
|
||||
public abstract class OverlayTabControl<T> : OsuTabControl<T>
|
||||
{
|
||||
private readonly Box bar;
|
||||
|
||||
public new Color4 AccentColour
|
||||
{
|
||||
get => base.AccentColour;
|
||||
set => base.AccentColour = bar.Colour = value;
|
||||
}
|
||||
private readonly Bar bar;
|
||||
|
||||
protected float BarHeight
|
||||
{
|
||||
@ -33,7 +28,7 @@ namespace osu.Game.Overlays
|
||||
TabContainer.Masking = false;
|
||||
TabContainer.Spacing = new Vector2(15, 0);
|
||||
|
||||
AddInternal(bar = new Box
|
||||
AddInternal(bar = new Bar
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = 2,
|
||||
@ -143,5 +138,24 @@ namespace osu.Game.Overlays
|
||||
Text.FadeColour(AccentColour, 120, Easing.InQuad);
|
||||
}
|
||||
}
|
||||
|
||||
private class Bar : CompositeDrawable, IHasAccentColour
|
||||
{
|
||||
public Color4 AccentColour
|
||||
{
|
||||
get => background.Colour;
|
||||
set => background.Colour = value;
|
||||
}
|
||||
|
||||
private readonly Box background;
|
||||
|
||||
public Bar()
|
||||
{
|
||||
AddInternal(background = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,29 +5,51 @@ using System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Overlays
|
||||
{
|
||||
public abstract class TabControlOverlayHeader<T> : ControllableOverlayHeader<T>
|
||||
/// <summary>
|
||||
/// <see cref="OverlayHeader"/> which contains <see cref="OsuTabControl{T}"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of item to be represented by tabs in <see cref="OsuTabControl{T}"/>.</typeparam>
|
||||
public abstract class TabControlOverlayHeader<T> : OverlayHeader
|
||||
{
|
||||
protected OverlayHeaderTabControl TabControl;
|
||||
protected OsuTabControl<T> TabControl;
|
||||
|
||||
protected override TabControl<T> CreateTabControl() => TabControl = new OverlayHeaderTabControl();
|
||||
private readonly Box controlBackground;
|
||||
|
||||
protected TabControlOverlayHeader(OverlayColourScheme colourScheme)
|
||||
: base(colourScheme)
|
||||
{
|
||||
HeaderInfo.Add(new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
controlBackground = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
TabControl = CreateTabControl().With(control => control.Margin = new MarginPadding { Left = UserProfileOverlay.CONTENT_X_MARGIN })
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
TabControl.AccentColour = colours.ForOverlayElement(ColourScheme, 1, 0.75f);
|
||||
controlBackground.Colour = colours.ForOverlayElement(ColourScheme, 0.2f, 0.2f);
|
||||
}
|
||||
|
||||
protected virtual OsuTabControl<T> CreateTabControl() => new OverlayHeaderTabControl();
|
||||
|
||||
public class OverlayHeaderTabControl : OverlayTabControl<T>
|
||||
{
|
||||
public OverlayHeaderTabControl()
|
||||
@ -38,18 +60,9 @@ namespace osu.Game.Overlays
|
||||
Anchor = Anchor.BottomLeft;
|
||||
Origin = Anchor.BottomLeft;
|
||||
Height = 35;
|
||||
|
||||
if (typeof(T).IsEnum)
|
||||
{
|
||||
foreach (var val in (T[])Enum.GetValues(typeof(T)))
|
||||
AddItem(val);
|
||||
}
|
||||
}
|
||||
|
||||
protected override TabItem<T> CreateTabItem(T value) => new OverlayHeaderTabItem(value)
|
||||
{
|
||||
AccentColour = AccentColour,
|
||||
};
|
||||
protected override TabItem<T> CreateTabItem(T value) => new OverlayHeaderTabItem(value);
|
||||
|
||||
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user