Compare commits
6 Commits
da631c1100
...
8bd6cf0b0c
Author | SHA1 | Date | |
---|---|---|---|
8bd6cf0b0c | |||
a42f05ee55 | |||
59b660202c | |||
cb5c08e7d8 | |||
31df22231f | |||
83236ef2d7 |
@ -1,4 +1,7 @@
|
||||
namespace ChatTwo.Code;
|
||||
using Dalamud.Data;
|
||||
using Lumina.Excel.GeneratedSheets;
|
||||
|
||||
namespace ChatTwo.Code;
|
||||
|
||||
internal static class InputChannelExt {
|
||||
internal static ChatType ToChatType(this InputChannel input) => input switch {
|
||||
@ -78,4 +81,49 @@ internal static class InputChannelExt {
|
||||
InputChannel.Linkshell8 => "/linkshell8",
|
||||
_ => "",
|
||||
};
|
||||
|
||||
public static IEnumerable<TextCommand>? TextCommands(this InputChannel channel, DataManager data) {
|
||||
var ids = channel switch {
|
||||
InputChannel.Tell => new uint[] { 104, 118 },
|
||||
InputChannel.Say => new uint[] { 102 },
|
||||
InputChannel.Party => new uint[] { 105 },
|
||||
InputChannel.Alliance => new uint[] { 119 },
|
||||
InputChannel.Yell => new uint[] { 117 },
|
||||
InputChannel.Shout => new uint[] { 103 },
|
||||
InputChannel.FreeCompany => new uint[] { 115 },
|
||||
InputChannel.PvpTeam => new uint[] { 91 },
|
||||
InputChannel.NoviceNetwork => new uint[] { 224 },
|
||||
InputChannel.CrossLinkshell1 => new uint[] { 13 },
|
||||
InputChannel.CrossLinkshell2 => new uint[] { 14 },
|
||||
InputChannel.CrossLinkshell3 => new uint[] { 15 },
|
||||
InputChannel.CrossLinkshell4 => new uint[] { 16 },
|
||||
InputChannel.CrossLinkshell5 => new uint[] { 17 },
|
||||
InputChannel.CrossLinkshell6 => new uint[] { 18 },
|
||||
InputChannel.CrossLinkshell7 => new uint[] { 19 },
|
||||
InputChannel.CrossLinkshell8 => new uint[] { 20 },
|
||||
InputChannel.Linkshell1 => new uint[] { 107 },
|
||||
InputChannel.Linkshell2 => new uint[] { 108 },
|
||||
InputChannel.Linkshell3 => new uint[] { 109 },
|
||||
InputChannel.Linkshell4 => new uint[] { 110 },
|
||||
InputChannel.Linkshell5 => new uint[] { 111 },
|
||||
InputChannel.Linkshell6 => new uint[] { 112 },
|
||||
InputChannel.Linkshell7 => new uint[] { 113 },
|
||||
InputChannel.Linkshell8 => new uint[] { 114 },
|
||||
_ => Array.Empty<uint>(),
|
||||
};
|
||||
|
||||
if (ids.Length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var cmds = data.GetExcelSheet<TextCommand>();
|
||||
if (cmds == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ids
|
||||
.Select(id => cmds.GetRow(id))
|
||||
.Where(id => id != null)
|
||||
.Cast<TextCommand>();
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ internal class Configuration : IPluginConfiguration {
|
||||
public bool CanResize = true;
|
||||
public bool ShowTitleBar;
|
||||
public float FontSize = 17f;
|
||||
public float WindowAlpha = 1f;
|
||||
public Dictionary<ChatType, uint> ChatColours = new();
|
||||
public List<Tab> Tabs = new();
|
||||
|
||||
@ -29,6 +30,7 @@ internal class Configuration : IPluginConfiguration {
|
||||
this.CanResize = other.CanResize;
|
||||
this.ShowTitleBar = other.ShowTitleBar;
|
||||
this.FontSize = other.FontSize;
|
||||
this.WindowAlpha = other.WindowAlpha;
|
||||
this.ChatColours = other.ChatColours.ToDictionary(entry => entry.Key, entry => entry.Value);
|
||||
this.Tabs = other.Tabs.Select(t => t.Clone()).ToList();
|
||||
}
|
||||
|
@ -23,10 +23,14 @@ internal sealed class ChatLog : IUiComponent {
|
||||
private int _lastTab;
|
||||
|
||||
private PayloadHandler PayloadHandler { get; }
|
||||
private Dictionary<string, ChatType> TextCommandChannels { get; } = new();
|
||||
|
||||
internal ChatLog(PluginUi ui) {
|
||||
this.Ui = ui;
|
||||
this.PayloadHandler = new PayloadHandler(this.Ui, this);
|
||||
|
||||
this.SetUpTextCommandChannels();
|
||||
|
||||
this.Ui.Plugin.CommandManager.AddHandler("/clearlog2", new CommandInfo(this.ClearLog) {
|
||||
HelpMessage = "Clears the Chat 2 chat log",
|
||||
});
|
||||
@ -76,6 +80,34 @@ internal sealed class ChatLog : IUiComponent {
|
||||
}
|
||||
}
|
||||
|
||||
private void SetUpTextCommandChannels() {
|
||||
this.TextCommandChannels.Clear();
|
||||
|
||||
foreach (var input in Enum.GetValues<InputChannel>()) {
|
||||
var commands = input.TextCommands(this.Ui.Plugin.DataManager);
|
||||
if (commands == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var type = input.ToChatType();
|
||||
foreach (var command in commands) {
|
||||
this.AddTextCommandChannel(command, type);
|
||||
}
|
||||
}
|
||||
|
||||
var echo = this.Ui.Plugin.DataManager.GetExcelSheet<TextCommand>()?.GetRow(116);
|
||||
if (echo != null) {
|
||||
this.AddTextCommandChannel(echo, ChatType.Echo);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddTextCommandChannel(TextCommand command, ChatType type) {
|
||||
this.TextCommandChannels[command.Command] = type;
|
||||
this.TextCommandChannels[command.ShortCommand] = type;
|
||||
this.TextCommandChannels[command.Alias] = type;
|
||||
this.TextCommandChannels[command.ShortAlias] = type;
|
||||
}
|
||||
|
||||
private void AddBacklog(string message) {
|
||||
for (var i = 0; i < this._inputBacklog.Count; i++) {
|
||||
if (this._inputBacklog[i] != message) {
|
||||
@ -96,6 +128,8 @@ internal sealed class ChatLog : IUiComponent {
|
||||
- ImGui.GetStyle().ItemSpacing.Y * 4;
|
||||
}
|
||||
|
||||
private unsafe ImGuiViewport* _lastViewport;
|
||||
|
||||
public unsafe void Draw() {
|
||||
var flags = ImGuiWindowFlags.None;
|
||||
if (!this.Ui.Plugin.Config.CanMove) {
|
||||
@ -110,11 +144,18 @@ internal sealed class ChatLog : IUiComponent {
|
||||
flags |= ImGuiWindowFlags.NoTitleBar;
|
||||
}
|
||||
|
||||
if (this._lastViewport == ImGuiHelpers.MainViewport.NativePtr) {
|
||||
ImGui.SetNextWindowBgAlpha(this.Ui.Plugin.Config.WindowAlpha);
|
||||
}
|
||||
|
||||
if (!ImGui.Begin($"{this.Ui.Plugin.Name}##chat", flags)) {
|
||||
this._lastViewport = ImGui.GetWindowViewport().NativePtr;
|
||||
ImGui.End();
|
||||
return;
|
||||
}
|
||||
|
||||
this._lastViewport = ImGui.GetWindowViewport().NativePtr;
|
||||
|
||||
var currentTab = this.Ui.Plugin.Config.SidebarTabView
|
||||
? this.DrawTabSidebar()
|
||||
: this.DrawTabBar();
|
||||
@ -172,7 +213,14 @@ internal sealed class ChatLog : IUiComponent {
|
||||
var buttonWidth = afterIcon.X - beforeIcon.X;
|
||||
var inputWidth = ImGui.GetContentRegionAvail().X - buttonWidth;
|
||||
|
||||
var inputType = this.Ui.Plugin.Functions.Chat.Channel.channel.ToChatType();
|
||||
var inputType = activeTab?.Channel?.ToChatType() ?? this.Ui.Plugin.Functions.Chat.Channel.channel.ToChatType();
|
||||
if (this.Chat.Trim().StartsWith('/')) {
|
||||
var command = this.Chat.Split(' ')[0];
|
||||
if (this.TextCommandChannels.TryGetValue(command, out var channel)) {
|
||||
inputType = channel;
|
||||
}
|
||||
}
|
||||
|
||||
var inputColour = this.Ui.Plugin.Config.ChatColours.TryGetValue(inputType, out var inputCol)
|
||||
? inputCol
|
||||
: inputType.DefaultColour();
|
||||
|
@ -97,7 +97,7 @@ internal sealed class Settings : IUiComponent {
|
||||
var config = this.Ui.Plugin.Config;
|
||||
|
||||
var hideChatChanged = this.Mutable.HideChat != this.Ui.Plugin.Config.HideChat;
|
||||
var fontSizeChanged = Math.Abs(this.Mutable.FontSize - this.Ui.Plugin.Config.FontSize) > float.Epsilon;
|
||||
var fontSizeChanged = Math.Abs(this.Mutable.FontSize - this.Ui.Plugin.Config.FontSize) > 0.001;
|
||||
|
||||
config.UpdateFrom(this.Mutable);
|
||||
|
||||
|
@ -21,7 +21,18 @@ internal sealed class Display : ISettingsTab {
|
||||
ImGui.Checkbox("More compact modern layout", ref this.Mutable.MoreCompactPretty);
|
||||
}
|
||||
|
||||
ImGui.DragFloat("Font size", ref this.Mutable.FontSize, .0125f, 12f, 36f, "%.1f");
|
||||
ImGui.DragFloat("Font size", ref this.Mutable.FontSize, .0125f, 12f, 36f, $"{this.Mutable.FontSize:N1}");
|
||||
if (ImGui.DragFloat("Window opacity", ref this.Mutable.WindowAlpha, .0025f, 0f, 1f, $"{this.Mutable.WindowAlpha * 100f:N2}%%")) {
|
||||
switch (this.Mutable.WindowAlpha) {
|
||||
case > 1f and <= 100f:
|
||||
this.Mutable.WindowAlpha /= 100f;
|
||||
break;
|
||||
case < 0f or > 100f:
|
||||
this.Mutable.WindowAlpha = 1f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.Checkbox("Allow moving main window", ref this.Mutable.CanMove);
|
||||
ImGui.Checkbox("Allow resizing main window", ref this.Mutable.CanResize);
|
||||
ImGui.Checkbox("Show title bar for main window", ref this.Mutable.ShowTitleBar);
|
||||
|
@ -67,7 +67,12 @@ internal static class ImGuiUtil {
|
||||
++text;
|
||||
} // skip a space at start of line
|
||||
|
||||
endPrevLine = ImGuiNative.ImFont_CalcWordWrapPositionA(ImGui.GetFont().NativePtr, ImGuiHelpers.GlobalScale, text, textEnd, widthLeft);
|
||||
var newEnd = ImGuiNative.ImFont_CalcWordWrapPositionA(ImGui.GetFont().NativePtr, ImGuiHelpers.GlobalScale, text, textEnd, widthLeft);
|
||||
if (newEnd == endPrevLine) {
|
||||
break;
|
||||
}
|
||||
|
||||
endPrevLine = newEnd;
|
||||
if (endPrevLine == null) {
|
||||
ImGui.TextUnformatted("");
|
||||
ImGui.TextUnformatted("");
|
||||
|
Loading…
Reference in New Issue
Block a user