-
Notifications
You must be signed in to change notification settings - Fork 1
/
ItemVisualizer.cs
191 lines (163 loc) · 6.65 KB
/
ItemVisualizer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
using System;
using System.Collections.Generic;
using System.Linq;
using ExileCore;
using ExileCore.PoEMemory;
using ExileCore.PoEMemory.Components;
using ExileCore.PoEMemory.Elements;
using ExileCore.PoEMemory.Elements.InventoryElements;
using ExileCore.PoEMemory.MemoryObjects;
using ExileCore.Shared.Enums;
using ItemVisualizer.Core;
using SharpDX;
namespace ItemVisualizer
{
public class ItemVisualizer : BaseSettingsPlugin<Settings>
{
public IngameUIElements _IngameUiElements;
public InventoryElement _InventoryElement;
public StashElement _StashElement;
public Inventory _VisibleStash;
public Element _hoverElement;
public RectangleF _hoverElementRec;
public List<RarityContainer> RarityContainerItems;
public IList<NormalInventoryItem> StashItems { get; set; }
public IList<NormalInventoryItem> InventoryItems { get; set; }
public override bool Initialise()
{
StashItems = new List<NormalInventoryItem>();
InventoryItems = new List<NormalInventoryItem>();
RarityContainerItems = new List<RarityContainer>();
Settings.Enable.OnValueChanged += (sender, enabled) =>
{
if (enabled)
{
// Setup
DebugWindow.LogMsg($"{Name}: enabled", 5);
}
else
{
// Teardown
DebugWindow.LogMsg($"{Name}: disabled", 5);
}
};
return true;
}
public override void Render()
{
UpdateCommonlyUsedData();
try
{
if (_InventoryElement.IsVisibleLocal)
{
var inventoryRarityContainerList = ConvertItemToContainerList(GetInventoryItems());
RarityContainerItems.AddRange(inventoryRarityContainerList);
}
if (_StashElement.IsVisibleLocal)
{
var stashRarityContainerList = ConvertItemToContainerList(GetStashItems());
RarityContainerItems.AddRange(stashRarityContainerList);
}
foreach (var containerItem in RarityContainerItems)
{
var containerItemElement = containerItem.Element;
containerItemElement.Inflate(-4f, -4f);
if (!_hoverElementRec.Intersects(containerItemElement))
Graphics.DrawFrame(containerItemElement, containerItem.Color, 2);
if (containerItem.Corrupted)
{
containerItemElement.Inflate(-3f, -3f);
if (!_hoverElementRec.Intersects(containerItemElement))
Graphics.DrawFrame(containerItemElement, Settings.CorruptedBorder, 2);
}
}
}
catch (Exception e)
{
// cbf writing null checks
}
}
public void UpdateCommonlyUsedData()
{
//reset
RarityContainerItems = new List<RarityContainer>();
_hoverElementRec = new RectangleF(0,0,0,0);
_IngameUiElements = GameController.Game.IngameState.IngameUi;
_InventoryElement = _IngameUiElements.InventoryPanel;
_StashElement = _IngameUiElements.StashElement;
_VisibleStash = _StashElement.VisibleStash;
_hoverElement = GameController.Game.IngameState.UIHover;
if (_hoverElement.Tooltip != null && _hoverElement.Tooltip.IsVisibleLocal)
_hoverElementRec = _hoverElement.Tooltip.GetClientRect();
}
public List<NormalInventoryItem> GetInventoryItems()
{
var inventory = GameController.Game.IngameState.IngameUi.InventoryPanel;
return !inventory.IsVisible
? null
: inventory[InventoryIndex.PlayerInventory].VisibleInventoryItems.ToList();
}
public List<NormalInventoryItem> GetStashItems()
{
var itemList = new List<NormalInventoryItem>();
if (_StashElement.IsVisible)
// Format stash items
switch (_VisibleStash.InvType)
{
case InventoryType.BlightStash:
itemList = _VisibleStash.VisibleInventoryItems.ToList();
itemList.RemoveAt(0);
itemList.RemoveAt(itemList.Count - 1);
break;
case InventoryType.MetamorphStash:
itemList = _VisibleStash.VisibleInventoryItems.ToList();
itemList.RemoveAt(0);
break;
default:
itemList = _VisibleStash.VisibleInventoryItems.ToList();
break;
}
return itemList;
}
public void GetHoveredEntity()
{
_hoverElement = GameController.Game.IngameState.UIHover;
}
public List<RarityContainer> ConvertItemToContainerList(List<NormalInventoryItem> itemList) => itemList.Select(ConvertItemToContainer).ToList();
public RarityContainer ConvertItemToContainer(NormalInventoryItem item)
{
var newContainer = new RarityContainer {Element = item.GetClientRect()};
if (item.Item.HasComponent<Mods>())
newContainer.Color = RarityToColor(item.Item.GetComponent<Mods>().ItemRarity);
if (item.Item.HasComponent<Base>())
newContainer.Corrupted = item.Item.GetComponent<Base>().isCorrupted;
return newContainer;
}
public class RarityContainer
{
public Color Color { get; set; } = Color.Transparent;
public bool Corrupted { get; set; }
public RectangleF Element { get; set; } = new RectangleF(0, 0, 0, 0);
}
public Color RarityToColor(ItemRarity itemRarity)
{
var color = new Color(0,0,0, 0);
switch (itemRarity)
{
case ItemRarity.Normal:
color = Settings.NormalBorder;
break;
case ItemRarity.Magic:
color = Settings.MagicBorder;
break;
case ItemRarity.Rare:
color = Settings.RareBorder;
break;
case ItemRarity.Unique:
color = Settings.UniqueBorder;
break;
}
return color;
}
}
}