mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 07:06:35 +09:00
Combine display and button into one control
This commit is contained in:
@ -17,7 +17,6 @@ using osu.Framework.Input.Events;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.Overlays;
|
||||
@ -48,9 +47,7 @@ namespace osu.Game.Rulesets.Edit
|
||||
protected ExpandingToolboxContainer RightSideToolboxContainer { get; private set; }
|
||||
|
||||
private ExpandableSlider<double, SizeSlider<double>> distanceSpacingSlider;
|
||||
private ExpandableButton readCurrentButton;
|
||||
|
||||
private OsuSpriteText currentDistanceSpacingDisplay;
|
||||
private ExpandableButton currentDistanceSpacingButton;
|
||||
|
||||
[Resolved(canBeNull: true)]
|
||||
private OnScreenDisplay onScreenDisplay { get; set; }
|
||||
@ -88,12 +85,8 @@ namespace osu.Game.Rulesets.Edit
|
||||
Current = { BindTarget = DistanceSpacingMultiplier },
|
||||
KeyboardStep = adjust_step,
|
||||
},
|
||||
currentDistanceSpacingDisplay = new OsuSpriteText
|
||||
currentDistanceSpacingButton = new ExpandableButton
|
||||
{
|
||||
},
|
||||
readCurrentButton = new ExpandableButton
|
||||
{
|
||||
Text = "Use current",
|
||||
Action = () =>
|
||||
{
|
||||
(HitObject before, HitObject after)? objects = getObjectsOnEitherSideOfCurrentTime();
|
||||
@ -140,14 +133,17 @@ namespace osu.Game.Rulesets.Edit
|
||||
if (objects != null)
|
||||
{
|
||||
double currentSnap = ReadCurrentDistanceSnap(objects.Value.before, objects.Value.after);
|
||||
readCurrentButton.Enabled.Value = Precision.AlmostEquals(currentSnap, DistanceSpacingMultiplier.Value, DistanceSpacingMultiplier.Precision);
|
||||
|
||||
currentDistanceSpacingDisplay.Text = $"Current {currentSnap:N1}x";
|
||||
currentDistanceSpacingButton.Enabled.Value = currentDistanceSpacingButton.Expanded.Value
|
||||
&& !Precision.AlmostEquals(currentSnap, DistanceSpacingMultiplier.Value, DistanceSpacingMultiplier.Precision / 2);
|
||||
currentDistanceSpacingButton.ContractedLabelText = $"(current {currentSnap:N2}x)";
|
||||
currentDistanceSpacingButton.ExpandedLabelText = $"Use current ({currentSnap:N2}x)";
|
||||
}
|
||||
else
|
||||
{
|
||||
readCurrentButton.Enabled.Value = false;
|
||||
currentDistanceSpacingDisplay.Text = "Current: -";
|
||||
currentDistanceSpacingButton.Enabled.Value = false;
|
||||
currentDistanceSpacingButton.ContractedLabelText = "Current N/A";
|
||||
currentDistanceSpacingButton.ExpandedLabelText = "Use current (N/A)";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,9 @@
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.UserInterfaceV2;
|
||||
|
||||
@ -10,6 +13,54 @@ namespace osu.Game.Rulesets.Edit
|
||||
{
|
||||
internal class ExpandableButton : RoundedButton, IExpandable
|
||||
{
|
||||
private float actualHeight;
|
||||
|
||||
public override float Height
|
||||
{
|
||||
get => base.Height;
|
||||
set => base.Height = actualHeight = value;
|
||||
}
|
||||
|
||||
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)
|
||||
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)
|
||||
Text = value;
|
||||
}
|
||||
}
|
||||
|
||||
public BindableBool Expanded { get; } = new BindableBool();
|
||||
|
||||
[Resolved(canBeNull: true)]
|
||||
@ -26,10 +77,24 @@ namespace osu.Game.Rulesets.Edit
|
||||
|
||||
Expanded.BindValueChanged(expanded =>
|
||||
{
|
||||
Text = expanded.NewValue ? expandedLabelText : contractedLabelText;
|
||||
|
||||
if (expanded.NewValue)
|
||||
Show();
|
||||
{
|
||||
SpriteText.Anchor = Anchor.Centre;
|
||||
SpriteText.Origin = Anchor.Centre;
|
||||
SpriteText.Font = OsuFont.GetFont(weight: FontWeight.Bold);
|
||||
base.Height = actualHeight;
|
||||
Background.Show();
|
||||
}
|
||||
else
|
||||
Hide();
|
||||
{
|
||||
SpriteText.Anchor = Anchor.CentreLeft;
|
||||
SpriteText.Origin = Anchor.CentreLeft;
|
||||
SpriteText.Font = OsuFont.GetFont(weight: FontWeight.Regular);
|
||||
base.Height = SpriteText.DrawHeight;
|
||||
Background.Hide();
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user