Merge branch 'master' into confine-host-cursor

This commit is contained in:
Dean Herbert
2022-03-14 22:23:45 +09:00
32 changed files with 765 additions and 297 deletions

View File

@ -2,23 +2,22 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using osuTK;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Audio; using osu.Game.Audio;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Skinning; using osu.Game.Rulesets.Osu.Skinning;
using osu.Game.Rulesets.Osu.Skinning.Default; using osu.Game.Rulesets.Osu.Skinning.Default;
using osu.Game.Rulesets.Osu.UI; using osu.Game.Rulesets.Osu.UI;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osuTK.Graphics;
using osu.Game.Skinning; using osu.Game.Skinning;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Osu.Objects.Drawables namespace osu.Game.Rulesets.Osu.Objects.Drawables
{ {
@ -126,18 +125,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
} }
Samples.Samples = HitObject.TailSamples.Select(s => HitObject.SampleControlPoint.ApplyTo(s)).Cast<ISampleInfo>().ToArray(); Samples.Samples = HitObject.TailSamples.Select(s => HitObject.SampleControlPoint.ApplyTo(s)).Cast<ISampleInfo>().ToArray();
slidingSample.Samples = HitObject.CreateSlidingSamples().Select(s => HitObject.SampleControlPoint.ApplyTo(s)).Cast<ISampleInfo>().ToArray();
var slidingSamples = new List<ISampleInfo>();
var normalSample = HitObject.Samples.FirstOrDefault(s => s.Name == HitSampleInfo.HIT_NORMAL);
if (normalSample != null)
slidingSamples.Add(HitObject.SampleControlPoint.ApplyTo(normalSample).With("sliderslide"));
var whistleSample = HitObject.Samples.FirstOrDefault(s => s.Name == HitSampleInfo.HIT_WHISTLE);
if (whistleSample != null)
slidingSamples.Add(HitObject.SampleControlPoint.ApplyTo(whistleSample).With("sliderwhistle"));
slidingSample.Samples = slidingSamples.ToArray();
} }
public override void StopAllSamples() public override void StopAllSamples()

View File

@ -74,6 +74,18 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
ScaleBindable.BindValueChanged(scale => scaleContainer.Scale = new Vector2(scale.NewValue)); ScaleBindable.BindValueChanged(scale => scaleContainer.Scale = new Vector2(scale.NewValue));
} }
protected override void LoadSamples()
{
// Tail models don't actually get samples, as the playback is handled by DrawableSlider.
// This override is only here for visibility in explaining this weird flow.
}
public override void PlaySamples()
{
// Tail models don't actually get samples, as the playback is handled by DrawableSlider.
// This override is only here for visibility in explaining this weird flow.
}
protected override void UpdateInitialTransforms() protected override void UpdateInitialTransforms()
{ {
base.UpdateInitialTransforms(); base.UpdateInitialTransforms();

View File

@ -121,16 +121,9 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
{ {
base.LoadSamples(); base.LoadSamples();
var firstSample = HitObject.Samples.FirstOrDefault(); spinningSample.Samples = HitObject.CreateSpinningSamples().Select(s => HitObject.SampleControlPoint.ApplyTo(s)).Cast<ISampleInfo>().ToArray();
if (firstSample != null)
{
var clone = HitObject.SampleControlPoint.ApplyTo(firstSample).With("spinnerspin");
spinningSample.Samples = new ISampleInfo[] { clone };
spinningSample.Frequency.Value = spinning_sample_initial_frequency; spinningSample.Frequency.Value = spinning_sample_initial_frequency;
} }
}
private void updateSpinningSample(ValueChangedEvent<bool> tracking) private void updateSpinningSample(ValueChangedEvent<bool> tracking)
{ {

View File

@ -29,6 +29,23 @@ namespace osu.Game.Rulesets.Osu.Objects
set => throw new System.NotSupportedException($"Adjust via {nameof(RepeatCount)} instead"); // can be implemented if/when needed. set => throw new System.NotSupportedException($"Adjust via {nameof(RepeatCount)} instead"); // can be implemented if/when needed.
} }
public override IList<HitSampleInfo> AuxiliarySamples => CreateSlidingSamples().Concat(TailSamples).ToArray();
public IList<HitSampleInfo> CreateSlidingSamples()
{
var slidingSamples = new List<HitSampleInfo>();
var normalSample = Samples.FirstOrDefault(s => s.Name == HitSampleInfo.HIT_NORMAL);
if (normalSample != null)
slidingSamples.Add(normalSample.With("sliderslide"));
var whistleSample = Samples.FirstOrDefault(s => s.Name == HitSampleInfo.HIT_WHISTLE);
if (whistleSample != null)
slidingSamples.Add(whistleSample.With("sliderwhistle"));
return slidingSamples;
}
private readonly Cached<Vector2> endPositionCache = new Cached<Vector2>(); private readonly Cached<Vector2> endPositionCache = new Cached<Vector2>();
public override Vector2 EndPosition => endPositionCache.IsValid ? endPositionCache.Value : endPositionCache.Value = Position + this.CurvePositionAt(1); public override Vector2 EndPosition => endPositionCache.IsValid ? endPositionCache.Value : endPositionCache.Value = Position + this.CurvePositionAt(1);

View File

@ -1,7 +1,11 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading; using System.Threading;
using osu.Game.Audio;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Judgements;
@ -73,5 +77,20 @@ namespace osu.Game.Rulesets.Osu.Objects
public override Judgement CreateJudgement() => new OsuJudgement(); public override Judgement CreateJudgement() => new OsuJudgement();
protected override HitWindows CreateHitWindows() => HitWindows.Empty; protected override HitWindows CreateHitWindows() => HitWindows.Empty;
public override IList<HitSampleInfo> AuxiliarySamples => CreateSpinningSamples();
public HitSampleInfo[] CreateSpinningSamples()
{
var referenceSample = Samples.FirstOrDefault();
if (referenceSample == null)
return Array.Empty<HitSampleInfo>();
return new[]
{
SampleControlPoint.ApplyTo(referenceSample).With("spinnerspin")
};
}
} }
} }

View File

@ -15,6 +15,7 @@ namespace osu.Game.Rulesets.Taiko.Mods
public void ApplyToDrawableRuleset(DrawableRuleset<TaikoHitObject> drawableRuleset) public void ApplyToDrawableRuleset(DrawableRuleset<TaikoHitObject> drawableRuleset)
{ {
drawableTaikoRuleset = (DrawableTaikoRuleset)drawableRuleset; drawableTaikoRuleset = (DrawableTaikoRuleset)drawableRuleset;
drawableTaikoRuleset.LockPlayfieldAspect.Value = false;
} }
public void Update(Playfield playfield) public void Update(Playfield playfield)

View File

@ -29,6 +29,8 @@ namespace osu.Game.Rulesets.Taiko.UI
{ {
public new BindableDouble TimeRange => base.TimeRange; public new BindableDouble TimeRange => base.TimeRange;
public readonly BindableBool LockPlayfieldAspect = new BindableBool(true);
protected override ScrollVisualisationMethod VisualisationMethod => ScrollVisualisationMethod.Overlapping; protected override ScrollVisualisationMethod VisualisationMethod => ScrollVisualisationMethod.Overlapping;
protected override bool UserScrollSpeedAdjustment => false; protected override bool UserScrollSpeedAdjustment => false;
@ -70,7 +72,10 @@ namespace osu.Game.Rulesets.Taiko.UI
return ControlPoints[result]; return ControlPoints[result];
} }
public override PlayfieldAdjustmentContainer CreatePlayfieldAdjustmentContainer() => new TaikoPlayfieldAdjustmentContainer(); public override PlayfieldAdjustmentContainer CreatePlayfieldAdjustmentContainer() => new TaikoPlayfieldAdjustmentContainer
{
LockPlayfieldAspect = { BindTarget = LockPlayfieldAspect }
};
protected override PassThroughInputManager CreateInputManager() => new TaikoInputManager(Ruleset.RulesetInfo); protected override PassThroughInputManager CreateInputManager() => new TaikoInputManager(Ruleset.RulesetInfo);

View File

@ -29,7 +29,7 @@ namespace osu.Game.Rulesets.Taiko.UI
/// <summary> /// <summary>
/// Default height of a <see cref="TaikoPlayfield"/> when inside a <see cref="DrawableTaikoRuleset"/>. /// Default height of a <see cref="TaikoPlayfield"/> when inside a <see cref="DrawableTaikoRuleset"/>.
/// </summary> /// </summary>
public const float DEFAULT_HEIGHT = 212; public const float DEFAULT_HEIGHT = 200;
private Container<HitExplosion> hitExplosionContainer; private Container<HitExplosion> hitExplosionContainer;
private Container<KiaiHitExplosion> kiaiExplosionContainer; private Container<KiaiHitExplosion> kiaiExplosionContainer;

View File

@ -2,9 +2,9 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
using osuTK;
namespace osu.Game.Rulesets.Taiko.UI namespace osu.Game.Rulesets.Taiko.UI
{ {
@ -13,16 +13,22 @@ namespace osu.Game.Rulesets.Taiko.UI
private const float default_relative_height = TaikoPlayfield.DEFAULT_HEIGHT / 768; private const float default_relative_height = TaikoPlayfield.DEFAULT_HEIGHT / 768;
private const float default_aspect = 16f / 9f; private const float default_aspect = 16f / 9f;
public readonly IBindable<bool> LockPlayfieldAspect = new BindableBool(true);
protected override void Update() protected override void Update()
{ {
base.Update(); base.Update();
float aspectAdjust = Math.Clamp(Parent.ChildSize.X / Parent.ChildSize.Y, 0.4f, 4) / default_aspect; float height = default_relative_height;
Size = new Vector2(1, default_relative_height * aspectAdjust);
if (LockPlayfieldAspect.Value)
height *= Math.Clamp(Parent.ChildSize.X / Parent.ChildSize.Y, 0.4f, 4) / default_aspect;
Height = height;
// Position the taiko playfield exactly one playfield from the top of the screen. // Position the taiko playfield exactly one playfield from the top of the screen.
RelativePositionAxes = Axes.Y; RelativePositionAxes = Axes.Y;
Y = Size.Y; Y = height;
} }
} }
} }

View File

@ -1,11 +1,14 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
using osu.Game.Skinning; using osu.Game.Skinning;
@ -22,6 +25,8 @@ namespace osu.Game.Tests.Visual.Gameplay
[Cached] [Cached]
private Storyboard storyboard { get; set; } = new Storyboard(); private Storyboard storyboard { get; set; } = new Storyboard();
private IEnumerable<DrawableStoryboardSprite> sprites => this.ChildrenOfType<DrawableStoryboardSprite>();
[Test] [Test]
public void TestSkinSpriteDisallowedByDefault() public void TestSkinSpriteDisallowedByDefault()
{ {
@ -41,9 +46,54 @@ namespace osu.Game.Tests.Visual.Gameplay
AddStep("allow skin lookup", () => storyboard.UseSkinSprites = true); AddStep("allow skin lookup", () => storyboard.UseSkinSprites = true);
AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.Centre, Vector2.Zero))); AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
assertSpritesFromSkin(true); assertSpritesFromSkin(true);
AddAssert("skinnable sprite has correct size", () => sprites.Any(s => Precision.AlmostEquals(s.ChildrenOfType<SkinnableSprite>().Single().Size, new Vector2(128, 128))));
}
[Test]
public void TestFlippedSprite()
{
const string lookup_name = "hitcircleoverlay";
AddStep("allow skin lookup", () => storyboard.UseSkinSprites = true);
AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
AddStep("flip sprites", () => sprites.ForEach(s =>
{
s.FlipH = true;
s.FlipV = true;
}));
AddAssert("origin flipped", () => sprites.All(s => s.Origin == Anchor.BottomRight));
}
[Test]
public void TestNegativeScale()
{
const string lookup_name = "hitcircleoverlay";
AddStep("allow skin lookup", () => storyboard.UseSkinSprites = true);
AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
AddStep("scale sprite", () => sprites.ForEach(s => s.VectorScale = new Vector2(-1)));
AddAssert("origin flipped", () => sprites.All(s => s.Origin == Anchor.BottomRight));
}
[Test]
public void TestNegativeScaleWithFlippedSprite()
{
const string lookup_name = "hitcircleoverlay";
AddStep("allow skin lookup", () => storyboard.UseSkinSprites = true);
AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
AddStep("scale sprite", () => sprites.ForEach(s => s.VectorScale = new Vector2(-1)));
AddAssert("origin flipped", () => sprites.All(s => s.Origin == Anchor.BottomRight));
AddStep("flip sprites", () => sprites.ForEach(s =>
{
s.FlipH = true;
s.FlipV = true;
}));
AddAssert("origin back", () => sprites.All(s => s.Origin == Anchor.TopLeft));
} }
private DrawableStoryboardSprite createSprite(string lookupName, Anchor origin, Vector2 initialPosition) private DrawableStoryboardSprite createSprite(string lookupName, Anchor origin, Vector2 initialPosition)
@ -57,7 +107,6 @@ namespace osu.Game.Tests.Visual.Gameplay
private void assertSpritesFromSkin(bool fromSkin) => private void assertSpritesFromSkin(bool fromSkin) =>
AddAssert($"sprites are {(fromSkin ? "from skin" : "from storyboard")}", AddAssert($"sprites are {(fromSkin ? "from skin" : "from storyboard")}",
() => this.ChildrenOfType<DrawableStoryboardSprite>() () => sprites.All(sprite => sprite.ChildrenOfType<SkinnableSprite>().Any() == fromSkin));
.All(sprite => sprite.ChildrenOfType<SkinnableSprite>().Any() == fromSkin));
} }
} }

View File

@ -48,7 +48,11 @@ namespace osu.Game.Tests.Visual.Gameplay
{ {
AddStep("create display", () => recreateDisplay(new OsuHitWindows(), 5)); AddStep("create display", () => recreateDisplay(new OsuHitWindows(), 5));
AddRepeatStep("New random judgement", () => newJudgement(), 40); AddRepeatStep("New random judgement", () =>
{
double offset = RNG.Next(-150, 150);
newJudgement(offset, drawableRuleset.HitWindows.ResultFor(offset));
}, 400);
AddRepeatStep("New max negative", () => newJudgement(-drawableRuleset.HitWindows.WindowFor(HitResult.Meh)), 20); AddRepeatStep("New max negative", () => newJudgement(-drawableRuleset.HitWindows.WindowFor(HitResult.Meh)), 20);
AddRepeatStep("New max positive", () => newJudgement(drawableRuleset.HitWindows.WindowFor(HitResult.Meh)), 20); AddRepeatStep("New max positive", () => newJudgement(drawableRuleset.HitWindows.WindowFor(HitResult.Meh)), 20);

View File

@ -412,6 +412,121 @@ namespace osu.Game.Tests.Visual.Online
AddAssert("channel left", () => !channelManager.JoinedChannels.Contains(multiplayerChannel)); AddAssert("channel left", () => !channelManager.JoinedChannels.Contains(multiplayerChannel));
} }
[Test]
public void TestHighlightOnCurrentChannel()
{
Message message = null;
AddStep("Join channel 1", () => channelManager.JoinChannel(channel1));
AddStep("Select channel 1", () => clickDrawable(chatOverlay.TabMap[channel1]));
AddStep("Send message in channel 1", () =>
{
channel1.AddNewMessages(message = new Message
{
ChannelId = channel1.Id,
Content = "Message to highlight!",
Timestamp = DateTimeOffset.Now,
Sender = new APIUser
{
Id = 2,
Username = "Someone",
}
});
});
AddStep("Highlight message", () => chatOverlay.HighlightMessage(message, channel1));
}
[Test]
public void TestHighlightOnAnotherChannel()
{
Message message = null;
AddStep("Join channel 1", () => channelManager.JoinChannel(channel1));
AddStep("Select channel 1", () => clickDrawable(chatOverlay.TabMap[channel1]));
AddStep("Join channel 2", () => channelManager.JoinChannel(channel2));
AddStep("Send message in channel 2", () =>
{
channel2.AddNewMessages(message = new Message
{
ChannelId = channel2.Id,
Content = "Message to highlight!",
Timestamp = DateTimeOffset.Now,
Sender = new APIUser
{
Id = 2,
Username = "Someone",
}
});
});
AddStep("Highlight message", () => chatOverlay.HighlightMessage(message, channel2));
AddAssert("Switched to channel 2", () => channelManager.CurrentChannel.Value == channel2);
}
[Test]
public void TestHighlightOnLeftChannel()
{
Message message = null;
AddStep("Join channel 1", () => channelManager.JoinChannel(channel1));
AddStep("Select channel 1", () => clickDrawable(chatOverlay.TabMap[channel1]));
AddStep("Join channel 2", () => channelManager.JoinChannel(channel2));
AddStep("Send message in channel 2", () =>
{
channel2.AddNewMessages(message = new Message
{
ChannelId = channel2.Id,
Content = "Message to highlight!",
Timestamp = DateTimeOffset.Now,
Sender = new APIUser
{
Id = 2,
Username = "Someone",
}
});
});
AddStep("Leave channel 2", () => channelManager.LeaveChannel(channel2));
AddStep("Highlight message", () => chatOverlay.HighlightMessage(message, channel2));
AddAssert("Switched to channel 2", () => channelManager.CurrentChannel.Value == channel2);
}
[Test]
public void TestHighlightWhileChatHidden()
{
Message message = null;
AddStep("hide chat", () => chatOverlay.Hide());
AddStep("Join channel 1", () => channelManager.JoinChannel(channel1));
AddStep("Select channel 1", () => clickDrawable(chatOverlay.TabMap[channel1]));
AddStep("Send message in channel 1", () =>
{
channel1.AddNewMessages(message = new Message
{
ChannelId = channel1.Id,
Content = "Message to highlight!",
Timestamp = DateTimeOffset.Now,
Sender = new APIUser
{
Id = 2,
Username = "Someone",
}
});
});
AddStep("Highlight message and show chat", () =>
{
chatOverlay.HighlightMessage(message, channel1);
chatOverlay.Show();
});
}
private void pressChannelHotkey(int number) private void pressChannelHotkey(int number)
{ {
var channelKey = Key.Number0 + number; var channelKey = Key.Number0 + number;

View File

@ -9,6 +9,8 @@ using System;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays.Chat; using osu.Game.Overlays.Chat;
using osuTK.Input; using osuTK.Input;
@ -107,49 +109,7 @@ namespace osu.Game.Tests.Visual.Online
[Test] [Test]
public void TestManyMessages() public void TestManyMessages()
{ {
AddStep("message from admin", () => testChannel.AddNewMessages(new Message(messageIdSequence++) sendRegularMessages();
{
Sender = admin,
Content = "I am a wang!"
}));
AddStep("message from team red", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
{
Sender = redUser,
Content = "I am team red."
}));
AddStep("message from team red", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
{
Sender = redUser,
Content = "I plan to win!"
}));
AddStep("message from team blue", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
{
Sender = blueUser,
Content = "Not on my watch. Prepare to eat saaaaaaaaaand. Lots and lots of saaaaaaand."
}));
AddStep("message from admin", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
{
Sender = admin,
Content = "Okay okay, calm down guys. Let's do this!"
}));
AddStep("message from long username", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
{
Sender = longUsernameUser,
Content = "Hi guys, my new username is lit!"
}));
AddStep("message with new date", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
{
Sender = longUsernameUser,
Content = "Message from the future!",
Timestamp = DateTimeOffset.Now
}));
checkScrolledToBottom(); checkScrolledToBottom();
const int messages_per_call = 10; const int messages_per_call = 10;
@ -182,6 +142,64 @@ namespace osu.Game.Tests.Visual.Online
checkScrolledToBottom(); checkScrolledToBottom();
} }
[Test]
public void TestMessageHighlighting()
{
Message highlighted = null;
sendRegularMessages();
AddStep("highlight first message", () =>
{
highlighted = testChannel.Messages[0];
testChannel.HighlightedMessage.Value = highlighted;
});
AddUntilStep("chat scrolled to first message", () =>
{
var line = chatDisplay.ChildrenOfType<ChatLine>().Single(c => c.Message == highlighted);
return chatDisplay.ScrollContainer.ScreenSpaceDrawQuad.Contains(line.ScreenSpaceDrawQuad.Centre);
});
sendMessage();
checkNotScrolledToBottom();
AddStep("highlight last message", () =>
{
highlighted = testChannel.Messages[^1];
testChannel.HighlightedMessage.Value = highlighted;
});
AddUntilStep("chat scrolled to last message", () =>
{
var line = chatDisplay.ChildrenOfType<ChatLine>().Single(c => c.Message == highlighted);
return chatDisplay.ScrollContainer.ScreenSpaceDrawQuad.Contains(line.ScreenSpaceDrawQuad.Centre);
});
sendMessage();
checkScrolledToBottom();
AddRepeatStep("highlight other random messages", () =>
{
highlighted = testChannel.Messages[RNG.Next(0, testChannel.Messages.Count - 1)];
testChannel.HighlightedMessage.Value = highlighted;
}, 10);
}
[Test]
public void TestMessageHighlightingOnFilledChat()
{
int index = 0;
fillChat(100);
AddStep("highlight first message", () => testChannel.HighlightedMessage.Value = testChannel.Messages[index = 0]);
AddStep("highlight next message", () => testChannel.HighlightedMessage.Value = testChannel.Messages[index = Math.Min(index + 1, testChannel.Messages.Count - 1)]);
AddStep("highlight last message", () => testChannel.HighlightedMessage.Value = testChannel.Messages[index = testChannel.Messages.Count - 1]);
AddStep("highlight previous message", () => testChannel.HighlightedMessage.Value = testChannel.Messages[index = Math.Max(index - 1, 0)]);
AddRepeatStep("highlight random messages", () => testChannel.HighlightedMessage.Value = testChannel.Messages[index = RNG.Next(0, testChannel.Messages.Count - 1)], 10);
}
/// <summary> /// <summary>
/// Tests that when a message gets wrapped by the chat display getting contracted while scrolled to bottom, the chat will still keep scrolling down. /// Tests that when a message gets wrapped by the chat display getting contracted while scrolled to bottom, the chat will still keep scrolling down.
/// </summary> /// </summary>
@ -286,11 +304,11 @@ namespace osu.Game.Tests.Visual.Online
checkScrolledToBottom(); checkScrolledToBottom();
} }
private void fillChat() private void fillChat(int count = 10)
{ {
AddStep("fill chat", () => AddStep("fill chat", () =>
{ {
for (int i = 0; i < 10; i++) for (int i = 0; i < count; i++)
{ {
testChannel.AddNewMessages(new Message(messageIdSequence++) testChannel.AddNewMessages(new Message(messageIdSequence++)
{ {
@ -321,6 +339,52 @@ namespace osu.Game.Tests.Visual.Online
})); }));
} }
private void sendRegularMessages()
{
AddStep("message from admin", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
{
Sender = admin,
Content = "I am a wang!"
}));
AddStep("message from team red", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
{
Sender = redUser,
Content = "I am team red."
}));
AddStep("message from team red", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
{
Sender = redUser,
Content = "I plan to win!"
}));
AddStep("message from team blue", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
{
Sender = blueUser,
Content = "Not on my watch. Prepare to eat saaaaaaaaaand. Lots and lots of saaaaaaand."
}));
AddStep("message from admin", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
{
Sender = admin,
Content = "Okay okay, calm down guys. Let's do this!"
}));
AddStep("message from long username", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
{
Sender = longUsernameUser,
Content = "Hi guys, my new username is lit!"
}));
AddStep("message with new date", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
{
Sender = longUsernameUser,
Content = "Message from the future!",
Timestamp = DateTimeOffset.Now
}));
}
private void checkScrolledToBottom() => private void checkScrolledToBottom() =>
AddUntilStep("is scrolled to bottom", () => chatDisplay.ScrolledToBottom); AddUntilStep("is scrolled to bottom", () => chatDisplay.ScrolledToBottom);

View File

@ -9,6 +9,7 @@ using Newtonsoft.Json;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Lists; using osu.Framework.Lists;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays.Chat;
namespace osu.Game.Online.Chat namespace osu.Game.Online.Chat
{ {
@ -89,6 +90,12 @@ namespace osu.Game.Online.Chat
/// </summary> /// </summary>
public Bindable<bool> Joined = new Bindable<bool>(); public Bindable<bool> Joined = new Bindable<bool>();
/// <summary>
/// Signals if there is a message to highlight.
/// This is automatically cleared by the associated <see cref="DrawableChannel"/> after highlighting.
/// </summary>
public Bindable<Message> HighlightedMessage = new Bindable<Message>();
[JsonConstructor] [JsonConstructor]
public Channel() public Channel()
{ {

View File

@ -59,7 +59,13 @@ namespace osu.Game.Online.Chat
return Id.Value.CompareTo(other.Id.Value); return Id.Value.CompareTo(other.Id.Value);
} }
public virtual bool Equals(Message other) => Id.HasValue && Id == other?.Id; public virtual bool Equals(Message other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Id.HasValue && Id == other.Id;
}
// ReSharper disable once ImpureMethodCallOnReadonlyValueField // ReSharper disable once ImpureMethodCallOnReadonlyValueField
public override int GetHashCode() => Id.GetHashCode(); public override int GetHashCode() => Id.GetHashCode();

View File

@ -114,7 +114,7 @@ namespace osu.Game.Online.Chat
if (!notifyOnPrivateMessage.Value || channel.Type != ChannelType.PM) if (!notifyOnPrivateMessage.Value || channel.Type != ChannelType.PM)
return false; return false;
notifications.Post(new PrivateMessageNotification(message.Sender.Username, channel)); notifications.Post(new PrivateMessageNotification(message, channel));
return true; return true;
} }
@ -122,7 +122,7 @@ namespace osu.Game.Online.Chat
{ {
if (!notifyOnUsername.Value || !CheckContainsUsername(message.Content, localUser.Value.Username)) return; if (!notifyOnUsername.Value || !CheckContainsUsername(message.Content, localUser.Value.Username)) return;
notifications.Post(new MentionNotification(message.Sender.Username, channel)); notifications.Post(new MentionNotification(message, channel));
} }
/// <summary> /// <summary>
@ -136,47 +136,49 @@ namespace osu.Game.Online.Chat
return Regex.IsMatch(message, $@"(^|\W)({fullName}|{underscoreName})($|\W)", RegexOptions.IgnoreCase); return Regex.IsMatch(message, $@"(^|\W)({fullName}|{underscoreName})($|\W)", RegexOptions.IgnoreCase);
} }
public class PrivateMessageNotification : OpenChannelNotification public class PrivateMessageNotification : HighlightMessageNotification
{ {
public PrivateMessageNotification(string username, Channel channel) public PrivateMessageNotification(Message message, Channel channel)
: base(channel) : base(message, channel)
{ {
Icon = FontAwesome.Solid.Envelope; Icon = FontAwesome.Solid.Envelope;
Text = $"You received a private message from '{username}'. Click to read it!"; Text = $"You received a private message from '{message.Sender.Username}'. Click to read it!";
} }
} }
public class MentionNotification : OpenChannelNotification public class MentionNotification : HighlightMessageNotification
{ {
public MentionNotification(string username, Channel channel) public MentionNotification(Message message, Channel channel)
: base(channel) : base(message, channel)
{ {
Icon = FontAwesome.Solid.At; Icon = FontAwesome.Solid.At;
Text = $"Your name was mentioned in chat by '{username}'. Click to find out why!"; Text = $"Your name was mentioned in chat by '{message.Sender.Username}'. Click to find out why!";
} }
} }
public abstract class OpenChannelNotification : SimpleNotification public abstract class HighlightMessageNotification : SimpleNotification
{ {
protected OpenChannelNotification(Channel channel) protected HighlightMessageNotification(Message message, Channel channel)
{ {
this.message = message;
this.channel = channel; this.channel = channel;
} }
private readonly Message message;
private readonly Channel channel; private readonly Channel channel;
public override bool IsImportant => false; public override bool IsImportant => false;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours, ChatOverlay chatOverlay, NotificationOverlay notificationOverlay, ChannelManager channelManager) private void load(OsuColour colours, ChatOverlay chatOverlay, NotificationOverlay notificationOverlay)
{ {
IconBackground.Colour = colours.PurpleDark; IconBackground.Colour = colours.PurpleDark;
Activated = delegate Activated = delegate
{ {
notificationOverlay.Hide(); notificationOverlay.Hide();
chatOverlay.HighlightMessage(message, channel);
chatOverlay.Show(); chatOverlay.Show();
channelManager.CurrentChannel.Value = channel;
return true; return true;
}; };

View File

@ -1140,10 +1140,8 @@ namespace osu.Game
MenuCursorContainer.CanShowCursor = (ScreenStack.CurrentScreen as IOsuScreen)?.CursorVisible ?? false; MenuCursorContainer.CanShowCursor = (ScreenStack.CurrentScreen as IOsuScreen)?.CursorVisible ?? false;
} }
protected virtual void ScreenChanged(IScreen current, IScreen newScreen) private void screenChanged(IScreen current, IScreen newScreen)
{ {
skinEditor.Reset();
switch (newScreen) switch (newScreen)
{ {
case IntroScreen intro: case IntroScreen intro:
@ -1185,13 +1183,15 @@ namespace osu.Game
else else
BackButton.Hide(); BackButton.Hide();
} }
skinEditor.SetTarget((Screen)newScreen);
} }
private void screenPushed(IScreen lastScreen, IScreen newScreen) => ScreenChanged(lastScreen, newScreen); private void screenPushed(IScreen lastScreen, IScreen newScreen) => screenChanged(lastScreen, newScreen);
private void screenExited(IScreen lastScreen, IScreen newScreen) private void screenExited(IScreen lastScreen, IScreen newScreen)
{ {
ScreenChanged(lastScreen, newScreen); screenChanged(lastScreen, newScreen);
if (newScreen == null) if (newScreen == null)
Exit(); Exit();

View File

@ -69,7 +69,7 @@ namespace osu.Game
/// </summary> /// </summary>
private const double global_track_volume_adjust = 0.8; private const double global_track_volume_adjust = 0.8;
public bool UseDevelopmentServer { get; } public virtual bool UseDevelopmentServer => DebugUtils.IsDebugBuild;
public virtual Version AssemblyVersion => Assembly.GetEntryAssembly()?.GetName().Version ?? new Version(); public virtual Version AssemblyVersion => Assembly.GetEntryAssembly()?.GetName().Version ?? new Version();
@ -177,7 +177,6 @@ namespace osu.Game
public OsuGameBase() public OsuGameBase()
{ {
UseDevelopmentServer = DebugUtils.IsDebugBuild;
Name = @"osu!"; Name = @"osu!";
} }

View File

@ -47,6 +47,12 @@ namespace osu.Game.Overlays.Chat
updateTrackState(); updateTrackState();
} }
public new void ScrollTo(float value, bool animated = true, double? distanceDecay = null)
{
base.ScrollTo(value, animated, distanceDecay);
updateTrackState();
}
public new void ScrollIntoView(Drawable d, bool animated = true) public new void ScrollIntoView(Drawable d, bool animated = true)
{ {
base.ScrollIntoView(d, animated); base.ScrollIntoView(d, animated);

View File

@ -42,7 +42,7 @@ namespace osu.Game.Overlays.Chat
protected virtual float TextSize => 20; protected virtual float TextSize => 20;
private Color4 customUsernameColour; private Color4 usernameColour;
private OsuSpriteText timestamp; private OsuSpriteText timestamp;
@ -78,19 +78,22 @@ namespace osu.Game.Overlays.Chat
} }
} }
private bool senderHasBackground => !string.IsNullOrEmpty(message.Sender.Colour); private bool senderHasColour => !string.IsNullOrEmpty(message.Sender.Colour);
[Resolved]
private OsuColour colours { get; set; }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load()
{ {
customUsernameColour = colours.ChatBlue; usernameColour = senderHasColour
? Color4Extensions.FromHex(message.Sender.Colour)
bool hasBackground = senderHasBackground; : username_colours[message.Sender.Id % username_colours.Length];
Drawable effectedUsername = username = new OsuSpriteText Drawable effectedUsername = username = new OsuSpriteText
{ {
Shadow = false, Shadow = false,
Colour = hasBackground ? customUsernameColour : username_colours[message.Sender.Id % username_colours.Length], Colour = senderHasColour ? colours.ChatBlue : usernameColour,
Truncate = true, Truncate = true,
EllipsisString = "… :", EllipsisString = "… :",
Font = OsuFont.GetFont(size: TextSize, weight: FontWeight.Bold, italics: true), Font = OsuFont.GetFont(size: TextSize, weight: FontWeight.Bold, italics: true),
@ -99,7 +102,7 @@ namespace osu.Game.Overlays.Chat
MaxWidth = MessagePadding - TimestampPadding MaxWidth = MessagePadding - TimestampPadding
}; };
if (hasBackground) if (senderHasColour)
{ {
// Background effect // Background effect
effectedUsername = new Container effectedUsername = new Container
@ -126,7 +129,7 @@ namespace osu.Game.Overlays.Chat
new Box new Box
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = Color4Extensions.FromHex(message.Sender.Colour), Colour = usernameColour,
}, },
new Container new Container
{ {
@ -177,7 +180,7 @@ namespace osu.Game.Overlays.Chat
{ {
t.Font = OsuFont.GetFont(italics: true); t.Font = OsuFont.GetFont(italics: true);
if (senderHasBackground) if (senderHasColour)
t.Colour = Color4Extensions.FromHex(message.Sender.Colour); t.Colour = Color4Extensions.FromHex(message.Sender.Colour);
} }
@ -200,13 +203,37 @@ namespace osu.Game.Overlays.Chat
FinishTransforms(true); FinishTransforms(true);
} }
private Container highlight;
/// <summary>
/// Performs a highlight animation on this <see cref="ChatLine"/>.
/// </summary>
public void Highlight()
{
if (highlight?.IsAlive != true)
{
AddInternal(highlight = new Container
{
CornerRadius = 2f,
Masking = true,
RelativeSizeAxes = Axes.Both,
Colour = usernameColour.Darken(1f),
Depth = float.MaxValue,
Child = new Box { RelativeSizeAxes = Axes.Both }
});
}
highlight.FadeTo(0.5f).FadeOut(1500, Easing.InQuint);
highlight.Expire();
}
private void updateMessageContent() private void updateMessageContent()
{ {
this.FadeTo(message is LocalEchoMessage ? 0.4f : 1.0f, 500, Easing.OutQuint); this.FadeTo(message is LocalEchoMessage ? 0.4f : 1.0f, 500, Easing.OutQuint);
timestamp.FadeTo(message is LocalEchoMessage ? 0 : 1, 500, Easing.OutQuint); timestamp.FadeTo(message is LocalEchoMessage ? 0 : 1, 500, Easing.OutQuint);
timestamp.Text = $@"{message.Timestamp.LocalDateTime:HH:mm:ss}"; timestamp.Text = $@"{message.Timestamp.LocalDateTime:HH:mm:ss}";
username.Text = $@"{message.Sender.Username}" + (senderHasBackground || message.IsAction ? "" : ":"); username.Text = $@"{message.Sender.Username}" + (senderHasColour || message.IsAction ? "" : ":");
// remove non-existent channels from the link list // remove non-existent channels from the link list
message.Links.RemoveAll(link => link.Action == LinkAction.OpenChannel && chatManager?.AvailableChannels.Any(c => c.Name == link.Argument.ToString()) != true); message.Links.RemoveAll(link => link.Action == LinkAction.OpenChannel && chatManager?.AvailableChannels.Any(c => c.Name == link.Argument.ToString()) != true);

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -48,6 +49,8 @@ namespace osu.Game.Overlays.Chat
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;
} }
private Bindable<Message> highlightedMessage;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
@ -79,6 +82,34 @@ namespace osu.Game.Overlays.Chat
Channel.PendingMessageResolved += pendingMessageResolved; Channel.PendingMessageResolved += pendingMessageResolved;
} }
protected override void LoadComplete()
{
base.LoadComplete();
highlightedMessage = Channel.HighlightedMessage.GetBoundCopy();
highlightedMessage.BindValueChanged(_ => processMessageHighlighting(), true);
}
/// <summary>
/// Processes any pending message in <see cref="highlightedMessage"/>.
/// </summary>
// ScheduleAfterChildren is for ensuring the scroll flow has updated with any new chat lines.
private void processMessageHighlighting() => SchedulerAfterChildren.AddOnce(() =>
{
if (highlightedMessage.Value == null)
return;
var chatLine = chatLines.SingleOrDefault(c => c.Message.Equals(highlightedMessage.Value));
if (chatLine == null)
return;
float center = scroll.GetChildPosInContent(chatLine, chatLine.DrawSize / 2) - scroll.DisplayableContent / 2;
scroll.ScrollTo(Math.Clamp(center, 0, scroll.ScrollableExtent));
chatLine.Highlight();
highlightedMessage.Value = null;
});
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
{ {
base.Dispose(isDisposing); base.Dispose(isDisposing);
@ -148,6 +179,8 @@ namespace osu.Game.Overlays.Chat
// to avoid making the container think the user has scrolled back up and unwantedly disable auto-scrolling. // to avoid making the container think the user has scrolled back up and unwantedly disable auto-scrolling.
if (newMessages.Any(m => m is LocalMessage)) if (newMessages.Any(m => m is LocalMessage))
scroll.ScrollToEnd(); scroll.ScrollToEnd();
processMessageHighlighting();
}); });
private void pendingMessageResolved(Message existing, Message updated) => Schedule(() => private void pendingMessageResolved(Message existing, Message updated) => Schedule(() =>

View File

@ -3,6 +3,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Diagnostics;
using System.Linq; using System.Linq;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -303,6 +304,26 @@ namespace osu.Game.Overlays
channelManager.MarkChannelAsRead(e.NewValue); channelManager.MarkChannelAsRead(e.NewValue);
} }
/// <summary>
/// Highlights a certain message in the specified channel.
/// </summary>
/// <param name="message">The message to highlight.</param>
/// <param name="channel">The channel containing the message.</param>
public void HighlightMessage(Message message, Channel channel)
{
Debug.Assert(channel.Id == message.ChannelId);
if (currentChannel.Value.Id != channel.Id)
{
if (!channel.Joined.Value)
channel = channelManager.JoinChannel(channel);
channelManager.CurrentChannel.Value = channel;
}
channel.HighlightedMessage.Value = message;
}
private float startDragChatHeight; private float startDragChatHeight;
private bool isDragging; private bool isDragging;

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading; using System.Threading;
using JetBrains.Annotations; using JetBrains.Annotations;
using Newtonsoft.Json; using Newtonsoft.Json;
@ -67,6 +68,12 @@ namespace osu.Game.Rulesets.Objects
} }
} }
/// <summary>
/// Any samples which may be used by this hit object that are non-standard.
/// This is used only to preload these samples ahead of time.
/// </summary>
public virtual IList<HitSampleInfo> AuxiliarySamples => ImmutableList<HitSampleInfo>.Empty;
public SampleControlPoint SampleControlPoint = SampleControlPoint.DEFAULT; public SampleControlPoint SampleControlPoint = SampleControlPoint.DEFAULT;
public DifficultyControlPoint DifficultyControlPoint = DifficultyControlPoint.DEFAULT; public DifficultyControlPoint DifficultyControlPoint = DifficultyControlPoint.DEFAULT;

View File

@ -500,12 +500,12 @@ namespace osu.Game.Rulesets.Objects.Legacy
=> new LegacyHitSampleInfo(newName.GetOr(Name), newBank.GetOr(Bank), newVolume.GetOr(Volume), newCustomSampleBank.GetOr(CustomSampleBank), newIsLayered.GetOr(IsLayered)); => new LegacyHitSampleInfo(newName.GetOr(Name), newBank.GetOr(Bank), newVolume.GetOr(Volume), newCustomSampleBank.GetOr(CustomSampleBank), newIsLayered.GetOr(IsLayered));
public bool Equals(LegacyHitSampleInfo? other) public bool Equals(LegacyHitSampleInfo? other)
=> base.Equals(other) && CustomSampleBank == other.CustomSampleBank && IsLayered == other.IsLayered; => base.Equals(other) && CustomSampleBank == other.CustomSampleBank;
public override bool Equals(object? obj) public override bool Equals(object? obj)
=> obj is LegacyHitSampleInfo other && Equals(other); => obj is LegacyHitSampleInfo other && Equals(other);
public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), CustomSampleBank, IsLayered); public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), CustomSampleBank);
} }
private class FileHitSampleInfo : LegacyHitSampleInfo, IEquatable<FileHitSampleInfo> private class FileHitSampleInfo : LegacyHitSampleInfo, IEquatable<FileHitSampleInfo>

View File

@ -3,22 +3,22 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Pooling; using osu.Framework.Graphics.Pooling;
using osu.Game.Audio; using osu.Game.Audio;
using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Skinning; using osu.Game.Skinning;
using osuTK; using osuTK;
using System.Diagnostics;
namespace osu.Game.Rulesets.UI namespace osu.Game.Rulesets.UI
{ {
@ -264,10 +264,25 @@ namespace osu.Game.Rulesets.UI
var entry = CreateLifetimeEntry(hitObject); var entry = CreateLifetimeEntry(hitObject);
lifetimeEntryMap[entry.HitObject] = entry; lifetimeEntryMap[entry.HitObject] = entry;
preloadSamples(hitObject);
HitObjectContainer.Add(entry); HitObjectContainer.Add(entry);
OnHitObjectAdded(entry.HitObject); OnHitObjectAdded(entry.HitObject);
} }
private void preloadSamples(HitObject hitObject)
{
// prepare sample pools ahead of time so we're not initialising at runtime.
foreach (var sample in hitObject.Samples)
prepareSamplePool(hitObject.SampleControlPoint.ApplyTo(sample));
foreach (var sample in hitObject.AuxiliarySamples)
prepareSamplePool(hitObject.SampleControlPoint.ApplyTo(sample));
foreach (var nestedObject in hitObject.NestedHitObjects)
preloadSamples(nestedObject);
}
/// <summary> /// <summary>
/// Removes a <see cref="HitObjectLifetimeEntry"/> for a pooled <see cref="HitObject"/> from this <see cref="Playfield"/>. /// Removes a <see cref="HitObjectLifetimeEntry"/> for a pooled <see cref="HitObject"/> from this <see cref="Playfield"/>.
/// </summary> /// </summary>
@ -330,22 +345,7 @@ namespace osu.Game.Rulesets.UI
DrawableHitObject IPooledHitObjectProvider.GetPooledDrawableRepresentation(HitObject hitObject, DrawableHitObject parent) DrawableHitObject IPooledHitObjectProvider.GetPooledDrawableRepresentation(HitObject hitObject, DrawableHitObject parent)
{ {
var lookupType = hitObject.GetType(); var pool = prepareDrawableHitObjectPool(hitObject);
IDrawablePool pool;
// Tests may add derived hitobject instances for which pools don't exist. Try to find any applicable pool and dynamically assign the type if the pool exists.
if (!pools.TryGetValue(lookupType, out pool))
{
foreach (var (t, p) in pools)
{
if (!t.IsInstanceOfType(hitObject))
continue;
pools[lookupType] = pool = p;
break;
}
}
return (DrawableHitObject)pool?.Get(d => return (DrawableHitObject)pool?.Get(d =>
{ {
@ -372,14 +372,39 @@ namespace osu.Game.Rulesets.UI
}); });
} }
private IDrawablePool prepareDrawableHitObjectPool(HitObject hitObject)
{
var lookupType = hitObject.GetType();
IDrawablePool pool;
// Tests may add derived hitobject instances for which pools don't exist. Try to find any applicable pool and dynamically assign the type if the pool exists.
if (!pools.TryGetValue(lookupType, out pool))
{
foreach (var (t, p) in pools)
{
if (!t.IsInstanceOfType(hitObject))
continue;
pools[lookupType] = pool = p;
break;
}
}
return pool;
}
private readonly Dictionary<ISampleInfo, DrawablePool<PoolableSkinnableSample>> samplePools = new Dictionary<ISampleInfo, DrawablePool<PoolableSkinnableSample>>(); private readonly Dictionary<ISampleInfo, DrawablePool<PoolableSkinnableSample>> samplePools = new Dictionary<ISampleInfo, DrawablePool<PoolableSkinnableSample>>();
public PoolableSkinnableSample GetPooledSample(ISampleInfo sampleInfo) public PoolableSkinnableSample GetPooledSample(ISampleInfo sampleInfo) => prepareSamplePool(sampleInfo).Get();
{
if (!samplePools.TryGetValue(sampleInfo, out var existingPool))
AddInternal(samplePools[sampleInfo] = existingPool = new DrawableSamplePool(sampleInfo, 1));
return existingPool.Get(); private DrawablePool<PoolableSkinnableSample> prepareSamplePool(ISampleInfo sampleInfo)
{
if (samplePools.TryGetValue(sampleInfo, out var pool)) return pool;
AddInternal(samplePools[sampleInfo] = pool = new DrawableSamplePool(sampleInfo, 1));
return pool;
} }
private class DrawableSamplePool : DrawablePool<PoolableSkinnableSample> private class DrawableSamplePool : DrawablePool<PoolableSkinnableSample>

View File

@ -13,23 +13,13 @@ using osu.Framework.Graphics.Sprites;
using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osuTK; using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.Play.HUD.HitErrorMeters namespace osu.Game.Screens.Play.HUD.HitErrorMeters
{ {
public class BarHitErrorMeter : HitErrorMeter public class BarHitErrorMeter : HitErrorMeter
{ {
private const int arrow_move_duration = 400; private const int judgement_line_width = 14;
private const int judgement_line_height = 4;
private const int judgement_line_width = 6;
private const int bar_height = 200;
private const int bar_width = 2;
private const int spacing = 2;
private const float chevron_size = 8;
private SpriteIcon arrow; private SpriteIcon arrow;
private SpriteIcon iconEarly; private SpriteIcon iconEarly;
@ -50,17 +40,94 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
InternalChild = new FillFlowContainer const int centre_marker_size = 8;
const int bar_height = 200;
const int bar_width = 2;
const float chevron_size = 8;
const float icon_size = 14;
var hitWindows = HitWindows.GetAllAvailableWindows().ToArray();
InternalChild = new Container
{ {
AutoSizeAxes = Axes.X, AutoSizeAxes = Axes.X,
Height = bar_height, Height = bar_height,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(spacing, 0),
Margin = new MarginPadding(2), Margin = new MarginPadding(2),
Children = new Drawable[] Children = new Drawable[]
{ {
colourBars = new Container
{
Name = "colour axis",
X = chevron_size,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Width = judgement_line_width,
RelativeSizeAxes = Axes.Y,
Children = new Drawable[]
{
iconEarly = new SpriteIcon
{
Y = -10,
Size = new Vector2(icon_size),
Icon = FontAwesome.Solid.ShippingFast,
Anchor = Anchor.TopCentre,
Origin = Anchor.Centre,
},
iconLate = new SpriteIcon
{
Y = 10,
Size = new Vector2(icon_size),
Icon = FontAwesome.Solid.Bicycle,
Anchor = Anchor.BottomCentre,
Origin = Anchor.Centre,
},
colourBarsEarly = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.TopCentre,
Width = bar_width,
RelativeSizeAxes = Axes.Y,
Height = 0.5f,
Scale = new Vector2(1, -1),
},
colourBarsLate = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.TopCentre,
Width = bar_width,
RelativeSizeAxes = Axes.Y,
Height = 0.5f,
},
new Circle
{
Name = "middle marker behind",
Colour = GetColourForHitResult(hitWindows.Last().result),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(centre_marker_size),
},
judgementsContainer = new Container
{
Name = "judgements",
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.Y,
Width = judgement_line_width,
},
new Circle
{
Name = "middle marker in front",
Colour = GetColourForHitResult(hitWindows.Last().result).Darken(0.3f),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(centre_marker_size),
Scale = new Vector2(0.5f),
},
}
},
new Container new Container
{ {
Name = "average chevron",
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
Width = chevron_size, Width = chevron_size,
@ -75,58 +142,10 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
Size = new Vector2(chevron_size), Size = new Vector2(chevron_size),
} }
}, },
colourBars = new Container
{
Width = bar_width,
RelativeSizeAxes = Axes.Y,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Children = new Drawable[]
{
colourBarsEarly = new Container
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.TopRight,
RelativeSizeAxes = Axes.Both,
Height = 0.5f,
Scale = new Vector2(1, -1),
},
colourBarsLate = new Container
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.TopRight,
RelativeSizeAxes = Axes.Both,
Height = 0.5f,
},
iconEarly = new SpriteIcon
{
Y = -10,
Size = new Vector2(10),
Icon = FontAwesome.Solid.ShippingFast,
Anchor = Anchor.TopCentre,
Origin = Anchor.Centre,
},
iconLate = new SpriteIcon
{
Y = 10,
Size = new Vector2(10),
Icon = FontAwesome.Solid.Bicycle,
Anchor = Anchor.BottomCentre,
Origin = Anchor.Centre,
}
}
},
judgementsContainer = new Container
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Width = judgement_line_width,
RelativeSizeAxes = Axes.Y,
},
} }
}; };
createColourBars(); createColourBars(hitWindows);
} }
protected override void LoadComplete() protected override void LoadComplete()
@ -149,10 +168,8 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
iconLate.Rotation = -Rotation; iconLate.Rotation = -Rotation;
} }
private void createColourBars() private void createColourBars((HitResult result, double length)[] windows)
{ {
var windows = HitWindows.GetAllAvailableWindows().ToArray();
// max to avoid div-by-zero. // max to avoid div-by-zero.
maxHitWindow = Math.Max(1, windows.First().length); maxHitWindow = Math.Max(1, windows.First().length);
@ -166,17 +183,11 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
colourBarsLate.Add(createColourBar(result, hitWindow, i == 0)); colourBarsLate.Add(createColourBar(result, hitWindow, i == 0));
} }
// a little nub to mark the centre point. Drawable createColourBar(HitResult result, float height, bool requireGradient = false)
var centre = createColourBar(windows.Last().result, 0.01f);
centre.Anchor = centre.Origin = Anchor.CentreLeft;
centre.Width = 2.5f;
colourBars.Add(centre);
Drawable createColourBar(HitResult result, float height, bool first = false)
{ {
var colour = GetColourForHitResult(result); var colour = GetColourForHitResult(result);
if (first) if (requireGradient)
{ {
// the first bar needs gradient rendering. // the first bar needs gradient rendering.
const float gradient_start = 0.8f; const float gradient_start = 0.8f;
@ -220,6 +231,8 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
protected override void OnNewJudgement(JudgementResult judgement) protected override void OnNewJudgement(JudgementResult judgement)
{ {
const int arrow_move_duration = 800;
if (!judgement.IsHit || judgement.HitObject.HitWindows?.WindowFor(HitResult.Miss) == 0) if (!judgement.IsHit || judgement.HitObject.HitWindows?.WindowFor(HitResult.Miss) == 0)
return; return;
@ -243,46 +256,52 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
judgementsContainer.Add(new JudgementLine judgementsContainer.Add(new JudgementLine
{ {
Y = getRelativeJudgementPosition(judgement.TimeOffset), Y = getRelativeJudgementPosition(judgement.TimeOffset),
Origin = Anchor.CentreLeft, Colour = GetColourForHitResult(judgement.Type),
}); });
arrow.MoveToY( arrow.MoveToY(
getRelativeJudgementPosition(floatingAverage = floatingAverage * 0.9 + judgement.TimeOffset * 0.1) getRelativeJudgementPosition(floatingAverage = floatingAverage * 0.9 + judgement.TimeOffset * 0.1)
, arrow_move_duration, Easing.Out); , arrow_move_duration, Easing.OutQuint);
} }
private float getRelativeJudgementPosition(double value) => Math.Clamp((float)((value / maxHitWindow) + 1) / 2, 0, 1); private float getRelativeJudgementPosition(double value) => Math.Clamp((float)((value / maxHitWindow) + 1) / 2, 0, 1);
internal class JudgementLine : CompositeDrawable internal class JudgementLine : CompositeDrawable
{ {
private const int judgement_fade_duration = 5000;
public JudgementLine() public JudgementLine()
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
RelativePositionAxes = Axes.Y; RelativePositionAxes = Axes.Y;
Height = 3; Height = judgement_line_height;
InternalChild = new CircularContainer Blending = BlendingParameters.Additive;
{
Masking = true, Origin = Anchor.Centre;
RelativeSizeAxes = Axes.Both, Anchor = Anchor.TopCentre;
Child = new Box
InternalChild = new Circle
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = Color4.White,
}
}; };
} }
protected override void LoadComplete() protected override void LoadComplete()
{ {
const int judgement_fade_in_duration = 100;
const int judgement_fade_out_duration = 5000;
base.LoadComplete(); base.LoadComplete();
Alpha = 0;
Width = 0; Width = 0;
this.ResizeWidthTo(1, 200, Easing.OutElasticHalf); this
this.FadeTo(0.8f, 150).Then().FadeOut(judgement_fade_duration).Expire(); .FadeTo(0.6f, judgement_fade_in_duration, Easing.OutQuint)
.ResizeWidthTo(1, judgement_fade_in_duration, Easing.OutQuint)
.Then()
.FadeOut(judgement_fade_out_duration)
.ResizeWidthTo(0, judgement_fade_out_duration, Easing.InQuint)
.Expire();
} }
} }

View File

@ -28,7 +28,7 @@ namespace osu.Game.Skinning.Editor
protected override bool StartHidden => true; protected override bool StartHidden => true;
private readonly Drawable targetScreen; private Drawable targetScreen;
private OsuTextFlowContainer headerText; private OsuTextFlowContainer headerText;
@ -42,11 +42,13 @@ namespace osu.Game.Skinning.Editor
private bool hasBegunMutating; private bool hasBegunMutating;
private Container content;
public SkinEditor(Drawable targetScreen) public SkinEditor(Drawable targetScreen)
{ {
this.targetScreen = targetScreen;
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;
UpdateTargetScreen(targetScreen);
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -113,13 +115,9 @@ namespace osu.Game.Skinning.Editor
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
RequestPlacement = placeComponent RequestPlacement = placeComponent
}, },
new Container content = new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new SkinBlueprintContainer(targetScreen),
}
}, },
} }
} }
@ -147,6 +145,21 @@ namespace osu.Game.Skinning.Editor
}, true); }, true);
} }
public void UpdateTargetScreen(Drawable targetScreen)
{
this.targetScreen = targetScreen;
Scheduler.AddOnce(loadBlueprintContainer);
void loadBlueprintContainer()
{
content.Children = new Drawable[]
{
new SkinBlueprintContainer(targetScreen),
};
}
}
private void skinChanged() private void skinChanged()
{ {
headerText.Clear(); headerText.Clear();
@ -171,7 +184,12 @@ namespace osu.Game.Skinning.Editor
private void placeComponent(Type type) private void placeComponent(Type type)
{ {
var targetContainer = getTarget(SkinnableTarget.MainHUDComponents); var target = availableTargets.FirstOrDefault()?.Target;
if (target == null)
return;
var targetContainer = getTarget(target.Value);
if (targetContainer == null) if (targetContainer == null)
return; return;

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Diagnostics;
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -8,6 +9,7 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Screens;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Input.Bindings; using osu.Game.Input.Bindings;
@ -114,15 +116,39 @@ namespace osu.Game.Skinning.Editor
} }
/// <summary> /// <summary>
/// Exit any existing skin editor due to the game state changing. /// Set a new target screen which will be used to find skinnable components.
/// </summary> /// </summary>
public void Reset() public void SetTarget(Screen screen)
{ {
skinEditor?.Save(); if (skinEditor == null) return;
skinEditor?.Hide();
skinEditor?.Expire();
skinEditor.Save();
// AddOnce with parameter will ensure the newest target is loaded if there is any overlap.
Scheduler.AddOnce(setTarget, screen);
}
private void setTarget(Screen target)
{
Debug.Assert(skinEditor != null);
if (!target.IsCurrentScreen())
return;
if (!target.IsLoaded)
{
Scheduler.AddOnce(setTarget, target);
return;
}
if (skinEditor.State.Value == Visibility.Visible)
skinEditor.UpdateTargetScreen(target);
else
{
skinEditor.Hide();
skinEditor.Expire();
skinEditor = null; skinEditor = null;
} }
} }
}
} }

View File

@ -3,7 +3,6 @@
using System; using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions.EnumExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Animations; using osu.Framework.Graphics.Animations;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
@ -73,31 +72,7 @@ namespace osu.Game.Storyboards.Drawables
protected override Vector2 DrawScale protected override Vector2 DrawScale
=> new Vector2(FlipH ? -base.DrawScale.X : base.DrawScale.X, FlipV ? -base.DrawScale.Y : base.DrawScale.Y) * VectorScale; => new Vector2(FlipH ? -base.DrawScale.X : base.DrawScale.X, FlipV ? -base.DrawScale.Y : base.DrawScale.Y) * VectorScale;
public override Anchor Origin public override Anchor Origin => StoryboardExtensions.AdjustOrigin(base.Origin, VectorScale, FlipH, FlipV);
{
get
{
var origin = base.Origin;
if (FlipH)
{
if (origin.HasFlagFast(Anchor.x0))
origin = Anchor.x2 | (origin & (Anchor.y0 | Anchor.y1 | Anchor.y2));
else if (origin.HasFlagFast(Anchor.x2))
origin = Anchor.x0 | (origin & (Anchor.y0 | Anchor.y1 | Anchor.y2));
}
if (FlipV)
{
if (origin.HasFlagFast(Anchor.y0))
origin = Anchor.y2 | (origin & (Anchor.x0 | Anchor.x1 | Anchor.x2));
else if (origin.HasFlagFast(Anchor.y2))
origin = Anchor.y0 | (origin & (Anchor.x0 | Anchor.x1 | Anchor.x2));
}
return origin;
}
}
public override bool IsPresent public override bool IsPresent
=> !float.IsNaN(DrawPosition.X) && !float.IsNaN(DrawPosition.Y) && base.IsPresent; => !float.IsNaN(DrawPosition.X) && !float.IsNaN(DrawPosition.Y) && base.IsPresent;

View File

@ -3,7 +3,6 @@
using System; using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions.EnumExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
@ -73,31 +72,7 @@ namespace osu.Game.Storyboards.Drawables
protected override Vector2 DrawScale protected override Vector2 DrawScale
=> new Vector2(FlipH ? -base.DrawScale.X : base.DrawScale.X, FlipV ? -base.DrawScale.Y : base.DrawScale.Y) * VectorScale; => new Vector2(FlipH ? -base.DrawScale.X : base.DrawScale.X, FlipV ? -base.DrawScale.Y : base.DrawScale.Y) * VectorScale;
public override Anchor Origin public override Anchor Origin => StoryboardExtensions.AdjustOrigin(base.Origin, VectorScale, FlipH, FlipV);
{
get
{
var origin = base.Origin;
if (FlipH)
{
if (origin.HasFlagFast(Anchor.x0))
origin = Anchor.x2 | (origin & (Anchor.y0 | Anchor.y1 | Anchor.y2));
else if (origin.HasFlagFast(Anchor.x2))
origin = Anchor.x0 | (origin & (Anchor.y0 | Anchor.y1 | Anchor.y2));
}
if (FlipV)
{
if (origin.HasFlagFast(Anchor.y0))
origin = Anchor.y2 | (origin & (Anchor.x0 | Anchor.x1 | Anchor.x2));
else if (origin.HasFlagFast(Anchor.y2))
origin = Anchor.y0 | (origin & (Anchor.x0 | Anchor.x1 | Anchor.x2));
}
return origin;
}
}
public override bool IsPresent public override bool IsPresent
=> !float.IsNaN(DrawPosition.X) && !float.IsNaN(DrawPosition.Y) && base.IsPresent; => !float.IsNaN(DrawPosition.X) && !float.IsNaN(DrawPosition.Y) && base.IsPresent;

View File

@ -104,7 +104,13 @@ namespace osu.Game.Storyboards
drawable = new Sprite { Texture = textureStore.Get(storyboardPath) }; drawable = new Sprite { Texture = textureStore.Get(storyboardPath) };
// if the texture isn't available locally in the beatmap, some storyboards choose to source from the underlying skin lookup hierarchy. // if the texture isn't available locally in the beatmap, some storyboards choose to source from the underlying skin lookup hierarchy.
else if (UseSkinSprites) else if (UseSkinSprites)
drawable = new SkinnableSprite(path); {
drawable = new SkinnableSprite(path)
{
RelativeSizeAxes = Axes.None,
AutoSizeAxes = Axes.Both,
};
}
return drawable; return drawable;
} }

View File

@ -0,0 +1,43 @@
// 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.Extensions.EnumExtensions;
using osu.Framework.Graphics;
using osuTK;
namespace osu.Game.Storyboards
{
public static class StoryboardExtensions
{
/// <summary>
/// Given an origin and a set of properties, adjust the origin to display the sprite/animation correctly.
/// </summary>
/// <param name="origin">The current origin.</param>
/// <param name="vectorScale">The vector scale.</param>
/// <param name="flipH">Whether the element is flipped horizontally.</param>
/// <param name="flipV">Whether the element is flipped vertically.</param>
/// <returns>The adjusted origin.</returns>
public static Anchor AdjustOrigin(Anchor origin, Vector2 vectorScale, bool flipH, bool flipV)
{
// Either flip horizontally or negative X scale, but not both.
if (flipH ^ (vectorScale.X < 0))
{
if (origin.HasFlagFast(Anchor.x0))
origin = Anchor.x2 | (origin & (Anchor.y0 | Anchor.y1 | Anchor.y2));
else if (origin.HasFlagFast(Anchor.x2))
origin = Anchor.x0 | (origin & (Anchor.y0 | Anchor.y1 | Anchor.y2));
}
// Either flip vertically or negative Y scale, but not both.
if (flipV ^ (vectorScale.Y < 0))
{
if (origin.HasFlagFast(Anchor.y0))
origin = Anchor.y2 | (origin & (Anchor.x0 | Anchor.x1 | Anchor.x2));
else if (origin.HasFlagFast(Anchor.y2))
origin = Anchor.y0 | (origin & (Anchor.x0 | Anchor.x1 | Anchor.x2));
}
return origin;
}
}
}