Merge branch 'master' into mod-consistency-function

This commit is contained in:
Dean Herbert 2021-02-02 20:01:42 +09:00 committed by GitHub
commit ac5662b1aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 250 additions and 70 deletions

View File

@ -30,7 +30,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.6" />
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="DiscordRichPresence" Version="1.0.169" />
<PackageReference Include="DiscordRichPresence" Version="1.0.175" />
</ItemGroup>
<ItemGroup Label="Resources">
<EmbeddedResource Include="lazer.ico" />

View File

@ -8,16 +8,16 @@
using osuTK;
using System;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.Containers;
using osu.Game.Overlays.Chat;
using osuTK.Input;
namespace osu.Game.Tests.Visual.Online
{
public class TestSceneStandAloneChatDisplay : OsuTestScene
public class TestSceneStandAloneChatDisplay : OsuManualInputManagerTestScene
{
private readonly Channel testChannel = new Channel();
private readonly User admin = new User
{
Username = "HappyStick",
@ -46,92 +46,97 @@ public class TestSceneStandAloneChatDisplay : OsuTestScene
[Cached]
private ChannelManager channelManager = new ChannelManager();
private readonly TestStandAloneChatDisplay chatDisplay;
private readonly TestStandAloneChatDisplay chatDisplay2;
private TestStandAloneChatDisplay chatDisplay;
private int messageIdSequence;
private Channel testChannel;
public TestSceneStandAloneChatDisplay()
{
Add(channelManager);
Add(chatDisplay = new TestStandAloneChatDisplay
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding(20),
Size = new Vector2(400, 80)
});
Add(chatDisplay2 = new TestStandAloneChatDisplay(true)
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Margin = new MarginPadding(20),
Size = new Vector2(400, 150)
});
}
protected override void LoadComplete()
[SetUp]
public void SetUp() => Schedule(() =>
{
base.LoadComplete();
messageIdSequence = 0;
channelManager.CurrentChannel.Value = testChannel = new Channel();
channelManager.CurrentChannel.Value = testChannel;
Children = new[]
{
chatDisplay = new TestStandAloneChatDisplay
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding(20),
Size = new Vector2(400, 80),
Channel = { Value = testChannel },
},
new TestStandAloneChatDisplay(true)
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Margin = new MarginPadding(20),
Size = new Vector2(400, 150),
Channel = { Value = testChannel },
}
};
});
chatDisplay.Channel.Value = testChannel;
chatDisplay2.Channel.Value = testChannel;
int sequence = 0;
AddStep("message from admin", () => testChannel.AddNewMessages(new Message(sequence++)
[Test]
public void TestManyMessages()
{
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(sequence++)
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(sequence++)
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(sequence++)
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(sequence++)
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(sequence++)
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(sequence++)
AddStep("message with new date", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
{
Sender = longUsernameUser,
Content = "Message from the future!",
Timestamp = DateTimeOffset.Now
}));
AddUntilStep("ensure still scrolled to bottom", () => chatDisplay.ScrolledToBottom);
checkScrolledToBottom();
const int messages_per_call = 10;
AddRepeatStep("add many messages", () =>
{
for (int i = 0; i < messages_per_call; i++)
{
testChannel.AddNewMessages(new Message(sequence++)
testChannel.AddNewMessages(new Message(messageIdSequence++)
{
Sender = longUsernameUser,
Content = "Many messages! " + Guid.NewGuid(),
@ -153,9 +158,133 @@ protected override void LoadComplete()
return true;
});
AddUntilStep("ensure still scrolled to bottom", () => chatDisplay.ScrolledToBottom);
checkScrolledToBottom();
}
/// <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.
/// </summary>
[Test]
public void TestMessageWrappingKeepsAutoScrolling()
{
fillChat();
// send message with short words for text wrapping to occur when contracting chat.
sendMessage();
AddStep("contract chat", () => chatDisplay.Width -= 100);
checkScrolledToBottom();
AddStep("send another message", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
{
Sender = admin,
Content = "As we were saying...",
}));
checkScrolledToBottom();
}
[Test]
public void TestUserScrollOverride()
{
fillChat();
sendMessage();
checkScrolledToBottom();
AddStep("User scroll up", () =>
{
InputManager.MoveMouseTo(chatDisplay.ScreenSpaceDrawQuad.Centre);
InputManager.PressButton(MouseButton.Left);
InputManager.MoveMouseTo(chatDisplay.ScreenSpaceDrawQuad.Centre + new Vector2(0, chatDisplay.ScreenSpaceDrawQuad.Height));
InputManager.ReleaseButton(MouseButton.Left);
});
checkNotScrolledToBottom();
sendMessage();
checkNotScrolledToBottom();
AddRepeatStep("User scroll to bottom", () =>
{
InputManager.MoveMouseTo(chatDisplay.ScreenSpaceDrawQuad.Centre);
InputManager.PressButton(MouseButton.Left);
InputManager.MoveMouseTo(chatDisplay.ScreenSpaceDrawQuad.Centre - new Vector2(0, chatDisplay.ScreenSpaceDrawQuad.Height));
InputManager.ReleaseButton(MouseButton.Left);
}, 5);
checkScrolledToBottom();
sendMessage();
checkScrolledToBottom();
}
[Test]
public void TestLocalEchoMessageResetsScroll()
{
fillChat();
sendMessage();
checkScrolledToBottom();
AddStep("User scroll up", () =>
{
InputManager.MoveMouseTo(chatDisplay.ScreenSpaceDrawQuad.Centre);
InputManager.PressButton(MouseButton.Left);
InputManager.MoveMouseTo(chatDisplay.ScreenSpaceDrawQuad.Centre + new Vector2(0, chatDisplay.ScreenSpaceDrawQuad.Height));
InputManager.ReleaseButton(MouseButton.Left);
});
checkNotScrolledToBottom();
sendMessage();
checkNotScrolledToBottom();
sendLocalMessage();
checkScrolledToBottom();
sendMessage();
checkScrolledToBottom();
}
private void fillChat()
{
AddStep("fill chat", () =>
{
for (int i = 0; i < 10; i++)
{
testChannel.AddNewMessages(new Message(messageIdSequence++)
{
Sender = longUsernameUser,
Content = $"some stuff {Guid.NewGuid()}",
});
}
});
checkScrolledToBottom();
}
private void sendMessage()
{
AddStep("send lorem ipsum", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
{
Sender = longUsernameUser,
Content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce et bibendum velit.",
}));
}
private void sendLocalMessage()
{
AddStep("send local echo", () => testChannel.AddLocalEcho(new LocalEchoMessage
{
Sender = longUsernameUser,
Content = "This is a local echo message.",
}));
}
private void checkScrolledToBottom() =>
AddUntilStep("is scrolled to bottom", () => chatDisplay.ScrolledToBottom);
private void checkNotScrolledToBottom() =>
AddUntilStep("not scrolled to bottom", () => !chatDisplay.ScrolledToBottom);
private class TestStandAloneChatDisplay : StandAloneChatDisplay
{
public TestStandAloneChatDisplay(bool textbox = false)
@ -165,7 +294,7 @@ public TestStandAloneChatDisplay(bool textbox = false)
protected DrawableChannel DrawableChannel => InternalChildren.OfType<DrawableChannel>().First();
protected OsuScrollContainer ScrollContainer => (OsuScrollContainer)((Container)DrawableChannel.Child).Child;
protected UserTrackingScrollContainer ScrollContainer => (UserTrackingScrollContainer)((Container)DrawableChannel.Child).Child;
public FillFlowContainer FillFlow => (FillFlowContainer)ScrollContainer.Child;

View File

@ -4,7 +4,6 @@
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Game.Graphics.Containers;
@ -28,12 +27,7 @@ public override void SetUpSteps()
{
base.SetUpSteps();
AddStep("push screen", () => LoadScreen(loungeScreen = new PlaylistsLoungeSubScreen
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Width = 0.5f,
}));
AddStep("push screen", () => LoadScreen(loungeScreen = new PlaylistsLoungeSubScreen()));
AddUntilStep("wait for present", () => loungeScreen.IsCurrentScreen());
}

View File

@ -25,6 +25,8 @@ public class UserTrackingScrollContainer<T> : OsuScrollContainer<T>
/// </summary>
public bool UserScrolling { get; private set; }
public void CancelUserScroll() => UserScrolling = false;
public UserTrackingScrollContainer()
{
}
@ -45,5 +47,11 @@ protected override void OnUserScroll(float value, bool animated = true, double?
UserScrolling = false;
base.ScrollTo(value, animated, distanceDecay);
}
public new void ScrollToEnd(bool animated = true, bool allowDuringDrag = false)
{
UserScrolling = false;
base.ScrollToEnd(animated, allowDuringDrag);
}
}
}

View File

@ -16,6 +16,7 @@
using osu.Game.Graphics;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Utils;
using osu.Game.Graphics.Sprites;
namespace osu.Game.Overlays.Chat
@ -24,7 +25,7 @@ public class DrawableChannel : Container
{
public readonly Channel Channel;
protected FillFlowContainer ChatLineFlow;
private OsuScrollContainer scroll;
private ChannelScrollContainer scroll;
private bool scrollbarVisible = true;
@ -56,7 +57,7 @@ private void load()
{
RelativeSizeAxes = Axes.Both,
Masking = true,
Child = scroll = new OsuScrollContainer
Child = scroll = new ChannelScrollContainer
{
ScrollbarVisible = scrollbarVisible,
RelativeSizeAxes = Axes.Both,
@ -80,12 +81,6 @@ private void load()
Channel.PendingMessageResolved += pendingMessageResolved;
}
protected override void LoadComplete()
{
base.LoadComplete();
scrollToEnd();
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
@ -113,8 +108,6 @@ private void newMessagesArrived(IEnumerable<Message> newMessages) => Schedule(()
ChatLineFlow.Clear();
}
bool shouldScrollToEnd = scroll.IsScrolledToEnd(10) || !chatLines.Any() || newMessages.Any(m => m is LocalMessage);
// Add up to last Channel.MAX_HISTORY messages
var displayMessages = newMessages.Skip(Math.Max(0, newMessages.Count() - Channel.MAX_HISTORY));
@ -153,8 +146,10 @@ void expireAndAdjustScroll(Drawable d)
}
}
if (shouldScrollToEnd)
scrollToEnd();
// due to the scroll adjusts from old messages removal above, a scroll-to-end must be enforced,
// to avoid making the container think the user has scrolled back up and unwantedly disable auto-scrolling.
if (newMessages.Any(m => m is LocalMessage))
scroll.ScrollToEnd();
});
private void pendingMessageResolved(Message existing, Message updated) => Schedule(() =>
@ -178,8 +173,6 @@ private void messageRemoved(Message removed) => Schedule(() =>
private IEnumerable<ChatLine> chatLines => ChatLineFlow.Children.OfType<ChatLine>();
private void scrollToEnd() => ScheduleAfterChildren(() => scroll.ScrollToEnd());
public class DaySeparator : Container
{
public float TextSize
@ -243,5 +236,51 @@ public DaySeparator(DateTimeOffset time)
};
}
}
/// <summary>
/// An <see cref="OsuScrollContainer"/> with functionality to automatically scroll whenever the maximum scrollable distance increases.
/// </summary>
private class ChannelScrollContainer : UserTrackingScrollContainer
{
/// <summary>
/// The chat will be automatically scrolled to end if and only if
/// the distance between the current scroll position and the end of the scroll
/// is less than this value.
/// </summary>
private const float auto_scroll_leniency = 10f;
private float? lastExtent;
protected override void OnUserScroll(float value, bool animated = true, double? distanceDecay = default)
{
base.OnUserScroll(value, animated, distanceDecay);
lastExtent = null;
}
protected override void Update()
{
base.Update();
// If the user has scrolled to the bottom of the container, we should resume tracking new content.
if (UserScrolling && IsScrolledToEnd(auto_scroll_leniency))
CancelUserScroll();
// If the user hasn't overridden our behaviour and there has been new content added to the container, we should update our scroll position to track it.
bool requiresScrollUpdate = !UserScrolling && (lastExtent == null || Precision.AlmostBigger(ScrollableExtent, lastExtent.Value));
if (requiresScrollUpdate)
{
// Schedule required to allow FillFlow to be the correct size.
Schedule(() =>
{
if (!UserScrolling)
{
ScrollToEnd();
lastExtent = ScrollableExtent;
}
});
}
}
}
}
}

View File

@ -109,7 +109,16 @@ private void load(OsuColour colours, GameHost host, OsuConfigManager config)
if (Beatmap.Value is DummyWorkingBeatmap)
{
isNewBeatmap = true;
Beatmap.Value = beatmapManager.CreateNew(Ruleset.Value, api.LocalUser.Value);
var newBeatmap = beatmapManager.CreateNew(Ruleset.Value, api.LocalUser.Value);
// this is a bit haphazard, but guards against setting the lease Beatmap bindable if
// the editor has already been exited.
if (!ValidForPush)
return;
// this probably shouldn't be set in the asynchronous load method, but everything following relies on it.
Beatmap.Value = newBeatmap;
}
beatDivisor.Value = Beatmap.Value.BeatmapInfo.BeatDivisor;

View File

@ -200,7 +200,7 @@ private void load(OsuColour colours)
Child = new GridContainer
{
RelativeSizeAxes = Axes.X,
Height = 300,
Height = 500,
Content = new[]
{
new Drawable[]

View File

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using osu.Game.Rulesets.Mods;
@ -45,7 +46,7 @@ public static bool CheckCompatibleSet(IEnumerable<Mod> combination)
/// <param name="combination">The <see cref="Mod"/> combination to check.</param>
/// <param name="invalidMods">Any invalid mods in the set.</param>
/// <returns>Whether all <see cref="Mod"/>s in the combination are compatible with each-other.</returns>
public static bool CheckCompatibleSet(IEnumerable<Mod> combination, out List<Mod>? invalidMods)
public static bool CheckCompatibleSet(IEnumerable<Mod> combination, [NotNullWhen(false)] out List<Mod>? invalidMods)
{
combination = FlattenMods(combination).ToArray();
invalidMods = null;

View File

@ -23,7 +23,7 @@ public SentryLogger(OsuGame game)
var options = new SentryOptions
{
Dsn = new Dsn("https://5e342cd55f294edebdc9ad604d28bbd3@sentry.io/1255255"),
Dsn = "https://5e342cd55f294edebdc9ad604d28bbd3@sentry.io/1255255",
Release = game.Version
};

View File

@ -29,8 +29,8 @@
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="ppy.osu.Framework" Version="2021.128.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2020.1202.0" />
<PackageReference Include="Sentry" Version="2.1.8" />
<PackageReference Include="SharpCompress" Version="0.26.0" />
<PackageReference Include="Sentry" Version="3.0.1" />
<PackageReference Include="SharpCompress" Version="0.27.1" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>

View File

@ -89,10 +89,10 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="ppy.osu.Framework" Version="2021.128.0" />
<PackageReference Include="SharpCompress" Version="0.26.0" />
<PackageReference Include="SharpCompress" Version="0.27.1" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="SharpRaven" Version="2.4.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="ppy.osu.Framework.NativeLibs" Version="2020.923.0" ExcludeAssets="all" />
<PackageReference Include="ppy.osu.Framework.NativeLibs" Version="2021.115.0" ExcludeAssets="all" />
</ItemGroup>
</Project>