diff --git a/PrefPro/Configuration.cs b/PrefPro/Configuration.cs index 9458a00..6621071 100644 --- a/PrefPro/Configuration.cs +++ b/PrefPro/Configuration.cs @@ -146,7 +146,7 @@ public ConfigHolder GetOrDefault() { var ch = new ConfigHolder { - Name = _prefPro.PlayerName, + Name = _prefPro.PlayerName ?? "", FullName = NameSetting.FirstLast, FirstName = NameSetting.FirstOnly, LastName = NameSetting.LastOnly, diff --git a/PrefPro/NameHandlerCache.cs b/PrefPro/NameHandlerCache.cs index b89cd78..7ce35e3 100644 --- a/PrefPro/NameHandlerCache.cs +++ b/PrefPro/NameHandlerCache.cs @@ -7,7 +7,7 @@ namespace PrefPro; public class NameHandlerCache { private readonly Configuration _configuration; - private string? _playerName; + public string? PlayerName; public HandlerConfig Config { get; private set; } = HandlerConfig.None; @@ -22,15 +22,15 @@ private void FrameworkOnUpdate(IFramework framework) { if (DalamudApi.ClientState.IsLoggedIn && DalamudApi.ClientState.LocalPlayer is { } localPlayer) { DalamudApi.Framework.Update -= FrameworkOnUpdate; - _playerName = localPlayer.Name.TextValue; + PlayerName = localPlayer.Name.TextValue; Refresh(); } } private void OnLogout(int type, int code) { - if (_playerName != null) { - _playerName = null; + if (PlayerName != null) { + PlayerName = null; Config = HandlerConfig.None; DalamudApi.Framework.Update += FrameworkOnUpdate; } @@ -38,8 +38,8 @@ private void OnLogout(int type, int code) public void Refresh() { - if (_playerName != null) { - Config = CreateConfig(_configuration, _playerName); + if (PlayerName != null) { + Config = CreateConfig(_configuration, PlayerName); } } @@ -47,6 +47,11 @@ private static HandlerConfig CreateConfig(Configuration config, string playerNam { var data = new HandlerConfig(); + if (string.IsNullOrEmpty(config.Name)) + { + return HandlerConfig.None; + } + if (config.Name != playerName) { data.ApplyFull = true; @@ -78,7 +83,8 @@ private static HandlerConfig CreateConfig(Configuration config, string playerNam private static string GetNameText(string playerName, string configName, NameSetting setting) { - switch (setting) { + switch (setting) + { case NameSetting.FirstLast: return configName; case NameSetting.FirstOnly: diff --git a/PrefPro/PluginUI.cs b/PrefPro/PluginUI.cs index f6973a4..a984257 100644 --- a/PrefPro/PluginUI.cs +++ b/PrefPro/PluginUI.cs @@ -25,18 +25,16 @@ class PluginUI : IDisposable private string _tmpFirstName = ""; private string _tmpLastName = ""; + private bool _resetNames; public bool SettingsVisible { get => _settingsVisible; - // set => _settingsVisible = value; set { if (value) { - var split = _configuration.Name.Split(' '); - _tmpFirstName = split[0]; - _tmpLastName = split[1]; + _resetNames = true; } _settingsVisible = value; } @@ -68,6 +66,27 @@ public void DrawSettingsWindow() ImGui.SetNextWindowSize(size, ImGuiCond.FirstUseEver); if (ImGui.Begin("PrefPro Config", ref _settingsVisible, ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse)) { + if (_prefPro.PlayerName is null || DalamudApi.ClientState.LocalPlayer is null) + { + ImGui.TextWrapped("Configuration is not available while logged out or in a loading screen."); + ImGui.End(); + return; + } + + if (_configuration.Name == "") + { + DalamudApi.PluginLog.Debug($"Configuration name is empty, setting to current player name ({_prefPro.PlayerName})."); + _configuration.Name = _prefPro.PlayerName; + } + + if (_resetNames) + { + var split = _configuration.Name.Split(' '); + _tmpFirstName = split[0]; + _tmpLastName = split[1]; + _resetNames = false; + } + var enabled = _configuration.Enabled; var currentGender = _configuration.Gender; var currentRace = _configuration.Race; diff --git a/PrefPro/PrefPro.cs b/PrefPro/PrefPro.cs index 295953a..02879e0 100644 --- a/PrefPro/PrefPro.cs +++ b/PrefPro/PrefPro.cs @@ -42,7 +42,7 @@ public unsafe class PrefPro : IDalamudPlugin public readonly NameHandlerCache NameHandlerCache; - public string PlayerName => DalamudApi.ClientState.LocalPlayer?.Name.ToString(); + public string? PlayerName => NameHandlerCache.PlayerName; public int PlayerGender => DalamudApi.ClientState.LocalPlayer?.Customize[(int)CustomizeIndex.Gender] ?? 0; public RaceSetting PlayerRace => (RaceSetting) (DalamudApi.ClientState.LocalPlayer?.Customize[(int)CustomizeIndex.Race] ?? 0); public TribeSetting PlayerTribe => (TribeSetting) (DalamudApi.ClientState.LocalPlayer?.Customize[(int)CustomizeIndex.Tribe] ?? 0);