fix: have input behave more like vanilla

This commit is contained in:
Anna 2022-06-30 17:56:11 -04:00
parent d9fbcc23c5
commit 569a2ea71e
1 changed files with 56 additions and 42 deletions

View File

@ -536,54 +536,24 @@ internal sealed class ChatLog : IUiComponent {
ImGui.PushStyleColor(ImGuiCol.Text, ColourUtil.RgbaToAbgr(inputColour.Value));
}
var chatCopy = this.Chat;
ImGui.SetNextItemWidth(inputWidth);
const ImGuiInputTextFlags inputFlags = ImGuiInputTextFlags.EnterReturnsTrue
| ImGuiInputTextFlags.CallbackAlways
const ImGuiInputTextFlags inputFlags = ImGuiInputTextFlags.CallbackAlways
| ImGuiInputTextFlags.CallbackCharFilter
| ImGuiInputTextFlags.CallbackCompletion
| ImGuiInputTextFlags.CallbackHistory;
if (ImGui.InputText("##chat2-input", ref this.Chat, 500, inputFlags, this.Callback)) {
if (!string.IsNullOrWhiteSpace(this.Chat)) {
var trimmed = this.Chat.Trim();
this.AddBacklog(trimmed);
this._inputBacklogIdx = -1;
ImGui.InputText("##chat2-input", ref this.Chat, 500, inputFlags, this.Callback);
if (!trimmed.StartsWith('/')) {
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);
}
if (this._tempChannel is InputChannel.Tell) {
this._tellTarget = null;
}
goto Skip;
}
if (this._tempChannel != null) {
trimmed = $"{this._tempChannel.Value.Prefix()} {trimmed}";
} else if (activeTab is { Channel: { } channel }) {
trimmed = $"{channel.Prefix()} {trimmed}";
}
}
var bytes = Encoding.UTF8.GetBytes(trimmed);
AutoTranslate.ReplaceWithPayload(this.Ui.Plugin.DataManager, ref bytes);
this.Ui.Plugin.Common.Functions.Chat.SendMessageUnsafe(bytes);
if (ImGui.IsItemDeactivated()) {
if (ImGui.IsKeyDown(ImGui.GetKeyIndex(ImGuiKey.Escape))) {
this.Chat = chatCopy;
}
var enter = ImGui.IsKeyDown(ImGui.GetKeyIndex(ImGuiKey.Enter))
|| ImGui.IsKeyDown(ImGui.GetKeyIndex(ImGuiKey.KeyPadEnter));
if (enter) {
this.SendChatBox(activeTab);
}
Skip:
this.Chat = string.Empty;
}
if (ImGui.IsItemActive()) {
@ -635,6 +605,50 @@ internal sealed class ChatLog : IUiComponent {
return true;
}
private void SendChatBox(Tab? activeTab) {
if (!string.IsNullOrWhiteSpace(this.Chat)) {
var trimmed = this.Chat.Trim();
this.AddBacklog(trimmed);
this._inputBacklogIdx = -1;
if (!trimmed.StartsWith('/')) {
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);
}
if (this._tempChannel is InputChannel.Tell) {
this._tellTarget = null;
}
goto Skip;
}
if (this._tempChannel != null) {
trimmed = $"{this._tempChannel.Value.Prefix()} {trimmed}";
} else if (activeTab is { Channel: { } channel }) {
trimmed = $"{channel.Prefix()} {trimmed}";
}
}
var bytes = Encoding.UTF8.GetBytes(trimmed);
AutoTranslate.ReplaceWithPayload(this.Ui.Plugin.DataManager, ref bytes);
this.Ui.Plugin.Common.Functions.Chat.SendMessageUnsafe(bytes);
}
Skip:
this.Chat = string.Empty;
}
internal void UserHide() {
this._hideState = HideState.User;
}