SoundFilter/SoundFilter/Ui/PluginUi.cs

48 lines
1.5 KiB
C#
Raw Normal View History

2021-05-08 17:34:13 +00:00
using System;
using System.Globalization;
2021-08-24 18:18:09 +00:00
using Dalamud.Logging;
2021-05-08 17:34:13 +00:00
using SoundFilter.Resources;
namespace SoundFilter.Ui {
public class PluginUi : IDisposable {
private SoundFilterPlugin Plugin { get; }
internal Settings Settings { get; }
private SoundLog SoundLog { get; }
internal PluginUi(SoundFilterPlugin plugin) {
this.Plugin = plugin;
this.ConfigureLanguage();
this.Settings = new Settings(this.Plugin);
this.SoundLog = new SoundLog(this.Plugin);
2021-08-24 18:18:09 +00:00
this.Plugin.Interface.UiBuilder.Draw += this.Draw;
this.Plugin.Interface.LanguageChanged += this.ConfigureLanguage;
2021-05-08 17:34:13 +00:00
}
public void Dispose() {
2021-08-24 18:18:09 +00:00
this.Plugin.Interface.LanguageChanged -= this.ConfigureLanguage;
this.Plugin.Interface.UiBuilder.Draw -= this.Draw;
2021-05-08 17:34:13 +00:00
this.Settings.Dispose();
}
private void ConfigureLanguage(string? langCode = null) {
2021-08-24 18:18:09 +00:00
// ReSharper disable once ConstantNullCoalescingCondition
2021-05-08 17:34:13 +00:00
langCode ??= this.Plugin.Interface.UiLanguage ?? "en";
try {
Language.Culture = new CultureInfo(langCode);
} catch (Exception ex) {
PluginLog.LogError(ex, $"Could not set culture to {langCode} - falling back to default");
Language.Culture = CultureInfo.DefaultThreadCurrentUICulture;
}
}
private void Draw() {
this.Settings.Draw();
this.SoundLog.Draw();
}
}
}