Compare commits

..

No commits in common. "da631c110039eb469b25b0129b908d4ac656865c" and "828d85a521cbea3359ce023002b346c2e6f9b6e5" have entirely different histories.

11 changed files with 159 additions and 299 deletions

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<Version>1.3.0</Version> <Version>1.2.0</Version>
<TargetFramework>net5.0-windows</TargetFramework> <TargetFramework>net5.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>

View File

@ -10,28 +10,10 @@ internal class Configuration : IPluginConfiguration {
public bool HideChat = true; public bool HideChat = true;
public bool NativeItemTooltips = true; public bool NativeItemTooltips = true;
public bool PrettierTimestamps = true; public bool PrettierTimestamps = true;
public bool MoreCompactPretty;
public bool SidebarTabView; public bool SidebarTabView;
public bool CanMove = true;
public bool CanResize = true;
public bool ShowTitleBar;
public float FontSize = 17f; public float FontSize = 17f;
public Dictionary<ChatType, uint> ChatColours = new(); public Dictionary<ChatType, uint> ChatColours = new();
public List<Tab> Tabs = new(); public List<Tab> Tabs = new();
internal void UpdateFrom(Configuration other) {
this.HideChat = other.HideChat;
this.NativeItemTooltips = other.NativeItemTooltips;
this.PrettierTimestamps = other.PrettierTimestamps;
this.MoreCompactPretty = other.MoreCompactPretty;
this.SidebarTabView = other.SidebarTabView;
this.CanMove = other.CanMove;
this.CanResize = other.CanResize;
this.ShowTitleBar = other.ShowTitleBar;
this.FontSize = other.FontSize;
this.ChatColours = other.ChatColours.ToDictionary(entry => entry.Key, entry => entry.Value);
this.Tabs = other.Tabs.Select(t => t.Clone()).ToList();
}
} }
[Serializable] [Serializable]
@ -73,12 +55,6 @@ internal class Tab {
} }
} }
internal void Clear() {
this.MessagesMutex.WaitOne();
this.Messages.Clear();
this.MessagesMutex.ReleaseMutex();
}
internal Tab Clone() { internal Tab Clone() {
return new Tab { return new Tab {
Name = this.Name, Name = this.Name,

View File

@ -6,7 +6,6 @@ using ChatTwo.Util;
using Dalamud.Game.ClientState.Objects.SubKinds; using Dalamud.Game.ClientState.Objects.SubKinds;
using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads; using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.Interface;
using Dalamud.Logging; using Dalamud.Logging;
using Dalamud.Utility; using Dalamud.Utility;
using ImGuiNET; using ImGuiNET;
@ -86,11 +85,9 @@ internal sealed class PayloadHandler {
} }
internal void Hover(Payload payload) { internal void Hover(Payload payload) {
var hoverSize = 250f * ImGuiHelpers.GlobalScale;
switch (payload) { switch (payload) {
case StatusPayload status: { case StatusPayload status: {
this.DoHover(() => this.HoverStatus(status), hoverSize); this.DoHover(() => this.HoverStatus(status), 250f);
break; break;
} }
case ItemPayload item: { case ItemPayload item: {
@ -108,7 +105,7 @@ internal sealed class PayloadHandler {
break; break;
} }
this.DoHover(() => this.HoverItem(item), hoverSize); this.DoHover(() => this.HoverItem(item), 250f);
break; break;
} }
} }
@ -134,10 +131,9 @@ internal sealed class PayloadHandler {
var lineHeight = ImGui.CalcTextSize("A").Y; var lineHeight = ImGui.CalcTextSize("A").Y;
var cursor = ImGui.GetCursorPos(); var cursor = ImGui.GetCursorPos();
var size = new Vector2(icon.Width, icon.Height) * ImGuiHelpers.GlobalScale; ImGui.Image(icon.ImGuiHandle, new Vector2(icon.Width, icon.Height));
ImGui.Image(icon.ImGuiHandle, size);
ImGui.SameLine(); ImGui.SameLine();
ImGui.SetCursorPos(cursor + new Vector2(size.X + 4, size.Y / 2 - lineHeight / 2)); ImGui.SetCursorPos(cursor + new Vector2(icon.Width + 4, (float) icon.Height / 2 - lineHeight / 2));
} }
private void HoverStatus(StatusPayload status) { private void HoverStatus(StatusPayload status) {

View File

@ -61,7 +61,7 @@ internal sealed class PluginUi : IDisposable {
var builder = new ImFontGlyphRangesBuilderPtr(ImGuiNative.ImFontGlyphRangesBuilder_ImFontGlyphRangesBuilder()); var builder = new ImFontGlyphRangesBuilderPtr(ImGuiNative.ImFontGlyphRangesBuilder_ImFontGlyphRangesBuilder());
builder.AddRanges(ImGui.GetIO().Fonts.GetGlyphRangesDefault()); builder.AddRanges(ImGui.GetIO().Fonts.GetGlyphRangesDefault());
builder.AddText("←→↑↓《》■※☀★★☆♥♡ヅツッシ☀☁☂℃℉°♀♂♠♣♦♣♧®©™€$£♯♭♪✓√◎◆◇♦■□〇●△▽▼▲‹›≤≥<«“”─\~Œœ"); builder.AddText("←→↑↓《》■※☀★★☆♥♡ヅツッシ☀☁☂℃℉°♀♂♠♣♦♣♧®©™€$£♯♭♪✓√◎◆◇♦■□〇●△▽▼▲‹›≤≥<«“”─\~");
builder.BuildRanges(out this._ranges); builder.BuildRanges(out this._ranges);
var regular = this.GetResource("ChatTwo.fonts.NotoSans-Regular.ttf"); var regular = this.GetResource("ChatTwo.fonts.NotoSans-Regular.ttf");

View File

@ -1,7 +1,6 @@
using System.Numerics; using System.Numerics;
using ChatTwo.Code; using ChatTwo.Code;
using ChatTwo.Util; using ChatTwo.Util;
using Dalamud.Game.Command;
using Dalamud.Game.Text.SeStringHandling.Payloads; using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.Interface; using Dalamud.Interface;
using ImGuiNET; using ImGuiNET;
@ -27,9 +26,6 @@ internal sealed class ChatLog : IUiComponent {
internal ChatLog(PluginUi ui) { internal ChatLog(PluginUi ui) {
this.Ui = ui; this.Ui = ui;
this.PayloadHandler = new PayloadHandler(this.Ui, this); this.PayloadHandler = new PayloadHandler(this.Ui, this);
this.Ui.Plugin.CommandManager.AddHandler("/clearlog2", new CommandInfo(this.ClearLog) {
HelpMessage = "Clears the Chat 2 chat log",
});
this._fontIcon = this.Ui.Plugin.DataManager.GetImGuiTexture("common/font/fonticon_ps5.tex"); this._fontIcon = this.Ui.Plugin.DataManager.GetImGuiTexture("common/font/fonticon_ps5.tex");
@ -39,7 +35,6 @@ internal sealed class ChatLog : IUiComponent {
public void Dispose() { public void Dispose() {
this.Ui.Plugin.Functions.Chat.Activated -= this.Activated; this.Ui.Plugin.Functions.Chat.Activated -= this.Activated;
this._fontIcon?.Dispose(); this._fontIcon?.Dispose();
this.Ui.Plugin.CommandManager.RemoveHandler("/clearlog2");
} }
private void Activated(string? input) { private void Activated(string? input) {
@ -49,33 +44,6 @@ internal sealed class ChatLog : IUiComponent {
} }
} }
private void ClearLog(string command, string arguments) {
switch (arguments) {
case "all":
using (var messages = this.Ui.Plugin.Store.GetMessages()) {
messages.Messages.Clear();
}
foreach (var tab in this.Ui.Plugin.Config.Tabs) {
tab.Clear();
}
break;
case "help":
this.Ui.Plugin.ChatGui.Print("- /clearlog2: clears the active tab's log");
this.Ui.Plugin.ChatGui.Print("- /clearlog2 all: clears all tabs' logs and the global history");
this.Ui.Plugin.ChatGui.Print("- /clearlog2 help: shows this help");
break;
default:
if (this._lastTab > -1 && this._lastTab < this.Ui.Plugin.Config.Tabs.Count) {
this.Ui.Plugin.Config.Tabs[this._lastTab].Clear();
}
break;
}
}
private void AddBacklog(string message) { private void AddBacklog(string message) {
for (var i = 0; i < this._inputBacklog.Count; i++) { for (var i = 0; i < this._inputBacklog.Count; i++) {
if (this._inputBacklog[i] != message) { if (this._inputBacklog[i] != message) {
@ -97,20 +65,7 @@ internal sealed class ChatLog : IUiComponent {
} }
public unsafe void Draw() { public unsafe void Draw() {
var flags = ImGuiWindowFlags.None; if (!ImGui.Begin($"{this.Ui.Plugin.Name}##chat", ImGuiWindowFlags.NoTitleBar)) {
if (!this.Ui.Plugin.Config.CanMove) {
flags |= ImGuiWindowFlags.NoMove;
}
if (!this.Ui.Plugin.Config.CanResize) {
flags |= ImGuiWindowFlags.NoResize;
}
if (!this.Ui.Plugin.Config.ShowTitleBar) {
flags |= ImGuiWindowFlags.NoTitleBar;
}
if (!ImGui.Begin($"{this.Ui.Plugin.Name}##chat", flags)) {
ImGui.End(); ImGui.End();
return; return;
} }
@ -124,7 +79,7 @@ internal sealed class ChatLog : IUiComponent {
} }
Tab? activeTab = null; Tab? activeTab = null;
if (currentTab > -1 && currentTab < this.Ui.Plugin.Config.Tabs.Count) { if (currentTab > -1 && currentTab < this.Ui.Plugin.Config.Tabs.Count - 1) {
activeTab = this.Ui.Plugin.Config.Tabs[currentTab]; activeTab = this.Ui.Plugin.Config.Tabs[currentTab];
} }
@ -219,13 +174,6 @@ internal sealed class ChatLog : IUiComponent {
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, Vector2.Zero); ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, Vector2.Zero);
var table = tab.DisplayTimestamp && this.Ui.Plugin.Config.PrettierTimestamps; var table = tab.DisplayTimestamp && this.Ui.Plugin.Config.PrettierTimestamps;
if (this.Ui.Plugin.Config.MoreCompactPretty) {
var padding = ImGui.GetStyle().CellPadding;
padding.Y = 0;
ImGui.PushStyleVar(ImGuiStyleVar.CellPadding, padding);
}
if (table) { if (table) {
if (!ImGui.BeginTable("timestamp-table", 2, ImGuiTableFlags.PreciseWidths)) { if (!ImGui.BeginTable("timestamp-table", 2, ImGuiTableFlags.PreciseWidths)) {
goto EndChild; goto EndChild;
@ -279,7 +227,7 @@ internal sealed class ChatLog : IUiComponent {
// } // }
} finally { } finally {
tab.MessagesMutex.ReleaseMutex(); tab.MessagesMutex.ReleaseMutex();
ImGui.PopStyleVar(this.Ui.Plugin.Config.MoreCompactPretty ? 2 : 1); ImGui.PopStyleVar();
} }
// PluginLog.Log($"numDrawn: {numDrawn}"); // PluginLog.Log($"numDrawn: {numDrawn}");
@ -396,7 +344,7 @@ internal sealed class ChatLog : IUiComponent {
ImGui.PushID($"tab-context-menu-{i}"); ImGui.PushID($"tab-context-menu-{i}");
ImGui.SetNextItemWidth(250f * ImGuiHelpers.GlobalScale); ImGui.SetNextItemWidth(250f);
if (ImGui.InputText("##tab-name", ref tab.Name, 128)) { if (ImGui.InputText("##tab-name", ref tab.Name, 128)) {
anyChanged = true; anyChanged = true;
} }
@ -519,7 +467,7 @@ internal sealed class ChatLog : IUiComponent {
var texSize = new Vector2(this._fontIcon.Width, this._fontIcon.Height); var texSize = new Vector2(this._fontIcon.Width, this._fontIcon.Height);
var sizeRatio = this.Ui.Plugin.Config.FontSize / bounds.Value.W; var sizeRatio = this.Ui.Plugin.Config.FontSize / bounds.Value.W;
var size = new Vector2(bounds.Value.Z, bounds.Value.W) * sizeRatio * ImGuiHelpers.GlobalScale; var size = new Vector2(bounds.Value.Z, bounds.Value.W) * sizeRatio;
var uv0 = new Vector2(bounds.Value.X, bounds.Value.Y - 2) / texSize; 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; var uv1 = new Vector2(bounds.Value.X + bounds.Value.Z, bounds.Value.Y - 2 + bounds.Value.W) / texSize;

View File

@ -1,6 +1,8 @@
using System.Numerics; using System.Numerics;
using ChatTwo.Ui.SettingsTabs; using ChatTwo.Code;
using ChatTwo.Util;
using Dalamud.Game.Command; using Dalamud.Game.Command;
using Dalamud.Interface;
using ImGuiNET; using ImGuiNET;
namespace ChatTwo.Ui; namespace ChatTwo.Ui;
@ -8,19 +10,16 @@ namespace ChatTwo.Ui;
internal sealed class Settings : IUiComponent { internal sealed class Settings : IUiComponent {
private PluginUi Ui { get; } private PluginUi Ui { get; }
private Configuration Mutable { get; } private bool _hideChat;
private List<ISettingsTab> Tabs { get; } private bool _nativeItemTooltips;
private bool _sidebarTabView;
private bool _prettierTimestamps;
private float _fontSize;
private Dictionary<ChatType, uint> _chatColours = new();
private List<Tab> _tabs = new();
internal Settings(PluginUi ui) { internal Settings(PluginUi ui) {
this.Ui = ui; this.Ui = ui;
this.Mutable = new Configuration();
this.Tabs = new List<ISettingsTab> {
new Display(this.Mutable),
new ChatColours(this.Mutable),
new Tabs(this.Mutable),
};
this.Ui.Plugin.CommandManager.AddHandler("/chat2", new CommandInfo(this.Command) { this.Ui.Plugin.CommandManager.AddHandler("/chat2", new CommandInfo(this.Command) {
HelpMessage = "Toggle the Chat 2 settings", HelpMessage = "Toggle the Chat 2 settings",
}); });
@ -35,7 +34,14 @@ internal sealed class Settings : IUiComponent {
} }
private void Initialise() { private void Initialise() {
this.Mutable.UpdateFrom(this.Ui.Plugin.Config); var config = this.Ui.Plugin.Config;
this._hideChat = config.HideChat;
this._nativeItemTooltips = config.NativeItemTooltips;
this._sidebarTabView = config.SidebarTabView;
this._prettierTimestamps = config.PrettierTimestamps;
this._fontSize = config.FontSize;
this._chatColours = config.ChatColours.ToDictionary(entry => entry.Key, entry => entry.Value);
this._tabs = config.Tabs.Select(tab => tab.Clone()).ToList();
} }
public void Draw() { public void Draw() {
@ -52,26 +58,127 @@ internal sealed class Settings : IUiComponent {
this.Initialise(); this.Initialise();
} }
if (ImGui.BeginTabBar("settings-tabs")) { var height = ImGui.GetContentRegionAvail().Y
foreach (var settingsTab in this.Tabs) { - ImGui.GetStyle().FramePadding.Y * 2
if (!ImGui.BeginTabItem(settingsTab.Name)) { - ImGui.GetStyle().ItemSpacing.Y
continue; - ImGui.GetStyle().ItemInnerSpacing.Y * 2
- 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.Checkbox("Show tabs in a sidebar", ref this._sidebarTabView);
ImGui.Checkbox("Use modern timestamp layout", ref this._prettierTimestamps);
ImGui.DragFloat("Font size", ref this._fontSize, .0125f, 12f, 36f, "%.1f");
if (ImGui.TreeNodeEx("Chat colours")) {
foreach (var type in Enum.GetValues<ChatType>()) {
if (ImGui.Button($"Default##{type}")) {
this._chatColours.Remove(type);
}
ImGui.SameLine();
var vec = this._chatColours.TryGetValue(type, out var colour)
? ColourUtil.RgbaToVector3(colour)
: ColourUtil.RgbaToVector3(type.DefaultColour() ?? 0);
if (ImGui.ColorEdit3(type.Name(), ref vec, ImGuiColorEditFlags.NoInputs)) {
this._chatColours[type] = ColourUtil.Vector3ToRgba(vec);
}
} }
var height = ImGui.GetContentRegionAvail().Y ImGui.TreePop();
- ImGui.GetStyle().FramePadding.Y * 2
- ImGui.GetStyle().ItemSpacing.Y
- ImGui.GetStyle().ItemInnerSpacing.Y * 2
- ImGui.CalcTextSize("A").Y;
if (ImGui.BeginChild("##chat2-settings", new Vector2(-1, height))) {
settingsTab.Draw();
ImGui.EndChild();
}
ImGui.EndTabItem();
} }
ImGui.EndTabBar(); if (ImGui.TreeNodeEx("Tabs")) {
if (ImGuiUtil.IconButton(FontAwesomeIcon.Plus, tooltip: "Add")) {
this._tabs.Add(new Tab());
}
var toRemove = -1;
for (var i = 0; i < this._tabs.Count; i++) {
var tab = this._tabs[i];
if (ImGui.TreeNodeEx($"{tab.Name}###tab-{i}")) {
ImGui.PushID($"tab-{i}");
if (ImGuiUtil.IconButton(FontAwesomeIcon.TrashAlt, tooltip: "Delete")) {
toRemove = i;
}
ImGui.SameLine();
if (ImGuiUtil.IconButton(FontAwesomeIcon.ArrowUp, tooltip: "Move up") && i > 0) {
(this._tabs[i - 1], this._tabs[i]) = (this._tabs[i], this._tabs[i - 1]);
}
ImGui.SameLine();
if (ImGuiUtil.IconButton(FontAwesomeIcon.ArrowDown, tooltip: "Move down") && i < this._tabs.Count - 1) {
(this._tabs[i + 1], this._tabs[i]) = (this._tabs[i], this._tabs[i + 1]);
}
ImGui.InputText("Name", ref tab.Name, 512, ImGuiInputTextFlags.EnterReturnsTrue);
ImGui.Checkbox("Show unread count", ref tab.DisplayUnread);
ImGui.Checkbox("Show timestamps", ref tab.DisplayTimestamp);
var input = tab.Channel?.ToChatType().Name() ?? "<None>";
if (ImGui.BeginCombo("Input channel", input)) {
if (ImGui.Selectable("<None>", tab.Channel == null)) {
tab.Channel = null;
}
foreach (var channel in Enum.GetValues<InputChannel>()) {
if (ImGui.Selectable(channel.ToChatType().Name(), tab.Channel == channel)) {
tab.Channel = channel;
}
}
ImGui.EndCombo();
}
if (ImGui.TreeNodeEx("Channels")) {
foreach (var type in Enum.GetValues<ChatType>()) {
var enabled = tab.ChatCodes.ContainsKey(type);
if (ImGui.Checkbox($"##{type.Name()}-{i}", ref enabled)) {
if (enabled) {
tab.ChatCodes[type] = ChatSourceExt.All;
} else {
tab.ChatCodes.Remove(type);
}
}
ImGui.SameLine();
if (ImGui.TreeNodeEx($"{type.Name()}##{i}")) {
tab.ChatCodes.TryGetValue(type, out var sourcesEnum);
var sources = (uint) sourcesEnum;
foreach (var source in Enum.GetValues<ChatSource>()) {
if (ImGui.CheckboxFlags(source.ToString(), ref sources, (uint) source)) {
tab.ChatCodes[type] = (ChatSource) sources;
}
}
ImGui.TreePop();
}
}
ImGui.TreePop();
}
ImGui.TreePop();
ImGui.PopID();
}
}
if (toRemove > -1) {
this._tabs.RemoveAt(toRemove);
}
}
ImGui.EndChild();
} }
ImGui.Separator(); ImGui.Separator();
@ -96,10 +203,16 @@ internal sealed class Settings : IUiComponent {
if (save) { if (save) {
var config = this.Ui.Plugin.Config; var config = this.Ui.Plugin.Config;
var hideChatChanged = this.Mutable.HideChat != this.Ui.Plugin.Config.HideChat; var hideChatChanged = this._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._fontSize - this.Ui.Plugin.Config.FontSize) > float.Epsilon;
config.UpdateFrom(this.Mutable); config.HideChat = this._hideChat;
config.NativeItemTooltips = this._nativeItemTooltips;
config.SidebarTabView = this._sidebarTabView;
config.PrettierTimestamps = this._prettierTimestamps;
config.FontSize = this._fontSize;
config.ChatColours = this._chatColours;
config.Tabs = this._tabs;
this.Ui.Plugin.SaveConfig(); this.Ui.Plugin.SaveConfig();
@ -109,7 +222,7 @@ internal sealed class Settings : IUiComponent {
this.Ui.Plugin.Interface.UiBuilder.RebuildFonts(); this.Ui.Plugin.Interface.UiBuilder.RebuildFonts();
} }
if (!this.Mutable.HideChat && hideChatChanged) { if (!this._hideChat && hideChatChanged) {
GameFunctions.GameFunctions.SetChatInteractable(true); GameFunctions.GameFunctions.SetChatInteractable(true);
} }

View File

@ -1,34 +0,0 @@
using ChatTwo.Code;
using ChatTwo.Util;
using ImGuiNET;
namespace ChatTwo.Ui.SettingsTabs;
internal sealed class ChatColours : ISettingsTab {
private Configuration Mutable { get; }
public string Name => "Chat colours";
internal ChatColours(Configuration mutable) {
this.Mutable = mutable;
}
public void Draw() {
foreach (var type in Enum.GetValues<ChatType>()) {
if (ImGui.Button($"Default##{type}")) {
this.Mutable.ChatColours.Remove(type);
}
ImGui.SameLine();
var vec = this.Mutable.ChatColours.TryGetValue(type, out var colour)
? ColourUtil.RgbaToVector3(colour)
: ColourUtil.RgbaToVector3(type.DefaultColour() ?? 0);
if (ImGui.ColorEdit3(type.Name(), ref vec, ImGuiColorEditFlags.NoInputs)) {
this.Mutable.ChatColours[type] = ColourUtil.Vector3ToRgba(vec);
}
}
ImGui.TreePop();
}
}

View File

@ -1,29 +0,0 @@
using ImGuiNET;
namespace ChatTwo.Ui.SettingsTabs;
internal sealed class Display : ISettingsTab {
private Configuration Mutable { get; }
public string Name => "Display";
internal Display(Configuration mutable) {
this.Mutable = mutable;
}
public void Draw() {
ImGui.Checkbox("Hide chat", ref this.Mutable.HideChat);
ImGui.Checkbox("Show native item tooltips", ref this.Mutable.NativeItemTooltips);
ImGui.Checkbox("Show tabs in a sidebar", ref this.Mutable.SidebarTabView);
ImGui.Checkbox("Use modern timestamp layout", ref this.Mutable.PrettierTimestamps);
if (this.Mutable.PrettierTimestamps) {
ImGui.Checkbox("More compact modern layout", ref this.Mutable.MoreCompactPretty);
}
ImGui.DragFloat("Font size", ref this.Mutable.FontSize, .0125f, 12f, 36f, "%.1f");
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);
}
}

View File

@ -1,6 +0,0 @@
namespace ChatTwo.Ui.SettingsTabs;
internal interface ISettingsTab {
string Name { get; }
void Draw();
}

View File

@ -1,105 +0,0 @@
using ChatTwo.Code;
using ChatTwo.Util;
using Dalamud.Interface;
using ImGuiNET;
namespace ChatTwo.Ui.SettingsTabs;
internal sealed class Tabs : ISettingsTab {
private Configuration Mutable { get; }
public string Name => "Tabs";
internal Tabs(Configuration mutable) {
this.Mutable = mutable;
}
public void Draw() {
if (ImGuiUtil.IconButton(FontAwesomeIcon.Plus, tooltip: "Add")) {
this.Mutable.Tabs.Add(new Tab());
}
var toRemove = -1;
for (var i = 0; i < this.Mutable.Tabs.Count; i++) {
var tab = this.Mutable.Tabs[i];
if (ImGui.TreeNodeEx($"{tab.Name}###tab-{i}")) {
ImGui.PushID($"tab-{i}");
if (ImGuiUtil.IconButton(FontAwesomeIcon.TrashAlt, tooltip: "Delete")) {
toRemove = i;
}
ImGui.SameLine();
if (ImGuiUtil.IconButton(FontAwesomeIcon.ArrowUp, tooltip: "Move up") && i > 0) {
(this.Mutable.Tabs[i - 1], this.Mutable.Tabs[i]) = (this.Mutable.Tabs[i], this.Mutable.Tabs[i - 1]);
}
ImGui.SameLine();
if (ImGuiUtil.IconButton(FontAwesomeIcon.ArrowDown, tooltip: "Move down") && i < this.Mutable.Tabs.Count - 1) {
(this.Mutable.Tabs[i + 1], this.Mutable.Tabs[i]) = (this.Mutable.Tabs[i], this.Mutable.Tabs[i + 1]);
}
ImGui.InputText("Name", ref tab.Name, 512, ImGuiInputTextFlags.EnterReturnsTrue);
ImGui.Checkbox("Show unread count", ref tab.DisplayUnread);
ImGui.Checkbox("Show timestamps", ref tab.DisplayTimestamp);
var input = tab.Channel?.ToChatType().Name() ?? "<None>";
if (ImGui.BeginCombo("Input channel", input)) {
if (ImGui.Selectable("<None>", tab.Channel == null)) {
tab.Channel = null;
}
foreach (var channel in Enum.GetValues<InputChannel>()) {
if (ImGui.Selectable(channel.ToChatType().Name(), tab.Channel == channel)) {
tab.Channel = channel;
}
}
ImGui.EndCombo();
}
if (ImGui.TreeNodeEx("Channels")) {
foreach (var type in Enum.GetValues<ChatType>()) {
var enabled = tab.ChatCodes.ContainsKey(type);
if (ImGui.Checkbox($"##{type.Name()}-{i}", ref enabled)) {
if (enabled) {
tab.ChatCodes[type] = ChatSourceExt.All;
} else {
tab.ChatCodes.Remove(type);
}
}
ImGui.SameLine();
if (ImGui.TreeNodeEx($"{type.Name()}##{i}")) {
tab.ChatCodes.TryGetValue(type, out var sourcesEnum);
var sources = (uint) sourcesEnum;
foreach (var source in Enum.GetValues<ChatSource>()) {
if (ImGui.CheckboxFlags(source.ToString(), ref sources, (uint) source)) {
tab.ChatCodes[type] = (ChatSource) sources;
}
}
ImGui.TreePop();
}
}
ImGui.TreePop();
}
ImGui.TreePop();
ImGui.PopID();
}
}
if (toRemove > -1) {
this.Mutable.Tabs.RemoveAt(toRemove);
}
}
}

View File

@ -52,8 +52,9 @@ internal static class ImGuiUtil {
return; return;
} }
const float scale = 1.0f;
var widthLeft = ImGui.GetContentRegionAvail().X; var widthLeft = ImGui.GetContentRegionAvail().X;
var endPrevLine = ImGuiNative.ImFont_CalcWordWrapPositionA(ImGui.GetFont().NativePtr, ImGuiHelpers.GlobalScale, text, textEnd, widthLeft); var endPrevLine = ImGuiNative.ImFont_CalcWordWrapPositionA(ImGui.GetFont().NativePtr, scale, text, textEnd, widthLeft);
if (endPrevLine == null) { if (endPrevLine == null) {
return; return;
} }
@ -67,7 +68,7 @@ internal static class ImGuiUtil {
++text; ++text;
} // skip a space at start of line } // skip a space at start of line
endPrevLine = ImGuiNative.ImFont_CalcWordWrapPositionA(ImGui.GetFont().NativePtr, ImGuiHelpers.GlobalScale, text, textEnd, widthLeft); endPrevLine = ImGuiNative.ImFont_CalcWordWrapPositionA(ImGui.GetFont().NativePtr, scale, text, textEnd, widthLeft);
if (endPrevLine == null) { if (endPrevLine == null) {
ImGui.TextUnformatted(""); ImGui.TextUnformatted("");
ImGui.TextUnformatted(""); ImGui.TextUnformatted("");