From c66d97829c0385b716e00ce804c30fd91eabaaf7 Mon Sep 17 00:00:00 2001 From: Infi Date: Fri, 12 Apr 2024 22:11:17 +0200 Subject: [PATCH] Just null check the styles --- ChatTwo/ChatTwo.csproj | 2 +- ChatTwo/Configuration.cs | 4 ++-- ChatTwo/Resources/Language.Designer.cs | 18 ++++++++++++++ ChatTwo/Resources/Language.resx | 6 +++++ ChatTwo/Ui/ChatLogWindow.cs | 28 ++++------------------ ChatTwo/Ui/Popout.cs | 30 +++++------------------- ChatTwo/Ui/SettingsTabs/About.cs | 1 + ChatTwo/Ui/SettingsTabs/ChatColours.cs | 2 ++ ChatTwo/Ui/SettingsTabs/Database.cs | 2 ++ ChatTwo/Ui/SettingsTabs/Display.cs | 25 +++++++++++++------- ChatTwo/Ui/SettingsTabs/Fonts.cs | 1 + ChatTwo/Ui/SettingsTabs/Miscellaneous.cs | 1 + 12 files changed, 60 insertions(+), 60 deletions(-) diff --git a/ChatTwo/ChatTwo.csproj b/ChatTwo/ChatTwo.csproj index a1b0450..f1c3804 100755 --- a/ChatTwo/ChatTwo.csproj +++ b/ChatTwo/ChatTwo.csproj @@ -1,7 +1,7 @@ - 1.20.3 + 1.20.4 net8.0-windows enable enable diff --git a/ChatTwo/Configuration.cs b/ChatTwo/Configuration.cs index 4cd9a41..5fad066 100755 --- a/ChatTwo/Configuration.cs +++ b/ChatTwo/Configuration.cs @@ -51,8 +51,8 @@ internal class Configuration : IPluginConfiguration { public Dictionary ChatColours = new(); public List Tabs = new(); - public bool OverrideStyle = false; - public string ChosenStyle = ""; + public bool OverrideStyle; + public string? ChosenStyle; public uint DatabaseMigration = LatestDbVersion; diff --git a/ChatTwo/Resources/Language.Designer.cs b/ChatTwo/Resources/Language.Designer.cs index 63cc8e5..159d556 100755 --- a/ChatTwo/Resources/Language.Designer.cs +++ b/ChatTwo/Resources/Language.Designer.cs @@ -2156,6 +2156,24 @@ namespace ChatTwo.Resources { } } + /// + /// Looks up a localized string similar to No dalamud styles available. + /// + internal static string Options_OverrideStyle_NotAvailable { + get { + return ResourceManager.GetString("Options_OverrideStyle_NotAvailable", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Not selected. + /// + internal static string Options_OverrideStyle_NotSelected { + get { + return ResourceManager.GetString("Options_OverrideStyle_NotSelected", resourceCulture); + } + } + /// /// Looks up a localized string similar to Styles. /// diff --git a/ChatTwo/Resources/Language.resx b/ChatTwo/Resources/Language.resx index f29ecc8..9cdebcb 100644 --- a/ChatTwo/Resources/Language.resx +++ b/ChatTwo/Resources/Language.resx @@ -982,4 +982,10 @@ Size: {0} + + Not selected + + + No dalamud styles available + diff --git a/ChatTwo/Ui/ChatLogWindow.cs b/ChatTwo/Ui/ChatLogWindow.cs index e41d396..1663542 100644 --- a/ChatTwo/Ui/ChatLogWindow.cs +++ b/ChatTwo/Ui/ChatLogWindow.cs @@ -101,34 +101,14 @@ public sealed class ChatLogWindow : Window, IUiComponent { public override void PreDraw() { - if (Plugin.Config.OverrideStyle && Plugin.Config.ChosenStyle != "") - { - var styles = StyleModel.GetConfiguredStyles(); - try - { - styles?.First(style => style.Name.Equals(Plugin.Config.ChosenStyle)).Push(); - } - catch (InvalidOperationException e) - { - // Swallow the error - User does not have a valid style set - } - } + if (Plugin.Config is { OverrideStyle: true, ChosenStyle: not null }) + StyleModel.GetConfiguredStyles()?.FirstOrDefault(style => style.Name == Plugin.Config.ChosenStyle)?.Push(); } public override void PostDraw() { - if (Plugin.Config.OverrideStyle && Plugin.Config.ChosenStyle != "") - { - var styles = StyleModel.GetConfiguredStyles(); - try - { - styles?.First(style => style.Name.Equals(Plugin.Config.ChosenStyle)).Pop(); - } - catch (InvalidOperationException e) - { - // Swallow the error - User does not have a valid style set - } - } + if (Plugin.Config is { OverrideStyle: true, ChosenStyle: not null }) + StyleModel.GetConfiguredStyles()?.FirstOrDefault(style => style.Name == Plugin.Config.ChosenStyle)?.Pop(); } public void Dispose() { diff --git a/ChatTwo/Ui/Popout.cs b/ChatTwo/Ui/Popout.cs index 19ffa1f..a84aa1f 100644 --- a/ChatTwo/Ui/Popout.cs +++ b/ChatTwo/Ui/Popout.cs @@ -25,18 +25,9 @@ internal class Popout : Window public override void PreDraw() { - if (ChatLogWindow.Plugin.Config.OverrideStyle && ChatLogWindow.Plugin.Config.ChosenStyle != "") - { - var styles = StyleModel.GetConfiguredStyles(); - try - { - styles?.First(style => style.Name.Equals(ChatLogWindow.Plugin.Config.ChosenStyle)).Push(); - } - catch (InvalidOperationException e) - { - // Swallow the error - User does not have a valid style set - } - } + if (ChatLogWindow.Plugin.Config is { OverrideStyle: true, ChosenStyle: not null }) + StyleModel.GetConfiguredStyles()?.FirstOrDefault(style => style.Name == ChatLogWindow.Plugin.Config.ChosenStyle)?.Push(); + Flags = ImGuiWindowFlags.None; if (!ChatLogWindow.Plugin.Config.ShowPopOutTitleBar) Flags |= ImGuiWindowFlags.NoTitleBar; @@ -66,18 +57,9 @@ internal class Popout : Window { ChatLogWindow.PopOutDocked[Idx] = ImGui.IsWindowDocked(); - if (ChatLogWindow.Plugin.Config.OverrideStyle && ChatLogWindow.Plugin.Config.ChosenStyle != "") - { - var styles = StyleModel.GetConfiguredStyles(); - try - { - styles?.First(style => style.Name.Equals(ChatLogWindow.Plugin.Config.ChosenStyle)).Pop(); - } - catch (InvalidOperationException e) - { - // Swallow the error - User does not have a valid style set - } - } + + if (ChatLogWindow.Plugin.Config is { OverrideStyle: true, ChosenStyle: not null }) + StyleModel.GetConfiguredStyles()?.FirstOrDefault(style => style.Name == ChatLogWindow.Plugin.Config.ChosenStyle)?.Pop(); } public override void OnClose() diff --git a/ChatTwo/Ui/SettingsTabs/About.cs b/ChatTwo/Ui/SettingsTabs/About.cs index d7b0927..4002e91 100755 --- a/ChatTwo/Ui/SettingsTabs/About.cs +++ b/ChatTwo/Ui/SettingsTabs/About.cs @@ -87,6 +87,7 @@ internal sealed class About : ISettingsTab { ImGui.EndChild(); } + ImGui.Spacing(); ImGui.PopTextWrapPos(); } } diff --git a/ChatTwo/Ui/SettingsTabs/ChatColours.cs b/ChatTwo/Ui/SettingsTabs/ChatColours.cs index 2addc28..afbfb34 100755 --- a/ChatTwo/Ui/SettingsTabs/ChatColours.cs +++ b/ChatTwo/Ui/SettingsTabs/ChatColours.cs @@ -60,5 +60,7 @@ internal sealed class ChatColours : ISettingsTab { } } } + + ImGui.Spacing(); } } diff --git a/ChatTwo/Ui/SettingsTabs/Database.cs b/ChatTwo/Ui/SettingsTabs/Database.cs index e29c10c..2ca9f43 100755 --- a/ChatTwo/Ui/SettingsTabs/Database.cs +++ b/ChatTwo/Ui/SettingsTabs/Database.cs @@ -126,5 +126,7 @@ internal sealed class Database : ISettingsTab ImGui.PopTextWrapPos(); ImGui.TreePop(); } + + ImGui.Spacing(); } } diff --git a/ChatTwo/Ui/SettingsTabs/Display.cs b/ChatTwo/Ui/SettingsTabs/Display.cs index c127086..2bb1b29 100755 --- a/ChatTwo/Ui/SettingsTabs/Display.cs +++ b/ChatTwo/Ui/SettingsTabs/Display.cs @@ -101,19 +101,26 @@ internal sealed class Display : ISettingsTab { if (Mutable.OverrideStyle) { - var currentStyle = Mutable.ChosenStyle.Equals("") ? StyleModel.GetConfiguredStyle().Name : Mutable.ChosenStyle; - if (ImGui.BeginCombo(Language.Options_OverrideStyleDropdown_Name, currentStyle)) { - foreach (var style in StyleModel.GetConfiguredStyles()) { - if (ImGui.Selectable(style.Name, Mutable.ChosenStyle == style.Name)) { - Mutable.ChosenStyle = style.Name; - } - } + 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(); + ImGui.EndCombo(); + } + } + else + { + ImGui.TextUnformatted(Language.Options_OverrideStyle_NotAvailable); } } - ImGui.Spacing(); + ImGui.Spacing(); ImGui.PopTextWrapPos(); } } diff --git a/ChatTwo/Ui/SettingsTabs/Fonts.cs b/ChatTwo/Ui/SettingsTabs/Fonts.cs index 95474f4..7aa45d7 100755 --- a/ChatTwo/Ui/SettingsTabs/Fonts.cs +++ b/ChatTwo/Ui/SettingsTabs/Fonts.cs @@ -113,6 +113,7 @@ public class Fonts : ISettingsTab { ImGuiUtil.DragFloatVertical(Language.Options_SymbolsFontSize_Name, ref Mutable.SymbolsFontSize, speed, min, max, $"{Mutable.SymbolsFontSize:N1}"); ImGuiUtil.HelpText(Language.Options_SymbolsFontSize_Description); + ImGui.Spacing(); ImGui.PopTextWrapPos(); } } diff --git a/ChatTwo/Ui/SettingsTabs/Miscellaneous.cs b/ChatTwo/Ui/SettingsTabs/Miscellaneous.cs index e03a795..2bc2e2d 100755 --- a/ChatTwo/Ui/SettingsTabs/Miscellaneous.cs +++ b/ChatTwo/Ui/SettingsTabs/Miscellaneous.cs @@ -61,6 +61,7 @@ internal sealed class Miscellaneous : ISettingsTab { ImGui.Checkbox(Language.Options_SortAutoTranslate_Name, ref Mutable.SortAutoTranslate); ImGuiUtil.HelpText(Language.Options_SortAutoTranslate_Description); + ImGui.Spacing(); } }