Add items to list

                Never    
Lua
       
--  Thursday 13 June 2019
-- create item link list if it dosent already exist
if not AAAGlobalItemLinkList then
    AAAGlobalItemLinkList = {}
end

-- temp tables
local tempItemList, listItems = {}, {}

-- list of item rarity types
local ListOfItemRarity = {
    rarityGrey = true,
    rarityWhite = true,
    rarityGreen = true,
    rarityBlue = true,
    rarityPurple = true,
    rarityHeirloom = true,
    rarityLegendary = true,
    rarityArtifact = true
}

-- button and frame dimensions
local NumberOfButtons, HeightOfButtons = 11, 16
local MainFrameHeight, MainFrameWidth = 500, 350
local ScrollFrameHeight, ScrollFrameWidth = 200, 200
local UpdateButtonHeight, UpdateButtonWidth = 30, 200
local ButtonGap = 40
local RarityButtonFalse = '|cffff0000' -- #ff0000

-----------------------------------------------------------------------------------------
-- test item rarity function
local function testItemRarity(incomingItemID)
    print(incomingItemID)
    --[[
    local itemName,
        itemLink,
        itemRarity,
        itemLevel,
        itemMinLevel,
        itemType,
        itemSubType,
        itemStackCount,
        itemEquipLoc,
        iconFileDataID,
        itemSellPrice,
        itemClassID,
        itemSubClassID,
        bindType,
        expacID,
        itemSetID,
        isCraftingReagent = GetItemInfo(incomingItemID)
    if
        (ListOfItemRarity.rarityGrey and itemRarity == 0) or (ListOfItemRarity.rarityWhite and itemRarity == 1) or
            (ListOfItemRarity.rarityGreen and itemRarity == 2) or
            (ListOfItemRarity.rarityBlue and itemRarity == 3) or
            (ListOfItemRarity.rarityPurple and itemRarity == 4) or
            (ListOfItemRarity.rarityHeirloom and itemRarity == 5) or
            (ListOfItemRarity.rarityLegendary and itemRarity == 6) or
            (ListOfItemRarity.rarityArtifact and itemRarity == 7)
     then
        return true
    end
    --]]
end

-- update scroll frames function
local function updateScrollFrame()
    wipe(listItems)
    for index = 1, #AAAGlobalItemLinkList do
        --if testItemRarity(AAAGlobalItemLinkList[index]) then
        table.insert(listItems, AAAGlobalItemLinkList[index]['itemLink'])
        --end
    end
    FauxScrollFrame_Update(testingScrollFrame, #listItems, NumberOfButtons, HeightOfButtons)
    for index = 1, NumberOfButtons do
        local offset = index + FauxScrollFrame_GetOffset(testingScrollFrame)
        local button = testingScrollFrame.buttons[index]
        if index > #listItems then
            button:SetText('')
            button.index = nil
        else
            button.index = offset
            --local itemName, itemLink = GetItemInfo(listItems[offset])
            button:SetText(listItems[offset])
        end
    end
end

--************************************************************************************
--************************************************************************************
--************************************************************************************
--************************************************************************************
--************************************************************************************
--************************************************************************************

-- clear list
local function clearList()
    wipe(AAAGlobalItemLinkList)
end

-- check if item is already listed
local function isItemOnList(incomingItemID)
    for k, v in pairs(AAAGlobalItemLinkList) do
        if v.itemID == incomingItemID then
            print(v.itemID, ':matched:', incomingItemID)
            return true
        end
        print('no match', incomingItemID)
        return false
    end
end

-- add item link to list function
local function addItemLinkToList()
    local cursorItemType, cursorItemID, cursorItemLink = GetCursorInfo()
    print(cursorItemID)
    if not isItemOnList(cursorItemID) then
        local itemName,
            itemLink,
            itemRarity,
            itemLevel,
            itemMinLevel,
            itemType,
            itemSubType,
            itemStackCount,
            itemEquipLoc,
            iconFileDataID,
            itemSellPrice,
            itemClassID,
            itemSubClassID,
            bindType,
            expacID,
            itemSetID,
            isCraftingReagent = GetItemInfo(cursorItemID)

        tempItemList = {
            itemID = cursorItemID,
            itemName = itemName,
            itemLink = itemLink,
            itemRarity = itemRarity,
            itemLevel = itemLevel,
            itemMinLevel = itemMinLevel,
            itemType = itemType,
            itemSubType = itemSubType,
            itemStackCount = itemStackCount,
            itemEquipLoc = itemEquipLoc,
            iconFileDataID = iconFileDataID,
            itemSellPrice = itemSellPrice,
            itemClassID = itemClassID,
            itemSubClassID = itemSubClassID,
            bindType = bindType,
            expacID = expacID,
            itemSetID = itemSetID,
            isCraftingReagent = isCraftingReagent
        }
        table.insert(AAAGlobalItemLinkList, 1, tempItemList)
        print(cursorItemLink, 'added to list')
    else
        print(cursorItemLink, 'already listed')
    end
    updateScrollFrame()
    ClearCursor()
end

--************************************************************************************
--************************************************************************************
--************************************************************************************
--************************************************************************************
--************************************************************************************
--************************************************************************************

-- show frame slash command
SLASH_AAA1 = '/aaa' -- Show frame
function SlashCmdList.AAA(msg, editbox)
    testingMainFrame:Show()
    updateScrollFrame()
end

-----------------------------------------------------------------------------------------
-- main frame
local testingMainFrame = CreateFrame('Frame', 'testingMainFrame', UIParent, 'ButtonFrameTemplate')
testingMainFrame:SetSize(MainFrameHeight, MainFrameWidth)
testingMainFrame:ClearAllPoints()
testingMainFrame:SetPoint('LEFT', 300, 50)
testingMainFrame:EnableMouse(true)
testingMainFrame:SetMovable(true)
testingMainFrame:RegisterForDrag('LeftButton')
testingMainFrame:SetScript('OnDragStart', testingMainFrame.StartMoving)
testingMainFrame:SetScript('OnDragStop', testingMainFrame.StopMovingOrSizing)
testingMainFrame:SetToplevel(true)
testingMainFrame:SetScript(
    'Onevent',
    function(self, event, ...)
        if event == 'PLAYER_LOGIN' then
            updateScrollFrame()
        elseif event == 'GET_ITEM_INFO_RECEIVED' then
            updateScrollFrame()
        end
        updateScrollFrame()
    end
)
testingMainFrame:RegisterEvent('PLAYER_LOGIN')
testingMainFrame:RegisterEvent('GET_ITEM_INFO_RECEIVED')
-- testingMainFrame:Hide()

-----------------------------------------------------------------------------------------
-- scroll frame parent
local scrollFrameParent = CreateFrame('Frame', 'scrollFrameParent', testingMainFrame, 'TooltipBorderedFrameTemplate')
scrollFrameParent:SetSize(ScrollFrameHeight, ScrollFrameWidth)
scrollFrameParent:SetPoint('TOPLEFT', testingMainFrame, 30, -70)

-- scroll frame
local testingScrollFrame =
    CreateFrame('ScrollFrame', 'testingScrollFrame', scrollFrameParent, 'FauxScrollFrameTemplate')
testingScrollFrame:SetPoint('TOPLEFT', 0, -8)
testingScrollFrame:SetPoint('BOTTOMRIGHT', -30, 8)
testingScrollFrame:SetScript(
    'OnVerticalScroll',
    function(self, offset)
        FauxScrollFrame_OnVerticalScroll(self, offset, 16, updateScrollFrame)
    end
)

-- scroll buttons
testingScrollFrame.buttons = {}
for index = 1, NumberOfButtons do
    testingScrollFrame.buttons[index] = CreateFrame('Button', nil, scrollFrameParent)
    button = testingScrollFrame.buttons[index]
    button:SetSize(ScrollFrameWidth, HeightOfButtons)
    button:SetNormalFontObject('GameFontHighlightLeft')
    button:SetPoint('TOPLEFT', 8, -(index - 1) * HeightOfButtons - 8)
    button.currentIndex = index
    button:SetScript(
        'OnClick',
        function(self)
            local offset = self.currentIndex + FauxScrollFrame_GetOffset(testingScrollFrame)
            --            local itemName, itemLink, itemID = GetItemInfo(listItems[offset])
            print('Item list:', listItems[offset])
            -- isItemOnList(listItems[offset])
        end
    )
end

-----------------------------------------------------------------------------------------
-- item drop box
local dropBoxFrame = CreateFrame('Button', 'dropBoxFrame', testingMainFrame, 'TooltipBorderedFrameTemplate')
dropBoxFrame:SetSize(ScrollFrameHeight / 2, ScrollFrameWidth / 2)
dropBoxFrame:SetPoint('TOPRIGHT', testingMainFrame, -30, -70)
dropBoxFrame:SetScript(
    'OnReceiveDrag',
    function()
        addItemLinkToList()
    end
)
dropBoxFrame:SetScript(
    'OnClick',
    function()
        if GetCursorInfo() then
            addItemLinkToList()
        end
    end
)

-----------------------------------------------------------------------------------------
-- update button
local updateListButton = CreateFrame('Button', 'updateListButton', testingMainFrame, 'UIMenuButtonStretchTemplate')
updateListButton:SetSize(UpdateButtonWidth, UpdateButtonHeight)
updateListButton:SetPoint('BOTTOMRIGHT', testingMainFrame, -30, 40)
updateListButton:SetFormattedText('Update list')
updateListButton:SetScript(
    'OnClick',
    function(self)
        updateScrollFrame()
    end
)

-- clear list button
local clearListButton = CreateFrame('Button', 'clearListButton', testingMainFrame, 'UIMenuButtonStretchTemplate')
clearListButton:SetSize(UpdateButtonWidth, UpdateButtonHeight)
clearListButton:SetPoint('BOTTOMLEFT', testingMainFrame, 30, 40)
clearListButton:SetFormattedText('Clear list')
clearListButton:SetScript(
    'OnClick',
    function(self)
        clearList()
        updateScrollFrame()
    end
)

-- grey filter toggle button
local toggleGreyButton = CreateFrame('Button', 'toggleGreyButton', testingMainFrame, 'UIMenuButtonStretchTemplate')
toggleGreyButton:SetBackdrop(
    {
        bgFile = nil,
        insets = nil,
        tileSize = nil,
        tile = true,
        edgeFile = 'Interface\\Tooltips\\UI-Tooltip-Border',
        edgeSize = 20
    }
)
toggleGreyButton:SetSize(UpdateButtonWidth / 2, UpdateButtonHeight)
toggleGreyButton:SetPoint('TOPRIGHT', dropBoxFrame, 'TOPLEFT', -20, 0)
toggleGreyButton:SetFormattedText(RarityButtonFalse .. 'Grey')
toggleGreyButton:SetBackdropBorderColor(0, 1, 0, 1)
toggleGreyButton:SetScript(
    'OnClick',
    function(self)
        if ListOfItemRarity.rarityGrey then
            toggleGreyButton:SetBackdropBorderColor(1, 0, 0, 1)
            ListOfItemRarity.rarityGrey = false
        else
            toggleGreyButton:SetBackdropBorderColor(0, 1, 0, 1)
            ListOfItemRarity.rarityGrey = true
        end
        updateScrollFrame()
    end
)

-- white filter toggle button
local toggleWhiteButton = CreateFrame('Button', 'toggleWhiteButton', testingMainFrame, 'UIMenuButtonStretchTemplate')
toggleWhiteButton:SetSize(UpdateButtonWidth / 2, UpdateButtonHeight)
toggleWhiteButton:SetPoint('TOP', toggleGreyButton, 0, -ButtonGap)
toggleWhiteButton:SetFormattedText('White')
toggleWhiteButton:SetScript(
    'OnClick',
    function(self)
        if ListOfItemRarity.rarityWhite then
            ListOfItemRarity.rarityWhite = false
            toggleWhiteButton:SetFormattedText(RarityButtonFalse .. 'White')
        else
            ListOfItemRarity.rarityWhite = true
            toggleWhiteButton:SetFormattedText('White')
        end
        updateScrollFrame()
    end
)

-- green filter toggle button
local toggleGreenButton = CreateFrame('Button', 'toggleGreenButton', testingMainFrame, 'UIMenuButtonStretchTemplate')
toggleGreenButton:SetSize(UpdateButtonWidth / 2, UpdateButtonHeight)
toggleGreenButton:SetPoint('TOP', toggleWhiteButton, 0, -ButtonGap)
toggleGreenButton:SetFormattedText('Green')
toggleGreenButton:SetScript(
    'OnClick',
    function(self)
        if ListOfItemRarity.rarityGreen then
            ListOfItemRarity.rarityGreen = false
            toggleGreenButton:SetFormattedText(RarityButtonFalse .. 'Green')
        else
            ListOfItemRarity.rarityGreen = true
            toggleGreenButton:SetFormattedText('Green')
        end
        updateScrollFrame()
    end
)

-- blue filter toggle button
local toogleBlueButton = CreateFrame('Button', 'toogleBlueButton', testingMainFrame, 'UIMenuButtonStretchTemplate')
toogleBlueButton:SetSize(UpdateButtonWidth / 2, UpdateButtonHeight)
toogleBlueButton:SetPoint('TOP', toggleGreenButton, 0, -ButtonGap)
toogleBlueButton:SetFormattedText('Blue')
toogleBlueButton:SetScript(
    'OnClick',
    function(self)
        if ListOfItemRarity.rarityBlue then
            ListOfItemRarity.rarityBlue = false
            toogleBlueButton:SetFormattedText(RarityButtonFalse .. 'Blue')
        else
            ListOfItemRarity.rarityBlue = true
            toogleBlueButton:SetFormattedText('Blue')
        end
        updateScrollFrame()
    end
)

-- purple filter toggle button
local tooglePurpleButton = CreateFrame('Button', 'tooglePurpleButton', testingMainFrame, 'UIMenuButtonStretchTemplate')
tooglePurpleButton:SetSize(UpdateButtonWidth / 2, UpdateButtonHeight)
tooglePurpleButton:SetPoint('TOP', toogleBlueButton, 0, -ButtonGap)
tooglePurpleButton:SetFormattedText('Purple')
tooglePurpleButton:SetScript(
    'OnClick',
    function(self)
        if ListOfItemRarity.rarityPurple then
            ListOfItemRarity.rarityPurple = false
            tooglePurpleButton:SetFormattedText(RarityButtonFalse .. 'Purple')
        else
            ListOfItemRarity.rarityPurple = true
            tooglePurpleButton:SetFormattedText('Purple')
        end
        updateScrollFrame()
    end
)

-- orange filter toggle button
local toggleOrangeButton = CreateFrame('Button', 'toggleOrangeButton', testingMainFrame, 'UIMenuButtonStretchTemplate')
toggleOrangeButton:SetSize(UpdateButtonWidth / 2, UpdateButtonHeight)
toggleOrangeButton:SetPoint('TOPLEFT', toogleBlueButton, 'TOPRIGHT', 20, 0)
toggleOrangeButton:SetFormattedText('Orange')
toggleOrangeButton:SetScript(
    'OnClick',
    function(self)
        if ListOfItemRarity.rarityLegendary then
            ListOfItemRarity.rarityLegendary = false
            toggleOrangeButton:SetFormattedText(RarityButtonFalse .. 'Orange')
        else
            ListOfItemRarity.rarityLegendary = true
            toggleOrangeButton:SetFormattedText('Orange')
        end
        updateScrollFrame()
    end
)

-- light blue filter toggle button
local toogleLightBlueButton =
    CreateFrame('Button', 'toogleLightBlueButton', testingMainFrame, 'UIMenuButtonStretchTemplate')
toogleLightBlueButton:SetSize(UpdateButtonWidth / 2, UpdateButtonHeight)
toogleLightBlueButton:SetPoint('TOP', toggleOrangeButton, 0, -ButtonGap)
toogleLightBlueButton:SetFormattedText('Light Blue')
toogleLightBlueButton:SetScript(
    'OnClick',
    function(self)
        if ListOfItemRarity.rarityHeirloom then
            ListOfItemRarity.rarityHeirloom = false
            toogleLightBlueButton:SetFormattedText(RarityButtonFalse .. 'Light Blue')
        else
            ListOfItemRarity.rarityHeirloom = true
            toogleLightBlueButton:SetFormattedText('Light Blue')
        end
        updateScrollFrame()
    end
)

Raw Text