1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 05:42:56 +08:00

Merge branch 'master' into more-change-state-support

This commit is contained in:
Dean Herbert 2020-04-13 19:13:07 +09:00 committed by GitHub
commit ca5971578a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 318 additions and 4 deletions

View File

@ -7,7 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.0" />
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
</ItemGroup>

View File

@ -70,6 +70,8 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables
public float DisplayRadius => DrawSize.X / 2 * Scale.X * HitObject.Scale;
protected override float SamplePlaybackPosition => HitObject.X;
protected DrawableCatchHitObject(CatchHitObject hitObject)
: base(hitObject)
{

View File

@ -7,6 +7,7 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.UI.Scrolling;
using osu.Game.Rulesets.Mania.UI;
namespace osu.Game.Rulesets.Mania.Objects.Drawables
{
@ -24,6 +25,20 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
protected readonly IBindable<ScrollingDirection> Direction = new Bindable<ScrollingDirection>();
[Resolved(canBeNull: true)]
private ManiaPlayfield playfield { get; set; }
protected override float SamplePlaybackPosition
{
get
{
if (playfield == null)
return base.SamplePlaybackPosition;
return (float)HitObject.Column / playfield.TotalColumns;
}
}
protected DrawableManiaHitObject(ManiaHitObject hitObject)
: base(hitObject)
{

View File

@ -6,6 +6,7 @@ using osu.Framework.Graphics.Containers;
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Objects.Drawables;
@ -14,6 +15,7 @@ using osuTK;
namespace osu.Game.Rulesets.Mania.UI
{
[Cached]
public class ManiaPlayfield : ScrollingPlayfield
{
private readonly List<Stage> stages = new List<Stage>();

View File

@ -7,6 +7,7 @@ using osu.Framework.Graphics;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Osu.Judgements;
using osu.Game.Graphics.Containers;
using osu.Game.Rulesets.Osu.UI;
using osu.Game.Rulesets.Scoring;
namespace osu.Game.Rulesets.Osu.Objects.Drawables
@ -18,6 +19,8 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
// Must be set to update IsHovered as it's used in relax mdo to detect osu hit objects.
public override bool HandlePositionalInput => true;
protected override float SamplePlaybackPosition => HitObject.X / OsuPlayfield.BASE_SIZE.X;
/// <summary>
/// Whether this <see cref="DrawableOsuHitObject"/> can be hit.
/// If non-null, judgements will be ignored (resulting in a shake) whilst the function returns false.

View File

@ -0,0 +1,113 @@
// 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.Graphics.Containers;
using osu.Game.Overlays;
using System;
using System.Collections.Generic;
using osu.Framework.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Shapes;
using osuTK.Graphics;
using NUnit.Framework;
using osu.Framework.Utils;
using osuTK.Input;
namespace osu.Game.Tests.Visual.UserInterface
{
public class TestSceneOverlayScrollContainer : OsuManualInputManagerTestScene
{
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(OverlayScrollContainer)
};
[Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
private TestScrollContainer scroll;
private int invocationCount;
[SetUp]
public void SetUp() => Schedule(() =>
{
Child = scroll = new TestScrollContainer
{
RelativeSizeAxes = Axes.Both,
Child = new Container
{
Height = 3000,
RelativeSizeAxes = Axes.X,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Gray
}
}
};
invocationCount = 0;
scroll.Button.Action += () => invocationCount++;
});
[Test]
public void TestButtonVisibility()
{
AddAssert("button is hidden", () => scroll.Button.State == Visibility.Hidden);
AddStep("scroll to end", () => scroll.ScrollToEnd(false));
AddAssert("button is visible", () => scroll.Button.State == Visibility.Visible);
AddStep("scroll to start", () => scroll.ScrollToStart(false));
AddAssert("button is hidden", () => scroll.Button.State == Visibility.Hidden);
AddStep("scroll to 500", () => scroll.ScrollTo(500));
AddUntilStep("scrolled to 500", () => Precision.AlmostEquals(scroll.Current, 500, 0.1f));
AddAssert("button is visible", () => scroll.Button.State == Visibility.Visible);
}
[Test]
public void TestButtonAction()
{
AddStep("scroll to end", () => scroll.ScrollToEnd(false));
AddStep("invoke action", () => scroll.Button.Action.Invoke());
AddUntilStep("scrolled back to start", () => Precision.AlmostEquals(scroll.Current, 0, 0.1f));
}
[Test]
public void TestClick()
{
AddStep("scroll to end", () => scroll.ScrollToEnd(false));
AddStep("click button", () =>
{
InputManager.MoveMouseTo(scroll.Button);
InputManager.Click(MouseButton.Left);
});
AddUntilStep("scrolled back to start", () => Precision.AlmostEquals(scroll.Current, 0, 0.1f));
}
[Test]
public void TestMultipleClicks()
{
AddStep("scroll to end", () => scroll.ScrollToEnd(false));
AddAssert("invocation count is 0", () => invocationCount == 0);
AddStep("hover button", () => InputManager.MoveMouseTo(scroll.Button));
AddRepeatStep("click button", () => InputManager.Click(MouseButton.Left), 3);
AddAssert("invocation count is 1", () => invocationCount == 1);
}
private class TestScrollContainer : OverlayScrollContainer
{
public new ScrollToTopButton Button => base.Button;
}
}
}

View File

@ -88,6 +88,7 @@ namespace osu.Game.Configuration
Set(OsuSetting.ShowProgressGraph, true);
Set(OsuSetting.ShowHealthDisplayWhenCantFail, true);
Set(OsuSetting.KeyOverlay, false);
Set(OsuSetting.PositionalHitSounds, true);
Set(OsuSetting.ScoreMeter, ScoreMeterType.HitErrorBoth);
Set(OsuSetting.FloatingComments, false);
@ -176,6 +177,7 @@ namespace osu.Game.Configuration
LightenDuringBreaks,
ShowStoryboard,
KeyOverlay,
PositionalHitSounds,
ScoreMeter,
FloatingComments,
ShowInterface,

View File

@ -0,0 +1,149 @@
// 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.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Game.Graphics.Containers;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Overlays
{
/// <summary>
/// <see cref="OsuScrollContainer"/> which provides <see cref="ScrollToTopButton"/>. Mostly used in <see cref="FullscreenOverlay"/>.
/// </summary>
public class OverlayScrollContainer : OsuScrollContainer
{
/// <summary>
/// Scroll position at which the <see cref="ScrollToTopButton"/> will be shown.
/// </summary>
private const int button_scroll_position = 200;
protected readonly ScrollToTopButton Button;
public OverlayScrollContainer()
{
AddInternal(Button = new ScrollToTopButton
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Margin = new MarginPadding(20),
Action = () =>
{
ScrollToStart();
Button.State = Visibility.Hidden;
}
});
}
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
if (ScrollContent.DrawHeight + button_scroll_position < DrawHeight)
{
Button.State = Visibility.Hidden;
return;
}
Button.State = Target > button_scroll_position ? Visibility.Visible : Visibility.Hidden;
}
public class ScrollToTopButton : OsuHoverContainer
{
private const int fade_duration = 500;
private Visibility state;
public Visibility State
{
get => state;
set
{
if (value == state)
return;
state = value;
Enabled.Value = state == Visibility.Visible;
this.FadeTo(state == Visibility.Visible ? 1 : 0, fade_duration, Easing.OutQuint);
}
}
protected override IEnumerable<Drawable> EffectTargets => new[] { background };
private Color4 flashColour;
private readonly Container content;
private readonly Box background;
public ScrollToTopButton()
{
Size = new Vector2(50);
Alpha = 0;
Add(content = new CircularContainer
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Masking = true,
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Offset = new Vector2(0f, 1f),
Radius = 3f,
Colour = Color4.Black.Opacity(0.25f),
},
Children = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both
},
new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(15),
Icon = FontAwesome.Solid.ChevronUp
}
}
});
TooltipText = "Scroll to top";
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
IdleColour = colourProvider.Background6;
HoverColour = colourProvider.Background5;
flashColour = colourProvider.Light1;
}
protected override bool OnClick(ClickEvent e)
{
background.FlashColour(flashColour, 800, Easing.OutQuint);
return base.OnClick(e);
}
protected override bool OnMouseDown(MouseDownEvent e)
{
content.ScaleTo(0.75f, 2000, Easing.OutQuint);
return true;
}
protected override void OnMouseUp(MouseUpEvent e)
{
content.ScaleTo(1, 1000, Easing.OutElastic);
base.OnMouseUp(e);
}
}
}
}

View File

@ -57,6 +57,11 @@ namespace osu.Game.Overlays.Settings.Sections.Gameplay
LabelText = "Always show key overlay",
Bindable = config.GetBindable<bool>(OsuSetting.KeyOverlay)
},
new SettingsCheckbox
{
LabelText = "Positional hitsounds",
Bindable = config.GetBindable<bool>(OsuSetting.PositionalHitSounds)
},
new SettingsEnumDropdown<ScoreMeterType>
{
LabelText = "Score meter type",

View File

@ -12,11 +12,13 @@ using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Threading;
using osu.Framework.Audio;
using osu.Game.Audio;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Scoring;
using osu.Game.Skinning;
using osu.Game.Configuration;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Objects.Drawables
@ -84,8 +86,20 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// </summary>
public JudgementResult Result { get; private set; }
/// <summary>
/// The relative X position of this hit object for sample playback balance adjustment.
/// </summary>
/// <remarks>
/// This is a range of 0..1 (0 for far-left, 0.5 for centre, 1 for far-right).
/// Dampening is post-applied to ensure the effect is not too intense.
/// </remarks>
protected virtual float SamplePlaybackPosition => 0.5f;
private readonly BindableDouble balanceAdjust = new BindableDouble();
private BindableList<HitSampleInfo> samplesBindable;
private Bindable<double> startTimeBindable;
private Bindable<bool> userPositionalHitSounds;
private Bindable<int> comboIndexBindable;
public override bool RemoveWhenNotAlive => false;
@ -104,8 +118,9 @@ namespace osu.Game.Rulesets.Objects.Drawables
}
[BackgroundDependencyLoader]
private void load()
private void load(OsuConfigManager config)
{
userPositionalHitSounds = config.GetBindable<bool>(OsuSetting.PositionalHitSounds);
var judgement = HitObject.CreateJudgement();
Result = CreateResult(judgement);
@ -156,7 +171,9 @@ namespace osu.Game.Rulesets.Objects.Drawables
+ $" This is an indication that {nameof(HitObject.ApplyDefaults)} has not been invoked on {this}.");
}
AddInternal(Samples = new SkinnableSound(samples.Select(s => HitObject.SampleControlPoint.ApplyTo(s))));
Samples = new SkinnableSound(samples.Select(s => HitObject.SampleControlPoint.ApplyTo(s)));
Samples.AddAdjustment(AdjustableProperty.Balance, balanceAdjust);
AddInternal(Samples);
}
private void onDefaultsApplied() => apply(HitObject);
@ -353,7 +370,13 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// Plays all the hit sounds for this <see cref="DrawableHitObject"/>.
/// This is invoked automatically when this <see cref="DrawableHitObject"/> is hit.
/// </summary>
public virtual void PlaySamples() => Samples?.Play();
public virtual void PlaySamples()
{
const float balance_adjust_amount = 0.4f;
balanceAdjust.Value = balance_adjust_amount * (userPositionalHitSounds.Value ? SamplePlaybackPosition - 0.5f : 0);
Samples?.Play();
}
protected override void Update()
{