|
|
|
|
local _, S = ...
|
|
|
|
|
local pairs, ipairs, string, type, time = pairs, ipairs, string, type, time
|
|
|
|
|
|
|
|
|
|
local GetContainerItemInfo = GetContainerItemInfo
|
|
|
|
|
local useNewContainerInfo
|
|
|
|
|
if C_Container then
|
|
|
|
|
if C_Container.GetContainerItemInfo then
|
|
|
|
|
GetContainerItemInfo = C_Container.GetContainerItemInfo
|
|
|
|
|
useNewContainerInfo = true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Slash command
|
|
|
|
|
SLASH_SORTED1 = "/sorted"
|
|
|
|
|
SlashCmdList.SORTED = function(msg)
|
|
|
|
|
S.settingsFrame:Show()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- EVENT HANDLING
|
|
|
|
|
local eventHandlerFrame = CreateFrame("FRAME")
|
|
|
|
|
eventHandlerFrame:RegisterEvent("BANKFRAME_OPENED")
|
|
|
|
|
eventHandlerFrame:RegisterEvent("BANKFRAME_CLOSED")
|
|
|
|
|
eventHandlerFrame:SetScript("OnEvent", function(self, event, param1, param2, param3)
|
|
|
|
|
if event == "BANKFRAME_OPENED" then
|
|
|
|
|
S.OpenBag()
|
|
|
|
|
elseif event == "BANKFRAME_CLOSED" then
|
|
|
|
|
S.CloseBag()
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- BAG OPENING / CLOSING
|
|
|
|
|
local enabled = true
|
|
|
|
|
function S.Enable()
|
|
|
|
|
enabled = true
|
|
|
|
|
end
|
|
|
|
|
function S.Disable()
|
|
|
|
|
enabled = false
|
|
|
|
|
end
|
|
|
|
|
local lastToggledTime = 0
|
|
|
|
|
local lastShownTime = 0
|
|
|
|
|
local lastHiddenTime = 0
|
|
|
|
|
local TOGGLE_TIMEOUT = 0.01
|
|
|
|
|
|
|
|
|
|
local newItemsToRemove = {}
|
|
|
|
|
function S.ScheduleNewItemToRemove(bag, slot)
|
|
|
|
|
if not newItemsToRemove[bag] then
|
|
|
|
|
newItemsToRemove[bag] = {}
|
|
|
|
|
end
|
|
|
|
|
if useNewContainerInfo then
|
|
|
|
|
local t = GetContainerItemInfo(bag, slot)
|
|
|
|
|
if t then
|
|
|
|
|
newItemsToRemove[bag][slot] = t.hyperlink
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
_, _, _, _, _, _,
|
|
|
|
|
newItemsToRemove[bag][slot], _, _, _ = GetContainerItemInfo(bag, slot)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
-- Function naming at its best
|
|
|
|
|
function S.IsItemScheduledToBeNotNew(bag, slot)
|
|
|
|
|
if not newItemsToRemove[bag] then
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
if useNewContainerAPI then
|
|
|
|
|
local t = GetContainerItemInfo(bag, slot)
|
|
|
|
|
if t then
|
|
|
|
|
return newItemsToRemove[bag][slot] == t.hyperlink
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
local _, _, _, _, _, _,
|
|
|
|
|
link, _, _, _ = GetContainerItemInfo(bag, slot)
|
|
|
|
|
return newItemsToRemove[bag][slot] == link
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
S.primaryFrame:SetScript("OnShow", function(self)
|
|
|
|
|
S.Utils.TriggerEvent("PrimaryFrameOpened")
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
S.primaryFrame:SetScript("OnHide", function(self)
|
|
|
|
|
-- Remove new items that have been hovered over
|
|
|
|
|
local removedANewItem = false
|
|
|
|
|
for bag, v in pairs(newItemsToRemove) do
|
|
|
|
|
for slot, link1 in pairs(v) do
|
|
|
|
|
local link2
|
|
|
|
|
if C_NewItems.IsNewItem(bag, slot) then
|
|
|
|
|
if useNewContainerInfo then
|
|
|
|
|
local t = GetContainerItemInfo(bag, slot)
|
|
|
|
|
if t then
|
|
|
|
|
link2 = t.hyperlink
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
_, _, _, _, _, _,
|
|
|
|
|
link2, _, _, _ = GetContainerItemInfo(bag, slot)
|
|
|
|
|
end
|
|
|
|
|
if link1 == link2 then
|
|
|
|
|
C_NewItems.RemoveNewItem(bag, slot)
|
|
|
|
|
removedANewItem = true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if removedANewItem then
|
|
|
|
|
S.Utils.TriggerEvent("NewItemsChanged")
|
|
|
|
|
end
|
|
|
|
|
newItemsToRemove = {}
|
|
|
|
|
|
|
|
|
|
if C_Bank then
|
|
|
|
|
C_Bank.CloseBankFrame()
|
|
|
|
|
else
|
|
|
|
|
CloseBankFrame()
|
|
|
|
|
end
|
|
|
|
|
C_PlayerInteractionManager.ClearInteraction()
|
|
|
|
|
|
|
|
|
|
S.Utils.TriggerEvent("PrimaryFrameClosed")
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
function S.OpenBag(bag)
|
|
|
|
|
if enabled then
|
|
|
|
|
if (force or lastToggledTime < GetTime() - TOGGLE_TIMEOUT) and not S.primaryFrame:IsShown() then
|
|
|
|
|
-- Make player select a settings profile before using Sorted.
|
|
|
|
|
if not S.Settings.HasProfile() then
|
|
|
|
|
S.settingsProfilesFrame:Show()
|
|
|
|
|
S.settingsProfilesFrame.source = "bags"
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
PlaySound(SOUNDKIT.IG_BACKPACK_OPEN)
|
|
|
|
|
|
|
|
|
|
--local startTime = debugprofilestop()
|
|
|
|
|
|
|
|
|
|
S.primaryFrame:Show()
|
|
|
|
|
|
|
|
|
|
--print(debugprofilestop() - startTime)
|
|
|
|
|
|
|
|
|
|
lastToggledTime = GetTime()
|
|
|
|
|
lastShownTime = GetTime()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
--[[if bag == KEYRING_CONTAINER then
|
|
|
|
|
_G["SortedBag-2Frame"]:Show()
|
|
|
|
|
end]]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
function S.CloseBag(bag)
|
|
|
|
|
if (force or lastToggledTime < GetTime() - TOGGLE_TIMEOUT) and S.primaryFrame:IsShown() then
|
|
|
|
|
PlaySound(SOUNDKIT.IG_BACKPACK_CLOSE)
|
|
|
|
|
S.primaryFrame:Hide()
|
|
|
|
|
lastToggledTime = GetTime()
|
|
|
|
|
lastHiddenTime = GetTime()
|
|
|
|
|
|
|
|
|
|
--[[for k,v in pairs(S.bagFrames) do
|
|
|
|
|
v:Hide()
|
|
|
|
|
end]]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
function S.ToggleBag(bag)
|
|
|
|
|
if S.primaryFrame:IsShown() then
|
|
|
|
|
S.CloseBag(bag)
|
|
|
|
|
else
|
|
|
|
|
S.OpenBag(bag)
|
|
|
|
|
if S.WoWVersion() == 1 and bag == KEYRING_CONTAINER then
|
|
|
|
|
S.primaryFrame.SelectSideTab(1, true)
|
|
|
|
|
elseif S.WoWVersion() <= 3 and bag == KEYRING_CONTAINER then
|
|
|
|
|
S.primaryFrame.SelectSideTab(3, true)
|
|
|
|
|
else
|
|
|
|
|
S.primaryFrame.SelectSideTab(nil)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
hooksecurefunc('OpenBackpack', S.ToggleBag)
|
|
|
|
|
hooksecurefunc('CloseBackpack', S.CloseBag)
|
|
|
|
|
hooksecurefunc('ToggleBackpack', S.ToggleBag)
|
|
|
|
|
hooksecurefunc('OpenBag', S.ToggleBag)
|
|
|
|
|
hooksecurefunc('ToggleBag', S.ToggleBag)
|