diff --git a/.editorconfig b/.editorconfig index 6724ee4..4c3ba4a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -33,11 +33,17 @@ dotnet_naming_rule.private_instance_fields_rule.resharper_guid=4a98fdf6-7d98-4f5 dotnet_naming_rule.private_instance_fields_rule.severity=warning dotnet_naming_rule.private_instance_fields_rule.style=upper_camel_case_style dotnet_naming_rule.private_instance_fields_rule.symbols=private_instance_fields_symbols +dotnet_naming_rule.private_instance_fields_rule_1.import_to_resharper=True +dotnet_naming_rule.private_instance_fields_rule_1.resharper_description=Instance fields (private) +dotnet_naming_rule.private_instance_fields_rule_1.resharper_guid=4a98fdf6-7d98-4f5a-afeb-ea44ad98c70c +dotnet_naming_rule.private_instance_fields_rule_1.severity=warning +dotnet_naming_rule.private_instance_fields_rule_1.style=upper_camel_case_style +dotnet_naming_rule.private_instance_fields_rule_1.symbols=private_instance_fields_symbols_1 dotnet_naming_rule.private_static_fields_rule.import_to_resharper=True dotnet_naming_rule.private_static_fields_rule.resharper_description=Static fields (private) dotnet_naming_rule.private_static_fields_rule.resharper_guid=f9fce829-e6f4-4cb2-80f1-5497c44f51df dotnet_naming_rule.private_static_fields_rule.severity=warning -dotnet_naming_rule.private_static_fields_rule.style=lower_camel_case_style +dotnet_naming_rule.private_static_fields_rule.style=upper_camel_case_style dotnet_naming_rule.private_static_fields_rule.symbols=private_static_fields_symbols dotnet_naming_rule.private_static_readonly_rule.import_to_resharper=True dotnet_naming_rule.private_static_readonly_rule.resharper_description=Static readonly fields (private) @@ -51,6 +57,12 @@ dotnet_naming_rule.unity_serialized_field_rule.resharper_guid=5f0fdb63-c892-4d2c dotnet_naming_rule.unity_serialized_field_rule.severity=warning dotnet_naming_rule.unity_serialized_field_rule.style=lower_camel_case_style_1 dotnet_naming_rule.unity_serialized_field_rule.symbols=unity_serialized_field_symbols +dotnet_naming_rule.unity_serialized_field_rule_1.import_to_resharper=True +dotnet_naming_rule.unity_serialized_field_rule_1.resharper_description=Unity serialized field +dotnet_naming_rule.unity_serialized_field_rule_1.resharper_guid=5f0fdb63-c892-4d2c-9324-15c80b22a7ef +dotnet_naming_rule.unity_serialized_field_rule_1.severity=warning +dotnet_naming_rule.unity_serialized_field_rule_1.style=lower_camel_case_style_1 +dotnet_naming_rule.unity_serialized_field_rule_1.symbols=unity_serialized_field_symbols_1 dotnet_naming_style.lower_camel_case_style.capitalization=camel_case dotnet_naming_style.lower_camel_case_style.required_prefix=_ dotnet_naming_style.lower_camel_case_style_1.capitalization=camel_case @@ -64,6 +76,10 @@ dotnet_naming_symbols.private_instance_fields_symbols.applicable_accessibilities dotnet_naming_symbols.private_instance_fields_symbols.applicable_kinds=field dotnet_naming_symbols.private_instance_fields_symbols.resharper_applicable_kinds=field,readonly_field dotnet_naming_symbols.private_instance_fields_symbols.resharper_required_modifiers=instance +dotnet_naming_symbols.private_instance_fields_symbols_1.applicable_accessibilities=private +dotnet_naming_symbols.private_instance_fields_symbols_1.applicable_kinds=field +dotnet_naming_symbols.private_instance_fields_symbols_1.resharper_applicable_kinds=field,readonly_field +dotnet_naming_symbols.private_instance_fields_symbols_1.resharper_required_modifiers=instance dotnet_naming_symbols.private_static_fields_symbols.applicable_accessibilities=private dotnet_naming_symbols.private_static_fields_symbols.applicable_kinds=field dotnet_naming_symbols.private_static_fields_symbols.required_modifiers=static @@ -78,6 +94,10 @@ dotnet_naming_symbols.unity_serialized_field_symbols.applicable_accessibilities= dotnet_naming_symbols.unity_serialized_field_symbols.applicable_kinds= dotnet_naming_symbols.unity_serialized_field_symbols.resharper_applicable_kinds=unity_serialised_field dotnet_naming_symbols.unity_serialized_field_symbols.resharper_required_modifiers=instance +dotnet_naming_symbols.unity_serialized_field_symbols_1.applicable_accessibilities=* +dotnet_naming_symbols.unity_serialized_field_symbols_1.applicable_kinds= +dotnet_naming_symbols.unity_serialized_field_symbols_1.resharper_applicable_kinds=unity_serialised_field +dotnet_naming_symbols.unity_serialized_field_symbols_1.resharper_required_modifiers=instance dotnet_style_parentheses_in_arithmetic_binary_operators=never_if_unnecessary:none dotnet_style_parentheses_in_other_binary_operators=always_for_clarity:none dotnet_style_parentheses_in_relational_binary_operators=never_if_unnecessary:none @@ -91,6 +111,7 @@ dotnet_style_require_accessibility_modifiers=for_non_interface_members:suggestio # ReSharper properties resharper_autodetect_indent_settings=true +resharper_cpp_insert_final_newline=true resharper_csharp_insert_final_newline=false resharper_formatter_off_tag=@formatter:off resharper_formatter_on_tag=@formatter:on @@ -99,7 +120,7 @@ resharper_fsharp_insert_final_newline=false resharper_html_insert_final_newline=false resharper_resx_insert_final_newline=false resharper_shaderlab_insert_final_newline=false -resharper_T4_insert_final_newline=false +resharper_t4_insert_final_newline=false resharper_use_indent_from_vs=false resharper_vb_insert_final_newline=false resharper_xmldoc_insert_final_newline=false diff --git a/ChatTwo/Ui/SettingsTabs/Fonts.cs b/ChatTwo/Ui/SettingsTabs/Fonts.cs index f2f2954..3294e4f 100755 --- a/ChatTwo/Ui/SettingsTabs/Fonts.cs +++ b/ChatTwo/Ui/SettingsTabs/Fonts.cs @@ -36,58 +36,60 @@ public class Fonts : ISettingsTab if (Mutable.FontsEnabled) { - if (ImGuiUtil.BeginComboVertical(Language.Options_Font_Name, Mutable.GlobalFont)) + using (var combo = ImGuiUtil.BeginComboVertical(Language.Options_Font_Name, Mutable.GlobalFont)) { - foreach (var font in Ui.Fonts.GlobalFonts) + if (combo) { - if (ImGui.Selectable(font.Name, Mutable.GlobalFont == font.Name)) - Mutable.GlobalFont = font.Name; + 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) - ImGui.SetScrollHereY(0.5f); + 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)) + Mutable.GlobalFont = name; + + if (ImGui.IsWindowAppearing() && Mutable.GlobalFont == name) + ImGui.SetScrollHereY(0.5f); + } } - - ImGui.Separator(); - - foreach (var name in GlobalFonts) - { - if (ImGui.Selectable(name, Mutable.GlobalFont == name)) - Mutable.GlobalFont = name; - - if (ImGui.IsWindowAppearing() && Mutable.GlobalFont == name) - ImGui.SetScrollHereY(0.5f); - } - - ImGui.EndCombo(); } ImGuiUtil.HelpText(string.Format(Language.Options_Font_Description, Plugin.PluginName)); ImGuiUtil.WarningText(Language.Options_Font_Warning); ImGui.Spacing(); - if (ImGuiUtil.BeginComboVertical(Language.Options_JapaneseFont_Name, Mutable.JapaneseFont)) + using (var combo = ImGuiUtil.BeginComboVertical(Language.Options_JapaneseFont_Name, Mutable.JapaneseFont)) { - foreach (var (name, _) in Ui.Fonts.JapaneseFonts) + if (combo) { - if (ImGui.Selectable(name, Mutable.JapaneseFont == name)) - Mutable.JapaneseFont = name; + foreach (var (name, _) in Ui.Fonts.JapaneseFonts) + { + if (ImGui.Selectable(name, Mutable.JapaneseFont == name)) + Mutable.JapaneseFont = name; - if (ImGui.IsWindowAppearing() && Mutable.JapaneseFont == name) - ImGui.SetScrollHereY(0.5f); + if (ImGui.IsWindowAppearing() && Mutable.JapaneseFont == name) + ImGui.SetScrollHereY(0.5f); + } + + ImGui.Separator(); + + foreach (var family in JpFonts) + { + if (ImGui.Selectable(family, Mutable.JapaneseFont == family)) + Mutable.JapaneseFont = family; + + if (ImGui.IsWindowAppearing() && Mutable.JapaneseFont == family) + ImGui.SetScrollHereY(0.5f); + } } - - ImGui.Separator(); - - foreach (var family in JpFonts) - { - if (ImGui.Selectable(family, Mutable.JapaneseFont == family)) - Mutable.JapaneseFont = family; - - if (ImGui.IsWindowAppearing() && Mutable.JapaneseFont == family) - ImGui.SetScrollHereY(0.5f); - } - - ImGui.EndCombo(); } ImGuiUtil.HelpText(string.Format(Language.Options_JapaneseFont_Description, Plugin.PluginName)); diff --git a/ChatTwo/Ui/SettingsTabs/Miscellaneous.cs b/ChatTwo/Ui/SettingsTabs/Miscellaneous.cs index 848339b..2fee8d6 100755 --- a/ChatTwo/Ui/SettingsTabs/Miscellaneous.cs +++ b/ChatTwo/Ui/SettingsTabs/Miscellaneous.cs @@ -11,42 +11,45 @@ internal sealed class Miscellaneous(Configuration mutable) : ISettingsTab public void Draw(bool changed) { - if (ImGuiUtil.BeginComboVertical(Language.Options_Language_Name, Mutable.LanguageOverride.Name())) + using (var combo = ImGuiUtil.BeginComboVertical(Language.Options_Language_Name, Mutable.LanguageOverride.Name())) { - foreach (var language in Enum.GetValues()) - if (ImGui.Selectable(language.Name())) - Mutable.LanguageOverride = language; - - ImGui.EndCombo(); + if (combo) + { + foreach (var language in Enum.GetValues()) + if (ImGui.Selectable(language.Name())) + Mutable.LanguageOverride = language; + } } ImGuiUtil.HelpText(string.Format(Language.Options_Language_Description, Plugin.PluginName)); ImGui.Spacing(); - if (ImGuiUtil.BeginComboVertical(Language.Options_CommandHelpSide_Name, Mutable.CommandHelpSide.Name())) + using (var combo = ImGuiUtil.BeginComboVertical(Language.Options_CommandHelpSide_Name, Mutable.CommandHelpSide.Name())) { - foreach (var side in Enum.GetValues()) - if (ImGui.Selectable(side.Name(), Mutable.CommandHelpSide == side)) - Mutable.CommandHelpSide = side; - - ImGui.EndCombo(); + if (combo) + { + foreach (var side in Enum.GetValues()) + if (ImGui.Selectable(side.Name(), Mutable.CommandHelpSide == side)) + Mutable.CommandHelpSide = side; + } } ImGuiUtil.HelpText(string.Format(Language.Options_CommandHelpSide_Description, Plugin.PluginName)); ImGui.Spacing(); - if (ImGuiUtil.BeginComboVertical(Language.Options_KeybindMode_Name, Mutable.KeybindMode.Name())) + using (var combo = ImGuiUtil.BeginComboVertical(Language.Options_KeybindMode_Name, Mutable.KeybindMode.Name())) { - foreach (var mode in Enum.GetValues()) + if (combo) { - if (ImGui.Selectable(mode.Name(), Mutable.KeybindMode == mode)) - Mutable.KeybindMode = mode; + foreach (var mode in Enum.GetValues()) + { + if (ImGui.Selectable(mode.Name(), Mutable.KeybindMode == mode)) + Mutable.KeybindMode = mode; - if (ImGui.IsItemHovered()) - ImGui.SetTooltip(mode.Tooltip()); + if (ImGui.IsItemHovered()) + ImGui.SetTooltip(mode.Tooltip()); + } } - - ImGui.EndCombo(); } ImGuiUtil.HelpText(string.Format(Language.Options_KeybindMode_Description, Plugin.PluginName)); diff --git a/ChatTwo/Ui/SettingsTabs/Tabs.cs b/ChatTwo/Ui/SettingsTabs/Tabs.cs index 32406b2..35fbe9a 100755 --- a/ChatTwo/Ui/SettingsTabs/Tabs.cs +++ b/ChatTwo/Ui/SettingsTabs/Tabs.cs @@ -93,31 +93,33 @@ internal sealed class Tabs : ISettingsTab 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())) + using (var combo = ImGuiUtil.BeginComboVertical(Language.Options_Tabs_UnreadMode, tab.UnreadMode.Name())) { - foreach (var mode in Enum.GetValues()) + if (combo) { - if (ImGui.Selectable(mode.Name(), tab.UnreadMode == mode)) - tab.UnreadMode = mode; + foreach (var mode in Enum.GetValues()) + { + if (ImGui.Selectable(mode.Name(), tab.UnreadMode == mode)) + tab.UnreadMode = mode; - if (mode.Tooltip() is { } tooltip && ImGui.IsItemHovered()) - ImGui.SetTooltip(tooltip); + 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)) + using (var combo = ImGuiUtil.BeginComboVertical(Language.Options_Tabs_InputChannel, input)) { - if (ImGui.Selectable(Language.Options_Tabs_NoInputChannel, tab.Channel == null)) - tab.Channel = null; + if (combo) + { + if (ImGui.Selectable(Language.Options_Tabs_NoInputChannel, tab.Channel == null)) + tab.Channel = null; - foreach (var channel in Enum.GetValues()) - if (ImGui.Selectable(channel.ToChatType().Name(), tab.Channel == channel)) - tab.Channel = channel; - - ImGui.EndCombo(); + foreach (var channel in Enum.GetValues()) + if (ImGui.Selectable(channel.ToChatType().Name(), tab.Channel == channel)) + tab.Channel = channel; + } } using (var channelNode = ImRaii.TreeNode(Language.Options_Tabs_Channels)) diff --git a/ChatTwo/Util/ImGuiUtil.cs b/ChatTwo/Util/ImGuiUtil.cs index f08a8d9..6c4c0d0 100755 --- a/ChatTwo/Util/ImGuiUtil.cs +++ b/ChatTwo/Util/ImGuiUtil.cs @@ -12,7 +12,7 @@ namespace ChatTwo.Util; internal static class ImGuiUtil { - private static Plugin Plugin; + private static Plugin Plugin = null!; public static void Initialize(Plugin plugin) { @@ -26,22 +26,22 @@ internal static class ImGuiUtil ImGuiMouseButton.Right ]; - private static Payload? _hovered; - private static Payload? _lastLink; - private static readonly List<(Vector2, Vector2)> PayloadBounds = new(); + private static Payload? Hovered; + private static Payload? LastLink; + private static readonly List<(Vector2, Vector2)> PayloadBounds = []; internal static void PostPayload(Chunk chunk, PayloadHandler? handler) { var payload = chunk.Link; if (payload != null && ImGui.IsItemHovered()) { - _hovered = payload; + Hovered = payload; ImGui.SetMouseCursor(ImGuiMouseCursor.Hand); handler?.Hover(payload); } - else if (!ReferenceEquals(_hovered, payload)) + else if (!ReferenceEquals(Hovered, payload)) { - _hovered = null; + Hovered = null; } if (handler == null) @@ -61,12 +61,12 @@ internal static class ImGuiUtil ImGuiNative.igTextUnformatted(text, textEnd); PostPayload(chunk, handler); - if (!ReferenceEquals(_lastLink, chunk.Link)) + if (!ReferenceEquals(LastLink, chunk.Link)) PayloadBounds.Clear(); - _lastLink = chunk.Link; + LastLink = chunk.Link; - if (_hovered != null && ReferenceEquals(_hovered, chunk.Link)) + if (Hovered != null && ReferenceEquals(Hovered, chunk.Link)) { defaultText.W = 0.25f; var actualCol = ColourUtil.Vector4ToAbgr(defaultText); @@ -78,14 +78,14 @@ internal static class ImGuiUtil PayloadBounds.Clear(); } - if (_hovered == null && chunk.Link != null) + if (Hovered == null && chunk.Link != null) PayloadBounds.Add((oldPos, ImGui.GetItemRectSize())); } if (csText.Length == 0) return; - foreach (var part in csText.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None)) + foreach (var part in csText.Split(["\r\n", "\r", "\n"], StringSplitOptions.None)) { var bytes = Encoding.UTF8.GetBytes(part); fixed (byte* rawText = bytes) @@ -199,17 +199,11 @@ internal static class ImGuiUtil internal static void HelpText(string text) { var colour = ImGui.GetStyle().Colors[(int) ImGuiCol.TextDisabled]; - ImGui.PushStyleColor(ImGuiCol.Text, colour); - ImGui.PushTextWrapPos(); - - try + using (ImRaii.PushColor(ImGuiCol.Text, colour)) { + ImGui.PushTextWrapPos(); ImGui.TextUnformatted(text); - } - finally - { ImGui.PopTextWrapPos(); - ImGui.PopStyleColor(); } } @@ -217,22 +211,26 @@ internal static class ImGuiUtil { var style = StyleModel.GetConfiguredStyle() ?? StyleModel.GetFromCurrent(); var dalamudOrange = style.BuiltInColors?.DalamudOrange; - if (dalamudOrange != null) - ImGui.PushStyleColor(ImGuiCol.Text, dalamudOrange.Value); - if (wrap) ImGui.PushTextWrapPos(); - ImGui.TextUnformatted(text); - if (wrap) ImGui.PopTextWrapPos(); + var push = dalamudOrange != null; + var color = dalamudOrange ?? Vector4.Zero; + using (ImRaii.PushColor(ImGuiCol.Text, color, push)) + { + if (wrap) + ImGui.PushTextWrapPos(); - if (dalamudOrange != null) - ImGui.PopStyleColor(); + ImGui.TextUnformatted(text); + + if (wrap) + ImGui.PopTextWrapPos(); + } } - internal static bool BeginComboVertical(string label, string previewValue, ImGuiComboFlags flags = ImGuiComboFlags.None) + internal static ImRaii.IEndObject BeginComboVertical(string label, string previewValue, ImGuiComboFlags flags = ImGuiComboFlags.None) { ImGui.TextUnformatted(label); ImGui.SetNextItemWidth(-1); - return ImGui.BeginCombo($"##{label}", previewValue, flags); + return ImRaii.Combo($"##{label}", previewValue, flags); } internal static bool DragFloatVertical(string label, ref float value, float vSpeed = 1.0f, float vMin = float.MinValue, float vMax = float.MaxValue, string? format = null, ImGuiSliderFlags flags = ImGuiSliderFlags.None) @@ -265,13 +263,10 @@ internal static class ImGuiUtil internal static bool CtrlShiftButton(string label, string tooltip = "") { var ctrlShiftHeld = ImGui.GetIO() is { KeyCtrl: true, KeyShift: true }; - if (!ctrlShiftHeld) - ImGui.BeginDisabled(); - var ret = ImGui.Button(label) && ctrlShiftHeld; - - if (!ctrlShiftHeld) - ImGui.EndDisabled(); + bool ret; + using (ImRaii.Disabled(!ctrlShiftHeld)) + ret = ImGui.Button(label) && ctrlShiftHeld; if (!string.IsNullOrEmpty(tooltip) && ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled)) ImGui.SetTooltip(tooltip);