-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapModHighlight.cs
More file actions
93 lines (80 loc) · 2.94 KB
/
MapModHighlight.cs
File metadata and controls
93 lines (80 loc) · 2.94 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using ExileCore;
using ExileCore.PoEMemory;
using ExileCore.PoEMemory.Elements;
using ExileCore.Shared.Helpers;
using Vector2 = System.Numerics.Vector2;
namespace MapModHighlight;
public class MapModHighlight : BaseSettingsPlugin<MapModHighlightSettings>
{
public override bool Initialise()
{
return true;
}
public override Job Tick()
{
return null;
}
internal Element FindRegularModElement(Element hoveredItem)
{
var tooltip = hoveredItem?.AsObject<HoverItemIcon>().ItemFrame;
if (tooltip is not { IsValid: true, IsVisible: true })
{
return null;
}
var modsRoot = tooltip.GetChildAtIndex(1);
if (modsRoot == null)
return null;
for (var i = modsRoot.Children.Count - 1; i >= 1; i--)
{
var element = modsRoot.Children[i];
if (element.ChildCount is > 2 or 0)
{
continue;
}
var textElements = GetExtendedModsTextElements(element);
var elementText = textElements.FirstOrDefault()?.Text;
if (!string.IsNullOrEmpty(elementText) &&
(elementText.StartsWith("<smaller>", StringComparison.Ordinal) ||
elementText.StartsWith("<fractured>{<smaller>", StringComparison.Ordinal)) &&
element.TextNoTags?.StartsWith("Allocated Crucible", StringComparison.Ordinal) != true)
{
return modsRoot.Children[i - 1];
}
}
return null;
}
private static List<Element> GetExtendedModsTextElements(Element element)
{
return element.Children.SelectMany(x => x.Children).Where(x => x.ChildCount == 1).Select(x => x[0]).Where(x => x != null).ToList();
}
public override void Render()
{
var hover = GameController.IngameState.UIHover;
if (hover is not { Address: not 0, IsValid: true, IsVisible: true })
{
return;
}
if (FindRegularModElement(hover) is { } modElement)
{
var lines = modElement.GetText(2500).Split("\n", StringSplitOptions.TrimEntries);
if (!lines.Any())
{
return;
}
var elementRect = modElement.GetClientRectCache;
var lineHeight = elementRect.Height / lines.Length;
for (int i = 0; i < lines.Length; i++)
{
var line = lines[i];
if (Settings.Crafts.Content.Where(x => !string.IsNullOrWhiteSpace(x.Input.Text)).FirstOrDefault(x => x.Input.LoadFilter().IsMatch(line)) is { } mod)
{
Graphics.DrawFrame(elementRect.TopLeft.ToVector2Num() + new Vector2(0, lineHeight * i),
elementRect.TopRight.ToVector2Num() + new Vector2(0, lineHeight * (i + 1)), mod.Color, 2);
}
}
}
}
}