What's new

addon for wow 3.3.5a

kingmob

Verified Member
7
2015
0
Hello, I have been creating this addon for a while now. I saw the function of this addon in the new versions of wow. Every new item that enters the bags makes the edge blink and when you pass over that item it stops doing that effect.
Although it works, but it has several problems 1.it only works with onebags3, I have tried to make it work with standard bags but without success.
2. Another problem is that the items that are stacked do not recognize them as new for the second time.

If anyone can and is willing to help understand how to solve these problems I would be very grateful.

Greetings

Code:
local frame = CreateFrame("Frame")
local seenItems = {}

function frame:OnEvent(event, arg1, arg2)
    if event == "BAG_UPDATE" then
        local bagId = arg1
        if bagId == 0 then
            -- Limpiar la tabla seenItems para eliminar elementos que ya no estén en el inventario
            for itemId, _ in pairs(seenItems) do
                if not IsItemInInventory(itemId) then
                    seenItems[itemId] = nil
                end
            end

            for slot = 1, GetContainerNumSlots(bagId) do
                local itemLink = GetContainerItemLink(bagId, slot)
                if itemLink then
                    local itemId = tonumber(string.match(itemLink, "item:(%d+)"))
                    local itemButton = _G["OneBagFrameBag" .. bagId .. "Item" .. slot]

                    if itemId and itemButton then
                        -- Verificar si el elemento es nuevo
                        if not seenItems[itemId] then
                            local border = itemButton:CreateTexture(nil, "OVERLAY")
                            border:SetTexture("Interface\\Buttons\\UI-ActionButton-Border")
                            border:SetBlendMode("ADD")
                            border:SetAlpha(1.0)
                            border:SetWidth(70)
                            border:SetHeight(70)
                            border:SetPoint("CENTER", itemButton, "CENTER", 0 , 0)

                            local blinkTimer = 1
                            local blinkSpeed = 0.3 -- Velocidad del parpadeo (segundos)
                            local isBlinking = false

                            local function Blink()
                                if isBlinking then
                                    border:SetVertexColor(1.0, 1.0, 1.0) -- Cambiar el color a blanco
                                    isBlinking = false
                                else
                                    border:SetVertexColor(1.0, 1.0, 0) -- Cambiar el color a rojo
                                    isBlinking = true
                                end
                            end

                            itemButton:SetScript("OnEnter", function(self)
                                border:SetVertexColor(0, 0, 0, 0) -- Al pasar el mouse, color transparente (detiene el parpadeo)

                                -- Mostrar la descripción del elemento al pasar el ratón
                                GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
                                GameTooltip:SetHyperlink(itemLink)
                                GameTooltip:Show()
                            end)

                            itemButton:SetScript("OnLeave", function(self)
                                GameTooltip:Hide()
                            end)

                            itemButton:SetScript("OnUpdate", function(self, elapsed)
                                blinkTimer = blinkTimer + elapsed
                                if blinkTimer >= blinkSpeed then
                                    Blink()
                                    blinkTimer = 0
                                end
                            end)

                            -- Marcar el elemento como visto
                            seenItems[itemId] = true
                        else
                            -- El elemento ya se ha visto, por lo que se actualiza el efecto de parpadeo en su lugar
                            local border = itemButton:GetNormalTexture() -- Obtener la textura de fondo (normal texture)
                            if border then
                                border:SetAlpha(1.0)
                                border:SetVertexColor(0.7, 0.4, 0.3)
                            end
                        end
                    end
                end
            end
        end
    end
end

-- Función auxiliar para verificar si un elemento todavía está en el inventario
function IsItemInInventory(itemId)
    for bagId = 0, NUM_BAG_SLOTS do
        for slot = 1, GetContainerNumSlots(bagId) do
            local itemLink = GetContainerItemLink(bagId, slot)
            if itemLink then
                local itemID = tonumber(string.match(itemLink, "item:(%d+)"))
                if itemID == itemId then
                    return true
                end
            end
        end
    end
    return false
end

frame:RegisterEvent("BAG_UPDATE")
frame:SetScript("OnEvent", frame.OnEvent)

local addonLoadedFrame = CreateFrame("Frame")

function addonLoadedFrame:OnEvent(event, arg1)
    if event == "ADDON_LOADED" and arg1 == "LuminaStack" then
        print("LuminaStack cargado.")
    end
end

addonLoadedFrame:RegisterEvent("ADDON_LOADED")
addonLoadedFrame:SetScript("OnEvent", addonLoadedFrame.OnEvent)
 
Top