mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Add support for removing colours from palette
This commit is contained in:
@ -5,6 +5,7 @@ using NUnit.Framework;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
|
using osu.Game.Graphics.Cursor;
|
||||||
using osu.Game.Graphics.UserInterfaceV2;
|
using osu.Game.Graphics.UserInterfaceV2;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
|
||||||
@ -34,17 +35,21 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
{
|
{
|
||||||
AddStep("create component", () =>
|
AddStep("create component", () =>
|
||||||
{
|
{
|
||||||
Child = new Container
|
Child = new OsuContextMenuContainer
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Origin = Anchor.Centre,
|
Child = new Container
|
||||||
Width = 500,
|
|
||||||
AutoSizeAxes = Axes.Y,
|
|
||||||
Child = component = new LabelledColourPalette
|
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = 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.
|
// 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 System;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Extensions;
|
using osu.Framework.Extensions;
|
||||||
@ -12,6 +13,7 @@ using osu.Framework.Graphics.UserInterface;
|
|||||||
using osu.Framework.Localisation;
|
using osu.Framework.Localisation;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Graphics.UserInterfaceV2
|
namespace osu.Game.Graphics.UserInterfaceV2
|
||||||
@ -19,12 +21,17 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A component which displays a colour along with related description text.
|
/// A component which displays a colour along with related description text.
|
||||||
/// </summary>
|
/// </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 readonly BindableWithCurrent<Colour4> current = new BindableWithCurrent<Colour4>();
|
||||||
|
|
||||||
private Box fill;
|
private OsuClickableContainer colourCircle;
|
||||||
private OsuSpriteText colourHexCode;
|
|
||||||
private OsuSpriteText colourName;
|
private OsuSpriteText colourName;
|
||||||
|
|
||||||
public Bindable<Colour4> Current
|
public Bindable<Colour4> Current
|
||||||
@ -63,26 +70,10 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
|||||||
Spacing = new Vector2(0, 10),
|
Spacing = new Vector2(0, 10),
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new OsuClickableContainer
|
colourCircle = new ColourCircle
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
Current = { BindTarget = Current },
|
||||||
Height = 100,
|
DeleteRequested = () => DeleteRequested?.Invoke(this)
|
||||||
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
|
|
||||||
},
|
},
|
||||||
colourName = new OsuSpriteText
|
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()
|
private readonly Box fill;
|
||||||
{
|
private readonly OsuSpriteText colourHexCode;
|
||||||
fill.Colour = current.Value;
|
|
||||||
colourHexCode.Text = current.Value.ToHex();
|
|
||||||
colourHexCode.Colour = OsuColour.ForegroundTextColourFor(current.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Popover GetPopover() => new OsuPopover(false)
|
public ColourCircle()
|
||||||
{
|
|
||||||
Child = new OsuColourPicker
|
|
||||||
{
|
{
|
||||||
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.Current.BindValueChanged(colour => Colours[colourIndex] = colour.NewValue);
|
||||||
|
display.DeleteRequested += colourDeletionRequested;
|
||||||
}
|
}
|
||||||
|
|
||||||
palette.Add(new AddColourButton
|
palette.Add(new AddColourButton
|
||||||
@ -102,6 +103,8 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
|||||||
reindexItems();
|
reindexItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void colourDeletionRequested(ColourDisplay display) => Colours.RemoveAt(palette.IndexOf(display));
|
||||||
|
|
||||||
private void reindexItems()
|
private void reindexItems()
|
||||||
{
|
{
|
||||||
int index = 1;
|
int index = 1;
|
||||||
|
Reference in New Issue
Block a user