use ImRaii in settings window

This commit is contained in:
Infi
2024-04-21 16:44:45 +02:00
parent ed5cedefd2
commit c152f3dfde
12 changed files with 402 additions and 438 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ using Lumina.Excel.GeneratedSheets;
namespace ChatTwo.Ui;
public sealed class ChatLogWindow : Window, IUiComponent
public sealed class ChatLogWindow : Window
{
private const string ChatChannelPicker = "chat-channel-picker";
private const string AutoCompleteId = "##chat2-autocomplete";
+2 -3
View File
@@ -1,5 +1,6 @@
using System.Numerics;
using Dalamud.Interface.Style;
using Dalamud.Interface.Utility.Raii;
using Dalamud.Interface.Windowing;
using ImGuiNET;
@@ -47,7 +48,7 @@ internal class Popout : Window
public override void Draw()
{
ImGui.PushID($"popout-{Tab.Name}");
using var id = ImRaii.PushId($"popout-{Tab.Name}");
if (!ChatLogWindow.Plugin.Config.ShowPopOutTitleBar) {
ImGui.TextUnformatted(Tab.Name);
@@ -56,8 +57,6 @@ internal class Popout : Window
var handler = ChatLogWindow.HandlerLender.Borrow();
ChatLogWindow.DrawMessageLog(Tab, handler, ImGui.GetContentRegionAvail().Y, false);
ImGui.PopID();
}
public override void PostDraw()
+44 -52
View File
@@ -2,13 +2,14 @@ using System.Numerics;
using ChatTwo.Resources;
using ChatTwo.Ui.SettingsTabs;
using ChatTwo.Util;
using Dalamud.Interface.Utility.Raii;
using Dalamud.Interface.Windowing;
using Dalamud.Utility;
using ImGuiNET;
namespace ChatTwo.Ui;
public sealed class SettingsWindow : Window, IUiComponent
public sealed class SettingsWindow : Window
{
private readonly Plugin Plugin;
@@ -30,7 +31,8 @@ public sealed class SettingsWindow : Window, IUiComponent
Plugin = plugin;
Mutable = new Configuration();
Tabs = new List<ISettingsTab> {
Tabs = new List<ISettingsTab>
{
new Display(Mutable),
new Ui.SettingsTabs.Fonts(Mutable),
new ChatColours(Mutable, Plugin),
@@ -49,17 +51,20 @@ public sealed class SettingsWindow : Window, IUiComponent
Plugin.Interface.UiBuilder.OpenConfigUi += Toggle;
}
public void Dispose() {
public void Dispose()
{
Plugin.Interface.UiBuilder.OpenConfigUi -= Toggle;
Plugin.Commands.Register("/chat2").Execute -= Command;
}
private void Command(string command, string args) {
private void Command(string command, string args)
{
if (string.IsNullOrWhiteSpace(args))
Toggle();
}
private void Initialise() {
private void Initialise()
{
Mutable.UpdateFrom(Plugin.Config);
}
@@ -68,33 +73,33 @@ public sealed class SettingsWindow : Window, IUiComponent
if (ImGui.IsWindowAppearing())
Initialise();
if (ImGui.BeginTable("##chat2-settings-table", 2)) {
using (var table = ImRaii.Table("##chat2-settings-table", 2))
{
if (table)
{
ImGui.TableSetupColumn("tab", ImGuiTableColumnFlags.WidthFixed);
ImGui.TableSetupColumn("settings", ImGuiTableColumnFlags.WidthStretch);
ImGui.TableNextColumn();
var changed = false;
for (var i = 0; i < Tabs.Count; i++) {
if (ImGui.Selectable($"{Tabs[i].Name}###tab-{i}", CurrentTab == i)) {
for (var i = 0; i < Tabs.Count; i++)
{
if (!ImGui.Selectable($"{Tabs[i].Name}###tab-{i}", CurrentTab == i))
continue;
CurrentTab = i;
changed = true;
}
}
ImGui.TableNextColumn();
var height = ImGui.GetContentRegionAvail().Y
- 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))) {
var height = ImGui.GetContentRegionAvail().Y - ImGui.GetStyle().FramePadding.Y * 2 - ImGui.GetStyle().ItemSpacing.Y
- ImGui.GetStyle().ItemInnerSpacing.Y * 2 - ImGui.CalcTextSize("A").Y;
using var child = ImRaii.Child("##chat2-settings", new Vector2(-1, height));
if (child)
Tabs[CurrentTab].Draw(changed);
ImGui.EndChild();
}
ImGui.EndTable();
}
ImGui.Separator();
@@ -114,65 +119,52 @@ public sealed class SettingsWindow : Window, IUiComponent
IsOpen = false;
}
var buttonLabel = "Anna's Ko-fi";
var buttonLabel2 = "Infi's Ko-fi";
const string buttonLabel = "Anna's Ko-fi";
const string buttonLabel2 = "Infi's Ko-fi";
ImGui.PushStyleColor(ImGuiCol.Button, ColourUtil.RgbaToAbgr(0xFF5E5BFF));
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, ColourUtil.RgbaToAbgr(0xFF7775FF));
ImGui.PushStyleColor(ImGuiCol.ButtonActive, ColourUtil.RgbaToAbgr(0xFF4542FF));
ImGui.PushStyleColor(ImGuiCol.Text, 0xFFFFFFFF);
try {
using (ImRaii.PushColor(ImGuiCol.Button, ColourUtil.RgbaToAbgr(0xFF5E5BFF)))
using (ImRaii.PushColor(ImGuiCol.ButtonHovered, ColourUtil.RgbaToAbgr(0xFF7775FF)))
using (ImRaii.PushColor(ImGuiCol.ButtonActive, ColourUtil.RgbaToAbgr(0xFF4542FF)))
using (ImRaii.PushColor(ImGuiCol.Text, 0xFFFFFFFF))
{
var buttonWidth = ImGui.CalcTextSize(buttonLabel).X + ImGui.GetStyle().FramePadding.X * 2;
var buttonWidth2 = ImGui.CalcTextSize(buttonLabel2).X + ImGui.GetStyle().FramePadding.X * 2;
ImGui.SameLine(ImGui.GetContentRegionAvail().X - buttonWidth - buttonWidth2);
if (ImGui.Button(buttonLabel2)) {
if (ImGui.Button(buttonLabel2))
Dalamud.Utility.Util.OpenLink("https://ko-fi.com/infiii");
}
ImGui.SameLine();
if (ImGui.Button(buttonLabel)) {
if (ImGui.Button(buttonLabel))
Dalamud.Utility.Util.OpenLink("https://ko-fi.com/lojewalo");
}
} finally {
ImGui.PopStyleColor(4);
}
if (save) {
var config = Plugin.Config;
if (!save)
return;
Plugin.Config.UpdateFrom(Mutable);
// save after 60 frames have passed, which should hopefully not
// commit any changes that cause a crash
Plugin.DeferredSaveFrames = 60;
Plugin.MessageManager.FilterAllTabs(false);
var hideChatChanged = Mutable.HideChat != Plugin.Config.HideChat;
var fontChanged = Mutable.GlobalFont != Plugin.Config.GlobalFont
|| Mutable.JapaneseFont != Plugin.Config.JapaneseFont
|| Mutable.ExtraGlyphRanges != Plugin.Config.ExtraGlyphRanges;
var fontSizeChanged = Math.Abs(Mutable.FontSize - Plugin.Config.FontSize) > 0.001
|| Math.Abs(Mutable.JapaneseFontSize - Plugin.Config.JapaneseFontSize) > 0.001
|| Math.Abs(Mutable.SymbolsFontSize - Plugin.Config.SymbolsFontSize) > 0.001;
var langChanged = Mutable.LanguageOverride != Plugin.Config.LanguageOverride;
config.UpdateFrom(Mutable);
// save after 60 frames have passed, which should hopefully not
// commit any changes that cause a crash
Plugin.DeferredSaveFrames = 60;
Plugin.MessageManager.FilterAllTabs(false);
if (fontChanged || fontSizeChanged) {
if (fontChanged || fontSizeChanged)
Plugin.FontManager.BuildFonts();
}
if (langChanged) {
if (Mutable.LanguageOverride != Plugin.Config.LanguageOverride)
Plugin.LanguageChanged(Plugin.Interface.UiLanguage);
}
if (!Mutable.HideChat && hideChatChanged) {
if (!Mutable.HideChat && Mutable.HideChat != Plugin.Config.HideChat)
GameFunctions.GameFunctions.SetChatInteractable(true);
}
Initialise();
}
}
}
+6 -3
View File
@@ -9,7 +9,8 @@ using ImGuiNET;
namespace ChatTwo.Ui.SettingsTabs;
internal sealed class About : ISettingsTab {
internal sealed class About : ISettingsTab
{
public string Name => string.Format(Language.Options_About_Tab, Plugin.PluginName) + "###tabs-about";
private readonly List<string> _translators =
@@ -25,11 +26,13 @@ internal sealed class About : ISettingsTab {
"zomsakura", "Sirayuki"
];
internal About() {
internal About()
{
_translators.Sort((a, b) => string.Compare(a.ToLowerInvariant(), b.ToLowerInvariant(), StringComparison.Ordinal));
}
public void Draw(bool changed) {
public void Draw(bool changed)
{
ImGui.PushTextWrapPos();
ImGui.TextUnformatted(string.Format(Language.Options_About_Opening, Plugin.PluginName));
+18 -15
View File
@@ -6,46 +6,50 @@ using ImGuiNET;
namespace ChatTwo.Ui.SettingsTabs;
internal sealed class ChatColours : ISettingsTab {
internal sealed class ChatColours : ISettingsTab
{
private Configuration Mutable { get; }
private Plugin Plugin { get; }
public string Name => Language.Options_ChatColours_Tab + "###tabs-chat-colours";
internal ChatColours(Configuration mutable, Plugin plugin) {
internal ChatColours(Configuration mutable, Plugin plugin)
{
Mutable = mutable;
Plugin = plugin;
#if DEBUG
// Users can set colours for ExtraChat linkshells in the ExtraChat plugin directly.
var sortable = ChatTypeExt.SortOrder
.SelectMany(entry => entry.Item2)
// Users can set colours for ExtraChat linkshells in the ExtraChat
// plugin directly.
.Where(type => !type.IsGm() && !type.IsExtraChatLinkshell())
.ToHashSet();
var total = Enum.GetValues<ChatType>()
.Where(type => !type.IsGm() && !type.IsExtraChatLinkshell())
.ToHashSet();
if (sortable.Count != total.Count) {
if (sortable.Count != total.Count)
{
Plugin.Log.Warning($"There are {sortable.Count} sortable channels, but there are {total.Count} total channels.");
total.ExceptWith(sortable);
foreach (var missing in total) {
foreach (var missing in total)
Plugin.Log.Information($"Missing {missing}");
}
}
#endif
}
public void Draw(bool changed) {
foreach (var (_, types) in ChatTypeExt.SortOrder) {
foreach (var type in types) {
if (ImGuiUtil.IconButton(FontAwesomeIcon.UndoAlt, $"{type}", Language.Options_ChatColours_Reset)) {
public void Draw(bool changed)
{
foreach (var (_, types) in ChatTypeExt.SortOrder)
{
foreach (var type in types)
{
if (ImGuiUtil.IconButton(FontAwesomeIcon.UndoAlt, $"{type}", Language.Options_ChatColours_Reset))
Mutable.ChatColours.Remove(type);
}
ImGui.SameLine();
if (ImGuiUtil.IconButton(FontAwesomeIcon.LongArrowAltDown, $"{type}", Language.Options_ChatColours_Import)) {
if (ImGuiUtil.IconButton(FontAwesomeIcon.LongArrowAltDown, $"{type}", Language.Options_ChatColours_Import))
{
var gameColour = Plugin.Functions.Chat.GetChannelColour(type);
Mutable.ChatColours[type] = gameColour ?? type.DefaultColour() ?? 0;
}
@@ -55,11 +59,10 @@ internal sealed class ChatColours : ISettingsTab {
var vec = Mutable.ChatColours.TryGetValue(type, out var colour)
? ColourUtil.RgbaToVector3(colour)
: ColourUtil.RgbaToVector3(type.DefaultColour() ?? 0);
if (ImGui.ColorEdit3(type.Name(), ref vec, ImGuiColorEditFlags.NoInputs)) {
if (ImGui.ColorEdit3(type.Name(), ref vec, ImGuiColorEditFlags.NoInputs))
Mutable.ChatColours[type] = ColourUtil.Vector3ToRgba(vec);
}
}
}
ImGui.Spacing();
}
+25 -26
View File
@@ -5,6 +5,7 @@ using ChatTwo.Util;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.Interface.Internal.Notifications;
using Dalamud.Interface.Utility.Raii;
using ImGuiNET;
namespace ChatTwo.Ui.SettingsTabs;
@@ -29,7 +30,8 @@ internal sealed class Database : ISettingsTab
private long DatabaseLogSize;
private int DatabaseMessageCount;
public void Draw(bool changed) {
public void Draw(bool changed)
{
if (changed)
ShowAdvanced = ImGui.GetIO().KeyShift;
@@ -37,18 +39,14 @@ internal sealed class Database : ISettingsTab
ImGui.Spacing();
if (ImGuiUtil.OptionCheckbox(ref Mutable.LoadPreviousSession, Language.Options_LoadPreviousSession_Name, Language.Options_LoadPreviousSession_Description))
{
if (Mutable.LoadPreviousSession)
Mutable.FilterIncludePreviousSessions = true;
}
ImGui.Spacing();
if (ImGuiUtil.OptionCheckbox(ref Mutable.FilterIncludePreviousSessions, Language.Options_FilterIncludePreviousSessions_Name, Language.Options_FilterIncludePreviousSessions_Description))
{
if (!Mutable.FilterIncludePreviousSessions)
Mutable.LoadPreviousSession = false;
}
ImGui.Spacing();
ImGui.Separator();
@@ -80,9 +78,8 @@ internal sealed class Database : ISettingsTab
}
ImGui.TextUnformatted(Language.Options_Database_Metadata_Heading);
var style = ImGui.GetStyle();
ImGui.Indent(style.IndentSpacing);
using (ImRaii.PushIndent(ImGui.GetStyle().IndentSpacing, false))
{
// Refresh the database size and message count every 5 seconds to avoid
// constant stat calls and spamming the database.
if (DatabaseLastRefreshTicks + 5 * 1000 < Environment.TickCount64)
@@ -93,11 +90,11 @@ internal sealed class Database : ISettingsTab
DatabaseLastRefreshTicks = Environment.TickCount64;
}
// Copy the directory path instead of the file path so people can
// paste it into their file explorer.
ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_Path, MessageManager.DatabasePath()));
if (ImGui.IsItemClicked(ImGuiMouseButton.Left))
{
// Copy the directory path instead of the file path so people can
// paste it into their file explorer.
var path = Path.GetDirectoryName(MessageManager.DatabasePath());
ImGui.SetClipboardText(path);
WrapperUtil.AddNotification(Language.Options_Database_Metadata_CopyConfigPathNotification, NotificationType.Info);
@@ -130,22 +127,25 @@ internal sealed class Database : ISettingsTab
DatabaseLastRefreshTicks = 0;
WrapperUtil.AddNotification(Language.Options_ClearDatabase_Success, NotificationType.Info);
}
}
ImGui.Unindent(style.IndentSpacing);
ImGui.Spacing();
if (ShowAdvanced && ImGui.TreeNodeEx(Language.Options_Database_Advanced))
{
if (!ShowAdvanced)
return;
using var treeNode = ImRaii.TreeNode(Language.Options_Database_Advanced);
ImGui.PushTextWrapPos();
ImGuiUtil.WarningText(Language.Options_Database_Advanced_Warning);
if (ImGuiUtil.CtrlShiftButton("Perform maintenance", "Ctrl+Shift: MessageManager.Store.PerformMaintenance()"))
Plugin.MessageManager.Store.PerformMaintenance();
if (ImGuiUtil.CtrlShiftButton("Reload messages from database",
"Ctrl+Shift: MessageManager.FilterAllTabs(false)")) {
if (ImGuiUtil.CtrlShiftButton("Reload messages from database", "Ctrl+Shift: MessageManager.FilterAllTabs(false)"))
{
foreach (var tab in Plugin.Config.Tabs)
tab.Clear();
Plugin.MessageManager.FilterAllTabs(false);
}
@@ -153,13 +153,11 @@ internal sealed class Database : ISettingsTab
new Thread(() => InsertMessages(10_000)).Start();
ImGui.PopTextWrapPos();
ImGui.TreePop();
}
ImGui.Spacing();
}
private void InsertMessages(int count) {
private void InsertMessages(int count)
{
Plugin.Log.Info($"Inserting {count} messages due to user request");
// Generate
@@ -175,7 +173,8 @@ internal sealed class Database : ISettingsTab
.Build();
var senderChunks = ChunkUtil.ToChunks(senderSource, ChunkSource.Sender, ChatType.Debug).ToList();
var messages = new List<Message>(count);
for (var i = 0; i < count; i++) {
for (var i = 0; i < count; i++)
{
var contentSource = new SeStringBuilder()
.AddText("Random message payload - ")
.AddItalics(Guid.NewGuid().ToString())
@@ -203,28 +202,28 @@ internal sealed class Database : ISettingsTab
// Insert
stopwatch = Stopwatch.StartNew();
foreach (var message in messages) {
foreach (var message in messages)
Plugin.MessageManager.Store.UpsertMessage(message);
}
elapsedTicks = stopwatch.ElapsedTicks;
stopwatch.Stop();
Plugin.Log.Info($"Upserted {count} messages in {elapsedTicks} ticks ({elapsedTicks / TimeSpan.TicksPerMillisecond}ms)");
// Clear tabs during framework frame
Plugin.Framework.Run(() => {
Plugin.Framework.Run(() =>
{
stopwatch = Stopwatch.StartNew();
foreach (var tab in Plugin.Config.Tabs)
tab.Clear();
elapsedTicks = stopwatch.ElapsedTicks;
stopwatch.Stop();
Plugin.Log.Info(
$"Cleared {Plugin.Config.Tabs.Count} tabs in {elapsedTicks} ticks ({elapsedTicks / TimeSpan.TicksPerMillisecond}ms)");
Plugin.Log.Info($"Cleared {Plugin.Config.Tabs.Count} tabs in {elapsedTicks} ticks ({elapsedTicks / TimeSpan.TicksPerMillisecond}ms)");
}).Wait();
// Fetch and filter during framework frame
Plugin.Framework.Run(() => {
Plugin.Framework.Run(() =>
{
stopwatch = Stopwatch.StartNew();
Plugin.MessageManager.FilterAllTabs(false);
elapsedTicks = stopwatch.ElapsedTicks;
+27 -49
View File
@@ -1,20 +1,24 @@
using ChatTwo.Resources;
using ChatTwo.Util;
using Dalamud.Interface.Style;
using Dalamud.Interface.Utility.Raii;
using ImGuiNET;
namespace ChatTwo.Ui.SettingsTabs;
internal sealed class Display : ISettingsTab {
internal sealed class Display : ISettingsTab
{
private Configuration Mutable { get; }
public string Name => Language.Options_Display_Tab + "###tabs-display";
internal Display(Configuration mutable) {
internal Display(Configuration mutable)
{
Mutable = mutable;
}
public void Draw(bool changed) {
public void Draw(bool changed)
{
ImGui.PushTextWrapPos();
ImGuiUtil.OptionCheckbox(ref Mutable.PlaySounds, Language.Options_PlaySounds_Name, Language.Options_PlaySounds_Description);
@@ -23,56 +27,33 @@ internal sealed class Display : ISettingsTab {
ImGuiUtil.OptionCheckbox(ref Mutable.HideChat, Language.Options_HideChat_Name, Language.Options_HideChat_Description);
ImGui.Spacing();
ImGuiUtil.OptionCheckbox(
ref Mutable.HideDuringCutscenes,
Language.Options_HideDuringCutscenes_Name,
string.Format(Language.Options_HideDuringCutscenes_Description, Plugin.PluginName)
);
ImGuiUtil.OptionCheckbox(ref Mutable.HideDuringCutscenes, Language.Options_HideDuringCutscenes_Name, string.Format(Language.Options_HideDuringCutscenes_Description, Plugin.PluginName));
ImGui.Spacing();
ImGuiUtil.OptionCheckbox(
ref Mutable.HideWhenNotLoggedIn,
Language.Options_HideWhenNotLoggedIn_Name,
string.Format(Language.Options_HideWhenNotLoggedIn_Description, Plugin.PluginName)
);
ImGuiUtil.OptionCheckbox(ref Mutable.HideWhenNotLoggedIn, Language.Options_HideWhenNotLoggedIn_Name, string.Format(Language.Options_HideWhenNotLoggedIn_Description, Plugin.PluginName));
ImGui.Spacing();
ImGuiUtil.OptionCheckbox(
ref Mutable.HideWhenUiHidden,
Language.Options_HideWhenUiHidden_Name,
string.Format(Language.Options_HideWhenUiHidden_Description, Plugin.PluginName)
);
ImGuiUtil.OptionCheckbox(ref Mutable.HideWhenUiHidden, Language.Options_HideWhenUiHidden_Name, string.Format(Language.Options_HideWhenUiHidden_Description, Plugin.PluginName));
ImGui.Spacing();
ImGuiUtil.OptionCheckbox(
ref Mutable.HideInLoadingScreens,
Language.Options_HideInLoadingScreens_Name,
string.Format(Language.Options_HideInLoadingScreens_Description, Plugin.PluginName));
ImGuiUtil.OptionCheckbox(ref Mutable.HideInLoadingScreens, Language.Options_HideInLoadingScreens_Name, string.Format(Language.Options_HideInLoadingScreens_Description, Plugin.PluginName));
ImGui.Spacing();
ImGuiUtil.OptionCheckbox(
ref Mutable.NativeItemTooltips,
Language.Options_NativeItemTooltips_Name,
string.Format(Language.Options_NativeItemTooltips_Description, Plugin.PluginName)
);
ImGuiUtil.OptionCheckbox(ref Mutable.NativeItemTooltips, Language.Options_NativeItemTooltips_Name, string.Format(Language.Options_NativeItemTooltips_Description, Plugin.PluginName));
ImGui.Spacing();
ImGuiUtil.OptionCheckbox(
ref Mutable.SidebarTabView,
Language.Options_SidebarTabView_Name,
string.Format(Language.Options_SidebarTabView_Description, Plugin.PluginName)
);
ImGuiUtil.OptionCheckbox(ref Mutable.SidebarTabView, Language.Options_SidebarTabView_Name, string.Format(Language.Options_SidebarTabView_Description, Plugin.PluginName));
ImGui.Spacing();
ImGuiUtil.OptionCheckbox(ref Mutable.PrettierTimestamps, Language.Options_PrettierTimestamps_Name, Language.Options_PrettierTimestamps_Description);
if (Mutable.PrettierTimestamps) {
if (Mutable.PrettierTimestamps)
{
ImGui.TreePush();
ImGuiUtil.OptionCheckbox(ref Mutable.MoreCompactPretty, Language.Options_MoreCompactPretty_Name, Language.Options_MoreCompactPretty_Description);
ImGuiUtil.OptionCheckbox(ref Mutable.HideSameTimestamps, Language.Options_HideSameTimestamps_Name, Language.Options_HideSameTimestamps_Description);
ImGui.TreePop();
}
ImGui.Spacing();
ImGuiUtil.OptionCheckbox(ref Mutable.CollapseDuplicateMessages, Language.Options_CollapseDuplicateMessages_Name, Language.Options_CollapseDuplicateMessages_Description);
@@ -106,29 +87,26 @@ internal sealed class Display : ISettingsTab {
ImGuiUtil.OptionCheckbox(ref Mutable.OverrideStyle, Language.Options_OverrideStyle_Name, Language.Options_OverrideStyle_Name_Desc);
ImGui.Spacing();
ImGui.PopTextWrapPos();
if (!Mutable.OverrideStyle)
return;
if (Mutable.OverrideStyle)
{
var styles = StyleModel.GetConfiguredStyles();
if (styles != null)
if (styles == null)
{
ImGui.TextUnformatted(Language.Options_OverrideStyle_NotAvailable);
ImGui.Spacing();
return;
}
var currentStyle = Mutable.ChosenStyle ?? Language.Options_OverrideStyle_NotSelected;
if (ImGui.BeginCombo(Language.Options_OverrideStyleDropdown_Name, currentStyle))
{
using var combo = ImRaii.Combo(Language.Options_OverrideStyleDropdown_Name, currentStyle);
if (combo)
foreach (var style in styles)
if (ImGui.Selectable(style.Name, Mutable.ChosenStyle == style.Name))
Mutable.ChosenStyle = style.Name;
ImGui.EndCombo();
}
}
else
{
ImGui.TextUnformatted(Language.Options_OverrideStyle_NotAvailable);
}
}
ImGui.Spacing();
ImGui.PopTextWrapPos();
}
}
+36 -34
View File
@@ -4,56 +4,59 @@ using ImGuiNET;
namespace ChatTwo.Ui.SettingsTabs;
public class Fonts : ISettingsTab {
public class Fonts : ISettingsTab
{
private Configuration Mutable { get; }
public string Name => Language.Options_Fonts_Tab + "###tabs-fonts";
private List<string> GlobalFonts { get; set; } = new();
private List<string> JpFonts { get; set; } = new();
private List<string> GlobalFonts { get; set; } = [];
private List<string> JpFonts { get; set; } = [];
internal Fonts(Configuration mutable) {
internal Fonts(Configuration mutable)
{
Mutable = mutable;
UpdateFonts();
}
private void UpdateFonts() {
private void UpdateFonts()
{
GlobalFonts = Ui.Fonts.GetFonts();
JpFonts = Ui.Fonts.GetJpFonts();
}
public void Draw(bool changed) {
if (changed) {
public void Draw(bool changed)
{
if (changed)
UpdateFonts();
}
ImGui.PushTextWrapPos();
ImGui.Checkbox(Language.Options_FontsEnabled, ref Mutable.FontsEnabled);
ImGui.Spacing();
if (Mutable.FontsEnabled) {
if (ImGuiUtil.BeginComboVertical(Language.Options_Font_Name, Mutable.GlobalFont)) {
foreach (var font in Ui.Fonts.GlobalFonts) {
if (ImGui.Selectable(font.Name, Mutable.GlobalFont == font.Name)) {
if (Mutable.FontsEnabled)
{
if (ImGuiUtil.BeginComboVertical(Language.Options_Font_Name, Mutable.GlobalFont))
{
foreach (var font in Ui.Fonts.GlobalFonts)
{
if (ImGui.Selectable(font.Name, Mutable.GlobalFont == font.Name))
Mutable.GlobalFont = font.Name;
}
if (ImGui.IsWindowAppearing() && Mutable.GlobalFont == font.Name) {
if (ImGui.IsWindowAppearing() && Mutable.GlobalFont == font.Name)
ImGui.SetScrollHereY(0.5f);
}
}
ImGui.Separator();
foreach (var name in GlobalFonts) {
if (ImGui.Selectable(name, Mutable.GlobalFont == name)) {
foreach (var name in GlobalFonts)
{
if (ImGui.Selectable(name, Mutable.GlobalFont == name))
Mutable.GlobalFont = name;
}
if (ImGui.IsWindowAppearing() && Mutable.GlobalFont == name) {
if (ImGui.IsWindowAppearing() && Mutable.GlobalFont == name)
ImGui.SetScrollHereY(0.5f);
}
}
ImGui.EndCombo();
}
@@ -62,28 +65,27 @@ public class Fonts : ISettingsTab {
ImGuiUtil.WarningText(Language.Options_Font_Warning);
ImGui.Spacing();
if (ImGuiUtil.BeginComboVertical(Language.Options_JapaneseFont_Name, Mutable.JapaneseFont)) {
foreach (var (name, _) in Ui.Fonts.JapaneseFonts) {
if (ImGui.Selectable(name, Mutable.JapaneseFont == name)) {
if (ImGuiUtil.BeginComboVertical(Language.Options_JapaneseFont_Name, Mutable.JapaneseFont))
{
foreach (var (name, _) in Ui.Fonts.JapaneseFonts)
{
if (ImGui.Selectable(name, Mutable.JapaneseFont == name))
Mutable.JapaneseFont = name;
}
if (ImGui.IsWindowAppearing() && Mutable.JapaneseFont == name) {
if (ImGui.IsWindowAppearing() && Mutable.JapaneseFont == name)
ImGui.SetScrollHereY(0.5f);
}
}
ImGui.Separator();
foreach (var family in JpFonts) {
if (ImGui.Selectable(family, Mutable.JapaneseFont == family)) {
foreach (var family in JpFonts)
{
if (ImGui.Selectable(family, Mutable.JapaneseFont == family))
Mutable.JapaneseFont = family;
}
if (ImGui.IsWindowAppearing() && Mutable.JapaneseFont == family) {
if (ImGui.IsWindowAppearing() && Mutable.JapaneseFont == family)
ImGui.SetScrollHereY(0.5f);
}
}
ImGui.EndCombo();
}
@@ -91,13 +93,13 @@ public class Fonts : ISettingsTab {
ImGuiUtil.HelpText(string.Format(Language.Options_JapaneseFont_Description, Plugin.PluginName));
ImGui.Spacing();
if (ImGui.CollapsingHeader(Language.Options_ExtraGlyphs_Name)) {
if (ImGui.CollapsingHeader(Language.Options_ExtraGlyphs_Name))
{
ImGuiUtil.HelpText(string.Format(Language.Options_ExtraGlyphs_Description, Plugin.PluginName));
var range = (int) Mutable.ExtraGlyphRanges;
foreach (var extra in Enum.GetValues<ExtraGlyphRanges>()) {
foreach (var extra in Enum.GetValues<ExtraGlyphRanges>())
ImGui.CheckboxFlags(extra.Name(), ref range, (int) extra);
}
Mutable.ExtraGlyphRanges = (ExtraGlyphRanges) range;
}
+2 -1
View File
@@ -1,6 +1,7 @@
namespace ChatTwo.Ui.SettingsTabs;
internal interface ISettingsTab {
internal interface ISettingsTab
{
string Name { get; }
void Draw(bool changed);
}
+20 -28
View File
@@ -4,22 +4,18 @@ using ImGuiNET;
namespace ChatTwo.Ui.SettingsTabs;
internal sealed class Miscellaneous : ISettingsTab {
private Configuration Mutable { get; }
internal sealed class Miscellaneous(Configuration mutable) : ISettingsTab
{
private Configuration Mutable { get; } = mutable;
public string Name => Language.Options_Miscellaneous_Tab + "###tabs-miscellaneous";
public Miscellaneous(Configuration mutable) {
Mutable = mutable;
}
public void Draw(bool changed) {
if (ImGuiUtil.BeginComboVertical(Language.Options_Language_Name, Mutable.LanguageOverride.Name())) {
foreach (var language in Enum.GetValues<LanguageOverride>()) {
if (ImGui.Selectable(language.Name())) {
public void Draw(bool changed)
{
if (ImGuiUtil.BeginComboVertical(Language.Options_Language_Name, Mutable.LanguageOverride.Name()))
{
foreach (var language in Enum.GetValues<LanguageOverride>())
if (ImGui.Selectable(language.Name()))
Mutable.LanguageOverride = language;
}
}
ImGui.EndCombo();
}
@@ -27,12 +23,11 @@ internal sealed class Miscellaneous : ISettingsTab {
ImGuiUtil.HelpText(string.Format(Language.Options_Language_Description, Plugin.PluginName));
ImGui.Spacing();
if (ImGuiUtil.BeginComboVertical(Language.Options_CommandHelpSide_Name, Mutable.CommandHelpSide.Name())) {
foreach (var side in Enum.GetValues<CommandHelpSide>()) {
if (ImGui.Selectable(side.Name(), Mutable.CommandHelpSide == side)) {
if (ImGuiUtil.BeginComboVertical(Language.Options_CommandHelpSide_Name, Mutable.CommandHelpSide.Name()))
{
foreach (var side in Enum.GetValues<CommandHelpSide>())
if (ImGui.Selectable(side.Name(), Mutable.CommandHelpSide == side))
Mutable.CommandHelpSide = side;
}
}
ImGui.EndCombo();
}
@@ -40,17 +35,15 @@ internal sealed class Miscellaneous : ISettingsTab {
ImGuiUtil.HelpText(string.Format(Language.Options_CommandHelpSide_Description, Plugin.PluginName));
ImGui.Spacing();
if (ImGuiUtil.BeginComboVertical(Language.Options_KeybindMode_Name, Mutable.KeybindMode.Name())) {
foreach (var mode in Enum.GetValues<KeybindMode>()) {
if (ImGui.Selectable(mode.Name(), Mutable.KeybindMode == mode)) {
if (ImGuiUtil.BeginComboVertical(Language.Options_KeybindMode_Name, Mutable.KeybindMode.Name()))
{
foreach (var mode in Enum.GetValues<KeybindMode>())
{
if (ImGui.Selectable(mode.Name(), Mutable.KeybindMode == mode))
Mutable.KeybindMode = mode;
}
if (ImGui.IsItemHovered()) {
ImGui.BeginTooltip();
ImGui.TextUnformatted(mode.Tooltip());
ImGui.EndTooltip();
}
if (ImGui.IsItemHovered())
ImGui.SetTooltip(mode.Tooltip());
}
ImGui.EndCombo();
@@ -61,7 +54,6 @@ internal sealed class Miscellaneous : ISettingsTab {
ImGui.Checkbox(Language.Options_SortAutoTranslate_Name, ref Mutable.SortAutoTranslate);
ImGuiUtil.HelpText(Language.Options_SortAutoTranslate_Description);
ImGui.Spacing();
}
}
+104 -104
View File
@@ -2,11 +2,13 @@ using ChatTwo.Code;
using ChatTwo.Resources;
using ChatTwo.Util;
using Dalamud.Interface;
using Dalamud.Interface.Utility.Raii;
using ImGuiNET;
namespace ChatTwo.Ui.SettingsTabs;
internal sealed class Tabs : ISettingsTab {
internal sealed class Tabs : ISettingsTab
{
private Plugin Plugin { get; }
private Configuration Mutable { get; }
@@ -14,63 +16,69 @@ internal sealed class Tabs : ISettingsTab {
private int _toOpen = -2;
internal Tabs(Plugin plugin, Configuration mutable) {
internal Tabs(Plugin plugin, Configuration mutable)
{
Plugin = plugin;
Mutable = mutable;
}
public void Draw(bool changed) {
public void Draw(bool changed)
{
const string addTabPopup = "add-tab-popup";
if (ImGuiUtil.IconButton(FontAwesomeIcon.Plus, tooltip: Language.Options_Tabs_Add)) {
if (ImGuiUtil.IconButton(FontAwesomeIcon.Plus, tooltip: Language.Options_Tabs_Add))
ImGui.OpenPopup(addTabPopup);
}
if (ImGui.BeginPopup(addTabPopup)) {
if (ImGui.Selectable(Language.Options_Tabs_NewTab)) {
using (var popup = ImRaii.Popup(addTabPopup))
{
if (popup)
{
if (ImGui.Selectable(Language.Options_Tabs_NewTab))
Mutable.Tabs.Add(new Tab());
}
ImGui.Separator();
if (ImGui.Selectable(string.Format(Language.Options_Tabs_Preset, Language.Tabs_Presets_General))) {
if (ImGui.Selectable(string.Format(Language.Options_Tabs_Preset, Language.Tabs_Presets_General)))
Mutable.Tabs.Add(TabsUtil.VanillaGeneral);
}
if (ImGui.Selectable(string.Format(Language.Options_Tabs_Preset, Language.Tabs_Presets_Event))) {
if (ImGui.Selectable(string.Format(Language.Options_Tabs_Preset, Language.Tabs_Presets_Event)))
Mutable.Tabs.Add(TabsUtil.VanillaEvent);
}
ImGui.EndPopup();
}
var toRemove = -1;
var doOpens = _toOpen > -2;
for (var i = 0; i < Mutable.Tabs.Count; i++) {
for (var i = 0; i < Mutable.Tabs.Count; i++)
{
var tab = Mutable.Tabs[i];
if (doOpens) {
if (doOpens)
ImGui.SetNextItemOpen(i == _toOpen);
}
if (ImGui.TreeNodeEx($"{tab.Name}###tab-{i}")) {
ImGui.PushID($"tab-{i}");
using var treeNode = ImRaii.TreeNode($"{tab.Name}###tab-{i}");
if (!treeNode.Success)
continue;
if (ImGuiUtil.IconButton(FontAwesomeIcon.TrashAlt, tooltip: Language.Options_Tabs_Delete)) {
using var pushedId = ImRaii.PushId($"tab-{i}");
if (ImGuiUtil.IconButton(FontAwesomeIcon.TrashAlt, tooltip: Language.Options_Tabs_Delete))
{
toRemove = i;
_toOpen = -1;
}
ImGui.SameLine();
if (ImGuiUtil.IconButton(FontAwesomeIcon.ArrowUp, tooltip: Language.Options_Tabs_MoveUp) && i > 0) {
if (ImGuiUtil.IconButton(FontAwesomeIcon.ArrowUp, tooltip: Language.Options_Tabs_MoveUp) && i > 0)
{
(Mutable.Tabs[i - 1], Mutable.Tabs[i]) = (Mutable.Tabs[i], Mutable.Tabs[i - 1]);
_toOpen = i - 1;
}
ImGui.SameLine();
if (ImGuiUtil.IconButton(FontAwesomeIcon.ArrowDown, tooltip: Language.Options_Tabs_MoveDown) && i < Mutable.Tabs.Count - 1) {
if (ImGuiUtil.IconButton(FontAwesomeIcon.ArrowDown, tooltip: Language.Options_Tabs_MoveDown) && i < Mutable.Tabs.Count - 1)
{
(Mutable.Tabs[i + 1], Mutable.Tabs[i]) = (Mutable.Tabs[i], Mutable.Tabs[i + 1]);
_toOpen = i + 1;
}
@@ -78,129 +86,121 @@ internal sealed class Tabs : ISettingsTab {
ImGui.InputText(Language.Options_Tabs_Name, ref tab.Name, 512, ImGuiInputTextFlags.EnterReturnsTrue);
ImGui.Checkbox(Language.Options_Tabs_ShowTimestamps, ref tab.DisplayTimestamp);
ImGui.Checkbox(Language.Options_Tabs_PopOut, ref tab.PopOut);
if (tab.PopOut) {
if (tab.PopOut)
{
ImGui.Checkbox(Language.Options_Tabs_IndependentOpacity, ref tab.IndependentOpacity);
if (tab.IndependentOpacity) {
if (tab.IndependentOpacity)
ImGuiUtil.DragFloatVertical(Language.Options_Tabs_Opacity, ref tab.Opacity, 0.25f, 0f, 100f, $"{tab.Opacity:N2}%%", ImGuiSliderFlags.AlwaysClamp);
}
}
if (ImGuiUtil.BeginComboVertical(Language.Options_Tabs_UnreadMode, tab.UnreadMode.Name())) {
foreach (var mode in Enum.GetValues<UnreadMode>()) {
if (ImGui.Selectable(mode.Name(), tab.UnreadMode == mode)) {
if (ImGuiUtil.BeginComboVertical(Language.Options_Tabs_UnreadMode, tab.UnreadMode.Name()))
{
foreach (var mode in Enum.GetValues<UnreadMode>())
{
if (ImGui.Selectable(mode.Name(), tab.UnreadMode == mode))
tab.UnreadMode = mode;
}
if (mode.Tooltip() is { } tooltip && ImGui.IsItemHovered()) {
ImGui.BeginTooltip();
ImGui.TextUnformatted(tooltip);
ImGui.EndTooltip();
}
if (mode.Tooltip() is { } tooltip && ImGui.IsItemHovered())
ImGui.SetTooltip(tooltip);
}
ImGui.EndCombo();
}
var input = tab.Channel?.ToChatType().Name() ?? Language.Options_Tabs_NoInputChannel;
if (ImGuiUtil.BeginComboVertical(Language.Options_Tabs_InputChannel, input)) {
if (ImGui.Selectable(Language.Options_Tabs_NoInputChannel, tab.Channel == null)) {
if (ImGuiUtil.BeginComboVertical(Language.Options_Tabs_InputChannel, input))
{
if (ImGui.Selectable(Language.Options_Tabs_NoInputChannel, tab.Channel == null))
tab.Channel = null;
}
foreach (var channel in Enum.GetValues<InputChannel>()) {
if (ImGui.Selectable(channel.ToChatType().Name(), tab.Channel == channel)) {
foreach (var channel in Enum.GetValues<InputChannel>())
if (ImGui.Selectable(channel.ToChatType().Name(), tab.Channel == channel))
tab.Channel = channel;
}
}
ImGui.EndCombo();
}
if (ImGui.TreeNodeEx(Language.Options_Tabs_Channels)) {
foreach (var (header, types) in ChatTypeExt.SortOrder) {
if (ImGui.TreeNodeEx(header + $"##{i}")) {
foreach (var type in types) {
if (type.IsGm()) {
using (var channelNode = ImRaii.TreeNode(Language.Options_Tabs_Channels))
{
if (channelNode)
{
foreach (var (header, types) in ChatTypeExt.SortOrder)
{
using var headerNode = ImRaii.TreeNode(header + $"##{i}");
if (!headerNode.Success)
continue;
foreach (var type in types)
{
if (type.IsGm())
continue;
}
var enabled = tab.ChatCodes.ContainsKey(type);
if (ImGui.Checkbox($"##{type.Name()}-{i}", ref enabled)) {
if (enabled) {
if (ImGui.Checkbox($"##{type.Name()}-{i}", ref enabled))
{
if (enabled)
tab.ChatCodes[type] = ChatSourceExt.All;
} else {
else
tab.ChatCodes.Remove(type);
}
}
ImGui.SameLine();
if (type.HasSource()) {
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.Name(), ref sources, (uint) source)) {
tab.ChatCodes[type] = (ChatSource) sources;
}
}
ImGui.TreePop();
}
} else {
if (!type.HasSource())
{
ImGui.TextUnformatted(type.Name());
}
}
ImGui.TreePop();
}
}
ImGui.TreePop();
}
if (Plugin.ExtraChat.ChannelNames.Count > 0 && ImGui.TreeNodeEx(Language.Options_Tabs_ExtraChatChannels)) {
ImGui.Checkbox(Language.Options_Tabs_ExtraChatAll, ref tab.ExtraChatAll);
ImGui.Separator();
if (tab.ExtraChatAll) {
ImGui.BeginDisabled();
}
foreach (var (id, name) in Plugin.ExtraChat.ChannelNames) {
var enabled = tab.ExtraChatChannels.Contains(id);
if (!ImGui.Checkbox($"{name}##ec-{id}", ref enabled)) {
continue;
}
if (enabled) {
tab.ExtraChatChannels.Add(id);
} else {
tab.ExtraChatChannels.Remove(id);
using var typeNode = ImRaii.TreeNode($"{type.Name()}##{i}");
if (!typeNode.Success)
continue;
tab.ChatCodes.TryGetValue(type, out var sourcesEnum);
var sources = (uint) sourcesEnum;
foreach (var source in Enum.GetValues<ChatSource>())
if (ImGui.CheckboxFlags(source.Name(), ref sources, (uint) source))
tab.ChatCodes[type] = (ChatSource) sources;
}
}
}
}
if (tab.ExtraChatAll) {
if (Plugin.ExtraChat.ChannelNames.Count <= 0)
continue;
using var extraTree = ImRaii.TreeNode(Language.Options_Tabs_ExtraChatChannels);
if (!extraTree.Success)
continue;
ImGui.Checkbox(Language.Options_Tabs_ExtraChatAll, ref tab.ExtraChatAll);
ImGui.Separator();
if (tab.ExtraChatAll)
ImGui.BeginDisabled();
foreach (var (id, name) in Plugin.ExtraChat.ChannelNames)
{
var enabled = tab.ExtraChatChannels.Contains(id);
if (!ImGui.Checkbox($"{name}##ec-{id}", ref enabled))
continue;
if (enabled)
tab.ExtraChatChannels.Add(id);
else
tab.ExtraChatChannels.Remove(id);
}
if (tab.ExtraChatAll)
ImGui.EndDisabled();
}
ImGui.TreePop();
}
ImGui.TreePop();
ImGui.PopID();
}
}
if (toRemove > -1) {
if (toRemove > -1)
Mutable.Tabs.RemoveAt(toRemove);
}
if (doOpens) {
if (doOpens)
_toOpen = -2;
}
}
}
-5
View File
@@ -1,5 +0,0 @@
namespace ChatTwo.Ui;
internal interface IUiComponent : IDisposable {
void Draw();
}