forked from AssemblerManiac/InventoryInsight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInventoryInsight.lua
1187 lines (1018 loc) · 46.7 KB
/
InventoryInsight.lua
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
----------------------------------------------------------------------
--IIfA.lua
--v0.8 - Original Author: Vicster0
-- v1.x and 2.x - rewrites by ManaVortex & AssemblerManiac
-- v3.x - new features mainly by ManaVortex
--[[
Collects inventory data for all characters on a single account including the shared bank and makes this information available
on tooltips across the entire account providing the playerwith useful insight into their account wide inventory.
DISCLAIMER
This Add-on is not created by, affiliated with or sponsored by ZeniMax Media Inc. or its affiliates. The Elder Scrolls® and related
logos are registered trademarks or trademarks of ZeniMax Media Inc. in the United States and/or other countries. All rights reserved."
]]
-- text searches in non-EN languages improved by Baertram 2019-10-13
----------------------------------------------------------------------
local LMP = LibMediaProvider
local IIFA_COLOR_DEFAULT = ZO_ColorDef:New("3399FF")
-- --------------------------------------------------------------
-- External functions
-- --------------------------------------------------------------
-- 7-26-16 AM - global func, not part of IIfA class, used in IIfA_OnLoad
local function IIfA_SlashCommands(cmd)
if (cmd == IIfA.EMPTY_STRING) then
d("[IIfA]: Please find the majority of options in the addon settings section of the menu under Inventory Insight.")
d(" ")
d("[IIfA]: Usage - ")
d(" /IIfA [options]")
d(" ")
d(" Options")
d(" debug - Enables debug functionality for the IIfA addon.")
d(" run - Runs the IIfA data collector.")
d(" color - Opens the color picker dialog to set tooltip text color.")
d(" toggle - Show/Hide IIfA")
return
end
if (cmd == "debug") then
if (IIFA_DATABASE[IIfA.currentAccount].settings.bDebug) then
d("[IIfA]: Debug [Off]")
IIFA_DATABASE[IIfA.currentAccount].settings.bDebug = false
else
d("[IIfA]: Debug [On]")
IIFA_DATABASE[IIfA.currentAccount].settings.bDebug = true
end
return
end
if (cmd == "run") then
d("[IIfA]: Running collector...")
IIfA:CollectAllUseAsync()
return
end
if (cmd == "color") then
local in2ColorPickerOnMouseUp = _in2OptionsColorPicker:GetHandler("OnMouseUp")
in2ColorPickerOnMouseUp(_in2OptionsColorPicker, nil, true)
return
end
if cmd == "toggle" then
IIfA:ToggleInventoryFrame()
end
end
function IIfA:DebugOut(output, ...)
local displayName = IIfA.currentAccount
local accountSettings = IIFA_DATABASE[displayName].settings
-- Return if any condition fails
if not accountSettings or not next(accountSettings) or not accountSettings.bDebug then return end
-- Proceed with the debug output if all conditions are met
IIfA:dm("Debug", output, ...)
end
function IIfA:StatusAlert(message)
local displayName = IIfA.currentAccount
local accountSettings = IIFA_DATABASE[displayName].settings
if accountSettings and accountSettings.bDebug then
ZO_Alert(UI_ALERT_CATEGORY_ALERT, IIfA.defaultAlertSound, message)
end
end
function IIfA:isItemKey(itemKey)
return type(itemKey) == "string" and itemKey:match("^%d+$") ~= nil and #itemKey < 10
end
function IIfA:isItemLink(itemLink)
return type(itemLink) == "string" and itemLink:match(":item:") ~= nil
end
function IIfA:isCollectibleLink(itemLink)
return type(itemLink) == "string" and itemLink:match(":collectible:") ~= nil
end
function IIfA:GetCollectibleLinkItemId(collectibleLink)
local link = { ZO_LinkHandler_ParseLink(collectibleLink) }
return tonumber(select(4, unpack(link)))
end
function IIfA:SetupTextColorHandlers()
local settings = IIFA_DATABASE[IIfA.currentAccount].settings
-- Assign color handlers based on saved settings
self.colorHandlerToon = ZO_ColorDef:New(settings.TextColorsToon)
self.colorHandlerCompanion = ZO_ColorDef:New(settings.TextColorsCompanion)
self.colorHandlerBank = ZO_ColorDef:New(settings.TextColorsBank)
self.colorHandlerGBank = ZO_ColorDef:New(settings.TextColorsGBank)
self.colorHandlerHouse = ZO_ColorDef:New(settings.TextColorsHouse)
self.colorHandlerHouseChest = ZO_ColorDef:New(settings.TextColorsHouseChest)
self.colorHandlerCraftBag = ZO_ColorDef:New(settings.TextColorsCraftBag)
end
--Check if the clientLanguage is using gender specific string suffix like ^mx or ^f which need to be replaced
--by zo_strformat functions
function IIfA:CheckIfClientLanguageUsesGenderStrings(clientLanguage)
clientLanguage = clientLanguage or GetCVar("language.2")
if not clientLanguage then return false end
local clientLanguagesWithGenderSpecificStringsSuffix = {
["de"] = true,
["fr"] = true,
}
local retVar = clientLanguagesWithGenderSpecificStringsSuffix[clientLanguage] or false
IIfA.clientLanguageUsesGenderString = retVar
return retVar
end
local IIfA_FONT_STYLE_NORMAL = 1
local IIfA_FONT_STYLE_OUTLINE = 2
local IIfA_FONT_STYLE_OUTLINE_THICK = 3
local IIfA_FONT_STYLE_SHADOW = 4
local IIfA_FONT_STYLE_SOFT_SHADOW_THICK = 5
local IIfA_FONT_STYLE_SOFT_SHADOW_THIN = 6
local StyleList = {
[IIfA_FONT_STYLE_NORMAL] = "Normal",
[IIfA_FONT_STYLE_OUTLINE] = "Outline",
[IIfA_FONT_STYLE_OUTLINE_THICK] = "Thin-Outline",
[IIfA_FONT_STYLE_SHADOW] = "Shadow",
[IIfA_FONT_STYLE_SOFT_SHADOW_THICK] = "Soft-Shadow-Thick",
[IIfA_FONT_STYLE_SOFT_SHADOW_THIN] = "Soft-Shadow-Thin",
}
function IIfA:CreateFontStyleChoices()
for styleConstant, styleString in pairs(StyleList) do
IIfA.fontStyleChoices[styleConstant] = styleString
IIfA.fontStyleValues[styleConstant] = styleConstant
end
end
function IIfA:SetFontListChoices()
IIfA.fontListChoices = LMP:List(LMP.MediaType.FONT)
end
function IIfA:GetColorHexFromTable(colorTable)
local r, g, b = ZO_ColorDef.FloatsToRGBA(colorTable.r, colorTable.g, colorTable.b, 1)
return ZO_ColorDef.RGBAToHex(r, g, b, 255)
end
-- Constants
local IIFA_DEFAULT_FORMAT = 1
local IIFA_MEGASERVER_FORMAT = 2
local function DetectProfile()
local displayName = GetDisplayName()
local worldName = GetWorldName()
-- Check for [GetWorldName()] first
if IIfA_Data and IIfA_Data[worldName] and IIfA_Data[worldName][displayName] then
if IIfA_Data[worldName][displayName]["$AccountWide"] then
return IIFA_MEGASERVER_FORMAT
end
end
-- Fallback to "Default"
if IIfA_Data and IIfA_Data["Default"] and IIfA_Data["Default"][displayName] then
if IIfA_Data["Default"][displayName]["$AccountWide"] then
return IIFA_DEFAULT_FORMAT
end
end
-- No valid profile found
IIfA:dm("Debug", "[DetectProfile] No valid profile found.")
return nil
end
local function GetSettingsAndDataLocations()
local profileFormat = DetectProfile()
local displayName = GetDisplayName()
local worldName = GetWorldName()
-- Determine dataLocation
local dataLocation
if profileFormat and profileFormat == IIFA_DEFAULT_FORMAT then
local baseLocation = IIfA_Data["Default"][displayName]["$AccountWide"]
if baseLocation and baseLocation["Data"] then
dataLocation = IIfA_Data["Default"][displayName]["$AccountWide"]["Data"]
else
IIfA:dm("Debug", "[GetSettingsAndDataLocations] Default format found but no Data present.")
return nil, nil -- No valid data location
end
elseif profileFormat and profileFormat == IIFA_MEGASERVER_FORMAT then
local baseLocation = IIfA_Data[worldName][displayName]["$AccountWide"]
if baseLocation and baseLocation["Data"] then
dataLocation = IIfA_Data[worldName][displayName]["$AccountWide"]["Data"]
else
IIfA:dm("Debug", "[GetSettingsAndDataLocations] Megaserver format found but no Data present.")
return nil, nil -- No valid data location
end
else
IIfA:dm("Debug", "[GetSettingsAndDataLocations] Unable to determine valid data profile for Default or worldName.")
return nil, nil -- No valid data location
end
-- Determine settingsLocation
local settingsLocation
local globalSettings = dataLocation and dataLocation.saveSettingsGlobally
if globalSettings then
settingsLocation = dataLocation
elseif not globalSettings then
local topLevelLocation = IIfA_Settings and IIfA_Settings["Default"] and IIfA_Settings["Default"][displayName]
if topLevelLocation and topLevelLocation[GetCurrentCharacterId()] then
settingsLocation = IIfA_Settings["Default"][displayName][GetCurrentCharacterId()]
else
settingsLocation = IIfA_Settings["Default"][displayName]
end
else
IIfA:dm("Debug", "[GetSettingsAndDataLocations] Data field present but unable to determine global or non global settings profile.")
return nil, nil -- No valid data location
end
return settingsLocation, dataLocation
end
-- Helper function to safely access nested tables
local function GetNestedTable(root, ...)
local tbl = root
for _, key in ipairs({ ... }) do
tbl = tbl[key]
if not tbl then return {} end -- Return an empty table if any key is missing
end
return tbl
end
function IIfA:MigrateLegacyValues()
if IIfA.data.legacyMigrationComplete then
IIfA:dm("Debug", "MigrateLegacyValues skipped, already executed previously..")
return
end
-- Safely access the settings and data tables
local settingsData, locationData = GetSettingsAndDataLocations()
if settingsData == nil then
IIfA:dm("Debug", "Settings or Account based information was nil migration of Legacy Values not possible.")
return
end
-- Skip migration if it has already been completed
IIfA:dm("Info", "MigrateLegacyValues Starting...")
-- Convert in2ToggleGuildBankDataCollection to bCollectGuildBankData
if settingsData.in2ToggleGuildBankDataCollection ~= nil then
settingsData.bCollectGuildBankData = settingsData.in2ToggleGuildBankDataCollection
settingsData.in2ToggleGuildBankDataCollection = nil
end
-- Clean up legacy text color settings
if settingsData.in2TextColors ~= nil then
settingsData.TextColorsToon = settingsData.TextColorsToon or ZO_ColorDef:New(settingsData.in2TextColors):ToHex()
settingsData.TextColorsCompanion = settingsData.TextColorsCompanion or ZO_ColorDef:New(settingsData.in2TextColors):ToHex()
settingsData.TextColorsBank = settingsData.TextColorsBank or ZO_ColorDef:New(settingsData.in2TextColors):ToHex()
settingsData.TextColorsGBank = settingsData.TextColorsGBank or ZO_ColorDef:New(settingsData.in2TextColors):ToHex()
settingsData.TextColorsHouse = settingsData.TextColorsHouse or ZO_ColorDef:New(settingsData.in2TextColors):ToHex()
settingsData.TextColorsHouseChest = settingsData.TextColorsHouseChest or ZO_ColorDef:New(settingsData.in2TextColors):ToHex()
settingsData.TextColorsCraftBag = settingsData.TextColorsCraftBag or ZO_ColorDef:New(settingsData.in2TextColors):ToHex()
-- Remove the legacy key
settingsData.in2TextColors = nil
end
-- Process DBv2 to convert names to IDs
if settingsData.DBv2 ~= nil then
IIfA:ConvertNameToId(settingsData.DBv2)
settingsData.DBv2 = nil -- Clean up after conversion
end
-- Clean up legacy accountCharacters key
if settingsData.accountCharacters ~= nil then
settingsData.accountCharacters = nil
end
-- Move DBv3 to the world-specific structure
local worldName = GetWorldName():gsub(" Megaserver", IIfA.EMPTY_STRING)
IIfA.data[worldName] = IIfA.data[worldName] or {}
if IIfA.data.DBv3 ~= nil then
if IIfA.data[worldName].DBv3 == nil then
IIfA.data[worldName].DBv3 = IIfA.data.DBv3
end
IIfA.data.DBv3 = nil
end
-- Convert InventoryListFilter from "All Account Owned" to "All Storage"
if IIfA.InventoryListFilter == "All Account Owned" then
IIfA.InventoryListFilter = GetString(IIFA_LOCATION_NAME_ALL_STORAGE)
end
-- Example for handling character-specific settings (from settingsData)
if settingsData.bFilterOnSetName == nil then
settingsData.bFilterOnSetName = false
end
-- Mark migration as completed
IIfA.data.legacyMigrationComplete = true
end
function IIfA:ConvertCompanionToServerFormat()
IIfA:dm("Debug", "ConvertCompanionToServerFormat Starting...")
-- Exit early if IIfA_Companion does not exist
if not IIfA_Companion or not IIfA_Companion["Default"] then
IIfA:dm("Debug", "IIfA_Companion does not exist or is already empty. Exiting early.")
return
end
local displayName = GetDisplayName()
local currentAccount = IIfA.currentAccount
local currentServerType = IIfA.currentServerType
-- Access the companion data table directly using GetDisplayName()
local companionData = IIfA_Companion["Default"][displayName] and IIfA_Companion["Default"][displayName]["$AccountWide"]
if not companionData then
IIfA:dm("Debug", "No companion data found for the current account. Exiting early.")
return
end
-- Access the server-specific data in IIFA_DATABASE
local serverData = IIFA_DATABASE[currentAccount].servers[currentServerType]
-- Ensure CharIdToName and CharNameToId tables exist in the serverData
serverData.CompanionIdToName = serverData.CompanionIdToName or {}
serverData.CompanionNameToId = serverData.CompanionNameToId or {}
-- Migrate data from the old companion table to the server-specific format
for id, name in pairs(companionData.CharIdToName or {}) do
serverData.CompanionIdToName[id] = name
end
for name, id in pairs(companionData.CharNameToId or {}) do
serverData.CompanionNameToId[name] = id
end
-- Cleanup old companion data for the current account
companionData.CharIdToName = nil
companionData.CharNameToId = nil
-- Helper function to check if an account in IIfA_Companion is safe to delete
local function IsAccountSafeToDelete(accountData)
local accountWideData = accountData["$AccountWide"]
return accountWideData and not accountWideData.CharNameToId and not accountWideData.CharIdToName
end
-- Check all accounts under "Default" in IIfA_Companion
local accountsToDelete = {}
for accountName, accountData in pairs(IIfA_Companion["Default"]) do
if IsAccountSafeToDelete(accountData) then
table.insert(accountsToDelete, accountName)
end
end
-- Delete accounts that are safe to delete
for _, accountName in ipairs(accountsToDelete) do
IIfA_Companion["Default"][accountName] = nil
end
-- Check if IIfA_Companion["Default"] is now empty
if next(IIfA_Companion["Default"]) == nil then
-- Safe to remove IIfA_Companion completely
IIfA_Companion = nil
IIfA:dm("Debug", "IIfA_Companion has been completely cleared and removed.")
else
IIfA:dm("Debug", "IIfA_Companion still contains accounts with data.")
end
IIFA_DATABASE[IIfA.currentAccount].settings.companionMigrationCompleted = IIFA_DATABASE[IIfA.currentAccount].settings.companionMigrationCompleted or true
end
function IIfA:MigrateFrameSettings()
IIfA:dm("Info", "MigrateFrameSettings Starting...")
local settingsData, locationData = GetSettingsAndDataLocations()
local hasSettingsData = settingsData and settingsData["frameSettings"]
if not settingsData then
IIfA:dm("Debug", "[MigrateFrameSettings] Migration not possible no data found for the current account. Exiting early.")
return
end
if not hasSettingsData then
IIfA:dm("Debug", "[MigrateFrameSettings] Migration not possible, settingsData present but no remaining frameSettings. Exiting early.")
return
end
-- Migrate settingsData to IIFA_DATABASE using defaults_character if settingsData is valid
for key, _ in pairs(IIfA.defaults_character) do
IIfA:dm("Debug", "[key] <<1>>", key)
if key ~= "frameSettings" and settingsData and settingsData[key] ~= nil then
IIfA:dm("Debug", "Copy non frameSettings value.")
IIFA_DATABASE[IIfA.currentAccount].characters[IIfA.currentCharacterId][key] = settingsData[key]
settingsData[key] = nil
elseif key == "frameSettings" then
for frameKey, frameDefault in pairs(IIfA.defaults_character["frameSettings"]) do
if settingsData and settingsData[key] and settingsData[key][frameKey] ~= nil then
IIfA:dm("Debug", "Copy frameSettings value from settingsData.")
IIFA_DATABASE[IIfA.currentAccount].characters[IIfA.currentCharacterId][key][frameKey] = settingsData[key][frameKey]
settingsData[key][frameKey] = nil
end
end
end
end
if settingsData and settingsData["frameSettings"] then settingsData["frameSettings"] = nil end
IIfA:dm("Debug", "MigrateFrameSettings Completed")
end
function IIfA:MigrateToAccountAndServerSpecificFormat()
IIfA:dm("Info", "MigrateToAccountAndServerSpecificFormat Starting...")
local settingsData, locationData = GetSettingsAndDataLocations()
if not settingsData then
IIfA:dm("Debug", "Migration not possible no data found for the current account. Exiting early.")
return
end
-- Assign NA and EU specific DBv3 tables
local naData = locationData.NA.DBv3
local euData = locationData.EU.DBv3
-- Migrate defaults_account
for key, _ in pairs(IIfA.defaults_account) do
if settingsData and settingsData[key] ~= nil then
IIFA_DATABASE[IIfA.currentAccount].settings[key] = settingsData[key]
settingsData[key] = nil
end
end
-- Migrate defaults_server specific keys
local serverSpecificKeys = { "collectHouseData", "bCollectGuildBankData", "ignoredCharEquipment", "ignoredCharInventories", "houseChestSpace", "assets" }
for _, key in ipairs(serverSpecificKeys) do
if settingsData and settingsData[key] ~= nil then
IIFA_DATABASE[IIfA.currentAccount].servers[IIfA.currentServerType][key] = settingsData[key]
settingsData[key] = nil
end
end
-- Copy NA and EU DBv3 data to the new database structure
if naData then
IIFA_DATABASE[IIfA.currentAccount].servers.NA.DBv3 = naData
locationData.NA.DBv3 = nil
end
if euData then
IIFA_DATABASE[IIfA.currentAccount].servers.EU.DBv3 = euData
locationData.EU.DBv3 = nil
end
-- Delete specific keys no longer used or needed
local specificKeysToDelete = { "defaultInventoryFrameView", "EU", "EU-guildBanks", "in2AgedGuildBankDataWarning", "in2DefaultInventoryFrameView", "NA", "NA-guildBanks", "DBv3", "ShowToolTipWhen" }
for _, key in ipairs(specificKeysToDelete) do
if settingsData and settingsData[key] ~= nil then
settingsData[key] = nil
end
if locationData and locationData[key] ~= nil then
locationData[key] = nil
end
end
-- Mark migration as complete
IIFA_DATABASE[IIfA.currentAccount].settings.newFormatMigrationCompleted = true
IIfA:dm("Debug", "MigrateToAccountAndServerSpecificFormat Completed")
end
function IIfA:InitializeDatabase()
-- Default Account-Wide Settings
local defaults_account = {
bDebug = false,
showItemCountOnRight = true,
showItemStats = false,
b_collectHouses = false,
ignoreCompanionEquipment = false,
BagSpaceWarn = {
["threshold"] = 85,
["r"] = 0.9019607902,
["g"] = 0.5098039508,
["b"] = 0,
},
BagSpaceAlert = {
["threshold"] = 95,
["r"] = 1,
["g"] = 1,
["b"] = 0,
},
BagSpaceFull = {
["r"] = 255,
["g"] = 0,
["b"] = 0,
},
in2TooltipsFont = "ZoFontGame",
TooltipFontFace = "ProseAntique",
TooltipFontSize = 18,
TooltipFontEffect = "Normal",
showToolTipWhen = "Always",
dontFocusSearch = false,
bAddContextMenuEntrySearchInIIfA = true,
bAddContextMenuEntryMissingMotifsInIIfA = true,
bInSeparateFrame = true,
showStyleInfo = true,
alwaysUseStyleMaterial = false,
bFilterOnSetNameToo = false,
bFilterOnSetName = false,
hideCloseButton = false,
FCOISshowMarkerIcons = false,
lastLang = GetCVar("language.2"),
refreshDelay = 250,
-- newFormatMigrationCompleted = false, -- Tracks if MigrateLegacyValues has run
-- Text colors for various contexts
TextColorsToon = IIFA_COLOR_DEFAULT:ToHex(),
TextColorsCompanion = IIFA_COLOR_DEFAULT:ToHex(),
TextColorsBank = IIFA_COLOR_DEFAULT:ToHex(),
TextColorsGBank = IIFA_COLOR_DEFAULT:ToHex(),
TextColorsHouse = IIFA_COLOR_DEFAULT:ToHex(),
TextColorsHouseChest = IIFA_COLOR_DEFAULT:ToHex(),
TextColorsCraftBag = IIFA_COLOR_DEFAULT:ToHex(),
}
IIfA.defaults_account = defaults_account
-- Default Server-Specific Settings
local defaults_server = {
NA = {
collectHouseData = {}, -- server specific
HouseNameToId = {}, -- server specific
HouseIdToName = {}, -- server specific
ignoredCharEquipment = {}, -- server specific
ignoredCharInventories = {}, -- server specific
bCollectGuildBankData = false, -- server specific
DBv3 = {}, -- server specific
guildBankInfo = {}, -- server specific
GuildIdToName = {}, -- server specific
GuildNameToId = {}, -- server specific
houseChestSpace = {}, -- server specific
assets = {}, -- server specific
CompanionIdToName = {}, -- server specific
CompanionNameToId = {}, -- server specific
CharIdToName = {}, -- server specific
CharNameToId = {}, -- server specific
},
EU = {
collectHouseData = {}, -- server specific
HouseNameToId = {}, -- server specific
HouseIdToName = {}, -- server specific
ignoredCharEquipment = {}, -- server specific
ignoredCharInventories = {}, -- server specific
bCollectGuildBankData = false, -- server specific
DBv3 = {}, -- server specific
guildBankInfo = {}, -- server specific
GuildIdToName = {}, -- server specific
GuildNameToId = {}, -- server specific
houseChestSpace = {}, -- server specific
assets = {}, -- server specific
CompanionIdToName = {}, -- server specific
CompanionNameToId = {}, -- server specific
CharIdToName = {}, -- server specific
CharNameToId = {}, -- server specific
},
}
IIfA.defaults_server = defaults_server
-- Default Character-Specific Settings
local valDocked, valLocked, valMinimized = true, false, false
local valGamepadDocked, valGamepadLocked = false, true
local valLastX, valLastY, valHeight, valWidth = 435, 300, 750, 420
local valGamepadLastX, valGamepadLastY = 1010, 175
local defaults_character = {
frameSettings = {
["bank"] = { hidden = false, docked = valDocked, locked = valLocked, minimized = valMinimized, lastX = valLastX, lastY = valLastY, height = valHeight, width = valWidth },
["guildBank"] = { hidden = false, docked = valDocked, locked = valLocked, minimized = valMinimized, lastX = valLastX, lastY = valLastY, height = valHeight, width = valWidth },
["tradinghouse"] = { hidden = false, docked = valDocked, locked = valLocked, minimized = valMinimized, lastX = valLastX, lastY = valLastY, height = valHeight, width = valWidth },
["smithing"] = { hidden = false, docked = valDocked, locked = valLocked, minimized = valMinimized, lastX = valLastX, lastY = valLastY, height = valHeight, width = valWidth },
["store"] = { hidden = false, docked = valDocked, locked = valLocked, minimized = valMinimized, lastX = valLastX, lastY = valLastY, height = valHeight, width = valWidth },
["stables"] = { hidden = false, docked = valDocked, locked = valLocked, minimized = valMinimized, lastX = valLastX, lastY = valLastY, height = valHeight, width = valWidth },
["trade"] = { hidden = false, docked = valDocked, locked = valLocked, minimized = valMinimized, lastX = valLastX, lastY = valLastY, height = valHeight, width = valWidth },
["inventory"] = { hidden = false, docked = valDocked, locked = valLocked, minimized = valMinimized, lastX = valLastX, lastY = valLastY, height = valHeight, width = valWidth },
["hud"] = { hidden = true, docked = false, locked = valLocked, minimized = valMinimized, lastX = valLastX, lastY = valLastY, height = valHeight, width = valWidth },
["alchemy"] = { hidden = false, docked = valDocked, locked = valLocked, minimized = valMinimized, lastX = valLastX, lastY = valLastY, height = valHeight, width = valWidth },
["gamepad_inventory_root"] = { hidden = false, docked = valGamepadDocked, locked = valGamepadLocked, minimized = valMinimized, lastX = valGamepadLastX, lastY = valGamepadLastY, height = valHeight, width = valWidth },
["gamepad_banking"] = { hidden = false, docked = valGamepadDocked, locked = valGamepadLocked, minimized = valMinimized, lastX = valGamepadLastX, lastY = valGamepadLastY, height = valHeight, width = valWidth },
["gamepad_store"] = { hidden = false, docked = valGamepadDocked, locked = valGamepadLocked, minimized = valMinimized, lastX = valGamepadLastX, lastY = valGamepadLastY, height = valHeight, width = valWidth },
},
defaultInventoryFrameView = IIFA_LOCATION_KEY_ALL,
}
IIfA.defaults_character = defaults_character
local defaults_assets = {
["wv"] = 0,
["gold"] = 0,
["tv"] = 0,
["spaceMax"] = 0,
["ap"] = 0,
["spaceUsed"] = 0,
}
-- Root Database Structure
local displayName = GetDisplayName()
local currentCharacterId = GetCurrentCharacterId()
local worldName = GetWorldName():gsub(" Megaserver", IIfA.EMPTY_STRING)
-- Initialize IIfA_Database
IIFA_DATABASE = IIFA_DATABASE or {}
IIFA_DATABASE[displayName] = IIFA_DATABASE[displayName] or {
settings = defaults_account, -- Account-wide settings
characters = {}, -- Character-specific settings
servers = defaults_server, -- Server-specific data
}
-- Ensure the current character has its own settings
IIFA_DATABASE[displayName].characters[currentCharacterId] = IIFA_DATABASE[displayName].characters[currentCharacterId] or defaults_character
IIFA_DATABASE[displayName].servers[worldName].assets[currentCharacterId] = IIFA_DATABASE[displayName].servers[worldName].assets[currentCharacterId] or defaults_assets
local settingsSavedVariables = IIFA_DATABASE[displayName].settings
local characterSavedVariables = IIFA_DATABASE[displayName].characters[currentCharacterId]
local serverSavedVariables = IIFA_DATABASE[displayName].servers
-- Remove keys from saved variables not in defaults
local skipRequiredMigrationData = { legacyMigrationComplete = true, newFormatMigrationCompleted = true }
IIfA:dm("Info", "Adding - Removing Vars ")
for key in pairs(settingsSavedVariables) do
if defaults_account[key] == nil and not skipRequiredMigrationData[key] then
IIfA:dm("Warn", "[<<1>>] Removed ", key)
settingsSavedVariables[key] = nil -- Remove unexpected key
end
end
for key in pairs(characterSavedVariables) do
if key ~= "frameSettings" and defaults_character[key] == nil then
IIfA:dm("Warn", "[<<1>>] Removed ", key)
characterSavedVariables[key] = nil -- Remove unexpected key
elseif key == "frameSettings" then
IIfA:dm("Debug", "Removing unused frameSettings...")
for frameKey, frameDefault in pairs(characterSavedVariables[key]) do
if defaults_character[key][frameKey] == nil then
IIfA:dm("Warn", "[<<1>>] Removed from [<<2>>]", frameKey, key)
characterSavedVariables[key][frameKey] = nil
end
end
end
end
for region, serverData in pairs(serverSavedVariables) do
if defaults_server[region] then
for key in pairs(serverData) do
if defaults_server[region][key] == nil then
IIfA:dm("Warn", "[<<1>>] Removed from [<<2>>]", key, region)
serverData[key] = nil -- Remove the entire table or scalar value
end
end
end
end
-- Add missing keys from defaults to saved variables
for key, defaultVal in pairs(defaults_account) do
if settingsSavedVariables[key] == nil then
IIfA:dm("Warn", "[<<1>>] Added ", key)
settingsSavedVariables[key] = defaultVal -- Add missing default
end
end
for key, defaultVal in pairs(defaults_character) do
characterSavedVariables[key] = characterSavedVariables[key] or {}
if key ~= "frameSettings" then
if characterSavedVariables[key] == nil then
IIfA:dm("Warn", "[<<1>>] Added ", key)
characterSavedVariables[key] = defaultVal -- Add missing default
end
elseif key == "frameSettings" then
IIfA:dm("Debug", "Adding frameSettings...")
for frameKey, frameDefault in pairs(defaults_character[key]) do
if characterSavedVariables[key][frameKey] == nil then
IIfA:dm("Warn", "[<<1>>] Added to [<<2>>]", frameKey, key)
characterSavedVariables[key][frameKey] = frameDefault -- Add missing default
end
end
end
end
for region, serverData in pairs(defaults_server) do
serverSavedVariables[region] = serverSavedVariables[region] or {}
for key, defaultVal in pairs(serverData) do
if serverSavedVariables[region][key] == nil then
IIfA:dm("Warn", "[<<1>>] Added to [<<2>>]", key, region)
serverSavedVariables[region][key] = defaultVal -- Add missing default
end
end
end
end
function IIfA:CleanupOldCharacterSettings()
IIfA:dm("Info", "[CleanupOldCharacterSettings]")
local settingsData = IIfA_Settings and IIfA_Settings["Default"] and IIfA_Settings["Default"][IIfA.currentAccount]
if not settingsData then
IIfA:dm("Debug", "Migration not possible no data found for the current account. Exiting early.")
return
end
if settingsData and settingsData[IIfA.currentCharacterId] then
-- Log the removal for debugging purposes
IIfA:dm("Debug", "[CleanupOldCharacterSettings] Removing old settings for characterId: <<1>>", IIfA.currentCharacterId)
-- Remove the old settings
settingsData[IIfA.currentCharacterId] = nil
else
-- Log that there were no old settings to remove
IIfA:dm("Debug", "[CleanupOldCharacterSettings] No old settings found for characterId: <<1>>", IIfA.currentCharacterId)
end
end
local function IsCompanionDataNonEmpty()
IIfA:dm("Debug", "IsCompanionDataNonEmpty...")
-- Safely check the presence of each level
local hasData = IIfA_Companion and IIfA_Companion["Default"] and next(IIfA_Companion["Default"])
if not hasData then return false end
-- Iterate through accounts in "Default" to check for meaningful data
for _, accountData in pairs(IIfA_Companion["Default"]) do
if accountData["$AccountWide"] and (accountData["$AccountWide"].CharNameToId or accountData["$AccountWide"].CharIdToName) then
return true -- Found companion data
end
end
return false -- No meaningful data
end
local function IsDBv3NonEmpty()
local format = DetectProfile()
local serverType = GetWorldName():gsub(" Megaserver", IIfA.EMPTY_STRING)
local worldName = GetWorldName()
local hasData, dbv3Table = false, nil
if format and format == IIFA_DEFAULT_FORMAT then
-- Check for Default Format
if IIfA_Data and IIfA_Data["Default"] and IIfA_Data["Default"][IIfA.currentAccount] and
IIfA_Data["Default"][IIfA.currentAccount]["$AccountWide"] and
IIfA_Data["Default"][IIfA.currentAccount]["$AccountWide"]["Data"] then
local accountData = IIfA_Data["Default"][IIfA.currentAccount]["$AccountWide"]["Data"]
if accountData[serverType] and accountData[serverType]["DBv3"] then
dbv3Table = accountData[serverType]["DBv3"]
hasData = true
end
end
elseif format and format == IIFA_MEGASERVER_FORMAT then
-- Check for Megaserver Format
if IIfA_Data and IIfA_Data[worldName] and IIfA_Data[worldName][IIfA.currentAccount] and
IIfA_Data[worldName][IIfA.currentAccount]["$AccountWide"] and
IIfA_Data[worldName][IIfA.currentAccount]["$AccountWide"]["Data"] then
local accountData = IIfA_Data[worldName][IIfA.currentAccount]["$AccountWide"]["Data"]
if accountData[serverType] and accountData[serverType]["DBv3"] then
dbv3Table = accountData[serverType]["DBv3"]
hasData = true
end
end
else
-- If format is unrecognized, consider DBv3 empty
IIfA:dm("Debug", "[IsDBv3NonEmpty] format is unrecognized...")
return false
end
-- Return true if DBv3 has any keys, false otherwise
return hasData and dbv3Table and next(dbv3Table) ~= nil
end
function IIfA_onLoad(eventCode, addOnName)
if (addOnName ~= "IIfA") then
return
end
IIfA:dm("Debug", "[IIfA_onLoad] Starting...")
local valDocked = true
local valLocked = false
local valMinimized = false
IIfA.minWidth = 435
IIfA.maxWidth = 500
IIfA.minHeight = 390
IIfA.maxHeight = 1400
local valLastX = IIfA.minWidth
local valLastY = 300
local valHeight = 750
local valWidth = 420
local lang = GetCVar("language.2")
IIfA.clientLanguage = lang
IIfA:CheckIfClientLanguageUsesGenderStrings(lang)
-- initializing default values
local defaults = {
saveSettingsGlobally = true,
bDebug = false,
showItemCountOnRight = true,
showItemStats = false,
b_collectHouses = false,
collectHouseData = {}, -- server specific
ignoredCharEquipment = {}, -- server specific
ignoredCharInventories = {}, -- server specific
ignoreCompanionEquipment = false, -- server specific
frameSettings = {
["bank"] = { hidden = false, docked = valDocked, locked = valLocked, minimized = valMinimized, lastX = valLastX, lastY = valLastY, height = valHeight, width = valWidth },
["guildBank"] = { hidden = false, docked = valDocked, locked = valLocked, minimized = valMinimized, lastX = valLastX, lastY = valLastY, height = valHeight, width = valWidth },
["tradinghouse"] = { hidden = false, docked = valDocked, locked = valLocked, minimized = valMinimized, lastX = valLastX, lastY = valLastY, height = valHeight, width = valWidth },
["smithing"] = { hidden = false, docked = valDocked, locked = valLocked, minimized = valMinimized, lastX = valLastX, lastY = valLastY, height = valHeight, width = valWidth },
["store"] = { hidden = false, docked = valDocked, locked = valLocked, minimized = valMinimized, lastX = valLastX, lastY = valLastY, height = valHeight, width = valWidth },
["stables"] = { hidden = false, docked = valDocked, locked = valLocked, minimized = valMinimized, lastX = valLastX, lastY = valLastY, height = valHeight, width = valWidth },
["trade"] = { hidden = false, docked = valDocked, locked = valLocked, minimized = valMinimized, lastX = valLastX, lastY = valLastY, height = valHeight, width = valWidth },
["inventory"] = { hidden = false, docked = valDocked, locked = valLocked, minimized = valMinimized, lastX = valLastX, lastY = valLastY, height = valHeight, width = valWidth },
["hud"] = { hidden = true, docked = false, locked = valLocked, minimized = valMinimized, lastX = valLastX, lastY = valLastY, height = valHeight, width = valWidth },
["alchemy"] = { hidden = false, docked = valDocked, locked = valLocked, minimized = valMinimized, lastX = valLastX, lastY = valLastY, height = valHeight, width = valWidth }
},
BagSpaceWarn = {
["threshold"] = 85,
["r"] = 230 / 255,
["g"] = 130 / 255,
["b"] = 0,
},
BagSpaceAlert = {
["threshold"] = 95,
["r"] = 1,
["g"] = 1,
["b"] = 0,
},
BagSpaceFull = {
["r"] = 255,
["g"] = 0,
["b"] = 0,
},
bCollectGuildBankData = false, -- server specific
in2DefaultInventoryFrameView = GetString(IIFA_LOCATION_NAME_ALL),
in2AgedGuildBankDataWarning = true,
in2TooltipsFont = "ZoFontGame",
TooltipFontFace = "ProseAntique",
TooltipFontSize = 18,
TooltipFontEffect = "Normal",
showToolTipWhen = "Always",
DBv3 = {},
dontFocusSearch = false,
bAddContextMenuEntrySearchInIIfA = true,
bInSeparateFrame = true,
showStyleInfo = true,
bFilterOnSetNameToo = false,
bFilterOnSetName = false,
hideCloseButton = false,
FCOISshowMarkerIcons = false,
-- Added for reference
lastLang = GetCVar("language.2"),
houseChestSpace = {}, -- server specific
NA = {
["DBv3"] = {},
},
["NA-guildBanks"] = { },
EU = {
["DBv3"] = {},
},
["EU-guildBanks"] = { },
assets = {}, -- server specific
legacyMigrationComplete = false,
}
local defaultsCompanion = { -- server specific
CharIdToName = { }, -- num, name
CharNameToId = { }, -- name, num
}
-- prevent resizing by user to be larger than this
IIFA_GUI:SetDimensionConstraints(IIfA.minWidth, IIfA.minHeight, IIfA.maxWidth, IIfA.maxHeight)
-- Grab a couple static values that shouldn't change while it's running
IIfA.HeaderHeight = IIFA_GUI_Header:GetHeight()
IIfA.SearchHeight = IIFA_GUI_Search:GetHeight()
IIFA_GUI_ListHolder.rowHeight = 52 -- trying to find optimal size for this, set it in one spot for easier adjusting
IIFA_GUI_ListHolder:SetDrawLayer(DL_BACKGROUND) -- keep the scrollable dropdown ABOVE this one
-- (otherwise scrollable dropdown is shown like it's above the list, but the mouse events end up going through to the list)
IIfA.currentCompanionId = IIfA:GetCurrentCompanionHashId() -- assign here to prevent errors in Init.lua
IIfA.filterGroup = GetString(IIFA_LOCATION_NAME_ALL)
IIfA.filterTypes = nil
-- grabs data from backpack, and worn items when we first open the inventory
-- ZO_PreHook(PLAYER_INVENTORY, "ApplyBackpackLayout", IIfA.OnFirstInventoryOpen)
ZO_PreHook(BACKPACK_GUILD_BANK_LAYOUT_FRAGMENT, "ApplyBackpackLayout", IIfA.CollectGuildBank)
-- ZO_PreHook(SHARED_INVENTORY, "GetOrCreateBagCache", function(self, bagId)
-- d("SHARED_INVENTORY: GetOrCreateBagCache: " .. tostring(bagId))
-- end)
-- ZO_PreHook(SHARED_INVENTORY, "PerformFullUpdateOnBagCache", function(self, bagId)
-- d("SHARED_INVENTORY: PerformFullUpdateOnBagCache: " .. tostring(bagId))
-- end)
-- http://esodata.uesp.net/100016/src/libraries/utility/zo_savedvars.lua.html#67
--[[We use the same default values is because function IIfA:GetSettings()
will return either IIfA.settings or IIfA.data. Some places will reference
IIfA.settings or IIfA.data directly which IIfA.data is intended to be global. However,
how are you going to allocate different values to both when someone may toggle
the settings so that they are not AccountWide. When that happens will the settings
have a nil value?
Also this seems problamatic because once you change from account wide to
character specific, there is no copy routine and some code will still reference IIfA.data
directly.
]]--
IIfA:InitializeDatabase()
if IsCompanionDataNonEmpty() then
IIfA.companion = ZO_SavedVars:NewAccountWide("IIfA_Companion", 1, nil, defaultsCompanion)
IIfA:ConvertCompanionToServerFormat()
else
IIfA:dm("Debug", "IIfA_Companion does not exist or was already cleared.")
end
if IsDBv3NonEmpty() then
IIfA.settings = ZO_SavedVars:NewCharacterIdSettings("IIfA_Settings", 1, nil, defaults)
if DetectProfile() == IIFA_DEFAULT_FORMAT then
IIfA.data = ZO_SavedVars:NewAccountWide("IIfA_Data", 1, "Data", defaults)
elseif DetectProfile() == IIFA_MEGASERVER_FORMAT then
IIfA.data = ZO_SavedVars:NewAccountWide("IIfA_Data", 1, "Data", defaults, GetWorldName())
end
IIfA:MigrateLegacyValues()
IIfA:MigrateToAccountAndServerSpecificFormat()
else
IIfA:dm("Debug", "[IsDBv3NonEmpty] Failed because of invalid or insufficient data.")
end
IIfA:MigrateFrameSettings()
IIfA:CleanupOldCharacterSettings()
--[[
SecurePostHook(ZO_SharedInventoryManager, "CreateOrUpdateSlotData", function(sharedInventoryPointer, existingSlotData, bagId, slotIndex, isNewItem)
local itemLink = GetItemLink(bagId, slotIndex, LINK_STYLE_BRACKETS)
if itemLink then
IIfA:dm("Debug", "[CreateOrUpdateSlotData] : <<1>>, <<2>> : <<3>>", bagId, slotIndex, GetItemLink(bagId, slotIndex, LINK_STYLE_BRACKETS))
end
end)
]]--
IIfA:CreateFontStyleChoices()
IIfA:SetTooltipFont()
IIfA:CreateTooltips()
IIfA:RebuildHouseMenuDropdowns()
IIfA:SetupCharLookups()
IIfA:SetupGuildBanks()
IIfA:SetupTextColorHandlers()
-- Convert saved data names into the proper language for this session if needed
if IIFA_DATABASE[IIfA.currentAccount].settings.lastLang ~= lang then
IIfA:RenameItems()
IIFA_DATABASE[IIfA.currentAccount].settings.lastLang = lang
end
IIFA_GUI_Header_Filter_Button0:SetState(BSTATE_PRESSED)
IIfA.LastFilterControl = IIFA_GUI_Header_Filter_Button0
IIfA.GUI_SearchBox = IIFA_GUI_SearchBackdropBox
SLASH_COMMANDS["/ii"] = IIfA_SlashCommands
-- IIfA:CreateSettingsWindow(IIfA.settings, default)
IIFA_GUI_ListHolder_Counts:SetHidden(not IIFA_DATABASE[IIfA.currentAccount].settings.showItemStats)
IIfA.CharCurrencyFrame:Initialize()
IIfA.CharBagFrame:Initialize()
IIfA:SetupBackpack() -- setup the inventory frame
if not IIFA_DATABASE[IIfA.currentAccount].characters[IIfA.currentCharacterId].frameSettings.hud.hidden then
IIfA:ProcessSceneChange("hud", "showing", "shown")
end
IIFA_GUI_Header_Hide:SetHidden(IIFA_DATABASE[IIfA.currentAccount].settings.hideCloseButton)
IIfA:RegisterForEvents()