mirror of
https://github.com/ppy/osu.git
synced 2024-12-16 23:42:54 +08:00
Add colour customization to the layout editor
This commit is contained in:
parent
bd8addfb5f
commit
8c72feda09
@ -186,6 +186,16 @@ namespace osu.Game.Configuration
|
||||
|
||||
break;
|
||||
|
||||
case BindableColour4 bColour:
|
||||
yield return new SettingsColour
|
||||
{
|
||||
LabelText = attr.Label,
|
||||
TooltipText = attr.Description,
|
||||
Current = bColour
|
||||
};
|
||||
|
||||
break;
|
||||
|
||||
case IBindable bindable:
|
||||
var dropdownType = typeof(ModSettingsEnumDropdown<>).MakeGenericType(bindable.GetType().GetGenericArguments()[0]);
|
||||
var dropdown = (Drawable)Activator.CreateInstance(dropdownType)!;
|
||||
@ -227,6 +237,9 @@ namespace osu.Game.Configuration
|
||||
case Bindable<bool> b:
|
||||
return b.Value;
|
||||
|
||||
case BindableColour4 c:
|
||||
return c.Value.ToHex();
|
||||
|
||||
case IBindable u:
|
||||
// An unknown (e.g. enum) generic type.
|
||||
var valueMethod = u.GetType().GetProperty(nameof(IBindable<int>.Value));
|
||||
|
79
osu.Game/Overlays/Settings/SettingsColour.cs
Normal file
79
osu.Game/Overlays/Settings/SettingsColour.cs
Normal file
@ -0,0 +1,79 @@
|
||||
// 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 osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterfaceV2;
|
||||
|
||||
namespace osu.Game.Overlays.Settings
|
||||
{
|
||||
public partial class SettingsColour : SettingsItem<Colour4>
|
||||
{
|
||||
protected override Drawable CreateControl() => new ColourControl();
|
||||
|
||||
public partial class ColourControl : OsuClickableContainer, IHasPopover, IHasCurrentValue<Colour4>
|
||||
{
|
||||
private readonly BindableWithCurrent<Colour4> current = new BindableWithCurrent<Colour4>();
|
||||
|
||||
public Bindable<Colour4> Current
|
||||
{
|
||||
get => current.Current;
|
||||
set => current.Current = value;
|
||||
}
|
||||
|
||||
private readonly Box fill;
|
||||
private readonly OsuSpriteText colourHexCode;
|
||||
|
||||
public ColourControl()
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
Height = 40;
|
||||
CornerRadius = 20;
|
||||
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: 20)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
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 }
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -33,6 +33,7 @@ using osu.Game.Screens.Edit;
|
||||
using osu.Game.Screens.Edit.Components;
|
||||
using osu.Game.Screens.Edit.Components.Menus;
|
||||
using osu.Game.Skinning;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
|
||||
namespace osu.Game.Overlays.SkinEditor
|
||||
{
|
||||
@ -117,6 +118,9 @@ namespace osu.Game.Overlays.SkinEditor
|
||||
|
||||
InternalChild = new OsuContextMenuContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = new PopoverContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = new GridContainer
|
||||
{
|
||||
@ -221,6 +225,7 @@ namespace osu.Game.Overlays.SkinEditor
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
clipboardContent = clipboard.Content.GetBoundCopy();
|
||||
|
Loading…
Reference in New Issue
Block a user