Add local chat echo support

This commit is contained in:
Dean Herbert
2017-08-21 17:43:26 +09:00
parent 5068bbfd87
commit 877c69d5fe
7 changed files with 223 additions and 99 deletions

View File

@ -6,23 +6,23 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input;
using osu.Framework.Threading;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.Chat;
using osu.Game.Graphics.UserInterface;
using osu.Framework.Graphics.UserInterface;
using OpenTK.Graphics;
using osu.Framework.Input;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Overlays.Chat;
using osu.Game.Graphics.Containers;
namespace osu.Game.Overlays
{
@ -37,7 +37,7 @@ namespace osu.Game.Overlays
private readonly LoadingAnimation loading;
private readonly FocusedTextBox inputTextBox;
private readonly FocusedTextBox textbox;
private APIAccess api;
@ -130,7 +130,7 @@ namespace osu.Game.Overlays
},
Children = new Drawable[]
{
inputTextBox = new FocusedTextBox
textbox = new FocusedTextBox
{
RelativeSizeAxes = Axes.Both,
Height = 1,
@ -175,7 +175,7 @@ namespace osu.Game.Overlays
if (state == Visibility.Visible)
{
inputTextBox.HoldFocus = false;
textbox.HoldFocus = false;
if (1f - chatHeight.Value < channel_selection_min_height)
{
chatContainer.ResizeHeightTo(1f - channel_selection_min_height, 800, Easing.OutQuint);
@ -186,7 +186,7 @@ namespace osu.Game.Overlays
}
else
{
inputTextBox.HoldFocus = true;
textbox.HoldFocus = true;
}
};
}
@ -242,8 +242,8 @@ namespace osu.Game.Overlays
protected override void OnFocus(InputState state)
{
//this is necessary as inputTextBox is masked away and therefore can't get focus :(
GetContainingInputManager().ChangeFocus(inputTextBox);
//this is necessary as textbox is masked away and therefore can't get focus :(
GetContainingInputManager().ChangeFocus(textbox);
base.OnFocus(state);
}
@ -252,7 +252,7 @@ namespace osu.Game.Overlays
this.MoveToY(0, transition_length, Easing.OutQuint);
this.FadeIn(transition_length, Easing.OutQuint);
inputTextBox.HoldFocus = true;
textbox.HoldFocus = true;
base.PopIn();
}
@ -261,7 +261,7 @@ namespace osu.Game.Overlays
this.MoveToY(Height, transition_length, Easing.InSine);
this.FadeOut(transition_length, Easing.InSine);
inputTextBox.HoldFocus = false;
textbox.HoldFocus = false;
base.PopOut();
}
@ -336,7 +336,7 @@ namespace osu.Game.Overlays
currentChannel = value;
inputTextBox.Current.Disabled = currentChannel.ReadOnly;
textbox.Current.Disabled = currentChannel.ReadOnly;
channelTabs.Current.Value = value;
var loaded = loadedChannels.Find(d => d.Channel == value);
@ -437,51 +437,42 @@ namespace osu.Game.Overlays
{
var postText = textbox.Text;
textbox.Text = string.Empty;
if (string.IsNullOrEmpty(postText))
return;
var target = currentChannel;
if (target == null) return;
if (!api.IsLoggedIn)
{
currentChannel?.AddNewMessages(new ErrorMessage("Please login to participate in chat!"));
textbox.Text = string.Empty;
target.AddNewMessages(new ErrorMessage("Please login to participate in chat!"));
return;
}
if (currentChannel == null) return;
if (postText[0] == '/')
{
// TODO: handle commands
currentChannel.AddNewMessages(new ErrorMessage("Chat commands are not supported yet!"));
textbox.Text = string.Empty;
target.AddNewMessages(new ErrorMessage("Chat commands are not supported yet!"));
return;
}
var message = new Message
var message = new LocalEchoMessage
{
Sender = api.LocalUser.Value,
Timestamp = DateTimeOffset.Now,
TargetType = TargetType.Channel, //TODO: read this from currentChannel
TargetId = currentChannel.Id,
TargetType = TargetType.Channel, //TODO: read this from channel
TargetId = target.Id,
Content = postText
};
textbox.ReadOnly = true;
var req = new PostMessageRequest(message);
req.Failure += e =>
{
textbox.FlashColour(Color4.Red, 1000);
textbox.ReadOnly = false;
};
req.Success += m =>
{
currentChannel.AddNewMessages(m);
textbox.ReadOnly = false;
textbox.Text = string.Empty;
};
target.AddLocalEcho(message);
req.Failure += e => target.ReplaceMessage(message, null);
req.Success += m => target.ReplaceMessage(message, m);
api.Queue(req);
}