Skip to content

Commit

Permalink
- Added app update notification.
Browse files Browse the repository at this point in the history
- Fixed detection of multiline affixes.
- Improve multiline aspect detection.
- Changed affix/aspect view to text.
- Updated system preset: 1920x1080_SMF_en.zip
  • Loading branch information
josdemmers committed Jul 11, 2023
1 parent a3c60d1 commit 90ad686
Show file tree
Hide file tree
Showing 31 changed files with 259 additions and 125 deletions.
9 changes: 1 addition & 8 deletions D4Companion.Entities/ItemAffix.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO.Enumeration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace D4Companion.Entities
namespace D4Companion.Entities
{
public class ItemAffix
{
Expand Down
40 changes: 40 additions & 0 deletions D4Companion.Entities/Release.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Text.Json.Serialization;

namespace D4Companion.Entities
{
public class Release
{
[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;
[JsonPropertyName("assets")]
public List<Assets> Assets { get; set; } = new List<Assets>();
[JsonPropertyName("body")]
public string Body { get; set; } = string.Empty;
[JsonPropertyName("tag_name")]
public string Version { get; set; } = string.Empty;
[JsonPropertyName("created_at")]
public DateTime CreatedAt { get; set; } = DateTime.MinValue;
[JsonPropertyName("published_at")]
public DateTime PublishedAt { get; set; } = DateTime.MinValue;
}

public class Assets
{
[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;
/// <summary>
/// zip: application/x-zip-compressed
/// </summary>
[JsonPropertyName("content_type")]
public string ContentType { get; set; } = string.Empty;
[JsonPropertyName("size")]
public int Size { get; set; }
[JsonPropertyName("created_at")]
public DateTime CreatedAt { get; set; } = DateTime.MinValue;
[JsonPropertyName("updated_at")]
public DateTime UpdatedAt { get; set; } = DateTime.MinValue;
[JsonPropertyName("browser_download_url")]
public string BrowserDownloadUrl { get; set; } = string.Empty;

}
}
14 changes: 9 additions & 5 deletions D4Companion.Events/LoggingEvents.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
using Prism.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace D4Companion.Events
{
public class InfoOccurredEvent : PubSubEvent<InfoOccurredEventParams>
{
}

public class InfoOccurredEventParams
{
public string Message { get; set; } = string.Empty;
}

public class ErrorOccurredEvent : PubSubEvent<ErrorOccurredEventParams>
{
}
Expand Down
6 changes: 6 additions & 0 deletions D4Companion.Events/ReleaseManagerEvents.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using Prism.Events;

namespace D4Companion.Events
{
public class ReleaseInfoUpdatedEvent : PubSubEvent { }
}
10 changes: 10 additions & 0 deletions D4Companion.Interfaces/IReleaseManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using D4Companion.Entities;

namespace D4Companion.Interfaces
{
public interface IReleaseManager
{
List<Release> Releases { get; }
string Repository { get; }
}
}
60 changes: 11 additions & 49 deletions D4Companion.Services/OverlayHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,21 @@ private void DrawGraphics(object? sender, DrawGraphicsEventArgs e)
if (_currentTooltip.ItemAffixLocations.Any())
{
int length = 10;
int affixLocationHeight = 0;

foreach (var itemAffixLocation in _currentTooltip.ItemAffixLocations)
{
float left = _currentTooltip.Location.X;
float top = _currentTooltip.Location.Y + itemAffixLocation.Y + (itemAffixLocation.Height / 2);
float top = _currentTooltip.Location.Y + itemAffixLocation.Y;
affixLocationHeight = itemAffixLocation.Height;

if (!CheckAffixLocationHasPreferedAffix(_currentTooltip, top))
{
gfx.OutlineFillCircle(_brushes["black"], _brushes["red"], left, top, length, 2);
gfx.OutlineFillCircle(_brushes["black"], _brushes["red"], left, top + (itemAffixLocation.Height / 2), length, 2);
}
}

foreach (var itemAffix in _currentTooltip.ItemAffixes)
{
float left = _currentTooltip.Location.X;
float top = _currentTooltip.Location.Y + itemAffix.Y + (itemAffix.Height / 2);

if (CheckAffixHasValidLocation(_currentTooltip, top))
else
{
gfx.OutlineFillCircle(_brushes["black"], _brushes["green"], left, top, length, 2);
gfx.OutlineFillCircle(_brushes["black"], _brushes["green"], left, top + (affixLocationHeight / 2), length, 2);
}
}
}
Expand All @@ -119,22 +114,17 @@ private void DrawGraphics(object? sender, DrawGraphicsEventArgs e)

var itemAspectLocation = _currentTooltip.ItemAspectLocation;
float left = _currentTooltip.Location.X;
//float top = _currentTooltip.Location.Y + itemAspectLocation.Y + (itemAspectLocation.Height / 2);
float top = _currentTooltip.Location.Y + itemAspectLocation.Y;
if (!CheckAspectLocationHasPreferedAspect(_currentTooltip, top))

if (_currentTooltip.ItemAspect.IsEmpty)
{
gfx.OutlineFillCircle(_brushes["black"], _brushes["red"], left, top + (itemAspectLocation.Height / 2), length, 2);
}

var itemAspect = _currentTooltip.ItemAspect;
//top = _currentTooltip.Location.Y + itemAspect.Y + (itemAspect.Height / 2);
top = _currentTooltip.Location.Y + itemAspect.Y;
if (CheckAspectHasValidLocation(_currentTooltip, top))
else
{
gfx.OutlineFillCircle(_brushes["black"], _brushes["green"], left, top + (itemAspectLocation.Height / 2), length, 2);
}
}

}

// Menu items
Expand Down Expand Up @@ -331,46 +321,18 @@ private void HandleMenuItemAction(string id, bool isLocked)
}
}

private bool CheckAffixHasValidLocation(ItemTooltipDescriptor tooltip, float top)
{
foreach (var itemAffixLocation in tooltip.ItemAffixLocations)
{
float topMatch = tooltip.Location.Y + itemAffixLocation.Y + (itemAffixLocation.Height / 2);

if (Math.Abs(top - topMatch) < 5) return true;
}

return false;
}

private bool CheckAffixLocationHasPreferedAffix(ItemTooltipDescriptor tooltip, float top)
{
foreach (var itemAffix in tooltip.ItemAffixes)
{
float topMatch = tooltip.Location.Y + itemAffix.Y + (itemAffix.Height / 2);
float topMatch = tooltip.Location.Y + itemAffix.Y;

if (Math.Abs(top - topMatch) < 5) return true;
if (Math.Abs(top - topMatch) < 10) return true;
}

return false;
}

private bool CheckAspectHasValidLocation(ItemTooltipDescriptor tooltip, float top)
{
var itemAspectLocation = tooltip.ItemAspectLocation;
//float topMatch = _currentTooltip.Location.Y + itemAspectLocation.Y + (itemAspectLocation.Height / 2);
float topMatch = tooltip.Location.Y + itemAspectLocation.Y;
return Math.Abs(top - topMatch) < 5;
}

private bool CheckAspectLocationHasPreferedAspect(ItemTooltipDescriptor tooltip, float top)
{
var itemAspect = tooltip.ItemAspect;
//float topMatch = _currentTooltip.Location.Y + itemAspect.Y + (itemAspect.Height / 2);
float topMatch = tooltip.Location.Y + itemAspect.Y;
return Math.Abs(top - topMatch) < 5;
}

#endregion
}

Expand Down
87 changes: 87 additions & 0 deletions D4Companion.Services/ReleaseManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using D4Companion.Entities;
using D4Companion.Events;
using D4Companion.Interfaces;
using Microsoft.Extensions.Logging;
using Prism.Events;
using System.Text.Json;

namespace D4Companion.Services
{
public class ReleaseManager : IReleaseManager
{
private readonly IEventAggregator _eventAggregator;
private readonly ILogger _logger;
private readonly IHttpClientHandler _httpClientHandler;

private List<Release> _releases = new List<Release>();

// Start of Constructors region

#region Constructors

public ReleaseManager(IEventAggregator eventAggregator, ILogger<ReleaseManager> logger, HttpClientHandler httpClientHandler)
{
// Init IEventAggregator
_eventAggregator = eventAggregator;

// Init logger
_logger = logger;

// Init services
_httpClientHandler = httpClientHandler;

// Update release info
Task.Factory.StartNew(() =>
{
UpdateAvailableReleases();
});
}

#endregion

// Start of Events region

#region Events

#endregion

// Start of Properties region

#region Properties

public List<Release> Releases { get => _releases; set => _releases = value; }
public string Repository { get; } = "https://api.github.com/repos/josdemmers/diablo4Companion/releases";

#endregion

// Start of Event handlers region

#region Event handlers

#endregion

// Start of Methods region

#region Methods

private async void UpdateAvailableReleases()
{
_logger.LogInformation($"Updating release info from: {Repository}");

string json = await _httpClientHandler.GetRequest(Repository);
if (!string.IsNullOrWhiteSpace(json))
{
Releases.Clear();
Releases = JsonSerializer.Deserialize<List<Release>>(json) ?? new List<Release>();

}
else
{
_logger.LogWarning($"Invalid response. uri: {Repository}");
}
_eventAggregator.GetEvent<ReleaseInfoUpdatedEvent>().Publish();
}

#endregion
}
}
2 changes: 1 addition & 1 deletion D4Companion.Services/ScreenProcessHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ private List<ItemAffixDescriptor> FindItemAffix(Image<Gray, byte> currentTooltip
CvInvoke.MatchTemplate(currentTooltipImage, currentItemAffixImage, result, Emgu.CV.CvEnum.TemplateMatchingType.SqdiffNormed);
CvInvoke.MinMaxLoc(result, ref minVal, ref maxVal, ref minLoc, ref maxLoc);

_logger.LogDebug($"{MethodBase.GetCurrentMethod()?.Name}: ({currentItemAffix}) Similarity: {String.Format("{0:0.0000000000}", minVal)}");
//_logger.LogDebug($"{MethodBase.GetCurrentMethod()?.Name}: ({currentItemAffix}) Similarity: {String.Format("{0:0.0000000000}", minVal)}");

// Note: Ignore minVal == 0 results. Looks like they are random false positives. Requires more testing
// Unfortunately also valid matches, can't ignore the results.
Expand Down
1 change: 1 addition & 0 deletions D4Companion/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ protected override void RegisterTypes(IContainerRegistry containerRegistry)
containerRegistry.RegisterSingleton<IAffixPresetManager, AffixPresetManager>();
containerRegistry.RegisterSingleton<IHttpClientHandler, HttpClientHandler>();
containerRegistry.RegisterSingleton<IOverlayHandler, OverlayHandler>();
containerRegistry.RegisterSingleton<IReleaseManager, ReleaseManager>();
containerRegistry.RegisterSingleton<ISettingsManager, SettingsManager>();
containerRegistry.RegisterSingleton<IScreenCaptureHandler, ScreenCaptureHandler>();
containerRegistry.RegisterSingleton<IScreenProcessHandler, ScreenProcessHandler>();
Expand Down
23 changes: 23 additions & 0 deletions D4Companion/Converters/FileNameToFileNameNoExtConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Globalization;
using System.IO;
using System.Windows.Data;

namespace D4Companion.Converters
{
[ValueConversion(typeof(string), typeof(string))]
public class FileNameToFileNameNoExtConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null) return string.Empty;

return Path.GetFileNameWithoutExtension((string)value);
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
Loading

0 comments on commit 90ad686

Please sign in to comment.