Merge branch 'master' into fix-toolbox-expansion

This commit is contained in:
Bartłomiej Dach 2022-05-06 13:47:36 +02:00
commit e527574ede
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
7 changed files with 198 additions and 48 deletions

View File

@ -7,6 +7,7 @@ using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics.Containers;
@ -17,6 +18,7 @@ using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
@ -56,6 +58,9 @@ namespace osu.Game.Tests.Visual.Multiplayer
private TestMultiplayerClient multiplayerClient => multiplayerComponents.MultiplayerClient;
private TestMultiplayerRoomManager roomManager => multiplayerComponents.RoomManager;
[Resolved]
private OsuConfigManager config { get; set; }
[BackgroundDependencyLoader]
private void load(GameHost host, AudioManager audio)
{
@ -668,6 +673,43 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddUntilStep("wait for results", () => multiplayerComponents.CurrentScreen is ResultsScreen);
}
[Test]
public void TestGameplayExitFlow()
{
Bindable<double> holdDelay = null;
AddStep("Set hold delay to zero", () =>
{
holdDelay = config.GetBindable<double>(OsuSetting.UIHoldActivationDelay);
holdDelay.Value = 0;
});
createRoom(() => new Room
{
Name = { Value = "Test Room" },
Playlist =
{
new PlaylistItem(beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.Ruleset.OnlineID == 0)).BeatmapInfo)
{
RulesetID = new OsuRuleset().RulesetInfo.OnlineID,
}
}
});
enterGameplay();
AddUntilStep("wait for playing", () => this.ChildrenOfType<Player>().FirstOrDefault()?.LocalUserPlaying.Value == true);
AddStep("attempt exit without hold", () => InputManager.Key(Key.Escape));
AddAssert("still in gameplay", () => multiplayerComponents.CurrentScreen is Player);
AddStep("attempt exit with hold", () => InputManager.PressKey(Key.Escape));
AddUntilStep("wait for lounge", () => multiplayerComponents.CurrentScreen is Screens.OnlinePlay.Multiplayer.Multiplayer);
AddStep("stop holding", () => InputManager.ReleaseKey(Key.Escape));
AddStep("set hold delay to default", () => holdDelay.SetDefault());
}
[Test]
public void TestGameplayDoesntStartWithNonLoadedUser()
{

View File

@ -18,6 +18,7 @@ using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Mods;
using osuTK;
using osuTK.Input;
namespace osu.Game.Tests.Visual.UserInterface
@ -164,7 +165,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddStep("select mod requiring configuration", () => SelectedMods.Value = new[] { new OsuModDifficultyAdjust() });
assertCustomisationToggleState(disabled: false, active: true);
AddStep("dismiss mod customisation via mouse", () =>
AddStep("dismiss mod customisation via toggle", () =>
{
InputManager.MoveMouseTo(modSelectScreen.ChildrenOfType<ShearedToggleButton>().Single());
InputManager.Click(MouseButton.Left);
@ -191,6 +192,29 @@ namespace osu.Game.Tests.Visual.UserInterface
assertCustomisationToggleState(disabled: true, active: false); // config was dismissed without explicit user action.
}
[Test]
public void TestDismissCustomisationViaDimmedArea()
{
createScreen();
assertCustomisationToggleState(disabled: true, active: false);
AddStep("select mod requiring configuration", () => SelectedMods.Value = new[] { new OsuModDifficultyAdjust() });
assertCustomisationToggleState(disabled: false, active: true);
AddStep("move mouse to settings area", () => InputManager.MoveMouseTo(this.ChildrenOfType<ModSettingsArea>().Single()));
AddStep("move mouse to dimmed area", () =>
{
InputManager.MoveMouseTo(new Vector2(
modSelectScreen.ScreenSpaceDrawQuad.TopLeft.X,
(modSelectScreen.ScreenSpaceDrawQuad.TopLeft.Y + modSelectScreen.ScreenSpaceDrawQuad.BottomLeft.Y) / 2));
});
AddStep("click", () => InputManager.Click(MouseButton.Left));
assertCustomisationToggleState(disabled: false, active: false);
AddStep("move mouse to first mod panel", () => InputManager.MoveMouseTo(modSelectScreen.ChildrenOfType<ModPanel>().First()));
AddAssert("first mod panel is hovered", () => modSelectScreen.ChildrenOfType<ModPanel>().First().IsHovered);
}
/// <summary>
/// Ensure that two mod overlays are not cross polluting via central settings instances.
/// </summary>

View File

@ -10,12 +10,32 @@ using osu.Game.Configuration;
namespace osu.Game.Graphics.Containers
{
/// <summary>
/// A container which adds a common "hold-to-perform" pattern to a container.
/// </summary>
/// <remarks>
/// This container does not handle triggering the hold/abort operations.
/// To use this class, please call <see cref="BeginConfirm"/> and <see cref="AbortConfirm"/> when necessary.
///
/// The <see cref="Progress"/> is exposed as a transforming bindable which smoothly tracks the progress of a hold operation.
/// It can be used for animating and displaying progress directly.
/// </remarks>
public abstract class HoldToConfirmContainer : Container
{
public Action Action;
public const double DANGEROUS_HOLD_ACTIVATION_DELAY = 500;
private const int fadeout_delay = 200;
/// <summary>
/// Whether the associated action is considered dangerous, warranting a longer hold.
/// </summary>
public bool IsDangerousAction { get; }
/// <summary>
/// The action to perform when a hold successfully completes.
/// </summary>
public Action Action;
/// <summary>
/// Whether currently in a fired state (and the confirm <see cref="Action"/> has been sent).
/// </summary>
@ -23,46 +43,61 @@ namespace osu.Game.Graphics.Containers
private bool confirming;
/// <summary>
/// The current activation delay for this control.
/// </summary>
public IBindable<double> HoldActivationDelay => holdActivationDelay;
/// <summary>
/// The progress of any ongoing hold operation. 0 means no hold has started; 1 means a hold has been completed.
/// </summary>
public IBindable<double> Progress => progress;
/// <summary>
/// Whether the overlay should be allowed to return from a fired state.
/// </summary>
protected virtual bool AllowMultipleFires => false;
/// <summary>
/// Specify a custom activation delay, overriding the game-wide user setting.
/// </summary>
/// <remarks>
/// This should be used in special cases where we want to be extra sure the user knows what they are doing. An example is when changes would be lost.
/// </remarks>
protected virtual double? HoldActivationDelay => null;
private readonly Bindable<double> progress = new BindableDouble();
public Bindable<double> Progress = new BindableDouble();
private readonly Bindable<double> holdActivationDelay = new Bindable<double>();
private Bindable<double> holdActivationDelay;
[Resolved]
private OsuConfigManager config { get; set; }
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
protected HoldToConfirmContainer(bool isDangerousAction = false)
{
holdActivationDelay = HoldActivationDelay != null
? new Bindable<double>(HoldActivationDelay.Value)
: config.GetBindable<double>(OsuSetting.UIHoldActivationDelay);
IsDangerousAction = isDangerousAction;
}
protected override void LoadComplete()
{
base.LoadComplete();
if (IsDangerousAction)
holdActivationDelay.Value = DANGEROUS_HOLD_ACTIVATION_DELAY;
else
config.BindWith(OsuSetting.UIHoldActivationDelay, holdActivationDelay);
}
/// <summary>
/// Begin a new confirmation. Should be called when the container is interacted with (ie. the user presses a key).
/// </summary>
/// <remarks>
/// Calling this method when already in the process of confirming has no effect.
/// </remarks>
protected void BeginConfirm()
{
if (confirming || (!AllowMultipleFires && Fired)) return;
confirming = true;
this.TransformBindableTo(Progress, 1, holdActivationDelay.Value * (1 - Progress.Value), Easing.Out).OnComplete(_ => Confirm());
}
protected virtual void Confirm()
{
Action?.Invoke();
Fired = true;
this.TransformBindableTo(progress, 1, holdActivationDelay.Value * (1 - progress.Value), Easing.Out).OnComplete(_ => Confirm());
}
/// <summary>
/// Abort any ongoing confirmation. Should be called when the container's interaction is no longer valid (ie. the user releases a key).
/// </summary>
protected void AbortConfirm()
{
if (!AllowMultipleFires && Fired) return;
@ -71,9 +106,19 @@ namespace osu.Game.Graphics.Containers
Fired = false;
this
.TransformBindableTo(Progress, Progress.Value)
.TransformBindableTo(progress, progress.Value)
.Delay(200)
.TransformBindableTo(Progress, 0, fadeout_delay, Easing.InSine);
.TransformBindableTo(progress, 0, fadeout_delay, Easing.InSine);
}
/// <summary>
/// A method which is invoked when the confirmation sequence completes successfully.
/// By default, will fire the associated <see cref="Action"/>.
/// </summary>
protected virtual void Confirm()
{
Action?.Invoke();
Fired = true;
}
}
}

View File

@ -42,7 +42,10 @@ namespace osu.Game.Overlays.Dialog
private class DangerousConfirmContainer : HoldToConfirmContainer
{
protected override double? HoldActivationDelay => 500;
public DangerousConfirmContainer()
: base(isDangerousAction: true)
{
}
protected override bool OnMouseDown(MouseDownEvent e)
{

View File

@ -464,6 +464,8 @@ namespace osu.Game.Overlays.Mods
public Action? OnClicked { get; set; }
public override bool HandlePositionalInput => base.HandlePositionalInput && HandleMouse.Value;
protected override bool Handle(UIEvent e)
{
if (!HandleMouse.Value)

View File

@ -1,7 +1,6 @@
// 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.Linq;
using osu.Framework.Graphics;
using osu.Framework.Input.Events;
using osu.Game.Graphics.Containers;
@ -25,7 +24,7 @@ namespace osu.Game.Rulesets.Edit
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => base.ReceivePositionalInputAt(screenSpacePos) && anyToolboxHovered(screenSpacePos);
private bool anyToolboxHovered(Vector2 screenSpacePos) => FillFlow.Children.Any(d => d.ScreenSpaceDrawQuad.Contains(screenSpacePos));
private bool anyToolboxHovered(Vector2 screenSpacePos) => FillFlow.ScreenSpaceDrawQuad.Contains(screenSpacePos);
protected override bool OnMouseDown(MouseDownEvent e) => true;

View File

@ -12,13 +12,14 @@ using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Threading;
using osu.Framework.Utils;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Input.Bindings;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.Play.HUD
{
@ -28,20 +29,22 @@ namespace osu.Game.Screens.Play.HUD
public readonly Bindable<bool> IsPaused = new Bindable<bool>();
private readonly Button button;
private HoldButton button;
public Action Action
{
set => button.Action = value;
}
public Action Action { get; set; }
private readonly OsuSpriteText text;
private OsuSpriteText text;
public HoldForMenuButton()
{
Direction = FillDirection.Horizontal;
Spacing = new Vector2(20, 0);
Margin = new MarginPadding(10);
}
[BackgroundDependencyLoader(true)]
private void load(Player player)
{
Children = new Drawable[]
{
text = new OsuSpriteText
@ -50,25 +53,20 @@ namespace osu.Game.Screens.Play.HUD
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft
},
button = new Button
button = new HoldButton(player?.Configuration.AllowRestart == false)
{
HoverGained = () => text.FadeIn(500, Easing.OutQuint),
HoverLost = () => text.FadeOut(500, Easing.OutQuint),
IsPaused = { BindTarget = IsPaused }
IsPaused = { BindTarget = IsPaused },
Action = () => Action(),
}
};
AutoSizeAxes = Axes.Both;
}
[Resolved]
private OsuConfigManager config { get; set; }
private Bindable<double> activationDelay;
protected override void LoadComplete()
{
activationDelay = config.GetBindable<double>(OsuSetting.UIHoldActivationDelay);
activationDelay.BindValueChanged(v =>
button.HoldActivationDelay.BindValueChanged(v =>
{
text.Text = v.NewValue > 0
? "hold for menu"
@ -102,7 +100,7 @@ namespace osu.Game.Screens.Play.HUD
}
}
private class Button : HoldToConfirmContainer, IKeyBindingHandler<GlobalAction>
private class HoldButton : HoldToConfirmContainer, IKeyBindingHandler<GlobalAction>
{
private SpriteIcon icon;
private CircularProgress circularProgress;
@ -115,6 +113,16 @@ namespace osu.Game.Screens.Play.HUD
public Action HoverGained;
public Action HoverLost;
private const double shake_duration = 20;
private bool pendingAnimation;
private ScheduledDelegate shakeOperation;
public HoldButton(bool isDangerousAction)
: base(isDangerousAction)
{
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
@ -161,11 +169,38 @@ namespace osu.Game.Screens.Play.HUD
private void bind()
{
circularProgress.Current.BindTo(Progress);
Progress.ValueChanged += progress => icon.Scale = new Vector2(1 + (float)progress.NewValue * 0.2f);
((IBindable<double>)circularProgress.Current).BindTo(Progress);
Progress.ValueChanged += progress =>
{
icon.Scale = new Vector2(1 + (float)progress.NewValue * 0.2f);
if (IsDangerousAction)
{
Colour = Interpolation.ValueAt(progress.NewValue, Color4.White, Color4.Red, 0, 1, Easing.OutQuint);
if (progress.NewValue > 0 && progress.NewValue < 1)
{
shakeOperation ??= Scheduler.AddDelayed(shake, shake_duration, true);
}
else
{
Child.MoveTo(Vector2.Zero, shake_duration * 2, Easing.OutQuint);
shakeOperation?.Cancel();
shakeOperation = null;
}
}
};
}
private bool pendingAnimation;
private void shake()
{
const float shake_magnitude = 8;
Child.MoveTo(new Vector2(
RNG.NextSingle(-1, 1) * (float)Progress.Value * shake_magnitude,
RNG.NextSingle(-1, 1) * (float)Progress.Value * shake_magnitude
), shake_duration);
}
protected override void Confirm()
{