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
+56 -42
View File
@@ -536,54 +536,24 @@ internal sealed class ChatLog : IUiComponent {
ImGui.PushStyleColor(ImGuiCol.Text, ColourUtil.RgbaToAbgr(inputColour.Value)); ImGui.PushStyleColor(ImGuiCol.Text, ColourUtil.RgbaToAbgr(inputColour.Value));
} }
var chatCopy = this.Chat;
ImGui.SetNextItemWidth(inputWidth); ImGui.SetNextItemWidth(inputWidth);
const ImGuiInputTextFlags inputFlags = ImGuiInputTextFlags.EnterReturnsTrue const ImGuiInputTextFlags inputFlags = ImGuiInputTextFlags.CallbackAlways
| ImGuiInputTextFlags.CallbackAlways
| ImGuiInputTextFlags.CallbackCharFilter | ImGuiInputTextFlags.CallbackCharFilter
| ImGuiInputTextFlags.CallbackCompletion | ImGuiInputTextFlags.CallbackCompletion
| ImGuiInputTextFlags.CallbackHistory; | ImGuiInputTextFlags.CallbackHistory;
if (ImGui.InputText("##chat2-input", ref this.Chat, 500, inputFlags, this.Callback)) { 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;
if (!trimmed.StartsWith('/')) { if (ImGui.IsItemDeactivated()) {
if (this._tellTarget != null) { if (ImGui.IsKeyDown(ImGui.GetKeyIndex(ImGuiKey.Escape))) {
var target = this._tellTarget; this.Chat = chatCopy;
var reason = target.Reason; }
var world = this.Ui.Plugin.DataManager.GetExcelSheet<World>()?.GetRow(target.World);
if (world is { IsPublic: true }) { var enter = ImGui.IsKeyDown(ImGui.GetKeyIndex(ImGuiKey.Enter))
if (reason == TellReason.Reply && this.Ui.Plugin.Common.Functions.FriendList.List.Any(friend => friend.ContentId == target.ContentId)) { || ImGui.IsKeyDown(ImGui.GetKeyIndex(ImGuiKey.KeyPadEnter));
reason = TellReason.Friend; if (enter) {
} this.SendChatBox(activeTab);
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;
} }
if (ImGui.IsItemActive()) { if (ImGui.IsItemActive()) {
@@ -635,6 +605,50 @@ internal sealed class ChatLog : IUiComponent {
return true; 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() { internal void UserHide() {
this._hideState = HideState.User; this._hideState = HideState.User;
} }