Skip to content

Commit

Permalink
Improved implicit affix detection.
Browse files Browse the repository at this point in the history
Added launch minimized option.
  • Loading branch information
josdemmers committed Feb 8, 2025
1 parent c7e8767 commit 4e386bf
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 6 deletions.
1 change: 1 addition & 0 deletions D4Companion.Entities/SettingsD4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class SettingsD4
public bool IsTradeOverlayEnabled { get; set; } = true;
public bool IsUniqueDetectionEnabled { get; set; } = true;
public int ItemPowerLimit { get; set; } = 800;
public bool LaunchMinimized { get; set; } = false;
public int MinimalOcrMatchType { get; set; } = 80;
public bool MinimizeToTray { get; set; } = false;
public List<MultiBuild> MultiBuildList { get; set; } = new List<MultiBuild>();
Expand Down
1 change: 1 addition & 0 deletions D4Companion.Interfaces/IReleaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public interface IReleaseManager
{
List<Release> Releases { get; }
string Repository { get; }
bool UpdateAvailable { get; set; }

void DownloadRelease(string url);
void ExtractRelease(string fileName);
Expand Down
22 changes: 20 additions & 2 deletions D4Companion.Localization/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions D4Companion.Localization/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@
<value>Time in ms between overlay updates. Default 5ms.</value>
</data>
<data name="rsTooltipRenamePreset" xml:space="preserve">
<value>Rename</value>
<value>Rename.</value>
</data>
<data name="rsCapRenamePreset" xml:space="preserve">
<value>Rename</value>
Expand All @@ -785,6 +785,12 @@
<value>Minimize to Tray</value>
</data>
<data name="rsTooltipMinimizeToTray" xml:space="preserve">
<value>Minimize to Tray</value>
<value>Minimize to Tray.</value>
</data>
<data name="rsLaunchMinimized" xml:space="preserve">
<value>Launch Minimized</value>
</data>
<data name="rsTooltipLaunchMinimized" xml:space="preserve">
<value>Launch Minimized.</value>
</data>
</root>
2 changes: 2 additions & 0 deletions D4Companion.Services/ReleaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ReleaseManager : IReleaseManager
private readonly ISettingsManager _settingsManager;

private List<Release> _releases = new List<Release>();
private bool _updateAvailable = false;

// Start of Constructors region

Expand Down Expand Up @@ -56,6 +57,7 @@ public ReleaseManager(IEventAggregator eventAggregator, ILogger<ReleaseManager>

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

#endregion

Expand Down
30 changes: 29 additions & 1 deletion D4Companion.Services/ScreenProcessHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -871,9 +871,10 @@ private void FindItemAffixAreas()
/// Update affix areas with extra information.
/// - Implicit affixes.
/// </summary>
/// <exception cref="NotImplementedException"></exception>
private void UpdateItemAffixAreas()
{
//_logger.LogDebug($"{MethodBase.GetCurrentMethod()?.Name}");

// Check if there are any areas with implicit affixes.
// - Types with implicit affixes: Amulet, Boots, Offhand, Ranged, Ring, Weapon.
// - Implicit area is between a top splitter and the first normal splitter.
Expand All @@ -884,19 +885,29 @@ private void UpdateItemAffixAreas()
_currentTooltip.ItemType.Equals(ItemTypeConstants.Ring) ||
_currentTooltip.ItemType.Equals(ItemTypeConstants.Weapon))
{
//_logger.LogDebug($"{MethodBase.GetCurrentMethod()?.Name}: ItemType: {_currentTooltip.ItemType}");
//_logger.LogDebug($"{MethodBase.GetCurrentMethod()?.Name}: HasTooltipTopSplitter: {_currentTooltip.HasTooltipTopSplitter}");

// Skip if top splitter icon is missing
if (!_currentTooltip.HasTooltipTopSplitter) return;

// List splitter variants
var splittersTop = _currentTooltip.ItemSplitterLocations.FindAll(s => s.Name.Contains("dot-splitter_top"));
var splitters = _currentTooltip.ItemSplitterLocations.FindAll(s => !s.Name.Contains("dot-splitter_top"));

//_logger.LogDebug($"{MethodBase.GetCurrentMethod()?.Name}: Count splittersTop: {splittersTop.Count}");
//_logger.LogDebug($"{MethodBase.GetCurrentMethod()?.Name}: Count splitters: {splitters.Count}");

// Skip if splitters are missing
if (splittersTop.Count == 0) return;
if (splitters.Count == 0) return;

int implicitBeginY = splittersTop[0].Location.Y;
int implicitEndY = splitters[0].Location.Y;

//_logger.LogDebug($"{MethodBase.GetCurrentMethod()?.Name}: implicitBeginY: {implicitBeginY}");
//_logger.LogDebug($"{MethodBase.GetCurrentMethod()?.Name}: implicitEndY: {implicitEndY}");

// Validate implicit area
// - No greater affixes
// - No tempered affixes
Expand All @@ -907,6 +918,8 @@ private void UpdateItemAffixAreas()
if (itemAffixArea.AffixType.Equals(AffixTypeConstants.Greater) ||
itemAffixArea.AffixType.Equals(AffixTypeConstants.Tempered))
{
//_logger.LogDebug($"{MethodBase.GetCurrentMethod()?.Name}: Invalid implicit area. Type {itemAffixArea.AffixType} found.");

// Skip implicit affixes for this item. Implicit area is invalid.
// Probably caused because one of the splitter icons was not detected.
return;
Expand All @@ -920,6 +933,8 @@ private void UpdateItemAffixAreas()
{
if (implicitBeginY <= _currentTooltip.ItemAspectLocation.Location.Y && _currentTooltip.ItemAspectLocation.Location.Y <= implicitEndY)
{
//_logger.LogDebug($"{MethodBase.GetCurrentMethod()?.Name}: Invalid implicit area. Contains aspect.");

// Skip implicit affixes for this item. Implicit area is invalid.
// Probably caused because one of the splitter icons was not detected.
return;
Expand All @@ -931,10 +946,14 @@ private void UpdateItemAffixAreas()
{
if (implicitBeginY <= itemAffixArea.Location.Y && itemAffixArea.Location.Y <= implicitEndY)
{
//_logger.LogDebug($"{MethodBase.GetCurrentMethod()?.Name}: Implicit affix found.");

itemAffixArea.AffixType = AffixTypeConstants.Implicit;
}
}
}

//_logger.LogDebug($"~{MethodBase.GetCurrentMethod()?.Name}");
}

private void UpdateItemAffixAreasWithOcrResults()
Expand Down Expand Up @@ -1471,6 +1490,15 @@ private bool FindItemSplitterLocations()
return x.Location.Top < y.Location.Top ? -1 : x.Location.Top > y.Location.Top ? 1 : 0;
});

// Clean item splitter locations
// This removes dot-splitter locations that matched at the same location as the first dot-splitter_top
var splittersTop = itemSplitterLocations.FindAll(s => s.Name.Contains("dot-splitter_top"));
if (splittersTop.Count > 0)
{
int splitterTopY = splittersTop[0].Location.Y;
itemSplitterLocations.RemoveAll(s => !s.Name.Contains("dot-splitter_top") && s.Location.Y - 2 <= splitterTopY && splitterTopY <= s.Location.Y + 2);
}

foreach (var itemSplitterLocation in itemSplitterLocations)
{
_currentTooltip.ItemSplitterLocations.Add(itemSplitterLocation);
Expand Down
26 changes: 25 additions & 1 deletion D4Companion/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ private void ApplicationLoadedExecute()
{
_logger.LogInformation(WindowTitle);

if (_settingsManager.Settings.LaunchMinimized && !_releaseManager.UpdateAvailable)
{
Application.Current.MainWindow.WindowState = WindowState.Minimized;
}

_eventAggregator.GetEvent<ApplicationLoadedEvent>().Publish();
}

Expand All @@ -139,6 +144,7 @@ private void HandleReleaseInfoUpdatedEvent()

if (latest > current)
{
_releaseManager.UpdateAvailable = true;
WindowTitle = $"Diablo IV Companion v{Assembly.GetExecutingAssembly().GetName().Version} ({release.Version} available)";
_eventAggregator.GetEvent<InfoOccurredEvent>().Publish(new InfoOccurredEventParams
{
Expand All @@ -148,6 +154,17 @@ private void HandleReleaseInfoUpdatedEvent()
// Open update dialog
if (File.Exists("D4Companion.Updater.exe"))
{
// Restore GUI when hidden.
Application.Current?.Dispatcher?.Invoke(() =>
{
if (Application.Current.MainWindow.Visibility == Visibility.Collapsed)
{
Application.Current.MainWindow.Show();
Application.Current.MainWindow.WindowState = WindowState.Normal;
Application.Current.MainWindow.Topmost = true;
}
});

_dialogCoordinator.ShowMessageAsync(this, $"Update", $"New version available, do you want to download {release.Version}?", MessageDialogStyle.AffirmativeAndNegative).ContinueWith(t =>
{
if (t.Result == MessageDialogResult.Affirmative)
Expand Down Expand Up @@ -311,7 +328,14 @@ private void WindowStateChangedExecute()
{
case WindowState.Minimized:
{
Application.Current.MainWindow.Visibility = Visibility.Collapsed;
if (_releaseManager.UpdateAvailable)
{
Application.Current.MainWindow.WindowState = WindowState.Normal;
}
else
{
Application.Current.MainWindow.Visibility = Visibility.Collapsed;
}
break;
}
}
Expand Down
12 changes: 12 additions & 0 deletions D4Companion/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ public bool IsDevModeEnabled
}
}

public bool IsLaunchMinimizedEnabled
{
get => _settingsManager.Settings.LaunchMinimized;
set
{
_settingsManager.Settings.LaunchMinimized = value;
RaisePropertyChanged(nameof(IsLaunchMinimizedEnabled));

_settingsManager.SaveSettings();
}
}

public bool IsMinimizeToTrayEnabled
{
get => _settingsManager.Settings.MinimizeToTray;
Expand Down
12 changes: 12 additions & 0 deletions D4Companion/Views/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@
</Label>
</Grid>

<Grid>
<mah:ToggleSwitch
Margin="0 0 0 0"
IsOn="{Binding IsLaunchMinimizedEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
OffContent="{loc:LocExtension rsLaunchMinimized}"
OnContent="{loc:LocExtension rsLaunchMinimized}"
ToolTip="{loc:LocExtension rsTooltipLaunchMinimized}"/>
<Label Margin="0 0 5 0" HorizontalAlignment="Right" VerticalAlignment="Center" ToolTip="{loc:LocExtension rsTooltipLaunchMinimized}">
<iconPacks:PackIconMaterial Kind="InformationOutline" Width="16" Height="16"/>
</Label>
</Grid>

<Grid>
<mah:ToggleSwitch
Margin="0 0 0 0"
Expand Down

0 comments on commit 4e386bf

Please sign in to comment.