Just null check the styles

This commit is contained in:
Infi
2024-04-12 22:11:17 +02:00
parent 4751e3c8f7
commit c66d97829c
12 changed files with 60 additions and 60 deletions
+4 -24
View File
@@ -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() {
+6 -24
View File
@@ -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()
+1
View File
@@ -87,6 +87,7 @@ internal sealed class About : ISettingsTab {
ImGui.EndChild();
}
ImGui.Spacing();
ImGui.PopTextWrapPos();
}
}
+2
View File
@@ -60,5 +60,7 @@ internal sealed class ChatColours : ISettingsTab {
}
}
}
ImGui.Spacing();
}
}
+2
View File
@@ -126,5 +126,7 @@ internal sealed class Database : ISettingsTab
ImGui.PopTextWrapPos();
ImGui.TreePop();
}
ImGui.Spacing();
}
}
+16 -9
View File
@@ -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();
}
}
+1
View File
@@ -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();
}
}
+1
View File
@@ -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();
}
}