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
+31 -53
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)
if (!Mutable.OverrideStyle)
return;
var styles = StyleModel.GetConfiguredStyles();
if (styles == null)
{
var styles = StyleModel.GetConfiguredStyles();
if (styles != null)
{
var currentStyle = Mutable.ChosenStyle ?? Language.Options_OverrideStyle_NotSelected;
if (ImGui.BeginCombo(Language.Options_OverrideStyleDropdown_Name, currentStyle))
{
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.TextUnformatted(Language.Options_OverrideStyle_NotAvailable);
ImGui.Spacing();
return;
}
var currentStyle = Mutable.ChosenStyle ?? Language.Options_OverrideStyle_NotSelected;
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.Spacing();
ImGui.PopTextWrapPos();
}
}