1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 10:23:04 +08:00

Revert SettingsItem<T>-related changes

This commit is contained in:
Salman Ahmed 2022-01-26 09:31:29 +03:00
parent 6b35c0fe01
commit b5e6352137
2 changed files with 21 additions and 84 deletions

View File

@ -2,22 +2,12 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using osu.Framework.Graphics;
namespace osu.Game.Overlays.Settings namespace osu.Game.Overlays.Settings
{ {
/// <summary> public interface ISettingsItem : IDrawable, IDisposable
/// A non-generic interface for <see cref="SettingsItem{T}"/>s.
/// </summary>
public interface ISettingsItem : IExpandable, IDisposable
{ {
/// <summary>
/// Invoked when the setting value has changed.
/// </summary>
event Action SettingChanged; event Action SettingChanged;
/// <summary>
/// Returns whether the UI control is currently in a dragged state.
/// </summary>
bool IsControlDragged { get; }
} }
} }

View File

@ -30,7 +30,7 @@ namespace osu.Game.Overlays.Settings
protected readonly FillFlowContainer FlowContent; protected readonly FillFlowContainer FlowContent;
private SpriteText label; private SpriteText labelText;
private OsuTextFlowContainer warningText; private OsuTextFlowContainer warningText;
@ -42,34 +42,21 @@ namespace osu.Game.Overlays.Settings
[Resolved] [Resolved]
private OsuColour colours { get; set; } private OsuColour colours { get; set; }
private LocalisableString labelText;
public virtual LocalisableString LabelText public virtual LocalisableString LabelText
{ {
get => labelText; get => labelText?.Text ?? string.Empty;
set 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; updateDisabled();
updateLabelText(); }
}
}
private LocalisableString? contractedLabelText; labelText.Text = value;
updateLayout();
/// <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();
} }
} }
@ -103,12 +90,6 @@ namespace osu.Game.Overlays.Settings
set => controlWithCurrent.Current = value; 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 virtual IEnumerable<string> FilterTerms => Keywords == null ? new[] { LabelText.ToString() } : new List<string>(Keywords) { LabelText.ToString() }.ToArray();
public IEnumerable<string> Keywords { get; set; } public IEnumerable<string> Keywords { get; set; }
@ -120,6 +101,8 @@ namespace osu.Game.Overlays.Settings
public bool FilteringActive { get; set; } public bool FilteringActive { get; set; }
public event Action SettingChanged;
protected SettingsItem() protected SettingsItem()
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
@ -168,59 +151,23 @@ namespace osu.Game.Overlays.Settings
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre Origin = Anchor.Centre
}); });
updateLayout();
} }
} }
[Resolved(canBeNull: true)] private void updateLayout()
private IExpandingContainer expandingContainer { get; set; }
protected override void LoadComplete()
{ {
base.LoadComplete(); bool hasLabel = labelText != null && !string.IsNullOrEmpty(labelText.Text.ToString());
expandingContainer?.Expanded.BindValueChanged(containerExpanded => Expanded.Value = containerExpanded.NewValue, true); // if the settings item is providing a label, the default value indicator should be centred vertically to the left of the label.
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.
// otherwise, it should be centred vertically to the left of the main control of the settings item. // 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() private void updateDisabled()
{ {
if (label != null) if (labelText != null)
label.Alpha = controlWithCurrent.Current.Disabled ? 0.3f : 1; labelText.Alpha = controlWithCurrent.Current.Disabled ? 0.3f : 1;
} }
} }
} }