diff --git a/LibSort-1.0/LibSort-1.0.lua b/LibSort-1.0/LibSort-1.0.lua
index 0dc8bef..9fdeede 100644
--- a/LibSort-1.0/LibSort-1.0.lua
+++ b/LibSort-1.0/LibSort-1.0.lua
@@ -2,11 +2,6 @@ local MAJOR, MINOR = "LibSort-1.0", 3
local LibSort, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
if not LibSort then return end --the same or newer version of this lib is already loaded into memory
---- Storage variables ---
-LibSort.RegisteredCallbacks = {}
-LibSort.AddonOrder = {}
-LibSort.DefaultOrdersLow = {}
-LibSort.DefaultOrdersHigh = {}
LibSort.sortKeys = ZO_Inventory_GetDefaultHeaderSortKeys()
-- Lookup Tables ---
@@ -29,11 +24,13 @@ local function makePrefix(name)
end
function LibSort:Debug(msg)
- if LibSort.isDebugging then d("[LibSort]: "..msg) end
+ if LibSort.isDebugging then
+ d("[LibSort]: "..msg)
+ end
end
--- Arrow generation ---
-function LibSort:SetupArrows()
+function LibSort:SetupArrows()
LibSort.ItemSortBank = WINDOW_MANAGER:CreateControlFromVirtual("ItemSortBank", ZO_PlayerBankSortBy, "ZO_SortHeaderIcon")
LibSort.ItemSortBank:SetDimensions(16, 32)
LibSort.ItemSortBank:SetAnchor(RIGHT, ZO_PlayerBankSortByName, LEFT, -15)
@@ -48,11 +45,11 @@ function LibSort:SetupArrows()
ZO_SortHeader_SetTooltip(LibSort.ItemSortGuild, "Sort", BOTTOMRIGHT, 0, 32)
ZO_SortHeader_InitializeArrowHeader(LibSort.ItemSortGuild, "age", ZO_SORT_ORDER_DOWN)
- PLAYER_INVENTORY.inventories[INVENTORY_GUILD_BANK].sortHeaders:AddHeader(ItemSortGuild)
+ PLAYER_INVENTORY.inventories[INVENTORY_GUILD_BANK].sortHeaders:AddHeader(ItemSortGuild)
end
--- Main functions ---
-function LibSort:InjectKeys()
+function LibSort:InjectKeys()
for addon, callbacks in pairs(self.RegisteredCallbacks) do
for name, data in pairs(callbacks) do
if not self.sortKeys[data.key] then
@@ -61,7 +58,7 @@ function LibSort:InjectKeys()
end
end
end
- self:ReOrderKeys()
+ self:ReOrderKeys()
end
function LibSort:ReOrderKeys()
@@ -106,7 +103,7 @@ function LibSort:SetKeyOrder(first, previous, data)
return first, data.key
end
-function LibSort:ProcessInventory(inventoryType)
+function LibSort:ProcessInventory(inventoryType)
local container = inventoryTypes[inventoryType]
if not container then return end
for i, slot in ipairs(container.data) do
@@ -118,22 +115,11 @@ function LibSort:ProcessInventory(inventoryType)
end
end
end
- end
-end
-
-function LibSort:Loaded(event, name)
- if name ~= "ZO_Ingame" then return end
-
- self.savedVars = ZO_SavedVars:New("ZO_Ingame_SavedVariables", 1, "LibSort")
-
- ZO_PreHook(PLAYER_INVENTORY, "ApplySort", function(self, inventoryType) LibSort:ProcessInventory(inventoryType) end)
- zo_callLater(function() self:SetupArrows() end, 3000)
-
- EVENT_MANAGER:UnregisterForEvent("LibSortLoaded", EVENT_ADD_ON_LOADED)
+ end
end
-EVENT_MANAGER:RegisterForEvent("LibSortLoaded", EVENT_ADD_ON_LOADED, function(...) LibSort:Loaded(...) end)
-
+ZO_PreHook(PLAYER_INVENTORY, "ApplySort", function(self, inventoryType) LibSort:ProcessInventory(inventoryType) end)
+LibSort:SetupArrows()
--------- API ---------
function LibSort:Unregister(addonName, name)
@@ -149,11 +135,23 @@ function LibSort:Unregister(addonName, name)
end
end
-function LibSort:Register(addonName, name, desc, key, func, dataType)
+function LibSort:Register(addonName, name, desc, key, func, dataType)
if not dataType then dataType = "isNumeric" end
- if not self.RegisteredCallbacks[addonName] then self.RegisteredCallbacks[addonName] = {} table.insert(self.AddonOrder, addonName) end
+
+ if not self.RegisteredCallbacks then self.RegisteredCallbacks = {} end
+ if not self.AddonOrder then self.AddonOrder = {} end
+ if not self.DefaultOrdersHigh then self.DefaultOrdersHigh = {} end
+ if not self.DefaultOrdersLow then self.DefaultOrdersLow = {} end
+
+ if not self.RegisteredCallbacks[addonName] then
+ self.RegisteredCallbacks[addonName] = {}
+ table.insert(self.AddonOrder, addonName)
+ end
+
self.RegisteredCallbacks[addonName][name] = {key = makePrefix(addonName)..key, func = func, desc = desc, dataType = dataType}
+
if not self.DefaultOrdersHigh[addonName] then self.DefaultOrdersHigh[addonName] = {} end
+
table.insert(self.DefaultOrdersHigh[addonName], name)
self:InjectKeys()
end
@@ -175,7 +173,3 @@ function LibSort:RegisterDefaultOrder(addonName, keyTableLow, keyTableHigh)
self.DefaultOrdersLow[addonName] = keyTableLow
self:ReOrderKeys()
end
-
-function LibSort:SetDebugging(flag)
- self.isDebugging = flag
-end
\ No newline at end of file