diff --git a/D4Companion.Constants/SystemPresetStatusConstants.cs b/D4Companion.Constants/SystemPresetStatusConstants.cs new file mode 100644 index 00000000..847f8309 --- /dev/null +++ b/D4Companion.Constants/SystemPresetStatusConstants.cs @@ -0,0 +1,8 @@ +namespace D4Companion.Constants +{ + public class SystemPresetStatusConstants + { + public const string Broken = "broken"; + public const string Ready = "ready"; + } +} \ No newline at end of file diff --git a/D4Companion.Entities/ItemTooltipDescriptor.cs b/D4Companion.Entities/ItemTooltipDescriptor.cs index d6ba75c8..0b36063d 100644 --- a/D4Companion.Entities/ItemTooltipDescriptor.cs +++ b/D4Companion.Entities/ItemTooltipDescriptor.cs @@ -67,5 +67,6 @@ public class ItemTooltipDescriptor { "Affixes", 0}, { "Aspects", 0} }; + public TradeItem? TradeItem { get; set; } = null; } } diff --git a/D4Companion.Entities/SystemPreset.cs b/D4Companion.Entities/SystemPreset.cs index fdb929f5..d04a124b 100644 --- a/D4Companion.Entities/SystemPreset.cs +++ b/D4Companion.Entities/SystemPreset.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace D4Companion.Entities +namespace D4Companion.Entities { public class SystemPreset { @@ -19,5 +13,6 @@ public class SystemPreset public string AffixAreaHeightOffsetBottom { get; set; } = string.Empty; public string AffixAspectAreaWidthOffset { get; set; } = string.Empty; public string AspectAreaHeightOffsetTop { get; set; } = string.Empty; + public string Status { get; set; } = string.Empty; } } \ No newline at end of file diff --git a/D4Companion.Interfaces/ITradeItemManager.cs b/D4Companion.Interfaces/ITradeItemManager.cs index a95bd8a8..93ccd588 100644 --- a/D4Companion.Interfaces/ITradeItemManager.cs +++ b/D4Companion.Interfaces/ITradeItemManager.cs @@ -1,10 +1,12 @@ using D4Companion.Entities; + namespace D4Companion.Interfaces { public interface ITradeItemManager { List TradeItems { get; } + TradeItem? FindTradeItem(List affixes); void SaveTradeItems(List tradeItems); } } diff --git a/D4Companion.Services/BuildsManagerD4Builds.cs b/D4Companion.Services/BuildsManagerD4Builds.cs index 9ee8d474..a569ae68 100644 --- a/D4Companion.Services/BuildsManagerD4Builds.cs +++ b/D4Companion.Services/BuildsManagerD4Builds.cs @@ -361,7 +361,7 @@ private void ConvertBuildVariants(D4BuildsBuild d4BuildsBuild) }); // Remove duplicates - affixPreset.ItemAffixes = affixPreset.ItemAffixes.DistinctBy(a => new { a.Id, a.Type, a.IsTempered }).ToList(); + affixPreset.ItemAffixes = affixPreset.ItemAffixes.DistinctBy(a => new { a.Id, a.Type, a.IsImplicit, a.IsTempered }).ToList(); // Find matching aspect ids ConcurrentBag itemAspectBag = new ConcurrentBag(); diff --git a/D4Companion.Services/BuildsManagerMobalytics.cs b/D4Companion.Services/BuildsManagerMobalytics.cs index b56ddf07..3ad400a6 100644 --- a/D4Companion.Services/BuildsManagerMobalytics.cs +++ b/D4Companion.Services/BuildsManagerMobalytics.cs @@ -388,7 +388,7 @@ private void ConvertBuildVariants(MobalyticsBuild mobalyticsBuild) }); // Remove duplicates - affixPreset.ItemAffixes = affixPreset.ItemAffixes.DistinctBy(a => new { a.Id, a.Type, a.IsTempered }).ToList(); + affixPreset.ItemAffixes = affixPreset.ItemAffixes.DistinctBy(a => new { a.Id, a.Type, a.IsImplicit, a.IsTempered }).ToList(); // Find matching aspect ids ConcurrentBag itemAspectBag = new ConcurrentBag(); diff --git a/D4Companion.Services/OverlayHandler.cs b/D4Companion.Services/OverlayHandler.cs index 67556aff..bed35db5 100644 --- a/D4Companion.Services/OverlayHandler.cs +++ b/D4Companion.Services/OverlayHandler.cs @@ -134,6 +134,9 @@ private void DrawGraphics(object? sender, DrawGraphicsEventArgs e) // Aspects DrawGraphicsAspects(sender, e, itemPowerLimitCheckOk); + + // Trading + DrawGraphicsTrading(sender, e, itemPowerLimitCheckOk); } // Menu items @@ -274,6 +277,44 @@ private void DrawGraphicsAspects(object? sender, DrawGraphicsEventArgs e, bool i } } + private void DrawGraphicsTrading(object? sender, DrawGraphicsEventArgs e, bool itemPowerLimitCheckOk) + { + if (_settingsManager.Settings.IsTradeOverlayEnabled && _currentTooltip.TradeItem != null) + { + var gfx = e.Graphics; + + string tradeItemValue = _currentTooltip.TradeItem.Value; + + float textOffset = 20; + float initialPresetPanelHeight = 50; + float fontSize = _settingsManager.Settings.OverlayFontSize; + + var textHeight = gfx.MeasureString(_fonts["consolasBold"], fontSize, tradeItemValue).Y; + + // Set the position of the panel + float presetPanelLeft = _currentTooltip.Location.X + _currentTooltip.OffsetX; + float presetPanelTop = _currentTooltip.Location.Y + _currentTooltip.Location.Height - initialPresetPanelHeight; + float presetPanelRight = _currentTooltip.Location.X + _currentTooltip.OffsetX + _currentTooltip.Location.Width; + float presetPanelBottom = _currentTooltip.Location.Y + _currentTooltip.Location.Height; + + // Draw the panel as a filled rectangle behind the text + gfx.FillRectangle(_brushes["background"], presetPanelLeft, presetPanelTop, presetPanelRight, presetPanelBottom); + + // Draw the border of the panel + gfx.DrawRectangle(_brushes["border"], presetPanelLeft, presetPanelTop, presetPanelRight, presetPanelBottom, stroke: 1); + + // Center the text inside the panel + float textLeft = presetPanelLeft + textOffset; + float textTop = presetPanelTop + (initialPresetPanelHeight - textHeight) / 2; + gfx.DrawText(_fonts["consolasBold"], fontSize, _brushes["text"], textLeft, textTop, tradeItemValue); + + // Center icon inside the panel + float iconLeft = presetPanelLeft; + float iconTop = presetPanelTop + (initialPresetPanelHeight) / 2; + gfx.OutlineFillCircle(_brushes[Colors.Black.ToString()], _brushes[Colors.Goldenrod.ToString()], iconLeft, iconTop, radius: 10, stroke: 2); + } + } + private void DestroyGraphics(object? sender, DestroyGraphicsEventArgs e) { try diff --git a/D4Companion.Services/ScreenProcessHandler.cs b/D4Companion.Services/ScreenProcessHandler.cs index a96c5bba..43ff77ce 100644 --- a/D4Companion.Services/ScreenProcessHandler.cs +++ b/D4Companion.Services/ScreenProcessHandler.cs @@ -23,6 +23,7 @@ public class ScreenProcessHandler : IScreenProcessHandler private readonly IOcrHandler _ocrHandler; private readonly ISettingsManager _settingsManager; private readonly ISystemPresetManager _systemPresetManager; + private readonly ITradeItemManager _tradeItemManager; private int _mouseCoordsX; private int _mouseCoordsY; @@ -48,7 +49,7 @@ public class ScreenProcessHandler : IScreenProcessHandler #region Constructors public ScreenProcessHandler(IEventAggregator eventAggregator, ILogger logger, IAffixManager affixManager, - IOcrHandler ocrHandler, ISettingsManager settingsManager, ISystemPresetManager systemPresetManager) + IOcrHandler ocrHandler, ISettingsManager settingsManager, ISystemPresetManager systemPresetManager, ITradeItemManager tradeItemManager) { // Init IEventAggregator _eventAggregator = eventAggregator; @@ -68,6 +69,7 @@ public ScreenProcessHandler(IEventAggregator eventAggregator, ILogger a.Item2).ToList()); + } + watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; diff --git a/D4Companion.Services/TradeItemManager.cs b/D4Companion.Services/TradeItemManager.cs index f1a154d7..48f540ce 100644 --- a/D4Companion.Services/TradeItemManager.cs +++ b/D4Companion.Services/TradeItemManager.cs @@ -59,6 +59,28 @@ public TradeItemManager(IEventAggregator eventAggregator, ILogger affixes) + { + var tradeItem = TradeItems.FirstOrDefault(t => + { + // Look for a tradeItem with affixes that are all available in the affixes parameter. + foreach (var affix in t.Affixes) + { + if (affix.IsGreater) + { + if (!affixes.Any(a => a.Id.Equals(affix.Id) && a.IsGreater == affix.IsGreater)) return false; + } + else + { + if (!affixes.Any(a => a.Id.Equals(affix.Id))) return false; + } + } + return true; + }); + + return tradeItem; + } + private void LoadTradeItems() { TradeItems.Clear(); diff --git a/D4Companion/Converters/SystemPresetStatusToHealthConverter.cs b/D4Companion/Converters/SystemPresetStatusToHealthConverter.cs new file mode 100644 index 00000000..e5e70f5b --- /dev/null +++ b/D4Companion/Converters/SystemPresetStatusToHealthConverter.cs @@ -0,0 +1,35 @@ +using System; +using System.Globalization; +using System.Windows.Data; +using System.Windows.Media; + +namespace D4Companion.Converters +{ + [ValueConversion(typeof(string), typeof(Brush))] + public class SystemPresetStatusToHealthConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + string valueAsString = (string)value; + if (string.IsNullOrWhiteSpace(valueAsString)) + { + return Brushes.Gray; + } + + switch (valueAsString.ToLower()) + { + case Constants.SystemPresetStatusConstants.Broken: + return Brushes.Red; + case Constants.SystemPresetStatusConstants.Ready: + return Brushes.Green; + default: + return Brushes.Gray; + } + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/D4Companion/Views/SettingsView.xaml b/D4Companion/Views/SettingsView.xaml index 79145f34..af0e3d81 100644 --- a/D4Companion/Views/SettingsView.xaml +++ b/D4Companion/Views/SettingsView.xaml @@ -17,6 +17,7 @@ d:DesignHeight="450" d:DesignWidth="800"> + @@ -160,7 +161,18 @@ - + + + + + + + + + + + +