2022-01-26 15:18:06 +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.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
using osu.Framework.Localisation;
|
2022-02-14 16:51:39 +08:00
|
|
|
using osu.Game.Graphics.Containers;
|
2022-01-26 15:18:06 +08:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2022-01-26 15:35:42 +08:00
|
|
|
using osuTK;
|
2022-01-26 15:18:06 +08:00
|
|
|
|
2022-02-14 16:51:39 +08:00
|
|
|
namespace osu.Game.Graphics.UserInterface
|
2022-01-26 15:18:06 +08:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// An <see cref="IExpandable"/> implementation for the UI slider bar control.
|
|
|
|
/// </summary>
|
2022-02-04 10:45:12 +08:00
|
|
|
public class ExpandableSlider<T, TSlider> : CompositeDrawable, IExpandable, IHasCurrentValue<T>
|
2022-01-26 15:18:06 +08:00
|
|
|
where T : struct, IEquatable<T>, IComparable<T>, IConvertible
|
|
|
|
where TSlider : OsuSliderBar<T>, new()
|
|
|
|
{
|
|
|
|
private readonly OsuSpriteText label;
|
|
|
|
private readonly TSlider slider;
|
|
|
|
|
|
|
|
private LocalisableString contractedLabelText;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The label text to display when this slider is in a contracted state.
|
|
|
|
/// </summary>
|
|
|
|
public LocalisableString ContractedLabelText
|
|
|
|
{
|
|
|
|
get => contractedLabelText;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (value == contractedLabelText)
|
|
|
|
return;
|
|
|
|
|
|
|
|
contractedLabelText = value;
|
|
|
|
|
|
|
|
if (!Expanded.Value)
|
|
|
|
label.Text = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private LocalisableString expandedLabelText;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The label text to display when this slider is in an expanded state.
|
|
|
|
/// </summary>
|
|
|
|
public LocalisableString ExpandedLabelText
|
|
|
|
{
|
|
|
|
get => expandedLabelText;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (value == expandedLabelText)
|
|
|
|
return;
|
|
|
|
|
|
|
|
expandedLabelText = value;
|
|
|
|
|
|
|
|
if (Expanded.Value)
|
|
|
|
label.Text = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Bindable<T> Current
|
|
|
|
{
|
|
|
|
get => slider.Current;
|
|
|
|
set => slider.Current = value;
|
|
|
|
}
|
|
|
|
|
2022-01-18 01:09:02 +08:00
|
|
|
/// <summary>
|
|
|
|
/// A custom step value for each key press which actuates a change on this control.
|
|
|
|
/// </summary>
|
|
|
|
public float KeyboardStep
|
|
|
|
{
|
|
|
|
get => slider.KeyboardStep;
|
|
|
|
set => slider.KeyboardStep = value;
|
|
|
|
}
|
|
|
|
|
2022-01-26 15:18:06 +08:00
|
|
|
public BindableBool Expanded { get; } = new BindableBool();
|
|
|
|
|
|
|
|
public override bool HandlePositionalInput => true;
|
|
|
|
|
|
|
|
public ExpandableSlider()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
InternalChild = new FillFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2022-01-26 15:35:42 +08:00
|
|
|
Spacing = new Vector2(0f, 10f),
|
2022-01-26 15:18:06 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
label = new OsuSpriteText(),
|
2022-01-26 15:35:42 +08:00
|
|
|
slider = new TSlider
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
},
|
2022-01-26 15:18:06 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
[Resolved(canBeNull: true)]
|
|
|
|
private IExpandingContainer expandingContainer { get; set; }
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
expandingContainer?.Expanded.BindValueChanged(containerExpanded =>
|
|
|
|
{
|
|
|
|
Expanded.Value = containerExpanded.NewValue;
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
Expanded.BindValueChanged(v =>
|
|
|
|
{
|
|
|
|
label.Text = v.NewValue ? expandedLabelText : contractedLabelText;
|
|
|
|
slider.FadeTo(v.NewValue ? 1f : 0f, 500, Easing.OutQuint);
|
2022-01-26 15:35:42 +08:00
|
|
|
slider.BypassAutoSizeAxes = !v.NewValue ? Axes.Y : Axes.None;
|
2022-01-26 15:18:06 +08:00
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// An <see cref="IExpandable"/> implementation for the UI slider bar control.
|
|
|
|
/// </summary>
|
|
|
|
public class ExpandableSlider<T> : ExpandableSlider<T, OsuSliderBar<T>>
|
|
|
|
where T : struct, IEquatable<T>, IComparable<T>, IConvertible
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|