1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 18:07:25 +08:00
osu-lazer/osu.Game/Screens/Edit/Components/RadioButtons/EditorRadioButton.cs

113 lines
3.6 KiB
C#
Raw Normal View History

// 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
using System;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Cursor;
2019-04-02 13:51:28 +08:00
using osu.Framework.Graphics.Effects;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
2018-04-13 17:19:50 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
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
2018-04-13 17:19:50 +08:00
{
public class EditorRadioButton : OsuButton, IHasTooltip
2018-04-13 17:19:50 +08:00
{
/// <summary>
/// Invoked when this <see cref="EditorRadioButton"/> has been selected.
2018-04-13 17:19:50 +08:00
/// </summary>
public Action<RadioButton> Selected;
public readonly RadioButton Button;
2018-04-13 17:19:50 +08:00
private Color4 defaultBackgroundColour;
private Color4 defaultBubbleColour;
private Color4 selectedBackgroundColour;
private Color4 selectedBubbleColour;
2020-09-09 17:35:25 +08:00
private Drawable icon;
[Resolved(canBeNull: true)]
private EditorBeatmap editorBeatmap { get; set; }
2018-04-13 17:19:50 +08:00
public EditorRadioButton(RadioButton button)
2018-04-13 17:19:50 +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;
Action = button.Select;
2018-04-13 17:19:50 +08:00
RelativeSizeAxes = Axes.X;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
defaultBackgroundColour = colours.Gray3;
defaultBubbleColour = defaultBackgroundColour.Darken(0.5f);
selectedBackgroundColour = colours.BlueDark;
selectedBubbleColour = selectedBackgroundColour.Lighten(0.5f);
Content.EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Radius = 2,
Offset = new Vector2(0, 1),
Colour = Color4.Black.Opacity(0.5f)
};
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;
}));
2018-04-13 17:19:50 +08:00
}
protected override void LoadComplete()
{
base.LoadComplete();
Button.Selected.ValueChanged += selected =>
2018-04-13 17:19:50 +08:00
{
updateSelectionState();
if (selected.NewValue)
Selected?.Invoke(Button);
2018-04-13 17:19:50 +08:00
};
editorBeatmap?.HasTiming.BindValueChanged(hasTiming => Button.Selected.Disabled = !hasTiming.NewValue, true);
Button.Selected.BindDisabledChanged(disabled => Enabled.Value = !disabled, true);
2018-04-13 17:19:50 +08:00
updateSelectionState();
}
private void updateSelectionState()
{
if (!IsLoaded)
return;
BackgroundColour = Button.Selected.Value ? selectedBackgroundColour : defaultBackgroundColour;
icon.Colour = Button.Selected.Value ? selectedBubbleColour : defaultBubbleColour;
2018-04-13 17:19:50 +08:00
}
protected override SpriteText CreateText() => new OsuSpriteText
{
Depth = -1,
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
X = 40f
};
public LocalisableString TooltipText => Enabled.Value ? string.Empty : "Add at least one timing point first!";
2018-04-13 17:19:50 +08:00
}
}