This repository has been archived by the owner on Dec 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathStatusNodeGroup.cs
170 lines (140 loc) · 5.19 KB
/
StatusNodeGroup.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
using Dalamud.Plugin;
using FFXIVClientStructs.FFXIV.Client.System.Memory;
using FFXIVClientStructs.FFXIV.Component.GUI;
using System;
using Dalamud.Logging;
namespace NamePlateDebuffs.StatusNode
{
public unsafe class StatusNodeGroup
{
private NamePlateDebuffsPlugin _plugin;
public AtkResNode* RootNode { get; private set; }
public StatusNode[] StatusNodes { get; private set; }
public static ushort NodePerGroupCount = 4;
public StatusNodeGroup(NamePlateDebuffsPlugin p)
{
_plugin = p;
StatusNodes = new StatusNode[NodePerGroupCount];
for (int i = 0; i < NodePerGroupCount; i++)
StatusNodes[i] = new StatusNode(_plugin);
}
public bool Built()
{
if (RootNode == null) return false;
foreach (var node in StatusNodes)
if (!node.Built()) return false;
return true;
}
public bool BuildNodes(uint baseNodeId)
{
if (Built()) return true;
var rootNode = CreateRootNode();
if (rootNode == null) return false;
RootNode = rootNode;
RootNode->NodeID = baseNodeId;
for (uint i = 0; i < NodePerGroupCount; i++)
{
if (!StatusNodes[i].BuildNodes(baseNodeId + 1 + i * 3))
{
DestroyNodes();
return false;
}
}
RootNode->ChildCount = (ushort) (NodePerGroupCount * 3);
RootNode->ChildNode = StatusNodes[0].RootNode;
StatusNodes[0].RootNode->ParentNode = RootNode;
var lastNode = StatusNodes[0].RootNode;
for (uint i = 1; i < NodePerGroupCount; i++)
{
var currNode = StatusNodes[i].RootNode;
lastNode->PrevSiblingNode = currNode;
currNode->NextSiblingNode = lastNode;
currNode->ParentNode = RootNode;
lastNode = currNode;
}
LoadConfig();
SetupVisibility();
return true;
}
public void DestroyNodes()
{
foreach(var node in StatusNodes)
{
node.DestroyNodes();
}
if (RootNode != null)
{
RootNode->Destroy(true);
RootNode = null;
}
}
public void ForEachNode(Action<StatusNode> func)
{
foreach (var node in StatusNodes)
if (node != null)
func(node);
}
public void LoadConfig()
{
RootNode->SetPositionShort((short)_plugin.Config.GroupX, (short)_plugin.Config.GroupY);
RootNode->SetScale(_plugin.Config.Scale, _plugin.Config.Scale);
RootNode->SetWidth((ushort) (StatusNodes[0].RootNode->Width * NodePerGroupCount + _plugin.Config.NodeSpacing * (NodePerGroupCount - 1)));
RootNode->SetHeight(StatusNodes[0].RootNode->Height);
for (int i = 0; i < NodePerGroupCount; i++)
{
if (StatusNodes[i] != null)
{
StatusNodes[i].RootNode->SetPositionShort((short)((_plugin.Config.FillFromRight ? 3 - i : i) * (StatusNodes[0].RootNode->Width + _plugin.Config.NodeSpacing)), 0);
}
}
}
public void SetVisibility(bool enable, bool setChildren)
{
RootNode->ToggleVisibility(enable);
if (setChildren)
{
ForEachNode(node => node.SetVisibility(enable));
}
}
public void SetStatus(int statusIndex, int id, int timer)
{
if (statusIndex > NodePerGroupCount)
return;
StatusNodes[statusIndex].SetStatus(id, timer);
}
public void HideUnusedStatus(int statusCount)
{
if (statusCount > NodePerGroupCount)
statusCount = NodePerGroupCount;
for (int i = NodePerGroupCount - 1; i > statusCount - 1; i--)
{
StatusNodes[i].SetVisibility(false);
}
}
public void SetupVisibility()
{
foreach(var node in StatusNodes)
{
node.IconNode->AtkResNode.ToggleVisibility(true);
node.DurationNode->AtkResNode.ToggleVisibility(true);
node.RootNode->ToggleVisibility(false);
}
RootNode->ToggleVisibility(false);
}
private AtkResNode* CreateRootNode()
{
var newResNode = (AtkResNode*)IMemorySpace.GetUISpace()->Malloc((ulong)sizeof(AtkResNode), 8);
if (newResNode == null)
{
PluginLog.Debug("Failed to allocate memory for res node");
return null;
}
IMemorySpace.Memset(newResNode, 0, (ulong)sizeof(AtkResNode));
newResNode->Ctor();
newResNode->Type = NodeType.Res;
newResNode->Flags = (short)(NodeFlags.AnchorLeft | NodeFlags.AnchorTop);
newResNode->DrawFlags = 0;
return newResNode;
}
}
}