Merge branch 'master' into limit-game-access

Conflicts:
	osu.Desktop.VisualTests/Tests/TestCaseChatDisplay.cs
	osu.Game/GameModes/Menu/ButtonSystem.cs
	osu.Game/Online/Chat/Display/ChatLine.cs
	osu.Game/OsuGame.cs
	osu.Game/Overlays/ToolbarButton.cs
This commit is contained in:
Dean Herbert
2016-10-12 20:05:46 +09:00
20 changed files with 908 additions and 558 deletions

View File

@ -1,8 +1,14 @@
//Copyright (c) 2007-2016 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 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
{
@ -24,9 +30,28 @@ namespace osu.Game.Online.Chat
//internal bool Joined;
public const int MAX_HISTORY = 100;
[JsonConstructor]
public Channel()
{
}
public event Action<Message[]> NewMessagesArrived;
public void AddNewMessages(params Message[] messages)
{
Messages.AddRange(messages);
purgeOldMessages();
NewMessagesArrived?.Invoke(messages);
}
private void purgeOldMessages()
{
int messageCount = Messages.Count;
if (messageCount > MAX_HISTORY)
Messages.RemoveRange(0, messageCount - MAX_HISTORY);
}
}
}

View File

@ -0,0 +1,81 @@
//Copyright (c) 2007-2016 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 System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Transformations;
using osu.Game.Online.Chat.Display.osu.Online.Social;
using OpenTK;
using osu.Framework;
namespace osu.Game.Online.Chat.Display
{
public class ChannelDisplay : Container
{
private readonly Channel channel;
private FlowContainer flow;
public ChannelDisplay(Channel channel)
{
this.channel = channel;
newMessages(channel.Messages);
channel.NewMessagesArrived += newMessages;
RelativeSizeAxes = Axes.Both;
Children = new Drawable[]
{
new SpriteText
{
Text = channel.Name,
TextSize = 50,
Alpha = 0.3f,
Anchor = Anchor.Centre,
Origin = Anchor.Centre
},
new ScrollContainer
{
Children = new Drawable[]
{
flow = new FlowContainer
{
Direction = FlowDirection.VerticalOnly,
RelativeSizeAxes = Axes.X,
Spacing = new Vector2(1, 1)
}
}
}
};
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
channel.NewMessagesArrived -= newMessages;
}
public override void Load(BaseGame game)
{
base.Load(game);
newMessages(channel.Messages);
}
private void newMessages(IEnumerable<Message> newMessages)
{
if (!IsLoaded) return;
var displayMessages = newMessages.Skip(Math.Max(0, newMessages.Count() - Channel.MAX_HISTORY));
//up to last Channel.MAX_HISTORY messages
foreach (Message m in displayMessages)
flow.Add(new ChatLine(m));
while (flow.Children.Count() > Channel.MAX_HISTORY)
flow.Remove(flow.Children.First());
}
}
}

View File

@ -1,6 +1,8 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Drawables;
@ -8,6 +10,7 @@ using osu.Framework.Graphics.Sprites;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework;
using osu.Framework.Graphics.Primitives;
namespace osu.Game.Online.Chat.Display
{
@ -15,48 +18,59 @@ namespace osu.Game.Online.Chat.Display
{
public class ChatLine : AutoSizeContainer
{
private readonly Message msg;
public readonly Message Message;
public ChatLine(Message msg)
public ChatLine(Message message)
{
this.msg = msg;
this.Message = message;
}
const float padding = 200;
const float text_size = 20;
public override void Load(BaseGame game)
{
base.Load(game);
RelativeSizeAxes = Axes.X;
Add(new Box
Children = new Drawable[]
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Aqua,
Alpha = 0.2f
});
Add(new SpriteText
{
Text = msg.Timestamp.ToLocalTime().ToLongTimeString(),
Colour = new Color4(128, 128, 128, 255)
});
Add(new SpriteText
{
Text = msg.User.Name,
Origin = Anchor.TopRight,
RelativePositionAxes = Axes.X,
Position = new Vector2(0.14f,0),
});
Add(new SpriteText
{
Text = msg.Content,
RelativePositionAxes = Axes.X,
Position = new Vector2(0.15f, 0),
RelativeSizeAxes = Axes.X,
Size = new Vector2(0.85f, 1),
});
new Container
{
Size = new Vector2(padding, text_size),
Children = new Drawable[]
{
new SpriteText
{
Text = Message.Timestamp.ToLocalTime().ToLongTimeString(),
TextSize = text_size,
Colour = new Color4(128, 128, 128, 255)
},
new SpriteText
{
Text = Message.User.Name,
TextSize = text_size,
Origin = Anchor.TopRight,
Anchor = Anchor.TopRight,
}
}
},
new Container
{
RelativeSizeAxes = Axes.X,
Padding = new MarginPadding { Left = padding + 10 },
Children = new Drawable[]
{
new SpriteText
{
Text = Message.Content,
TextSize = text_size,
RelativeSizeAxes = Axes.X,
}
}
}
};
}
}
}

View File

@ -12,10 +12,10 @@ namespace osu.Game.Online.Chat
public long Id;
[JsonProperty(@"user_id")]
public string UserId;
public int UserId;
[JsonProperty(@"channel_id")]
public string ChannelId;
public int ChannelId;
[JsonProperty(@"timestamp")]
public DateTime Timestamp;