mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 21:03:08 +08:00
Revert SettingsItem<T>
-related changes
This commit is contained in:
parent
6b35c0fe01
commit
b5e6352137
@ -2,22 +2,12 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using osu.Framework.Graphics;
|
||||
|
||||
namespace osu.Game.Overlays.Settings
|
||||
{
|
||||
/// <summary>
|
||||
/// A non-generic interface for <see cref="SettingsItem{T}"/>s.
|
||||
/// </summary>
|
||||
public interface ISettingsItem : IExpandable, IDisposable
|
||||
public interface ISettingsItem : IDrawable, IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Invoked when the setting value has changed.
|
||||
/// </summary>
|
||||
event Action SettingChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether the UI control is currently in a dragged state.
|
||||
/// </summary>
|
||||
bool IsControlDragged { get; }
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ namespace osu.Game.Overlays.Settings
|
||||
|
||||
protected readonly FillFlowContainer FlowContent;
|
||||
|
||||
private SpriteText label;
|
||||
private SpriteText labelText;
|
||||
|
||||
private OsuTextFlowContainer warningText;
|
||||
|
||||
@ -42,34 +42,21 @@ namespace osu.Game.Overlays.Settings
|
||||
[Resolved]
|
||||
private OsuColour colours { get; set; }
|
||||
|
||||
private LocalisableString labelText;
|
||||
|
||||
public virtual LocalisableString LabelText
|
||||
{
|
||||
get => labelText;
|
||||
get => labelText?.Text ?? string.Empty;
|
||||
set
|
||||
{
|
||||
ensureLabelCreated();
|
||||
if (labelText == null)
|
||||
{
|
||||
// construct lazily for cases where the label is not needed (may be provided by the Control).
|
||||
FlowContent.Insert(-1, labelText = new OsuSpriteText());
|
||||
|
||||
labelText = value;
|
||||
updateLabelText();
|
||||
}
|
||||
}
|
||||
updateDisabled();
|
||||
}
|
||||
|
||||
private LocalisableString? contractedLabelText;
|
||||
|
||||
/// <summary>
|
||||
/// Text to be displayed in place of <see cref="LabelText"/> when this <see cref="SettingsItem{T}"/> is in a contracted state.
|
||||
/// </summary>
|
||||
public LocalisableString? ContractedLabelText
|
||||
{
|
||||
get => contractedLabelText;
|
||||
set
|
||||
{
|
||||
ensureLabelCreated();
|
||||
|
||||
contractedLabelText = value;
|
||||
updateLabelText();
|
||||
labelText.Text = value;
|
||||
updateLayout();
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,12 +90,6 @@ namespace osu.Game.Overlays.Settings
|
||||
set => controlWithCurrent.Current = value;
|
||||
}
|
||||
|
||||
public BindableBool Expanded { get; } = new BindableBool(true);
|
||||
|
||||
public bool IsControlDragged => Control.IsDragged;
|
||||
|
||||
public event Action SettingChanged;
|
||||
|
||||
public virtual IEnumerable<string> FilterTerms => Keywords == null ? new[] { LabelText.ToString() } : new List<string>(Keywords) { LabelText.ToString() }.ToArray();
|
||||
|
||||
public IEnumerable<string> Keywords { get; set; }
|
||||
@ -120,6 +101,8 @@ namespace osu.Game.Overlays.Settings
|
||||
|
||||
public bool FilteringActive { get; set; }
|
||||
|
||||
public event Action SettingChanged;
|
||||
|
||||
protected SettingsItem()
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
@ -168,59 +151,23 @@ namespace osu.Game.Overlays.Settings
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre
|
||||
});
|
||||
updateLayout();
|
||||
}
|
||||
}
|
||||
|
||||
[Resolved(canBeNull: true)]
|
||||
private IExpandingContainer expandingContainer { get; set; }
|
||||
|
||||
protected override void LoadComplete()
|
||||
private void updateLayout()
|
||||
{
|
||||
base.LoadComplete();
|
||||
bool hasLabel = labelText != null && !string.IsNullOrEmpty(labelText.Text.ToString());
|
||||
|
||||
expandingContainer?.Expanded.BindValueChanged(containerExpanded => Expanded.Value = containerExpanded.NewValue, true);
|
||||
|
||||
Expanded.BindValueChanged(v =>
|
||||
{
|
||||
updateLabelText();
|
||||
|
||||
Control.FadeTo(v.NewValue ? 1 : 0, 500, Easing.OutQuint);
|
||||
Control.BypassAutoSizeAxes = v.NewValue ? Axes.None : Axes.Both;
|
||||
}, true);
|
||||
|
||||
FinishTransforms(true);
|
||||
}
|
||||
|
||||
private void ensureLabelCreated()
|
||||
{
|
||||
if (label != null)
|
||||
return;
|
||||
|
||||
// construct lazily for cases where the label is not needed (may be provided by the Control).
|
||||
FlowContent.Insert(-1, label = new OsuSpriteText());
|
||||
|
||||
updateDisabled();
|
||||
}
|
||||
|
||||
private void updateLabelText()
|
||||
{
|
||||
if (label != null)
|
||||
{
|
||||
if (contractedLabelText is LocalisableString contractedText)
|
||||
label.Text = Expanded.Value ? labelText : contractedText;
|
||||
else
|
||||
label.Text = labelText;
|
||||
}
|
||||
|
||||
// if the settings item is providing a non-empty label, the default value indicator should be centred vertically to the left of the label.
|
||||
// if the settings item is providing a label, the default value indicator should be centred vertically to the left of the label.
|
||||
// otherwise, it should be centred vertically to the left of the main control of the settings item.
|
||||
defaultValueIndicatorContainer.Height = !string.IsNullOrEmpty(label?.Text.ToString()) ? label.DrawHeight : Control.DrawHeight;
|
||||
defaultValueIndicatorContainer.Height = hasLabel ? labelText.DrawHeight : Control.DrawHeight;
|
||||
}
|
||||
|
||||
private void updateDisabled()
|
||||
{
|
||||
if (label != null)
|
||||
label.Alpha = controlWithCurrent.Current.Disabled ? 0.3f : 1;
|
||||
if (labelText != null)
|
||||
labelText.Alpha = controlWithCurrent.Current.Disabled ? 0.3f : 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user