/
Error.cs
134 lines (114 loc) · 3.88 KB
/
Error.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
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExileCore.PoEMemory;
using ImGuiNET;
namespace AutoSextant;
public class Error
{
public static bool IsDisplaying
{
get
{
return showErrorModal;
}
}
private static bool showErrorModal = false;
private static List<(string, string)> errorList = new List<(string, string)>();
public static void Add(string errorType, string errorMessage)
{
errorList.Add((errorType, errorMessage));
Log.Error($"{errorType}: {errorMessage}");
}
public static void AddAndShow(string errorType, string errorMessage)
{
if (errorList.FindIndex(x => x.Item1 == errorType && x.Item2 == errorMessage) >= 0)
{
Show();
return;
}
else
{
Add(errorType, errorMessage);
Show();
}
}
public static void Show()
{
showErrorModal = true;
if (AutoSextant.Instance.IsAnyRoutineRunning)
{
AutoSextant.Instance.StopAllRoutines();
}
}
public static void ShowIfNeeded()
{
if (errorList.Count > 0)
{
Show();
}
}
public static void Clear()
{
showErrorModal = false;
errorList.Clear();
}
public static void Render()
{
if (showErrorModal)
{
ImGui.OpenPopup("AutoSextant Alert");
}
bool modalOpen = true;
System.Numerics.Vector2 center = ImGui.GetMainViewport().GetCenter();
ImGui.SetNextWindowPos(center, ImGuiCond.Always, new System.Numerics.Vector2(0.5f, 0.5f));
ImGui.PushStyleColor(ImGuiCol.ModalWindowDimBg, new System.Numerics.Vector4(0.2f, 0.2f, 0.2f, 0.7f));
if (ImGui.BeginPopupModal("AutoSextant Alert", ref modalOpen, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.AlwaysAutoResize))
{
System.Numerics.Vector2 windowPos = ImGui.GetWindowPos();
System.Numerics.Vector2 windowSize = ImGui.GetWindowSize();
ImGui.GetWindowDrawList().AddRectFilled(windowPos, new System.Numerics.Vector2(windowPos.X + windowSize.X, windowPos.Y + 30), ImGui.GetColorU32(ImGuiCol.Header));
ImGui.TextColored(new System.Numerics.Vector4(1, 1, 1, 1), "AutoSextant Alert");
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + 8);
ImGui.Separator();
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + 8);
foreach (var e in errorList)
{
ImGui.TextColored(new System.Numerics.Vector4(1, 0.3f, 0, 1), e.Item1);
ImGui.Text(e.Item2);
ImGui.Spacing();
ImGui.Separator();
ImGui.Spacing();
}
float buttonWidth = 120.0f;
ImGui.SetCursorPosX((windowSize.X - buttonWidth) * 0.5f);
if (ImGui.Button("OK", new System.Numerics.Vector2(buttonWidth, 0)))
{
Clear();
ImGui.CloseCurrentPopup();
}
ImGui.EndPopup();
}
ImGui.PopStyleColor();
}
public static string VisualizeElementTree(Element node, int depth = 0)
{
StringBuilder sb = new StringBuilder();
string displayText = node.Text != null ? node.Text : $"({node.GetType().Name})";
// Create prefix based on depth
string prefix = new string(' ', depth * 2);
if (node.IndexInParent >= 0)
{
displayText = $"[{node.IndexInParent}] {displayText}";
}
sb.AppendLine(prefix + "|-" + displayText);
for (int i = 0; i < node.Children.Count; i++)
{
sb.Append(VisualizeElementTree(node.Children[i], depth + 1));
}
return sb.ToString();
}
}