1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 03:27:24 +08:00

Merge branch 'master' into localise-toasts

This commit is contained in:
smoogipoo 2021-10-20 15:04:07 +09:00
commit 2c979d6420
19 changed files with 440 additions and 184 deletions

View File

@ -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);
}
}
}

View File

@ -5,6 +5,9 @@ using System.Linq;
using NUnit.Framework;
using osu.Framework.Bindables;
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;
@ -29,9 +32,10 @@ namespace osu.Game.Tests.Visual.Settings
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);
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);
}
[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>
/// 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).
@ -64,9 +110,9 @@ namespace osu.Game.Tests.Visual.Settings
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);

View File

@ -0,0 +1,20 @@
// 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.Graphics;
using osu.Game.Beatmaps;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Tests.Visual.UserInterface
{
public class TestSceneOsuDropdown : ThemeComparisonTestScene
{
protected override Drawable CreateContent() =>
new OsuEnumDropdown<BeatmapSetOnlineStatus>
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Width = 150
};
}
}

View File

@ -0,0 +1,69 @@
// 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 System;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Overlays;
namespace osu.Game.Tests.Visual.UserInterface
{
public abstract class ThemeComparisonTestScene : OsuGridTestScene
{
protected ThemeComparisonTestScene()
: base(1, 2)
{
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Cell(0, 0).AddRange(new[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colours.GreySeafoam
},
CreateContent()
});
}
private void createThemedContent(OverlayColourScheme colourScheme)
{
var colourProvider = new OverlayColourProvider(colourScheme);
Cell(0, 1).Clear();
Cell(0, 1).Add(new DependencyProvidingContainer
{
RelativeSizeAxes = Axes.Both,
CachedDependencies = new (Type, object)[]
{
(typeof(OverlayColourProvider), colourProvider)
},
Children = new[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background4
},
CreateContent()
}
});
}
protected abstract Drawable CreateContent();
[Test]
public void TestAllColourSchemes()
{
foreach (var scheme in Enum.GetValues(typeof(OverlayColourScheme)).Cast<OverlayColourScheme>())
AddStep($"set {scheme} scheme", () => createThemedContent(scheme));
}
}
}

View File

@ -181,7 +181,11 @@ namespace osu.Game.Collections
MaxHeight = 200;
}
protected override DrawableDropdownMenuItem CreateDrawableDropdownMenuItem(MenuItem item) => new CollectionDropdownMenuItem(item);
protected override DrawableDropdownMenuItem CreateDrawableDropdownMenuItem(MenuItem item) => new CollectionDropdownMenuItem(item)
{
BackgroundColourHover = HoverColour,
BackgroundColourSelected = SelectionColour
};
}
protected class CollectionDropdownMenuItem : OsuDropdownMenu.DrawableOsuDropdownMenuItem

View File

@ -235,11 +235,18 @@ namespace osu.Game.Graphics
/// </summary>
public readonly Color4 Blue3 = Color4Extensions.FromHex(@"3399cc");
public readonly Color4 Lime0 = Color4Extensions.FromHex(@"ccff99");
/// <summary>
/// Equivalent to <see cref="OverlayColourProvider.Lime"/>'s <see cref="OverlayColourProvider.Colour1"/>.
/// </summary>
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>
/// Equivalent to <see cref="OverlayColourProvider.Orange"/>'s <see cref="OverlayColourProvider.Colour1"/>.
/// </summary>

View File

@ -21,44 +21,17 @@ using osuTK.Graphics;
namespace osu.Game.Graphics.UserInterface
{
public class OsuDropdown<T> : Dropdown<T>, IHasAccentColour
public class OsuDropdown<T> : Dropdown<T>
{
private const float corner_radius = 5;
private Color4 accentColour;
public Color4 AccentColour
{
get => accentColour;
set
{
accentColour = value;
updateAccentColour();
}
}
[BackgroundDependencyLoader(true)]
private void load(OverlayColourProvider? colourProvider, OsuColour colours)
{
if (accentColour == default)
accentColour = colourProvider?.Light4 ?? colours.PinkDarker;
updateAccentColour();
}
private void updateAccentColour()
{
if (Header is IHasAccentColour header) header.AccentColour = accentColour;
if (Menu is IHasAccentColour menu) menu.AccentColour = accentColour;
}
protected override DropdownHeader CreateHeader() => new OsuDropdownHeader();
protected override DropdownMenu CreateMenu() => new OsuDropdownMenu();
#region OsuDropdownMenu
protected class OsuDropdownMenu : DropdownMenu, IHasAccentColour
protected class OsuDropdownMenu : DropdownMenu
{
public override bool HandleNonPositionalInput => State == MenuState.Open;
@ -78,9 +51,11 @@ namespace osu.Game.Graphics.UserInterface
}
[BackgroundDependencyLoader(true)]
private void load(OverlayColourProvider? colourProvider, AudioManager audio)
private void load(OverlayColourProvider? colourProvider, OsuColour colours, AudioManager audio)
{
BackgroundColour = colourProvider?.Background5 ?? Color4.Black.Opacity(0.5f);
HoverColour = colourProvider?.Light4 ?? colours.PinkDarker;
SelectionColour = colourProvider?.Background3 ?? colours.PinkDarker.Opacity(0.5f);
sampleOpen = audio.Samples.Get(@"UI/dropdown-open");
sampleClose = audio.Samples.Get(@"UI/dropdown-close");
@ -121,57 +96,77 @@ namespace osu.Game.Graphics.UserInterface
}
}
private Color4 accentColour;
private Color4 hoverColour;
public Color4 AccentColour
public Color4 HoverColour
{
get => accentColour;
get => hoverColour;
set
{
accentColour = value;
foreach (var c in Children.OfType<IHasAccentColour>())
c.AccentColour = value;
hoverColour = value;
foreach (var c in Children.OfType<DrawableOsuDropdownMenuItem>())
c.BackgroundColourHover = value;
}
}
private Color4 selectionColour;
public Color4 SelectionColour
{
get => selectionColour;
set
{
selectionColour = value;
foreach (var c in Children.OfType<DrawableOsuDropdownMenuItem>())
c.BackgroundColourSelected = value;
}
}
protected override Menu CreateSubMenu() => new OsuMenu(Direction.Vertical);
protected override DrawableDropdownMenuItem CreateDrawableDropdownMenuItem(MenuItem item) => new DrawableOsuDropdownMenuItem(item) { AccentColour = accentColour };
protected override DrawableDropdownMenuItem CreateDrawableDropdownMenuItem(MenuItem item) => new DrawableOsuDropdownMenuItem(item)
{
BackgroundColourHover = HoverColour,
BackgroundColourSelected = SelectionColour
};
protected override ScrollContainer<Drawable> CreateScrollContainer(Direction direction) => new OsuScrollContainer(direction);
#region DrawableOsuDropdownMenuItem
public class DrawableOsuDropdownMenuItem : DrawableDropdownMenuItem, IHasAccentColour
public class DrawableOsuDropdownMenuItem : DrawableDropdownMenuItem
{
// IsHovered is used
public override bool HandlePositionalInput => true;
private Color4? accentColour;
public Color4 AccentColour
public new Color4 BackgroundColourHover
{
get => accentColour ?? nonAccentSelectedColour;
get => base.BackgroundColourHover;
set
{
accentColour = value;
base.BackgroundColourHover = value;
updateColours();
}
}
public new Color4 BackgroundColourSelected
{
get => base.BackgroundColourSelected;
set
{
base.BackgroundColourSelected = value;
updateColours();
}
}
private void updateColours()
{
BackgroundColourHover = accentColour ?? nonAccentHoverColour;
BackgroundColourSelected = accentColour ?? nonAccentSelectedColour;
BackgroundColour = BackgroundColourHover.Opacity(0);
UpdateBackgroundColour();
UpdateForegroundColour();
}
private Color4 nonAccentHoverColour;
private Color4 nonAccentSelectedColour;
public DrawableOsuDropdownMenuItem(MenuItem item)
: base(item)
{
@ -182,12 +177,8 @@ namespace osu.Game.Graphics.UserInterface
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
private void load()
{
nonAccentHoverColour = colours.PinkDarker;
nonAccentSelectedColour = Color4.Black.Opacity(0.5f);
updateColours();
AddInternal(new HoverSounds());
}
@ -290,7 +281,7 @@ namespace osu.Game.Graphics.UserInterface
#endregion
public class OsuDropdownHeader : DropdownHeader, IHasAccentColour
public class OsuDropdownHeader : DropdownHeader
{
protected readonly SpriteText Text;
@ -302,18 +293,6 @@ namespace osu.Game.Graphics.UserInterface
protected readonly SpriteIcon Icon;
private Color4 accentColour;
public virtual Color4 AccentColour
{
get => accentColour;
set
{
accentColour = value;
BackgroundColourHover = accentColour;
}
}
public OsuDropdownHeader()
{
Foreground.Padding = new MarginPadding(10);

View File

@ -11,13 +11,33 @@ using osu.Framework.Input.Events;
namespace osu.Game.Graphics.UserInterface
{
public class OsuTabDropdown<T> : OsuDropdown<T>
public class OsuTabDropdown<T> : OsuDropdown<T>, IHasAccentColour
{
private Color4 accentColour;
public Color4 AccentColour
{
get => accentColour;
set
{
accentColour = value;
if (IsLoaded)
propagateAccentColour();
}
}
public OsuTabDropdown()
{
RelativeSizeAxes = Axes.X;
}
protected override void LoadComplete()
{
base.LoadComplete();
propagateAccentColour();
}
protected override DropdownMenu CreateMenu() => new OsuTabDropdownMenu();
protected override DropdownHeader CreateHeader() => new OsuTabDropdownHeader
@ -26,6 +46,18 @@ namespace osu.Game.Graphics.UserInterface
Origin = Anchor.TopRight
};
private void propagateAccentColour()
{
if (Menu is OsuDropdownMenu dropdownMenu)
{
dropdownMenu.HoverColour = accentColour;
dropdownMenu.SelectionColour = accentColour.Opacity(0.5f);
}
if (Header is OsuTabDropdownHeader tabDropdownHeader)
tabDropdownHeader.AccentColour = accentColour;
}
private class OsuTabDropdownMenu : OsuDropdownMenu
{
public OsuTabDropdownMenu()
@ -37,7 +69,7 @@ namespace osu.Game.Graphics.UserInterface
MaxHeight = 400;
}
protected override DrawableDropdownMenuItem CreateDrawableDropdownMenuItem(MenuItem item) => new DrawableOsuTabDropdownMenuItem(item) { AccentColour = AccentColour };
protected override DrawableDropdownMenuItem CreateDrawableDropdownMenuItem(MenuItem item) => new DrawableOsuTabDropdownMenuItem(item);
private class DrawableOsuTabDropdownMenuItem : DrawableOsuDropdownMenuItem
{
@ -49,15 +81,18 @@ namespace osu.Game.Graphics.UserInterface
}
}
protected class OsuTabDropdownHeader : OsuDropdownHeader
protected class OsuTabDropdownHeader : OsuDropdownHeader, IHasAccentColour
{
public override Color4 AccentColour
private Color4 accentColour;
public Color4 AccentColour
{
get => base.AccentColour;
get => accentColour;
set
{
base.AccentColour = value;
Foreground.Colour = value;
accentColour = value;
BackgroundColourHover = value;
updateColour();
}
}
@ -93,15 +128,20 @@ namespace osu.Game.Graphics.UserInterface
protected override bool OnHover(HoverEvent e)
{
Foreground.Colour = BackgroundColour;
updateColour();
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
Foreground.Colour = BackgroundColourHover;
updateColour();
base.OnHoverLost(e);
}
private void updateColour()
{
Foreground.Colour = IsHovered ? BackgroundColour : BackgroundColourHover;
}
}
}
}

View File

@ -29,12 +29,6 @@ namespace osu.Game.Overlays.Login
}
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
AccentColour = colours.Gray5;
}
protected class UserDropdownMenu : OsuDropdownMenu
{
public UserDropdownMenu()
@ -56,6 +50,8 @@ namespace osu.Game.Overlays.Login
private void load(OsuColour colours)
{
BackgroundColour = colours.Gray3;
SelectionColour = colours.Gray4;
HoverColour = colours.Gray5;
}
protected override DrawableDropdownMenuItem CreateDrawableDropdownMenuItem(MenuItem item) => new DrawableUserDropdownMenuItem(item);
@ -118,6 +114,7 @@ namespace osu.Game.Overlays.Login
private void load(OsuColour colours)
{
BackgroundColour = colours.Gray3;
BackgroundColourHover = colours.Gray5;
}
}
}

View File

@ -19,12 +19,6 @@ namespace osu.Game.Overlays.Music
{
protected override bool ShowManageCollectionsItem => false;
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
AccentColour = colours.Gray6;
}
protected override CollectionDropdownHeader CreateCollectionHeader() => new CollectionsHeader();
protected override CollectionDropdownMenu CreateCollectionMenu() => new CollectionsMenu();
@ -41,6 +35,8 @@ namespace osu.Game.Overlays.Music
private void load(OsuColour colours)
{
BackgroundColour = colours.Gray4;
SelectionColour = colours.Gray5;
HoverColour = colours.Gray6;
}
}
@ -50,6 +46,7 @@ namespace osu.Game.Overlays.Music
private void load(OsuColour colours)
{
BackgroundColour = colours.Gray4;
BackgroundColourHover = colours.Gray6;
}
public CollectionsHeader()

View File

@ -175,18 +175,18 @@ namespace osu.Game.Overlays.Rankings
private class SpotlightsDropdown : OsuDropdown<APISpotlight>
{
private DropdownMenu menu;
private OsuDropdownMenu menu;
protected override DropdownMenu CreateMenu() => menu = base.CreateMenu().With(m => m.MaxHeight = 400);
protected override DropdownMenu CreateMenu() => menu = (OsuDropdownMenu)base.CreateMenu().With(m => m.MaxHeight = 400);
protected override DropdownHeader CreateHeader() => new SpotlightsDropdownHeader();
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
// osu-web adds a 0.6 opacity container on top of the 0.5 base one when hovering, 0.8 on a single container here matches the resulting colour
AccentColour = colourProvider.Background6.Opacity(0.8f);
menu.BackgroundColour = colourProvider.Background5;
menu.HoverColour = colourProvider.Background4;
menu.SelectionColour = colourProvider.Background3;
Padding = new MarginPadding { Vertical = 20 };
}
@ -205,7 +205,8 @@ namespace osu.Game.Overlays.Rankings
private void load(OverlayColourProvider colourProvider)
{
BackgroundColour = colourProvider.Background6.Opacity(0.5f);
BackgroundColourHover = colourProvider.Background5;
// osu-web adds a 0.6 opacity container on top of the 0.5 base one when hovering, 0.8 on a single container here matches the resulting colour
BackgroundColourHover = colourProvider.Background6.Opacity(0.8f);
}
}
}

View File

@ -3,10 +3,8 @@
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osuTK.Graphics;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.UserInterface;
@ -14,6 +12,7 @@ using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using osuTK;
namespace osu.Game.Overlays
{
@ -45,30 +44,21 @@ namespace osu.Game.Overlays
}
}
private bool hovering;
[Resolved]
private OsuColour colours { get; set; }
public RestoreDefaultValueButton()
{
Height = 1;
RelativeSizeAxes = Axes.Y;
Width = SettingsPanel.CONTENT_MARGINS;
}
private const float size = 4;
[BackgroundDependencyLoader]
private void load(OsuColour colour)
{
BackgroundColour = colour.Yellow;
Content.Width = 0.33f;
Content.CornerRadius = 3;
Content.EdgeEffect = new EdgeEffectParameters
{
Colour = BackgroundColour.Opacity(0.1f),
Type = EdgeEffectType.Glow,
Radius = 2,
};
BackgroundColour = colour.Lime1;
Size = new Vector2(3 * size);
Content.RelativeSizeAxes = Axes.None;
Content.Size = new Vector2(size);
Content.CornerRadius = size / 2;
Padding = new MarginPadding { Vertical = 1.5f };
Alpha = 0f;
Action += () =>
@ -81,39 +71,55 @@ namespace osu.Game.Overlays
protected override void LoadComplete()
{
base.LoadComplete();
// avoid unnecessary transforms on first display.
Alpha = currentAlpha;
Background.Colour = currentColour;
updateState();
FinishTransforms(true);
}
public LocalisableString TooltipText => "revert to default";
protected override bool OnHover(HoverEvent e)
{
hovering = true;
UpdateState();
return false;
}
protected override void OnHoverLost(HoverLostEvent e)
{
hovering = false;
UpdateState();
}
public void UpdateState() => Scheduler.AddOnce(updateState);
private float currentAlpha => current.IsDefault ? 0f : hovering && !current.Disabled ? 1f : 0.65f;
private ColourInfo currentColour => current.Disabled ? Color4.Gray : BackgroundColour;
private const double fade_duration = 200;
private void updateState()
{
if (current == null)
return;
this.FadeTo(currentAlpha, 200, Easing.OutQuint);
Background.FadeColour(currentColour, 200, Easing.OutQuint);
Enabled.Value = !Current.Disabled;
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);
}
}
}
}

View File

@ -82,60 +82,75 @@ namespace osu.Game.Overlays.Settings.Sections.Input
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Padding = new MarginPadding { Horizontal = SettingsPanel.CONTENT_MARGINS };
Padding = new MarginPadding { Right = SettingsPanel.CONTENT_MARGINS };
InternalChildren = new Drawable[]
{
new RestoreDefaultValueButton<bool>
new Container
{
Current = isDefault,
Action = RestoreDefaults,
Origin = Anchor.TopRight,
RelativeSizeAxes = Axes.Y,
Width = SettingsPanel.CONTENT_MARGINS,
Child = new RestoreDefaultValueButton<bool>
{
Current = isDefault,
Action = RestoreDefaults,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}
},
content = new Container
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Masking = true,
CornerRadius = padding,
EdgeEffect = new EdgeEffectParameters
{
Radius = 2,
Colour = colourProvider.Highlight1.Opacity(0),
Type = EdgeEffectType.Shadow,
Hollow = true,
},
Padding = new MarginPadding { Left = SettingsPanel.CONTENT_MARGINS },
Children = new Drawable[]
{
new Box
content = new Container
{
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),
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Masking = true,
CornerRadius = padding,
EdgeEffect = new EdgeEffectParameters
{
Radius = 2,
Colour = colourProvider.Highlight1.Opacity(0),
Type = EdgeEffectType.Shadow,
Hollow = true,
},
Children = new Drawable[]
{
new CancelButton { Action = finalise },
new ClearButton { Action = clear },
},
new Box
{
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 },
},
}
}
}
}
},

View File

@ -6,7 +6,6 @@ using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Graphics.UserInterface;
using osuTK;
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 SettingsDropdown()
{
FlowContent.Spacing = new Vector2(0, 10);
}
protected sealed override Drawable CreateControl() => CreateDropdown();
protected virtual OsuDropdown<T> CreateDropdown() => new DropdownControl();

View File

@ -14,6 +14,7 @@ using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.Containers;
using osuTK;
namespace osu.Game.Overlays.Settings
{
@ -34,6 +35,7 @@ namespace osu.Game.Overlays.Settings
private OsuTextFlowContainer warningText;
public bool ShowsDefaultIndicator = true;
private readonly Container defaultValueIndicatorContainer;
public LocalisableString TooltipText { get; set; }
@ -54,6 +56,7 @@ namespace osu.Game.Overlays.Settings
}
labelText.Text = value;
updateLayout();
}
}
@ -108,16 +111,23 @@ namespace osu.Game.Overlays.Settings
InternalChildren = new Drawable[]
{
FlowContent = new FillFlowContainer
defaultValueIndicatorContainer = new Container
{
Width = SettingsPanel.CONTENT_MARGINS,
},
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
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
@ -135,13 +145,25 @@ namespace osu.Game.Overlays.Settings
// intentionally done before LoadComplete to avoid overhead.
if (ShowsDefaultIndicator)
{
AddInternal(new RestoreDefaultValueButton<T>
defaultValueIndicatorContainer.Add(new RestoreDefaultValueButton<T>
{
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()
{
if (labelText != null)

View File

@ -13,7 +13,6 @@ namespace osu.Game.Overlays.Settings
protected override Drawable CreateControl() => new NumberControl
{
RelativeSizeAxes = Axes.X,
Margin = new MarginPadding { Top = 5 }
};
private sealed class NumberControl : CompositeDrawable, IHasCurrentValue<int?>

View File

@ -19,7 +19,6 @@ namespace osu.Game.Overlays.Settings
{
protected override Drawable CreateControl() => new TSlider
{
Margin = new MarginPadding { Vertical = 10 },
RelativeSizeAxes = Axes.X
};

View File

@ -11,7 +11,6 @@ namespace osu.Game.Overlays.Settings
{
protected override Drawable CreateControl() => new OutlinedTextBox
{
Margin = new MarginPadding { Top = 5 },
RelativeSizeAxes = Axes.X,
CommitOnFocusLost = true
};

View File

@ -17,7 +17,6 @@ namespace osu.Game.Screens.Play.PlayerSettings
protected override Drawable CreateControl() => new Sliderbar
{
Margin = new MarginPadding { Top = 5, Bottom = 5 },
RelativeSizeAxes = Axes.X
};