Adding Requested changed

This commit is contained in:
Swords
2021-05-15 11:24:08 +10:00
parent 843da30f9d
commit 304caf8bdf
5 changed files with 56 additions and 84 deletions

View File

@ -35,10 +35,10 @@ namespace osu.Game.Tests.Visual.Settings
AddStep("click first row", () => AddStep("click first row", () =>
{ {
InputManager.MoveMouseTo(panel.ChildrenOfType<SettingsKeyBindingRow>().First()); firstRow = panel.ChildrenOfType<KeyBindingRow>().First();
InputManager.Click(MouseButton.Left);
firstRow = panel.ChildrenOfType<SettingsKeyBindingRow>().First().KeyBindingRow; InputManager.MoveMouseTo(firstRow);
InputManager.Click(MouseButton.Left);
}); });
AddStep("schedule button clicks", () => AddStep("schedule button clicks", () =>
@ -72,7 +72,7 @@ namespace osu.Game.Tests.Visual.Settings
AddStep("click first row with two bindings", () => AddStep("click first row with two bindings", () =>
{ {
multiBindingRow = panel.ChildrenOfType<SettingsKeyBindingRow>().First(row => row.KeyBindingRow.Defaults.Count() > 1).KeyBindingRow; multiBindingRow = panel.ChildrenOfType<KeyBindingRow>().First(row => row.Defaults.Count() > 1);
InputManager.MoveMouseTo(multiBindingRow); InputManager.MoveMouseTo(multiBindingRow);
InputManager.Click(MouseButton.Left); InputManager.Click(MouseButton.Left);
}); });
@ -108,66 +108,55 @@ namespace osu.Game.Tests.Visual.Settings
[Test] [Test]
public void TestSingleBindResetButton() public void TestSingleBindResetButton()
{ {
KeyBindingRow multiBindingRow = null; SettingsKeyBindingRow settingsKeyBindingRow = null;
AddStep("click first row with two bindings", () => AddStep("click first row with two bindings", () =>
{ {
multiBindingRow = panel.ChildrenOfType<KeyBindingRow>().First(row => row.Defaults.Count() > 1); settingsKeyBindingRow = panel.ChildrenOfType<SettingsKeyBindingRow>().First(row => row.KeyBindingRow.Defaults.Count() > 1);
InputManager.MoveMouseTo(multiBindingRow); InputManager.MoveMouseTo(settingsKeyBindingRow.KeyBindingRow);
InputManager.Click(MouseButton.Left); InputManager.Click(MouseButton.Left);
InputManager.PressKey(Key.P); InputManager.PressKey(Key.P);
InputManager.ReleaseKey(Key.P); InputManager.ReleaseKey(Key.P);
}); });
AddUntilStep("restore button shown", () => panel.ChildrenOfType<SettingsKeyBindingRow>().First(row => row.KeyBindingRow.Defaults.Count() > 1).ChildrenOfType<RestoreDefaultValueButton<bool>>().First().Alpha > 0); AddUntilStep("restore button shown", () => settingsKeyBindingRow.ChildrenOfType<RestoreDefaultValueButton<bool>>().First().Alpha > 0);
clickSingleBindResetButton(); AddStep("click reset button for bindings", () =>
AddAssert("first binding cleared", () => panel.ChildrenOfType<SettingsKeyBindingRow>().First(row => row.KeyBindingRow.Defaults.Count() > 1).ChildrenOfType<KeyBindingRow.KeyButton>().ElementAt(0).KeyBinding.KeyCombination.Equals(multiBindingRow.Defaults.ElementAt(0)));
AddAssert("second binding cleared", () => panel.ChildrenOfType<SettingsKeyBindingRow>().First(row => row.KeyBindingRow.Defaults.Count() > 1).ChildrenOfType<KeyBindingRow.KeyButton>().ElementAt(1).KeyBinding.KeyCombination.Equals(multiBindingRow.Defaults.ElementAt(1)));
AddUntilStep("restore button hidden", () => panel.ChildrenOfType<SettingsKeyBindingRow>().First(row => row.KeyBindingRow.Defaults.Count() > 1).ChildrenOfType<RestoreDefaultValueButton<bool>>().First().Alpha == 0);
void clickSingleBindResetButton()
{ {
AddStep("click reset button for bindings", () => var clearButton = settingsKeyBindingRow.ChildrenOfType<RestoreDefaultValueButton<bool>>().Single();
{
var clearButton = panel.ChildrenOfType<SettingsKeyBindingRow>().First(row => row.KeyBindingRow.Defaults.Count() > 1).ChildrenOfType<RestoreDefaultValueButton<bool>>().Single();
InputManager.MoveMouseTo(clearButton); InputManager.MoveMouseTo(clearButton);
InputManager.Click(MouseButton.Left); InputManager.Click(MouseButton.Left);
}); });
}
AddUntilStep("restore button hidden", () => settingsKeyBindingRow.ChildrenOfType<RestoreDefaultValueButton<bool>>().First().Alpha == 0);
AddAssert("first binding cleared", () => settingsKeyBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().ElementAt(0).KeyBinding.KeyCombination.Equals(settingsKeyBindingRow.KeyBindingRow.Defaults.ElementAt(0)));
AddAssert("second binding cleared", () => settingsKeyBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().ElementAt(1).KeyBinding.KeyCombination.Equals(settingsKeyBindingRow.KeyBindingRow.Defaults.ElementAt(1)));
} }
[Test] [Test]
public void TestResetAllBindingsButton() public void TestResetAllBindingsButton()
{ {
KeyBindingRow multiBindingRow = null; KeyBindingRow keyBindingRow = null;
AddStep("click first row and press p", () => AddStep("click first row and press p", () =>
{ {
multiBindingRow = panel.ChildrenOfType<SettingsKeyBindingRow>().First().KeyBindingRow; keyBindingRow = panel.ChildrenOfType<KeyBindingRow>().First();
InputManager.MoveMouseTo(multiBindingRow); InputManager.MoveMouseTo(keyBindingRow);
InputManager.Click(MouseButton.Left); InputManager.Click(MouseButton.Left);
InputManager.PressKey(Key.P); InputManager.PressKey(Key.P);
InputManager.ReleaseKey(Key.P); InputManager.ReleaseKey(Key.P);
}); });
AddStep("click reset button for all bindings", () =>
clickResetAllBindingsButton();
AddAssert("bindings cleared", () => multiBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().ElementAt(0).KeyBinding.KeyCombination.Equals(multiBindingRow.Defaults.ElementAt(0)));
void clickResetAllBindingsButton()
{ {
AddStep("click reset button for all bindings", () => var clearButton = panel.ChildrenOfType<ResetButton>().First();
{
var clearButton = panel.ChildrenOfType<ResetButton>().First();
InputManager.MoveMouseTo(clearButton); InputManager.MoveMouseTo(clearButton);
InputManager.Click(MouseButton.Left); InputManager.Click(MouseButton.Left);
}); });
}
AddUntilStep("bindings cleared", () => keyBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().ElementAt(0).KeyBinding.KeyCombination.Equals(keyBindingRow.Defaults.ElementAt(0)));
} }
[Test] [Test]

View File

@ -53,7 +53,11 @@ namespace osu.Game.Overlays.KeyBinding
private FillFlowContainer cancelAndClearButtons; private FillFlowContainer cancelAndClearButtons;
private FillFlowContainer<KeyButton> buttons; private FillFlowContainer<KeyButton> buttons;
private readonly BindableWithCurrent<bool> isKeysDefaultValue; private readonly BindableWithCurrent<bool> isKeysDefaultValue = new BindableWithCurrent<bool>
{
Default = true
};
public Bindable<bool> Current public Bindable<bool> Current
{ {
@ -67,12 +71,6 @@ namespace osu.Game.Overlays.KeyBinding
{ {
this.action = action; this.action = action;
this.bindings = bindings; this.bindings = bindings;
isKeysDefaultValue = new BindableWithCurrent<bool>
{
Default = true
};
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
@ -89,7 +87,7 @@ namespace osu.Game.Overlays.KeyBinding
isKeysDefaultValue.Value = bindings.Select(b => b.KeyCombination).SequenceEqual(Defaults); isKeysDefaultValue.Value = bindings.Select(b => b.KeyCombination).SequenceEqual(Defaults);
isKeysDefaultValue.BindValueChanged(resetButtons => isKeysDefaultValue.BindValueChanged(resetButtons =>
{ {
if (resetButtons.NewValue != resetButtons.OldValue && resetButtons.NewValue && !bindings.Select(b => b.KeyCombination).SequenceEqual(Defaults)) if (resetButtons.NewValue && !bindings.Select(b => b.KeyCombination).SequenceEqual(Defaults))
{ {
RestoreDefaults(); RestoreDefaults();
finalise(); finalise();
@ -314,23 +312,7 @@ namespace osu.Game.Overlays.KeyBinding
{ {
store.Update(bindTarget.KeyBinding); store.Update(bindTarget.KeyBinding);
KeyCombination keyDefault = Defaults.ElementAt(buttons.IndexOf(bindTarget)); isKeysDefaultValue.Value = buttons.Select(b => b.KeyBinding.KeyCombination).SequenceEqual(Defaults);
if (isKeysDefaultValue.Value)
{
if (!keyDefault.Equals(bindTarget.KeyBinding.KeyCombination))
{
isKeysDefaultValue.Value = false;
}
}
else
{
if (keyDefault.Equals(bindTarget.KeyBinding.KeyCombination) &&
buttons.Select(b => b.KeyBinding.KeyCombination).SequenceEqual(Defaults))
{
isKeysDefaultValue.Value = true;
}
}
bindTarget.IsBinding = false; bindTarget.IsBinding = false;
Schedule(() => Schedule(() =>

View File

@ -12,7 +12,7 @@ namespace osu.Game.Overlays.KeyBinding
public class SettingsKeyBindingRow : Container, IFilterable public class SettingsKeyBindingRow : Container, IFilterable
{ {
private readonly IGrouping<object, Framework.Input.Bindings.KeyBinding> defaultGroup; private readonly IGrouping<object, Framework.Input.Bindings.KeyBinding> defaultGroup;
private readonly IEnumerable<Framework.Input.Bindings.KeyBinding> bindings; private readonly ICollection<Input.Bindings.DatabasedKeyBinding> bindings;
public readonly KeyBindingRow KeyBindingRow; public readonly KeyBindingRow KeyBindingRow;
private bool matchingFilter; private bool matchingFilter;
@ -33,7 +33,7 @@ namespace osu.Game.Overlays.KeyBinding
public SettingsKeyBindingRow( public SettingsKeyBindingRow(
IGrouping<object, Framework.Input.Bindings.KeyBinding> defaultGroup, IGrouping<object, Framework.Input.Bindings.KeyBinding> defaultGroup,
IEnumerable<Framework.Input.Bindings.KeyBinding> bindings, ICollection<Input.Bindings.DatabasedKeyBinding> bindings,
RulesetInfo ruleset) RulesetInfo ruleset)
{ {
this.defaultGroup = defaultGroup; this.defaultGroup = defaultGroup;
@ -63,7 +63,7 @@ namespace osu.Game.Overlays.KeyBinding
}, },
}; };
restoreDefaultButton.Bindable = KeyBindingRow.Current; restoreDefaultButton.Current = KeyBindingRow.Current;
} }
} }
} }

View File

@ -10,27 +10,27 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Graphics; using osu.Game.Graphics;
using osuTK; using osuTK;
namespace osu.Game.Overlays namespace osu.Game.Overlays
{ {
public class RestoreDefaultValueButton<T> : Container, IHasTooltip public class RestoreDefaultValueButton<T> : Container, IHasTooltip, IHasCurrentValue<T>
{ {
public override bool IsPresent => base.IsPresent || Scheduler.HasPendingTasks; public override bool IsPresent => base.IsPresent || Scheduler.HasPendingTasks;
private Bindable<T> bindable; private BindableWithCurrent<T> current = new BindableWithCurrent<T>();
public Bindable<T> Bindable public Bindable<T> Current
{ {
get => bindable; get => current.Current;
set set {
{ current.Current = value;
bindable = value; current.ValueChanged += _ => UpdateState();
bindable.ValueChanged += _ => UpdateState(); current.DisabledChanged += _ => UpdateState();
bindable.DisabledChanged += _ => UpdateState(); current.DefaultChanged += _ => UpdateState();
bindable.DefaultChanged += _ => UpdateState();
UpdateState(); UpdateState();
} }
} }
@ -43,6 +43,7 @@ namespace osu.Game.Overlays
{ {
RelativeSizeAxes = Axes.Y; RelativeSizeAxes = Axes.Y;
Width = SettingsPanel.CONTENT_MARGINS; Width = SettingsPanel.CONTENT_MARGINS;
Padding = new MarginPadding { Vertical = 1.5f };
Alpha = 0f; Alpha = 0f;
} }
@ -80,8 +81,8 @@ namespace osu.Game.Overlays
protected override bool OnClick(ClickEvent e) protected override bool OnClick(ClickEvent e)
{ {
if (bindable != null && !bindable.Disabled) if (current != null && !current.Disabled)
bindable.SetDefault(); current.SetDefault();
return true; return true;
} }
@ -108,12 +109,12 @@ namespace osu.Game.Overlays
private void updateState() private void updateState()
{ {
if (bindable == null) if (current == null)
return; return;
this.FadeTo(bindable.IsDefault ? 0f : this.FadeTo(current.IsDefault ? 0f :
hovering && !bindable.Disabled ? 1f : 0.65f, 200, Easing.OutQuint); hovering && !current.Disabled ? 1f : 0.65f, 200, Easing.OutQuint);
this.FadeColour(bindable.Disabled ? Color4.Gray : buttonColour, 200, Easing.OutQuint); this.FadeColour(current.Disabled ? Color4.Gray : buttonColour, 200, Easing.OutQuint);
} }
} }
} }

View File

@ -132,7 +132,7 @@ namespace osu.Game.Overlays.Settings
controlWithCurrent.Current.DisabledChanged += _ => updateDisabled(); controlWithCurrent.Current.DisabledChanged += _ => updateDisabled();
if (ShowsDefaultIndicator) if (ShowsDefaultIndicator)
restoreDefaultButton.Bindable = controlWithCurrent.Current; restoreDefaultButton.Current = controlWithCurrent.Current;
} }
} }