forked from ThornyFFXI/tCrossBar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.lua
More file actions
288 lines (251 loc) · 9.43 KB
/
interface.lua
File metadata and controls
288 lines (251 loc) · 9.43 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
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
ffi.cdef[[
typedef struct FontInitializer_t {
int32_t OffsetX;
int32_t OffsetY;
int32_t BoxWidth;
int32_t BoxHeight;
int32_t OutlineWidth;
int32_t FontHeight;
char FontFamily[256];
uint32_t FontFlags;
uint32_t FontAlignment;
uint32_t FontColor;
uint32_t OutlineColor;
} FontInitializer_t;
typedef struct ImageInitializer_t {
int32_t OffsetX;
int32_t OffsetY;
int32_t Width;
int32_t Height;
} ImageInitializer_t;
typedef struct SquareInitializer_t {
int32_t OffsetX;
int32_t OffsetY;
} SquareInitializer_t;
typedef struct EventInitializer_t {
char UniqueIdentifier[256];
FontInitializer_t Cost;
FontInitializer_t Macro;
FontInitializer_t Name;
FontInitializer_t Recast;
ImageInitializer_t Frame;
ImageInitializer_t Icon;
ImageInitializer_t Overlay;
float IconFadeAlpha;
char FramePath[256];
int32_t PanelHeight;
int32_t PanelWidth;
int32_t SquareHeight;
int32_t SquareWidth;
int32_t SquareCount;
SquareInitializer_t Squares[100];
} EventInitializer_t;
typedef struct AbilitySquareState_t {
uint32_t Fade;
char Cost[32];
char Hotkey[32];
char Name[32];
char Recast[32];
char IconImage[256];
char OverlayImage1[256];
char OverlayImage2[256];
char OverlayImage3[256];
} AbilitySquareState_t;
typedef struct AbilitySquarePanelState_t {
uint32_t Render;
int32_t PositionX;
int32_t PositionY;
AbilitySquareState_t Squares[100];
} AbilitySquarePanelState_t;
]];
local function lua_FontInitializerToStruct(font)
local struct = ffi.new('FontInitializer_t');
struct.OffsetX = font.OffsetX;
struct.OffsetY = font.OffsetY;
struct.BoxWidth = font.BoxWidth;
struct.BoxHeight = font.BoxHeight;
struct.OutlineWidth = font.OutlineWidth;
struct.FontHeight = font.FontHeight;
struct.FontFamily = font.FontFamily;
struct.FontFlags = font.FontFlags;
struct.FontAlignment = font.FontAlignment;
struct.FontColor = font.FontColor;
struct.OutlineColor = font.OutlineColor;
return struct;
end
local function lua_ImageInitializerToStruct(image)
local struct = ffi.new('ImageInitializer_t');
struct.OffsetX = image.OffsetX;
struct.OffsetY = image.OffsetY;
struct.Width = image.Width;
struct.Height = image.Height;
return struct;
end
local function lua_SquareInitializerToStruct(square)
local struct = ffi.new('SquareInitializer_t');
struct.OffsetX = square.OffsetX;
struct.OffsetY = square.OffsetY;
return struct;
end
local function lua_EventInitializerToStruct(layout, identifier)
local struct = ffi.new('EventInitializer_t');
if (identifier ~= nil) then
struct.UniqueIdentifier = identifier;
else
struct.UniqueIdentifier = layout.Path;
end
struct.Cost = lua_FontInitializerToStruct(layout.FontObjects.Cost);
struct.Macro = lua_FontInitializerToStruct(layout.FontObjects.Macro);
struct.Name = lua_FontInitializerToStruct(layout.FontObjects.Name);
struct.Recast = lua_FontInitializerToStruct(layout.FontObjects.Recast);
struct.Frame = lua_ImageInitializerToStruct(layout.ImageObjects.Frame);
struct.Icon = lua_ImageInitializerToStruct(layout.ImageObjects.Icon);
struct.Overlay = lua_ImageInitializerToStruct(layout.ImageObjects.Overlay);
struct.IconFadeAlpha = layout.IconFadeAlpha;
struct.FramePath = layout.FramePath;
struct.PanelHeight = layout.PanelHeight;
struct.PanelWidth = layout.PanelWidth;
struct.SquareHeight = layout.SquareHeight;
struct.SquareWidth = layout.SquareWidth;
struct.SquareCount = 0;
for _,square in ipairs(layout.Squares) do
struct.Squares[struct.SquareCount] = lua_SquareInitializerToStruct(square);
struct.SquareCount = struct.SquareCount + 1;
end
return struct;
end
local function LoadLayout(interface, layoutName)
interface.Layout = nil;
--Attempt to load layout file.
local layoutPaths = T{
string.format('%sconfig/addons/%s/resources/layouts/%s.lua', AshitaCore:GetInstallPath(), addon.name, layoutName),
string.format('%saddons/%s/resources/layouts/%s.lua', AshitaCore:GetInstallPath(), addon.name, layoutName),
};
for _,path in ipairs(layoutPaths) do
interface.Layout = LoadFile_s(path);
if (interface.Layout ~= nil) then
interface.Layout.Name = layoutName;
interface.Layout.Path = path;
break;
end
end
if (interface.Layout == nil) then
return false;
end
interface.Layout.CrossPath = GetImagePath(interface.Layout.CrossPath);
if (interface.Layout.CrossPath == nil) then
interface.Layout.CrossPath = '';
end
interface.Layout.TriggerPath = GetImagePath(interface.Layout.TriggerPath);
if (interface.Layout.TriggerPath == nil) then
interface.Layout.TriggerPath = '';
end
local newPaths = T{};
for _,value in ipairs(interface.Layout.SkillchainAnimationPaths) do
local path = GetImagePath(value);
if (path ~= nil) then
newPaths:append(path);
end
end
interface.Layout.SkillchainAnimationPaths = newPaths;
for _,layoutType in ipairs(T{'SingleDisplay', 'DoubleDisplay'}) do
local layout = interface.Layout[layoutType];
layout.IconFadeAlpha = interface.Layout.IconFadeAlpha;
for _,primitiveInfo in ipairs(layout.Primitives) do
if (primitiveInfo.File ~= nil) then
primitiveInfo.texture = GetImagePath(primitiveInfo.File);
primitiveInfo.File = nil;
end
end
layout.FramePath = GetImagePath(layout.FramePath);
if (layout.FramePath == nil) then
layout.FramePath = '';
end
--Fill in position from new layout if necessary..
if (gSettings.Position[layoutName] == nil) then
gSettings.Position[layoutName] = {};
end
if (gSettings.Position[layoutName][layoutType] == nil) then
gSettings.Position[layoutName][layoutType] = { layout.DefaultX, layout.DefaultY };
settings.save();
end
end
return true;
end
local interface = {};
interface.SquareManager = require('square_manager');
function interface:Clear()
self.StructPointer = nil;
end
function interface:Destroy()
self.SquareManager:Destroy();
if (self.StructPointer ~= nil) then
AshitaCore:GetPluginManager():RaiseEvent('tRenderer_Destroy', (self.Layout.Path .. '\x00'):totable());
self.StructPointer = nil;
end
end
function interface:GetLayout()
return self.Layout;
end
function interface:GetSquareManager()
return self.SquareManager;
end
function interface:HandleEvent(e)
if (e.name == self.EventIdentifier[1]) and (self.StructPointer[1] == nil) then
self.StructPointer[1] = struct.unpack('L', e.data, 1);
end
if (e.name == self.EventIdentifier[2]) and (self.StructPointer[1] ~= nil) and (self.StructPointer[2] == nil) then
self.StructPointer[2] = struct.unpack('L', e.data, 1);
self.SquareManager:Initialize(self.Layout, self.StructPointer[1], self.StructPointer[2]);
gBindings:Update();
gSettings.Layout = self.Layout.Name;
settings.save();
end
end
function interface:Initialize(layoutName)
if (self.Initializer ~= nil) and (self.StructPointer == nil) then
Error('Could not load layout. Please wait for last layout to finish loading then manually apply layout via $H/tb$R.');
return;
end
self.Initializer = nil;
if (self.StructPointer ~= nil) then
self.SquareManager:Destroy();
AshitaCore:GetPluginManager():RaiseEvent('tRenderer_Destroy', (self.Layout.Path .. '\x00'):totable());
self.StructPointer = nil;
end
if (LoadLayout(self, layoutName)) then
self.Initializer = T{
lua_EventInitializerToStruct(self.Layout.SingleDisplay, string.format('%s_Single', self.Layout.Path)),
lua_EventInitializerToStruct(self.Layout.DoubleDisplay, string.format('%s_Double', self.Layout.Path))
};
self.EventIdentifier = {
string.format('tRenderer_Accessor_%s_Single', self.Layout.Path),
string.format('tRenderer_Accessor_%s_Double', self.Layout.Path)
};
ashita.events.register('plugin_event', 'interface_event_cb', (function (self, e)
self:HandleEvent(e);
end):bind1(self));
else
Error(string.format('Failed to load layout $H%s$R. Please select a layout via $H/tb$R.', layoutName));
end
end
function interface:Tick()
if (self.Initializer == nil) then
return;
end
if (self.StructPointer == nil) then
self.StructPointer = T{};
end
if (self.StructPointer[1] == nil) then
local eventStruct = ffi.string(self.Initializer[1], ffi.sizeof(self.Initializer[1])):totable();
AshitaCore:GetPluginManager():RaiseEvent('tRenderer_Initialize', eventStruct);
return;
end
if (self.StructPointer[2] == nil) then
local eventStruct = ffi.string(self.Initializer[2], ffi.sizeof(self.Initializer[2])):totable();
AshitaCore:GetPluginManager():RaiseEvent('tRenderer_Initialize', eventStruct);
return;
end
self.SquareManager:Tick();
end
return interface;