mirror of
https://github.com/ppy/osu
synced 2025-01-03 12:52:10 +00:00
Adding Requested changed
This commit is contained in:
parent
843da30f9d
commit
304caf8bdf
@ -35,10 +35,10 @@ namespace osu.Game.Tests.Visual.Settings
|
||||
|
||||
AddStep("click first row", () =>
|
||||
{
|
||||
InputManager.MoveMouseTo(panel.ChildrenOfType<SettingsKeyBindingRow>().First());
|
||||
InputManager.Click(MouseButton.Left);
|
||||
firstRow = panel.ChildrenOfType<KeyBindingRow>().First();
|
||||
|
||||
firstRow = panel.ChildrenOfType<SettingsKeyBindingRow>().First().KeyBindingRow;
|
||||
InputManager.MoveMouseTo(firstRow);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
||||
AddStep("schedule button clicks", () =>
|
||||
@ -72,7 +72,7 @@ namespace osu.Game.Tests.Visual.Settings
|
||||
|
||||
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.Click(MouseButton.Left);
|
||||
});
|
||||
@ -108,66 +108,55 @@ namespace osu.Game.Tests.Visual.Settings
|
||||
[Test]
|
||||
public void TestSingleBindResetButton()
|
||||
{
|
||||
KeyBindingRow multiBindingRow = null;
|
||||
SettingsKeyBindingRow settingsKeyBindingRow = null;
|
||||
|
||||
AddStep("click first row with two bindings", () =>
|
||||
{
|
||||
multiBindingRow = panel.ChildrenOfType<KeyBindingRow>().First(row => row.Defaults.Count() > 1);
|
||||
InputManager.MoveMouseTo(multiBindingRow);
|
||||
settingsKeyBindingRow = panel.ChildrenOfType<SettingsKeyBindingRow>().First(row => row.KeyBindingRow.Defaults.Count() > 1);
|
||||
InputManager.MoveMouseTo(settingsKeyBindingRow.KeyBindingRow);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
InputManager.PressKey(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();
|
||||
|
||||
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", () =>
|
||||
{
|
||||
AddStep("click reset button for bindings", () =>
|
||||
{
|
||||
var clearButton = panel.ChildrenOfType<SettingsKeyBindingRow>().First(row => row.KeyBindingRow.Defaults.Count() > 1).ChildrenOfType<RestoreDefaultValueButton<bool>>().Single();
|
||||
var clearButton = settingsKeyBindingRow.ChildrenOfType<RestoreDefaultValueButton<bool>>().Single();
|
||||
|
||||
InputManager.MoveMouseTo(clearButton);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
}
|
||||
InputManager.MoveMouseTo(clearButton);
|
||||
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]
|
||||
public void TestResetAllBindingsButton()
|
||||
{
|
||||
KeyBindingRow multiBindingRow = null;
|
||||
KeyBindingRow keyBindingRow = null;
|
||||
|
||||
AddStep("click first row and press p", () =>
|
||||
{
|
||||
multiBindingRow = panel.ChildrenOfType<SettingsKeyBindingRow>().First().KeyBindingRow;
|
||||
InputManager.MoveMouseTo(multiBindingRow);
|
||||
keyBindingRow = panel.ChildrenOfType<KeyBindingRow>().First();
|
||||
InputManager.MoveMouseTo(keyBindingRow);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
InputManager.PressKey(Key.P);
|
||||
InputManager.ReleaseKey(Key.P);
|
||||
});
|
||||
|
||||
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", () =>
|
||||
{
|
||||
AddStep("click reset button for all bindings", () =>
|
||||
{
|
||||
var clearButton = panel.ChildrenOfType<ResetButton>().First();
|
||||
var clearButton = panel.ChildrenOfType<ResetButton>().First();
|
||||
|
||||
InputManager.MoveMouseTo(clearButton);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
}
|
||||
InputManager.MoveMouseTo(clearButton);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
||||
AddUntilStep("bindings cleared", () => keyBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().ElementAt(0).KeyBinding.KeyCombination.Equals(keyBindingRow.Defaults.ElementAt(0)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -53,7 +53,11 @@ namespace osu.Game.Overlays.KeyBinding
|
||||
private FillFlowContainer cancelAndClearButtons;
|
||||
private FillFlowContainer<KeyButton> buttons;
|
||||
|
||||
private readonly BindableWithCurrent<bool> isKeysDefaultValue;
|
||||
private readonly BindableWithCurrent<bool> isKeysDefaultValue = new BindableWithCurrent<bool>
|
||||
{
|
||||
Default = true
|
||||
};
|
||||
|
||||
|
||||
public Bindable<bool> Current
|
||||
{
|
||||
@ -67,12 +71,6 @@ namespace osu.Game.Overlays.KeyBinding
|
||||
{
|
||||
this.action = action;
|
||||
this.bindings = bindings;
|
||||
|
||||
isKeysDefaultValue = new BindableWithCurrent<bool>
|
||||
{
|
||||
Default = true
|
||||
};
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
|
||||
@ -89,7 +87,7 @@ namespace osu.Game.Overlays.KeyBinding
|
||||
isKeysDefaultValue.Value = bindings.Select(b => b.KeyCombination).SequenceEqual(Defaults);
|
||||
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();
|
||||
finalise();
|
||||
@ -314,23 +312,7 @@ namespace osu.Game.Overlays.KeyBinding
|
||||
{
|
||||
store.Update(bindTarget.KeyBinding);
|
||||
|
||||
KeyCombination keyDefault = Defaults.ElementAt(buttons.IndexOf(bindTarget));
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
isKeysDefaultValue.Value = buttons.Select(b => b.KeyBinding.KeyCombination).SequenceEqual(Defaults);
|
||||
|
||||
bindTarget.IsBinding = false;
|
||||
Schedule(() =>
|
||||
|
@ -12,7 +12,7 @@ namespace osu.Game.Overlays.KeyBinding
|
||||
public class SettingsKeyBindingRow : Container, IFilterable
|
||||
{
|
||||
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;
|
||||
|
||||
private bool matchingFilter;
|
||||
@ -33,7 +33,7 @@ namespace osu.Game.Overlays.KeyBinding
|
||||
|
||||
public SettingsKeyBindingRow(
|
||||
IGrouping<object, Framework.Input.Bindings.KeyBinding> defaultGroup,
|
||||
IEnumerable<Framework.Input.Bindings.KeyBinding> bindings,
|
||||
ICollection<Input.Bindings.DatabasedKeyBinding> bindings,
|
||||
RulesetInfo ruleset)
|
||||
{
|
||||
this.defaultGroup = defaultGroup;
|
||||
@ -63,7 +63,7 @@ namespace osu.Game.Overlays.KeyBinding
|
||||
},
|
||||
};
|
||||
|
||||
restoreDefaultButton.Bindable = KeyBindingRow.Current;
|
||||
restoreDefaultButton.Current = KeyBindingRow.Current;
|
||||
}
|
||||
}
|
||||
}
|
@ -10,27 +10,27 @@ using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Graphics.Effects;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Graphics;
|
||||
using osuTK;
|
||||
|
||||
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;
|
||||
|
||||
private Bindable<T> bindable;
|
||||
private BindableWithCurrent<T> current = new BindableWithCurrent<T>();
|
||||
|
||||
public Bindable<T> Bindable
|
||||
public Bindable<T> Current
|
||||
{
|
||||
get => bindable;
|
||||
set
|
||||
{
|
||||
bindable = value;
|
||||
bindable.ValueChanged += _ => UpdateState();
|
||||
bindable.DisabledChanged += _ => UpdateState();
|
||||
bindable.DefaultChanged += _ => UpdateState();
|
||||
get => current.Current;
|
||||
set {
|
||||
current.Current = value;
|
||||
current.ValueChanged += _ => UpdateState();
|
||||
current.DisabledChanged += _ => UpdateState();
|
||||
current.DefaultChanged += _ => UpdateState();
|
||||
UpdateState();
|
||||
}
|
||||
}
|
||||
@ -43,6 +43,7 @@ namespace osu.Game.Overlays
|
||||
{
|
||||
RelativeSizeAxes = Axes.Y;
|
||||
Width = SettingsPanel.CONTENT_MARGINS;
|
||||
Padding = new MarginPadding { Vertical = 1.5f };
|
||||
Alpha = 0f;
|
||||
}
|
||||
|
||||
@ -80,8 +81,8 @@ namespace osu.Game.Overlays
|
||||
|
||||
protected override bool OnClick(ClickEvent e)
|
||||
{
|
||||
if (bindable != null && !bindable.Disabled)
|
||||
bindable.SetDefault();
|
||||
if (current != null && !current.Disabled)
|
||||
current.SetDefault();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -108,12 +109,12 @@ namespace osu.Game.Overlays
|
||||
|
||||
private void updateState()
|
||||
{
|
||||
if (bindable == null)
|
||||
if (current == null)
|
||||
return;
|
||||
|
||||
this.FadeTo(bindable.IsDefault ? 0f :
|
||||
hovering && !bindable.Disabled ? 1f : 0.65f, 200, Easing.OutQuint);
|
||||
this.FadeColour(bindable.Disabled ? Color4.Gray : buttonColour, 200, Easing.OutQuint);
|
||||
this.FadeTo(current.IsDefault ? 0f :
|
||||
hovering && !current.Disabled ? 1f : 0.65f, 200, Easing.OutQuint);
|
||||
this.FadeColour(current.Disabled ? Color4.Gray : buttonColour, 200, Easing.OutQuint);
|
||||
}
|
||||
}
|
||||
}
|
@ -132,7 +132,7 @@ namespace osu.Game.Overlays.Settings
|
||||
controlWithCurrent.Current.DisabledChanged += _ => updateDisabled();
|
||||
|
||||
if (ShowsDefaultIndicator)
|
||||
restoreDefaultButton.Bindable = controlWithCurrent.Current;
|
||||
restoreDefaultButton.Current = controlWithCurrent.Current;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user