Skip to content

Commit

Permalink
fix and new features
Browse files Browse the repository at this point in the history
  • Loading branch information
TiuDerca committed May 30, 2022
1 parent 1cf144c commit 8a6a699
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 100 deletions.
194 changes: 151 additions & 43 deletions Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@
using System.IO;
using System.Linq;
using System.Net;
using ExileCore.PoEMemory.MemoryObjects;

namespace Tradie
{
public partial class Core : BaseSettingsPlugin<Settings>
{
private readonly List<string> _whiteListedPaths = new List<string>
{
"Art/2DItems/Currency"

"Art/2DItems/Currency",
"Art/2DItems/Divination",
//TODO, maps are loading strange and causing too many draw issues
//"Art/2DItems/Maps"
"Art/2DItems/Maps",

};

private List<string> _initializedImageList = new List<string>();
Expand All @@ -34,15 +36,33 @@ public override void Render()

private void ShowNpcTradeItems()
{
if (!NpcTradeWindowVisible)
if (!NpcTradeWindowVisible && Settings.UseCoreNPCTrade == false)
return;

SellWindowHideout npcTradingWindow = Settings.UseCoreNPCTrade ? GameController.Game.IngameState.IngameUi.SellWindowHideout
:GetNpcTradeWindow() as SellWindowHideout
;

if (npcTradingWindow == null || npcTradingWindow.IsVisible == false)
{
return;
var npcTradingWindow = GetNpcTradeWindow();
var tradingItems = GetItemsInTradingWindow(npcTradingWindow);
}

var tradingItems = GetItemsInSellWindow(npcTradingWindow);



var ourData = new ItemDisplay
{
Items = GetItemObjects(tradingItems.ourItems).OrderBy(item => item.Path),
X = Settings.YourItemStartingLocationX,
Y = Settings.YourItemStartingLocationY,

X = Settings.UseHorizon ?
(int)npcTradingWindow.YourOffer.GetClientRect().TopLeft.X
: Settings.YourItemStartingLocationX,

Y = Settings.UseHorizon ?
(int)npcTradingWindow.YourOffer.GetClientRect().TopLeft.Y - Settings.ImageSize
: Settings.YourItemStartingLocationY,
TextSize = Settings.TextSize,
TextColor = Settings.YourItemTextColor,
BackgroundColor = Settings.YourItemBackgroundColor,
Expand All @@ -55,8 +75,9 @@ private void ShowNpcTradeItems()
var theirData = new ItemDisplay
{
Items = GetItemObjects(tradingItems.theirItems).OrderBy(item => item.Path),
X = Settings.TheirItemStartingLocationX,
Y = Settings.TheirItemStartingLocationY,
X =Settings.UseHorizon ? (int)npcTradingWindow.OtherOffer.GetClientRect().TopLeft.X
: Settings.TheirItemStartingLocationX,
Y =Settings.UseHorizon ? (int)npcTradingWindow.OtherOffer.GetClientRect().TopLeft.Y - Settings.ImageSize: Settings.TheirItemStartingLocationY,
TextSize = Settings.TextSize,
TextColor = Settings.TheirItemTextColor,
BackgroundColor = Settings.TheirItemBackgroundColor,
Expand All @@ -74,15 +95,27 @@ private void ShowNpcTradeItems()

private void ShowPlayerTradeItems()
{
if (!TradingWindowVisible)


if (!TradingWindowVisible && Settings.UseCoreYourItems == false)
return;
var tradingWindow = GetTradingWindow();

TradeWindow tradingWindow = Settings.UseCoreYourItems ? GameController.Game.IngameState.IngameUi.TradeWindow
:GetTradingWindow() as TradeWindow
;
if (tradingWindow == null || tradingWindow.IsVisible == false)
{
return;
}

var tradingItems = GetItemsInTradingWindow(tradingWindow);
var ourData = new ItemDisplay
{
Items = GetItemObjects(tradingItems.ourItems).OrderBy(item => item.Path),
X = Settings.YourItemStartingLocationX,
Y = Settings.YourItemStartingLocationY,
X =Settings.UseHorizon ? (int)tradingWindow.OtherOfferElement.GetClientRect().TopLeft.X
: Settings.YourItemStartingLocationX,
Y =Settings.UseHorizon ? (int)tradingWindow.OtherOfferElement.GetClientRect().TopLeft.Y - Settings.ImageSize
: Settings.YourItemStartingLocationY,
TextSize = Settings.TextSize,
TextColor = Settings.YourItemTextColor,
BackgroundColor = Settings.YourItemBackgroundColor,
Expand All @@ -95,8 +128,10 @@ private void ShowPlayerTradeItems()
var theirData = new ItemDisplay
{
Items = GetItemObjects(tradingItems.theirItems).OrderBy(item => item.Path),
X = Settings.TheirItemStartingLocationX,
Y = Settings.TheirItemStartingLocationY,
X =Settings.UseHorizon ? (int)tradingWindow.YourOfferElement.GetClientRect().TopLeft.X
: Settings.TheirItemStartingLocationX,
Y =Settings.UseHorizon ? (int)tradingWindow.YourOfferElement.GetClientRect().TopLeft.Y - Settings.ImageSize
: Settings.TheirItemStartingLocationY,
TextSize = Settings.TextSize,
TextColor = Settings.TheirItemTextColor,
BackgroundColor = Settings.TheirItemBackgroundColor,
Expand All @@ -117,35 +152,64 @@ private void DrawCurrency(ItemDisplay data)
const string symbol = "-";
var counter = 0;
var newColor = data.BackgroundColor;
newColor.A = (byte) data.BackgroundTransparency;
newColor.A = (byte)data.BackgroundTransparency;
var maxCount = data.Items.Max(i => i.Amount);
var lengthText = Graphics.MeasureText(symbol + " " + maxCount, data.TextSize).X;

var background = new RectangleF(data.LeftAlignment ? data.X : data.X + data.ImageSize, data.Y,
data.LeftAlignment
? +data.ImageSize + data.Spacing + 3 +
Graphics.MeasureText(symbol + " " + maxCount, data.TextSize).X
: -data.ImageSize - data.Spacing - 3 -
Graphics.MeasureText(symbol + " " + maxCount, data.TextSize).X,
data.Ascending ? -data.ImageSize * data.Items.Count() : data.ImageSize * data.Items.Count());
if (Settings.UseHorizon)
{
var background = new RectangleF(data.X, data.Y,
(data.ImageSize + data.Spacing * 2 + lengthText) * data.Items.Count(),
data.ImageSize);

Graphics.DrawBox(background, newColor);
Graphics.DrawBox(background, newColor);

foreach (var ourItem in data.Items)
foreach (var ourItem in data.Items)
{
var imageBox = new RectangleF(
data.X + counter * (data.ImageSize + data.Spacing * 2 + lengthText),
data.Y,
data.ImageSize, data.ImageSize);

Graphics.DrawImageGui(ourItem.Path, imageBox, new RectangleF(0, 0, 1, 1));

Graphics.DrawText($"{symbol} {ourItem.Amount}",
new Vector2(
imageBox.Center.X + imageBox.Width / 2 + data.Spacing / 2,
imageBox.Center.Y - data.TextSize / 2 - 3)
, data.TextColor,
FontAlign.Left);
counter++;
}
}
else
{
counter++;
var imageBox = new RectangleF(data.X,
data.Ascending
? data.Y - counter * data.ImageSize
: data.Y - data.ImageSize + counter * data.ImageSize,
data.ImageSize, data.ImageSize);

Graphics.DrawImageGui(ourItem.Path, imageBox, new RectangleF(0, 0, 1, 1));
var background = new RectangleF(data.LeftAlignment ? data.X : data.X + data.ImageSize, data.Y,
data.LeftAlignment
? +data.ImageSize + data.Spacing + 3 +
Graphics.MeasureText(symbol + " " + maxCount, data.TextSize).X
: -data.ImageSize - data.Spacing - 3 -
Graphics.MeasureText(symbol + " " + maxCount, data.TextSize).X,
data.Ascending ? -data.ImageSize * data.Items.Count() : data.ImageSize * data.Items.Count());

Graphics.DrawText(data.LeftAlignment ? $"{symbol} {ourItem.Amount}" : $"{ourItem.Amount} {symbol}",
new Vector2(data.LeftAlignment ? data.X + data.ImageSize + data.Spacing : data.X - data.Spacing,
imageBox.Center.Y - data.TextSize / 2 - 3), data.TextColor,
data.LeftAlignment ? FontAlign.Left : FontAlign.Right);
Graphics.DrawBox(background, newColor);

foreach (var ourItem in data.Items)
{
counter++;
var imageBox = new RectangleF(data.X,
data.Ascending
? data.Y - counter * data.ImageSize
: data.Y - data.ImageSize + counter * data.ImageSize,
data.ImageSize, data.ImageSize);

Graphics.DrawImageGui(ourItem.Path, imageBox, new RectangleF(0, 0, 1, 1));

Graphics.DrawText(data.LeftAlignment ? $"{symbol} {ourItem.Amount}" : $"{ourItem.Amount} {symbol}",
new Vector2(data.LeftAlignment ? data.X + data.ImageSize + data.Spacing : data.X - data.Spacing,
imageBox.Center.Y - data.TextSize / 2 - 3), data.TextColor,
data.LeftAlignment ? FontAlign.Left : FontAlign.Right);
}
}
}

Expand Down Expand Up @@ -191,7 +255,51 @@ private Element GetNpcTradeWindow()
}
}

private (List<NormalInventoryItem> ourItems, List<NormalInventoryItem> theirItems) GetItemsInTradingWindow(Element tradingWindow)
private (List<NormalInventoryItem> ourItems, List<NormalInventoryItem> theirItems) GetItemsInSellWindow(SellWindowHideout tradingWindow)
{
var ourItems = new List<NormalInventoryItem>();
var theirItems = new List<NormalInventoryItem>();
if (tradingWindow.ChildCount < 2)
{
return (ourItems, theirItems);
}

var ourItemsElement = tradingWindow.YourOffer;
var theirItemsElement = tradingWindow.OtherOffer;


// We are skipping the first, since it's a Element ("Place items you want to trade here") that we don't need.
//
// skipping the first item as its a strange object added after 3.3 Incursion
foreach (var ourElement in ourItemsElement.Children.Skip(1))
{
var normalInventoryItem = ourElement.AsObject<NormalInventoryItem>();
if (normalInventoryItem == null)
{
LogMessage("Tradie: OurItem was null!", 5);
throw new Exception("Tradie: OurItem was null!");
}

ourItems.Add(normalInventoryItem);
}

// skipping the first item as its a strange object added after 3.3 Incursion
foreach (var theirElement in theirItemsElement.Children.Skip(1))
{
var normalInventoryItem = theirElement.AsObject<NormalInventoryItem>();
if (normalInventoryItem == null)
{
LogMessage("Tradie: OurItem was null!", 5);
throw new Exception("Tradie: OurItem was null!");
}

theirItems.Add(normalInventoryItem);
}

return (ourItems, theirItems);
}

private (List<NormalInventoryItem> ourItems, List<NormalInventoryItem> theirItems) GetItemsInTradingWindow(TradeWindow tradingWindow)
{
var ourItems = new List<NormalInventoryItem>();
var theirItems = new List<NormalInventoryItem>();
Expand All @@ -200,14 +308,14 @@ private Element GetNpcTradeWindow()
return (ourItems, theirItems);
}

var ourItemsElement = tradingWindow.GetChildAtIndex(0);
var theirItemsElement = tradingWindow.GetChildAtIndex(1);
var ourItemsElement = tradingWindow.OtherOfferElement;
var theirItemsElement = tradingWindow.YourOfferElement;


// We are skipping the first, since it's a Element ("Place items you want to trade here") that we don't need.
//
// skipping the first item as its a strange object added after 3.3 Incursion
foreach (var ourElement in ourItemsElement.Children.Skip(2))
foreach (var ourElement in ourItemsElement.Children.Skip(1))
{
var normalInventoryItem = ourElement.AsObject<NormalInventoryItem>();
if (normalInventoryItem == null)
Expand Down Expand Up @@ -243,7 +351,7 @@ private IEnumerable<Item> GetItemObjects(IEnumerable<NormalInventoryItem> normal
foreach (var normalInventoryItem in normalInventoryItems)
try
{
if (normalInventoryItem.Item == null) continue;
if (normalInventoryItem.Item == null || normalInventoryItem.Item.Address < 1) continue;
var metaData = normalInventoryItem.Item.GetComponent<RenderItem>().ResourcePath;
if (metaData.Equals("")) continue;
if (!IsWhitelisted(metaData))
Expand Down
20 changes: 20 additions & 0 deletions Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public Settings()
YourItemStartingLocationX = new RangeNode<int>(966, 0, 2560);
YourItemStartingLocationY = new RangeNode<int>(863, 0, 2560);
YourItemsAscending = new ToggleNode(true);
UseCoreNPCTrade = new ToggleNode(true);
UseCoreYourItems = new ToggleNode(true);
YourItemTextColor = Color.LightBlue;
YourItemBackgroundColor = Color.Black;
YourItemsImageLeftOrRight = new ToggleNode(true);
Expand All @@ -28,18 +30,36 @@ public Settings()
TheirItemBackgroundColor = Color.Black;
TheirItemsImageLeftOrRight = new ToggleNode(false);
}

//[Menu("Auto Search")]
//public ButtonNode AutoSearch { get; set; } = new ButtonNode();

[Menu("NPC Trade Window Index #")]
public RangeNode<int> NPCTradeIndex { get; set; } = new RangeNode<int>(93, 0, 400);
[Menu("Use core NPC Trade Window")]

public ToggleNode UseCoreNPCTrade { get; set; } = new ToggleNode(true);


[Menu("Player Trade Window Index #")]
public RangeNode<int> PlayerTradeIndex { get; set; } = new RangeNode<int>(94, 0, 400);

[Menu("Use core Player Trade Window")]

public ToggleNode UseCoreYourItems { get; set; } = new ToggleNode(true);


[Menu("Image Size")]
public RangeNode<int> ImageSize { get; set; }
[Menu("Text Size")]
public RangeNode<int> TextSize { get; set; }
[Menu("Spacing", "Spacing between image and text")]
public RangeNode<int> Spacing { get; set; }

[Menu("Use horizontal view")]

public ToggleNode UseHorizon { get; set; } = new ToggleNode(true);

[Menu("Your Trade Items", 1001)]
public EmptyNode Blank1 { get; set; }
[Menu("X", 10011, 1001)]
Expand Down
Loading

0 comments on commit 8a6a699

Please sign in to comment.