2021-04-18 17:29:04 +00:00
|
|
|
// 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.
|
|
|
|
|
2021-07-11 18:02:39 +00:00
|
|
|
using System;
|
2021-04-18 17:29:04 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2021-06-20 18:20:46 +00:00
|
|
|
using osu.Framework.Extensions;
|
2021-04-18 17:29:04 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-06-20 18:20:46 +00:00
|
|
|
using osu.Framework.Graphics.Cursor;
|
2021-04-18 17:29:04 +00:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
using osu.Framework.Localisation;
|
2021-06-20 18:20:46 +00:00
|
|
|
using osu.Game.Graphics.Containers;
|
2021-04-18 17:29:04 +00:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2021-07-11 18:02:39 +00:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-04-18 17:29:04 +00:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterfaceV2
|
|
|
|
{
|
2021-04-19 03:37:56 +00:00
|
|
|
/// <summary>
|
|
|
|
/// A component which displays a colour along with related description text.
|
|
|
|
/// </summary>
|
2021-07-11 18:02:39 +00:00
|
|
|
public class ColourDisplay : CompositeDrawable, IHasCurrentValue<Colour4>
|
2021-04-18 17:29:04 +00:00
|
|
|
{
|
2021-07-11 18:02:39 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Invoked when the user has requested the colour corresponding to this <see cref="ColourDisplay"/>
|
|
|
|
/// to be removed from its palette.
|
|
|
|
/// </summary>
|
|
|
|
public event Action<ColourDisplay> DeleteRequested;
|
|
|
|
|
2021-06-20 17:37:09 +00:00
|
|
|
private readonly BindableWithCurrent<Colour4> current = new BindableWithCurrent<Colour4>();
|
2021-04-18 17:29:04 +00:00
|
|
|
|
|
|
|
private OsuSpriteText colourName;
|
|
|
|
|
2021-06-20 17:37:09 +00:00
|
|
|
public Bindable<Colour4> Current
|
2021-04-18 17:29:04 +00:00
|
|
|
{
|
|
|
|
get => current.Current;
|
|
|
|
set => current.Current = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
private LocalisableString name;
|
|
|
|
|
|
|
|
public LocalisableString ColourName
|
|
|
|
{
|
|
|
|
get => name;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (name == value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
name = value;
|
|
|
|
|
|
|
|
colourName.Text = name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
Width = 100;
|
|
|
|
|
|
|
|
InternalChild = new FillFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Spacing = new Vector2(0, 10),
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2021-07-31 22:11:56 +00:00
|
|
|
new ColourCircle
|
2021-04-18 17:29:04 +00:00
|
|
|
{
|
2021-07-11 18:02:39 +00:00
|
|
|
Current = { BindTarget = Current },
|
|
|
|
DeleteRequested = () => DeleteRequested?.Invoke(this)
|
2021-04-18 17:29:04 +00:00
|
|
|
},
|
|
|
|
colourName = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-07-11 18:02:39 +00:00
|
|
|
private class ColourCircle : OsuClickableContainer, IHasPopover, IHasContextMenu
|
2021-04-18 17:29:04 +00:00
|
|
|
{
|
2021-07-11 18:02:39 +00:00
|
|
|
public Bindable<Colour4> Current { get; } = new Bindable<Colour4>();
|
2021-04-18 17:29:04 +00:00
|
|
|
|
2021-07-11 18:02:39 +00:00
|
|
|
public Action DeleteRequested { get; set; }
|
2021-04-18 17:29:04 +00:00
|
|
|
|
2021-07-11 18:02:39 +00:00
|
|
|
private readonly Box fill;
|
|
|
|
private readonly OsuSpriteText colourHexCode;
|
2021-06-20 18:20:46 +00:00
|
|
|
|
2021-07-11 18:02:39 +00:00
|
|
|
public ColourCircle()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
Height = 100;
|
|
|
|
CornerRadius = 50;
|
|
|
|
Masking = true;
|
|
|
|
Action = this.ShowPopover;
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
fill = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
},
|
|
|
|
colourHexCode = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Font = OsuFont.Default.With(size: 12)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
2021-06-20 18:20:46 +00:00
|
|
|
{
|
2021-07-11 18:02:39 +00:00
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
Current.BindValueChanged(_ => updateColour(), true);
|
2021-06-20 18:20:46 +00:00
|
|
|
}
|
2021-07-11 18:02:39 +00:00
|
|
|
|
|
|
|
private void updateColour()
|
|
|
|
{
|
|
|
|
fill.Colour = Current.Value;
|
|
|
|
colourHexCode.Text = Current.Value.ToHex();
|
|
|
|
colourHexCode.Colour = OsuColour.ForegroundTextColourFor(Current.Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Popover GetPopover() => new OsuPopover(false)
|
|
|
|
{
|
|
|
|
Child = new OsuColourPicker
|
|
|
|
{
|
|
|
|
Current = { BindTarget = Current }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
public MenuItem[] ContextMenuItems => new MenuItem[]
|
|
|
|
{
|
|
|
|
new OsuMenuItem("Delete", MenuItemType.Destructive, () => DeleteRequested?.Invoke())
|
|
|
|
};
|
|
|
|
}
|
2021-04-18 17:29:04 +00:00
|
|
|
}
|
|
|
|
}
|