Skip to content

Commit

Permalink
Added price overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
josdemmers committed Mar 6, 2022
1 parent 8a2d127 commit 37ef14c
Show file tree
Hide file tree
Showing 39 changed files with 6,275 additions and 7,103 deletions.
2 changes: 1 addition & 1 deletion NewWorldCompanion.Entities/CraftingRecipeJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace NewWorldCompanion.Entities
{
public class CraftingRecipeJson
{
/// <value>Matches SalvageAchievement from MasterItemDefinitionsCrafting</value>
/// <value>Matches SalvageAchievement from MasterItemDefinitionsCraftingJson</value>
public string RequiredAchievementID { get; set; } = string.Empty;
public string Tradeskill { get; set; } = string.Empty;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
{
public class MasterItemDefinitionsCraftingJson
{
/// <value>Website nwdb uses this to identify items</value>
public string ItemID { get; set; } = string.Empty;
/// <value>Contains master name for localisation</value>
public string Name { get; set; } = string.Empty;
/// <value>Matches RequiredAchievementID from CraftingRecipe</value>
/// <value>Used to define if an item is tradable</value>
public bool BindOnPickup { get; set; } = false;
/// <value>Matches RequiredAchievementID from CraftingRecipeJson</value>
public string SalvageAchievement { get; set; } = string.Empty;
}
}
16 changes: 16 additions & 0 deletions NewWorldCompanion.Entities/NwmarketpriceJson.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NewWorldCompanion.Entities
{
public class NwmarketpriceJson
{
public string item_name { get; set; } = string.Empty;
public string last_checked { get; set; } = string.Empty;
public string recent_lowest_price { get; set; } = string.Empty;
//public double recent_lowest_price { get; set; } = 0.0;
}
}
14 changes: 14 additions & 0 deletions NewWorldCompanion.Entities/PriceServer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NewWorldCompanion.Entities
{
public class PriceServer
{
public string Name { get; set; } = string.Empty;
public string Id { get; set; } = string.Empty;
}
}
6 changes: 6 additions & 0 deletions NewWorldCompanion.Entities/SettingsNWC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ namespace NewWorldCompanion.Entities
{
public class SettingsNWC
{
// App
public bool DebugModeActive { get; set; } = false;

// Overlay
public string ServerId { get; set; } = "1";

// Shape detection
public int EmguAreaLower { get; set; } = 10000;
public int EmguAreaUpper { get; set; } = 15000;
Expand Down
17 changes: 17 additions & 0 deletions NewWorldCompanion.Events/OverlayEvents.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Prism.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NewWorldCompanion.Events
{
public class OverlayHideEvent : PubSubEvent
{
}

public class OverlayShowEvent : PubSubEvent
{
}
}
27 changes: 27 additions & 0 deletions NewWorldCompanion.Helpers/BoolConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace NewWorldCompanion.Helpers
{
public class BoolConverter : JsonConverter<bool>
{
public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options) =>
writer.WriteBooleanValue(value);

public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
reader.TokenType switch
{
JsonTokenType.True => true,
JsonTokenType.False => false,
JsonTokenType.String => bool.TryParse(reader.GetString(), out var b) ? b : throw new JsonException(),
JsonTokenType.Number => reader.TryGetInt64(out long l) ? Convert.ToBoolean(l) : reader.TryGetDouble(out double d) ? Convert.ToBoolean(d) : false,
JsonTokenType.Null => false,
_ => throw new JsonException(),
};
}
}
5 changes: 4 additions & 1 deletion NewWorldCompanion.Helpers/ScreenCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Bitmap GetScreenCapture(IntPtr windowHandle)
return bitmap;
}

public Bitmap? GetScreenCaptureMouse(IntPtr windowHandle)
public Bitmap? GetScreenCaptureMouse(IntPtr windowHandle, ref int offsetX, ref int offsetY)
{
Bitmap? bitmap = null;

Expand All @@ -73,6 +73,9 @@ public Bitmap GetScreenCapture(IntPtr windowHandle)
yPos = Math.Min(Math.Max(yPos - height / 2, region.top), region.bottom - height);
bool status = PInvoke.Gdi32.BitBlt(memoryDCHandle.DangerousGetHandle(), 0, 0, width, height, windowDCHandle.DangerousGetHandle(), xPos, yPos, SRCCOPY | CAPTUREBLT);

offsetX = xPos;
offsetY = yPos;

try
{
if (status)
Expand Down
10 changes: 0 additions & 10 deletions NewWorldCompanion.Interfaces/ICraftingRecipeStore.cs

This file was deleted.

13 changes: 13 additions & 0 deletions NewWorldCompanion.Interfaces/IHttpClientHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NewWorldCompanion.Interfaces
{
public interface IHttpClientHandler
{
Task<string> GetRequest(string uri);
}
}
15 changes: 15 additions & 0 deletions NewWorldCompanion.Interfaces/INewWorldDataStore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using NewWorldCompanion.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NewWorldCompanion.Interfaces
{
public interface INewWorldDataStore
{
List<CraftingRecipe> GetCraftingRecipes();
bool IsBindOnPickup(string itemName);
}
}
12 changes: 12 additions & 0 deletions NewWorldCompanion.Interfaces/IOverlayHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NewWorldCompanion.Interfaces
{
public interface IOverlayHandler
{
}
}
17 changes: 17 additions & 0 deletions NewWorldCompanion.Interfaces/IPriceManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using NewWorldCompanion.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NewWorldCompanion.Interfaces
{
public interface IPriceManager
{
List<PriceServer> Servers { get; }

NwmarketpriceJson GetPriceData(string itemName);
void UpdatePriceData(string itemName);
}
}
20 changes: 5 additions & 15 deletions NewWorldCompanion.Interfaces/IScreenCaptureHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,12 @@ namespace NewWorldCompanion.Interfaces
{
public interface IScreenCaptureHandler
{
Bitmap? CurrentScreen
{
get;
}

Bitmap? CurrentScreen { get; }
bool IsActive { get; set; }

public string MouseCoordinates
{
get;
}

public string MouseCoordinatesScaled
{
get;
}
string MouseCoordinates { get; }
string MouseCoordinatesScaled { get; }
int OffsetX { get; }
int OffsetY { get; }

BitmapSource? ImageSourceFromScreenCapture();
}
Expand Down
5 changes: 5 additions & 0 deletions NewWorldCompanion.Interfaces/IScreenProcessHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ public interface IScreenProcessHandler
Bitmap? ProcessedImage { get; }
Bitmap? RoiImage { get; }
Bitmap? OcrImage { get; }

int OverlayX { get; }
int OverlayY { get; }
int OverlayWidth { get; }
int OverlayHeigth { get; }
}
}
8 changes: 4 additions & 4 deletions NewWorldCompanion.Services/CraftingRecipeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ namespace NewWorldCompanion.Services
public class CraftingRecipeManager : ICraftingRecipeManager
{
private readonly IEventAggregator _eventAggregator;
private readonly ICraftingRecipeStore _craftingRecipeStore;
private readonly INewWorldDataStore _newWorldDataStore;

private List<CraftingRecipe> _craftingRecipes = new List<CraftingRecipe>();

// Start of Constructor region

#region Constructor

public CraftingRecipeManager(IEventAggregator eventAggregator, ICraftingRecipeStore craftingRecipeStore)
public CraftingRecipeManager(IEventAggregator eventAggregator, INewWorldDataStore newWorldDataStore)
{
// Init IEventAggregator
_eventAggregator = eventAggregator;

// Init stores
_craftingRecipeStore = craftingRecipeStore;
_newWorldDataStore = newWorldDataStore;

// Init recipes
LoadRecipes();
Expand Down Expand Up @@ -64,7 +64,7 @@ private void LoadRecipes()
}

// Update recipe list
var recipesJson = _craftingRecipeStore.GetCraftingRecipes();
var recipesJson = _newWorldDataStore.GetCraftingRecipes();
foreach (var recipeJson in recipesJson)
{
var recipe = _craftingRecipes.FirstOrDefault(r => r.Id.Equals(recipeJson.Id));
Expand Down
Loading

0 comments on commit 37ef14c

Please sign in to comment.