2017-12-07 20:17:51 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
2017-12-07 17:29:33 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Online.Chat;
|
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
|
using osu.Game.Overlays.Chat;
|
|
|
|
|
using osu.Game.Users;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
|
{
|
2017-12-26 02:43:35 +08:00
|
|
|
|
public class TestCaseChatLink : OsuTestCase
|
2017-12-07 17:29:33 +08:00
|
|
|
|
{
|
|
|
|
|
private readonly BeatmapSetOverlay beatmapSetOverlay;
|
|
|
|
|
private readonly ChatOverlay chat;
|
|
|
|
|
|
|
|
|
|
private DependencyContainer dependencies;
|
|
|
|
|
|
2017-12-07 18:11:43 +08:00
|
|
|
|
private readonly TestChatLineContainer textContainer;
|
2017-12-07 17:29:33 +08:00
|
|
|
|
|
|
|
|
|
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) => dependencies = new DependencyContainer(parent);
|
|
|
|
|
|
|
|
|
|
public TestCaseChatLink()
|
|
|
|
|
{
|
|
|
|
|
chat = new ChatOverlay();
|
2017-12-07 18:11:43 +08:00
|
|
|
|
Add(beatmapSetOverlay = new BeatmapSetOverlay { Depth = float.MinValue });
|
2017-12-07 17:29:33 +08:00
|
|
|
|
|
2017-12-07 18:11:43 +08:00
|
|
|
|
Add(textContainer = new TestChatLineContainer
|
2017-12-07 17:29:33 +08:00
|
|
|
|
{
|
|
|
|
|
Padding = new MarginPadding { Left = 20, Right = 20 },
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-28 00:14:08 +08:00
|
|
|
|
testAddLinks();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void testAddLinks()
|
|
|
|
|
{
|
|
|
|
|
int msgCounter = 0;
|
|
|
|
|
void addMessage(string text, bool isAction = false) => AddStep($"Add message #{++msgCounter}", () => textContainer.Add(new ChatLine(new DummyMessage(text, isAction))));
|
|
|
|
|
|
|
|
|
|
addMessage("Test!");
|
|
|
|
|
addMessage("osu.ppy.sh!");
|
|
|
|
|
addMessage("https://osu.ppy.sh!");
|
|
|
|
|
addMessage("00:12:345 (1,2) - Test?");
|
|
|
|
|
addMessage("Wiki link for tasty [[Performance Points]]");
|
|
|
|
|
addMessage("(osu forums)[https://osu.ppy.sh/forum] (old link format)");
|
|
|
|
|
addMessage("[https://osu.ppy.sh/home New site] (new link format)");
|
|
|
|
|
addMessage("[https://osu.ppy.sh/home This is only a link to the new osu webpage but this is supposed to test word wrap.]");
|
|
|
|
|
addMessage("is now listening to [https://osu.ppy.sh/s/93523 IMAGE -MATERIAL- <Version 0>]", true);
|
|
|
|
|
addMessage("is now playing [https://osu.ppy.sh/b/252238 IMAGE -MATERIAL- <Version 0>]", true);
|
|
|
|
|
addMessage("#lobby or #osu would be blue (and work) in the ChatDisplay test (when a proper ChatOverlay is present).");
|
2017-12-07 17:29:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
|
|
|
|
dependencies.Cache(chat);
|
|
|
|
|
dependencies.Cache(beatmapSetOverlay);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class DummyMessage : Message
|
|
|
|
|
{
|
2017-12-07 23:41:46 +08:00
|
|
|
|
private static long messageCounter;
|
2017-12-08 02:39:13 +08:00
|
|
|
|
private static readonly User sender = new User
|
2017-12-07 17:29:33 +08:00
|
|
|
|
{
|
|
|
|
|
Username = @"Somebody",
|
|
|
|
|
Id = 1,
|
|
|
|
|
Country = new Country { FullName = @"Alien" },
|
|
|
|
|
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c1.jpg",
|
|
|
|
|
JoinDate = DateTimeOffset.Now.AddDays(-1),
|
|
|
|
|
LastVisit = DateTimeOffset.Now,
|
|
|
|
|
Age = 1,
|
|
|
|
|
ProfileOrder = new[] { "me" },
|
|
|
|
|
CountryRank = 1,
|
|
|
|
|
Statistics = new UserStatistics
|
|
|
|
|
{
|
|
|
|
|
Rank = 2148,
|
|
|
|
|
PP = 4567.89m
|
|
|
|
|
},
|
|
|
|
|
RankHistory = new User.RankHistoryData
|
|
|
|
|
{
|
|
|
|
|
Mode = @"osu",
|
2017-12-07 20:17:51 +08:00
|
|
|
|
Data = Enumerable.Range(2345, 45).Concat(Enumerable.Range(2109, 40)).ToArray(),
|
2017-12-07 17:29:33 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
2017-12-07 20:17:51 +08:00
|
|
|
|
|
2017-12-07 17:29:33 +08:00
|
|
|
|
public new DateTimeOffset Timestamp = DateTimeOffset.Now;
|
|
|
|
|
|
|
|
|
|
public DummyMessage(string text, bool isAction = false)
|
|
|
|
|
: base(messageCounter++)
|
|
|
|
|
{
|
|
|
|
|
Content = text;
|
|
|
|
|
IsAction = isAction;
|
|
|
|
|
Sender = sender;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-07 18:11:43 +08:00
|
|
|
|
private class TestChatLineContainer : FillFlowContainer<ChatLine>
|
2017-12-07 17:29:33 +08:00
|
|
|
|
{
|
|
|
|
|
protected override int Compare(Drawable x, Drawable y)
|
|
|
|
|
{
|
|
|
|
|
var xC = (ChatLine)x;
|
|
|
|
|
var yC = (ChatLine)y;
|
|
|
|
|
|
|
|
|
|
return xC.Message.CompareTo(yC.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|