2022-10-21 21:58:36 +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 osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2022-10-21 22:21:07 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Localisation;
|
|
|
|
using osu.Game.Graphics;
|
2022-10-21 21:58:36 +08:00
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Edit
|
|
|
|
{
|
|
|
|
internal class ExpandableButton : RoundedButton, IExpandable
|
|
|
|
{
|
2022-10-21 22:21:07 +08:00
|
|
|
private float actualHeight;
|
|
|
|
|
|
|
|
public override float Height
|
|
|
|
{
|
|
|
|
get => base.Height;
|
|
|
|
set => base.Height = actualHeight = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
private LocalisableString contractedLabelText;
|
|
|
|
|
|
|
|
/// <summary>
|
2022-10-26 12:14:12 +08:00
|
|
|
/// The label text to display when this button is in a contracted state.
|
2022-10-21 22:21:07 +08:00
|
|
|
/// </summary>
|
|
|
|
public LocalisableString ContractedLabelText
|
|
|
|
{
|
|
|
|
get => contractedLabelText;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (value == contractedLabelText)
|
|
|
|
return;
|
|
|
|
|
|
|
|
contractedLabelText = value;
|
|
|
|
|
|
|
|
if (!Expanded.Value)
|
|
|
|
Text = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private LocalisableString expandedLabelText;
|
|
|
|
|
|
|
|
/// <summary>
|
2022-10-26 12:14:12 +08:00
|
|
|
/// The label text to display when this button is in an expanded state.
|
2022-10-21 22:21:07 +08:00
|
|
|
/// </summary>
|
|
|
|
public LocalisableString ExpandedLabelText
|
|
|
|
{
|
|
|
|
get => expandedLabelText;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (value == expandedLabelText)
|
|
|
|
return;
|
|
|
|
|
|
|
|
expandedLabelText = value;
|
|
|
|
|
|
|
|
if (Expanded.Value)
|
|
|
|
Text = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 21:58:36 +08:00
|
|
|
public BindableBool Expanded { get; } = new BindableBool();
|
|
|
|
|
|
|
|
[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(expanded =>
|
|
|
|
{
|
2022-10-21 22:21:07 +08:00
|
|
|
Text = expanded.NewValue ? expandedLabelText : contractedLabelText;
|
|
|
|
|
2022-10-21 21:58:36 +08:00
|
|
|
if (expanded.NewValue)
|
2022-10-21 22:21:07 +08:00
|
|
|
{
|
|
|
|
SpriteText.Anchor = Anchor.Centre;
|
|
|
|
SpriteText.Origin = Anchor.Centre;
|
|
|
|
SpriteText.Font = OsuFont.GetFont(weight: FontWeight.Bold);
|
|
|
|
base.Height = actualHeight;
|
|
|
|
Background.Show();
|
|
|
|
}
|
2022-10-21 21:58:36 +08:00
|
|
|
else
|
2022-10-21 22:21:07 +08:00
|
|
|
{
|
|
|
|
SpriteText.Anchor = Anchor.CentreLeft;
|
|
|
|
SpriteText.Origin = Anchor.CentreLeft;
|
|
|
|
SpriteText.Font = OsuFont.GetFont(weight: FontWeight.Regular);
|
2022-10-21 22:35:53 +08:00
|
|
|
base.Height = actualHeight / 2;
|
2022-10-21 22:21:07 +08:00
|
|
|
Background.Hide();
|
|
|
|
}
|
2022-10-21 21:58:36 +08:00
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|