mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 04:02:59 +08:00
Let selection container handle manual selection changes
This commit is contained in:
parent
c5a0672277
commit
07d54d261a
@ -1,6 +1,8 @@
|
||||
// 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.Collections.Generic;
|
||||
using osu.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@ -60,5 +62,34 @@ namespace osu.Game.Graphics.Containers
|
||||
}
|
||||
|
||||
public T Selected => (selectedIndex >= 0 && selectedIndex < Count) ? this[selectedIndex.Value] : null;
|
||||
|
||||
private readonly Dictionary<T, Action<SelectionState>> handlerMap = new Dictionary<T, Action<SelectionState>>();
|
||||
|
||||
public override void Add(T drawable)
|
||||
{
|
||||
// This event is used to update selection state when modified within the drawable itself.
|
||||
// It is added to a dictionary so that we can unsubscribe if the drawable is removed from this container
|
||||
drawable.StateChanged += handlerMap[drawable] = state => selectionChanged(drawable, state);
|
||||
|
||||
base.Add(drawable);
|
||||
}
|
||||
|
||||
public override bool Remove(T drawable)
|
||||
{
|
||||
if (!base.Remove(drawable))
|
||||
return false;
|
||||
|
||||
drawable.StateChanged -= handlerMap[drawable];
|
||||
handlerMap.Remove(drawable);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void selectionChanged(T drawable, SelectionState state)
|
||||
{
|
||||
if (state == SelectionState.NotSelected)
|
||||
Deselect();
|
||||
else
|
||||
Select(drawable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ using osu.Framework.Input.Events;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.Overlays.Volume;
|
||||
using osuTK;
|
||||
@ -92,10 +91,7 @@ namespace osu.Game.Overlays
|
||||
base.LoadComplete();
|
||||
|
||||
foreach (var volumeMeter in volumeMeters)
|
||||
{
|
||||
volumeMeter.Bindable.ValueChanged += _ => Show();
|
||||
volumeMeter.StateChanged += selected => volumeMeterSelectionChanged(volumeMeter, selected);
|
||||
}
|
||||
|
||||
muteButton.Current.ValueChanged += _ => Show();
|
||||
}
|
||||
@ -141,14 +137,6 @@ namespace osu.Game.Overlays
|
||||
return false;
|
||||
}
|
||||
|
||||
private void volumeMeterSelectionChanged(VolumeMeter meter, SelectionState state)
|
||||
{
|
||||
if (state == SelectionState.NotSelected)
|
||||
volumeMeters.Deselect();
|
||||
else
|
||||
volumeMeters.Select(meter);
|
||||
}
|
||||
|
||||
private ScheduledDelegate popOutDelegate;
|
||||
|
||||
public override void Show()
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Humanizer;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
@ -184,8 +183,6 @@ namespace osu.Game.Screens.Play
|
||||
}
|
||||
};
|
||||
|
||||
button.StateChanged += selected => buttonSelectionChanged(button, selected);
|
||||
|
||||
InternalButtons.Add(button);
|
||||
}
|
||||
|
||||
@ -216,15 +213,6 @@ namespace osu.Game.Screens.Play
|
||||
public void OnReleased(GlobalAction action)
|
||||
{
|
||||
}
|
||||
|
||||
private void buttonSelectionChanged(DialogButton button, SelectionState state)
|
||||
{
|
||||
if (state == SelectionState.NotSelected)
|
||||
InternalButtons.Deselect();
|
||||
else
|
||||
InternalButtons.Select(button);
|
||||
}
|
||||
|
||||
private void updateRetryCount()
|
||||
{
|
||||
// "You've retried 1,065 times in this session"
|
||||
|
Loading…
Reference in New Issue
Block a user