From 754d9c78bd8baa0750195b7fb0ead9ad9eab2c72 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 27 Sep 2016 19:22:22 +0900 Subject: [PATCH] Simple chat message display functionality. --- .../Tests/TestCaseChatDisplay.cs | 44 +++++++++---------- osu.Game/Online/Chat/Message.cs | 4 +- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseChatDisplay.cs b/osu.Desktop.VisualTests/Tests/TestCaseChatDisplay.cs index d883895a94..8f939501c9 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseChatDisplay.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseChatDisplay.cs @@ -14,6 +14,7 @@ using osu.Game.Online.Chat; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using osu.Framework.Graphics.Sprites; namespace osu.Desktop.Tests { @@ -24,26 +25,19 @@ namespace osu.Desktop.Tests public override string Name => @"Chat"; public override string Description => @"Testing API polling"; - List channels = new List(); + private List channels = new List(); private FlowContainer flow; - Scheduler scheduler = new Scheduler(); + private Scheduler scheduler = new Scheduler(); private APIAccess api => ((OsuGameBase)Game).API; + private long? lastMessageId; + public override void Reset() { base.Reset(); - flow = new FlowContainer() - { - Direction = FlowDirection.VerticalOnly, - LayoutDuration = 100, - LayoutEasing = EasingTypes.Out, - Padding = new Vector2(1, 1) - }; - - lastMessageId = null; if (api.State != APIAccess.APIState.Online) @@ -51,14 +45,20 @@ namespace osu.Desktop.Tests else initializeChannels(); - - ScrollContainer scrolling = new ScrollContainer() + Add(new ScrollContainer() { - Size = new Vector2(1, 0.5f) - }; - - scrolling.Add(flow); - Add(scrolling); + Size = new Vector2(1, 0.5f), + Children = new Drawable[] + { + flow = new FlowContainer + { + Direction = FlowDirection.VerticalOnly, + LayoutDuration = 100, + LayoutEasing = EasingTypes.Out, + Padding = new Vector2(1, 1) + } + } + }); } protected override void Update() @@ -83,8 +83,6 @@ namespace osu.Desktop.Tests api.Queue(req); } - long? lastMessageId = null; - private void requestNewMessages() { messageRequest.Wait(); @@ -94,7 +92,6 @@ namespace osu.Desktop.Tests GetMessagesRequest gm = new GetMessagesRequest(new List { channel }, lastMessageId); gm.Success += delegate (List messages) { - channel.Messages.Clear(); foreach (Message m in messages) { //m.LineWidth = this.Size.X; //this is kinda ugly. @@ -108,7 +105,10 @@ namespace osu.Desktop.Tests // osu.Messages[0].Drawable.Expire(); // osu.Messages.RemoveAt(0); //} - + flow.Add(new SpriteText + { + Text = $@"{m.User.Name}: {m.Content}" + }); channel.Messages.Add(m); } diff --git a/osu.Game/Online/Chat/Message.cs b/osu.Game/Online/Chat/Message.cs index 28e6a89037..7f9f6ece2c 100644 --- a/osu.Game/Online/Chat/Message.cs +++ b/osu.Game/Online/Chat/Message.cs @@ -21,10 +21,10 @@ namespace osu.Game.Online.Chat public DateTime Timestamp; [JsonProperty(@"content")] - internal string Content; + public string Content; [JsonProperty(@"sender")] - internal User User; + public User User; [JsonConstructor] public Message()