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
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2017-11-30 14:43:19 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-11-20 15:51:59 +08:00
|
|
|
using osuTK;
|
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 EditorRadioButtonCollection : CompositeDrawable
|
2017-11-30 14:43:19 +08:00
|
|
|
{
|
2017-11-30 18:49:55 +08:00
|
|
|
private IReadOnlyList<RadioButton> items;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
2017-11-30 14:43:19 +08:00
|
|
|
public IReadOnlyList<RadioButton> Items
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
get => items;
|
2017-11-30 14:43:19 +08:00
|
|
|
set
|
|
|
|
{
|
2017-11-30 18:54:58 +08:00
|
|
|
if (ReferenceEquals(items, value))
|
2017-11-30 18:49:55 +08:00
|
|
|
return;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
2017-11-30 18:49:55 +08:00
|
|
|
items = value;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-11-30 14:43:19 +08:00
|
|
|
buttonContainer.Clear();
|
2017-12-02 19:31:10 +08:00
|
|
|
items.ForEach(addButton);
|
2017-11-30 14:43:19 +08:00
|
|
|
}
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2021-07-19 15:57:12 +08:00
|
|
|
private readonly FlowContainer<EditorRadioButton> buttonContainer;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2021-07-19 15:57:12 +08:00
|
|
|
public EditorRadioButtonCollection()
|
2017-11-30 14:43:19 +08:00
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Y;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2021-07-19 15:57:12 +08:00
|
|
|
InternalChild = buttonContainer = new FillFlowContainer<EditorRadioButton>
|
2017-11-30 14:43:19 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Spacing = new Vector2(0, 5)
|
|
|
|
};
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-11-30 18:49:55 +08:00
|
|
|
private RadioButton currentlySelected;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
2017-11-30 18:49:55 +08:00
|
|
|
private void addButton(RadioButton button)
|
2017-11-30 14:43:19 +08:00
|
|
|
{
|
2019-02-22 16:51:39 +08:00
|
|
|
button.Selected.ValueChanged += selected =>
|
2017-11-30 18:49:55 +08:00
|
|
|
{
|
2019-02-22 16:51:39 +08:00
|
|
|
if (selected.NewValue)
|
2017-11-30 18:49:55 +08:00
|
|
|
{
|
|
|
|
currentlySelected?.Deselect();
|
|
|
|
currentlySelected = button;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
currentlySelected = null;
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2021-07-19 15:57:12 +08:00
|
|
|
buttonContainer.Add(new EditorRadioButton(button));
|
2017-11-30 14:43:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|