From df8e325f904787a3c17b3a3f85774c176b5a900f Mon Sep 17 00:00:00 2001 From: Jos Demmers Date: Sun, 5 Feb 2023 16:17:13 +0100 Subject: [PATCH] - Added status for loaded game data during startup. - Fixed issue that allowed you to launch the app multiple times. - Improved startup time. - Moved game data. --- .../CraftingRecipeManagerEvents.cs | 8 ++ .../NewWorldDataStoreEvents.cs | 12 +++ .../ICraftingRecipeManager.cs | 2 + .../INewWorldDataStore.cs | 7 ++ .../CraftingRecipeManager.cs | 19 +++- .../NewWorldCompanion.Services.csproj | 28 ----- .../NewWorldDataStore.cs | 99 +++++++++++++----- NewWorldCompanion.Services/OcrHandler.cs | 2 +- NewWorldCompanion.Services/OverlayHandler.cs | 20 ++-- .../ScreenCaptureHandler.cs | 7 +- NewWorldCompanion.Services/VersionManager.cs | 9 +- NewWorldCompanion/App.xaml.cs | 23 +++- .../Data/CraftingRecipes.json | 0 .../Data/HouseItems.json | 0 .../Data/MasterItemDefinitions_Common.json | 0 .../Data/MasterItemDefinitions_Crafting.json | 0 .../Data/MasterItemDefinitions_Loot.json | 0 .../Data/MasterItemDefinitions_Quest.json | 0 .../Data/javelindata_housingitems.loc.xml | 0 ...javelindata_itemdefinitions_master.loc.xml | 0 NewWorldCompanion/NewWorldCompanion.csproj | 24 +++++ .../ViewModels/MainWindowViewModel.cs | 29 ++++- .../Tabs/Config/ConfigOverlayViewModel.cs | 15 ++- .../ViewModels/Tabs/CraftingViewModel.cs | 22 ++-- .../Tabs/Debug/DebugScreenProcessViewModel.cs | 23 +++- .../ViewModels/Tabs/StorageViewModel.cs | 2 +- NewWorldCompanion/Views/MainWindow.xaml | 67 +++++++----- .../Tabs/Debug/DebugScreenProcessView.xaml | 3 +- NewWorldCompanion/common.props | 4 +- readme/ServiceDependencies.drawio.png | Bin 0 -> 67916 bytes 30 files changed, 291 insertions(+), 134 deletions(-) create mode 100644 NewWorldCompanion.Events/CraftingRecipeManagerEvents.cs create mode 100644 NewWorldCompanion.Events/NewWorldDataStoreEvents.cs rename {NewWorldCompanion.Services => NewWorldCompanion}/Data/CraftingRecipes.json (100%) rename {NewWorldCompanion.Services => NewWorldCompanion}/Data/HouseItems.json (100%) rename {NewWorldCompanion.Services => NewWorldCompanion}/Data/MasterItemDefinitions_Common.json (100%) rename {NewWorldCompanion.Services => NewWorldCompanion}/Data/MasterItemDefinitions_Crafting.json (100%) rename {NewWorldCompanion.Services => NewWorldCompanion}/Data/MasterItemDefinitions_Loot.json (100%) rename {NewWorldCompanion.Services => NewWorldCompanion}/Data/MasterItemDefinitions_Quest.json (100%) rename {NewWorldCompanion.Services => NewWorldCompanion}/Data/javelindata_housingitems.loc.xml (100%) rename {NewWorldCompanion.Services => NewWorldCompanion}/Data/javelindata_itemdefinitions_master.loc.xml (100%) create mode 100644 readme/ServiceDependencies.drawio.png diff --git a/NewWorldCompanion.Events/CraftingRecipeManagerEvents.cs b/NewWorldCompanion.Events/CraftingRecipeManagerEvents.cs new file mode 100644 index 0000000..7b38442 --- /dev/null +++ b/NewWorldCompanion.Events/CraftingRecipeManagerEvents.cs @@ -0,0 +1,8 @@ +using Prism.Events; + +namespace NewWorldCompanion.Events +{ + public class CraftingRecipeManagerUpdated : PubSubEvent + { + } +} \ No newline at end of file diff --git a/NewWorldCompanion.Events/NewWorldDataStoreEvents.cs b/NewWorldCompanion.Events/NewWorldDataStoreEvents.cs new file mode 100644 index 0000000..909bae5 --- /dev/null +++ b/NewWorldCompanion.Events/NewWorldDataStoreEvents.cs @@ -0,0 +1,12 @@ +using Prism.Events; + +namespace NewWorldCompanion.Events +{ + public class NewWorldDataStoreUpdated : PubSubEvent + { + } + + public class NewWorldDataStoreStatusUpdated : PubSubEvent + { + } +} \ No newline at end of file diff --git a/NewWorldCompanion.Interfaces/ICraftingRecipeManager.cs b/NewWorldCompanion.Interfaces/ICraftingRecipeManager.cs index 55687ee..b90189b 100644 --- a/NewWorldCompanion.Interfaces/ICraftingRecipeManager.cs +++ b/NewWorldCompanion.Interfaces/ICraftingRecipeManager.cs @@ -5,6 +5,8 @@ namespace NewWorldCompanion.Interfaces { public interface ICraftingRecipeManager { + bool Available { get; } + List CraftingRecipes { get; diff --git a/NewWorldCompanion.Interfaces/INewWorldDataStore.cs b/NewWorldCompanion.Interfaces/INewWorldDataStore.cs index f29813e..fb61c83 100644 --- a/NewWorldCompanion.Interfaces/INewWorldDataStore.cs +++ b/NewWorldCompanion.Interfaces/INewWorldDataStore.cs @@ -9,6 +9,12 @@ namespace NewWorldCompanion.Interfaces { public interface INewWorldDataStore { + bool Available { get; } + string LoadStatusItemDefinitions { get; } + string LoadStatusCraftingRecipes { get; } + string LoadStatusHouseItems { get; } + string LoadStatusLocalisation { get; } + List GetCraftingRecipes(); bool IsBindOnPickup(string itemName); string GetItemId(string itemName); @@ -18,5 +24,6 @@ public interface INewWorldDataStore string GetItemLocalisation(string itemMasterName); List GetRelatedRecipes(string itemId); CraftingRecipeJson GetCraftingRecipeDetails(string itemId); + void UpdateStoreData(); } } diff --git a/NewWorldCompanion.Services/CraftingRecipeManager.cs b/NewWorldCompanion.Services/CraftingRecipeManager.cs index 6fb18e8..3a89ed6 100644 --- a/NewWorldCompanion.Services/CraftingRecipeManager.cs +++ b/NewWorldCompanion.Services/CraftingRecipeManager.cs @@ -1,4 +1,5 @@ using NewWorldCompanion.Entities; +using NewWorldCompanion.Events; using NewWorldCompanion.Interfaces; using Prism.Events; using System; @@ -16,6 +17,8 @@ public class CraftingRecipeManager : ICraftingRecipeManager private List _craftingRecipes = new List(); + private bool _available = false; + // Start of Constructor region #region Constructor @@ -24,12 +27,10 @@ public CraftingRecipeManager(IEventAggregator eventAggregator, INewWorldDataStor { // Init IEventAggregator _eventAggregator = eventAggregator; + _eventAggregator.GetEvent().Subscribe(HandleNewWorldDataStoreUpdatedEvent); // Init stores _newWorldDataStore = newWorldDataStore; - - // Init recipes - LoadRecipes(); } #endregion @@ -40,12 +41,20 @@ public CraftingRecipeManager(IEventAggregator eventAggregator, INewWorldDataStor public List CraftingRecipes { get => _craftingRecipes; } + public bool Available { get => _available; set => _available = value; } + #endregion // Start of Events region #region Events + private void HandleNewWorldDataStoreUpdatedEvent() + { + // Init recipes + LoadRecipes(); + } + #endregion // Start of Methods region @@ -89,6 +98,10 @@ private void LoadRecipes() // Save recipe progress SaveRecipes(); + + // Finished initializing data. Inform subscribers. + Available = true; + _eventAggregator.GetEvent().Publish(); } public void SaveRecipes() diff --git a/NewWorldCompanion.Services/NewWorldCompanion.Services.csproj b/NewWorldCompanion.Services/NewWorldCompanion.Services.csproj index e1c578d..54d8885 100644 --- a/NewWorldCompanion.Services/NewWorldCompanion.Services.csproj +++ b/NewWorldCompanion.Services/NewWorldCompanion.Services.csproj @@ -8,17 +8,6 @@ true - - - - - - - - - - - @@ -38,21 +27,4 @@ - - - Never - - - - - Never - - - - Never - - - - - diff --git a/NewWorldCompanion.Services/NewWorldDataStore.cs b/NewWorldCompanion.Services/NewWorldDataStore.cs index c6bd7aa..0335a8e 100644 --- a/NewWorldCompanion.Services/NewWorldDataStore.cs +++ b/NewWorldCompanion.Services/NewWorldDataStore.cs @@ -1,5 +1,6 @@ using NewWorldCompanion.Constants; using NewWorldCompanion.Entities; +using NewWorldCompanion.Events; using NewWorldCompanion.Helpers; using NewWorldCompanion.Interfaces; using Prism.Events; @@ -12,6 +13,7 @@ using System.Text; using System.Text.Json; using System.Threading.Tasks; +using System.Windows.Shapes; using System.Xml.Linq; namespace NewWorldCompanion.Services @@ -25,6 +27,14 @@ public class NewWorldDataStore : INewWorldDataStore private List _houseItemsJson = new List(); private Dictionary _itemDefinitionsLocalisation = new Dictionary(); + private bool _available = false; + + private string _loadStatusItemDefinitions = string.Empty; + private string _loadStatusCraftingRecipes = string.Empty; + private string _loadStatusHouseItems = string.Empty; + private string _loadStatusLocalisation = string.Empty; + + // Start of Constructor region #region Constructor @@ -35,7 +45,7 @@ public NewWorldDataStore(IEventAggregator eventAggregator) _eventAggregator = eventAggregator; // Init store data - UpdateStoreData(); + Task.Run(() => UpdateStoreData()); } #endregion @@ -44,23 +54,31 @@ public NewWorldDataStore(IEventAggregator eventAggregator) #region Properties + public bool Available { get => _available; set => _available = value; } + public string LoadStatusItemDefinitions { get => _loadStatusItemDefinitions; set => _loadStatusItemDefinitions = value; } + public string LoadStatusCraftingRecipes { get => _loadStatusCraftingRecipes; set => _loadStatusCraftingRecipes = value; } + public string LoadStatusHouseItems { get => _loadStatusHouseItems; set => _loadStatusHouseItems = value; } + public string LoadStatusLocalisation { get => _loadStatusLocalisation; set => _loadStatusLocalisation = value; } + #endregion // Start of Methods region #region Methods - private void UpdateStoreData() + public void UpdateStoreData() { var assembly = Assembly.GetExecutingAssembly(); string resourcePath = string.Empty; + _loadStatusItemDefinitions = $"ItemDefinitions: 0. Loading common items"; + _eventAggregator.GetEvent().Publish(); + // MasterItemDefinitions Common _masterItemDefinitionsJson.Clear(); var masterItemDefinitionsJson = new List(); - resourcePath = "MasterItemDefinitions_Common.json"; - resourcePath = assembly.GetManifestResourceNames().Single(str => str.EndsWith(resourcePath)); - using (Stream? stream = assembly.GetManifestResourceStream(resourcePath)) + resourcePath = @".\Data\MasterItemDefinitions_Common.json"; + using (FileStream? stream = File.OpenRead(resourcePath)) { if (stream != null) { @@ -78,11 +96,13 @@ private void UpdateStoreData() } } + _loadStatusItemDefinitions = $"ItemDefinitions: {_masterItemDefinitionsJson.Count}. Loading crafting items"; + _eventAggregator.GetEvent().Publish(); + // MasterItemDefinitions Crafting masterItemDefinitionsJson.Clear(); - resourcePath = "MasterItemDefinitions_Crafting.json"; - resourcePath = assembly.GetManifestResourceNames().Single(str => str.EndsWith(resourcePath)); - using (Stream? stream = assembly.GetManifestResourceStream(resourcePath)) + resourcePath = @".\Data\MasterItemDefinitions_Crafting.json"; + using (FileStream? stream = File.OpenRead(resourcePath)) { if (stream != null) { @@ -100,11 +120,13 @@ private void UpdateStoreData() } } + _loadStatusItemDefinitions = $"ItemDefinitions: {_masterItemDefinitionsJson.Count}. Loading loot items"; + _eventAggregator.GetEvent().Publish(); + // MasterItemDefinitions Loot masterItemDefinitionsJson.Clear(); - resourcePath = "MasterItemDefinitions_Loot.json"; - resourcePath = assembly.GetManifestResourceNames().Single(str => str.EndsWith(resourcePath)); - using (Stream? stream = assembly.GetManifestResourceStream(resourcePath)) + resourcePath = @".\Data\MasterItemDefinitions_Loot.json"; + using (FileStream? stream = File.OpenRead(resourcePath)) { if (stream != null) { @@ -122,11 +144,13 @@ private void UpdateStoreData() } } + _loadStatusItemDefinitions = $"ItemDefinitions: {_masterItemDefinitionsJson.Count}. Loading quest items"; + _eventAggregator.GetEvent().Publish(); + // MasterItemDefinitions Quest masterItemDefinitionsJson.Clear(); - resourcePath = "MasterItemDefinitions_Quest.json"; - resourcePath = assembly.GetManifestResourceNames().Single(str => str.EndsWith(resourcePath)); - using (Stream? stream = assembly.GetManifestResourceStream(resourcePath)) + resourcePath = @".\Data\MasterItemDefinitions_Quest.json"; + using (FileStream? stream = File.OpenRead(resourcePath)) { if (stream != null) { @@ -144,11 +168,14 @@ private void UpdateStoreData() } } + _loadStatusItemDefinitions = $"ItemDefinitions: {_masterItemDefinitionsJson.Count}"; + _loadStatusCraftingRecipes = $"CraftingRecipes: 0. Loading recipes"; + _eventAggregator.GetEvent().Publish(); + // CraftingRecipe Json _craftingRecipesJson.Clear(); - resourcePath = "CraftingRecipes.json"; - resourcePath = assembly.GetManifestResourceNames().Single(str => str.EndsWith(resourcePath)); - using (Stream? stream = assembly.GetManifestResourceStream(resourcePath)) + resourcePath = @".\Data\CraftingRecipes.json"; + using (FileStream? stream = File.OpenRead(resourcePath)) { if (stream != null) { @@ -165,11 +192,14 @@ private void UpdateStoreData() } } + _loadStatusCraftingRecipes = $"CraftingRecipes: {_craftingRecipesJson.Count}"; + _loadStatusHouseItems = $"HouseItems: 0. Loading items"; + _eventAggregator.GetEvent().Publish(); + // HouseItems Json _houseItemsJson.Clear(); - resourcePath = "HouseItems.json"; - resourcePath = assembly.GetManifestResourceNames().Single(str => str.EndsWith(resourcePath)); - using (Stream? stream = assembly.GetManifestResourceStream(resourcePath)) + resourcePath = @".\Data\HouseItems.json"; + using (FileStream? stream = File.OpenRead(resourcePath)) { if (stream != null) { @@ -177,11 +207,14 @@ private void UpdateStoreData() } } + _loadStatusHouseItems = $"HouseItems: {_houseItemsJson.Count}"; + _loadStatusLocalisation = $"Localisation: 0. Loading localisations"; + _eventAggregator.GetEvent().Publish(); + // ItemDefinitionsLocalisation - Itemdefinitions _itemDefinitionsLocalisation.Clear(); - resourcePath = "javelindata_itemdefinitions_master.loc.xml"; - resourcePath = assembly.GetManifestResourceNames().Single(str => str.EndsWith(resourcePath)); - using (Stream? stream = assembly.GetManifestResourceStream(resourcePath)) + resourcePath = @".\Data\javelindata_itemdefinitions_master.loc.xml"; + using (FileStream? stream = File.OpenRead(resourcePath)) { if (stream != null) { @@ -204,6 +237,9 @@ private void UpdateStoreData() { _itemDefinitionsLocalisation.TryAdd(key.ToLower(), value); } + + _loadStatusLocalisation = $"Localisation data: {_itemDefinitionsLocalisation.Count}"; + _eventAggregator.GetEvent().Publish(); } } } @@ -214,9 +250,8 @@ private void UpdateStoreData() _itemDefinitionsLocalisation.Remove("ArrowBT5_MasterName".ToLower()); // ItemDefinitionsLocalisation - HouseItems - resourcePath = "javelindata_housingitems.loc.xml"; - resourcePath = assembly.GetManifestResourceNames().Single(str => str.EndsWith(resourcePath)); - using (Stream? stream = assembly.GetManifestResourceStream(resourcePath)) + resourcePath = @".\Data\javelindata_housingitems.loc.xml"; + using (FileStream? stream = File.OpenRead(resourcePath)) { if (stream != null) { @@ -236,9 +271,16 @@ private void UpdateStoreData() { _itemDefinitionsLocalisation.TryAdd(key.ToLower(), value); } + + _loadStatusLocalisation = $"Localisation data: {_itemDefinitionsLocalisation.Count}"; + _eventAggregator.GetEvent().Publish(); } } } + + // Finished initializing data. Inform subscribers. + Available = true; + _eventAggregator.GetEvent().Publish(); } public List GetCraftingRecipes() @@ -298,9 +340,8 @@ public List GetOverlayResources() // MasterItemDefinitions Crafting var masterItemDefinitionsJson = new List(); - resourcePath = "MasterItemDefinitions_Crafting.json"; - resourcePath = assembly.GetManifestResourceNames().Single(str => str.EndsWith(resourcePath)); - using (Stream? stream = assembly.GetManifestResourceStream(resourcePath)) + resourcePath = @".\Data\MasterItemDefinitions_Crafting.json"; + using (FileStream? stream = File.OpenRead(resourcePath)) { if (stream != null) { diff --git a/NewWorldCompanion.Services/OcrHandler.cs b/NewWorldCompanion.Services/OcrHandler.cs index dbd28da..2ee9561 100644 --- a/NewWorldCompanion.Services/OcrHandler.cs +++ b/NewWorldCompanion.Services/OcrHandler.cs @@ -72,7 +72,7 @@ private void HandleOcrImageReadyEvent() { lock (nameLock) { - if (_screenProcessHandler.OcrImage != null) + if (_screenProcessHandler.OcrImage != null && _newWorldDataStore.Available) { try { diff --git a/NewWorldCompanion.Services/OverlayHandler.cs b/NewWorldCompanion.Services/OverlayHandler.cs index 24a6895..815ab9f 100644 --- a/NewWorldCompanion.Services/OverlayHandler.cs +++ b/NewWorldCompanion.Services/OverlayHandler.cs @@ -50,6 +50,7 @@ public OverlayHandler(IEventAggregator eventAggregator, ISettingsManager setting _eventAggregator.GetEvent().Subscribe(HandleOverlayHideEvent); _eventAggregator.GetEvent().Subscribe(HandleOverlayShowEvent); _eventAggregator.GetEvent().Subscribe(HandleRoiImageReadyEvent); + _eventAggregator.GetEvent().Subscribe(HandleNewWorldDataStoreUpdatedEvent); // Init services _settingsManager = settingsManager; @@ -79,14 +80,6 @@ public OverlayHandler(IEventAggregator eventAggregator, ISettingsManager setting _window.DestroyGraphics += DestroyGraphics; _window.DrawGraphics += DrawGraphics; _window.SetupGraphics += SetupGraphics; - - // Start overlay task - _timer = new DispatcherTimer - { - Interval = TimeSpan.FromMilliseconds(100), - IsEnabled = true - }; - _timer.Tick += Timer_Tick; ; } #endregion @@ -242,12 +235,6 @@ private void SetupGraphics(object? sender, SetupGraphicsEventArgs e) _fonts["consolas"] = gfx.CreateFont("Consolas", 14); } - private void Timer_Tick(object? sender, EventArgs e) - { - (sender as DispatcherTimer)?.Stop(); - StartOverlay(); - } - private void HandleOcrTextReadyEvent() { _itemName = _ocrHandler.OcrText; @@ -291,6 +278,11 @@ private void HandleRoiImageReadyEvent() _overlayHeigth = _screenProcessHandler.OverlayHeigth; } + private void HandleNewWorldDataStoreUpdatedEvent() + { + StartOverlay(); + } + #endregion // Start of Methods region diff --git a/NewWorldCompanion.Services/ScreenCaptureHandler.cs b/NewWorldCompanion.Services/ScreenCaptureHandler.cs index f803bd0..b8ead52 100644 --- a/NewWorldCompanion.Services/ScreenCaptureHandler.cs +++ b/NewWorldCompanion.Services/ScreenCaptureHandler.cs @@ -19,6 +19,7 @@ public class ScreenCaptureHandler : IScreenCaptureHandler private readonly IEventAggregator _eventAggregator; private readonly ILogger _logger; private readonly ISettingsManager _settingsManager; + private readonly INewWorldDataStore _newWorldDataStore; private DispatcherTimer _captureTimer = new(); private DispatcherTimer _coordinatesTimer = new(); @@ -34,7 +35,7 @@ public class ScreenCaptureHandler : IScreenCaptureHandler #region Constructor - public ScreenCaptureHandler(IEventAggregator eventAggregator, ILogger logger, ISettingsManager settingsManager) + public ScreenCaptureHandler(IEventAggregator eventAggregator, ILogger logger, ISettingsManager settingsManager, INewWorldDataStore newWorldDataStore) { // Init IEventAggregator _eventAggregator = eventAggregator; @@ -44,6 +45,7 @@ public ScreenCaptureHandler(IEventAggregator eventAggregator, ILogger().Subscribe(HandleNewWorldDataStoreUpdatedEvent); // Init services _httpClientHandler = httpClientHandler; - - // Init servers - UpdateVersionInfo(); } #endregion @@ -58,6 +56,11 @@ public string CurrentVersion #region Events + private void HandleNewWorldDataStoreUpdatedEvent() + { + UpdateVersionInfo(); + } + #endregion // Start of Methods region diff --git a/NewWorldCompanion/App.xaml.cs b/NewWorldCompanion/App.xaml.cs index 6bc881a..157ab39 100644 --- a/NewWorldCompanion/App.xaml.cs +++ b/NewWorldCompanion/App.xaml.cs @@ -1,4 +1,5 @@ -using MahApps.Metro.Controls.Dialogs; +using Emgu.CV.Cuda; +using MahApps.Metro.Controls.Dialogs; using Microsoft.Extensions.DependencyInjection; using NewWorldCompanion.Entities; using NewWorldCompanion.Interfaces; @@ -7,6 +8,8 @@ using NLog.Extensions.Logging; using Prism.Ioc; using Prism.Unity; +using System.IO; +using System.Threading; using System.Windows; using Unity; using Unity.Microsoft.DependencyInjection; @@ -18,6 +21,24 @@ namespace NewWorldCompanion /// public partial class App : PrismApplication { + private static Mutex _mutex = null; + + protected override void OnStartup(StartupEventArgs e) + { + const string appName = "NewWorldCompanion"; + + bool createdNew; + + _mutex = new Mutex(true, appName, out createdNew); + + if (!createdNew) + { + Application.Current.Shutdown(); + } + + base.OnStartup(e); + } + protected override void RegisterTypes(IContainerRegistry containerRegistry) { // Register services diff --git a/NewWorldCompanion.Services/Data/CraftingRecipes.json b/NewWorldCompanion/Data/CraftingRecipes.json similarity index 100% rename from NewWorldCompanion.Services/Data/CraftingRecipes.json rename to NewWorldCompanion/Data/CraftingRecipes.json diff --git a/NewWorldCompanion.Services/Data/HouseItems.json b/NewWorldCompanion/Data/HouseItems.json similarity index 100% rename from NewWorldCompanion.Services/Data/HouseItems.json rename to NewWorldCompanion/Data/HouseItems.json diff --git a/NewWorldCompanion.Services/Data/MasterItemDefinitions_Common.json b/NewWorldCompanion/Data/MasterItemDefinitions_Common.json similarity index 100% rename from NewWorldCompanion.Services/Data/MasterItemDefinitions_Common.json rename to NewWorldCompanion/Data/MasterItemDefinitions_Common.json diff --git a/NewWorldCompanion.Services/Data/MasterItemDefinitions_Crafting.json b/NewWorldCompanion/Data/MasterItemDefinitions_Crafting.json similarity index 100% rename from NewWorldCompanion.Services/Data/MasterItemDefinitions_Crafting.json rename to NewWorldCompanion/Data/MasterItemDefinitions_Crafting.json diff --git a/NewWorldCompanion.Services/Data/MasterItemDefinitions_Loot.json b/NewWorldCompanion/Data/MasterItemDefinitions_Loot.json similarity index 100% rename from NewWorldCompanion.Services/Data/MasterItemDefinitions_Loot.json rename to NewWorldCompanion/Data/MasterItemDefinitions_Loot.json diff --git a/NewWorldCompanion.Services/Data/MasterItemDefinitions_Quest.json b/NewWorldCompanion/Data/MasterItemDefinitions_Quest.json similarity index 100% rename from NewWorldCompanion.Services/Data/MasterItemDefinitions_Quest.json rename to NewWorldCompanion/Data/MasterItemDefinitions_Quest.json diff --git a/NewWorldCompanion.Services/Data/javelindata_housingitems.loc.xml b/NewWorldCompanion/Data/javelindata_housingitems.loc.xml similarity index 100% rename from NewWorldCompanion.Services/Data/javelindata_housingitems.loc.xml rename to NewWorldCompanion/Data/javelindata_housingitems.loc.xml diff --git a/NewWorldCompanion.Services/Data/javelindata_itemdefinitions_master.loc.xml b/NewWorldCompanion/Data/javelindata_itemdefinitions_master.loc.xml similarity index 100% rename from NewWorldCompanion.Services/Data/javelindata_itemdefinitions_master.loc.xml rename to NewWorldCompanion/Data/javelindata_itemdefinitions_master.loc.xml diff --git a/NewWorldCompanion/NewWorldCompanion.csproj b/NewWorldCompanion/NewWorldCompanion.csproj index ca7e303..7df2da0 100644 --- a/NewWorldCompanion/NewWorldCompanion.csproj +++ b/NewWorldCompanion/NewWorldCompanion.csproj @@ -69,6 +69,30 @@ Always + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + diff --git a/NewWorldCompanion/ViewModels/MainWindowViewModel.cs b/NewWorldCompanion/ViewModels/MainWindowViewModel.cs index 90044a9..ff89975 100644 --- a/NewWorldCompanion/ViewModels/MainWindowViewModel.cs +++ b/NewWorldCompanion/ViewModels/MainWindowViewModel.cs @@ -2,6 +2,7 @@ using Microsoft.Extensions.Logging; using NewWorldCompanion.Events; using NewWorldCompanion.Interfaces; +using NewWorldCompanion.Services; using Prism.Commands; using Prism.Events; using Prism.Mvvm; @@ -9,6 +10,7 @@ using System.Diagnostics; using System.IO; using System.Reflection; +using System.Threading.Tasks; namespace NewWorldCompanion.ViewModels { @@ -20,6 +22,8 @@ public class MainWindowViewModel : BindableBase private readonly IOverlayHandler _overlayHandler; private readonly IVersionManager _versionManager; private readonly IDialogCoordinator _dialogCoordinator; + private readonly INewWorldDataStore _newWorldDataStore; + private readonly ICraftingRecipeManager _craftingRecipeManager; private string _windowTitle = $"New World Companion v{Assembly.GetExecutingAssembly().GetName().Version}"; @@ -27,11 +31,14 @@ public class MainWindowViewModel : BindableBase #region Constructor - public MainWindowViewModel(IEventAggregator eventAggregator, ILogger logger, ISettingsManager settingsManager, IOverlayHandler overlayHandler, IVersionManager versionManager, IDialogCoordinator dialogCoordinator) + public MainWindowViewModel(IEventAggregator eventAggregator, ILogger logger, ISettingsManager settingsManager, IOverlayHandler overlayHandler, IVersionManager versionManager, IDialogCoordinator dialogCoordinator, INewWorldDataStore newWorldDataStore, ICraftingRecipeManager craftingRecipeManager) { // Init IEventAggregator _eventAggregator = eventAggregator; _eventAggregator.GetEvent().Subscribe(HandleVersionInfoUpdatedEvent); + _eventAggregator.GetEvent().Subscribe(HandleDataReadyEvent); + _eventAggregator.GetEvent().Subscribe(HandleDataReadyEvent); + _eventAggregator.GetEvent().Subscribe(HandleDataStatusUpdatedEvent); // Init logger _logger = logger; @@ -41,6 +48,8 @@ public MainWindowViewModel(IEventAggregator eventAggregator, ILogger _settingsManager.Settings.DebugModeActive; } public string WindowTitle { get => _windowTitle; set => _windowTitle = value; } + public bool WaitingForData => !(_newWorldDataStore.Available && _craftingRecipeManager.Available); + public string DataStatusItemDefinitions => _newWorldDataStore.LoadStatusItemDefinitions; + public string DataStatusCraftingRecipes => _newWorldDataStore.LoadStatusCraftingRecipes; + public string DataStatusHouseItems => _newWorldDataStore.LoadStatusHouseItems; + public string DataStatusLocalisation => _newWorldDataStore.LoadStatusLocalisation; #endregion @@ -99,6 +113,19 @@ private void HandleVersionInfoUpdatedEvent() _logger.LogInformation(WindowTitle); } + private void HandleDataReadyEvent() + { + RaisePropertyChanged(nameof(WaitingForData)); + } + + private void HandleDataStatusUpdatedEvent() + { + RaisePropertyChanged(nameof(DataStatusItemDefinitions)); + RaisePropertyChanged(nameof(DataStatusCraftingRecipes)); + RaisePropertyChanged(nameof(DataStatusHouseItems)); + RaisePropertyChanged(nameof(DataStatusLocalisation)); + } + #endregion // Start of Methods region diff --git a/NewWorldCompanion/ViewModels/Tabs/Config/ConfigOverlayViewModel.cs b/NewWorldCompanion/ViewModels/Tabs/Config/ConfigOverlayViewModel.cs index 4123ec3..2fe68be 100644 --- a/NewWorldCompanion/ViewModels/Tabs/Config/ConfigOverlayViewModel.cs +++ b/NewWorldCompanion/ViewModels/Tabs/Config/ConfigOverlayViewModel.cs @@ -41,6 +41,7 @@ public ConfigOverlayViewModel(IEventAggregator eventAggregator, ISettingsManager // Init IEventAggregator _eventAggregator = eventAggregator; _eventAggregator.GetEvent().Subscribe(HandlePriceServerListUpdatedEvent); + _eventAggregator.GetEvent().Subscribe(HandleNewWorldDataStoreUpdatedEvent); // Init services _settingsManager = settingsManager; @@ -48,9 +49,6 @@ public ConfigOverlayViewModel(IEventAggregator eventAggregator, ISettingsManager _priceManager = priceManager; _relatedPriceManager = relatedPriceManager; - // Init related prices - InitOverlayResources(); - // Init filter views CreateOverlayResourcesFilteredView(); } @@ -155,6 +153,17 @@ private void HandlePriceServerListUpdatedEvent() updateServerList(); } + private void HandleNewWorldDataStoreUpdatedEvent() + { + // As the view is accessed by the UI it will need to be created on the UI thread + Application.Current?.Dispatcher?.Invoke(() => + { + // Init related prices + InitOverlayResources(); + OverlayResourcesFiltered?.Refresh(); + }); + } + #endregion // Start of Methods region diff --git a/NewWorldCompanion/ViewModels/Tabs/CraftingViewModel.cs b/NewWorldCompanion/ViewModels/Tabs/CraftingViewModel.cs index b04497f..b8cf26b 100644 --- a/NewWorldCompanion/ViewModels/Tabs/CraftingViewModel.cs +++ b/NewWorldCompanion/ViewModels/Tabs/CraftingViewModel.cs @@ -77,6 +77,7 @@ public CraftingViewModel(IEventAggregator eventAggregator, ILogger().Subscribe(HandleOcrTextReadyEvent); _eventAggregator.GetEvent().Subscribe(HandlePriceCacheUpdatedEvent); + _eventAggregator.GetEvent().Subscribe(HandleCraftingRecipeManagerUpdatedEvent); // Init logger _logger = logger; @@ -97,14 +98,6 @@ public CraftingViewModel(IEventAggregator eventAggregator, ILogger _selectedPresetConfig; + set + { + _selectedPresetConfig = value; + RestoreDefaultsCommand?.RaiseCanExecuteChanged(); + } + } public BitmapSource? ProcessedImage { @@ -182,6 +195,12 @@ private void HandleOcrImageCountReadyEvent() #region Methods + private bool CanRestoreDefaultsExecute() + { + var result = ((SelectedPresetConfig as ComboBoxItem)?.Content ?? string.Empty).ToString()?.Contains("x") ?? false; + return result; + } + private void RestoreDefaultsExecute() { switch ((SelectedPresetConfig as ComboBoxItem)?.Content ?? string.Empty) diff --git a/NewWorldCompanion/ViewModels/Tabs/StorageViewModel.cs b/NewWorldCompanion/ViewModels/Tabs/StorageViewModel.cs index 1818621..a766691 100644 --- a/NewWorldCompanion/ViewModels/Tabs/StorageViewModel.cs +++ b/NewWorldCompanion/ViewModels/Tabs/StorageViewModel.cs @@ -145,7 +145,7 @@ public bool ToggleRefresh private void HandleOcrTextReadyEvent() { - if (ToggleRefresh) + if (ToggleRefresh && _newWorldDataStore.Available) { // Recording active _itemName = _ocrHandler.OcrText; diff --git a/NewWorldCompanion/Views/MainWindow.xaml b/NewWorldCompanion/Views/MainWindow.xaml index 9f75b4f..c41ed50 100644 --- a/NewWorldCompanion/Views/MainWindow.xaml +++ b/NewWorldCompanion/Views/MainWindow.xaml @@ -13,42 +13,53 @@ mc:Ignorable="d" Title="{Binding WindowTitle}" Height="550" Width="800" WindowStartupLocation="CenterScreen"> - - - + - + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/NewWorldCompanion/Views/Tabs/Debug/DebugScreenProcessView.xaml b/NewWorldCompanion/Views/Tabs/Debug/DebugScreenProcessView.xaml index d3c92d9..e9bbb87 100644 --- a/NewWorldCompanion/Views/Tabs/Debug/DebugScreenProcessView.xaml +++ b/NewWorldCompanion/Views/Tabs/Debug/DebugScreenProcessView.xaml @@ -44,7 +44,8 @@