1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 06:42:56 +08:00

Initial implementation of chat commands

This commit is contained in:
MrTheMake 2017-09-22 01:47:24 +02:00
parent 278e51eebc
commit 31e26364a6
4 changed files with 39 additions and 7 deletions

View File

@ -23,6 +23,7 @@ namespace osu.Game.Online.API.Requests
req.Method = HttpMethod.POST;
req.AddParameter(@"target_type", message.TargetType.GetDescription());
req.AddParameter(@"target_id", message.TargetId.ToString());
req.AddParameter(@"is_action", message.IsAction.ToString().ToLower());
req.AddParameter(@"message", message.Content);
return req;

View File

@ -23,6 +23,9 @@ namespace osu.Game.Online.Chat
[JsonProperty(@"target_id")]
public int TargetId;
[JsonProperty(@"is_action")]
public bool IsAction;
[JsonProperty(@"timestamp")]
public DateTimeOffset Timestamp;

View File

@ -62,6 +62,7 @@ namespace osu.Game.Overlays.Chat
public const float LEFT_PADDING = message_padding + padding * 2;
private const float padding = 15;
private const float padding_action = 5;
private const float message_padding = 200;
private const float text_size = 20;
@ -183,7 +184,7 @@ namespace osu.Game.Overlays.Chat
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding { Left = message_padding + padding },
Padding = new MarginPadding { Left = message_padding + (message.IsAction ? padding_action : padding) },
Children = new Drawable[]
{
contentFlow = new OsuTextFlowContainer(t => { t.TextSize = text_size; })
@ -194,6 +195,8 @@ namespace osu.Game.Overlays.Chat
}
}
};
if (message.IsAction)
contentFlow.Colour = senderHasBackground ? OsuColour.FromHex(message.Sender.Colour) : username_colours[message.Sender.Id % username_colours.Length];
updateMessageContent();
FinishTransforms(true);
@ -205,7 +208,7 @@ namespace osu.Game.Overlays.Chat
timestamp.FadeTo(message is LocalEchoMessage ? 0 : 1, 500, Easing.OutQuint);
timestamp.Text = $@"{message.Timestamp.LocalDateTime:HH:mm:ss}";
username.Text = $@"{message.Sender.Username}" + (senderHasBackground ? "" : ":");
username.Text = (message.IsAction ? "*" : "") + $@"{message.Sender.Username}" + (senderHasBackground || message.IsAction ? "" : ":");
contentFlow.Text = message.Content;
}

View File

@ -465,7 +465,7 @@ namespace osu.Game.Overlays
textbox.Text = string.Empty;
if (string.IsNullOrEmpty(postText))
if (string.IsNullOrWhiteSpace(postText))
return;
var target = currentChannel;
@ -478,19 +478,44 @@ namespace osu.Game.Overlays
return;
}
bool isAction = false;
if (postText[0] == '/')
{
// TODO: handle commands
target.AddNewMessages(new ErrorMessage("Chat commands are not supported yet!"));
postText = postText.Substring(1);
string commandKeyword = postText.Split(' ')[0];
switch (commandKeyword)
{
case "me":
if (!postText.StartsWith("me ") || string.IsNullOrWhiteSpace(postText.Substring(3)))
{
currentChannel.AddNewMessages(new ErrorMessage("Usage: /me [action]"));
return;
}
isAction = true;
postText = postText.Substring(3);
break;
case "help":
currentChannel.AddNewMessages(new ErrorMessage("Supported commands: /help, /me [action]"));
return;
default:
currentChannel.AddNewMessages(new ErrorMessage($@"""/{commandKeyword}"" is not supported! For a list of supported commands see /help"));
return;
}
}
var message = new LocalEchoMessage
{
Sender = api.LocalUser.Value,
Timestamp = DateTimeOffset.Now,
TargetType = TargetType.Channel, //TODO: read this from channel
TargetId = target.Id,
IsAction = isAction,
Content = postText
};