Verified Commit a93841c3 authored by Repooc's avatar Repooc

redo the equipment set indicator

parent 090caac8
local SLE, _, E = unpack(select(2, ...))
local SLE, T, E = unpack(select(2, ...))
local BI = SLE:NewModule('BagInfo', 'AceHook-3.0', 'AceEvent-3.0')
local B = E:GetModule('Bags')
local _G = _G
local GetContainerNumSlots = GetContainerNumSlots
local CUSTOM = CUSTOM
local EQUIPMENT_SETS = EQUIPMENT_SETS
EQUIPMENT_SETS = E:StripString(EQUIPMENT_SETS)
EQUIPMENT_SETS = EQUIPMENT_SETS:gsub('%%s', '')
EQUIPMENT_SETS = E:EscapeString(EQUIPMENT_SETS)
-- local EQUIPMENT_SETS = EQUIPMENT_SETS
-- EQUIPMENT_SETS = E:StripString(EQUIPMENT_SETS)
-- EQUIPMENT_SETS = EQUIPMENT_SETS:gsub('%%s', '')
-- EQUIPMENT_SETS = E:EscapeString(EQUIPMENT_SETS)
local MAX_CONTAINER_ITEMS = 36
local REAGENTBANK_CONTAINER = REAGENTBANK_CONTAINER
local NUM_BANKGENERIC_SLOTS = NUM_BANKGENERIC_SLOTS
local GetContainerItemEquipmentSetInfo = GetContainerItemEquipmentSetInfo
local C_EquipmentSet_GetEquipmentSetIDs = C_EquipmentSet.GetEquipmentSetIDs
local C_EquipmentSet_GetEquipmentSetInfo = C_EquipmentSet.GetEquipmentSetInfo
--* Used this to help translate known texcoords to a |T |t string
-- CreateTextureMarkup('Interface\\PaperDollInfoFrame\\PaperDollSidebarTabs', 64, 256, 0, 0, 0.01562500, 0.53125000, 0.46875000, 0.60546875, 0, 0)
-- CreateTextureMarkup(file, fileWidth, fileHeight, width, height, left, right, top, bottom, xOffset, yOffset)
......@@ -31,11 +39,22 @@ BI.equipmentmanager = {
},
}
local function SetupBags()
for _, bagFrame in pairs(B.BagFrames) do
for _, bagID in ipairs(bagFrame.BagIDs) do
for slotID = 1, GetContainerNumSlots(bagID) do
local button = bagFrame.Bags[bagID][slotID]
BI.currentSets = {
-- ['1'] = { --setID
-- name = 'some set',
-- iconFileID = 123456,
-- isEquipped = false,
-- numItems = 1,
-- numEquipped = false,
-- numInInventory = 1,
-- },
}
local function ConstructBagIcons()
for _, f in pairs(B.BagFrames) do
for _, bagID in next, f.BagIDs do
for slotID = 1, MAX_CONTAINER_ITEMS do
local button = f.Bags[bagID][slotID]
if not button.equipIcon then
button.equipIcon = button:CreateTexture(nil, 'OVERLAY')
......@@ -46,132 +65,158 @@ local function SetupBags()
end
end
function BI:UpdateEquipment()
for _, bagFrame in pairs(B.BagFrames) do
for _, bagID in ipairs(bagFrame.BagIDs) do
for slotID = 1, GetContainerNumSlots(bagID) do
local button = bagFrame.Bags[bagID][slotID]
if not button.equipIcon then
SetupBags()
BI:UpdateSettings()
end
button.equipIcon:SetShown(BI:CheckVisibility(bagFrame, bagID, slotID))
function BI:UpdateAllBagSlots()
for _, f in pairs(B.BagFrames) do
for _, bagID in next, f.BagIDs do
for slotID = 1, MAX_CONTAINER_ITEMS do
BI:UpdateSlot(f, bagID, slotID)
end
end
end
end
-- function BI:CheckVisibility(bagFrame, bagID, slotID)
-- if not bagFrame or not bagID or not slotID then return end
-- local button = bagFrame.Bags[bagID][slotID]
-- local show = false
-- E.ScanTooltip:SetOwner(_G.UIParent, 'ANCHOR_NONE')
-- if button.GetInventorySlot then -- this fixes bank bagid -1
-- E.ScanTooltip:SetInventoryItem('player', button:GetInventorySlot())
-- else
-- E.ScanTooltip:SetBagItem(bagID, slotID)
-- end
-- E.ScanTooltip:Show()
-- for i = 3, E.ScanTooltip:NumLines() do
-- local str = _G['ElvUI_ScanTooltipTextLeft' .. i]
-- local text = str and str:GetText()
-- if not text or text == '' then return end
-- if text:find(EQUIPMENT_SETS:gsub('%%s','.-')) then
-- show = true
-- end
-- end
-- E.ScanTooltip:Hide()
-- return E.db.sle.bags.equipmentmanager.enable and show
-- end
function BI:CheckVisibility(bagFrame, bagID, slotID)
if not bagFrame or not bagID or not slotID then return end
local button = bagFrame.Bags[bagID][slotID]
local show = false
E.ScanTooltip:SetOwner(_G.UIParent, 'ANCHOR_NONE')
if button.GetInventorySlot then -- this fixes bank bagid -1
E.ScanTooltip:SetInventoryItem('player', button:GetInventorySlot())
else
E.ScanTooltip:SetBagItem(bagID, slotID)
end
E.ScanTooltip:Show()
for i = 3, E.ScanTooltip:NumLines() do
local str = _G['ElvUI_ScanTooltipTextLeft' .. i]
local text = str and str:GetText()
if not text or text == '' then return end
if text:find(EQUIPMENT_SETS) then
show = true
function BI:UpdateBagSlots(frame, bagID)
if bagID ~= REAGENTBANK_CONTAINER then
for slotID = 1, GetContainerNumSlots(bagID) do
-- print('yo')
BI:UpdateSlot(frame, bagID, slotID)
end
end
E.ScanTooltip:Hide()
return E.db.sle.bags.equipmentmanager.enable and show
end
function BI:ToggleSettings()
if E.db.sle.bags.equipmentmanager.enable then
BI:RegisterEvent('EQUIPMENT_SETS_CHANGED', BI.UpdateEquipment)
BI:RegisterEvent('BAG_UPDATE', BI.UpdateEquipment)
BI:RegisterEvent('PLAYERBANKSLOTS_CHANGED', BI.UpdateEquipment)
else
BI:UnregisterEvent('EQUIPMENT_SETS_CHANGED')
BI:UnregisterEvent('BAG_UPDATE')
BI:UnregisterEvent('PLAYERBANKSLOTS_CHANGED')
function BI:UpdateSlot(f, bagID, slotID)
if not f.Bags[bagID] or not f.Bags[bagID][slotID] then
return
end
BI:UpdateEquipment()
local button = f.Bags[bagID][slotID]
-- local link = GetContainerItemLink(bagID, slotID)
if not button then return end
if not button.equipIcon then ConstructBagIcons() end
local isInSet, setName = GetContainerItemEquipmentSetInfo(bagID, slotID)
button.equipIcon:SetShown(BI.db.enable and isInSet)
end
function BI:UpdateSettings()
local db = E.db.sle.bags.equipmentmanager
local texture = db.icon
function BI:UpdateBagSettings()
for _, f in pairs(B.BagFrames) do
for _, bagID in next, f.BagIDs do
for slotID = 1, MAX_CONTAINER_ITEMS do
local button = f.Bags[bagID][slotID]
if not button.equipIcon then return end
for _, bagFrame in pairs(B.BagFrames) do
for _, bagID in ipairs(bagFrame.BagIDs) do
for slotID = 1, GetContainerNumSlots(bagID) do
local button = bagFrame.Bags[bagID][slotID]
button.equipIcon:SetSize(db.size, db.size)
button.equipIcon:SetSize(BI.db.size, BI.db.size)
button.equipIcon:ClearAllPoints()
button.equipIcon:Point(db.point, db.xOffset, db.yOffset)
button.equipIcon:Point(BI.db.point, BI.db.xOffset, BI.db.yOffset)
if texture == 'EQUIPMGR' then
if BI.db.icon == 'EQUIPMGR' then
button.equipIcon:SetTexture('Interface\\PaperDollInfoFrame\\PaperDollSidebarTabs')
button.equipIcon:SetTexCoord(0.01562500, 0.53125000, 0.46875000, 0.60546875)
elseif texture == 'CUSTOM' then
button.equipIcon:SetTexture(db.customTexture)
elseif BI.db.icon == 'CUSTOM' then
button.equipIcon:SetTexture(BI.db.customTexture)
button.equipIcon:SetTexCoord(0, 0, 0, 1, 1, 0, 1, 1)
else
-- button.equipIcon:SetTexture(3547163)
button.equipIcon:SetTexture(BI.equipmentmanager.iconLocations[texture] or texture)
button.equipIcon:SetTexture(BI.equipmentmanager.iconLocations[BI.db.icon] or BI.db.icon)
button.equipIcon:SetTexCoord(0, 0, 0, 1, 1, 0, 1, 1)
end
-- button.equipIcon:SetVertexColor(1, .82, 0, 1)
button.equipIcon:SetVertexColor(db.color.r, db.color.g, db.color.b, db.color.a)
button.equipIcon:SetVertexColor(BI.db.color.r, BI.db.color.g, BI.db.color.b, BI.db.color.a)
end
end
end
end
function BI:OnEventHook(frame, event, ...)
if event == 'ITEM_LOCK_CHANGED' then
BI:UpdateSlot(frame, ...)
elseif event == 'BAG_UPDATE' then
BI:UpdateBagSlots(frame, ...)
elseif event == 'PLAYERBANKSLOTS_CHANGED' then
local slot = ...
local bagID = (slot <= NUM_BANKGENERIC_SLOTS) and -1 or (slot - NUM_BANKGENERIC_SLOTS)
if bagID == -1 then
BI:UpdateBagSlots(frame, -1)
end
elseif event == 'EQUIPMENT_SETS_CHANGED' then
BI:UpdateAllBagSlots()
elseif event == 'BAG_UPDATE_DELAYED' and (ElvUI_BankContainerFrame:IsShown() or ElvUI_ContainerFrame:IsShown()) then
BI:UpdateAllBagSlots()
end
end
hooksecurefunc(B, 'OnEvent', function(frame, event, ...)
if not BI.db.enable then return end
BI:OnEventHook(frame, event, ...)
end)
function BI:PLAYER_ENTERING_WORLD(initLogin)
if not initLogin then return end
local setIDs = C_EquipmentSet_GetEquipmentSetIDs()
for id in next, setIDs do
local name, iconFileID, setID, isEquipped, numItems, numEquipped, numInInventory, numLost, numIgnored = C_EquipmentSet_GetEquipmentSetInfo(id)
BI.currentSets[id] = { -- ['1'] = { --setID
name = name,
iconFileID = iconFileID,
setID = setID,
isEquipped = isEquipped,
numItems = numItems,
numEquipped = numEquipped,
numInInventory = numInInventory,
numLost = numLost,
numIgnored = numIgnored,
}
end
end
function BI:ToggleSettings()
if BI.db.enable then
BI:RegisterEvent('EQUIPMENT_SETS_CHANGED', function(event)
BI:OnEventHook(nil, event)
end)
BI:RegisterEvent('BAG_UPDATE_DELAYED', function(event)
BI:OnEventHook(nil, event)
end)
else
BI:UnregisterEvent('EQUIPMENT_SETS_CHANGED')
BI:UnregisterEvent('BAG_UPDATE_DELAYED')
end
BI:UpdateAllBagSlots()
end
function BI:Initialize()
if not SLE.initialized or not E.private.bags.enable then return end
BI.db = E.db.sle.bags.equipmentmanager
--* May need to add these, just a note to check these if any weird reports of shit not updating as expected
-- EQUIPMENT_SWAP_FINISHED
-- PLAYER_EQUIPMENT_CHANGED
SetupBags()
BI:UpdateSettings()
BI:ToggleSettings()
hooksecurefunc(B, 'OpenBank', function()
SetupBags()
BI:UpdateSettings()
ConstructBagIcons()
function BI:ForUpdateAll()
BI.db = E.db.sle.bags.equipmentmanager
BI:UpdateBagSettings()
BI:ToggleSettings()
end
BI:ForUpdateAll()
BI.bankFirstOpen = false
BI:RegisterEvent('BANKFRAME_OPENED', function()
-- Update all bag slots on initial bank open so the bank has the icons on them
if not BI.bankFirstOpen or not BI.db.enable then
BI.bankFirstOpen = true
BI:UpdateAllBagSlots()
end
end)
end
SLE:RegisterModule(BI:GetName())
......@@ -15,7 +15,7 @@ local function configTable()
name = L["Equipment Manager"],
guiInline = true,
get = function(info) return E.db.sle.bags.equipmentmanager[info[#info]] end,
set = function(info, value) E.db.sle.bags.equipmentmanager[info[#info]] = value; BI:UpdateSettings() end,
set = function(info, value) E.db.sle.bags.equipmentmanager[info[#info]] = value; BI:UpdateBagSettings() end,
args = {
enable = {
order = 1,
......@@ -75,7 +75,7 @@ local function configTable()
set = function(info, r, g, b, a)
local t = E.db.sle.bags.equipmentmanager[info[#info]]
t.r, t.g, t.b, t.a = r, g, b, a
BI:UpdateSettings()
BI:UpdateBagSettings()
end,
},
},
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment