Skip to content

Commit

Permalink
Game data updated to 2022-04-25
Browse files Browse the repository at this point in the history
  • Loading branch information
josdemmers committed Apr 27, 2022
1 parent 3e6181a commit 6e7c949
Show file tree
Hide file tree
Showing 3 changed files with 278 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
using NewWorldCompanion.Events;
using NewWorldCompanion.Interfaces;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Imaging;

namespace NewWorldCompanion.ViewModels.Tabs.Debug
{
public class DebugScreenCountOCRViewModel : BindableBase
{
private readonly IEventAggregator _eventAggregator;
private readonly IScreenProcessHandler _screenProcessHandler;
private readonly IOcrHandler _ocrHandler;

private string _itemCount = string.Empty;
private BitmapSource? _ocrImageCount = null;
private BitmapSource? _ocrImageCountRaw = null;

private int _thresholdMinR = 0;
private int _thresholdMinG = 0;
private int _thresholdMinB = 0;
private int _thresholdMaxR = 181;
private int _thresholdMaxG = 195;
private int _thresholdMaxB = 214;

// Start of Constructor region

#region Constructor

public DebugScreenCountOCRViewModel(IEventAggregator eventAggregator, IScreenProcessHandler screenProcessHandler, IOcrHandler ocrHandler)
{
// Init IEventAggregator
_eventAggregator = eventAggregator;
_eventAggregator.GetEvent<OcrImageCountReadyEvent>().Subscribe(HandleOcrImageCountReadyEvent);
_eventAggregator.GetEvent<OcrTextCountReadyEvent>().Subscribe(HandleOcrTextCountReadyEvent);

// Init services
_screenProcessHandler = screenProcessHandler;
_ocrHandler = ocrHandler;

// Init View commands
CopyItemCountCommand = new DelegateCommand(CopyItemCountExecute);
}

#endregion

// Start of Properties region

#region Properties

public DelegateCommand CopyItemCountCommand { get; }

public string ItemCount
{
get => _itemCount;
set
{
_itemCount = value;
RaisePropertyChanged(nameof(ItemCount));
}
}

public int ThresholdMinR
{
get => _thresholdMinR;
set
{
_thresholdMinR = value;
_screenProcessHandler.ProcessImageCountOCRDebug(ThresholdMinR, ThresholdMinG, ThresholdMinB, ThresholdMaxR, ThresholdMaxG, ThresholdMaxB);
}
}

public int ThresholdMinG
{
get => _thresholdMinG;
set
{
_thresholdMinG = value;
_screenProcessHandler.ProcessImageCountOCRDebug(ThresholdMinR, ThresholdMinG, ThresholdMinB, ThresholdMaxR, ThresholdMaxG, ThresholdMaxB);
}
}

public int ThresholdMinB
{
get => _thresholdMinB;
set
{
_thresholdMinB = value;
_screenProcessHandler.ProcessImageCountOCRDebug(ThresholdMinR, ThresholdMinG, ThresholdMinB, ThresholdMaxR, ThresholdMaxG, ThresholdMaxB);
}
}

public int ThresholdMaxR
{
get => _thresholdMaxR;
set
{
_thresholdMaxR = value;
_screenProcessHandler.ProcessImageCountOCRDebug(ThresholdMinR, ThresholdMinG, ThresholdMinB, ThresholdMaxR, ThresholdMaxG, ThresholdMaxB);
}
}

public int ThresholdMaxG
{
get => _thresholdMaxG;
set
{
_thresholdMaxG = value;
_screenProcessHandler.ProcessImageCountOCRDebug(ThresholdMinR, ThresholdMinG, ThresholdMinB, ThresholdMaxR, ThresholdMaxG, ThresholdMaxB);
}
}

public int ThresholdMaxB
{
get => _thresholdMaxB;
set
{
_thresholdMaxB = value;
_screenProcessHandler.ProcessImageCountOCRDebug(ThresholdMinR, ThresholdMinG, ThresholdMinB, ThresholdMaxR, ThresholdMaxG, ThresholdMaxB);
}
}

public BitmapSource? OcrImageCount
{
get => _ocrImageCount;
set
{
_ocrImageCount = value;
RaisePropertyChanged(nameof(OcrImageCount));
}
}

public BitmapSource? OcrImageCountRaw
{
get => _ocrImageCountRaw;
set
{
_ocrImageCountRaw = value;
RaisePropertyChanged(nameof(OcrImageCountRaw));
}
}

#endregion

// Start of Events region

#region Events

private void HandleOcrImageCountReadyEvent()
{
// As the view is accessed by the UI it will need to be created on the UI thread
Application.Current?.Dispatcher?.Invoke(() =>
{
OcrImageCountRaw = Helpers.ScreenCapture.ImageSourceFromBitmap(_screenProcessHandler.OcrImageCountRaw);
OcrImageCount = Helpers.ScreenCapture.ImageSourceFromBitmap(_screenProcessHandler.OcrImageCount);
});
}

private void HandleOcrTextCountReadyEvent()
{
// As the view is accessed by the UI it will need to be created on the UI thread
Application.Current?.Dispatcher?.Invoke(() =>
{
ItemCount = _ocrHandler.OcrTextCount;
});
}

#endregion

// Start of Methods region

#region Methods

private void CopyItemCountExecute()
{
try
{
System.Windows.Clipboard.SetText(ItemCount);
}
catch (Exception) { }
}

#endregion
}
}
58 changes: 58 additions & 0 deletions NewWorldCompanion/Views/Tabs/Debug/DebugScreenCountOCRView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<UserControl x:Class="NewWorldCompanion.Views.Tabs.Debug.DebugScreenCountOCRView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
xmlns:local="clr-namespace:NewWorldCompanion.Views.Tabs.Debug"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<Label Grid.Row="0" Grid.Column="0" Content="Min R" />
<Slider Grid.Row="0" Grid.Column="1" Minimum="0" Maximum="255" Value="{Binding ThresholdMinR}" IsSnapToTickEnabled="True" TickFrequency="1" AutoToolTipPlacement="TopLeft" AutoToolTipPrecision="0"/>
<Label Grid.Row="1" Grid.Column="0" Content="Min G" />
<Slider Grid.Row="1" Grid.Column="1" Minimum="0" Maximum="255" Value="{Binding ThresholdMinG}" IsSnapToTickEnabled="True" TickFrequency="1" AutoToolTipPlacement="TopLeft" AutoToolTipPrecision="0"/>
<Label Grid.Row="2" Grid.Column="0" Content="Min B" />
<Slider Grid.Row="2" Grid.Column="1" Minimum="0" Maximum="255" Value="{Binding ThresholdMinB}" IsSnapToTickEnabled="True" TickFrequency="1" AutoToolTipPlacement="TopLeft" AutoToolTipPrecision="0"/>

<Label Grid.Row="0" Grid.Column="2" Content="Max R" />
<Slider Grid.Row="0" Grid.Column="3" Minimum="0" Maximum="255" Value="{Binding ThresholdMaxR}" IsSnapToTickEnabled="True" TickFrequency="1" AutoToolTipPlacement="TopLeft" AutoToolTipPrecision="0"/>
<Label Grid.Row="1" Grid.Column="2" Content="Max G" />
<Slider Grid.Row="1" Grid.Column="3" Minimum="0" Maximum="255" Value="{Binding ThresholdMaxG}" IsSnapToTickEnabled="True" TickFrequency="1" AutoToolTipPlacement="TopLeft" AutoToolTipPrecision="0"/>
<Label Grid.Row="2" Grid.Column="2" Content="Max B" />
<Slider Grid.Row="2" Grid.Column="3" Minimum="0" Maximum="255" Value="{Binding ThresholdMaxB}" IsSnapToTickEnabled="True" TickFrequency="1" AutoToolTipPlacement="TopLeft" AutoToolTipPrecision="0"/>

<StackPanel Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="5" Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<Image Width="100" HorizontalAlignment="Left" VerticalAlignment="top" Source="{Binding OcrImageCountRaw}"/>
<Image Width="100" HorizontalAlignment="Left" VerticalAlignment="top" Source="{Binding OcrImageCount}"/>
</StackPanel>
</StackPanel>

<StackPanel Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="5">
<Label Content="Item count: "/>
<StackPanel Orientation="Horizontal">
<Label Content="{Binding ItemCount}"/>
<Button BorderThickness="0" Background="Transparent" Focusable="False" Command="{Binding CopyItemCountCommand}">
<iconPacks:PackIconMaterial Kind="ContentCopy" />
</Button>
</StackPanel>
</StackPanel>
</Grid>
</UserControl>
28 changes: 28 additions & 0 deletions NewWorldCompanion/Views/Tabs/Debug/DebugScreenCountOCRView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace NewWorldCompanion.Views.Tabs.Debug
{
/// <summary>
/// Interaction logic for DebugScreenCountOCRView.xaml
/// </summary>
public partial class DebugScreenCountOCRView : UserControl
{
public DebugScreenCountOCRView()
{
InitializeComponent();
}
}
}

0 comments on commit 6e7c949

Please sign in to comment.