2019-01-24 16:43:03 +08: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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-11-30 14:43:19 +08:00
|
|
|
using System;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
using osu.Framework.Graphics;
|
2021-07-17 01:30:13 +08:00
|
|
|
using osu.Framework.Graphics.Cursor;
|
2017-11-30 14:43:19 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2021-07-17 01:30:13 +08:00
|
|
|
using osu.Framework.Localisation;
|
2017-11-30 14:43:19 +08:00
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2022-10-13 15:33:09 +08:00
|
|
|
using osu.Game.Overlays;
|
2018-11-20 15:51:59 +08:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-11-06 17:14:46 +08:00
|
|
|
namespace osu.Game.Screens.Edit.Components.RadioButtons
|
2017-11-30 14:43:19 +08:00
|
|
|
{
|
2021-07-19 15:57:12 +08:00
|
|
|
public partial class EditorRadioButton : OsuButton, IHasTooltip
|
2017-11-30 14:43:19 +08:00
|
|
|
{
|
|
|
|
/// <summary>
|
2021-07-19 15:57:12 +08:00
|
|
|
/// Invoked when this <see cref="EditorRadioButton"/> has been selected.
|
2017-11-30 14:43:19 +08:00
|
|
|
/// </summary>
|
2023-01-12 23:07:54 +08:00
|
|
|
public Action<RadioButton>? Selected;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2021-07-17 01:30:13 +08:00
|
|
|
public readonly RadioButton Button;
|
|
|
|
|
2017-12-02 19:30:18 +08:00
|
|
|
private Color4 defaultBackgroundColour;
|
2022-10-13 15:33:09 +08:00
|
|
|
private Color4 defaultIconColour;
|
2017-12-02 19:30:18 +08:00
|
|
|
private Color4 selectedBackgroundColour;
|
2022-10-13 15:33:09 +08:00
|
|
|
private Color4 selectedIconColour;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2023-01-12 23:07:54 +08:00
|
|
|
private Drawable icon = null!;
|
2021-07-17 01:30:13 +08:00
|
|
|
|
2023-01-12 23:07:54 +08:00
|
|
|
[Resolved]
|
|
|
|
private EditorBeatmap? editorBeatmap { get; set; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2021-07-19 15:57:12 +08:00
|
|
|
public EditorRadioButton(RadioButton button)
|
2017-11-30 14:43:19 +08:00
|
|
|
{
|
2021-07-17 01:30:49 +08:00
|
|
|
Button = button;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2021-07-17 01:30:49 +08:00
|
|
|
Text = button.Label;
|
2020-01-28 14:00:45 +08:00
|
|
|
Action = button.Select;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-11-30 14:43:19 +08:00
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-11-30 14:43:19 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2022-10-13 15:33:09 +08:00
|
|
|
private void load(OverlayColourProvider colourProvider)
|
2017-11-30 14:43:19 +08:00
|
|
|
{
|
2022-10-13 15:33:09 +08:00
|
|
|
defaultBackgroundColour = colourProvider.Background3;
|
|
|
|
selectedBackgroundColour = colourProvider.Background1;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2022-10-13 15:33:09 +08:00
|
|
|
defaultIconColour = defaultBackgroundColour.Darken(0.5f);
|
|
|
|
selectedIconColour = selectedBackgroundColour.Lighten(0.5f);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2021-07-17 01:30:13 +08:00
|
|
|
Add(icon = (Button.CreateIcon?.Invoke() ?? new Circle()).With(b =>
|
2020-09-09 17:35:25 +08:00
|
|
|
{
|
|
|
|
b.Blending = BlendingParameters.Additive;
|
|
|
|
b.Anchor = Anchor.CentreLeft;
|
|
|
|
b.Origin = Anchor.CentreLeft;
|
|
|
|
b.Size = new Vector2(20);
|
|
|
|
b.X = 10;
|
|
|
|
}));
|
2017-11-30 14:43:19 +08:00
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-11-30 18:49:55 +08:00
|
|
|
protected override void LoadComplete()
|
2017-11-30 14:43:19 +08:00
|
|
|
{
|
2017-11-30 18:49:55 +08:00
|
|
|
base.LoadComplete();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2021-07-17 01:30:13 +08:00
|
|
|
Button.Selected.ValueChanged += selected =>
|
2017-11-30 18:49:55 +08:00
|
|
|
{
|
|
|
|
updateSelectionState();
|
2019-02-22 16:51:39 +08:00
|
|
|
if (selected.NewValue)
|
2021-07-17 01:30:13 +08:00
|
|
|
Selected?.Invoke(Button);
|
2017-11-30 18:49:55 +08:00
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2021-07-17 01:30:13 +08:00
|
|
|
editorBeatmap?.HasTiming.BindValueChanged(hasTiming => Button.Selected.Disabled = !hasTiming.NewValue, true);
|
|
|
|
|
|
|
|
Button.Selected.BindDisabledChanged(disabled => Enabled.Value = !disabled, true);
|
2017-11-30 18:49:55 +08:00
|
|
|
updateSelectionState();
|
2017-11-30 14:43:19 +08:00
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-11-30 18:49:55 +08:00
|
|
|
private void updateSelectionState()
|
2017-11-30 14:43:19 +08:00
|
|
|
{
|
2017-11-30 18:49:55 +08:00
|
|
|
if (!IsLoaded)
|
2017-11-30 14:43:19 +08:00
|
|
|
return;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2021-07-17 01:30:13 +08:00
|
|
|
BackgroundColour = Button.Selected.Value ? selectedBackgroundColour : defaultBackgroundColour;
|
2022-10-13 15:33:09 +08:00
|
|
|
icon.Colour = Button.Selected.Value ? selectedIconColour : defaultIconColour;
|
2017-11-30 14:43:19 +08:00
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-11-30 14:43:19 +08:00
|
|
|
protected override SpriteText CreateText() => new OsuSpriteText
|
|
|
|
{
|
|
|
|
Depth = -1,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
X = 40f
|
|
|
|
};
|
2021-07-17 01:30:13 +08:00
|
|
|
|
|
|
|
public LocalisableString TooltipText => Enabled.Value ? string.Empty : "Add at least one timing point first!";
|
2017-11-30 14:43:19 +08:00
|
|
|
}
|
|
|
|
}
|