diff --git a/CHANGELOG.md b/CHANGELOG.md index 9574ec6..751dd6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,8 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- Lots of performance and under the hood optimizations - Auto-save and load reliability +- Some UI bugs on auto-load +- Lots of performance and under the hood optimizations ## [4.10.1] - 2023-06-27 diff --git a/SleepHunter/Models/Player.cs b/SleepHunter/Models/Player.cs index c3ed2ac..04fe299 100644 --- a/SleepHunter/Models/Player.cs +++ b/SleepHunter/Models/Player.cs @@ -222,9 +222,8 @@ protected override void OnUpdate() spellbook.TryUpdate(); var wasLoggedIn = IsLoggedIn; - IsLoggedIn = !string.IsNullOrWhiteSpace(Name) && stats.Level > 0; - var isNowLoggedIn = IsLoggedIn; - + var isNowLoggedIn = !string.IsNullOrWhiteSpace(Name) && stats.Level > 0; + if (isNowLoggedIn && !wasLoggedIn) OnLoggedIn(); else if (wasLoggedIn && !isNowLoggedIn) @@ -247,6 +246,7 @@ private void UpdateName(ProcessMemoryAccessor accessor) private void OnLoggedIn() { + IsLoggedIn = true; LoggedIn?.Invoke(this, EventArgs.Empty); } @@ -255,6 +255,7 @@ void OnLoggedOut() // This memory gets re-allocated when a new character logs into the same client instance skillbook.ResetCooldownPointer(); + IsLoggedIn = false; LoggedOut?.Invoke(this, EventArgs.Empty); } diff --git a/SleepHunter/Models/PlayerManager.cs b/SleepHunter/Models/PlayerManager.cs index bb5861f..3c71b85 100644 --- a/SleepHunter/Models/PlayerManager.cs +++ b/SleepHunter/Models/PlayerManager.cs @@ -20,9 +20,8 @@ private PlayerManager() { } private bool showAllClients; public event PlayerEventHandler PlayerAdded; - public event PropertyChangedEventHandler PlayerPropertyChanged; - public event PlayerEventHandler PlayerUpdated; public event PlayerEventHandler PlayerRemoved; + public event PropertyChangedEventHandler PlayerPropertyChanged; public event PropertyChangedEventHandler PropertyChanged; @@ -97,9 +96,7 @@ public void AddPlayer(Player player) players[player.Process.ProcessId] = player; - if (alreadyExists) - OnPlayerUpdated(player); - else + if (!alreadyExists) OnPlayerAdded(player); } @@ -123,6 +120,7 @@ public Player GetPlayerByName(string playerName) public bool RemovePlayer(int processId) { var wasRemoved = players.TryRemove(processId, out var removedPlayer); + removedPlayer.PropertyChanged -= Player_PropertyChanged; if (wasRemoved) { @@ -160,25 +158,11 @@ public void UpdateClients(Predicate predicate = null) private void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - private void OnPlayerAdded(Player player) - { - player.PropertyChanged += Player_PropertyChanged; - PlayerAdded?.Invoke(this, new PlayerEventArgs(player)); - } + private void OnPlayerAdded(Player player) => PlayerAdded?.Invoke(this, new PlayerEventArgs(player)); private void OnPlayerPropertyChanged(Player player, string propertyName) => PlayerPropertyChanged?.Invoke(player, new PropertyChangedEventArgs(propertyName)); - private void OnPlayerUpdated(Player player) - { - player.PropertyChanged += Player_PropertyChanged; - PlayerUpdated?.Invoke(this, new PlayerEventArgs(player)); - } - - private void OnPlayerRemoved(Player player) - { - player.PropertyChanged -= Player_PropertyChanged; - PlayerRemoved?.Invoke(this, new PlayerEventArgs(player)); - } + private void OnPlayerRemoved(Player player) => PlayerRemoved?.Invoke(this, new PlayerEventArgs(player)); private void Player_PropertyChanged(object sender, PropertyChangedEventArgs e) { diff --git a/SleepHunter/Views/FlowerTargetWindow.xaml.cs b/SleepHunter/Views/FlowerTargetWindow.xaml.cs index e033ffc..38e7462 100644 --- a/SleepHunter/Views/FlowerTargetWindow.xaml.cs +++ b/SleepHunter/Views/FlowerTargetWindow.xaml.cs @@ -73,7 +73,6 @@ public FlowerTargetWindow() private void InitializeViews() { PlayerManager.Instance.PlayerAdded += OnPlayerCollectionChanged; - PlayerManager.Instance.PlayerUpdated += OnPlayerCollectionChanged; PlayerManager.Instance.PlayerRemoved += OnPlayerCollectionChanged; PlayerManager.Instance.PlayerPropertyChanged += OnPlayerPropertyChanged; diff --git a/SleepHunter/Views/MainWindow.xaml.cs b/SleepHunter/Views/MainWindow.xaml.cs index 43f4463..8774127 100644 --- a/SleepHunter/Views/MainWindow.xaml.cs +++ b/SleepHunter/Views/MainWindow.xaml.cs @@ -291,7 +291,6 @@ private void InitializeHotkeyHook() private void InitializeViews() { PlayerManager.Instance.PlayerAdded += OnPlayerCollectionAdd; - PlayerManager.Instance.PlayerUpdated += OnPlayerCollectionAdd; PlayerManager.Instance.PlayerRemoved += OnPlayerCollectionRemove; PlayerManager.Instance.PlayerPropertyChanged += OnPlayerPropertyChanged; diff --git a/SleepHunter/Views/SpellTargetWindow.xaml.cs b/SleepHunter/Views/SpellTargetWindow.xaml.cs index 3d949aa..40d9bfb 100644 --- a/SleepHunter/Views/SpellTargetWindow.xaml.cs +++ b/SleepHunter/Views/SpellTargetWindow.xaml.cs @@ -98,7 +98,6 @@ public SpellTargetWindow() private void InitializeViews() { PlayerManager.Instance.PlayerAdded += OnPlayerCollectionChanged; - PlayerManager.Instance.PlayerUpdated += OnPlayerCollectionChanged; PlayerManager.Instance.PlayerRemoved += OnPlayerCollectionChanged; PlayerManager.Instance.PlayerPropertyChanged += OnPlayerPropertyChanged; @@ -120,7 +119,7 @@ private async void OnPlayerPropertyChanged(object sender, PropertyChangedEventAr if (string.Equals(nameof(player.Name), e.PropertyName, StringComparison.OrdinalIgnoreCase) || string.Equals(nameof(player.IsLoggedIn), e.PropertyName, StringComparison.OrdinalIgnoreCase)) { - BindingOperations.GetBindingExpression(characterComboBox, ListView.ItemsSourceProperty).UpdateTarget(); + BindingOperations.GetBindingExpression(characterComboBox, ItemsControl.ItemsSourceProperty).UpdateTarget(); characterComboBox.Items.Refresh(); } }