forked from TehCheat/MinimapIcons
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMinimapIcons.cs
268 lines (225 loc) · 10.8 KB
/
MinimapIcons.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ExileCore;
using ExileCore.PoEMemory.Components;
using ExileCore.PoEMemory.MemoryObjects;
using ExileCore.Shared;
using ExileCore.Shared.Abstract;
using ExileCore.Shared.Cache;
using ExileCore.Shared.Enums;
using ExileCore.Shared.Helpers;
using JM.LinqFaster;
using SharpDX;
using Map = ExileCore.PoEMemory.Elements.Map;
using Vector2 = System.Numerics.Vector2;
namespace MinimapIcons
{
public class MinimapIcons : BaseSettingsPlugin<MapIconsSettings>
{
private const string ALERT_CONFIG = "config\\new_mod_alerts.txt";
private readonly Dictionary<string, Size2> modIcons = new Dictionary<string, Size2>();
private CachedValue<float> _diag;
private CachedValue<RectangleF> _mapRect;
private List<string> ignoreEntites = new List<string>
{
"Metadata/Monsters/Frog/FrogGod/SilverPool",
"Metadata/MiscellaneousObjects/WorldItem",
"Metadata/Pet/Weta/Basic",
"Metadata/Monsters/Daemon/SilverPoolChillDaemon",
"Metadata/Monsters/Daemon",
"Metadata/Monsters/Frog/FrogGod/SilverOrbFromMonsters"
};
private IngameUIElements ingameStateIngameUi;
private float k;
private bool? largeMap;
private float scale;
private Vector2 screentCenterCache;
private RectangleF MapRect => _mapRect?.Value ?? (_mapRect = new TimeCache<RectangleF>(() => mapWindow.GetClientRect(), 100)).Value;
private Map mapWindow => GameController.Game.IngameState.IngameUi.Map;
private Camera camera => GameController.Game.IngameState.Camera;
private float diag =>
_diag?.Value ?? (_diag = new TimeCache<float>(() =>
{
if (ingameStateIngameUi.Map.SmallMiniMap.IsVisibleLocal)
{
var mapRect = ingameStateIngameUi.Map.SmallMiniMap.GetClientRect();
return (float)(Math.Sqrt(mapRect.Width * mapRect.Width + mapRect.Height * mapRect.Height) / 2f);
}
return (float)Math.Sqrt(camera.Width * camera.Width + camera.Height * camera.Height);
}, 100)).Value;
private Vector2 screenCenter =>
new Vector2(MapRect.Width / 2, MapRect.Height / 2 - 20) + new Vector2(MapRect.X, MapRect.Y) +
new Vector2(mapWindow.LargeMapShiftX, mapWindow.LargeMapShiftY);
public override void OnLoad()
{
LoadConfig();
Graphics.InitImage("sprites.png");
Graphics.InitImage("Icons.png");
CanUseMultiThreading = true;
}
public override bool Initialise()
{
return true;
}
private void LoadConfig()
{
var readAllLines = File.ReadAllLines(ALERT_CONFIG);
foreach (var readAllLine in readAllLines)
{
if (readAllLine.StartsWith("#")) continue;
var s = readAllLine.Split(';');
var sz = s[2].Trim().Split(',');
modIcons[s[0]] = new Size2(int.Parse(sz[0]), int.Parse(sz[1]));
}
}
public override Job Tick()
{
if (Settings.MultiThreading)
return GameController.MultiThreadManager.AddJob(TickLogic, nameof(MinimapIcons));
TickLogic();
return null;
}
private void TickLogic()
{
ingameStateIngameUi = GameController.Game.IngameState.IngameUi;
if (ingameStateIngameUi.Map.SmallMiniMap.IsVisibleLocal)
{
var mapRect = ingameStateIngameUi.Map.SmallMiniMap.GetClientRectCache;
screentCenterCache = new Vector2(mapRect.X + mapRect.Width / 2, mapRect.Y + mapRect.Height / 2);
largeMap = false;
}
else if (ingameStateIngameUi.Map.LargeMap.IsVisibleLocal)
{
screentCenterCache = screenCenter;
largeMap = true;
}
else
{
largeMap = null;
}
k = camera.Width < 1024f ? 1120f : 1024f;
scale = k / camera.Height * camera.Width * 3f / 4f / mapWindow.LargeMapZoom;
}
public override void Render()
{
if (!Settings.Enable.Value || !GameController.InGame || Settings.DrawOnlyOnLargeMap && largeMap != true) return;
if (!Settings.IgnoreFullscreenPanels &&
ingameStateIngameUi.FullscreenPanels.Any(x => x.IsVisible) ||
!Settings.IgnoreLargePanels &&
ingameStateIngameUi.LargePanels.Any(x => x.IsVisible))
return;
Positioned playerPositioned = GameController?.Player?.GetComponent<Positioned>();
if (playerPositioned == null) return;
Vector2 playerPos = playerPositioned.WorldPosNum.WorldToGrid();
Render playerRender = GameController?.Player?.GetComponent<Render>();
if (playerRender == null) return;
float posZ = playerRender.PosNum.Z;
if (mapWindow == null) return;
var mapWindowLargeMapZoom = mapWindow.LargeMapZoom;
var baseIcons = GameController?.EntityListWrapper?.OnlyValidEntities
.SelectWhereF(x => x.GetHudComponent<BaseIcon>(), icon => icon != null).OrderByF(x => x.Priority)
.ToList();
if (baseIcons == null) return;
foreach (var icon in baseIcons)
{
if (icon == null) continue;
if (icon.Entity == null) continue;
if (icon.Entity.Type == EntityType.WorldItem)
continue;
if (!icon.Show())
continue;
if (!Settings.DrawMonsters && icon.Entity.Type == EntityType.Monster)
continue;
if (icon.HasIngameIcon && icon.Entity.Type != EntityType.Monster && icon.Entity.League != LeagueType.Heist)
continue;
var component = icon?.Entity?.GetComponent<Render>();
if (component == null) continue;
var iconZ = component.PosNum.Z;
Vector2 position;
if (largeMap == true)
{
position = screentCenterCache + MapIcon.DeltaInWorldToMinimapDelta(
icon.GridPositionNum() - playerPos, diag, scale, (iconZ - posZ) / (9f / mapWindowLargeMapZoom));
}
else if (largeMap == false)
{
position = screentCenterCache +
MapIcon.DeltaInWorldToMinimapDelta(icon.GridPositionNum() - playerPos, diag, 240f, (iconZ - posZ) / 20);
}
else
{
continue;
}
var iconValueMainTexture = icon.MainTexture;
var size = iconValueMainTexture.Size;
var halfSize = size / 2f;
icon.DrawRect = new RectangleF(position.X - halfSize, position.Y - halfSize, size, size);
Graphics.DrawImage(iconValueMainTexture.FileName, icon.DrawRect, iconValueMainTexture.UV, iconValueMainTexture.Color);
if (icon.Hidden())
{
var s = icon.DrawRect.Width * 0.5f;
icon.DrawRect.Inflate(-s, -s);
Graphics.DrawImage(icon.MainTexture.FileName, icon.DrawRect,
SpriteHelper.GetUV(MapIconsIndex.LootFilterSmallCyanCircle), Color.White);
icon.DrawRect.Inflate(s, s);
}
if (!string.IsNullOrEmpty(icon.Text))
Graphics.DrawText(icon.Text, position.Translate(0, Settings.ZForText), FontAlign.Center);
}
if (Settings.DrawNotValid)
{
foreach (var entity in GameController.EntityListWrapper.NotOnlyValidEntities)
{
if (entity.Type == EntityType.WorldItem) continue;
var icon = entity.GetHudComponent<BaseIcon>();
if (icon != null && !entity.IsValid && icon.Show())
{
if (icon.Entity.Type == EntityType.WorldItem)
continue;
if (!Settings.DrawMonsters && icon.Entity.Type == EntityType.Monster)
continue;
if (icon.HasIngameIcon &&
icon.Entity.Type != EntityType.Monster &&
icon.Entity.League != LeagueType.Heist &&
!Settings.DrawReplacementsForGameIconsWhenOutOfRange &&
!icon.Entity.Path.Contains("Metadata/Terrain/Leagues/Delve/Objects/DelveWall"))
continue;
var iconZ = icon.Entity.PosNum.Z;
Vector2 position;
if (largeMap == true)
{
position = screentCenterCache + MapIcon.DeltaInWorldToMinimapDelta(
icon.GridPositionNum() - playerPos, diag, scale, (iconZ - posZ) / (9f / mapWindowLargeMapZoom));
}
else if (largeMap == false)
{
position = screentCenterCache +
MapIcon.DeltaInWorldToMinimapDelta(icon.GridPositionNum() - playerPos, diag, 240f, (iconZ - posZ) / 20);
}
else
{
continue;
}
HudTexture iconValueMainTexture = icon.MainTexture;
var size = iconValueMainTexture.Size;
var halfSize = size / 2f;
icon.DrawRect = new RectangleF(position.X - halfSize, position.Y - halfSize, size, size);
Graphics.DrawImage(iconValueMainTexture.FileName, icon.DrawRect, iconValueMainTexture.UV, iconValueMainTexture.Color);
if (icon.Hidden())
{
var s = icon.DrawRect.Width * 0.5f;
icon.DrawRect.Inflate(-s, -s);
Graphics.DrawImage(icon.MainTexture.FileName, icon.DrawRect,
SpriteHelper.GetUV(MapIconsIndex.LootFilterSmallCyanCircle), Color.White);
icon.DrawRect.Inflate(s, s);
}
if (!string.IsNullOrEmpty(icon.Text))
Graphics.DrawText(icon.Text, position.Translate(0, Settings.ZForText), FontAlign.Center);
}
}
}
}
}
}