-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPanelRenderer.cs
More file actions
102 lines (89 loc) · 4.03 KB
/
PanelRenderer.cs
File metadata and controls
102 lines (89 loc) · 4.03 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
94
95
96
97
98
99
100
101
102
using ExileCore.Shared.Enums;
using ExileCore.Shared.Helpers;
using SharpDX;
using static ExileCore.Shared.Enums.FontAlign;
using Vector2 = System.Numerics.Vector2;
namespace UniqueFinder;
public class PanelRenderer(UniqueFinder plugin)
{
private const int ItemMargin = 4;
private const int TextPaddingX = 5;
private const int TextPaddingY = 2;
private const int BorderWidth = 1;
private EPanelAlign _align = EPanelAlign.Left;
private float _margin;
private Vector2 _pos = Vector2.Zero;
private FontAlign _fontAlign = Right;
public void Render(List<GroundItemInstance> summary)
{
if (plugin.GameController?.IngameState?.IngameUi is null) return;
if (!plugin.Settings.Panel.Enabled) return;
if (plugin.GameController.IngameState.IngameUi.OpenRightPanel?.IsVisible == true) return;
Reset();
foreach (var instance in summary) RenderNextElement(instance);
}
private void Reset()
{
_align = Enum.Parse<EPanelAlign>(plugin.Settings.Panel.PanelAlign.Value);
_margin = _align == EPanelAlign.Bottom ? -plugin.Settings.Panel.Margin : plugin.Settings.Panel.Margin;
var rect = plugin.GameController.IngameState.IngameUi.Map.GetClientRect();
switch (_align)
{
case EPanelAlign.Left:
_pos = new Vector2(_margin, 200 /* todo! settings? */);
_fontAlign = Left;
break;
case EPanelAlign.Top:
_pos = new Vector2(rect.Width / 2, _margin);
_fontAlign = Center;
break;
case EPanelAlign.Right:
_pos = plugin.GameController.UnderPanel.StartDrawPoint.ToVector2Num();
_pos.X -= _margin;
_fontAlign = Right;
// In case of missing UI offsets...
if (_pos.X <= 0) _pos = new Vector2(rect.Width - _margin, 500 /* todo settings? default? */);
break;
case EPanelAlign.Bottom:
_pos = new Vector2(rect.Width / 2, rect.Height + _margin);
_fontAlign = Center;
break;
}
}
private void RenderNextElement(GroundItemInstance item)
{
var textSize = plugin.Graphics.MeasureText(item.ItemName) * plugin.Settings.Panel.TextSize;
var fullWidth = (textSize.X + TextPaddingX * 2 + BorderWidth * 2) * plugin.Settings.Panel.TextSize;
var textHeight = textSize.Y + TextPaddingY * 2 + BorderWidth * 2;
var stepShift = _align == EPanelAlign.Bottom ? -(textHeight + ItemMargin) : textHeight + ItemMargin;
RectangleF boxRect;
Vector2 textPos;
switch (_align)
{
default:
case EPanelAlign.Left:
boxRect = new RectangleF(_pos.X, _pos.Y, fullWidth, textHeight);
textPos = new Vector2(_pos.X + TextPaddingX, _pos.Y + BorderWidth * 2);
break;
case EPanelAlign.Top:
boxRect = new RectangleF(_pos.X - fullWidth / 2, _pos.Y, fullWidth, textHeight);
textPos = new Vector2(_pos.X + BorderWidth, _pos.Y + BorderWidth * 2);
break;
case EPanelAlign.Right:
boxRect = new RectangleF(_pos.X - fullWidth, _pos.Y, fullWidth, textHeight);
textPos = new Vector2(_pos.X - TextPaddingX, _pos.Y + BorderWidth * 2);
break;
case EPanelAlign.Bottom:
boxRect = new RectangleF(_pos.X - fullWidth / 2, _pos.Y + stepShift + ItemMargin, fullWidth, textHeight);
textPos = new Vector2(_pos.X + BorderWidth, _pos.Y + stepShift + ItemMargin + BorderWidth * 2);
break;
}
plugin.Graphics.DrawBox(boxRect, item.BackgroundColor);
plugin.Graphics.DrawFrame(boxRect, item.BorderColor, BorderWidth);
using (plugin.Graphics.SetTextScale(plugin.Settings.Panel.TextSize))
{
plugin.Graphics.DrawText(item.ItemName, textPos, item.TextColor, _fontAlign);
}
_pos.Y += stepShift;
}
}