mirror of
https://github.com/ppy/osu.git
synced 2025-01-27 02:32:59 +08:00
Use IStateful<SelectionState> instead of ISelected
This commit is contained in:
parent
32ef2405c4
commit
c5a0672277
@ -1,6 +1,7 @@
|
||||
// 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;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
@ -11,7 +12,7 @@ namespace osu.Game.Graphics.Containers
|
||||
/// A FillFlowContainer that provides functionality to cycle selection between children
|
||||
/// The selection wraps around when overflowing past the first or last child.
|
||||
/// </summary>
|
||||
public class SelectionCycleFillFlowContainer<T> : FillFlowContainer<T> where T : Drawable, ISelectable
|
||||
public class SelectionCycleFillFlowContainer<T> : FillFlowContainer<T> where T : Drawable, IStateful<SelectionState>
|
||||
{
|
||||
private int? selectedIndex;
|
||||
|
||||
@ -22,13 +23,13 @@ namespace osu.Game.Graphics.Containers
|
||||
|
||||
// Deselect the previously-selected button
|
||||
if (selectedIndex.HasValue)
|
||||
this[selectedIndex.Value].Selected = false;
|
||||
this[selectedIndex.Value].State = SelectionState.NotSelected;
|
||||
|
||||
selectedIndex = value;
|
||||
|
||||
// Select the newly-selected button
|
||||
if (selectedIndex.HasValue)
|
||||
this[selectedIndex.Value].Selected = true;
|
||||
this[selectedIndex.Value].State = SelectionState.Selected;
|
||||
}
|
||||
|
||||
public void SelectNext()
|
||||
|
@ -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 osu.Framework;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
@ -19,7 +21,7 @@ using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
public class DialogButton : OsuClickableContainer, ISelectable
|
||||
public class DialogButton : OsuClickableContainer, IStateful<SelectionState>
|
||||
{
|
||||
private const float idle_width = 0.8f;
|
||||
private const float hover_width = 0.9f;
|
||||
@ -27,12 +29,21 @@ namespace osu.Game.Graphics.UserInterface
|
||||
private const float hover_duration = 500;
|
||||
private const float click_duration = 200;
|
||||
|
||||
public readonly BindableBool SelectedBindable = new BindableBool();
|
||||
public event Action<SelectionState> StateChanged;
|
||||
|
||||
public bool Selected
|
||||
private SelectionState state;
|
||||
|
||||
public SelectionState State
|
||||
{
|
||||
get => SelectedBindable.Value;
|
||||
set => SelectedBindable.Value = value;
|
||||
get => state;
|
||||
set
|
||||
{
|
||||
if (state == value)
|
||||
return;
|
||||
|
||||
state = value;
|
||||
StateChanged?.Invoke(value);
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Container backgroundContainer;
|
||||
@ -159,7 +170,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
updateGlow();
|
||||
|
||||
SelectedBindable.ValueChanged += selectionChanged;
|
||||
StateChanged += selectionChanged;
|
||||
}
|
||||
|
||||
private Color4 buttonColour;
|
||||
@ -227,7 +238,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
.OnComplete(_ =>
|
||||
{
|
||||
clickAnimating = false;
|
||||
SelectedBindable.TriggerChange();
|
||||
StateChanged?.Invoke(State);
|
||||
});
|
||||
|
||||
return base.OnClick(e);
|
||||
@ -241,7 +252,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
protected override void OnMouseUp(MouseUpEvent e)
|
||||
{
|
||||
if (Selected)
|
||||
if (State == SelectionState.Selected)
|
||||
colourContainer.ResizeWidthTo(hover_width, click_duration, Easing.In);
|
||||
base.OnMouseUp(e);
|
||||
}
|
||||
@ -249,7 +260,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
protected override bool OnHover(HoverEvent e)
|
||||
{
|
||||
base.OnHover(e);
|
||||
Selected = true;
|
||||
State = SelectionState.Selected;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -257,15 +268,15 @@ namespace osu.Game.Graphics.UserInterface
|
||||
protected override void OnHoverLost(HoverLostEvent e)
|
||||
{
|
||||
base.OnHoverLost(e);
|
||||
Selected = false;
|
||||
State = SelectionState.NotSelected;
|
||||
}
|
||||
|
||||
private void selectionChanged(ValueChangedEvent<bool> args)
|
||||
private void selectionChanged(SelectionState newState)
|
||||
{
|
||||
if (clickAnimating)
|
||||
return;
|
||||
|
||||
if (args.NewValue)
|
||||
if (newState == SelectionState.Selected)
|
||||
{
|
||||
spriteText.TransformSpacingTo(hoverSpacing, hover_duration, Easing.OutElastic);
|
||||
colourContainer.ResizeWidthTo(hover_width, hover_duration, Easing.OutElastic);
|
||||
|
@ -1,10 +0,0 @@
|
||||
// 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.
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
public interface ISelectable
|
||||
{
|
||||
bool Selected { get; set; }
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using osu.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
@ -26,7 +27,7 @@ using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Overlays.Volume
|
||||
{
|
||||
public class VolumeMeter : Container, IKeyBindingHandler<GlobalAction>, ISelectable
|
||||
public class VolumeMeter : Container, IKeyBindingHandler<GlobalAction>, IStateful<SelectionState>
|
||||
{
|
||||
private CircularProgress volumeCircle;
|
||||
private CircularProgress volumeCircleGlow;
|
||||
@ -44,12 +45,21 @@ namespace osu.Game.Overlays.Volume
|
||||
private Sample sample;
|
||||
private double sampleLastPlaybackTime;
|
||||
|
||||
public BindableBool SelectedBindable = new BindableBool();
|
||||
public event Action<SelectionState> StateChanged;
|
||||
|
||||
public bool Selected
|
||||
private SelectionState state;
|
||||
|
||||
public SelectionState State
|
||||
{
|
||||
get => SelectedBindable.Value;
|
||||
set => SelectedBindable.Value = value;
|
||||
get => state;
|
||||
set
|
||||
{
|
||||
if (state == value)
|
||||
return;
|
||||
|
||||
state = value;
|
||||
StateChanged?.Invoke(value);
|
||||
}
|
||||
}
|
||||
|
||||
public VolumeMeter(string name, float circleSize, Color4 meterColour)
|
||||
@ -220,7 +230,7 @@ namespace osu.Game.Overlays.Volume
|
||||
|
||||
bgProgress.Current.Value = 0.75f;
|
||||
|
||||
SelectedBindable.ValueChanged += selectionChanged;
|
||||
StateChanged += stateChanged;
|
||||
}
|
||||
|
||||
private int? displayVolumeInt;
|
||||
@ -341,7 +351,7 @@ namespace osu.Game.Overlays.Volume
|
||||
|
||||
protected override bool OnHover(HoverEvent e)
|
||||
{
|
||||
Selected = true;
|
||||
State = SelectionState.Selected;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -349,9 +359,9 @@ namespace osu.Game.Overlays.Volume
|
||||
{
|
||||
}
|
||||
|
||||
private void selectionChanged(ValueChangedEvent<bool> selected)
|
||||
private void stateChanged(SelectionState newState)
|
||||
{
|
||||
if (selected.NewValue)
|
||||
if (newState == SelectionState.Selected)
|
||||
{
|
||||
this.ScaleTo(1.04f, transition_length, Easing.OutExpo);
|
||||
focusGlowContainer.FadeIn(transition_length, Easing.OutExpo);
|
||||
@ -371,12 +381,12 @@ namespace osu.Game.Overlays.Volume
|
||||
switch (action)
|
||||
{
|
||||
case GlobalAction.SelectPrevious:
|
||||
Selected = true;
|
||||
State = SelectionState.Selected;
|
||||
adjust(1, false);
|
||||
return true;
|
||||
|
||||
case GlobalAction.SelectNext:
|
||||
Selected = true;
|
||||
State = SelectionState.Selected;
|
||||
adjust(-1, false);
|
||||
return true;
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ 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;
|
||||
@ -93,7 +94,7 @@ namespace osu.Game.Overlays
|
||||
foreach (var volumeMeter in volumeMeters)
|
||||
{
|
||||
volumeMeter.Bindable.ValueChanged += _ => Show();
|
||||
volumeMeter.SelectedBindable.ValueChanged += selected => volumeMeterSelectionChanged(volumeMeter, selected.NewValue);
|
||||
volumeMeter.StateChanged += selected => volumeMeterSelectionChanged(volumeMeter, selected);
|
||||
}
|
||||
|
||||
muteButton.Current.ValueChanged += _ => Show();
|
||||
@ -140,9 +141,9 @@ namespace osu.Game.Overlays
|
||||
return false;
|
||||
}
|
||||
|
||||
private void volumeMeterSelectionChanged(VolumeMeter meter, bool isSelected)
|
||||
private void volumeMeterSelectionChanged(VolumeMeter meter, SelectionState state)
|
||||
{
|
||||
if (!isSelected)
|
||||
if (state == SelectionState.NotSelected)
|
||||
volumeMeters.Deselect();
|
||||
else
|
||||
volumeMeters.Select(meter);
|
||||
|
@ -184,7 +184,7 @@ namespace osu.Game.Screens.Play
|
||||
}
|
||||
};
|
||||
|
||||
button.SelectedBindable.ValueChanged += selected => buttonSelectionChanged(button, selected.NewValue);
|
||||
button.StateChanged += selected => buttonSelectionChanged(button, selected);
|
||||
|
||||
InternalButtons.Add(button);
|
||||
}
|
||||
@ -217,9 +217,9 @@ namespace osu.Game.Screens.Play
|
||||
{
|
||||
}
|
||||
|
||||
private void buttonSelectionChanged(DialogButton button, bool isSelected)
|
||||
private void buttonSelectionChanged(DialogButton button, SelectionState state)
|
||||
{
|
||||
if (!isSelected)
|
||||
if (state == SelectionState.NotSelected)
|
||||
InternalButtons.Deselect();
|
||||
else
|
||||
InternalButtons.Select(button);
|
||||
@ -263,7 +263,7 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
protected override bool OnMouseMove(MouseMoveEvent e)
|
||||
{
|
||||
Selected = true;
|
||||
State = SelectionState.Selected;
|
||||
return base.OnMouseMove(e);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user