mirror of
https://github.com/ppy/osu.git
synced 2024-09-22 06:47:24 +08:00
Merge pull request #15164 from bdach/default-value-indicator
Update appearance of setting default value indicator
This commit is contained in:
commit
6c1d224164
@ -0,0 +1,63 @@
|
|||||||
|
// 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 NUnit.Framework;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Shapes;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Overlays;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.Settings
|
||||||
|
{
|
||||||
|
public class TestSceneRestoreDefaultValueButton : OsuTestScene
|
||||||
|
{
|
||||||
|
[Resolved]
|
||||||
|
private OsuColour colours { get; set; }
|
||||||
|
|
||||||
|
private float scale = 1;
|
||||||
|
|
||||||
|
private readonly Bindable<float> current = new Bindable<float>
|
||||||
|
{
|
||||||
|
Default = default,
|
||||||
|
Value = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestBasic()
|
||||||
|
{
|
||||||
|
RestoreDefaultValueButton<float> restoreDefaultValueButton = null;
|
||||||
|
|
||||||
|
AddStep("create button", () => Child = new Container
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new Box
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Colour = colours.GreySeafoam
|
||||||
|
},
|
||||||
|
restoreDefaultValueButton = new RestoreDefaultValueButton<float>
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Scale = new Vector2(scale),
|
||||||
|
Current = current,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
AddSliderStep("set scale", 1, 4, 1, scale =>
|
||||||
|
{
|
||||||
|
this.scale = scale;
|
||||||
|
if (restoreDefaultValueButton != null)
|
||||||
|
restoreDefaultValueButton.Scale = new Vector2(scale);
|
||||||
|
});
|
||||||
|
AddToggleStep("toggle default state", state => current.Value = state ? default : 1);
|
||||||
|
AddToggleStep("toggle disabled state", state => current.Disabled = state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,9 @@ using System.Linq;
|
|||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
|
using osu.Framework.Utils;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Overlays.Settings;
|
using osu.Game.Overlays.Settings;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
|
|
||||||
@ -29,9 +32,10 @@ namespace osu.Game.Tests.Visual.Settings
|
|||||||
Value = "test"
|
Value = "test"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
restoreDefaultValueButton = textBox.ChildrenOfType<RestoreDefaultValueButton<string>>().Single();
|
|
||||||
});
|
});
|
||||||
|
AddUntilStep("wait for loaded", () => textBox.IsLoaded);
|
||||||
|
AddStep("retrieve restore default button", () => restoreDefaultValueButton = textBox.ChildrenOfType<RestoreDefaultValueButton<string>>().Single());
|
||||||
|
|
||||||
AddAssert("restore button hidden", () => restoreDefaultValueButton.Alpha == 0);
|
AddAssert("restore button hidden", () => restoreDefaultValueButton.Alpha == 0);
|
||||||
|
|
||||||
AddStep("change value from default", () => textBox.Current.Value = "non-default");
|
AddStep("change value from default", () => textBox.Current.Value = "non-default");
|
||||||
@ -41,6 +45,48 @@ namespace osu.Game.Tests.Visual.Settings
|
|||||||
AddUntilStep("restore button hidden", () => restoreDefaultValueButton.Alpha == 0);
|
AddUntilStep("restore button hidden", () => restoreDefaultValueButton.Alpha == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestSetAndClearLabelText()
|
||||||
|
{
|
||||||
|
SettingsTextBox textBox = null;
|
||||||
|
RestoreDefaultValueButton<string> restoreDefaultValueButton = null;
|
||||||
|
OsuTextBox control = null;
|
||||||
|
|
||||||
|
AddStep("create settings item", () =>
|
||||||
|
{
|
||||||
|
Child = textBox = new SettingsTextBox
|
||||||
|
{
|
||||||
|
Current = new Bindable<string>
|
||||||
|
{
|
||||||
|
Default = "test",
|
||||||
|
Value = "test"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
AddUntilStep("wait for loaded", () => textBox.IsLoaded);
|
||||||
|
AddStep("retrieve components", () =>
|
||||||
|
{
|
||||||
|
restoreDefaultValueButton = textBox.ChildrenOfType<RestoreDefaultValueButton<string>>().Single();
|
||||||
|
control = textBox.ChildrenOfType<OsuTextBox>().Single();
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep("set non-default value", () => restoreDefaultValueButton.Current.Value = "non-default");
|
||||||
|
AddAssert("default value button centre aligned to control size", () => Precision.AlmostEquals(restoreDefaultValueButton.Parent.DrawHeight, control.DrawHeight, 1));
|
||||||
|
|
||||||
|
AddStep("set label", () => textBox.LabelText = "label text");
|
||||||
|
AddAssert("default value button centre aligned to label size", () =>
|
||||||
|
{
|
||||||
|
var label = textBox.ChildrenOfType<OsuSpriteText>().Single(spriteText => spriteText.Text == "label text");
|
||||||
|
return Precision.AlmostEquals(restoreDefaultValueButton.Parent.DrawHeight, label.DrawHeight, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep("clear label", () => textBox.LabelText = default);
|
||||||
|
AddAssert("default value button centre aligned to control size", () => Precision.AlmostEquals(restoreDefaultValueButton.Parent.DrawHeight, control.DrawHeight, 1));
|
||||||
|
|
||||||
|
AddStep("set warning text", () => textBox.WarningText = "This is some very important warning text! Hopefully it doesn't break the alignment of the default value indicator...");
|
||||||
|
AddAssert("default value button centre aligned to control size", () => Precision.AlmostEquals(restoreDefaultValueButton.Parent.DrawHeight, control.DrawHeight, 1));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ensures that the reset to default button uses the correct implementation of IsDefault to determine whether it should be shown or not.
|
/// Ensures that the reset to default button uses the correct implementation of IsDefault to determine whether it should be shown or not.
|
||||||
/// Values have been chosen so that after being set, Value != Default (but they are close enough that the difference is negligible compared to Precision).
|
/// Values have been chosen so that after being set, Value != Default (but they are close enough that the difference is negligible compared to Precision).
|
||||||
@ -64,9 +110,9 @@ namespace osu.Game.Tests.Visual.Settings
|
|||||||
Precision = 0.1f,
|
Precision = 0.1f,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
restoreDefaultValueButton = sliderBar.ChildrenOfType<RestoreDefaultValueButton<float>>().Single();
|
|
||||||
});
|
});
|
||||||
|
AddUntilStep("wait for loaded", () => sliderBar.IsLoaded);
|
||||||
|
AddStep("retrieve restore default button", () => restoreDefaultValueButton = sliderBar.ChildrenOfType<RestoreDefaultValueButton<float>>().Single());
|
||||||
|
|
||||||
AddAssert("restore button hidden", () => restoreDefaultValueButton.Alpha == 0);
|
AddAssert("restore button hidden", () => restoreDefaultValueButton.Alpha == 0);
|
||||||
|
|
||||||
|
@ -235,11 +235,18 @@ namespace osu.Game.Graphics
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly Color4 Blue3 = Color4Extensions.FromHex(@"3399cc");
|
public readonly Color4 Blue3 = Color4Extensions.FromHex(@"3399cc");
|
||||||
|
|
||||||
|
public readonly Color4 Lime0 = Color4Extensions.FromHex(@"ccff99");
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Equivalent to <see cref="OverlayColourProvider.Lime"/>'s <see cref="OverlayColourProvider.Colour1"/>.
|
/// Equivalent to <see cref="OverlayColourProvider.Lime"/>'s <see cref="OverlayColourProvider.Colour1"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly Color4 Lime1 = Color4Extensions.FromHex(@"b2ff66");
|
public readonly Color4 Lime1 = Color4Extensions.FromHex(@"b2ff66");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Equivalent to <see cref="OverlayColourProvider.Lime"/>'s <see cref="OverlayColourProvider.Colour3"/>.
|
||||||
|
/// </summary>
|
||||||
|
public readonly Color4 Lime3 = Color4Extensions.FromHex(@"7fcc33");
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Equivalent to <see cref="OverlayColourProvider.Orange"/>'s <see cref="OverlayColourProvider.Colour1"/>.
|
/// Equivalent to <see cref="OverlayColourProvider.Orange"/>'s <see cref="OverlayColourProvider.Colour1"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -3,10 +3,8 @@
|
|||||||
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osuTK.Graphics;
|
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Colour;
|
|
||||||
using osu.Framework.Graphics.Cursor;
|
using osu.Framework.Graphics.Cursor;
|
||||||
using osu.Framework.Graphics.Effects;
|
using osu.Framework.Graphics.Effects;
|
||||||
using osu.Framework.Graphics.UserInterface;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
@ -14,6 +12,7 @@ using osu.Framework.Input.Events;
|
|||||||
using osu.Framework.Localisation;
|
using osu.Framework.Localisation;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Overlays
|
namespace osu.Game.Overlays
|
||||||
{
|
{
|
||||||
@ -45,30 +44,21 @@ namespace osu.Game.Overlays
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool hovering;
|
[Resolved]
|
||||||
|
private OsuColour colours { get; set; }
|
||||||
|
|
||||||
public RestoreDefaultValueButton()
|
private const float size = 4;
|
||||||
{
|
|
||||||
Height = 1;
|
|
||||||
|
|
||||||
RelativeSizeAxes = Axes.Y;
|
|
||||||
Width = SettingsPanel.CONTENT_MARGINS;
|
|
||||||
}
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colour)
|
private void load(OsuColour colour)
|
||||||
{
|
{
|
||||||
BackgroundColour = colour.Yellow;
|
BackgroundColour = colour.Lime1;
|
||||||
Content.Width = 0.33f;
|
Size = new Vector2(3 * size);
|
||||||
Content.CornerRadius = 3;
|
|
||||||
Content.EdgeEffect = new EdgeEffectParameters
|
Content.RelativeSizeAxes = Axes.None;
|
||||||
{
|
Content.Size = new Vector2(size);
|
||||||
Colour = BackgroundColour.Opacity(0.1f),
|
Content.CornerRadius = size / 2;
|
||||||
Type = EdgeEffectType.Glow,
|
|
||||||
Radius = 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
Padding = new MarginPadding { Vertical = 1.5f };
|
|
||||||
Alpha = 0f;
|
Alpha = 0f;
|
||||||
|
|
||||||
Action += () =>
|
Action += () =>
|
||||||
@ -81,39 +71,55 @@ namespace osu.Game.Overlays
|
|||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
updateState();
|
||||||
// avoid unnecessary transforms on first display.
|
FinishTransforms(true);
|
||||||
Alpha = currentAlpha;
|
|
||||||
Background.Colour = currentColour;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalisableString TooltipText => "revert to default";
|
public LocalisableString TooltipText => "revert to default";
|
||||||
|
|
||||||
protected override bool OnHover(HoverEvent e)
|
protected override bool OnHover(HoverEvent e)
|
||||||
{
|
{
|
||||||
hovering = true;
|
|
||||||
UpdateState();
|
UpdateState();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnHoverLost(HoverLostEvent e)
|
protected override void OnHoverLost(HoverLostEvent e)
|
||||||
{
|
{
|
||||||
hovering = false;
|
|
||||||
UpdateState();
|
UpdateState();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateState() => Scheduler.AddOnce(updateState);
|
public void UpdateState() => Scheduler.AddOnce(updateState);
|
||||||
|
|
||||||
private float currentAlpha => current.IsDefault ? 0f : hovering && !current.Disabled ? 1f : 0.65f;
|
private const double fade_duration = 200;
|
||||||
private ColourInfo currentColour => current.Disabled ? Color4.Gray : BackgroundColour;
|
|
||||||
|
|
||||||
private void updateState()
|
private void updateState()
|
||||||
{
|
{
|
||||||
if (current == null)
|
if (current == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.FadeTo(currentAlpha, 200, Easing.OutQuint);
|
Enabled.Value = !Current.Disabled;
|
||||||
Background.FadeColour(currentColour, 200, Easing.OutQuint);
|
|
||||||
|
if (!Current.Disabled)
|
||||||
|
{
|
||||||
|
this.FadeTo(Current.IsDefault ? 0 : 1, fade_duration, Easing.OutQuint);
|
||||||
|
Background.FadeColour(IsHovered ? colours.Lime0 : colours.Lime1, fade_duration, Easing.OutQuint);
|
||||||
|
Content.TweenEdgeEffectTo(new EdgeEffectParameters
|
||||||
|
{
|
||||||
|
Colour = (IsHovered ? colours.Lime1 : colours.Lime3).Opacity(0.4f),
|
||||||
|
Radius = IsHovered ? 8 : 4,
|
||||||
|
Type = EdgeEffectType.Glow
|
||||||
|
}, fade_duration, Easing.OutQuint);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Background.FadeColour(colours.Lime3, fade_duration, Easing.OutQuint);
|
||||||
|
Content.TweenEdgeEffectTo(new EdgeEffectParameters
|
||||||
|
{
|
||||||
|
Colour = colours.Lime3.Opacity(0.1f),
|
||||||
|
Radius = 2,
|
||||||
|
Type = EdgeEffectType.Glow
|
||||||
|
}, fade_duration, Easing.OutQuint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,60 +82,75 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
AutoSizeAxes = Axes.Y;
|
AutoSizeAxes = Axes.Y;
|
||||||
Padding = new MarginPadding { Horizontal = SettingsPanel.CONTENT_MARGINS };
|
Padding = new MarginPadding { Right = SettingsPanel.CONTENT_MARGINS };
|
||||||
|
|
||||||
InternalChildren = new Drawable[]
|
InternalChildren = new Drawable[]
|
||||||
{
|
{
|
||||||
new RestoreDefaultValueButton<bool>
|
new Container
|
||||||
{
|
{
|
||||||
Current = isDefault,
|
RelativeSizeAxes = Axes.Y,
|
||||||
Action = RestoreDefaults,
|
Width = SettingsPanel.CONTENT_MARGINS,
|
||||||
Origin = Anchor.TopRight,
|
Child = new RestoreDefaultValueButton<bool>
|
||||||
|
{
|
||||||
|
Current = isDefault,
|
||||||
|
Action = RestoreDefaults,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
content = new Container
|
new Container
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
Masking = true,
|
Padding = new MarginPadding { Left = SettingsPanel.CONTENT_MARGINS },
|
||||||
CornerRadius = padding,
|
|
||||||
EdgeEffect = new EdgeEffectParameters
|
|
||||||
{
|
|
||||||
Radius = 2,
|
|
||||||
Colour = colourProvider.Highlight1.Opacity(0),
|
|
||||||
Type = EdgeEffectType.Shadow,
|
|
||||||
Hollow = true,
|
|
||||||
},
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new Box
|
content = new Container
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.X,
|
||||||
Colour = colourProvider.Background5,
|
AutoSizeAxes = Axes.Y,
|
||||||
},
|
Masking = true,
|
||||||
text = new OsuSpriteText
|
CornerRadius = padding,
|
||||||
{
|
EdgeEffect = new EdgeEffectParameters
|
||||||
Text = action.GetLocalisableDescription(),
|
{
|
||||||
Margin = new MarginPadding(1.5f * padding),
|
Radius = 2,
|
||||||
},
|
Colour = colourProvider.Highlight1.Opacity(0),
|
||||||
buttons = new FillFlowContainer<KeyButton>
|
Type = EdgeEffectType.Shadow,
|
||||||
{
|
Hollow = true,
|
||||||
AutoSizeAxes = Axes.Both,
|
},
|
||||||
Anchor = Anchor.TopRight,
|
|
||||||
Origin = Anchor.TopRight
|
|
||||||
},
|
|
||||||
cancelAndClearButtons = new FillFlowContainer
|
|
||||||
{
|
|
||||||
AutoSizeAxes = Axes.Both,
|
|
||||||
Padding = new MarginPadding(padding) { Top = height + padding * 2 },
|
|
||||||
Anchor = Anchor.TopRight,
|
|
||||||
Origin = Anchor.TopRight,
|
|
||||||
Alpha = 0,
|
|
||||||
Spacing = new Vector2(5),
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new CancelButton { Action = finalise },
|
new Box
|
||||||
new ClearButton { Action = clear },
|
{
|
||||||
},
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Colour = colourProvider.Background5,
|
||||||
|
},
|
||||||
|
text = new OsuSpriteText
|
||||||
|
{
|
||||||
|
Text = action.GetLocalisableDescription(),
|
||||||
|
Margin = new MarginPadding(1.5f * padding),
|
||||||
|
},
|
||||||
|
buttons = new FillFlowContainer<KeyButton>
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Anchor = Anchor.TopRight,
|
||||||
|
Origin = Anchor.TopRight
|
||||||
|
},
|
||||||
|
cancelAndClearButtons = new FillFlowContainer
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Padding = new MarginPadding(padding) { Top = height + padding * 2 },
|
||||||
|
Anchor = Anchor.TopRight,
|
||||||
|
Origin = Anchor.TopRight,
|
||||||
|
Alpha = 0,
|
||||||
|
Spacing = new Vector2(5),
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new CancelButton { Action = finalise },
|
||||||
|
new ClearButton { Action = clear },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -6,7 +6,6 @@ using System.Linq;
|
|||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osuTK;
|
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Settings
|
namespace osu.Game.Overlays.Settings
|
||||||
{
|
{
|
||||||
@ -28,11 +27,6 @@ namespace osu.Game.Overlays.Settings
|
|||||||
|
|
||||||
public override IEnumerable<string> FilterTerms => base.FilterTerms.Concat(Control.Items.Select(i => i.ToString()));
|
public override IEnumerable<string> FilterTerms => base.FilterTerms.Concat(Control.Items.Select(i => i.ToString()));
|
||||||
|
|
||||||
public SettingsDropdown()
|
|
||||||
{
|
|
||||||
FlowContent.Spacing = new Vector2(0, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected sealed override Drawable CreateControl() => CreateDropdown();
|
protected sealed override Drawable CreateControl() => CreateDropdown();
|
||||||
|
|
||||||
protected virtual OsuDropdown<T> CreateDropdown() => new DropdownControl();
|
protected virtual OsuDropdown<T> CreateDropdown() => new DropdownControl();
|
||||||
|
@ -14,6 +14,7 @@ using osu.Framework.Localisation;
|
|||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Settings
|
namespace osu.Game.Overlays.Settings
|
||||||
{
|
{
|
||||||
@ -34,6 +35,7 @@ namespace osu.Game.Overlays.Settings
|
|||||||
private OsuTextFlowContainer warningText;
|
private OsuTextFlowContainer warningText;
|
||||||
|
|
||||||
public bool ShowsDefaultIndicator = true;
|
public bool ShowsDefaultIndicator = true;
|
||||||
|
private readonly Container defaultValueIndicatorContainer;
|
||||||
|
|
||||||
public LocalisableString TooltipText { get; set; }
|
public LocalisableString TooltipText { get; set; }
|
||||||
|
|
||||||
@ -54,6 +56,7 @@ namespace osu.Game.Overlays.Settings
|
|||||||
}
|
}
|
||||||
|
|
||||||
labelText.Text = value;
|
labelText.Text = value;
|
||||||
|
updateLayout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,16 +111,23 @@ namespace osu.Game.Overlays.Settings
|
|||||||
|
|
||||||
InternalChildren = new Drawable[]
|
InternalChildren = new Drawable[]
|
||||||
{
|
{
|
||||||
FlowContent = new FillFlowContainer
|
defaultValueIndicatorContainer = new Container
|
||||||
|
{
|
||||||
|
Width = SettingsPanel.CONTENT_MARGINS,
|
||||||
|
},
|
||||||
|
new Container
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
Padding = new MarginPadding { Left = SettingsPanel.CONTENT_MARGINS },
|
Padding = new MarginPadding { Left = SettingsPanel.CONTENT_MARGINS },
|
||||||
Children = new[]
|
Child = FlowContent = new FillFlowContainer
|
||||||
{
|
{
|
||||||
Control = CreateControl(),
|
RelativeSizeAxes = Axes.X,
|
||||||
},
|
AutoSizeAxes = Axes.Y,
|
||||||
},
|
Spacing = new Vector2(0, 10),
|
||||||
|
Child = Control = CreateControl(),
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// IMPORTANT: all bindable logic is in constructor intentionally to support "CreateSettingsControls" being used in a context it is
|
// IMPORTANT: all bindable logic is in constructor intentionally to support "CreateSettingsControls" being used in a context it is
|
||||||
@ -135,13 +145,25 @@ namespace osu.Game.Overlays.Settings
|
|||||||
// intentionally done before LoadComplete to avoid overhead.
|
// intentionally done before LoadComplete to avoid overhead.
|
||||||
if (ShowsDefaultIndicator)
|
if (ShowsDefaultIndicator)
|
||||||
{
|
{
|
||||||
AddInternal(new RestoreDefaultValueButton<T>
|
defaultValueIndicatorContainer.Add(new RestoreDefaultValueButton<T>
|
||||||
{
|
{
|
||||||
Current = controlWithCurrent.Current,
|
Current = controlWithCurrent.Current,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre
|
||||||
});
|
});
|
||||||
|
updateLayout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateLayout()
|
||||||
|
{
|
||||||
|
bool hasLabel = labelText != null && !string.IsNullOrEmpty(labelText.Text.ToString());
|
||||||
|
|
||||||
|
// 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 = hasLabel ? labelText.DrawHeight : Control.DrawHeight;
|
||||||
|
}
|
||||||
|
|
||||||
private void updateDisabled()
|
private void updateDisabled()
|
||||||
{
|
{
|
||||||
if (labelText != null)
|
if (labelText != null)
|
||||||
|
@ -13,7 +13,6 @@ namespace osu.Game.Overlays.Settings
|
|||||||
protected override Drawable CreateControl() => new NumberControl
|
protected override Drawable CreateControl() => new NumberControl
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Margin = new MarginPadding { Top = 5 }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private sealed class NumberControl : CompositeDrawable, IHasCurrentValue<int?>
|
private sealed class NumberControl : CompositeDrawable, IHasCurrentValue<int?>
|
||||||
|
@ -19,7 +19,6 @@ namespace osu.Game.Overlays.Settings
|
|||||||
{
|
{
|
||||||
protected override Drawable CreateControl() => new TSlider
|
protected override Drawable CreateControl() => new TSlider
|
||||||
{
|
{
|
||||||
Margin = new MarginPadding { Vertical = 10 },
|
|
||||||
RelativeSizeAxes = Axes.X
|
RelativeSizeAxes = Axes.X
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ namespace osu.Game.Overlays.Settings
|
|||||||
{
|
{
|
||||||
protected override Drawable CreateControl() => new OutlinedTextBox
|
protected override Drawable CreateControl() => new OutlinedTextBox
|
||||||
{
|
{
|
||||||
Margin = new MarginPadding { Top = 5 },
|
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
CommitOnFocusLost = true
|
CommitOnFocusLost = true
|
||||||
};
|
};
|
||||||
|
@ -17,7 +17,6 @@ namespace osu.Game.Screens.Play.PlayerSettings
|
|||||||
|
|
||||||
protected override Drawable CreateControl() => new Sliderbar
|
protected override Drawable CreateControl() => new Sliderbar
|
||||||
{
|
{
|
||||||
Margin = new MarginPadding { Top = 5, Bottom = 5 },
|
|
||||||
RelativeSizeAxes = Axes.X
|
RelativeSizeAxes = Axes.X
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user