From 9b67df910dac9b5f60c31a1fdd3ae702dcd1f265 Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 7 Aug 2024 16:32:38 +0200 Subject: [PATCH 1/3] Change vaults and container models --- .../Models/NetworkModel/ContainerItem.cs | 14 ---- .../Models/NetworkModel/Vault.cs | 36 --------- .../Handler/BankVaultInfoEventHandler.cs | 2 +- .../Network/Manager/VaultController.cs | 65 ++++++++-------- .../StorageHistory/ContainerItem.cs | 32 ++++++++ .../StorageHistory/ContainerItemDto.cs | 11 +++ .../StorageHistory/StorageHistoryMapping.cs | 71 ++++++++++++++++++ .../StorageHistory/Vault.cs | 75 +++++++++++++++++++ .../VaultBindings.cs | 15 ++-- .../StorageHistory/VaultContainer.cs | 64 ++++++++++++++++ .../VaultContainerDto.cs} | 6 +- .../StorageHistory/VaultDto.cs | 12 +++ .../VaultInfo.cs | 8 +- .../Styles/GuildStyles.xaml | 5 +- .../Styles/StorageHistoryStyle.xaml | 5 +- .../ViewModels/MainWindowViewModel.cs | 1 + 16 files changed, 319 insertions(+), 103 deletions(-) delete mode 100644 src/StatisticsAnalysisTool/Models/NetworkModel/ContainerItem.cs delete mode 100644 src/StatisticsAnalysisTool/Models/NetworkModel/Vault.cs create mode 100644 src/StatisticsAnalysisTool/StorageHistory/ContainerItem.cs create mode 100644 src/StatisticsAnalysisTool/StorageHistory/ContainerItemDto.cs create mode 100644 src/StatisticsAnalysisTool/StorageHistory/StorageHistoryMapping.cs create mode 100644 src/StatisticsAnalysisTool/StorageHistory/Vault.cs rename src/StatisticsAnalysisTool/{Models/BindingModel => StorageHistory}/VaultBindings.cs (91%) create mode 100644 src/StatisticsAnalysisTool/StorageHistory/VaultContainer.cs rename src/StatisticsAnalysisTool/{Models/NetworkModel/VaultContainer.cs => StorageHistory/VaultContainerDto.cs} (59%) create mode 100644 src/StatisticsAnalysisTool/StorageHistory/VaultDto.cs rename src/StatisticsAnalysisTool/{Models/NetworkModel => StorageHistory}/VaultInfo.cs (89%) diff --git a/src/StatisticsAnalysisTool/Models/NetworkModel/ContainerItem.cs b/src/StatisticsAnalysisTool/Models/NetworkModel/ContainerItem.cs deleted file mode 100644 index a5e5e798f..000000000 --- a/src/StatisticsAnalysisTool/Models/NetworkModel/ContainerItem.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Text.Json.Serialization; -using StatisticsAnalysisTool.Common; - -namespace StatisticsAnalysisTool.Models.NetworkModel; - -public class ContainerItem -{ - [JsonPropertyName("I")] - public int ItemIndex { get; set; } - [JsonIgnore] - public Item Item => ItemController.GetItemByIndex(ItemIndex); - [JsonPropertyName("Q")] - public int Quantity { get; set; } -} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Models/NetworkModel/Vault.cs b/src/StatisticsAnalysisTool/Models/NetworkModel/Vault.cs deleted file mode 100644 index 3b9b7e702..000000000 --- a/src/StatisticsAnalysisTool/Models/NetworkModel/Vault.cs +++ /dev/null @@ -1,36 +0,0 @@ -using StatisticsAnalysisTool.Cluster; -using StatisticsAnalysisTool.GameFileData; -using StatisticsAnalysisTool.Localization; -using System.Collections.Generic; -using System.Text.Json.Serialization; - -namespace StatisticsAnalysisTool.Models.NetworkModel; - -public class Vault -{ - public string Location { get; set; } - public string MainLocationIndex { get; set; } - public MapType MapType { get; set; } - public List VaultContainer { get; set; } = new(); - - [JsonIgnore] - public string MainLocation => WorldData.GetUniqueNameOrDefault(MainLocationIndex); - [JsonIgnore] - public string LocationDisplayString - { - get - { - if (MapType is MapType.Hideout) - { - return $"{Location} ({LocalizationController.Translation("HIDEOUT")}) - {MainLocation}"; - } - - if (MapType is MapType.Island) - { - return $"{Location} ({LocalizationController.Translation("ISLAND")})"; - } - - return Location; - } - } -} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Network/Handler/BankVaultInfoEventHandler.cs b/src/StatisticsAnalysisTool/Network/Handler/BankVaultInfoEventHandler.cs index 5089b52c5..b03e90b09 100644 --- a/src/StatisticsAnalysisTool/Network/Handler/BankVaultInfoEventHandler.cs +++ b/src/StatisticsAnalysisTool/Network/Handler/BankVaultInfoEventHandler.cs @@ -1,7 +1,7 @@ using StatisticsAnalysisTool.Network.Events; using StatisticsAnalysisTool.Network.Manager; +using StatisticsAnalysisTool.StorageHistory; using System.Threading.Tasks; -using StatisticsAnalysisTool.Models.NetworkModel; namespace StatisticsAnalysisTool.Network.Handler; diff --git a/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs b/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs index b3ae93099..62d7f98b4 100644 --- a/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs +++ b/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs @@ -4,6 +4,7 @@ using StatisticsAnalysisTool.Models; using StatisticsAnalysisTool.Models.NetworkModel; using StatisticsAnalysisTool.Properties; +using StatisticsAnalysisTool.StorageHistory; using StatisticsAnalysisTool.ViewModels; using System; using System.Collections.Generic; @@ -23,23 +24,11 @@ public class VaultController private VaultInfo _currentVaultInfo; private readonly List _discoveredItems = new(); private readonly List _vaultContainer = new(); - private ObservableCollection _vault = new(); - - private ObservableCollection Vaults - { - get => _vault; - set - { - _vault = value; - OnVaultsChange?.Invoke(); - } - } - + public VaultController(MainWindowViewModel mainWindowViewModel) { _mainWindowViewModel = mainWindowViewModel; - - OnVaultsChange += UpdateUi; + OnVaultsChange += UpdateSearchListUiAsync; OnVaultsRemove += UpdateSearchListUiAsync; } @@ -121,11 +110,12 @@ public void RemoveVault(Vault vault) { _vaultContainer?.Remove(removableContainer); } - - _vault.Remove(vault); + + Application.Current.Dispatcher.Invoke(() => + { + _mainWindowViewModel.VaultBindings.Vaults.Remove(vault); + }); OnVaultsRemove?.Invoke(); - - UpdateUi(); } private void ParseVault() @@ -135,13 +125,17 @@ private void ParseVault() return; } - var removableVaultInfo = Vaults.FirstOrDefault(x => x.Location == _currentVaultInfo.UniqueClusterName); + var removableVaultInfo = _mainWindowViewModel.VaultBindings.Vaults.FirstOrDefault(x => x.Location == _currentVaultInfo.UniqueClusterName); if (removableVaultInfo != null) { - Vaults.Remove(removableVaultInfo); + Application.Current.Dispatcher.Invoke(() => + { + _mainWindowViewModel.VaultBindings.Vaults.Remove(removableVaultInfo); + }); } + // TODO: Hier Add or update und nicht remove and add var vault = new Vault() { Location = _currentVaultInfo.UniqueClusterName, @@ -170,7 +164,11 @@ private void ParseVault() vault.VaultContainer.Add(vaultContainer); } - Vaults.Add(vault); + Application.Current.Dispatcher.Invoke(() => + { + _mainWindowViewModel.VaultBindings.Vaults.Add(vault); + }); + OnVaultsChange?.Invoke(); } catch (Exception e) @@ -205,20 +203,12 @@ private void SetItemsToVaultContainer(ItemContainerObject containerObject, Vault } #region Ui - - private void UpdateUi() - { - Application.Current.Dispatcher.Invoke(() => - { - _mainWindowViewModel.VaultBindings.Vaults = Vaults.ToList(); - }); - } - + private async void UpdateSearchListUiAsync() { var vaultSearchItem = new List(); - await foreach (var vault in Vaults.ToList().ToAsyncEnumerable()) + await foreach (var vault in _mainWindowViewModel.VaultBindings.Vaults.ToList().ToAsyncEnumerable()) { var tempItems = new List(); @@ -326,14 +316,21 @@ private void GetRepairCostsOfContainer(ItemContainerObject newContainerObject) public async Task LoadFromFileAsync() { FileController.TransferFileIfExistFromOldPathToUserDataDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Settings.Default.VaultsFileName)); - Vaults = await FileController.LoadAsync>( - Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Settings.Default.UserDataDirectoryName, Settings.Default.VaultsFileName)); + + var vaultDtos = await FileController.LoadAsync>(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Settings.Default.UserDataDirectoryName, Settings.Default.VaultsFileName)); + _mainWindowViewModel.VaultBindings.Vaults = new ObservableCollection(vaultDtos.Select(StorageHistoryMapping.Mapping)); } public async Task SaveInFileAsync() { DirectoryController.CreateDirectoryWhenNotExists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Settings.Default.UserDataDirectoryName)); - await FileController.SaveAsync(Vaults, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Settings.Default.UserDataDirectoryName, Settings.Default.VaultsFileName)); + + var vaultDtosToSave = _mainWindowViewModel.VaultBindings.Vaults + .ToList() + .Select(StorageHistoryMapping.Mapping); + + await FileController.SaveAsync(vaultDtosToSave, + Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Settings.Default.UserDataDirectoryName, Settings.Default.VaultsFileName)); Debug.Print("Vault saved"); } diff --git a/src/StatisticsAnalysisTool/StorageHistory/ContainerItem.cs b/src/StatisticsAnalysisTool/StorageHistory/ContainerItem.cs new file mode 100644 index 000000000..a760a2baf --- /dev/null +++ b/src/StatisticsAnalysisTool/StorageHistory/ContainerItem.cs @@ -0,0 +1,32 @@ +using StatisticsAnalysisTool.Common; +using StatisticsAnalysisTool.Models; +using StatisticsAnalysisTool.ViewModels; + +namespace StatisticsAnalysisTool.StorageHistory; + +public class ContainerItem : BaseViewModel +{ + private int _itemIndex; + private int _quantity; + + public int ItemIndex + { + get => _itemIndex; + set + { + _itemIndex = value; + OnPropertyChanged(); + } + } + + public int Quantity + { + get => _quantity; + set + { + _quantity = value; + OnPropertyChanged(); + } + } + public Item Item => ItemController.GetItemByIndex(ItemIndex); +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/StorageHistory/ContainerItemDto.cs b/src/StatisticsAnalysisTool/StorageHistory/ContainerItemDto.cs new file mode 100644 index 000000000..1b00629d5 --- /dev/null +++ b/src/StatisticsAnalysisTool/StorageHistory/ContainerItemDto.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; + +namespace StatisticsAnalysisTool.StorageHistory; + +public class ContainerItemDto +{ + [JsonPropertyName("I")] + public int ItemIndex { get; set; } + [JsonPropertyName("Q")] + public int Quantity { get; set; } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/StorageHistory/StorageHistoryMapping.cs b/src/StatisticsAnalysisTool/StorageHistory/StorageHistoryMapping.cs new file mode 100644 index 000000000..18b1efdd4 --- /dev/null +++ b/src/StatisticsAnalysisTool/StorageHistory/StorageHistoryMapping.cs @@ -0,0 +1,71 @@ +using System.Collections.ObjectModel; +using System.Linq; + +namespace StatisticsAnalysisTool.StorageHistory; + +public static class StorageHistoryMapping +{ + public static VaultDto Mapping(Vault vault) + { + return new VaultDto() + { + Location = vault.Location, + MainLocationIndex = vault.MainLocationIndex, + MapType = vault.MapType, + VaultContainer = vault.VaultContainer + }; + } + + public static Vault Mapping(VaultDto vaultDto) + { + return new Vault() + { + Location = vaultDto.Location, + MainLocationIndex = vaultDto.MainLocationIndex, + MapType = vaultDto.MapType, + VaultContainer = vaultDto.VaultContainer + }; + } + + public static VaultContainerDto Mapping(VaultContainer vaultContainer) + { + return new VaultContainerDto() + { + LastUpdate = vaultContainer.LastUpdate, + Guid = vaultContainer.Guid, + Name = vaultContainer.Name, + Icon = vaultContainer.Icon, + Items = vaultContainer.Items.Select(Mapping).ToList() + }; + } + + public static VaultContainer Mapping(VaultContainerDto vaultContainerDto) + { + return new VaultContainer() + { + LastUpdate = vaultContainerDto.LastUpdate, + Guid = vaultContainerDto.Guid, + Name = vaultContainerDto.Name, + Icon = vaultContainerDto.Icon, + Items = new ObservableCollection(vaultContainerDto.Items.Select(Mapping)) + }; + } + + public static ContainerItemDto Mapping(ContainerItem containerItem) + { + return new ContainerItemDto() + { + ItemIndex = containerItem.ItemIndex, + Quantity = containerItem.Quantity + }; + } + + public static ContainerItem Mapping(ContainerItemDto containerItemDto) + { + return new ContainerItem() + { + ItemIndex = containerItemDto.ItemIndex, + Quantity = containerItemDto.Quantity + }; + } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/StorageHistory/Vault.cs b/src/StatisticsAnalysisTool/StorageHistory/Vault.cs new file mode 100644 index 000000000..c46d7c87a --- /dev/null +++ b/src/StatisticsAnalysisTool/StorageHistory/Vault.cs @@ -0,0 +1,75 @@ +using StatisticsAnalysisTool.Cluster; +using StatisticsAnalysisTool.GameFileData; +using StatisticsAnalysisTool.Localization; +using StatisticsAnalysisTool.ViewModels; +using System.Collections.Generic; + +namespace StatisticsAnalysisTool.StorageHistory; + +public class Vault : BaseViewModel +{ + private string _location; + private string _mainLocationIndex; + private MapType _mapType; + private List _vaultContainer = new(); + + public string Location + { + get => _location; + set + { + _location = value; + OnPropertyChanged(); + } + } + + public string MainLocationIndex + { + get => _mainLocationIndex; + set + { + _mainLocationIndex = value; + OnPropertyChanged(); + } + } + + public MapType MapType + { + get => _mapType; + set + { + _mapType = value; + OnPropertyChanged(); + } + } + + public List VaultContainer + { + get => _vaultContainer; + set + { + _vaultContainer = value; + OnPropertyChanged(); + } + } + + public string MainLocation => WorldData.GetUniqueNameOrDefault(MainLocationIndex); + + public string LocationDisplayString + { + get + { + if (MapType is MapType.Hideout) + { + return $"{Location} ({LocalizationController.Translation("HIDEOUT")}) - {MainLocation}"; + } + + if (MapType is MapType.Island) + { + return $"{Location} ({LocalizationController.Translation("ISLAND")})"; + } + + return Location; + } + } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Models/BindingModel/VaultBindings.cs b/src/StatisticsAnalysisTool/StorageHistory/VaultBindings.cs similarity index 91% rename from src/StatisticsAnalysisTool/Models/BindingModel/VaultBindings.cs rename to src/StatisticsAnalysisTool/StorageHistory/VaultBindings.cs index 2fc33948f..ce0c02067 100644 --- a/src/StatisticsAnalysisTool/Models/BindingModel/VaultBindings.cs +++ b/src/StatisticsAnalysisTool/StorageHistory/VaultBindings.cs @@ -1,18 +1,19 @@ using StatisticsAnalysisTool.Common.UserSettings; -using StatisticsAnalysisTool.Models.NetworkModel; +using StatisticsAnalysisTool.Models; using StatisticsAnalysisTool.ViewModels; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Windows; using System.Windows.Data; -namespace StatisticsAnalysisTool.Models.BindingModel; +namespace StatisticsAnalysisTool.StorageHistory; public class VaultBindings : BaseViewModel { - private List _vaultContainerContent; - private List _vaults; + private ObservableCollection _vaultContainerContent; + private ObservableCollection _vaults; private Vault _vaultSelected; private List _vaultContainer; private VaultContainer _vaultContainerSelected; @@ -36,7 +37,7 @@ public VaultBindings() } } - public List Vaults + public ObservableCollection Vaults { get => _vaults; set @@ -73,14 +74,14 @@ public VaultContainer VaultContainerSelected set { _vaultContainerSelected = value; - VaultContainerContent = _vaultContainer?.FirstOrDefault(x => x.Guid == _vaultContainerSelected.Guid)?.Items ?? new List(); + VaultContainerContent = _vaultContainer?.FirstOrDefault(x => x.Guid == _vaultContainerSelected.Guid)?.Items ?? new ObservableCollection(); LastUpdate = _vaultContainerSelected?.LastUpdate ?? new DateTime(0); LastUpdateVisibility = _vaultContainerSelected?.LastUpdate.Ticks <= 1 ? Visibility.Hidden : Visibility.Visible; OnPropertyChanged(); } } - public List VaultContainerContent + public ObservableCollection VaultContainerContent { get => _vaultContainerContent; set diff --git a/src/StatisticsAnalysisTool/StorageHistory/VaultContainer.cs b/src/StatisticsAnalysisTool/StorageHistory/VaultContainer.cs new file mode 100644 index 000000000..a542b0f25 --- /dev/null +++ b/src/StatisticsAnalysisTool/StorageHistory/VaultContainer.cs @@ -0,0 +1,64 @@ +using StatisticsAnalysisTool.ViewModels; +using System; +using System.Collections.ObjectModel; + +namespace StatisticsAnalysisTool.StorageHistory; + +public class VaultContainer : BaseViewModel +{ + private DateTime _lastUpdate; + private Guid _guid; + private string _name; + private string _icon; + private ObservableCollection _items = new(); + + public DateTime LastUpdate + { + get => _lastUpdate; + set + { + _lastUpdate = value; + OnPropertyChanged(); + } + } + + public Guid Guid + { + get => _guid; + set + { + _guid = value; + OnPropertyChanged(); + } + } + + public string Name + { + get => _name; + set + { + _name = value; + OnPropertyChanged(); + } + } + + public string Icon + { + get => _icon; + set + { + _icon = value; + OnPropertyChanged(); + } + } + + public ObservableCollection Items + { + get => _items; + set + { + _items = value; + OnPropertyChanged(); + } + } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Models/NetworkModel/VaultContainer.cs b/src/StatisticsAnalysisTool/StorageHistory/VaultContainerDto.cs similarity index 59% rename from src/StatisticsAnalysisTool/Models/NetworkModel/VaultContainer.cs rename to src/StatisticsAnalysisTool/StorageHistory/VaultContainerDto.cs index cb3709b23..e3aeb871b 100644 --- a/src/StatisticsAnalysisTool/Models/NetworkModel/VaultContainer.cs +++ b/src/StatisticsAnalysisTool/StorageHistory/VaultContainerDto.cs @@ -1,13 +1,13 @@ using System; using System.Collections.Generic; -namespace StatisticsAnalysisTool.Models.NetworkModel; +namespace StatisticsAnalysisTool.StorageHistory; -public class VaultContainer +public class VaultContainerDto { public DateTime LastUpdate { get; set; } public Guid Guid { get; set; } public string Name { get; set; } public string Icon { get; set; } - public List Items { get; set; } = new (); + public List Items { get; set; } = new(); } \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/StorageHistory/VaultDto.cs b/src/StatisticsAnalysisTool/StorageHistory/VaultDto.cs new file mode 100644 index 000000000..2b1dc3600 --- /dev/null +++ b/src/StatisticsAnalysisTool/StorageHistory/VaultDto.cs @@ -0,0 +1,12 @@ +using StatisticsAnalysisTool.Cluster; +using System.Collections.Generic; + +namespace StatisticsAnalysisTool.StorageHistory; + +public class VaultDto +{ + public string Location { get; set; } + public string MainLocationIndex { get; set; } + public MapType MapType { get; set; } + public List VaultContainer { get; set; } = new(); +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Models/NetworkModel/VaultInfo.cs b/src/StatisticsAnalysisTool/StorageHistory/VaultInfo.cs similarity index 89% rename from src/StatisticsAnalysisTool/Models/NetworkModel/VaultInfo.cs rename to src/StatisticsAnalysisTool/StorageHistory/VaultInfo.cs index 807ab9e5a..9aa09d9ec 100644 --- a/src/StatisticsAnalysisTool/Models/NetworkModel/VaultInfo.cs +++ b/src/StatisticsAnalysisTool/StorageHistory/VaultInfo.cs @@ -1,9 +1,9 @@ -using StatisticsAnalysisTool.Cluster; -using StatisticsAnalysisTool.GameFileData; -using System; +using System; using System.Collections.Generic; +using StatisticsAnalysisTool.Cluster; +using StatisticsAnalysisTool.GameFileData; -namespace StatisticsAnalysisTool.Models.NetworkModel; +namespace StatisticsAnalysisTool.StorageHistory; public class VaultInfo { diff --git a/src/StatisticsAnalysisTool/Styles/GuildStyles.xaml b/src/StatisticsAnalysisTool/Styles/GuildStyles.xaml index 16690a99c..31e9e500c 100644 --- a/src/StatisticsAnalysisTool/Styles/GuildStyles.xaml +++ b/src/StatisticsAnalysisTool/Styles/GuildStyles.xaml @@ -2,9 +2,10 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:networkModel="clr-namespace:StatisticsAnalysisTool.Models.NetworkModel" xmlns:guild="clr-namespace:StatisticsAnalysisTool.Guild" - xmlns:common="clr-namespace:StatisticsAnalysisTool.Common"> + xmlns:common="clr-namespace:StatisticsAnalysisTool.Common" + xmlns:storageHistory="clr-namespace:StatisticsAnalysisTool.StorageHistory"> - + diff --git a/src/StatisticsAnalysisTool/Styles/StorageHistoryStyle.xaml b/src/StatisticsAnalysisTool/Styles/StorageHistoryStyle.xaml index e96c0e274..44e41c78c 100644 --- a/src/StatisticsAnalysisTool/Styles/StorageHistoryStyle.xaml +++ b/src/StatisticsAnalysisTool/Styles/StorageHistoryStyle.xaml @@ -1,9 +1,10 @@  + xmlns:networkModel="clr-namespace:StatisticsAnalysisTool.Models.NetworkModel" + xmlns:storageHistory="clr-namespace:StatisticsAnalysisTool.StorageHistory"> - + diff --git a/src/StatisticsAnalysisTool/ViewModels/MainWindowViewModel.cs b/src/StatisticsAnalysisTool/ViewModels/MainWindowViewModel.cs index 03d671bf0..17af3d4d3 100644 --- a/src/StatisticsAnalysisTool/ViewModels/MainWindowViewModel.cs +++ b/src/StatisticsAnalysisTool/ViewModels/MainWindowViewModel.cs @@ -34,6 +34,7 @@ using System.Windows; using System.Windows.Data; using System.Windows.Media; +using StatisticsAnalysisTool.StorageHistory; // ReSharper disable UnusedMember.Global From c011e4a4b003a44ce166920d5ddf78843235ffcd Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 7 Aug 2024 16:32:38 +0200 Subject: [PATCH 2/3] Change vaults and container models + added container repair costs --- .../Cluster/ClusterController.cs | 4 +- .../Models/NetworkModel/ContainerItem.cs | 14 -- .../NetworkModel/ItemContainerObject.cs | 1 + .../Models/NetworkModel/Vault.cs | 36 --- .../Handler/BankVaultInfoEventHandler.cs | 4 +- .../Handler/NewEquipmentItemEventHandler.cs | 2 +- .../Handler/NewFurnitureItemEventHandler.cs | 2 +- .../Handler/NewJournalItemEventHandler.cs | 2 +- .../Handler/NewKillTrophyItemHandler.cs | 2 +- .../Handler/NewLaborerItemEventHandler.cs | 2 +- .../Handler/NewSimpleItemEventHandler.cs | 2 +- .../Network/Manager/TrackingController.cs | 1 + .../StorageHistory/ContainerItem.cs | 32 +++ .../StorageHistory/ContainerItemDto.cs | 11 + .../InternalVault.cs} | 13 +- .../StorageHistory/StorageHistoryMapping.cs | 71 ++++++ .../StorageHistory/Vault.cs | 75 +++++++ .../VaultBindings.cs | 32 ++- .../StorageHistory/VaultContainer.cs | 75 +++++++ .../VaultContainerDto.cs} | 6 +- .../VaultController.cs | 208 ++++++++++-------- .../StorageHistory/VaultDto.cs | 12 + .../Styles/DashboardStyles.xaml | 4 - .../Styles/GuildStyles.xaml | 5 +- .../Styles/StorageHistoryStyle.xaml | 5 +- .../UserControls/StorageHistoryControl.xaml | 13 +- .../ViewModels/MainWindowViewModel.cs | 1 + 27 files changed, 450 insertions(+), 185 deletions(-) delete mode 100644 src/StatisticsAnalysisTool/Models/NetworkModel/ContainerItem.cs delete mode 100644 src/StatisticsAnalysisTool/Models/NetworkModel/Vault.cs create mode 100644 src/StatisticsAnalysisTool/StorageHistory/ContainerItem.cs create mode 100644 src/StatisticsAnalysisTool/StorageHistory/ContainerItemDto.cs rename src/StatisticsAnalysisTool/{Models/NetworkModel/VaultInfo.cs => StorageHistory/InternalVault.cs} (68%) create mode 100644 src/StatisticsAnalysisTool/StorageHistory/StorageHistoryMapping.cs create mode 100644 src/StatisticsAnalysisTool/StorageHistory/Vault.cs rename src/StatisticsAnalysisTool/{Models/BindingModel => StorageHistory}/VaultBindings.cs (79%) create mode 100644 src/StatisticsAnalysisTool/StorageHistory/VaultContainer.cs rename src/StatisticsAnalysisTool/{Models/NetworkModel/VaultContainer.cs => StorageHistory/VaultContainerDto.cs} (59%) rename src/StatisticsAnalysisTool/{Network/Manager => StorageHistory}/VaultController.cs (53%) create mode 100644 src/StatisticsAnalysisTool/StorageHistory/VaultDto.cs diff --git a/src/StatisticsAnalysisTool/Cluster/ClusterController.cs b/src/StatisticsAnalysisTool/Cluster/ClusterController.cs index f94c1b8fb..8af04d62a 100644 --- a/src/StatisticsAnalysisTool/Cluster/ClusterController.cs +++ b/src/StatisticsAnalysisTool/Cluster/ClusterController.cs @@ -72,8 +72,8 @@ public void SetAndResetValues(ClusterInfo currentCluster) _trackingController.CombatController.ResetDamageMeterByClusterChange(); _trackingController.StatisticController.SetKillsDeathsValues(); _trackingController.VaultController.ResetDiscoveredItems(); - _trackingController.VaultController.ResetVaultContainer(); - _trackingController.VaultController.ResetCurrentVaultInfo(); + _trackingController.VaultController.ResetInternalVaultContainer(); + _trackingController.VaultController.ResetCurrentInternalVault(); _trackingController.TreasureController.RemoveTemporaryTreasures(); _trackingController.TreasureController.UpdateLootedChestsDashboardUi(); _trackingController.LootController.ResetLocalPlayerDiscoveredLoot(); diff --git a/src/StatisticsAnalysisTool/Models/NetworkModel/ContainerItem.cs b/src/StatisticsAnalysisTool/Models/NetworkModel/ContainerItem.cs deleted file mode 100644 index a5e5e798f..000000000 --- a/src/StatisticsAnalysisTool/Models/NetworkModel/ContainerItem.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Text.Json.Serialization; -using StatisticsAnalysisTool.Common; - -namespace StatisticsAnalysisTool.Models.NetworkModel; - -public class ContainerItem -{ - [JsonPropertyName("I")] - public int ItemIndex { get; set; } - [JsonIgnore] - public Item Item => ItemController.GetItemByIndex(ItemIndex); - [JsonPropertyName("Q")] - public int Quantity { get; set; } -} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Models/NetworkModel/ItemContainerObject.cs b/src/StatisticsAnalysisTool/Models/NetworkModel/ItemContainerObject.cs index 72a2c985c..5aaa288bf 100644 --- a/src/StatisticsAnalysisTool/Models/NetworkModel/ItemContainerObject.cs +++ b/src/StatisticsAnalysisTool/Models/NetworkModel/ItemContainerObject.cs @@ -20,4 +20,5 @@ public ItemContainerObject(long? objectId, Guid privateContainerGuid, Guid conta public Guid PrivateContainerGuid { get; set; } public Guid ContainerGuid { get; set; } public List SlotItemIds { get; set; } + public double RepairCosts { get; set; } } \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Models/NetworkModel/Vault.cs b/src/StatisticsAnalysisTool/Models/NetworkModel/Vault.cs deleted file mode 100644 index 3b9b7e702..000000000 --- a/src/StatisticsAnalysisTool/Models/NetworkModel/Vault.cs +++ /dev/null @@ -1,36 +0,0 @@ -using StatisticsAnalysisTool.Cluster; -using StatisticsAnalysisTool.GameFileData; -using StatisticsAnalysisTool.Localization; -using System.Collections.Generic; -using System.Text.Json.Serialization; - -namespace StatisticsAnalysisTool.Models.NetworkModel; - -public class Vault -{ - public string Location { get; set; } - public string MainLocationIndex { get; set; } - public MapType MapType { get; set; } - public List VaultContainer { get; set; } = new(); - - [JsonIgnore] - public string MainLocation => WorldData.GetUniqueNameOrDefault(MainLocationIndex); - [JsonIgnore] - public string LocationDisplayString - { - get - { - if (MapType is MapType.Hideout) - { - return $"{Location} ({LocalizationController.Translation("HIDEOUT")}) - {MainLocation}"; - } - - if (MapType is MapType.Island) - { - return $"{Location} ({LocalizationController.Translation("ISLAND")})"; - } - - return Location; - } - } -} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Network/Handler/BankVaultInfoEventHandler.cs b/src/StatisticsAnalysisTool/Network/Handler/BankVaultInfoEventHandler.cs index 5089b52c5..94f4de9af 100644 --- a/src/StatisticsAnalysisTool/Network/Handler/BankVaultInfoEventHandler.cs +++ b/src/StatisticsAnalysisTool/Network/Handler/BankVaultInfoEventHandler.cs @@ -1,7 +1,7 @@ using StatisticsAnalysisTool.Network.Events; using StatisticsAnalysisTool.Network.Manager; +using StatisticsAnalysisTool.StorageHistory; using System.Threading.Tasks; -using StatisticsAnalysisTool.Models.NetworkModel; namespace StatisticsAnalysisTool.Network.Handler; @@ -18,7 +18,7 @@ protected override async Task OnActionAsync(BankVaultInfoEvent value) { if (_trackingController.IsTrackingAllowedByMainCharacter()) { - _trackingController.VaultController.SetCurrentVault(new VaultInfo(value.ObjectId, value.LocationGuidString, value.VaultGuidList, value.VaultNames, value.IconTags)); + _trackingController.VaultController.SetCurrentVault(new InternalVault(value.ObjectId, value.LocationGuidString, value.VaultGuidList, value.VaultNames, value.IconTags)); } await Task.CompletedTask; diff --git a/src/StatisticsAnalysisTool/Network/Handler/NewEquipmentItemEventHandler.cs b/src/StatisticsAnalysisTool/Network/Handler/NewEquipmentItemEventHandler.cs index fce5cc8b6..2ec0901b6 100644 --- a/src/StatisticsAnalysisTool/Network/Handler/NewEquipmentItemEventHandler.cs +++ b/src/StatisticsAnalysisTool/Network/Handler/NewEquipmentItemEventHandler.cs @@ -19,7 +19,7 @@ protected override async Task OnActionAsync(NewEquipmentItemEvent value) { if (_trackingController.IsTrackingAllowedByMainCharacter()) { - _trackingController.VaultController.Add(value.Item); + _trackingController.VaultController.AddDiscoveredItem(value.Item); } _trackingController.EntityController.AddEquipmentItem(new EquipmentItemInternal diff --git a/src/StatisticsAnalysisTool/Network/Handler/NewFurnitureItemEventHandler.cs b/src/StatisticsAnalysisTool/Network/Handler/NewFurnitureItemEventHandler.cs index a90646fe7..960454b1c 100644 --- a/src/StatisticsAnalysisTool/Network/Handler/NewFurnitureItemEventHandler.cs +++ b/src/StatisticsAnalysisTool/Network/Handler/NewFurnitureItemEventHandler.cs @@ -18,7 +18,7 @@ protected override async Task OnActionAsync(NewFurnitureItemEvent value) { if (_trackingController.IsTrackingAllowedByMainCharacter()) { - _trackingController.VaultController.Add(value.Item); + _trackingController.VaultController.AddDiscoveredItem(value.Item); } EstimatedMarketValueController.Add(value.Item.ItemIndex, value.Item.EstimatedMarketValueInternal, value.Item.Quality); diff --git a/src/StatisticsAnalysisTool/Network/Handler/NewJournalItemEventHandler.cs b/src/StatisticsAnalysisTool/Network/Handler/NewJournalItemEventHandler.cs index 4e4628f88..9900e878e 100644 --- a/src/StatisticsAnalysisTool/Network/Handler/NewJournalItemEventHandler.cs +++ b/src/StatisticsAnalysisTool/Network/Handler/NewJournalItemEventHandler.cs @@ -19,7 +19,7 @@ protected override async Task OnActionAsync(NewJournalItemEvent value) { if (_trackingController.IsTrackingAllowedByMainCharacter()) { - _trackingController.VaultController.Add(value.Item); + _trackingController.VaultController.AddDiscoveredItem(value.Item); } EstimatedMarketValueController.Add(value.Item.ItemIndex, value.Item.EstimatedMarketValueInternal, value.Item.Quality); diff --git a/src/StatisticsAnalysisTool/Network/Handler/NewKillTrophyItemHandler.cs b/src/StatisticsAnalysisTool/Network/Handler/NewKillTrophyItemHandler.cs index 0f960b9a9..50692e2f4 100644 --- a/src/StatisticsAnalysisTool/Network/Handler/NewKillTrophyItemHandler.cs +++ b/src/StatisticsAnalysisTool/Network/Handler/NewKillTrophyItemHandler.cs @@ -18,7 +18,7 @@ protected override async Task OnActionAsync(NewKillTrophyItemEvent value) { if (_trackingController.IsTrackingAllowedByMainCharacter()) { - _trackingController.VaultController.Add(value.Item); + _trackingController.VaultController.AddDiscoveredItem(value.Item); } EstimatedMarketValueController.Add(value.Item.ItemIndex, value.Item.EstimatedMarketValueInternal, value.Item.Quality); diff --git a/src/StatisticsAnalysisTool/Network/Handler/NewLaborerItemEventHandler.cs b/src/StatisticsAnalysisTool/Network/Handler/NewLaborerItemEventHandler.cs index b52e22d51..7a5b28ac1 100644 --- a/src/StatisticsAnalysisTool/Network/Handler/NewLaborerItemEventHandler.cs +++ b/src/StatisticsAnalysisTool/Network/Handler/NewLaborerItemEventHandler.cs @@ -18,7 +18,7 @@ protected override async Task OnActionAsync(NewLaborerItemEvent value) { if (_trackingController.IsTrackingAllowedByMainCharacter()) { - _trackingController.VaultController.Add(value.Item); + _trackingController.VaultController.AddDiscoveredItem(value.Item); } EstimatedMarketValueController.Add(value.Item.ItemIndex, value.Item.EstimatedMarketValueInternal, value.Item.Quality); diff --git a/src/StatisticsAnalysisTool/Network/Handler/NewSimpleItemEventHandler.cs b/src/StatisticsAnalysisTool/Network/Handler/NewSimpleItemEventHandler.cs index 1493c46b0..36a87cd49 100644 --- a/src/StatisticsAnalysisTool/Network/Handler/NewSimpleItemEventHandler.cs +++ b/src/StatisticsAnalysisTool/Network/Handler/NewSimpleItemEventHandler.cs @@ -18,7 +18,7 @@ protected override async Task OnActionAsync(NewSimpleItemEvent value) { if (_trackingController.IsTrackingAllowedByMainCharacter()) { - _trackingController.VaultController.Add(value.Item); + _trackingController.VaultController.AddDiscoveredItem(value.Item); } EstimatedMarketValueController.Add(value.Item.ItemIndex, value.Item.EstimatedMarketValueInternal, value.Item.Quality); diff --git a/src/StatisticsAnalysisTool/Network/Manager/TrackingController.cs b/src/StatisticsAnalysisTool/Network/Manager/TrackingController.cs index cd65a4157..e509b04ed 100644 --- a/src/StatisticsAnalysisTool/Network/Manager/TrackingController.cs +++ b/src/StatisticsAnalysisTool/Network/Manager/TrackingController.cs @@ -13,6 +13,7 @@ using StatisticsAnalysisTool.Localization; using StatisticsAnalysisTool.Network.PacketProviders; using StatisticsAnalysisTool.Party; +using StatisticsAnalysisTool.StorageHistory; using StatisticsAnalysisTool.Trade; using StatisticsAnalysisTool.Trade.Mails; using StatisticsAnalysisTool.Trade.Market; diff --git a/src/StatisticsAnalysisTool/StorageHistory/ContainerItem.cs b/src/StatisticsAnalysisTool/StorageHistory/ContainerItem.cs new file mode 100644 index 000000000..a760a2baf --- /dev/null +++ b/src/StatisticsAnalysisTool/StorageHistory/ContainerItem.cs @@ -0,0 +1,32 @@ +using StatisticsAnalysisTool.Common; +using StatisticsAnalysisTool.Models; +using StatisticsAnalysisTool.ViewModels; + +namespace StatisticsAnalysisTool.StorageHistory; + +public class ContainerItem : BaseViewModel +{ + private int _itemIndex; + private int _quantity; + + public int ItemIndex + { + get => _itemIndex; + set + { + _itemIndex = value; + OnPropertyChanged(); + } + } + + public int Quantity + { + get => _quantity; + set + { + _quantity = value; + OnPropertyChanged(); + } + } + public Item Item => ItemController.GetItemByIndex(ItemIndex); +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/StorageHistory/ContainerItemDto.cs b/src/StatisticsAnalysisTool/StorageHistory/ContainerItemDto.cs new file mode 100644 index 000000000..1b00629d5 --- /dev/null +++ b/src/StatisticsAnalysisTool/StorageHistory/ContainerItemDto.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; + +namespace StatisticsAnalysisTool.StorageHistory; + +public class ContainerItemDto +{ + [JsonPropertyName("I")] + public int ItemIndex { get; set; } + [JsonPropertyName("Q")] + public int Quantity { get; set; } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Models/NetworkModel/VaultInfo.cs b/src/StatisticsAnalysisTool/StorageHistory/InternalVault.cs similarity index 68% rename from src/StatisticsAnalysisTool/Models/NetworkModel/VaultInfo.cs rename to src/StatisticsAnalysisTool/StorageHistory/InternalVault.cs index 807ab9e5a..0f87fa67e 100644 --- a/src/StatisticsAnalysisTool/Models/NetworkModel/VaultInfo.cs +++ b/src/StatisticsAnalysisTool/StorageHistory/InternalVault.cs @@ -1,13 +1,13 @@ -using StatisticsAnalysisTool.Cluster; -using StatisticsAnalysisTool.GameFileData; -using System; +using System; using System.Collections.Generic; +using StatisticsAnalysisTool.Cluster; +using StatisticsAnalysisTool.GameFileData; -namespace StatisticsAnalysisTool.Models.NetworkModel; +namespace StatisticsAnalysisTool.StorageHistory; -public class VaultInfo +public class InternalVault { - public VaultInfo(long? objectId, string locationGuidString, List containerGuidList, List containerNames, List containerIconTags) + public InternalVault(long? objectId, string locationGuidString, List containerGuidList, List containerNames, List containerIconTags) { ObjectId = objectId; LocationGuidString = locationGuidString; @@ -24,4 +24,5 @@ public VaultInfo(long? objectId, string locationGuidString, List container public MapType MapType => WorldData.GetMapType(LocationGuidString); public string MainLocationIndex { get; set; } public string UniqueClusterName { get; set; } + public double RepairCosts { get; set; } } \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/StorageHistory/StorageHistoryMapping.cs b/src/StatisticsAnalysisTool/StorageHistory/StorageHistoryMapping.cs new file mode 100644 index 000000000..851d7c47c --- /dev/null +++ b/src/StatisticsAnalysisTool/StorageHistory/StorageHistoryMapping.cs @@ -0,0 +1,71 @@ +using System.Collections.ObjectModel; +using System.Linq; + +namespace StatisticsAnalysisTool.StorageHistory; + +public static class StorageHistoryMapping +{ + public static VaultDto Mapping(Vault vault) + { + return new VaultDto() + { + Location = vault.Location, + MainLocationIndex = vault.MainLocationIndex, + MapType = vault.MapType, + VaultContainer = vault.VaultContainer.Select(Mapping).ToList() + }; + } + + public static Vault Mapping(VaultDto vaultDto) + { + return new Vault() + { + Location = vaultDto.Location, + MainLocationIndex = vaultDto.MainLocationIndex, + MapType = vaultDto.MapType, + VaultContainer = vaultDto.VaultContainer.Select(Mapping).ToList() + }; + } + + public static VaultContainerDto Mapping(VaultContainer vaultContainer) + { + return new VaultContainerDto() + { + LastUpdate = vaultContainer.LastUpdate, + Guid = vaultContainer.Guid, + Name = vaultContainer.Name, + Icon = vaultContainer.Icon, + Items = vaultContainer.Items.Select(Mapping).ToList() + }; + } + + public static VaultContainer Mapping(VaultContainerDto vaultContainerDto) + { + return new VaultContainer() + { + LastUpdate = vaultContainerDto.LastUpdate, + Guid = vaultContainerDto.Guid, + Name = vaultContainerDto.Name, + Icon = vaultContainerDto.Icon, + Items = new ObservableCollection(vaultContainerDto.Items.Select(Mapping)) + }; + } + + public static ContainerItemDto Mapping(ContainerItem containerItem) + { + return new ContainerItemDto() + { + ItemIndex = containerItem.ItemIndex, + Quantity = containerItem.Quantity + }; + } + + public static ContainerItem Mapping(ContainerItemDto containerItemDto) + { + return new ContainerItem() + { + ItemIndex = containerItemDto.ItemIndex, + Quantity = containerItemDto.Quantity + }; + } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/StorageHistory/Vault.cs b/src/StatisticsAnalysisTool/StorageHistory/Vault.cs new file mode 100644 index 000000000..c46d7c87a --- /dev/null +++ b/src/StatisticsAnalysisTool/StorageHistory/Vault.cs @@ -0,0 +1,75 @@ +using StatisticsAnalysisTool.Cluster; +using StatisticsAnalysisTool.GameFileData; +using StatisticsAnalysisTool.Localization; +using StatisticsAnalysisTool.ViewModels; +using System.Collections.Generic; + +namespace StatisticsAnalysisTool.StorageHistory; + +public class Vault : BaseViewModel +{ + private string _location; + private string _mainLocationIndex; + private MapType _mapType; + private List _vaultContainer = new(); + + public string Location + { + get => _location; + set + { + _location = value; + OnPropertyChanged(); + } + } + + public string MainLocationIndex + { + get => _mainLocationIndex; + set + { + _mainLocationIndex = value; + OnPropertyChanged(); + } + } + + public MapType MapType + { + get => _mapType; + set + { + _mapType = value; + OnPropertyChanged(); + } + } + + public List VaultContainer + { + get => _vaultContainer; + set + { + _vaultContainer = value; + OnPropertyChanged(); + } + } + + public string MainLocation => WorldData.GetUniqueNameOrDefault(MainLocationIndex); + + public string LocationDisplayString + { + get + { + if (MapType is MapType.Hideout) + { + return $"{Location} ({LocalizationController.Translation("HIDEOUT")}) - {MainLocation}"; + } + + if (MapType is MapType.Island) + { + return $"{Location} ({LocalizationController.Translation("ISLAND")})"; + } + + return Location; + } + } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Models/BindingModel/VaultBindings.cs b/src/StatisticsAnalysisTool/StorageHistory/VaultBindings.cs similarity index 79% rename from src/StatisticsAnalysisTool/Models/BindingModel/VaultBindings.cs rename to src/StatisticsAnalysisTool/StorageHistory/VaultBindings.cs index 2fc33948f..587fa8e66 100644 --- a/src/StatisticsAnalysisTool/Models/BindingModel/VaultBindings.cs +++ b/src/StatisticsAnalysisTool/StorageHistory/VaultBindings.cs @@ -1,20 +1,21 @@ using StatisticsAnalysisTool.Common.UserSettings; -using StatisticsAnalysisTool.Models.NetworkModel; +using StatisticsAnalysisTool.Models; using StatisticsAnalysisTool.ViewModels; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Windows; using System.Windows.Data; -namespace StatisticsAnalysisTool.Models.BindingModel; +namespace StatisticsAnalysisTool.StorageHistory; public class VaultBindings : BaseViewModel { - private List _vaultContainerContent; - private List _vaults; + private ObservableCollection _vaultContainerContent; + private ObservableCollection _vaults; private Vault _vaultSelected; - private List _vaultContainer; + private ObservableCollection _vaultContainer; private VaultContainer _vaultContainerSelected; private Visibility _lastUpdateVisibility = Visibility.Hidden; private DateTime _lastUpdate; @@ -22,6 +23,7 @@ public class VaultBindings : BaseViewModel private ListCollectionView _vaultCollectionView; private List _vaultSearchList = new(); private string _searchText; + private double _repairCosts; public VaultBindings() { @@ -36,7 +38,7 @@ public VaultBindings() } } - public List Vaults + public ObservableCollection Vaults { get => _vaults; set @@ -52,17 +54,25 @@ public Vault VaultSelected set { _vaultSelected = value; - VaultContainer = _vaultSelected?.VaultContainer?.FindAll(x => x?.LastUpdate.Ticks > 0).OrderBy(y => y.Name).ToList(); + VaultContainer = new ObservableCollection( + _vaultSelected?.VaultContainer?.FindAll(x => x?.LastUpdate.Ticks > 0).OrderBy(y => y.Name).ToList() ?? + new List() + ); OnPropertyChanged(); } } - public List VaultContainer + public ObservableCollection VaultContainer { get => _vaultContainer; set { + var vaultContainerSelectedGuid = VaultContainerSelected?.Guid; _vaultContainer = value; + if (VaultContainerSelected is not null) + { + VaultContainerSelected = VaultContainer.FirstOrDefault(x => x?.Guid == vaultContainerSelectedGuid); + } OnPropertyChanged(); } } @@ -73,14 +83,14 @@ public VaultContainer VaultContainerSelected set { _vaultContainerSelected = value; - VaultContainerContent = _vaultContainer?.FirstOrDefault(x => x.Guid == _vaultContainerSelected.Guid)?.Items ?? new List(); + VaultContainerContent = _vaultContainer?.FirstOrDefault(x => x.Guid == _vaultContainerSelected?.Guid)?.Items ?? new ObservableCollection(); LastUpdate = _vaultContainerSelected?.LastUpdate ?? new DateTime(0); LastUpdateVisibility = _vaultContainerSelected?.LastUpdate.Ticks <= 1 ? Visibility.Hidden : Visibility.Visible; OnPropertyChanged(); } } - public List VaultContainerContent + public ObservableCollection VaultContainerContent { get => _vaultContainerContent; set @@ -161,7 +171,7 @@ public GridLength GridSplitterPosition OnPropertyChanged(); } } - + #region Filter private bool Filter(object obj) diff --git a/src/StatisticsAnalysisTool/StorageHistory/VaultContainer.cs b/src/StatisticsAnalysisTool/StorageHistory/VaultContainer.cs new file mode 100644 index 000000000..0938b2cf8 --- /dev/null +++ b/src/StatisticsAnalysisTool/StorageHistory/VaultContainer.cs @@ -0,0 +1,75 @@ +using StatisticsAnalysisTool.ViewModels; +using System; +using System.Collections.ObjectModel; + +namespace StatisticsAnalysisTool.StorageHistory; + +public class VaultContainer : BaseViewModel +{ + private DateTime _lastUpdate; + private Guid _guid; + private string _name; + private string _icon; + private ObservableCollection _items = new(); + private double _repairCosts; + + public DateTime LastUpdate + { + get => _lastUpdate; + set + { + _lastUpdate = value; + OnPropertyChanged(); + } + } + + public Guid Guid + { + get => _guid; + set + { + _guid = value; + OnPropertyChanged(); + } + } + + public string Name + { + get => _name; + set + { + _name = value; + OnPropertyChanged(); + } + } + + public string Icon + { + get => _icon; + set + { + _icon = value; + OnPropertyChanged(); + } + } + + public ObservableCollection Items + { + get => _items; + set + { + _items = value; + OnPropertyChanged(); + } + } + + public double RepairCosts + { + get => _repairCosts; + set + { + _repairCosts = value; + OnPropertyChanged(); + } + } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Models/NetworkModel/VaultContainer.cs b/src/StatisticsAnalysisTool/StorageHistory/VaultContainerDto.cs similarity index 59% rename from src/StatisticsAnalysisTool/Models/NetworkModel/VaultContainer.cs rename to src/StatisticsAnalysisTool/StorageHistory/VaultContainerDto.cs index cb3709b23..e3aeb871b 100644 --- a/src/StatisticsAnalysisTool/Models/NetworkModel/VaultContainer.cs +++ b/src/StatisticsAnalysisTool/StorageHistory/VaultContainerDto.cs @@ -1,13 +1,13 @@ using System; using System.Collections.Generic; -namespace StatisticsAnalysisTool.Models.NetworkModel; +namespace StatisticsAnalysisTool.StorageHistory; -public class VaultContainer +public class VaultContainerDto { public DateTime LastUpdate { get; set; } public Guid Guid { get; set; } public string Name { get; set; } public string Icon { get; set; } - public List Items { get; set; } = new (); + public List Items { get; set; } = new(); } \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs b/src/StatisticsAnalysisTool/StorageHistory/VaultController.cs similarity index 53% rename from src/StatisticsAnalysisTool/Network/Manager/VaultController.cs rename to src/StatisticsAnalysisTool/StorageHistory/VaultController.cs index b3ae93099..a3863fd82 100644 --- a/src/StatisticsAnalysisTool/Network/Manager/VaultController.cs +++ b/src/StatisticsAnalysisTool/StorageHistory/VaultController.cs @@ -15,31 +15,21 @@ using System.Threading.Tasks; using System.Windows; -namespace StatisticsAnalysisTool.Network.Manager; +namespace StatisticsAnalysisTool.StorageHistory; public class VaultController { private readonly MainWindowViewModel _mainWindowViewModel; - private VaultInfo _currentVaultInfo; + private InternalVault _currentInternalVault; private readonly List _discoveredItems = new(); - private readonly List _vaultContainer = new(); - private ObservableCollection _vault = new(); - - private ObservableCollection Vaults - { - get => _vault; - set - { - _vault = value; - OnVaultsChange?.Invoke(); - } - } + private readonly List _internalItemContainers = new(); + private readonly VaultBindings _vaultBindings; public VaultController(MainWindowViewModel mainWindowViewModel) { _mainWindowViewModel = mainWindowViewModel; + _vaultBindings = _mainWindowViewModel.VaultBindings; - OnVaultsChange += UpdateUi; OnVaultsChange += UpdateSearchListUiAsync; OnVaultsRemove += UpdateSearchListUiAsync; } @@ -47,24 +37,24 @@ public VaultController(MainWindowViewModel mainWindowViewModel) public event Action OnVaultsChange; public event Action OnVaultsRemove; - public void SetCurrentVault(VaultInfo vaultInfo) + public void SetCurrentVault(InternalVault internalVault) { - if (vaultInfo == null) + if (internalVault == null) { - _currentVaultInfo = null; + _currentInternalVault = null; return; } - vaultInfo.UniqueClusterName = ClusterController.CurrentCluster.UniqueClusterName; - vaultInfo.MainLocationIndex = ClusterController.CurrentCluster.MainClusterIndex; + internalVault.UniqueClusterName = ClusterController.CurrentCluster.UniqueClusterName; + internalVault.MainLocationIndex = ClusterController.CurrentCluster.MainClusterIndex; - if (string.IsNullOrEmpty(vaultInfo.UniqueClusterName)) + if (string.IsNullOrEmpty(internalVault.UniqueClusterName)) { - _currentVaultInfo = null; + _currentInternalVault = null; return; } - _currentVaultInfo = vaultInfo; + _currentInternalVault = internalVault; } public void AddContainer(ItemContainerObject newContainerObject) @@ -74,18 +64,19 @@ public void AddContainer(ItemContainerObject newContainerObject) return; } - var container = _vaultContainer.FirstOrDefault(x => x.PrivateContainerGuid == newContainerObject.PrivateContainerGuid); + var container = _internalItemContainers.FirstOrDefault(x => x.PrivateContainerGuid == newContainerObject.PrivateContainerGuid); if (container != null) { - _vaultContainer.Remove(container); + _internalItemContainers.Remove(container); } - _vaultContainer.Add(newContainerObject); - ParseVault(); - GetRepairCostsOfContainer(newContainerObject); + SetRepairCostsOfContainer(newContainerObject); + + _internalItemContainers.Add(newContainerObject); + UpdateUi(); } - public void Add(DiscoveredItem item) + public void AddDiscoveredItem(DiscoveredItem item) { if (_discoveredItems.Exists(x => x.ObjectId == item.ObjectId)) { @@ -95,9 +86,9 @@ public void Add(DiscoveredItem item) _discoveredItems.Add(item); } - public void ResetVaultContainer() + public void ResetInternalVaultContainer() { - _vaultContainer.Clear(); + _internalItemContainers.Clear(); } public void ResetDiscoveredItems() @@ -105,9 +96,9 @@ public void ResetDiscoveredItems() _discoveredItems.Clear(); } - public void ResetCurrentVaultInfo() + public void ResetCurrentInternalVault() { - _currentVaultInfo = null; + _currentInternalVault = null; } public void RemoveVault(Vault vault) @@ -117,69 +108,103 @@ public void RemoveVault(Vault vault) return; } - foreach (var removableContainer in vault.VaultContainer.Select(container => _vaultContainer?.FirstOrDefault(x => x?.PrivateContainerGuid == container?.Guid))) + foreach (var removableContainer in vault.VaultContainer.Select(container => _internalItemContainers?.FirstOrDefault(x => x?.PrivateContainerGuid == container?.Guid))) { - _vaultContainer?.Remove(removableContainer); + _internalItemContainers?.Remove(removableContainer); } - _vault.Remove(vault); - OnVaultsRemove?.Invoke(); + Application.Current.Dispatcher.Invoke(() => + { + _vaultBindings.Vaults.Remove(vault); + }); - UpdateUi(); + OnVaultsRemove?.Invoke(); } - private void ParseVault() + #region Ui + + private void UpdateUi() { - if (_currentVaultInfo == null) + if (_currentInternalVault == null) { return; } - var removableVaultInfo = Vaults.FirstOrDefault(x => x.Location == _currentVaultInfo.UniqueClusterName); + var vaultSelected = _vaultBindings.VaultSelected; + var vaultContainerSelectedGuid = _vaultBindings.VaultContainerSelected?.Guid; - if (removableVaultInfo != null) + var currentVault = _vaultBindings.Vaults.FirstOrDefault(x => x.Location == _currentInternalVault.UniqueClusterName); + if (currentVault is not null) { - Vaults.Remove(removableVaultInfo); - } + var vaultContainers = PreparationVaultContainerForUi(_internalItemContainers); - var vault = new Vault() + Application.Current.Dispatcher.Invoke(() => + { + currentVault.VaultContainer.Clear(); + currentVault.VaultContainer.AddRange(vaultContainers); + }); + } + else { - Location = _currentVaultInfo.UniqueClusterName, - MainLocationIndex = _currentVaultInfo.MainLocationIndex, - MapType = _currentVaultInfo.MapType - }; + var vault = new Vault() + { + Location = _currentInternalVault.UniqueClusterName, + MainLocationIndex = _currentInternalVault.MainLocationIndex, + MapType = _currentInternalVault.MapType + }; - try - { - for (var i = 0; i < _currentVaultInfo.ContainerGuidList.Count; i++) + try { - var vaultContainer = new VaultContainer() - { - Guid = _currentVaultInfo.ContainerGuidList[i], - Icon = _currentVaultInfo.ContainerIconTags[i], - Name = (_currentVaultInfo.ContainerNames[i] == "@BUILDINGS_T1_BANK") ? LocalizationController.Translation("BANK") : _currentVaultInfo.ContainerNames[i] - }; + var vaultContainers = PreparationVaultContainerForUi(_internalItemContainers); + vault.VaultContainer.AddRange(vaultContainers); - var itemContainer = _vaultContainer.FirstOrDefault(x => x.PrivateContainerGuid == vaultContainer.Guid); - if (itemContainer != null) + Application.Current.Dispatcher.Invoke(() => { - vaultContainer.LastUpdate = itemContainer.LastUpdate; - SetItemsToVaultContainer(itemContainer, vaultContainer, _discoveredItems); - } - - vault.VaultContainer.Add(vaultContainer); + _vaultBindings.Vaults.Add(vault); + }); + } + catch (Exception e) + { + ConsoleManager.WriteLineForError(MethodBase.GetCurrentMethod()?.DeclaringType, e); } - - Vaults.Add(vault); - OnVaultsChange?.Invoke(); } - catch (Exception e) + + _vaultBindings.VaultSelected = _vaultBindings.Vaults.Contains(vaultSelected) ? vaultSelected : default; + _vaultBindings.VaultContainerSelected = _vaultBindings.VaultContainer.FirstOrDefault(x => x?.Guid == vaultContainerSelectedGuid); + + OnVaultsChange?.Invoke(); + } + + private IEnumerable PreparationVaultContainerForUi(IReadOnlyCollection itemContainers) + { + var vaultContainers = new List(); + + for (var i = 0; i < _currentInternalVault.ContainerGuidList.Count; i++) { - ConsoleManager.WriteLineForError(MethodBase.GetCurrentMethod()?.DeclaringType, e); + var vaultContainer = new VaultContainer() + { + Guid = _currentInternalVault.ContainerGuidList[i], + Icon = _currentInternalVault.ContainerIconTags[i], + Name = _currentInternalVault.ContainerNames[i] == "@BUILDINGS_T1_BANK" + ? LocalizationController.Translation("BANK") + : _currentInternalVault.ContainerNames[i] + }; + + var itemContainer = itemContainers.FirstOrDefault(x => x.PrivateContainerGuid == vaultContainer.Guid); + if (itemContainer != null) + { + vaultContainer.LastUpdate = itemContainer.LastUpdate; + SetItemsToVaultContainerForUi(itemContainer, vaultContainer, _discoveredItems); + vaultContainer.RepairCosts = itemContainer.RepairCosts; + } + + vaultContainers.Add(vaultContainer); } + + return vaultContainers; } - private void SetItemsToVaultContainer(ItemContainerObject containerObject, VaultContainer vaultContainer, List discoveredItems) + private void SetItemsToVaultContainerForUi(ItemContainerObject containerObject, VaultContainer vaultContainer, IReadOnlyCollection discoveredItems) { foreach (var slotItemId in containerObject?.SlotItemIds ?? new List()) { @@ -204,21 +229,11 @@ private void SetItemsToVaultContainer(ItemContainerObject containerObject, Vault } } - #region Ui - - private void UpdateUi() - { - Application.Current.Dispatcher.Invoke(() => - { - _mainWindowViewModel.VaultBindings.Vaults = Vaults.ToList(); - }); - } - private async void UpdateSearchListUiAsync() { var vaultSearchItem = new List(); - await foreach (var vault in Vaults.ToList().ToAsyncEnumerable()) + await foreach (var vault in _vaultBindings.Vaults.ToList().ToAsyncEnumerable()) { var tempItems = new List(); @@ -250,19 +265,19 @@ private async void UpdateSearchListUiAsync() Application.Current.Dispatcher.Invoke(() => { - _mainWindowViewModel.VaultBindings.VaultSearchList.Clear(); - _mainWindowViewModel.VaultBindings.VaultSearchList.AddRange(vaultSearchItem); + _vaultBindings.VaultSearchList.Clear(); + _vaultBindings.VaultSearchList.AddRange(vaultSearchItem); _mainWindowViewModel?.VaultBindings?.VaultSearchCollectionView?.Refresh(); }); } - + #endregion #region Repair costs calculation private const double RepairCostModifier = 6.0606d; - private void GetRepairCostsOfContainer(ItemContainerObject newContainerObject) + private void SetRepairCostsOfContainer(ItemContainerObject newContainerObject) { var discoveredItems = new List(); foreach (var slotItemId in newContainerObject.SlotItemIds) @@ -304,18 +319,18 @@ private void GetRepairCostsOfContainer(ItemContainerObject newContainerObject) continue; } - var repairCosts = Math.Round((itemValue / RepairCostModifier * lostDurability), MidpointRounding.ToPositiveInfinity); + var repairCosts = Math.Round(itemValue / RepairCostModifier * lostDurability, MidpointRounding.ToPositiveInfinity); totalCosts += repairCosts * discoveredItem.Quantity; } try { - _mainWindowViewModel.DashboardBindings.RepairCostsChest = Convert.ToInt32(totalCosts); + newContainerObject.RepairCosts = totalCosts; } - catch + catch (Exception e) { - // ignore + ConsoleManager.WriteLineForError(MethodBase.GetCurrentMethod()?.DeclaringType, e); } } @@ -326,14 +341,21 @@ private void GetRepairCostsOfContainer(ItemContainerObject newContainerObject) public async Task LoadFromFileAsync() { FileController.TransferFileIfExistFromOldPathToUserDataDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Settings.Default.VaultsFileName)); - Vaults = await FileController.LoadAsync>( - Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Settings.Default.UserDataDirectoryName, Settings.Default.VaultsFileName)); + + var vaultDtos = await FileController.LoadAsync>(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Settings.Default.UserDataDirectoryName, Settings.Default.VaultsFileName)); + _vaultBindings.Vaults = new ObservableCollection(vaultDtos.Select(StorageHistoryMapping.Mapping)); } public async Task SaveInFileAsync() { DirectoryController.CreateDirectoryWhenNotExists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Settings.Default.UserDataDirectoryName)); - await FileController.SaveAsync(Vaults, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Settings.Default.UserDataDirectoryName, Settings.Default.VaultsFileName)); + + var vaultDtosToSave = _vaultBindings.Vaults + .ToList() + .Select(StorageHistoryMapping.Mapping); + + await FileController.SaveAsync(vaultDtosToSave, + Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Settings.Default.UserDataDirectoryName, Settings.Default.VaultsFileName)); Debug.Print("Vault saved"); } diff --git a/src/StatisticsAnalysisTool/StorageHistory/VaultDto.cs b/src/StatisticsAnalysisTool/StorageHistory/VaultDto.cs new file mode 100644 index 000000000..73f11fedc --- /dev/null +++ b/src/StatisticsAnalysisTool/StorageHistory/VaultDto.cs @@ -0,0 +1,12 @@ +using StatisticsAnalysisTool.Cluster; +using System.Collections.Generic; + +namespace StatisticsAnalysisTool.StorageHistory; + +public class VaultDto +{ + public string Location { get; set; } + public string MainLocationIndex { get; set; } + public MapType MapType { get; set; } + public List VaultContainer { get; set; } = new(); +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Styles/DashboardStyles.xaml b/src/StatisticsAnalysisTool/Styles/DashboardStyles.xaml index ba46cc3f8..c1b75709a 100644 --- a/src/StatisticsAnalysisTool/Styles/DashboardStyles.xaml +++ b/src/StatisticsAnalysisTool/Styles/DashboardStyles.xaml @@ -469,10 +469,6 @@ Foreground="{StaticResource SolidColorBrush.Accent.Red.3}" VerticalAlignment="Center" Margin="0,0,10,0" /> - - diff --git a/src/StatisticsAnalysisTool/Styles/GuildStyles.xaml b/src/StatisticsAnalysisTool/Styles/GuildStyles.xaml index 16690a99c..31e9e500c 100644 --- a/src/StatisticsAnalysisTool/Styles/GuildStyles.xaml +++ b/src/StatisticsAnalysisTool/Styles/GuildStyles.xaml @@ -2,9 +2,10 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:networkModel="clr-namespace:StatisticsAnalysisTool.Models.NetworkModel" xmlns:guild="clr-namespace:StatisticsAnalysisTool.Guild" - xmlns:common="clr-namespace:StatisticsAnalysisTool.Common"> + xmlns:common="clr-namespace:StatisticsAnalysisTool.Common" + xmlns:storageHistory="clr-namespace:StatisticsAnalysisTool.StorageHistory"> - + diff --git a/src/StatisticsAnalysisTool/Styles/StorageHistoryStyle.xaml b/src/StatisticsAnalysisTool/Styles/StorageHistoryStyle.xaml index e96c0e274..44e41c78c 100644 --- a/src/StatisticsAnalysisTool/Styles/StorageHistoryStyle.xaml +++ b/src/StatisticsAnalysisTool/Styles/StorageHistoryStyle.xaml @@ -1,9 +1,10 @@  + xmlns:networkModel="clr-namespace:StatisticsAnalysisTool.Models.NetworkModel" + xmlns:storageHistory="clr-namespace:StatisticsAnalysisTool.StorageHistory"> - + diff --git a/src/StatisticsAnalysisTool/UserControls/StorageHistoryControl.xaml b/src/StatisticsAnalysisTool/UserControls/StorageHistoryControl.xaml index c54a315ad..0f4eb7742 100644 --- a/src/StatisticsAnalysisTool/UserControls/StorageHistoryControl.xaml +++ b/src/StatisticsAnalysisTool/UserControls/StorageHistoryControl.xaml @@ -21,11 +21,11 @@ - + - +