Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Old version of the glove swap AddOn.
- -- Get localized name for Herbalism and Mining for tooltip scanning
- local LOCALIZED_HERBALISM = GetSpellInfo(184251)
- local LOCALIZED_MINING = GetSpellInfo(32606)
- local NUM_BAG_SLOTS = NUM_BAG_SLOTS
- local select = select
- local tonumber = tonumber
- local GetContainerNumSlots = GetContainerNumSlots
- local GetContainerItemLink = GetContainerItemLink
- local PickupContainerItem = PickupContainerItem
- local AutoEquipCursorItem = AutoEquipCursorItem
- local InCombatLockdown = InCombatLockdown
- local GetMouseFocus = GetMouseFocus
- local UnitCastingInfo = UnitCastingInfo
- local GameTooltip = GameTooltip
- local GameTooltipTextLeft2 = GameTooltipTextLeft2
- -- Create a frame to handle events
- local f = CreateFrame("Frame")
- f:SetScript("OnEvent", function(self, event, ...)
- if self[event] then
- self[event](...)
- end
- end)
- local enchantIDs = {
- 5444, --Herbalism
- 5445, --Mining
- 5446, --Skinning
- }
- local lastGloves = {}
- local gatheringGlovesEquipped = false
- -- Scan bags for gathering gloves with the right enchant
- -- For the profession argument:
- -- 1 = Herbalism
- -- 2 = Mining
- local function ScanForGloves(profession)
- for containerID = 0, NUM_BAG_SLOTS do
- for slotID = 1, GetContainerNumSlots(containerID) do
- local itemLink = GetContainerItemLink(containerID, slotID)
- if itemLink then
- local itemString = itemLink:match("|H(.*)|h")
- local enchantID = select(3, string.split(":", itemString))
- enchantID = tonumber(enchantID)
- if enchantID == enchantIDs[profession] then
- PickupContainerItem(containerID, slotID)
- AutoEquipCursorItem()
- if not gatheringGlovesEquipped and not f["UNIT_INVENTORY_CHANGED"] then
- f:RegisterEvent("UNIT_INVENTORY_CHANGED")
- f["UNIT_INVENTORY_CHANGED"] = function()
- lastGloves.containerID = containerID
- lastGloves.slotID = slotID
- gatheringGlovesEquipped = true
- f["UNIT_INVENTORY_CHANGED"] = nil
- f:UnregisterEvent("UNIT_INVENTORY_CHANGED")
- end
- end
- end
- end
- end
- end
- end
- local function EquipStandardGloves()
- -- Don't try to equip the normal gloves, if player is in combat or there's an earlier glove change pending
- if gatheringGlovesEquipped and not InCombatLockdown() and not f["UNIT_INVENTORY_CHANGED"] then
- if not UnitCastingInfo("player") then
- PickupContainerItem(lastGloves.containerID, lastGloves.slotID)
- AutoEquipCursorItem()
- f:RegisterEvent("UNIT_INVENTORY_CHANGED")
- f["UNIT_INVENTORY_CHANGED"] = function()
- gatheringGlovesEquipped = false
- f["UNIT_INVENTORY_CHANGED"] = nil
- f:UnregisterEvent("UNIT_INVENTORY_CHANGED")
- end
- else
- -- If the user is casting, wait for the cast to stop before trying to re-equip the gloves
- f:RegisterEvent("UNIT_SPELLCAST_STOP")
- end
- end
- end
- f["UNIT_SPELLCAST_STOP"] = function(unitID)
- if unitID ~= "player" then return end
- f:UnregisterEvent("UNIT_SPELLCAST_STOP")
- EquipStandardGloves()
- end
- local function ScanTooltip()
- if InCombatLockdown() or GameTooltip:NumLines() == 0 then return end
- if GetMouseFocus():GetName() ~= "WorldFrame" then EquipStandardGloves(); return end
- local text = GameTooltipTextLeft2:GetText()
- if text then
- if text == LOCALIZED_MINING then
- ScanForGloves(2)
- elseif text == LOCALIZED_HERBALISM then
- ScanForGloves(1)
- else
- EquipStandardGloves()
- end
- else
- EquipStandardGloves()
- end
- end
- -- Change tooltip size to force OnSizeChanged script handler to run after the tooltip changes for the gathering node
- -- The tooltip cannot be scanned at this point, because it will have no contents yet
- GameTooltip:HookScript("OnTooltipSetDefaultAnchor", function(self)
- self:SetWidth(1)
- end)
- -- OnSizeChanged runs after the contents of the tooltip have been updated, so the tooltip can be reliably scanned
- GameTooltip:HookScript("OnSizeChanged", ScanTooltip)
- GameTooltip:HookScript("OnHide", EquipStandardGloves)
Advertisement
Add Comment
Please, Sign In to add comment