Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PrefPro/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 13 additions & 7 deletions PrefPro/NameHandlerCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -22,31 +22,36 @@ 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;
}
}

public void Refresh()
{
if (_playerName != null) {
Config = CreateConfig(_configuration, _playerName);
if (PlayerName != null) {
Config = CreateConfig(_configuration, PlayerName);
}
}

private static HandlerConfig CreateConfig(Configuration config, string playerName)
{
var data = new HandlerConfig();

if (string.IsNullOrEmpty(config.Name))
{
return HandlerConfig.None;
}

if (config.Name != playerName)
{
data.ApplyFull = true;
Expand Down Expand Up @@ -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:
Expand Down
27 changes: 23 additions & 4 deletions PrefPro/PluginUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion PrefPro/PrefPro.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading