forked from IlliumIv/HeistIcons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HeistIconsCore.cs
276 lines (226 loc) · 14.7 KB
/
HeistIconsCore.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
using ExileCore;
using ExileCore.Shared.Cache;
using ExileCore.Shared.Enums;
using ExileCore.Shared.Helpers;
using HeistIcons.Libs;
using SharpDX;
using System;
using System.Linq;
using ExileCore.PoEMemory.MemoryObjects;
using ExileCore.PoEMemory.Components;
using System.Collections.Generic;
namespace HeistIcons
{
public partial class HeistIconsCore : BaseSettingsPlugin<HeistIconsSettings>
{
private IngameUIElements ingameStateIngameUi;
private float k;
private bool largeMap;
private float scale;
private Vector2 screentCenterCache;
private Vector2 playerPos;
private float posZ;
private Dictionary<Entity, (MapIcon, WorldIcon)> Entities = new Dictionary<Entity, (MapIcon, WorldIcon)>();
private CachedValue<RectangleF> _mapRectangle;
private CachedValue<float> _diag;
private ExileCore.PoEMemory.Elements.Map MapWindow => GameController.Game.IngameState.IngameUi.Map;
private RectangleF MapRectangle => _mapRectangle?.Value ?? (_mapRectangle = new TimeCache<RectangleF>(() => MapWindow.GetClientRect(), 100)).Value;
private Camera Camera => GameController.Game.IngameState.Camera;
private float Diag =>
_diag?.Value ?? (_diag = new TimeCache<float>(() =>
{
if (ingameStateIngameUi.Map.SmallMiniMap.IsVisibleLocal)
{
var mapRectangle = ingameStateIngameUi.Map.SmallMiniMap.GetClientRect();
return (float)(Math.Sqrt(mapRectangle.Width * mapRectangle.Width + mapRectangle.Height * mapRectangle.Height) / 2f);
}
return (float)Math.Sqrt(Camera.Width * Camera.Width + Camera.Height * Camera.Height);
}, 100)).Value;
private Vector2 ScreenCenter =>
new Vector2(MapRectangle.Width / 2, MapRectangle.Height / 2 - 20) + new Vector2(MapRectangle.X, MapRectangle.Y) +
new Vector2(MapWindow.LargeMapShiftX, MapWindow.LargeMapShiftY);
public override bool Initialise()
{
Name = "Heist Icons";
return base.Initialise();
}
public override Job Tick()
{
return GameController.MultiThreadManager.AddJob(TickLogic, nameof(HeistIconsCore));
}
private void TickLogic()
{
ingameStateIngameUi = GameController.Game.IngameState.IngameUi;
if (ingameStateIngameUi.Map.SmallMiniMap.IsVisibleLocal)
{
var mapRectangle = ingameStateIngameUi.Map.SmallMiniMap.GetClientRectCache;
screentCenterCache = new Vector2(mapRectangle.X + mapRectangle.Width / 2, mapRectangle.Y + mapRectangle.Height / 2);
largeMap = false;
}
else if (ingameStateIngameUi.Map.LargeMap.IsVisibleLocal)
{
screentCenterCache = ScreenCenter;
largeMap = true;
}
k = Camera.Width < 1024f ? 1120f : 1024f;
scale = k / Camera.Height * Camera.Width * 3.06f / 4f / MapWindow.LargeMapZoom;
playerPos = GameController.Player.GetComponent<Positioned>().GridPos;
posZ = GameController.Player.GetComponent<Render>().Pos.Z;
var validEntities = GameController.EntityListWrapper.OnlyValidEntities;
var displayedEntities = new Dictionary<Entity, (MapIcon, WorldIcon)>();
foreach (var e in validEntities)
{
if (e == null) continue;
if (!e.IsHostile) continue;
if (!e.Path.Contains("Heist")) continue;
if (!e.Path.Contains("Monsters") && !e.Path.Contains("Chest")) continue;
if (e.Type == EntityType.Monster && e.Rarity != MonsterRarity.Unique) continue;
if (e.Type == EntityType.Chest && e.IsOpened) continue;
if (e.Type == EntityType.Monster && e.IsDead) continue;
var icon = GetMapIcon(e);
var worldIcon = GetWorldIcon(e);
if (icon == null && worldIcon == null) continue;
displayedEntities.Add(e, (icon, worldIcon));
}
Entities = displayedEntities;
}
public override void Render()
{
var mapWindowLargeMapZoom = MapWindow.LargeMapZoom;
var displayed = Entities;
foreach (var keyValuePair in displayed)
{
try
{
var e = keyValuePair.Key;
var renderComponent = e?.GetComponent<Render>();
if (renderComponent == null) continue;
string renderName = e.Path
.Replace("Metadata/Chests/LeagueHeist/HeistChest", "")
.Replace("Metadata/Chests/LeaguesHeist/HeistChest", "")
.Replace("Metadata/Chests/LeagueHeist/Heist", "")
.Replace("Military", "")
.Replace("Thug", "")
.Replace("Science", "")
.Replace("Robot", "")
.Replace("Secondary", "");
if (!e.Path.Contains("RewardRoom"))
{
var icon = keyValuePair.Value.Item1;
if (icon == null) continue;
var size = icon.Size * (1 + mapWindowLargeMapZoom);
var iconZ = renderComponent.Pos.Z;
Vector2 position;
if (largeMap)
{
position = screentCenterCache + MapIcon.DeltaInWorldToMinimapDelta(
e.GetComponent<Positioned>().GridPos - playerPos, Diag, scale, (iconZ - posZ) / (9f / mapWindowLargeMapZoom));
Graphics.DrawImage(icon.Texture, new RectangleF(position.X - size / 2f, position.Y - size / 2f, size, size), icon.Color);
}
else
{
position = screentCenterCache + MapIcon.DeltaInWorldToMinimapDelta(
e.GetComponent<Positioned>().GridPos - playerPos, Diag, 240f, (iconZ - posZ) / 20);
var mapRectangle = ingameStateIngameUi.Map.SmallMiniMap.GetClientRectCache;
var rectangle = new RectangleF(position.X - size / 2f, position.Y - size / 2f, size, size);
mapRectangle.Contains(ref rectangle, out var isContain);
if (isContain)
Graphics.DrawImage(icon.Texture, new RectangleF(position.X - size / 2f, position.Y - size / 2f, size, size), icon.Color);
}
}
if (e.Type != EntityType.Chest) continue;
if (Settings.TextEnable || Settings.WorldIcon)
{
var worldtoscreen = Camera.WorldToScreen(e.Pos);
if (Settings.TextEnable)
{
renderName = renderName.Replace("RewardRoom", "")
.Replace("LockPicking", "")
.Replace("BruteForce", "")
.Replace("Perception", "")
.Replace("Demolition", "")
.Replace("CounterThaumaturge", "")
.Replace("TrapDisarmament", "")
.Replace("Agility", "")
.Replace("Deception", "")
.Replace("Engineering", "");
renderName = string.Join("", renderName.ToCharArray().Select(x => char.IsUpper(x) ? " " + x : "" + x).ToList());
renderName += " ";
var textBox = Graphics.MeasureText(renderName);
System.Numerics.Vector2 backgroundBox;
backgroundBox.X = textBox.X + 2;
backgroundBox.Y = textBox.Y * 2f;
var rectangleHeight = backgroundBox.Y;
if (Settings.UseDefaultText)
Graphics.DrawText(renderName, worldtoscreen.ToVector2Num(), Settings.TextColor.Value, 22, "Default:13", FontAlign.Center);
else
{
Graphics.DrawText(renderName, worldtoscreen.ToVector2Num(), Settings.TextColor.Value, 22, FontAlign.Center);
backgroundBox.X *= Settings.BackgroundWidth;
rectangleHeight *= Settings.BackgroundHeight;
}
var rectangle = new RectangleF(worldtoscreen.X - backgroundBox.X / 2, worldtoscreen.Y - (backgroundBox.Y - textBox.Y) / 2, backgroundBox.X, rectangleHeight);
Graphics.DrawBox(rectangle, Settings.TextBackgroundColor.Value);
Graphics.DrawFrame(rectangle, Settings.TextBorderColor.Value, 1);
}
if (Settings.WorldIcon && !e.Path.Contains("RewardRoom"))
{
var icon = keyValuePair.Value.Item2;
if (icon == null) continue;
worldtoscreen = Camera.WorldToScreen(e.Pos.Translate(0, 0, -150));
if (worldtoscreen == new Vector2()) continue;
Graphics.DrawImage(icon.Texture, new RectangleF(worldtoscreen.X - icon.Size / 2f, worldtoscreen.Y - icon.Size / 2f, icon.Size, icon.Size), icon.Color);
}
}
}
catch (Exception ex)
{
LogError($"{Name}: {ex.Message}");
}
}
base.Render();
}
private WorldIcon GetWorldIcon(Entity e)
{
// if (e.Path.Contains("Waypoint")) { return new WorldIcon(GetAtlasTexture("ChestUnopenedGeneric"), Settings.WorldIconSize.Value); }
if (e.Path.Contains("Safe")) { return new WorldIcon(GetAtlasTexture("ChestUnopenedGeneric"), Settings.WorldIconSize.Value); }
if (e.Path.Contains("QualityCurrency")) { return new WorldIcon(GetAtlasTexture("ChestUnopenedCurrency"), Settings.WorldIconSize.Value, Color.Gray); }
if (e.Path.Contains("Currency")) { return new WorldIcon(GetAtlasTexture("ChestUnopenedCurrency"), Settings.WorldIconSize.Value); }
if (e.Path.Contains("Armour")) { return new WorldIcon(GetAtlasTexture("ChestUnopenedArmour"), Settings.WorldIconSize.Value); }
if (e.Path.Contains("Weapons")) { return new WorldIcon(GetAtlasTexture("ChestUnopenedWeapons"), Settings.WorldIconSize.Value); }
if (e.Path.Contains("Jewellery")) { return new WorldIcon(GetAtlasTexture("ChestUnopenedTrinkets"), Settings.WorldIconSize.Value); }
if (e.Path.Contains("Jewels")) { return new WorldIcon(GetAtlasTexture("Jewel"), Settings.WorldIconSize.Value * 0.8f); }
if (e.Path.Contains("Maps")) { return new WorldIcon(GetAtlasTexture("ChestUnopenedMaps"), Settings.WorldIconSize.Value); }
if (e.Path.Contains("DivinationCards")) { return new WorldIcon(GetAtlasTexture("ChestUnopenedDivination"), Settings.WorldIconSize.Value); }
if (e.Path.Contains("StackedDecks")) { return new WorldIcon(GetAtlasTexture("StackedDecks"), Settings.WorldIconSize.Value * 0.8f); }
if (e.Path.Contains("Gems")) { return new WorldIcon(GetAtlasTexture("ChestUnopenedGems"), Settings.WorldIconSize.Value); }
if (e.Path.Contains("Corrupted")) { return new WorldIcon(GetAtlasTexture("Corruption"), Settings.WorldIconSize.Value * 0.8f); }
if (e.Path.Contains("Uniques")) { return new WorldIcon(GetAtlasTexture("ChestUnopenedUniques"), Settings.WorldIconSize.Value); }
if (e.Path.Contains("Prophecies")) { return new WorldIcon(GetAtlasTexture("ChestUnopenedProphecies"), Settings.WorldIconSize.Value); }
if (e.Path.Contains("Essences")) { return new WorldIcon(GetAtlasTexture("ChestUnopenedEssence"), Settings.WorldIconSize.Value); }
return null;
}
public MapIcon GetMapIcon(Entity e)
{
// if (e.Path.Contains("Waypoint")) { return new MapIcon(GetAtlasTexture("HeistPathChest"), Settings.MapIconSize.Value); }
if (e.Path.Contains("Heist") && e.Path.Contains("Monster")) { return new MapIcon(GetAtlasTexture("HeistSpottedMiniBoss"), Settings.MapIconSize.Value * 0.8f); }
if (e.Path.Contains("Smugglers")) { return new MapIcon(GetAtlasTexture("HeistSumgglersCache"), Settings.MapIconSize.Value); }
if (e.Path.Contains("Safe")) { return new MapIcon(GetAtlasTexture("HeistPathChest"), Settings.MapIconSize.Value); }
if (e.Path.Contains("QualityCurrency")) { return new MapIcon(GetAtlasTexture("RewardCurrency"), Settings.MapIconSize.Value, Color.Gray); }
if (e.Path.Contains("Currency")) { return new MapIcon(GetAtlasTexture("RewardCurrency"), Settings.MapIconSize.Value); }
if (e.Path.Contains("Armour")) { return new MapIcon(GetAtlasTexture("RewardArmour"), Settings.MapIconSize.Value); }
if (e.Path.Contains("Weapons")) { return new MapIcon(GetAtlasTexture("RewardWeapons"), Settings.MapIconSize.Value); }
if (e.Path.Contains("Jewellery")) { return new MapIcon(GetAtlasTexture("RewardJewellery"), Settings.MapIconSize.Value); }
if (e.Path.Contains("Jewels")) { return new MapIcon(GetAtlasTexture("Jewel"), Settings.MapIconSize.Value); }
if (e.Path.Contains("Maps")) { return new MapIcon(GetAtlasTexture("RewardMaps"), Settings.MapIconSize.Value); }
if (e.Path.Contains("DivinationCards")) { return new MapIcon(GetAtlasTexture("RewardDivinationCards"), Settings.MapIconSize.Value); }
if (e.Path.Contains("StackedDecks")) { return new MapIcon(GetAtlasTexture("StackedDecks"), Settings.MapIconSize.Value); }
if (e.Path.Contains("Gems")) { return new MapIcon(GetAtlasTexture("RewardGems"), Settings.MapIconSize.Value); }
if (e.Path.Contains("Corrupted")) { return new MapIcon(GetAtlasTexture("Corruption"), Settings.MapIconSize.Value); }
if (e.Path.Contains("Uniques")) { return new MapIcon(GetAtlasTexture("RewardUniques"), Settings.MapIconSize.Value); }
if (e.Path.Contains("Prophecies")) { return new MapIcon(GetAtlasTexture("RewardProphecy"), Settings.MapIconSize.Value); }
if (e.Path.Contains("Essences")) { return new MapIcon(GetAtlasTexture("RewardEssences"), Settings.MapIconSize.Value); }
return null;
}
}
}