mirror of
https://github.com/ppy/osu.git
synced 2025-03-19 01:58:46 +08:00
Resolve RestoreDefaultValueButton
issue by internal management
This commit is contained in:
parent
2b366e04fd
commit
612ed6353c
@ -20,15 +20,30 @@ namespace osu.Game.Overlays
|
||||
{
|
||||
public override bool IsPresent => base.IsPresent || Scheduler.HasPendingTasks;
|
||||
|
||||
private readonly BindableWithCurrent<T> current = new BindableWithCurrent<T>();
|
||||
|
||||
// this is done to ensure a click on this button doesn't trigger focus on a parent element which contains the button.
|
||||
public override bool AcceptsFocus => true;
|
||||
|
||||
private Bindable<T> current;
|
||||
|
||||
public Bindable<T> Current
|
||||
{
|
||||
get => current.Current;
|
||||
set => current.Current = value;
|
||||
get => current;
|
||||
set
|
||||
{
|
||||
if (current != null)
|
||||
{
|
||||
current.ValueChanged -= onValueChanged;
|
||||
current.DefaultChanged -= onDefaultChanged;
|
||||
current.DisabledChanged -= onDisabledChanged;
|
||||
}
|
||||
|
||||
current = value;
|
||||
|
||||
current.ValueChanged += onValueChanged;
|
||||
current.DefaultChanged += onDefaultChanged;
|
||||
current.DisabledChanged += onDisabledChanged;
|
||||
UpdateState();
|
||||
}
|
||||
}
|
||||
|
||||
private Color4 buttonColour;
|
||||
@ -62,21 +77,11 @@ namespace osu.Game.Overlays
|
||||
|
||||
Action += () =>
|
||||
{
|
||||
if (!current.Disabled) current.SetDefault();
|
||||
if (!current.Disabled)
|
||||
current.SetDefault();
|
||||
};
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
Current.ValueChanged += _ => UpdateState();
|
||||
Current.DisabledChanged += _ => UpdateState();
|
||||
Current.DefaultChanged += _ => UpdateState();
|
||||
|
||||
UpdateState();
|
||||
}
|
||||
|
||||
public LocalisableString TooltipText => "revert to default";
|
||||
|
||||
protected override bool OnHover(HoverEvent e)
|
||||
@ -92,6 +97,10 @@ namespace osu.Game.Overlays
|
||||
UpdateState();
|
||||
}
|
||||
|
||||
private void onValueChanged(ValueChangedEvent<T> _) => UpdateState();
|
||||
private void onDefaultChanged(ValueChangedEvent<T> _) => UpdateState();
|
||||
private void onDisabledChanged(bool _) => UpdateState();
|
||||
|
||||
public void UpdateState() => Scheduler.AddOnce(updateState);
|
||||
|
||||
private void updateState()
|
||||
|
Loading…
x
Reference in New Issue
Block a user