mirror of
https://github.com/ppy/osu.git
synced 2025-03-19 05:57:19 +08:00
Add support for removing colours from palette
This commit is contained in:
parent
9a7537cd56
commit
3f005886d6
@ -5,6 +5,7 @@ using NUnit.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Graphics.Cursor;
|
||||
using osu.Game.Graphics.UserInterfaceV2;
|
||||
using osuTK.Graphics;
|
||||
|
||||
@ -34,17 +35,21 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
AddStep("create component", () =>
|
||||
{
|
||||
Child = new Container
|
||||
Child = new OsuContextMenuContainer
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Width = 500,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Child = component = new LabelledColourPalette
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = new Container
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
ColourNamePrefix = "My colour #"
|
||||
Width = 500,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Child = component = new LabelledColourPalette
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
ColourNamePrefix = "My colour #"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
// 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;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions;
|
||||
@ -12,6 +13,7 @@ using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterfaceV2
|
||||
@ -19,12 +21,17 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
/// <summary>
|
||||
/// A component which displays a colour along with related description text.
|
||||
/// </summary>
|
||||
public class ColourDisplay : CompositeDrawable, IHasCurrentValue<Colour4>, IHasPopover
|
||||
public class ColourDisplay : CompositeDrawable, IHasCurrentValue<Colour4>
|
||||
{
|
||||
/// <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;
|
||||
|
||||
private readonly BindableWithCurrent<Colour4> current = new BindableWithCurrent<Colour4>();
|
||||
|
||||
private Box fill;
|
||||
private OsuSpriteText colourHexCode;
|
||||
private OsuClickableContainer colourCircle;
|
||||
private OsuSpriteText colourName;
|
||||
|
||||
public Bindable<Colour4> Current
|
||||
@ -63,26 +70,10 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
Spacing = new Vector2(0, 10),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new OsuClickableContainer
|
||||
colourCircle = new ColourCircle
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = 100,
|
||||
CornerRadius = 50,
|
||||
Masking = true,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
fill = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both
|
||||
},
|
||||
colourHexCode = new OsuSpriteText
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Font = OsuFont.Default.With(size: 12)
|
||||
}
|
||||
},
|
||||
Action = this.ShowPopover
|
||||
Current = { BindTarget = Current },
|
||||
DeleteRequested = () => DeleteRequested?.Invoke(this)
|
||||
},
|
||||
colourName = new OsuSpriteText
|
||||
{
|
||||
@ -93,26 +84,64 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
};
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
private class ColourCircle : OsuClickableContainer, IHasPopover, IHasContextMenu
|
||||
{
|
||||
base.LoadComplete();
|
||||
public Bindable<Colour4> Current { get; } = new Bindable<Colour4>();
|
||||
|
||||
current.BindValueChanged(_ => updateColour(), true);
|
||||
}
|
||||
public Action DeleteRequested { get; set; }
|
||||
|
||||
private void updateColour()
|
||||
{
|
||||
fill.Colour = current.Value;
|
||||
colourHexCode.Text = current.Value.ToHex();
|
||||
colourHexCode.Colour = OsuColour.ForegroundTextColourFor(current.Value);
|
||||
}
|
||||
private readonly Box fill;
|
||||
private readonly OsuSpriteText colourHexCode;
|
||||
|
||||
public Popover GetPopover() => new OsuPopover(false)
|
||||
{
|
||||
Child = new OsuColourPicker
|
||||
public ColourCircle()
|
||||
{
|
||||
Current = { BindTarget = Current }
|
||||
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()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
Current.BindValueChanged(_ => updateColour(), true);
|
||||
}
|
||||
|
||||
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())
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -92,6 +92,7 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
});
|
||||
|
||||
display.Current.BindValueChanged(colour => Colours[colourIndex] = colour.NewValue);
|
||||
display.DeleteRequested += colourDeletionRequested;
|
||||
}
|
||||
|
||||
palette.Add(new AddColourButton
|
||||
@ -102,6 +103,8 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
reindexItems();
|
||||
}
|
||||
|
||||
private void colourDeletionRequested(ColourDisplay display) => Colours.RemoveAt(palette.IndexOf(display));
|
||||
|
||||
private void reindexItems()
|
||||
{
|
||||
int index = 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user