Add placeholder when no colours are visible

Will be removed once combo colours are mutable.
This commit is contained in:
Bartłomiej Dach 2021-04-18 20:15:30 +02:00
parent 0cd1aa8c1c
commit 577755ee19
2 changed files with 41 additions and 8 deletions

View File

@ -20,13 +20,14 @@ namespace osu.Game.Tests.Visual.UserInterface
createColourPalette(hasDescription);
AddRepeatStep("add random colour", () => component.Colours.Add(randomColour()), 4);
AddStep("set custom prefix", () => component.ColourNamePrefix = "Combo");
AddRepeatStep("remove random colour", () =>
{
if (component.Colours.Count > 0)
component.Colours.RemoveAt(RNG.Next(component.Colours.Count));
}, 5);
AddStep("set custom prefix", () => component.ColourNamePrefix = "Combo");
}, 8);
}
private void createColourPalette(bool hasDescription = false)

View File

@ -1,10 +1,12 @@
// 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 System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osuTK;
using osuTK.Graphics;
@ -32,6 +34,7 @@ namespace osu.Game.Graphics.UserInterfaceV2
}
private FillFlowContainer<ColourDisplay> palette;
private Container placeholder;
[BackgroundDependencyLoader]
private void load()
@ -39,12 +42,27 @@ namespace osu.Game.Graphics.UserInterfaceV2
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
InternalChild = palette = new FillFlowContainer<ColourDisplay>
InternalChildren = new Drawable[]
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Spacing = new Vector2(10),
Direction = FillDirection.Full
palette = new FillFlowContainer<ColourDisplay>
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Spacing = new Vector2(10),
Direction = FillDirection.Full
},
placeholder = new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Child = new OsuSpriteText
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Text = "(none)",
Font = OsuFont.Default.With(weight: FontWeight.Bold)
}
}
};
}
@ -53,12 +71,26 @@ namespace osu.Game.Graphics.UserInterfaceV2
base.LoadComplete();
Colours.BindCollectionChanged((_, __) => updatePalette(), true);
FinishTransforms(true);
}
private const int fade_duration = 200;
private void updatePalette()
{
palette.Clear();
if (Colours.Any())
{
palette.FadeIn(fade_duration, Easing.OutQuint);
placeholder.FadeOut(fade_duration, Easing.OutQuint);
}
else
{
palette.FadeOut(fade_duration, Easing.OutQuint);
placeholder.FadeIn(fade_duration, Easing.OutQuint);
}
foreach (var item in Colours)
{
palette.Add(new ColourDisplay