mirror of
https://github.com/osukey/osukey.git
synced 2025-08-02 14:17:06 +09:00
Share item cycling logic with GameplayMenuOverlay
This commit is contained in:
@ -2,23 +2,24 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Humanizer;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Framework.Graphics.Effects;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Input.Bindings;
|
||||
using Humanizer;
|
||||
using osu.Framework.Graphics.Effects;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Screens.Play
|
||||
{
|
||||
@ -41,18 +42,18 @@ namespace osu.Game.Screens.Play
|
||||
/// <summary>
|
||||
/// Action that is invoked when <see cref="GlobalAction.Back"/> is triggered.
|
||||
/// </summary>
|
||||
protected virtual Action BackAction => () => InternalButtons.Children.LastOrDefault()?.Click();
|
||||
protected virtual Action BackAction => () => InternalButtons.Selected?.Click();
|
||||
|
||||
/// <summary>
|
||||
/// Action that is invoked when <see cref="GlobalAction.Select"/> is triggered.
|
||||
/// </summary>
|
||||
protected virtual Action SelectAction => () => InternalButtons.Children.FirstOrDefault(f => f.Selected.Value)?.Click();
|
||||
protected virtual Action SelectAction => () => InternalButtons.Selected?.Click();
|
||||
|
||||
public abstract string Header { get; }
|
||||
|
||||
public abstract string Description { get; }
|
||||
|
||||
protected ButtonContainer InternalButtons;
|
||||
protected SelectionCycleFillFlowContainer<DialogButton> InternalButtons;
|
||||
public IReadOnlyList<DialogButton> Buttons => InternalButtons;
|
||||
|
||||
private FillFlowContainer retryCounterContainer;
|
||||
@ -116,7 +117,7 @@ namespace osu.Game.Screens.Play
|
||||
}
|
||||
}
|
||||
},
|
||||
InternalButtons = new ButtonContainer
|
||||
InternalButtons = new SelectionCycleFillFlowContainer<DialogButton>
|
||||
{
|
||||
Origin = Anchor.TopCentre,
|
||||
Anchor = Anchor.TopCentre,
|
||||
@ -183,7 +184,7 @@ namespace osu.Game.Screens.Play
|
||||
}
|
||||
};
|
||||
|
||||
button.Selected.ValueChanged += selected => buttonSelectionChanged(button, selected.NewValue);
|
||||
button.SelectedBindable.ValueChanged += selected => buttonSelectionChanged(button, selected.NewValue);
|
||||
|
||||
InternalButtons.Add(button);
|
||||
}
|
||||
@ -255,46 +256,6 @@ namespace osu.Game.Screens.Play
|
||||
};
|
||||
}
|
||||
|
||||
protected class ButtonContainer : FillFlowContainer<DialogButton>
|
||||
{
|
||||
private int selectedIndex = -1;
|
||||
|
||||
private void setSelected(int value)
|
||||
{
|
||||
if (selectedIndex == value)
|
||||
return;
|
||||
|
||||
// Deselect the previously-selected button
|
||||
if (selectedIndex != -1)
|
||||
this[selectedIndex].Selected.Value = false;
|
||||
|
||||
selectedIndex = value;
|
||||
|
||||
// Select the newly-selected button
|
||||
if (selectedIndex != -1)
|
||||
this[selectedIndex].Selected.Value = true;
|
||||
}
|
||||
|
||||
public void SelectNext()
|
||||
{
|
||||
if (selectedIndex == -1 || selectedIndex == Count - 1)
|
||||
setSelected(0);
|
||||
else
|
||||
setSelected(selectedIndex + 1);
|
||||
}
|
||||
|
||||
public void SelectPrevious()
|
||||
{
|
||||
if (selectedIndex == -1 || selectedIndex == 0)
|
||||
setSelected(Count - 1);
|
||||
else
|
||||
setSelected(selectedIndex - 1);
|
||||
}
|
||||
|
||||
public void Deselect() => setSelected(-1);
|
||||
public void Select(DialogButton button) => setSelected(IndexOf(button));
|
||||
}
|
||||
|
||||
private class Button : DialogButton
|
||||
{
|
||||
// required to ensure keyboard navigation always starts from an extremity (unless the cursor is moved)
|
||||
@ -302,7 +263,7 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
protected override bool OnMouseMove(MouseMoveEvent e)
|
||||
{
|
||||
Selected.Value = true;
|
||||
Selected = true;
|
||||
return base.OnMouseMove(e);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user