feat: handle tells

This commit is contained in:
Anna
2022-01-29 00:43:51 -05:00
parent d844b000e5
commit 027a9946d7
4 changed files with 96 additions and 24 deletions
+50 -20
View File
@@ -4,6 +4,7 @@ using ChatTwo.GameFunctions.Types;
using ChatTwo.Util;
using Dalamud.Game.ClientState.Keys;
using Dalamud.Game.Command;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.Interface;
using Dalamud.Logging;
@@ -25,7 +26,7 @@ internal sealed class ChatLog : IUiComponent {
private int _inputBacklogIdx = -1;
private int _lastTab;
private InputChannel? _tempChannel;
private (string, string, ulong)? _tellTarget;
private TellTarget? _tellTarget;
private int _tellIdx;
private PayloadHandler PayloadHandler { get; }
@@ -52,7 +53,7 @@ internal sealed class ChatLog : IUiComponent {
this.Ui.Plugin.CommandManager.RemoveHandler("/clearlog2");
}
private void Activated(string? input, ChannelSwitchInfo info) {
private void Activated(string? input, ChannelSwitchInfo info, TellReason? reason, TellTarget? target) {
this.Activate = true;
if (input != null && !this.Chat.Contains(input)) {
this.Chat += input;
@@ -67,18 +68,24 @@ internal sealed class ChatLog : IUiComponent {
this._tempChannel = info.Channel.Value;
}
if (info.Channel is InputChannel.Tell && info.Rotate != RotateMode.None) {
this._tellIdx = prevTemp != InputChannel.Tell
? 0
: info.Rotate == RotateMode.Reverse
? -1
: 1;
if (info.Channel is InputChannel.Tell) {
if (info.Rotate != RotateMode.None) {
this._tellIdx = prevTemp != InputChannel.Tell
? 0
: info.Rotate == RotateMode.Reverse
? -1
: 1;
var tellInfo = this.Ui.Plugin.Functions.Chat.GetTellHistoryInfo(this._tellIdx);
if (tellInfo != null) {
var world = this.Ui.Plugin.DataManager.GetExcelSheet<World>()?.GetRow(tellInfo.World);
if (world != null) {
this._tellTarget = (tellInfo.Name, world.Name, tellInfo.ContentId);
var tellInfo = this.Ui.Plugin.Functions.Chat.GetTellHistoryInfo(this._tellIdx);
if (tellInfo != null && reason != null) {
this._tellTarget = new TellTarget(tellInfo.Name, (ushort) tellInfo.World, tellInfo.ContentId, reason.Value);
}
} else {
this._tellIdx = 0;
this._tellTarget = null;
if (target != null) {
this._tellTarget = target;
}
}
} else {
@@ -211,7 +218,8 @@ internal sealed class ChatLog : IUiComponent {
}
try {
this.Activated(null, info);
TellReason? reason = info.Channel == InputChannel.Tell ? TellReason.Reply : null;
this.Activated(null, info, reason, null);
} catch (Exception ex) {
PluginLog.LogError(ex, "Error in chat Activated event");
}
@@ -261,7 +269,17 @@ internal sealed class ChatLog : IUiComponent {
try {
if (this._tempChannel != null) {
if (this._tellTarget != null) {
ImGui.TextUnformatted($"Tell {this._tellTarget.Value.Item1}@{this._tellTarget.Value.Item2}");
var world = this.Ui.Plugin.DataManager.GetExcelSheet<World>()
?.GetRow(this._tellTarget.World)
?.Name
?.RawString ?? "???";
this.DrawChunks(new List<Chunk> {
new TextChunk(null, null, "Tell "),
new TextChunk(null, null, this._tellTarget.Name),
new IconChunk(null, null, BitmapFontIcon.CrossWorld),
new TextChunk(null, null, world),
});
} else {
ImGui.TextUnformatted(this._tempChannel.Value.ToChatType().Name());
}
@@ -333,12 +351,23 @@ internal sealed class ChatLog : IUiComponent {
this.AddBacklog(trimmed);
this._inputBacklogIdx = -1;
if (this._tempChannel != null) {
if (this._tellTarget != null) {
trimmed = $"{this._tempChannel.Value.Prefix()} {this._tellTarget.Value.Item1}@{this._tellTarget.Value.Item2} {trimmed}";
} else {
trimmed = $"{this._tempChannel.Value.Prefix()} {trimmed}";
if (this._tellTarget != null) {
var target = this._tellTarget;
var reason = target.Reason;
var world = this.Ui.Plugin.DataManager.GetExcelSheet<World>()?.GetRow(target.World);
if (world is { IsPublic: true }) {
if (reason == TellReason.Reply && this.Ui.Plugin.Common.Functions.FriendList.List.Any(friend => friend.ContentId == target.ContentId)) {
reason = TellReason.Friend;
}
this.Ui.Plugin.Functions.Chat.SendTell(reason, target.ContentId, target.Name, (ushort) world.RowId, trimmed);
}
goto Skip;
}
if (this._tempChannel != null) {
trimmed = $"{this._tempChannel.Value.Prefix()} {trimmed}";
} else if (activeTab is { Channel: { } channel } && !trimmed.StartsWith('/')) {
trimmed = $"{channel.Prefix()} {trimmed}";
}
@@ -346,6 +375,7 @@ internal sealed class ChatLog : IUiComponent {
this.Ui.Plugin.Common.Functions.Chat.SendMessage(trimmed);
}
Skip:
this.Chat = string.Empty;
}