mirror of
https://github.com/ppy/osu.git
synced 2025-02-23 02:25:12 +08:00
Cleanup OsuTabControl.AccentColour
This commit is contained in:
parent
87af482823
commit
bf2b71f7dd
@ -17,12 +17,19 @@ using osu.Framework.Graphics.UserInterface;
|
|||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
|
||||||
|
|
||||||
namespace osu.Game.Graphics.UserInterface
|
namespace osu.Game.Graphics.UserInterface
|
||||||
{
|
{
|
||||||
public class OsuTabControl<T> : TabControl<T>
|
public class OsuTabControl<T> : TabControl<T>
|
||||||
{
|
{
|
||||||
|
private readonly Bindable<Color4> accentColour = new Bindable<Color4>();
|
||||||
|
|
||||||
|
public Color4 AccentColour
|
||||||
|
{
|
||||||
|
get => accentColour.Value;
|
||||||
|
set => accentColour.Value = value;
|
||||||
|
}
|
||||||
|
|
||||||
private readonly Box strip;
|
private readonly Box strip;
|
||||||
|
|
||||||
protected override Dropdown<T> CreateDropdown() => new OsuTabDropdown();
|
protected override Dropdown<T> CreateDropdown() => new OsuTabDropdown();
|
||||||
@ -60,24 +67,22 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours)
|
private void load(OsuColour colours)
|
||||||
{
|
{
|
||||||
if (accentColour == default)
|
if (accentColour.Value == default)
|
||||||
AccentColour = colours.Blue;
|
AccentColour = colours.Blue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Color4 accentColour;
|
protected override void LoadComplete()
|
||||||
|
|
||||||
public Color4 AccentColour
|
|
||||||
{
|
{
|
||||||
get => accentColour;
|
base.LoadComplete();
|
||||||
set
|
accentColour.BindValueChanged(OnAccentColourChanged, true);
|
||||||
{
|
|
||||||
accentColour = value;
|
|
||||||
if (Dropdown is IHasAccentColour dropdown)
|
|
||||||
dropdown.AccentColour = value;
|
|
||||||
foreach (var i in TabContainer.Children.OfType<IHasAccentColour>())
|
|
||||||
i.AccentColour = value;
|
|
||||||
InternalChildren.OfType<IHasAccentColour>().ForEach(c => c.AccentColour = value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual void OnAccentColourChanged(ValueChangedEvent<Color4> colour)
|
||||||
|
{
|
||||||
|
if (Dropdown is IHasAccentColour dropdown)
|
||||||
|
dropdown.AccentColour = colour.NewValue;
|
||||||
|
foreach (var i in TabContainer.Children.OfType<IHasAccentColour>())
|
||||||
|
i.AccentColour = colour.NewValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Color4 StripColour
|
public Color4 StripColour
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Graphics.UserInterface;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
@ -16,7 +16,7 @@ namespace osu.Game.Overlays
|
|||||||
{
|
{
|
||||||
public abstract class OverlayTabControl<T> : OsuTabControl<T>
|
public abstract class OverlayTabControl<T> : OsuTabControl<T>
|
||||||
{
|
{
|
||||||
private readonly TabControlBar bar;
|
private readonly Box bar;
|
||||||
|
|
||||||
protected float BarHeight
|
protected float BarHeight
|
||||||
{
|
{
|
||||||
@ -28,7 +28,7 @@ namespace osu.Game.Overlays
|
|||||||
TabContainer.Masking = false;
|
TabContainer.Masking = false;
|
||||||
TabContainer.Spacing = new Vector2(15, 0);
|
TabContainer.Spacing = new Vector2(15, 0);
|
||||||
|
|
||||||
AddInternal(bar = new TabControlBar
|
AddInternal(bar = new Box
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Height = 2,
|
Height = 2,
|
||||||
@ -37,6 +37,12 @@ namespace osu.Game.Overlays
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnAccentColourChanged(ValueChangedEvent<Color4> colour)
|
||||||
|
{
|
||||||
|
base.OnAccentColourChanged(colour);
|
||||||
|
bar.Colour = colour.NewValue;
|
||||||
|
}
|
||||||
|
|
||||||
protected override Dropdown<T> CreateDropdown() => null;
|
protected override Dropdown<T> CreateDropdown() => null;
|
||||||
|
|
||||||
protected override TabItem<T> CreateTabItem(T value) => new OverlayTabItem(value);
|
protected override TabItem<T> CreateTabItem(T value) => new OverlayTabItem(value);
|
||||||
@ -138,24 +144,5 @@ namespace osu.Game.Overlays
|
|||||||
Text.FadeColour(AccentColour, 120, Easing.InQuad);
|
Text.FadeColour(AccentColour, 120, Easing.InQuad);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TabControlBar : CompositeDrawable, IHasAccentColour
|
|
||||||
{
|
|
||||||
public Color4 AccentColour
|
|
||||||
{
|
|
||||||
get => background.Colour;
|
|
||||||
set => background.Colour = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly Box background;
|
|
||||||
|
|
||||||
public TabControlBar()
|
|
||||||
{
|
|
||||||
AddInternal(background = new Box
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user