2019-01-24 08:43:03 +00:00
|
|
|
// 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.
|
2018-12-20 07:50:38 +00:00
|
|
|
|
2018-12-20 09:21:37 +00:00
|
|
|
using osu.Framework.Allocation;
|
2018-12-20 07:50:38 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Game.Online.Chat;
|
|
|
|
using osu.Game.Users;
|
|
|
|
using osuTK;
|
2019-10-21 22:37:30 +00:00
|
|
|
using System;
|
2019-10-29 05:32:38 +00:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-10-29 06:27:08 +00:00
|
|
|
using osu.Game.Graphics.Containers;
|
2019-10-29 05:32:38 +00:00
|
|
|
using osu.Game.Overlays.Chat;
|
2018-12-20 07:50:38 +00:00
|
|
|
|
2019-03-24 16:02:36 +00:00
|
|
|
namespace osu.Game.Tests.Visual.Online
|
2018-12-20 07:50:38 +00:00
|
|
|
{
|
2019-05-14 19:37:25 +00:00
|
|
|
public class TestSceneStandAloneChatDisplay : OsuTestScene
|
2018-12-20 07:50:38 +00:00
|
|
|
{
|
|
|
|
private readonly Channel testChannel = new Channel();
|
|
|
|
|
|
|
|
private readonly User admin = new User
|
|
|
|
{
|
|
|
|
Username = "HappyStick",
|
|
|
|
Id = 2,
|
|
|
|
Colour = "f2ca34"
|
|
|
|
};
|
|
|
|
|
|
|
|
private readonly User redUser = new User
|
|
|
|
{
|
|
|
|
Username = "BanchoBot",
|
|
|
|
Id = 3,
|
|
|
|
};
|
|
|
|
|
|
|
|
private readonly User blueUser = new User
|
|
|
|
{
|
|
|
|
Username = "Zallius",
|
|
|
|
Id = 4,
|
|
|
|
};
|
|
|
|
|
2019-10-01 13:47:53 +00:00
|
|
|
private readonly User longUsernameUser = new User
|
|
|
|
{
|
|
|
|
Username = "Very Long Long Username",
|
|
|
|
Id = 5,
|
|
|
|
};
|
|
|
|
|
2018-12-20 09:21:37 +00:00
|
|
|
[Cached]
|
|
|
|
private ChannelManager channelManager = new ChannelManager();
|
|
|
|
|
2019-10-29 05:32:38 +00:00
|
|
|
private readonly TestStandAloneChatDisplay chatDisplay;
|
|
|
|
private readonly TestStandAloneChatDisplay chatDisplay2;
|
2018-12-20 09:21:37 +00:00
|
|
|
|
2019-05-14 19:37:25 +00:00
|
|
|
public TestSceneStandAloneChatDisplay()
|
2018-12-20 07:50:38 +00:00
|
|
|
{
|
2018-12-20 09:21:37 +00:00
|
|
|
Add(channelManager);
|
2018-12-20 07:50:38 +00:00
|
|
|
|
2019-10-29 05:32:38 +00:00
|
|
|
Add(chatDisplay = new TestStandAloneChatDisplay
|
2018-12-20 07:50:38 +00:00
|
|
|
{
|
2018-12-20 09:21:37 +00:00
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Margin = new MarginPadding(20),
|
2018-12-20 07:50:38 +00:00
|
|
|
Size = new Vector2(400, 80)
|
|
|
|
});
|
|
|
|
|
2019-10-29 05:32:38 +00:00
|
|
|
Add(chatDisplay2 = new TestStandAloneChatDisplay(true)
|
2018-12-20 09:21:37 +00:00
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
Margin = new MarginPadding(20),
|
|
|
|
Size = new Vector2(400, 150)
|
|
|
|
});
|
2018-12-20 07:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2018-12-20 09:21:37 +00:00
|
|
|
channelManager.CurrentChannel.Value = testChannel;
|
|
|
|
|
|
|
|
chatDisplay.Channel.Value = testChannel;
|
|
|
|
chatDisplay2.Channel.Value = testChannel;
|
|
|
|
|
2018-12-21 08:54:12 +00:00
|
|
|
int sequence = 0;
|
|
|
|
|
|
|
|
AddStep("message from admin", () => testChannel.AddNewMessages(new Message(sequence++)
|
2018-12-20 07:50:38 +00:00
|
|
|
{
|
|
|
|
Sender = admin,
|
|
|
|
Content = "I am a wang!"
|
|
|
|
}));
|
|
|
|
|
2018-12-21 08:54:12 +00:00
|
|
|
AddStep("message from team red", () => testChannel.AddNewMessages(new Message(sequence++)
|
2018-12-20 07:50:38 +00:00
|
|
|
{
|
|
|
|
Sender = redUser,
|
|
|
|
Content = "I am team red."
|
|
|
|
}));
|
|
|
|
|
2018-12-21 08:54:12 +00:00
|
|
|
AddStep("message from team red", () => testChannel.AddNewMessages(new Message(sequence++)
|
2018-12-20 07:50:38 +00:00
|
|
|
{
|
|
|
|
Sender = redUser,
|
|
|
|
Content = "I plan to win!"
|
|
|
|
}));
|
|
|
|
|
2018-12-21 08:54:12 +00:00
|
|
|
AddStep("message from team blue", () => testChannel.AddNewMessages(new Message(sequence++)
|
2018-12-20 07:50:38 +00:00
|
|
|
{
|
|
|
|
Sender = blueUser,
|
|
|
|
Content = "Not on my watch. Prepare to eat saaaaaaaaaand. Lots and lots of saaaaaaand."
|
|
|
|
}));
|
|
|
|
|
2018-12-21 08:54:12 +00:00
|
|
|
AddStep("message from admin", () => testChannel.AddNewMessages(new Message(sequence++)
|
2018-12-20 07:50:38 +00:00
|
|
|
{
|
|
|
|
Sender = admin,
|
|
|
|
Content = "Okay okay, calm down guys. Let's do this!"
|
|
|
|
}));
|
2019-10-01 13:47:53 +00:00
|
|
|
|
|
|
|
AddStep("message from long username", () => testChannel.AddNewMessages(new Message(sequence++)
|
|
|
|
{
|
|
|
|
Sender = longUsernameUser,
|
|
|
|
Content = "Hi guys, my new username is lit!"
|
|
|
|
}));
|
2019-10-21 22:37:30 +00:00
|
|
|
|
|
|
|
AddStep("message with new date", () => testChannel.AddNewMessages(new Message(sequence++)
|
|
|
|
{
|
|
|
|
Sender = longUsernameUser,
|
|
|
|
Content = "Message from the future!",
|
|
|
|
Timestamp = DateTimeOffset.Now
|
|
|
|
}));
|
2019-10-29 05:32:38 +00:00
|
|
|
|
|
|
|
AddUntilStep("ensure still scrolled to bottom", () => chatDisplay.ScrolledToBottom);
|
|
|
|
|
|
|
|
const int messages_per_call = 10;
|
|
|
|
AddRepeatStep("add many messages", () =>
|
|
|
|
{
|
|
|
|
for (int i = 0; i < messages_per_call; i++)
|
|
|
|
testChannel.AddNewMessages(new Message(sequence++)
|
|
|
|
{
|
|
|
|
Sender = longUsernameUser,
|
|
|
|
Content = "Many messages! " + Guid.NewGuid(),
|
|
|
|
Timestamp = DateTimeOffset.Now
|
|
|
|
});
|
|
|
|
}, Channel.MAX_HISTORY / messages_per_call + 5);
|
|
|
|
|
2019-10-29 06:27:08 +00:00
|
|
|
AddAssert("Ensure no adjacent day separators", () =>
|
|
|
|
{
|
|
|
|
var indices = chatDisplay.FillFlow.OfType<DrawableChannel.DaySeparator>().Select(ds => chatDisplay.FillFlow.IndexOf(ds));
|
|
|
|
|
|
|
|
foreach (var i in indices)
|
|
|
|
if (i < chatDisplay.FillFlow.Count && chatDisplay.FillFlow[i + 1] is DrawableChannel.DaySeparator)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
2019-10-29 05:32:38 +00:00
|
|
|
AddUntilStep("ensure still scrolled to bottom", () => chatDisplay.ScrolledToBottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
private class TestStandAloneChatDisplay : StandAloneChatDisplay
|
|
|
|
{
|
|
|
|
public TestStandAloneChatDisplay(bool textbox = false)
|
|
|
|
: base(textbox)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-10-29 06:27:08 +00:00
|
|
|
protected DrawableChannel DrawableChannel => InternalChildren.OfType<DrawableChannel>().First();
|
|
|
|
|
|
|
|
protected OsuScrollContainer ScrollContainer => (OsuScrollContainer)((Container)DrawableChannel.Child).Child;
|
|
|
|
|
|
|
|
public FillFlowContainer FillFlow => (FillFlowContainer)ScrollContainer.Child;
|
|
|
|
|
|
|
|
public bool ScrolledToBottom => ScrollContainer.IsScrolledToEnd(1);
|
2018-12-20 07:50:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|