forked from ThornyFFXI/tCrossBar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbindinggui.lua
More file actions
1026 lines (928 loc) · 35.4 KB
/
bindinggui.lua
File metadata and controls
1026 lines (928 loc) · 35.4 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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local d3d8 = require('d3d8');
local d3d8_device = d3d8.get_device();
local encoding = require('gdifonts.encoding');
local ffi = require('ffi');
local imgui = require('imgui');
local inventory = require('state.inventory');
local player = require('state.player');
local header = { 1.0, 0.75, 0.55, 1.0 };
local activeHeader = { 0.5, 1.0, 0.5, 1.0 };
local state = { IsOpen={ false } };
local wsmap = require('resources.wsmap');
local Setup = {};
local Update = {};
local macroStateText = {
[1] = 'Left Trigger',
[2] = 'Right Trigger',
[3] = 'Both Triggers (Left First)',
[4] = 'Both Triggers (Right First)',
[5] = 'Left Trigger (Double Tap)',
[6] = 'Right Trigger (Double Tap)'
};
local buttonText = {
'Left Grouping, Top Square',
'Left Grouping, Right Square',
'Left Grouping, Bottom Square',
'Left Grouping, Left Square',
'Right Grouping, Top Square',
'Right Grouping, Right Square',
'Right Grouping, Bottom Square',
'Right Grouping, Left Square'
};
local macroComboBinds = {
[1] = 'LT',
[2] = 'RT',
[3] = 'LTRT',
[4] = 'RTLT',
[5] = 'LT2',
[6] = 'RT2'
};
local function GetMacroStateText(state)
if (state == 3) and (gSettings.EnableDoubleTap == false) then
return 'Both Triggers';
end
return macroStateText[state];
end
local function CheckBox(display, field)
local displayName = display;
local fieldName = display;
if (field ~= nil) then
fieldName = field;
end
if (imgui.Checkbox(string.format('%s##Binding_%s', displayName, displayName), { state.Components[fieldName] })) then
state.Components[fieldName] = not state.Components[fieldName];
end
end
local function ComboBox(displayName, varName, color)
if (state.Combos[varName] == nil) then
state.Combos[varName] = T{};
end
if (state.Indices[varName] == nil) then
state.Indices[varName] = 1;
end
if (color == nil) then color = header; end
imgui.TextColored(color, displayName);
local text = state.Combos[varName][state.Indices[varName]];
if (text == nil) then text = 'N/A'; end
if (imgui.BeginCombo(string.format('##%s', displayName), text, ImGuiComboFlags_None)) then
for index,entry in ipairs(state.Combos[varName]) do
local isSelected = (index == state.Indices[varName]);
if (imgui.Selectable(entry, isSelected)) then
if (not isSelected) then
state.Indices[varName] = index;
local updateFunction = Update[varName];
if updateFunction then
updateFunction(state.Combos[varName][index]);
end
end
end
end
imgui.EndCombo();
end
end
local function AdvanceCombo(varName)
local index = state.Indices[varName] + 1;
if (index > #state.Combos[varName]) then
index = 1;
end
state.Indices[varName] = index;
local updateFunction = Update[varName];
if updateFunction then
updateFunction(state.Combos[varName][index]);
end
end
local function DecrementCombo(varName)
local index = state.Indices[varName] - 1;
if (index == 0) then
index = #state.Combos[varName];
end
state.Indices[varName] = index;
local updateFunction = Update[varName];
if updateFunction then
updateFunction(state.Combos[varName][index]);
end
end
local function UpdateMacroImage()
state.Texture = nil;
if (state.MacroImage == nil) then
return;
end
local tx = gTextureCache:GetTexture(state.MacroImage[1]);
if tx then
state.Texture = tx.Texture;
end
end
local blockedAbilities = T{
567, --Pet Commands
603, --Blood Pact: Rage
609, --Phantom Roll
636, --Quick Draw
684, --Blood Pact: Ward
694, --Sambas
695, --Waltzes
710, --Jigs
711, --Steps
712, --Flourishes I
725, --Flourishes II
735, --Stratagems
763, --Ready
775, --Flourishes III
869, --Rune Enchantment
891, --Ward
892, --Effusion
};
Setup.Ability = function(skipUpdate)
state.ActionResources = T{};
local resMgr = AshitaCore:GetResourceManager();
for i = 0x200,0x600 do
if (not blockedAbilities:contains(i)) then
local res = resMgr:GetAbilityById(i);
if (res) and (player:KnowsAbility(res.Id)) then
state.ActionResources:append(res);
end
end
end
table.sort(state.ActionResources, function(a,b)
return a.Name[1] < b.Name[1];
end);
state.Combos.Action = T{};
for _,res in ipairs(state.ActionResources) do
state.Combos.Action:append(encoding:ShiftJIS_To_UTF8(res.Name[1]));
end
state.Indices.Action = 1;
if not skipUpdate then
Update.Action(state.Combos.Action[1]);
end
end
Setup.Command = function(skipUpdate)
state.Combos.Action = T{};
state.Indices.Action = 0;
if not skipUpdate then
Update.Command();
end
end
Setup.Empty = function()
state.Combos.Action = T{};
state.Indices.Action = 0;
Update.Empty();
end
Setup.Item = function(skipUpdate)
state.ActionResources = T{};
local resMgr = AshitaCore:GetResourceManager();
local bags = T{0, 3};
for _,bag in ipairs(bags) do
for i = 1,80 do
local item = inventory:GetItemTable(bag, i);
if (item ~= nil) then
local res = resMgr:GetItemById(item.Id);
if (res ~= nil) and (bit.band(res.Flags, 0x200) == 0x200) then
if (not state.ActionResources:contains(res)) then
state.ActionResources:append(res);
end
end
end
end
end
bags = T{ 0, 8, 10, 11, 12, 13, 14, 15, 16 };
for _,bag in ipairs(bags) do
for i = 1,80 do
local item = inventory:GetItemTable(bag, i);
if (item ~= nil) then
local res = resMgr:GetItemById(item.Id);
if (res ~= nil) and (bit.band(res.Flags, 0x400) == 0x400) then
if (not state.ActionResources:contains(res)) then
state.ActionResources:append(res);
end
end
end
end
end
table.sort(state.ActionResources, function(a,b)
return a.Name[1] < b.Name[1];
end);
state.Combos.Action = T{};
for index,res in ipairs(state.ActionResources) do
local prev = state.ActionResources[index - 1];
local next = state.ActionResources[index + 1];
--Show item id if multiple matching items..
local name = encoding:ShiftJIS_To_UTF8(res.Name[1]);
if (prev) and (prev.Name[1] == name) then
state.Combos.Action:append(string.format('%s[%u]', name, res.Id));
elseif (next) and (next.Name[1] == name) then
state.Combos.Action:append(string.format('%s[%u]', name, res.Id));
else
state.Combos.Action:append(name);
end
end
if not skipUpdate then
state.Indices.Action = 1;
Update.Action(state.Combos.Action[1]);
end
end
Setup.Spell = function(skipUpdate)
state.ActionResources = T{};
local resMgr = AshitaCore:GetResourceManager();
local jobData = player:GetJobData();
local mainJob = jobData.MainJob;
local mainJobLevel = jobData.MainJobLevel;
local subJob = jobData.SubJob;
local subJobLevel = jobData.SubJobLevel;
for i = 1,0x400 do
local res = resMgr:GetSpellById(i);
if (res) and (player:HasSpell(res)) then
local levelRequired = res.LevelRequired;
--Maybe not best workaround, but trust are all usable at WAR1.
if (levelRequired[2] ~= 1) then
local hasSpell = false;
local jpMask = res.JobPointMask;
if (bit.band(bit.rshift(jpMask, mainJob), 1) == 1) then
if (mainJobLevel == 99) and (player:GetJobPointTotal(mainJob) >= levelRequired[mainJob + 1]) then
hasSpell = true;
end
elseif (levelRequired[mainJob + 1] ~= -1) and (mainJobLevel >= levelRequired[mainJob + 1]) then
hasSpell = true;
end
if (bit.band(bit.rshift(jpMask, subJob), 1) == 0) then
if (levelRequired[subJob + 1] ~= -1) and (subJobLevel >= levelRequired[subJob + 1]) then
hasSpell = true;
end
end
if (hasSpell) then
state.ActionResources:append(res);
end
end
end
end
table.sort(state.ActionResources, function(a,b)
return a.Name[1] < b.Name[1];
end);
state.Combos.Action = T{};
for _,res in ipairs(state.ActionResources) do
state.Combos.Action:append(encoding:ShiftJIS_To_UTF8(res.Name[1]));
end
if (not skipUpdate) then
state.Indices.Action = 1;
Update.Action(state.Combos.Action[1]);
end
end
Setup.Trust = function(skipUpdate)
state.ActionResources = T{};
local resMgr = AshitaCore:GetResourceManager();
local jobData = player:GetJobData();
local mainJob = jobData.MainJob;
local mainJobLevel = jobData.MainJobLevel;
local subJob = jobData.SubJob;
local subJobLevel = jobData.SubJobLevel;
for i = 1,0x400 do
local res = resMgr:GetSpellById(i);
if (res) and (player:HasSpell(res)) then
local levelRequired = res.LevelRequired;
--Maybe not best workaround, but trust are all usable at WAR1.
if (levelRequired[2] == 1) then
local hasSpell = false;
local jpMask = res.JobPointMask;
if (bit.band(bit.rshift(jpMask, mainJob), 1) == 1) then
if (mainJobLevel == 99) and (player:GetJobPointTotal(mainJob) >= levelRequired[mainJob + 1]) then
hasSpell = true;
end
elseif (levelRequired[mainJob + 1] ~= -1) and (mainJobLevel >= levelRequired[mainJob + 1]) then
hasSpell = true;
end
if (bit.band(bit.rshift(jpMask, subJob), 1) == 0) then
if (levelRequired[subJob + 1] ~= -1) and (subJobLevel >= levelRequired[subJob + 1]) then
hasSpell = true;
end
end
if (hasSpell) then
state.ActionResources:append(res);
end
end
end
end
table.sort(state.ActionResources, function(a,b)
return a.Name[1] < b.Name[1];
end);
state.Combos.Action = T{};
for _,res in ipairs(state.ActionResources) do
state.Combos.Action:append(encoding:ShiftJIS_To_UTF8(res.Name[1]));
end
if (not skipUpdate) then
state.Indices.Action = 1;
Update.Action(state.Combos.Action[1]);
end
end
Setup.Weaponskill = function(skipUpdate)
state.ActionResources = T{};
local resMgr = AshitaCore:GetResourceManager();
for i = 1,0x200 do
local res = resMgr:GetAbilityById(i);
if (res) and (player:KnowsAbility(res.Id)) then
state.ActionResources:append(res);
end
end
table.sort(state.ActionResources, function(a,b)
return a.Name[1] < b.Name[1];
end);
state.Combos.Action = T{};
for _,res in ipairs(state.ActionResources) do
state.Combos.Action:append(encoding:ShiftJIS_To_UTF8(res.Name[1]));
end
if (not skipUpdate) then
state.Indices.Action = 1;
Update.Action(state.Combos.Action[1]);
end
end
Update.Type = function(newValue)
Setup[newValue]();
end
Update.Action = function(newValue)
local type = state.Combos.Type[state.Indices.Type];
if (state.Indices.Action > #state.ActionResources) then
Update.Empty();
else
Update[type](state.Indices.Action);
end
end
Update.Ability = function(index)
local res = state.ActionResources[index];
local name = encoding:ShiftJIS_To_UTF8(res.Name[1]);
if (bit.band(res.Targets, 0xFC) ~= 0) then
if (gSettings.DefaultSelectTarget) then
state.MacroText = { string.format('/ja \"%s\" <st>', name) };
else
state.MacroText = { string.format('/ja \"%s\" <t>', name) };
end
else
state.MacroText = { string.format('/ja \"%s\" <me>', name) };
end
state.MacroLabel = { name };
if ((res.RecastTimerId == 0) or (res.RecastTimerId == 254)) then
state.MacroImage = { 'abilities/1hr.png' };
else
state.MacroImage = { string.format('abilities/%u.png', res.Id - 0x200) };
end
state.CostOverride = { '' };
UpdateMacroImage();
end
Update.Command = function(index)
if (gSettings.DefaultSelectTarget) then
state.MacroText = { '/attack <st>' };
else
state.MacroText = { '/attack <t>' };
end
state.MacroLabel = { 'Attack' };
state.MacroImage = { 'misc/command.png' };
state.CostOverride = { '' };
UpdateMacroImage();
end
Update.Empty = function(index)
state.MacroText = nil;
state.MacroLabel = nil;
state.MacroImage = { 'misc/empty.png' };
state.CostOverride = nil;
UpdateMacroImage();
end
Update.Item = function(index)
local res = state.ActionResources[index];
local name = encoding:ShiftJIS_To_UTF8(res.Name[1]);
if (bit.band(res.Targets, 0xFC) ~= 0) then
if (gSettings.DefaultSelectTarget) then
state.MacroText = { string.format('/item \"%s\" <st>', name) };
else
state.MacroText = { string.format('/item \"%s\" <t>', name) };
end
else
state.MacroText = { string.format('/item \"%s\" <me>', name) };
end
state.MacroLabel = { name };
state.MacroImage = { string.format('ITEM:%u', res.Id) };
state.CostOverride = nil;
UpdateMacroImage();
end
Update.Spell = function(index)
local res = state.ActionResources[index];
local name = encoding:ShiftJIS_To_UTF8(res.Name[1]);
if (bit.band(res.Targets, 0xFC) ~= 0) then
if (gSettings.DefaultSelectTarget) then
state.MacroText = { string.format('/ma \"%s\" <st>', name) };
else
state.MacroText = { string.format('/ma \"%s\" <t>', name) };
end
else
state.MacroText = { string.format('/ma \"%s\" <me>', name) };
end
state.MacroLabel = { name };
state.MacroImage = { string.format('spells/%u.png', res.Index) };
state.CostOverride = { '' };
UpdateMacroImage();
end
Update.Trust = function(index)
local res = state.ActionResources[index];
local name = encoding:ShiftJIS_To_UTF8(res.Name[1]);
state.MacroText = { string.format('/ma \"%s\" <me>', name) };
state.MacroLabel = { name };
state.MacroImage = { string.format('spells/%u.png', res.Index) };
state.CostOverride = { '' };
UpdateMacroImage();
end
Update.Weaponskill = function(index)
local res = state.ActionResources[index];
local name = encoding:ShiftJIS_To_UTF8(res.Name[1]);
if (bit.band(res.Targets, 0xFC) ~= 0) then
if (gSettings.DefaultSelectTarget) then
state.MacroText = { string.format('/ws \"%s\" <st>', name) };
else
state.MacroText = { string.format('/ws \"%s\" <t>', name) };
end
else
state.MacroText = { string.format('/ws \"%s\" <me>', name) };
end
state.MacroLabel = { name };
state.MacroImage = { wsmap[res.Id] or '' };
state.CostOverride = { '' };
UpdateMacroImage();
end
local function GetBindResource()
local type = state.Combos.Type[state.Indices.Type];
if T{'Ability', 'Item', 'Spell', 'Trust', 'Weaponskill'}:contains(type) then
local res = state.ActionResources[state.Indices.Action];
return res;
else
return true;
end
end
local function AttemptBind()
local bindResource = GetBindResource();
if (bindResource == nil) then
return false;
end
if (state.Combos.Type[state.Indices.Type] == 'Empty') then
if (state.Indices.Scope == 1) then
gBindings:BindGlobal(state.Hotkey, nil);
elseif (state.Indices.Scope == 2) then
gBindings:BindJob(state.Hotkey, nil);
elseif (state.Indices.Scope == 3) then
gBindings:BindPalette(state.Hotkey, nil);
else
return false;
end
return true;
end
local binding = {};
binding.ActionType = state.Combos.Type[state.Indices.Type];
if T{'Ability', 'Item', 'Spell', 'Trust', 'Weaponskill'}:contains(binding.ActionType) then
if (binding.ActionType == 'Spell') or (binding.ActionType == 'Trust') then
binding.Id = bindResource.Index;
else
binding.Id = bindResource.Id;
end
end
if ((state.CostOverride ~= nil) and (state.CostOverride[1] ~= '')) then
local ids = T{};
local compString = string.gsub(state.CostOverride[1], ' ', '');
if (string.find(compString, ',')) then
for entry in string.gmatch(compString, '([^,]+)') do
local id = tonumber(entry);
if type(id) == 'number' then
local res = AshitaCore:GetResourceManager():GetItemById(id);
if (res ~= nil) and (string.len(res.Name[1]) > 0) then
ids:append(id);
end
end
end
else
local id = tonumber(compString);
if type(id) == 'number' then
local res = AshitaCore:GetResourceManager():GetItemById(id);
if (res ~= nil) and (string.len(res.Name[1]) > 0) then
ids:append(id);
end
end
end
if (#ids > 0) then
binding.CostOverride = ids;
end
end
if (state.MacroLabel == nil) then
binding.Label = '';
else
binding.Label = state.MacroLabel[1];
end
if (state.MacroText == nil) then
binding.Macro = T{};
else
binding.Macro = T{};
for line in string.gmatch(state.MacroText[1], "[^\r\n]+") do
binding.Macro:append(line);
end
end
binding.Image = state.MacroImage[1];
binding.ShowCost = state.Components.Cost;
binding.ShowCross = state.Components.Cross;
binding.ShowFade = state.Components.Fade;
binding.ShowRecast = state.Components.Recast;
binding.ShowName = state.Components.Name;
binding.ShowTrigger = state.Components.Trigger;
binding.ShowReadyPulse = state.Components.ReadyPulse;
binding.ShowSkillchainIcon = state.Components.SkillchainIcon;
binding.ShowSkillchainAnimation = state.Components.SkillchainAnimation;
binding.ShowHotkey = state.Components.Hotkey;
if (state.Indices.Scope == 1) then
gBindings:BindGlobal(state.Hotkey, binding);
elseif (state.Indices.Scope == 2) then
gBindings:BindJob(state.Hotkey, binding);
elseif (state.Indices.Scope == 3) then
gBindings:BindPalette(state.Hotkey, binding);
else
return false;
end
return true;
end
local exposed = {};
function exposed:Close()
state = { IsOpen = { false } };
end
function exposed:GetActive()
return (state.IsOpen[1] == true);
end
function exposed:GetMacroState()
if (state.IsOpen[1] == true) then
return state.MacroState;
end
return 0;
end
function exposed:HandleButton(button, pressed)
if (pressed) then
if (button == state.RepeatButton) then
if (state.RepeatDelay > 0.05) then
state.RepeatDelay = state.RepeatDelay - 0.05;
end
state.RepeatTime = os.clock();
else
state.RepeatButton = button;
state.RepeatTime = os.clock();
state.RepeatDelay = 0.3;
end
if (state.Tab == 1) then
if (button == 'BindingUp') then
if (state.SelectedIndex > 1) then
state.SelectedIndex = state.SelectedIndex - 1;
end
end
if (button == 'BindingDown') then
if (state.SelectedIndex < 3) then
state.SelectedIndex = state.SelectedIndex + 1;
end
end
if (button == 'BindingNext') then
if (state.SelectedIndex == 1) then
AdvanceCombo('Scope');
elseif (state.SelectedIndex == 2) then
AdvanceCombo('Type');
elseif (state.SelectedIndex == 3) then
AdvanceCombo('Action');
end
end
if (button == 'BindingPrevious') then
if (state.SelectedIndex == 1) then
DecrementCombo('Scope');
elseif (state.SelectedIndex == 2) then
DecrementCombo('Type');
elseif (state.SelectedIndex == 3) then
DecrementCombo('Action');
end
end
end
if (button == 'BindingTab') then
if (state.Tab == 1) then
state.ForceTab = 2;
else
state.ForceTab = 1;
end
end
if (button == 'BindingConfirm') then
if (AttemptBind()) then
state = { IsOpen = { false } };
end
end
if (button == 'BindingCancel') then
state = { IsOpen = { false } };
end
elseif (button == state.RepeatButton) then
state.RepeatButton = nil;
end
end
function exposed:Render()
if (state.RepeatButton ~= nil) and (os.clock() > (state.RepeatTime + state.RepeatDelay)) then
self:HandleButton(state.RepeatButton, true);
end
if (state.IsOpen[1]) then
if (imgui.Begin(string.format('%s v%s Binding', addon.name, addon.version), state.IsOpen, ImGuiWindowFlags_AlwaysAutoResize)) then
imgui.BeginGroup();
if imgui.BeginTabBar('##TabBar', ImGuiTabBarFlags_NoCloseWithMiddleMouseButton) then
if imgui.BeginTabItem('Binding##BindingTab', 0, (state.ForceTab == 1) and 6 or 4) then
state.Tab = 1;
if (state.ForceTab == 1) then
state.ForceTab = nil;
end
imgui.BeginChild('BindingChild', { 253, 390 }, ImGuiChildFlags_Borders);
imgui.TextColored(header, 'Combo Type');
imgui.Text(GetMacroStateText(state.MacroState));
imgui.TextColored(header, 'Macro Button');
imgui.Text(buttonText[state.MacroButton]);
ComboBox('Scope', 'Scope', state.SelectedIndex == 1 and activeHeader or header);
imgui.ShowHelp('Determines how wide the binding will apply. Job binds are used to fill empty slots in palette binds, then global binds are used to fill any remaining empty slots.');
ComboBox('Action Type', 'Type', state.SelectedIndex == 2 and activeHeader or header);
if (#state.Combos.Action > 0) then
ComboBox('Action', 'Action', state.SelectedIndex == 3 and activeHeader or header);
else
imgui.TextColored(state.SelectedIndex == 3 and activeHeader or header, 'Action');
imgui.Text('N/A');
end
imgui.TextColored(header, 'Macro');
if (state.MacroText ~= nil) then
imgui.InputTextMultiline('##MacroText', state.MacroText, 4096, { 237, 116 });
else
imgui.Text('N/A');
end
imgui.TextColored(header, 'Label');
if (state.MacroLabel ~= nil) then
imgui.InputText('##MacroLabel', state.MacroLabel, 32);
else
imgui.Text('N/A');
end
imgui.EndChild();
imgui.EndTabItem();
end
if imgui.BeginTabItem('Appearance##AppearanceTab', 0, (state.ForceTab == 2) and 6 or 4) then
state.Tab = 2;
if (state.ForceTab == 2) then
state.ForceTab = nil;
end
local layout = gSingleDisplay.Layout;
local width = 32;
local height = 32;
if layout then
width = layout.Icon.Width;
height = layout.Icon.Height;
end
imgui.BeginChild('AppearanceChild', { 253, 235 + height }, ImGuiChildFlags_Borders);
imgui.TextColored(header, 'Image');
imgui.ShowHelp('While the image file and size are correct, rendering here is done with ImGui instead of GdiPlus and may vary slightly in appearance.');
local posY = imgui.GetCursorPosY();
if (state.Texture ~= nil) then
imgui.Image(tonumber(ffi.cast("uint32_t", state.Texture)),
{ width, height },
{ 0, 0 }, { 1, 1 }, { 1, 1, 1, 1 }, { 0, 0, 0, 0 });
end
imgui.SetCursorPos({imgui.GetCursorPosX(), posY + height});
if (state.Combos.Type[state.Indices.Type] ~= 'Empty') then
imgui.InputText('##MacroImage', state.MacroImage, 256);
imgui.SameLine();
if (imgui.Button('Preview', { 60, 0 })) then
UpdateMacroImage();
end
end
imgui.TextColored(header, 'Components');
if (state.Combos.Type[state.Indices.Type] ~= 'Empty') then
imgui.BeginGroup();
CheckBox('Cost');
imgui.ShowHelp('Display action cost indicators.');
CheckBox('Cross');
imgui.ShowHelp('Displays a X over actions you don\'t currently know.');
CheckBox('Fade');
imgui.ShowHelp('Fades the icon for actions where cooldown is not 0 or cost is not met.');
CheckBox('Recast');
imgui.ShowHelp('Shows action recast timers.');
CheckBox('Hotkey');
imgui.ShowHelp('Shows hotkey label.');
imgui.EndGroup();
imgui.SameLine();
imgui.BeginGroup();
CheckBox('Name');
imgui.ShowHelp('Shows action names.');
CheckBox('Trigger');
imgui.ShowHelp('Shows an overlay when you activate an action.');
CheckBox('Ready Pulse', 'ReadyPulse');
imgui.ShowHelp('Pulses the icon brightness while the action is off cooldown and usable. Best on long-cooldown abilities like Steal, Mug, Provoke.');
CheckBox('SC Icon', 'SkillchainIcon');
imgui.ShowHelp('Overrides weaponskill icons when a skillchain would be formed.');
CheckBox('SC Animation', 'SkillchainAnimation');
imgui.ShowHelp('Animates a border around weaponskill icons when a skillchain would be formed.');
imgui.EndGroup();
else
imgui.Text('N/A');
end
imgui.TextColored(header, 'Cost Override');
imgui.ShowHelp('Entering an item ID, or multiple item IDs seperated by commas, will make cost display as the total amount of those items in your inventory and wardrobes(if equippable) or temporary items(if not). This can be useful for actions like Call Beast or Reward that use an item, but not always the same item. Actions like angon and ninjutsu with fixed items are automatically handled without specifying this.');
if (state.CostOverride ~= nil) then
imgui.InputText('##MacroCostOverride', state.CostOverride, 256);
else
imgui.Text('N/A');
end
imgui.EndChild();
imgui.EndTabItem();
end
imgui.EndTabBar();
end
imgui.EndGroup();
if imgui.Button('Cancel', { 60, 0 }) then
state.IsOpen[1] = false;
end
local bindResource = GetBindResource();
if (bindResource ~= nil) then
imgui.SameLine();
imgui.SetCursorPos( { 202, imgui.GetCursorPosY() });
if imgui.Button('Bind', { 60, 0 }) then
if (AttemptBind()) then
state = { IsOpen = { false } };
end
end
end
end
imgui.End();
end
if (state.IsOpen[1] == false) then
self.ForceDisplay = nil;
else
self.ForceDisplay = gSingleDisplay;
self.ForceState = state.MacroState;
end
end
function exposed:Show(macroState, macroButton)
local square = gSingleDisplay:GetElementByMacro(macroState, macroButton);
if square == nil then
state = { IsOpen = { false } };
return;
end
local hotkey = string.format('%s:%s', macroComboBinds[macroState], macroButton);
local binding = square.Binding;
if (binding == nil) then
state = {
IsOpen = { true },
SelectedIndex = 1,
Tab = 1,
ForceTab = 1,
MacroState = macroState,
MacroButton = macroButton,
Hotkey = hotkey,
ActionResources = T{},
Combos = {
['Scope'] = T{ 'Global', 'Job', 'Palette' },
['Type'] = T{ 'Ability', 'Command', 'Empty', 'Item', 'Spell', 'Trust', 'Weaponskill' },
['Action'] = T{ },
},
Components = {
Cost = true,
Cross = true,
Fade = true,
Recast = true,
Name = true,
Trigger = true,
ReadyPulse = false,
SkillchainIcon = true,
SkillchainAnimation = true,
Hotkey = false,
},
Indices = {
['Scope'] = 3,
['Type'] = 1,
},
CostOverride = { '' },
MacroText = { '' },
MacroLabel = { '' },
};
Setup.Ability();
return;
end
state = {
IsOpen = { true },
SelectedIndex = 1,
MacroState = macroState,
MacroButton = macroButton,
Hotkey = hotkey,
Tab = 1,
ForceTab = 1,
ActionResources = T{},
Combos = {
['Scope'] = T{ 'Global', 'Job', 'Palette' },
['Type'] = T{ 'Ability', 'Command', 'Empty', 'Item', 'Spell', 'Trust', 'Weaponskill' },
['Action'] = T{ },
},
Components = {
Cost = binding.ShowCost,
Cross = binding.ShowCross,
Fade = binding.ShowFade,
Recast = binding.ShowRecast,
Name = binding.ShowName,
Trigger = binding.ShowTrigger,
ReadyPulse = binding.ShowReadyPulse,
SkillchainIcon = binding.ShowSkillchainIcon,
SkillchainAnimation = binding.ShowSkillchainAnimation,
Hotkey = binding.ShowHotkey,
},
Indices = {
['Scope'] = binding.Scope
},
CostOverride = { '' },
MacroText = { '' },
MacroLabel = { binding.Label },
MacroImage = { binding.Image }
};
UpdateMacroImage();
for index,entry in ipairs(state.Combos.Type) do
if (entry == binding.ActionType) then
state.Indices.Type = index;
Setup[entry](true);
end
end
if (binding.ActionType == 'Ability') or (binding.ActionType == 'Weaponskill') then
local res = AshitaCore:GetResourceManager():GetAbilityById(binding.Id);
if not state.ActionResources:contains(res) then
state.ActionResources:append(res);
table.sort(state.ActionResources, function(a,b)
return a.Name[1] < b.Name[1];
end);
state.Combos.Action = T{};
for _,res in ipairs(state.ActionResources) do
state.Combos.Action:append(encoding:ShiftJIS_To_UTF8(res.Name[1]));
end
end
for index,match in ipairs(state.ActionResources) do
if (match == res) then
state.Indices.Action = index;
break;
end
end
elseif (binding.ActionType == 'Spell') or (binding.ActionType == 'Trust') then
local res = AshitaCore:GetResourceManager():GetSpellById(binding.Id);
if not state.ActionResources:contains(res) then
state.ActionResources:append(res);
table.sort(state.ActionResources, function(a,b)
return a.Name[1] < b.Name[1];
end);
state.Combos.Action = T{};
for _,res in ipairs(state.ActionResources) do
state.Combos.Action:append(encoding:ShiftJIS_To_UTF8(res.Name[1]));
end
end
for index,match in ipairs(state.ActionResources) do
if (match == res) then
state.Indices.Action = index;
break;
end
end
elseif (binding.ActionType == 'Item') then
local res = AshitaCore:GetResourceManager():GetItemById(binding.Id);
if not state.ActionResources:contains(res) then
state.ActionResources:append(res);
table.sort(state.ActionResources, function(a,b)
return a.Name[1] < b.Name[1];
end);
state.Combos.Action = T{};
for index,res in ipairs(state.ActionResources) do
local prev = state.ActionResources[index - 1];
local next = state.ActionResources[index + 1];
local name = encoding:ShiftJIS_To_UTF8(res.Name[1]);
--Show item id if multiple matching items..
if (prev) and (prev.Name[1] == name) then
state.Combos.Action:append(string.format('%s[%u]', name, res.Id));
elseif (next) and (next.Name[1] == name) then
state.Combos.Action:append(string.format('%s[%u]', name, res.Id));
else
state.Combos.Action:append(name);
end
end
end
for index,match in ipairs(state.ActionResources) do
if (match == res) then
state.Indices.Action = index;
break;
end
end
end
if (type(binding.CostOverride) == 'table') then
local output = '';