Skip to content

Commit

Permalink
- Add trading list.
Browse files Browse the repository at this point in the history
- Add warning when preset name already exists.
- Fixed issue with D4Builds imports.
- Show system preset status.
  • Loading branch information
josdemmers committed Jul 10, 2024
1 parent 2a3aa29 commit 3bfa768
Show file tree
Hide file tree
Showing 60 changed files with 149 additions and 26 deletions.
8 changes: 8 additions & 0 deletions D4Companion.Constants/SystemPresetStatusConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace D4Companion.Constants
{
public class SystemPresetStatusConstants
{
public const string Broken = "broken";
public const string Ready = "ready";
}
}
1 change: 1 addition & 0 deletions D4Companion.Entities/ItemTooltipDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ public class ItemTooltipDescriptor
{ "Affixes", 0},
{ "Aspects", 0}
};
public TradeItem? TradeItem { get; set; } = null;
}
}
9 changes: 2 additions & 7 deletions D4Companion.Entities/SystemPreset.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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;
}
}
2 changes: 2 additions & 0 deletions D4Companion.Interfaces/ITradeItemManager.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using D4Companion.Entities;

namespace D4Companion.Interfaces
{
public interface ITradeItemManager
{
List<TradeItem> TradeItems { get; }

TradeItem? FindTradeItem(List<ItemAffix> affixes);
void SaveTradeItems(List<TradeItem> tradeItems);
}
}
2 changes: 1 addition & 1 deletion D4Companion.Services/BuildsManagerD4Builds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemAffix> itemAspectBag = new ConcurrentBag<ItemAffix>();
Expand Down
2 changes: 1 addition & 1 deletion D4Companion.Services/BuildsManagerMobalytics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemAffix> itemAspectBag = new ConcurrentBag<ItemAffix>();
Expand Down
41 changes: 41 additions & 0 deletions D4Companion.Services/OverlayHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ private void DrawGraphics(object? sender, DrawGraphicsEventArgs e)

// Aspects
DrawGraphicsAspects(sender, e, itemPowerLimitCheckOk);

// Trading
DrawGraphicsTrading(sender, e, itemPowerLimitCheckOk);
}

// Menu items
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion D4Companion.Services/ScreenProcessHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -48,7 +49,7 @@ public class ScreenProcessHandler : IScreenProcessHandler
#region Constructors

public ScreenProcessHandler(IEventAggregator eventAggregator, ILogger<ScreenProcessHandler> logger, IAffixManager affixManager,
IOcrHandler ocrHandler, ISettingsManager settingsManager, ISystemPresetManager systemPresetManager)
IOcrHandler ocrHandler, ISettingsManager settingsManager, ISystemPresetManager systemPresetManager, ITradeItemManager tradeItemManager)
{
// Init IEventAggregator
_eventAggregator = eventAggregator;
Expand All @@ -68,6 +69,7 @@ public ScreenProcessHandler(IEventAggregator eventAggregator, ILogger<ScreenProc
_ocrHandler = ocrHandler;
_settingsManager = settingsManager;
_systemPresetManager = systemPresetManager;
_tradeItemManager = tradeItemManager;

// Init image list.
LoadImageList();
Expand Down Expand Up @@ -345,6 +347,12 @@ private void ProcessScreen(Bitmap currentScreen)
}
});

// Find tradable item
if(_settingsManager.Settings.IsTradeOverlayEnabled && _currentTooltip.ItemAffixes.Any())
{
_currentTooltip.TradeItem = _tradeItemManager.FindTradeItem(_currentTooltip.ItemAffixes.Select(a => a.Item2).ToList());
}

watch.Stop();
var elapsedMs = watch.ElapsedMilliseconds;

Expand Down
22 changes: 22 additions & 0 deletions D4Companion.Services/TradeItemManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,28 @@ public TradeItemManager(IEventAggregator eventAggregator, ILogger<TradeItemManag

#region Methods

public TradeItem? FindTradeItem(List<ItemAffix> 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();
Expand Down
35 changes: 35 additions & 0 deletions D4Companion/Converters/SystemPresetStatusToHealthConverter.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
14 changes: 13 additions & 1 deletion D4Companion/Views/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<converters:FlagToImagePathConverter x:Key="FlagToImagePathConverter"/>
<converters:SystemPresetStatusToHealthConverter x:Key="SystemPresetStatusToHealthConverter"/>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
Expand Down Expand Up @@ -160,7 +161,18 @@
<DockPanel Grid.Row="0" Grid.Column="1">
<mah:MetroHeader Margin="0 10 0 5" Header="{loc:LocExtension rsCapAvailableSystemPresets}" DockPanel.Dock="Top">
<StackPanel Orientation="Horizontal">
<ComboBox Width="175" ItemsSource="{Binding Path=CommunitySystemPresets}" DisplayMemberPath="FileName" SelectedItem="{Binding Path=SelectedCommunityPreset}"/>
<ComboBox Width="175" ItemsSource="{Binding Path=CommunitySystemPresets}" SelectedItem="{Binding Path=SelectedCommunityPreset}">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<BulletDecorator Margin="0,0,5,0">
<Ellipse Fill="{Binding Status, Converter={StaticResource SystemPresetStatusToHealthConverter}}" Width="10" Height="10"/>
</BulletDecorator>
<TextBlock Text="{Binding FileName}" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<Button Margin="2 0 0 0" MinWidth="80" Content="{Binding PresetDownloadButtonCaption}" Command="{Binding DownloadSystemPresetCommand}"/>
<Label Margin="0 0 5 0" HorizontalAlignment="Right" VerticalAlignment="Center" ToolTip="{loc:LocExtension rsTooltipPresetDownloadTip}">
<iconPacks:PackIconMaterial Kind="InformationOutline" Width="16" Height="16"/>
Expand Down
29 changes: 14 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Looking for help?
- Specify your prefered affixes for each gear slot and monitor them ingame.
- Supports affixes, aspects, and sigils.
- Filter by item power.
- Trading lists
- Track valuable items for trading.
- Show trade value ingame.
- Import builds from D4Builds.gg
- Import builds from Maxroll.gg
- Import builds from Mobalytics.gg
Expand All @@ -63,22 +66,22 @@ Currently the following system presets are included:

| Preset | Language | Config | Status | Comment |
| ---------------- | ----------------------------------------------- | --------------------------------------------------------------------------- | ----------------------------------------------------------------- | ----------------------- |
| 1050p_SMF_en | <img src="./D4Companion/Images/Flags/enUS.png"> | SDR (HDR off) with font set to medium for the English language | ![Static Badge](https://img.shields.io/badge/status-broken-red) | Missing S4 icons |
| 1050p_SMF_en | <img src="./D4Companion/Images/Flags/enUS.png"> | SDR (HDR off) with font set to medium for the English language | ![Static Badge](https://img.shields.io/badge/status-broken-red) | Missing icons temper |
| 1080p_SMF_en | <img src="./D4Companion/Images/Flags/enUS.png"> | SDR (HDR off) with font set to medium for the English language | ![Static Badge](https://img.shields.io/badge/status-ready-green) | |
| 1080p_SMF_es-US | <img src="./D4Companion/Images/Flags/esES.png"> | SDR (HDR off) with font set to medium for the Spanish (LA) language | ![Static Badge](https://img.shields.io/badge/status-unknown-red) | |
| 1080p_SMF_es-US | <img src="./D4Companion/Images/Flags/esES.png"> | SDR (HDR off) with font set to medium for the Spanish (LA) language | ![Static Badge](https://img.shields.io/badge/status-ready-green) | |
| 1080p_SMF_fr | <img src="./D4Companion/Images/Flags/frFR.png"> | SDR (HDR off) with font set to medium for the French language | ![Static Badge](https://img.shields.io/badge/status-ready-green) | |
| 1080p_SSF_de | <img src="./D4Companion/Images/Flags/deDE.png"> | SDR (HDR off) with font set to small for the German language | ![Static Badge](https://img.shields.io/badge/status-unknown-red) | |
| 1080p_SSF_en | <img src="./D4Companion/Images/Flags/enUS.png"> | SDR (HDR off) with font set to small for the English language | ![Static Badge](https://img.shields.io/badge/status-ready-green) | |
| 1080p_SSF_es-US | <img src="./D4Companion/Images/Flags/esES.png"> | SDR (HDR off) with font set to small for the Spanish (LA) language | ![Static Badge](https://img.shields.io/badge/status-unknown-red) | |
| 1440p_HSF_en | <img src="./D4Companion/Images/Flags/enUS.png"> | HDR with font set to small for the English language | ![Static Badge](https://img.shields.io/badge/status-ready-green) | |
| 1080p_SSF_de | <img src="./D4Companion/Images/Flags/deDE.png"> | SDR (HDR off) with font set to small for the German language | ![Static Badge](https://img.shields.io/badge/status-broken-red) | Missing icons temper |
| 1080p_SSF_en | <img src="./D4Companion/Images/Flags/enUS.png"> | SDR (HDR off) with font set to small for the English language | ![Static Badge](https://img.shields.io/badge/status-broken-red) | Missing icons temper |
| 1080p_SSF_es-US | <img src="./D4Companion/Images/Flags/esES.png"> | SDR (HDR off) with font set to small for the Spanish (LA) language | ![Static Badge](https://img.shields.io/badge/status-broken-red) | Missing icons temper |
| 1440p_HSF_en | <img src="./D4Companion/Images/Flags/enUS.png"> | HDR with font set to small for the English language | ![Static Badge](https://img.shields.io/badge/status-broken-red) | Missing icons temper |
| 1440p_SMF_en | <img src="./D4Companion/Images/Flags/enUS.png"> | SDR (HDR off) with font set to medium for the English language | ![Static Badge](https://img.shields.io/badge/status-ready-green) | |
| 1440p_SMF_fr | <img src="./D4Companion/Images/Flags/frFR.png"> | SDR (HDR off) with font set to medium for the French language | ![Static Badge](https://img.shields.io/badge/status-ready-green) | |
| 1440p_SMF_zh-CN | <img src="./D4Companion/Images/Flags/zhCN.png"> | SDR (HDR off) with font set to medium for the Chinese (Simplified) language | ![Static Badge](https://img.shields.io/badge/status-ready-green) | |
| 1440p_SSF_en | <img src="./D4Companion/Images/Flags/enUS.png"> | SDR (HDR off) with font set to small for the English language | ![Static Badge](https://img.shields.io/badge/status-ready-green) | |
| 1600p_SMF_en | <img src="./D4Companion/Images/Flags/enUS.png"> | SDR (HDR off) with font set to medium for the English language | ![Static Badge](https://img.shields.io/badge/status-ready-yellow) | New greater affix |
| 1600p_SMF_zh-CN | <img src="./D4Companion/Images/Flags/zhCN.png"> | SDR (HDR off) with font set to medium for the Chinese (Simplified) language | ![Static Badge](https://img.shields.io/badge/status-unknown-red) | |
| 2160p_HSF_en | <img src="./D4Companion/Images/Flags/enUS.png"> | HDR with font set to small for the English language. | ![Static Badge](https://img.shields.io/badge/status-ready-green) | |
| 2160p_SSF_en | <img src="./D4Companion/Images/Flags/enUS.png"> | SDR (HDR off) with font set to small for the English language. | ![Static Badge](https://img.shields.io/badge/status-broken-red) | Missing S4 icons |
| 1440p_SSF_en | <img src="./D4Companion/Images/Flags/enUS.png"> | SDR (HDR off) with font set to small for the English language | ![Static Badge](https://img.shields.io/badge/status-broken-red) | Missing icons temper |
| 1600p_SMF_en | <img src="./D4Companion/Images/Flags/enUS.png"> | SDR (HDR off) with font set to medium for the English language | ![Static Badge](https://img.shields.io/badge/status-broken-red) | Missing icons greater, temper |
| 1600p_SMF_zh-CN | <img src="./D4Companion/Images/Flags/zhCN.png"> | SDR (HDR off) with font set to medium for the Chinese (Simplified) language | ![Static Badge](https://img.shields.io/badge/status-broken-red) | Missing icons |
| 2160p_HSF_en | <img src="./D4Companion/Images/Flags/enUS.png"> | HDR with font set to small for the English language. | ![Static Badge](https://img.shields.io/badge/status-broken-red) | Missing icons temper |
| 2160p_SSF_en | <img src="./D4Companion/Images/Flags/enUS.png"> | SDR (HDR off) with font set to small for the English language. | ![Static Badge](https://img.shields.io/badge/status-broken-red) | Missing icons greater, temper |

Each preset works for both normal and widescreen resolutions. e.g. for 2560x1440 and 3440x1440 use the 1440p preset.

Expand Down Expand Up @@ -148,7 +151,3 @@ MIT
- [d4builds.gg](https://d4builds.gg/)
- [maxroll.gg](https://maxroll.gg/d4/build-guides)
- [mobalitics.gg](https://mobalytics.gg/diablo-4)

## Disclaimer

This app does not interact with Diablo IV, everything is done using image recognition and OCR. However use at your own risk.
Binary file modified downloads/systempresets-v3/1080p_SMF_en.zip
Binary file not shown.
Binary file modified downloads/systempresets-v3/1080p_SMF_es-US.zip
Binary file not shown.
Binary file modified downloads/systempresets-v3/1080p_SMF_fr.zip
Binary file not shown.
Binary file modified downloads/systempresets-v3/1440p_SMF_en.zip
Binary file not shown.
Binary file modified downloads/systempresets-v3/1440p_SMF_fr.zip
Binary file not shown.
Binary file modified downloads/systempresets-v3/1440p_SMF_zh-CN.zip
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Diff not rendered.
Diff not rendered.

0 comments on commit 3bfa768

Please sign in to comment.