Repository navigation
Expand file tree
/
Copy pathxplosion.lua
More file actions
470 lines (427 loc) · 16.7 KB
/
Copy pathxplosion.lua
File metadata and controls
470 lines (427 loc) · 16.7 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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
--[[
* MIT License
*
* Copyright (c) 2023 tirem [github.com/tirem]
* Copyright (c) 2025 TreeFidyDad (XPlosion standalone + EXP juice patches)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
]]--
addon.name = 'xplosion';
addon.author = 'TreeFidyDad, building on HXUI by Team HXUI (Tirem, Shuu, colorglut, RheaCloud)';
addon.version = '1.1.0';
addon.desc = 'XPlosion: a juiced-up, standalone FFXI EXP bar - gain pops, level-up fanfare, kill-chain combo meter (chain 2-5) with countdown, rainbow overdrive and confetti.';
addon.link = 'https://github.com/tirem/HXUI';
require('common');
local imgui = require('imgui');
local settings = require('settings');
local ffi = require('ffi');
local d3d = require('d3d8');
local C = ffi.C;
local d3d8dev = d3d.get_device();
----------------------------------------------------------------
-- Globals required by the carried-over modules
-- expbar.lua reads the global `gConfig`
-- progressbar.lua calls the global `LoadTexture` (bookend)
-- both need `deep_copy_table` via the host
----------------------------------------------------------------
function deep_copy_table(orig)
local orig_type = type(orig);
local copy;
if (orig_type == 'table') then
copy = {};
for orig_key, orig_value in next, orig, nil do
copy[deep_copy_table(orig_key)] = deep_copy_table(orig_value);
end
setmetatable(copy, deep_copy_table(getmetatable(orig)));
else
copy = orig;
end
return copy;
end
-- Minimal texture loader (progressbar.lua uses this for the bar bookends).
function LoadTexture(textureName)
local textures = T{};
local texture_ptr = ffi.new('IDirect3DTexture8*[1]');
local res = C.D3DXCreateTextureFromFileA(d3d8dev, string.format('%s/assets/%s.png', addon.path, textureName), texture_ptr);
if (res ~= C.S_OK) then
return nil;
end
textures.image = ffi.new('IDirect3DTexture8*', texture_ptr[0]);
d3d.gc_safe_release(textures.image);
return textures;
end
local expBar = require('expbar');
----------------------------------------------------------------
-- User settings (persisted) + defaults
----------------------------------------------------------------
local user_settings =
T{
showExpBar = true,
-- behaviour
expBarLimitPointsMode = true,
expBarInlineMode = false,
lockPositions = false,
-- display
showExpBarBookends = true,
expBarShowText = true,
expBarShowPercent = true,
expBarSegments = 20,
expBarColor = T{ 0.91, 0.74, 0.36 }, -- base bar color (r,g,b 0..1)
-- juice / effects
expBarJuice = true,
expBarChain = true,
expBarAnticipation = true,
expBarSoundDing = true,
expBarSoundChain = true,
expBarRainbow = true,
-- sizing
expBarScaleX = 1,
expBarScaleY = 1,
expBarTextScaleX = 1,
expBarFontOffset = 0,
};
local user_settings_container =
T{
userSettings = user_settings;
};
----------------------------------------------------------------
-- Default (unscaled) render settings for the exp bar
----------------------------------------------------------------
local default_settings =
T{
expBarSettings =
T{
barWidth = 550;
textWidth = 550;
barHeight = 12;
textOffsetY = 5;
percentOffsetX = -5;
job_font_settings =
T{
visible = true,
locked = true,
font_family = 'Consolas',
font_height = 13,
color = 0xFFFFFFFF,
bold = true,
italic = false;
color_outline = 0xFF000000,
draw_flags = 0x10,
background =
T{
visible = false,
},
right_justified = false;
};
exp_font_settings =
T{
visible = true,
locked = true,
font_family = 'Consolas',
font_height = 13,
color = 0xFFFFFFFF,
bold = true,
italic = false;
color_outline = 0xFF000000,
draw_flags = 0x10,
background =
T{
visible = false,
},
right_justified = true;
};
percent_font_settings =
T{
visible = true,
locked = true,
font_family = 'Consolas',
font_height = 8,
color = 0xFFFFFF00,
bold = false,
italic = true;
color_outline = 0xFF000000,
draw_flags = 0x10,
background =
T{
visible = false,
},
right_justified = true;
};
};
};
gAdjustedSettings = deep_copy_table(default_settings);
local defaultUserSettings = deep_copy_table(user_settings);
local config = settings.load(user_settings_container);
gConfig = config.userSettings;
showConfig = { false };
----------------------------------------------------------------
-- Settings plumbing (exp-bar only)
----------------------------------------------------------------
local function UpdateUserSettings()
local ds = default_settings;
local us = gConfig;
gAdjustedSettings.expBarSettings.textWidth = ds.expBarSettings.textWidth * us.expBarTextScaleX;
gAdjustedSettings.expBarSettings.barWidth = ds.expBarSettings.barWidth * us.expBarScaleX;
gAdjustedSettings.expBarSettings.barHeight = ds.expBarSettings.barHeight * us.expBarScaleY;
gAdjustedSettings.expBarSettings.job_font_settings.font_height = math.max(ds.expBarSettings.job_font_settings.font_height + us.expBarFontOffset, 1);
gAdjustedSettings.expBarSettings.exp_font_settings.font_height = math.max(ds.expBarSettings.exp_font_settings.font_height + us.expBarFontOffset, 1);
gAdjustedSettings.expBarSettings.percent_font_settings.font_height = math.max(ds.expBarSettings.percent_font_settings.font_height + us.expBarFontOffset, 1);
end
local function CheckVisibility()
if (gConfig.showExpBar == false) then
expBar.SetHidden(true);
end
end
local function UpdateFonts()
expBar.UpdateFonts(gAdjustedSettings.expBarSettings);
end
function UpdateSettings()
settings.save();
UpdateUserSettings();
CheckVisibility();
UpdateFonts();
end
function ResetSettings()
gConfig = deep_copy_table(defaultUserSettings);
UpdateSettings();
end
settings.register('settings', 'settings_update', function (s)
if (s ~= nil) then
config = s;
gConfig = config.userSettings;
UpdateSettings();
end
end);
----------------------------------------------------------------
-- Config menu
----------------------------------------------------------------
local function DrawConfigMenu()
imgui.PushStyleColor(ImGuiCol_WindowBg, {0,0.06,.16,.9});
imgui.PushStyleColor(ImGuiCol_TitleBg, {0,0.06,.16, .7});
imgui.PushStyleColor(ImGuiCol_TitleBgActive, {0,0.06,.16, .9});
imgui.PushStyleColor(ImGuiCol_TitleBgCollapsed, {0,0.06,.16, .5});
imgui.PushStyleColor(ImGuiCol_Header, {0,0.06,.16,.7});
imgui.PushStyleColor(ImGuiCol_HeaderHovered, {0,0.06,.16, .9});
imgui.PushStyleColor(ImGuiCol_HeaderActive, {0,0.06,.16, 1});
imgui.PushStyleColor(ImGuiCol_FrameBg, {0,0.06,.16, 1});
imgui.SetNextWindowSize({ 430, 560 }, ImGuiCond_FirstUseEver);
if (showConfig[1] and imgui.Begin('XPlosion Config', showConfig, ImGuiWindowFlags_NoSavedSettings)) then
if (imgui.Button('Preview FX', { 130, 22 })) then
expBar.PreviewFX();
end
imgui.SameLine();
if (imgui.Button('Restore Defaults', { 150, 22 })) then
ResetSettings();
end
imgui.Separator();
imgui.BeginChild('ExpBarSettings', { 0, 0 }, true);
if (imgui.Checkbox('Enabled', { gConfig.showExpBar })) then
gConfig.showExpBar = not gConfig.showExpBar;
UpdateSettings();
end
if (imgui.Checkbox('Lock Position', { gConfig.lockPositions })) then
gConfig.lockPositions = not gConfig.lockPositions;
UpdateSettings();
end
imgui.ShowHelp('When unlocked, drag the bar to move it. Position is remembered.');
if (imgui.Checkbox('Limit Points Mode', { gConfig.expBarLimitPointsMode })) then
gConfig.expBarLimitPointsMode = not gConfig.expBarLimitPointsMode;
UpdateSettings();
end
imgui.ShowHelp('Shows Limit Points if your character is set to earn Limit Points in the game.');
if (imgui.Checkbox('Inline Mode', { gConfig.expBarInlineMode })) then
gConfig.expBarInlineMode = not gConfig.expBarInlineMode;
UpdateSettings();
end
if (imgui.Checkbox('Show Bookends', { gConfig.showExpBarBookends })) then
gConfig.showExpBarBookends = not gConfig.showExpBarBookends;
UpdateSettings();
end
if (imgui.Checkbox('Show Text', { gConfig.expBarShowText })) then
gConfig.expBarShowText = not gConfig.expBarShowText;
UpdateSettings();
end
if (imgui.Checkbox('Show Percent', { gConfig.expBarShowPercent })) then
gConfig.expBarShowPercent = not gConfig.expBarShowPercent;
UpdateSettings();
end
imgui.Separator();
-- EXP bar color: single base color chosen from a hue wheel; the bar
-- renders as a gradient derived from it (see expbar.lua).
imgui.Text('Bar Color');
imgui.ShowHelp('Pick the EXP bar color. The bar shades it into a gradient automatically.');
if (type(gConfig.expBarColor) ~= 'table') then
gConfig.expBarColor = { 0.91, 0.74, 0.36 };
end
local barColor = { gConfig.expBarColor[1] or 0.91, gConfig.expBarColor[2] or 0.74, gConfig.expBarColor[3] or 0.36 };
local colorPickerFlags = ImGuiColorEditFlags_NoAlpha + ImGuiColorEditFlags_NoInputs + ImGuiColorEditFlags_NoSidePreview + ImGuiColorEditFlags_PickerHueWheel;
if (imgui.ColorPicker3('##expBarColor', barColor, colorPickerFlags)) then
gConfig.expBarColor = { barColor[1], barColor[2], barColor[3] };
UpdateSettings();
end
if (imgui.Button('Reset Bar Color', { 130, 22 })) then
gConfig.expBarColor = { 0.91, 0.74, 0.36 };
UpdateSettings();
end
imgui.Separator();
local juiceCur = (gConfig.expBarJuice ~= false);
if (imgui.Checkbox('Visual FX (gain pops, ding burst)', { juiceCur })) then
gConfig.expBarJuice = not juiceCur;
UpdateSettings();
end
local chainCur = (gConfig.expBarChain ~= false);
if (imgui.Checkbox('Chain combo meter', { chainCur })) then
gConfig.expBarChain = not chainCur;
UpdateSettings();
end
local anticCur = (gConfig.expBarAnticipation ~= false);
if (imgui.Checkbox('"Next kill dings" shimmer', { anticCur })) then
gConfig.expBarAnticipation = not anticCur;
UpdateSettings();
end
local sDingCur = (gConfig.expBarSoundDing ~= false);
if (imgui.Checkbox('Sound: level-up fanfare', { sDingCur })) then
gConfig.expBarSoundDing = not sDingCur;
UpdateSettings();
end
local sChainCur = (gConfig.expBarSoundChain ~= false);
if (imgui.Checkbox('Sound: chain tink', { sChainCur })) then
gConfig.expBarSoundChain = not sChainCur;
UpdateSettings();
end
local rbCur = (gConfig.expBarRainbow ~= false);
if (imgui.Checkbox('Rainbow overdrive & confetti', { rbCur })) then
gConfig.expBarRainbow = not rbCur;
UpdateSettings();
end
imgui.Separator();
local segOpts = { 'Off', '5 Segments', '20 Segments' };
local segIdx = { 1 };
if gConfig.expBarSegments == 5 then segIdx = { 2 };
elseif gConfig.expBarSegments == 20 then segIdx = { 3 } end
if imgui.Combo('Bar Segments', segIdx, segOpts, #segOpts) then
local vals = { 0, 5, 20 };
gConfig.expBarSegments = vals[segIdx[1]];
UpdateSettings();
end
local scaleX = { gConfig.expBarScaleX };
if (imgui.SliderFloat('Scale X', scaleX, 0.1, 3.0, '%.2f')) then
gConfig.expBarScaleX = scaleX[1];
UpdateSettings();
end
local scaleY = { gConfig.expBarScaleY };
if (imgui.SliderFloat('Scale Y', scaleY, 0.1, 3.0, '%.2f')) then
gConfig.expBarScaleY = scaleY[1];
UpdateSettings();
end
local textScaleX = { gConfig.expBarTextScaleX };
if (imgui.SliderFloat('Text Scale X', textScaleX, 0.1, 3.0, '%.2f')) then
gConfig.expBarTextScaleX = textScaleX[1];
UpdateSettings();
end
local fontOffset = { gConfig.expBarFontOffset };
if (imgui.SliderInt('Font Height', fontOffset, -5, 10)) then
gConfig.expBarFontOffset = fontOffset[1];
UpdateSettings();
end
imgui.EndChild();
end
imgui.PopStyleColor(8);
imgui.End();
end
----------------------------------------------------------------
-- Events
----------------------------------------------------------------
ashita.events.register('load', 'load_cb', function ()
UpdateUserSettings();
expBar.Initialize(gAdjustedSettings.expBarSettings);
end);
ashita.events.register('unload', 'unload_cb', function ()
expBar.SetHidden(true);
end);
ashita.events.register('d3d_present', 'present_cb', function ()
if (gConfig.showExpBar) then
expBar.DrawWindow(gAdjustedSettings.expBarSettings);
else
expBar.SetHidden(true);
end
DrawConfigMenu();
end);
ashita.events.register('packet_in', 'packet_in_cb', function (e)
expBar.HandlePacket(e);
end);
ashita.events.register('command', 'command_cb', function (e)
local args = e.command:lower():args();
if (#args == 0) then
return;
end
-- /expfx as a top-level shortcut to preview the whole show
if (args[1] == '/expfx') then
e.blocked = true;
expBar.PreviewFX();
return;
end
if (not table.contains({'/xplosion', '/xpl'}, args[1])) then
return;
end
e.blocked = true;
-- Bare command toggles the config menu
if (#args == 1) then
showConfig[1] = not showConfig[1];
return;
end
if (args[2]:any('expfx', 'fxtest', 'preview')) then
expBar.PreviewFX();
return;
end
if (args[2]:any('reset', 'defaults')) then
ResetSettings();
return;
end
if (args[2]:any('menu', 'config')) then
showConfig[1] = not showConfig[1];
return;
end
-- /xpl share [p|l|s] -- broadcast a one-line progress summary (level,
-- EXP, TNL, rate, ETA) to party / linkshell / say. With no channel it
-- just echoes locally so you can preview it without spamming anyone.
if (args[2]:any('share', 'send', 'tnl')) then
local msg = expBar.GetShareString();
if (not msg) then
print('[XPlosion] Nothing to share right now (zoning or no job data).');
return;
end
local ch = args[3];
local prefix = nil;
if (ch == 'p' or ch == 'party') then prefix = '/p ';
elseif (ch == 'l' or ch == 'ls' or ch == 'l1' or ch == 'linkshell') then prefix = '/l ';
elseif (ch == 'l2' or ch == 'ls2') then prefix = '/l2 ';
elseif (ch == 's' or ch == 'say') then prefix = '/s ';
end
if (prefix) then
AshitaCore:GetChatManager():QueueCommand(1, prefix .. msg);
else
print('[XPlosion] ' .. msg);
if (ch ~= nil) then
print('[XPlosion] Unknown channel "' .. tostring(ch) .. '". Usage: /xpl share [p | l | s] (p=party, l=linkshell, s=say)');
end
end
return;
end
end);