1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-07 06:38:27 +08:00

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

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