feat: partially handle some payloads

This commit is contained in:
Anna
2021-12-29 21:53:44 -05:00
parent 1d9581abca
commit 0b9d617021
14 changed files with 341 additions and 50 deletions
+33 -27
View File
@@ -9,15 +9,18 @@ namespace ChatTwo.Ui;
internal sealed class ChatLog : IUiComponent {
private PluginUi Ui { get; }
private bool _activate;
private string _chat = string.Empty;
internal bool Activate;
internal string Chat = string.Empty;
private readonly TextureWrap? _fontIcon;
private readonly List<string> _inputBacklog = new();
private int _inputBacklogIdx = -1;
private int _lastTab;
private PayloadHandler PayloadHandler { get; }
internal ChatLog(PluginUi ui) {
this.Ui = ui;
this.PayloadHandler = new PayloadHandler(this.Ui, this);
this._fontIcon = this.Ui.Plugin.DataManager.GetImGuiTexture("common/font/fonticon_ps5.tex");
@@ -30,9 +33,9 @@ internal sealed class ChatLog : IUiComponent {
}
private void ChatActivated(string? input) {
this._activate = true;
if (input != null && !this._chat.Contains(input)) {
this._chat += input;
this.Activate = true;
if (input != null && !this.Chat.Contains(input)) {
this.Chat += input;
}
}
@@ -80,7 +83,7 @@ internal sealed class ChatLog : IUiComponent {
// int numMessages;
try {
tab.MessagesMutex.WaitOne();
for (var i = 0; i < tab.Messages.Count; i++) {
// numDrawn += 1;
var message = tab.Messages[i];
@@ -94,11 +97,11 @@ internal sealed class ChatLog : IUiComponent {
}
if (message.Sender.Count > 0) {
this.DrawChunks(message.Sender);
this.DrawChunks(message.Sender, this.PayloadHandler);
ImGui.SameLine();
}
this.DrawChunks(message.Content);
this.DrawChunks(message.Content, this.PayloadHandler);
// drawnHeight += ImGui.GetCursorPosY() - lastPos;
// lastPos = ImGui.GetCursorPosY();
@@ -115,7 +118,7 @@ internal sealed class ChatLog : IUiComponent {
}
// PluginLog.Log($"numDrawn: {numDrawn}");
if (switchedTab || ImGui.GetScrollY() >= ImGui.GetScrollMaxY()) {
// PluginLog.Log($"drawnHeight: {drawnHeight}");
// var itemPosY = clipper.StartPosY + drawnHeight;
@@ -125,6 +128,8 @@ internal sealed class ChatLog : IUiComponent {
}
}
this.PayloadHandler.Draw();
ImGui.EndChild();
ImGui.EndTabItem();
@@ -134,7 +139,7 @@ internal sealed class ChatLog : IUiComponent {
ImGui.EndTabBar();
}
if (this._activate) {
if (this.Activate) {
ImGui.SetKeyboardFocusHere();
}
@@ -148,23 +153,23 @@ internal sealed class ChatLog : IUiComponent {
if (inputColour != null) {
ImGui.PushStyleColor(ImGuiCol.Text, ColourUtil.RgbaToAbgr(inputColour.Value));
}
ImGui.SetNextItemWidth(-1);
const ImGuiInputTextFlags inputFlags = ImGuiInputTextFlags.EnterReturnsTrue
| ImGuiInputTextFlags.CallbackAlways
| ImGuiInputTextFlags.CallbackHistory;
if (ImGui.InputText("##chat2-input", ref this._chat, 500, inputFlags, this.Callback)) {
if (!string.IsNullOrWhiteSpace(this._chat)) {
var trimmed = this._chat.Trim();
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;
this.Ui.Plugin.Common.Functions.Chat.SendMessage(trimmed);
}
this._chat = string.Empty;
this.Chat = string.Empty;
}
if (inputColour != null) {
ImGui.PopStyleColor();
}
@@ -175,9 +180,9 @@ internal sealed class ChatLog : IUiComponent {
private unsafe int Callback(ImGuiInputTextCallbackData* data) {
var ptr = new ImGuiInputTextCallbackDataPtr(data);
if (this._activate) {
this._activate = false;
data->CursorPos = this._chat.Length;
if (this.Activate) {
this.Activate = false;
data->CursorPos = this.Chat.Length;
data->SelectionStart = data->SelectionEnd = data->CursorPos;
}
@@ -192,12 +197,12 @@ internal sealed class ChatLog : IUiComponent {
switch (this._inputBacklogIdx) {
case -1:
var offset = 0;
if (!string.IsNullOrWhiteSpace(this._chat)) {
this.AddBacklog(this._chat);
if (!string.IsNullOrWhiteSpace(this.Chat)) {
this.AddBacklog(this.Chat);
offset = 1;
}
this._inputBacklogIdx = this._inputBacklog.Count - 1 - offset;
break;
case > 0:
@@ -229,9 +234,9 @@ internal sealed class ChatLog : IUiComponent {
return 0;
}
private void DrawChunks(IReadOnlyList<Chunk> chunks) {
internal void DrawChunks(IReadOnlyList<Chunk> chunks, PayloadHandler? handler = null) {
for (var i = 0; i < chunks.Count; i++) {
this.DrawChunk(chunks[i]);
this.DrawChunk(chunks[i], handler);
if (i < chunks.Count - 1) {
ImGui.SameLine();
@@ -239,7 +244,7 @@ internal sealed class ChatLog : IUiComponent {
}
}
private void DrawChunk(Chunk chunk) {
private void DrawChunk(Chunk chunk, PayloadHandler? handler = null) {
if (chunk is IconChunk icon && this._fontIcon != null) {
var bounds = IconUtil.GetBounds((byte) icon.Icon);
if (bounds != null) {
@@ -251,6 +256,7 @@ internal sealed class ChatLog : IUiComponent {
var uv0 = new Vector2(bounds.Value.X, bounds.Value.Y - 2) / texSize;
var uv1 = new Vector2(bounds.Value.X + bounds.Value.Z, bounds.Value.Y - 2 + bounds.Value.W) / texSize;
ImGui.Image(this._fontIcon.ImGuiHandle, size, uv0, uv1);
ImGuiUtil.PostPayload(chunk.Link, handler);
}
return;
@@ -277,7 +283,7 @@ internal sealed class ChatLog : IUiComponent {
ImGui.PushFont(this.Ui.ItalicFont.Value);
}
ImGuiUtil.WrapText(text.Content);
ImGuiUtil.WrapText(text.Content, chunk.Link, handler);
if (text.Italic && this.Ui.ItalicFont.HasValue) {
ImGui.PopFont();
+4
View File
@@ -12,6 +12,7 @@ internal sealed class Settings : IUiComponent {
private bool _visible;
private bool _hideChat;
private bool _nativeItemTooltips;
private float _fontSize;
private Dictionary<ChatType, uint> _chatColours = new();
private List<Tab> _tabs = new();
@@ -34,6 +35,7 @@ internal sealed class Settings : IUiComponent {
private void Initialise() {
var config = this.Ui.Plugin.Config;
this._hideChat = config.HideChat;
this._nativeItemTooltips = config.NativeItemTooltips;
this._fontSize = config.FontSize;
this._chatColours = config.ChatColours.ToDictionary(entry => entry.Key, entry => entry.Value);
this._tabs = config.Tabs.Select(tab => tab.Clone()).ToList();
@@ -60,6 +62,7 @@ internal sealed class Settings : IUiComponent {
- ImGui.CalcTextSize("A").Y;
if (ImGui.BeginChild("##chat2-settings", new Vector2(-1, height))) {
ImGui.Checkbox("Hide chat", ref this._hideChat);
ImGui.Checkbox("Show native item tooltips", ref this._nativeItemTooltips);
ImGui.DragFloat("Font size", ref this._fontSize, .5f, 12f, 36f);
if (ImGui.TreeNodeEx("Chat colours")) {
@@ -163,6 +166,7 @@ internal sealed class Settings : IUiComponent {
var fontSizeChanged = Math.Abs(this._fontSize - this.Ui.Plugin.Config.FontSize) > float.Epsilon;
config.HideChat = this._hideChat;
config.NativeItemTooltips = this._nativeItemTooltips;
config.FontSize = this._fontSize;
config.ChatColours = this._chatColours;
config.Tabs = this._tabs;
+1 -1
View File
@@ -1,4 +1,4 @@
namespace ChatTwo.Ui;
namespace ChatTwo.Ui;
internal interface IUiComponent : IDisposable {
void Draw();