mirror of
https://github.com/osukey/osukey.git
synced 2025-08-05 07:33:55 +09:00
Merge branch 'master' into general-fixes
This commit is contained in:
@ -3,12 +3,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
|
||||
namespace osu.Game.Online.Chat
|
||||
{
|
||||
@ -30,16 +25,16 @@ namespace osu.Game.Online.Chat
|
||||
|
||||
//internal bool Joined;
|
||||
|
||||
public const int MAX_HISTORY = 100;
|
||||
public const int MAX_HISTORY = 300;
|
||||
|
||||
[JsonConstructor]
|
||||
public Channel()
|
||||
{
|
||||
}
|
||||
|
||||
public event Action<Message[]> NewMessagesArrived;
|
||||
public event Action<IEnumerable<Message>> NewMessagesArrived;
|
||||
|
||||
public void AddNewMessages(params Message[] messages)
|
||||
public void AddNewMessages(IEnumerable<Message> messages)
|
||||
{
|
||||
Messages.AddRange(messages);
|
||||
purgeOldMessages();
|
||||
|
@ -1,10 +1,12 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Primitives;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
@ -15,6 +17,50 @@ namespace osu.Game.Online.Chat.Drawables
|
||||
{
|
||||
public readonly Message Message;
|
||||
|
||||
private static readonly Color4[] username_colours = {
|
||||
OsuColour.FromHex("588c7e"),
|
||||
OsuColour.FromHex("b2a367"),
|
||||
OsuColour.FromHex("c98f65"),
|
||||
OsuColour.FromHex("bc5151"),
|
||||
OsuColour.FromHex("5c8bd6"),
|
||||
OsuColour.FromHex("7f6ab7"),
|
||||
OsuColour.FromHex("a368ad"),
|
||||
OsuColour.FromHex("aa6880"),
|
||||
|
||||
OsuColour.FromHex("6fad9b"),
|
||||
OsuColour.FromHex("f2e394"),
|
||||
OsuColour.FromHex("f2ae72"),
|
||||
OsuColour.FromHex("f98f8a"),
|
||||
OsuColour.FromHex("7daef4"),
|
||||
OsuColour.FromHex("a691f2"),
|
||||
OsuColour.FromHex("c894d3"),
|
||||
OsuColour.FromHex("d895b0"),
|
||||
|
||||
OsuColour.FromHex("53c4a1"),
|
||||
OsuColour.FromHex("eace5c"),
|
||||
OsuColour.FromHex("ea8c47"),
|
||||
OsuColour.FromHex("fc4f4f"),
|
||||
OsuColour.FromHex("3d94ea"),
|
||||
OsuColour.FromHex("7760ea"),
|
||||
OsuColour.FromHex("af52c6"),
|
||||
OsuColour.FromHex("e25696"),
|
||||
|
||||
OsuColour.FromHex("677c66"),
|
||||
OsuColour.FromHex("9b8732"),
|
||||
OsuColour.FromHex("8c5129"),
|
||||
OsuColour.FromHex("8c3030"),
|
||||
OsuColour.FromHex("1f5d91"),
|
||||
OsuColour.FromHex("4335a5"),
|
||||
OsuColour.FromHex("812a96"),
|
||||
OsuColour.FromHex("992861"),
|
||||
};
|
||||
|
||||
private Color4 getUsernameColour(Message message)
|
||||
{
|
||||
//todo: use User instead of Message when user_id is correctly populated.
|
||||
return username_colours[message.UserId % username_colours.Length];
|
||||
}
|
||||
|
||||
const float padding = 200;
|
||||
const float text_size = 20;
|
||||
|
||||
@ -25,6 +71,8 @@ namespace osu.Game.Online.Chat.Drawables
|
||||
RelativeSizeAxes = Axes.X;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
|
||||
Padding = new MarginPadding { Left = 15, Right = 15 };
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Container
|
||||
@ -34,13 +82,19 @@ namespace osu.Game.Online.Chat.Drawables
|
||||
{
|
||||
new OsuSpriteText
|
||||
{
|
||||
Text = Message.Timestamp.LocalDateTime.ToLongTimeString(),
|
||||
TextSize = text_size,
|
||||
Colour = Color4.Gray
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Font = @"Exo2.0-SemiBold",
|
||||
Text = $@"{Message.Timestamp.LocalDateTime:hh:mm:ss}",
|
||||
FixedWidth = true,
|
||||
TextSize = text_size * 0.75f,
|
||||
Alpha = 0.4f,
|
||||
},
|
||||
new OsuSpriteText
|
||||
{
|
||||
Text = Message.User.Name,
|
||||
Font = @"Exo2.0-BoldItalic",
|
||||
Text = $@"{Message.User.Name}:",
|
||||
Colour = getUsernameColour(Message),
|
||||
TextSize = text_size,
|
||||
Origin = Anchor.TopRight,
|
||||
Anchor = Anchor.TopRight,
|
||||
@ -51,7 +105,7 @@ namespace osu.Game.Online.Chat.Drawables
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Padding = new MarginPadding { Left = padding + 10 },
|
||||
Padding = new MarginPadding { Left = padding + 15 },
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new OsuSpriteText
|
||||
|
@ -4,25 +4,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.Primitives;
|
||||
using osu.Framework.MathUtils;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Online.Chat.Drawables
|
||||
{
|
||||
public class ChannelDisplay : Container
|
||||
public class DrawableChannel : Container
|
||||
{
|
||||
private readonly Channel channel;
|
||||
private FlowContainer flow;
|
||||
private ScrollContainer scroll;
|
||||
|
||||
public ChannelDisplay(Channel channel)
|
||||
public DrawableChannel(Channel channel)
|
||||
{
|
||||
this.channel = channel;
|
||||
newMessages(channel.Messages);
|
||||
channel.NewMessagesArrived += newMessages;
|
||||
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
|
||||
@ -36,7 +36,7 @@ namespace osu.Game.Online.Chat.Drawables
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre
|
||||
},
|
||||
new ScrollContainer
|
||||
scroll = new ScrollContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
@ -46,37 +46,54 @@ namespace osu.Game.Online.Chat.Drawables
|
||||
Direction = FlowDirections.Vertical,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Spacing = new Vector2(1, 1)
|
||||
Padding = new MarginPadding { Left = 20, Right = 20 }
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
channel.NewMessagesArrived += newMessagesArrived;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
newMessagesArrived(channel.Messages);
|
||||
scrollToEnd();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
channel.NewMessagesArrived -= newMessages;
|
||||
channel.NewMessagesArrived -= newMessagesArrived;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
newMessages(channel.Messages);
|
||||
}
|
||||
|
||||
private void newMessages(IEnumerable<Message> newMessages)
|
||||
private void newMessagesArrived(IEnumerable<Message> newMessages)
|
||||
{
|
||||
if (!IsLoaded) return;
|
||||
|
||||
var displayMessages = newMessages.Skip(Math.Max(0, newMessages.Count() - Channel.MAX_HISTORY));
|
||||
|
||||
if (scroll.IsScrolledToEnd(10) || !flow.Children.Any())
|
||||
scrollToEnd();
|
||||
|
||||
//up to last Channel.MAX_HISTORY messages
|
||||
foreach (Message m in displayMessages)
|
||||
flow.Add(new ChatLine(m));
|
||||
{
|
||||
var d = new ChatLine(m);
|
||||
flow.Add(d);
|
||||
}
|
||||
|
||||
while (flow.Children.Count() > Channel.MAX_HISTORY)
|
||||
flow.Remove(flow.Children.First());
|
||||
while (flow.Children.Count(c => c.LifetimeEnd == double.MaxValue) > Channel.MAX_HISTORY)
|
||||
{
|
||||
var d = flow.Children.First(c => c.LifetimeEnd == double.MaxValue);
|
||||
if (!scroll.IsScrolledToEnd(10))
|
||||
scroll.OffsetScrollPosition(-d.DrawHeight);
|
||||
d.Expire();
|
||||
}
|
||||
}
|
||||
|
||||
private void scrollToEnd() => Scheduler.AddDelayed(() => scroll.ScrollToEnd(), 50);
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ namespace osu.Game.Online.Chat
|
||||
[JsonProperty(@"message_id")]
|
||||
public long Id;
|
||||
|
||||
//todo: this should be inside sender.
|
||||
[JsonProperty(@"user_id")]
|
||||
public int UserId;
|
||||
|
||||
|
Reference in New Issue
Block a user