diff --git a/EZTrade.lua b/EZTrade.lua index 739b373..6b0a1d1 100644 --- a/EZTrade.lua +++ b/EZTrade.lua @@ -6,6 +6,11 @@ local addonName, EZT = ... local f = CreateFrame("Frame") local function isRelevantLoot(classID) + + if EZTradeDB.debug then + return true + end + if (classID == 2 and EZTradeDB.trackWeapons) then return true elseif (classID == 4 and EZTradeDB.trackArmors) then @@ -14,8 +19,6 @@ local function isRelevantLoot(classID) return true elseif (classID == 17 and EZTradeDB.trackPets) then return true - --elseif (classID == 0 or classID == 15) then -- Temporary - -- return true else return false end @@ -53,20 +56,16 @@ function f:CHAT_MSG_LOOT(lootText) local localizedLootString = LOOT_ITEM_SELF:gsub("%%s", ""):gsub("%.$", "") local itemLinkTmp = string.match(lootText, "|c.-|h|r") - --local itemId = GetItemInfoFromHyperlink(itemLinkTmp) if (itemLinkTmp) then - local itemName, itemLink, itemQuality, itemLevel, itemMinLevel, itemType, - itemSubType, itemStackCount, itemEquipLoc, itemTexture, sellPrice, classID, - subclassID, bindType, expansionID, setID, isCraftingReagent = C_Item.GetItemInfo(itemLinkTmp) - - EZT.debugPrint(itemLink .. classID) + local _, _, _, _, _, _, _, _, _, _, _, classID = C_Item.GetItemInfo(itemLinkTmp) if (isMyLoot(lootText, localizedLootString)) then -- Only add "my" loot to the list. ---@diagnostic disable-next-line: undefined-field - if (isRelevantLoot(classID)) then -- Only add relevant loot - EZT.AddLoot(itemLinkTmp) - --EZT.RedrawLootList() + if (isRelevantLoot(classID)) then -- Only add relevant loot + C_Timer.After(1, function() + EZT.AddLoot(itemLinkTmp) + end) end end end @@ -79,4 +78,4 @@ end) f:RegisterEvent("ADDON_LOADED") f:RegisterEvent("CHAT_MSG_LOOT") f:RegisterEvent("TRADE_SHOW") -f:RegisterEvent("TRADE_CLOSED") +f:RegisterEvent("TRADE_CLOSED") \ No newline at end of file diff --git a/EZTrade.toc b/EZTrade.toc index 6fd4a3c..212593e 100644 --- a/EZTrade.toc +++ b/EZTrade.toc @@ -3,8 +3,10 @@ ## Title: |cff45D388EZTrade|r ## Notes: EZ trade items you recently looted ## Author: Pinta365@Github -## Version: 0.0.1 -## SavedVariables: EZTradeDB +## Version: 0.1.0 +## SavedVariables: EZTradeDB +## X-Curse-Project-ID: 1016387 +## X-Wago-ID: BKpqarGE ## IconTexture: Interface\AddOns\EZTrade\Textures\pinta src\Config.lua diff --git a/README.md b/README.md index 23725ba..4657256 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -## EZTrade +## EZTrade - World of Warcraft Addon Your bags are a chaotic mess of reagents, grey vendor trash, and that epic trinket you just won. Your friends are green with envy, but you can't even find the darn thing to trade it to them. **EZTrade** to the rescue! diff --git a/src/DebugPanel.lua b/src/DebugPanel.lua index 5312b3d..300687e 100644 --- a/src/DebugPanel.lua +++ b/src/DebugPanel.lua @@ -1,9 +1,8 @@ --DebugPanel.lua +-- Just a temporary panel with things for development local addonName, EZT = ... - - EZT.setUpDebugFrame = function() ---@class EZTDebugFrame: Frame local EZTDebugFrame = CreateFrame("Frame", "EZTradeFrame", UIParent, "BasicFrameTemplateWithInset") @@ -25,7 +24,9 @@ EZT.setUpDebugFrame = function() button1:SetWidth(200) EZT.setOrHookHandler(button1, "OnClick", function(self) EZT.AddLoot("|cffa335ee|Hitem:193869::::::::4:1448:::::::::|h[Pattern: Toxic Thorn Footwraps]|h|r") - --EZT.RedrawLootList() + C_Timer.After(1, function() + EZT.RedrawLootList() + end) end) local button2 = CreateFrame("Button", "Dathea's Cyclonic Cage", EZTDebugFrame, "UIPanelButtonTemplate") @@ -35,7 +36,9 @@ EZT.setUpDebugFrame = function() button2:SetWidth(200) EZT.setOrHookHandler(button2, "OnClick", function(self) EZT.AddLoot("|cffa335ee|Hitem:195494::::::::4:1448:::::::::|h[Dathea's Cyclonic Cage]|h|r") - --EZT.RedrawLootList() + C_Timer.After(1, function() + EZT.RedrawLootList() + end) end) local button3 = CreateFrame("Button", "Sargha's Smasher", EZTDebugFrame, "UIPanelButtonTemplate") @@ -45,7 +48,9 @@ EZT.setUpDebugFrame = function() button3:SetWidth(200) EZT.setOrHookHandler(button3, "OnClick", function(self) EZT.AddLoot("|cff0070dd|Hitem:193779::::::::4:1448:::::::::|h[Sargha's Smasher]|h|r") - --EZT.RedrawLootList() + C_Timer.After(1, function() + EZT.RedrawLootList() + end) end) local button4 = CreateFrame("Button", "Eye of Allseeing", EZTDebugFrame, "UIPanelButtonTemplate") @@ -55,7 +60,9 @@ EZT.setUpDebugFrame = function() button4:SetWidth(200) EZT.setOrHookHandler(button4, "OnClick", function(self) EZT.AddLoot("|cff1eff00|Hitem:186554::::::::4:1448:::::::::|h[Eye of Allseeing]|h|r") - --EZT.RedrawLootList() + C_Timer.After(1, function() + EZT.RedrawLootList() + end) end) local button5 = CreateFrame("Button", "Redraw", EZTDebugFrame, "UIPanelButtonTemplate") diff --git a/src/OptionsPanel.lua b/src/OptionsPanel.lua index 0bad492..3aafb23 100644 --- a/src/OptionsPanel.lua +++ b/src/OptionsPanel.lua @@ -44,51 +44,53 @@ EZT.InitOptions = function() optionsPanel.name = addonName -- Create a toggle for the "Debug" option. - local debugCheckbox = createOptionCheckButton(optionsPanel, "Debug mode (developer mode)", "ToggleDebugCheckbox", 16, -16) - EZT.setOrHookHandler(debugCheckbox, "OnClick", function(self) - EZTradeDB.debug = self:GetChecked() - end) - debugCheckbox:SetChecked(EZTradeDB.debug) + --local debugCheckbox = createOptionCheckButton(optionsPanel, "Debug mode (developer mode)", "ToggleDebugCheckbox", 16, -16) + --EZT.setOrHookHandler(debugCheckbox, "OnClick", function(self) + -- EZTradeDB.debug = self:GetChecked() + --end) + --debugCheckbox:SetChecked(EZTradeDB.debug) -- Loot options optionsPanel.lootHeader = optionsPanel:CreateFontString(nil, "OVERLAY", "GameFontHighlightMedium") - optionsPanel.lootHeader:SetPoint("TOPLEFT", 16, -100) + optionsPanel.lootHeader:SetPoint("TOPLEFT", 16, -10) optionsPanel.lootHeader:SetText("Loot tracking") - local trackWeapons = createOptionCheckButton(optionsPanel, "Track weapons", "trackWeaponsButton", 16, -120) + local trackWeapons = createOptionCheckButton(optionsPanel, "Track weapons", "trackWeaponsButton", 16, -30) EZT.setOrHookHandler(trackWeapons, "OnClick", function(self) EZTradeDB.trackWeapons = self:GetChecked() end) trackWeapons:SetChecked(EZTradeDB.trackWeapons) - local trackArmors = createOptionCheckButton(optionsPanel, "Track armors", "trackArmorsButton", 16, -140) + local trackArmors = createOptionCheckButton(optionsPanel, "Track armors", "trackArmorsButton", 16, -50) EZT.setOrHookHandler(trackArmors, "OnClick", function(self) EZTradeDB.trackArmors = self:GetChecked() end) trackArmors:SetChecked(EZTradeDB.trackArmors) - local trackRecipe = createOptionCheckButton(optionsPanel, "Track recipies", "trackRecipeButton", 16, -160) + local trackRecipe = createOptionCheckButton(optionsPanel, "Track recipies", "trackRecipeButton", 16, -70) EZT.setOrHookHandler(trackRecipe, "OnClick", function(self) EZTradeDB.trackRecipe = self:GetChecked() end) trackRecipe:SetChecked(EZTradeDB.trackRecipe) - local trackPets = createOptionCheckButton(optionsPanel, "Track battle pets", "trackPetsButton", 16, -180) + local trackPets = createOptionCheckButton(optionsPanel, "Track battle pets", "trackPetsButton", 16, -90) EZT.setOrHookHandler(trackPets, "OnClick", function(self) EZTradeDB.trackPets = self:GetChecked() end) trackPets:SetChecked(EZTradeDB.trackPets) -- Button for resetting to default settings. - local resetButton = createOptionButton(optionsPanel, "Reset settings", "resetButton", 16, -48, 100, 25) + local resetButton = createOptionButton(optionsPanel, "Reset to default settings", "resetButton", 16, -200, 200, 25) EZT.setOrHookHandler(resetButton, "OnClick", function() EZTradeDB = CopyTable(EZT.addonDefaults) - debugCheckbox:SetChecked(EZTradeDB.debug) + --debugCheckbox:SetChecked(EZTradeDB.debug) trackWeapons:SetChecked(EZTradeDB.trackWeapons) trackArmors:SetChecked(EZTradeDB.trackArmors) trackRecipe:SetChecked(EZTradeDB.trackRecipe) trackPets:SetChecked(EZTradeDB.trackPets) + + print(WrapTextInColorCode(EZT.addon.title .. " is reset to default settings.", EZT.colors["PRIMARY"])) end) optionsPanel.versionInfo = optionsPanel:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall") diff --git a/src/SlashCommand.lua b/src/SlashCommand.lua index a91137d..384df71 100644 --- a/src/SlashCommand.lua +++ b/src/SlashCommand.lua @@ -23,6 +23,15 @@ SlashCmdList["EZTrade_CMD"] = function(args) --Reset to default settings. EZTradeDB = CopyTable(EZT.addonDefaults) ReloadUI() + elseif lowercaseArgs == "debug" then + -- toggle EZTradeDB.debug + EZTradeDB.debug = not EZTradeDB.debug + if EZTradeDB.debug then + print(WrapTextInColorCode(EZT.addon.title .. " debug mode enabled.", EZT.colors["PRIMARY"])) + else + print(WrapTextInColorCode(EZT.addon.title .. " debug mode disabled.", EZT.colors["PRIMARY"])) + end + else InterfaceOptionsFrame_OpenToCategory("EZTrade") end diff --git a/src/TradePanel.lua b/src/TradePanel.lua index a8dd53c..231f6fa 100644 --- a/src/TradePanel.lua +++ b/src/TradePanel.lua @@ -2,7 +2,7 @@ local addonName, EZT = ... -local attachToFrame = TradeFrame --TradeFrame MailFrame PaperDollItemsFrame +local attachToFrame = TradeFrame --TradeFrame MailFrame PaperDollItemsFrame MerchantFrame ---@class EZTradeFrame: Frame local EZTradeFrame = CreateFrame("Frame", "EZTradeFrame", attachToFrame, "DefaultPanelFlatTemplate") @@ -11,17 +11,20 @@ local minMaxButton = CreateFrame("Button", "ToggleMinMax", EZTradeFrame, "UIPane local myLoot = {} local maxLootItems = 10 +local longestLootString = 10 -- used to estimate width of "open" loot panel. local lootRowFrames = {} + local windowOpen = 0 -local windowOpenSize = 250 -local windowCloseSize = 105 +local windowClosedSize = 105 EZT.AddLoot = function(item) + EZT.debugPrint("Adding loot: " .. item) myLoot[#myLoot + 1] = item if #myLoot == maxLootItems then table.remove(myLoot, 1) end + EZT.RedrawLootList() end local function getRequiredHeight() @@ -32,13 +35,16 @@ local function getRequiredHeight() return lootHeight end -local function findAndUseItem(listedId) - local GetContainerNumSlots = C_Container and C_Container.GetContainerNumSlots - local GetContainerItemInfo = C_Container and C_Container.GetContainerItemInfo +local function getRequiredWidth() + local lootWidth = 105 -- Minimized panel size. + local magicNumber = 7 -- A bit of guesstimate number. "Width of a char". + return lootWidth + (longestLootString * magicNumber) +end +local function findAndUseItem(listedId) for bag = 0, NUM_BAG_FRAMES do - for slot = 1, GetContainerNumSlots(bag) do - local containerInfo = GetContainerItemInfo(bag, slot) + for slot = 1, C_Container.GetContainerNumSlots(bag) do + local containerInfo = C_Container.GetContainerItemInfo(bag, slot) local iid = containerInfo and containerInfo.itemID or nil if iid == listedId then C_Container.UseContainerItem(bag, slot) @@ -49,12 +55,14 @@ local function findAndUseItem(listedId) end local function findItem(listedId) - local GetContainerNumSlots = C_Container and C_Container.GetContainerNumSlots - local GetContainerItemInfo = C_Container and C_Container.GetContainerItemInfo + + if EZTradeDB.debug then + return true + end for bag = 0, NUM_BAG_FRAMES do - for slot = 1, GetContainerNumSlots(bag) do - local containerInfo = GetContainerItemInfo(bag, slot) + for slot = 1, C_Container.GetContainerNumSlots(bag) do + local containerInfo = C_Container.GetContainerItemInfo(bag, slot) local iid = containerInfo and containerInfo.itemID or nil if iid == listedId then return true @@ -90,8 +98,8 @@ local function toggleFrameSize() end local function setUpTradeFrame(f) - f:SetSize(windowOpenSize, getRequiredHeight()) - f:SetPoint("RIGHT", attachToFrame, "RIGHT", 255, 0) + f:SetSize(windowClosedSize, getRequiredHeight()) + f:SetPoint("TOPLEFT", attachToFrame, "TOPRIGHT", 0, 0) f.title = f:CreateFontString("Title", "OVERLAY") f.title:SetFontObject("GameFontHighlight") @@ -110,7 +118,6 @@ local function setUpTradeFrame(f) end minMaxButton:SetScript("OnClick", toggleFrameSize) - -- Create loot row frames that we reuse for i = 1, maxLootItems do local rowFrame = CreateFrame("Frame", "LootRow" .. i, f) @@ -124,11 +131,17 @@ local function setUpTradeFrame(f) GameTooltip:Hide() end) + ---@diagnostic disable-next-line: inject-field + rowFrame.icon = rowFrame:CreateTexture(nil, "OVERLAY") + rowFrame.icon:SetSize(32, 32) + rowFrame.icon:SetPoint("LEFT", rowFrame, "LEFT", -3, 0) + + rowFrame:Hide() lootRowFrames[i] = rowFrame - lootRowFrames[i]:Hide() + end - hideOnNoLoot() + EZTradeFrame:Hide() end setUpTradeFrame(EZTradeFrame) @@ -137,16 +150,24 @@ setUpTradeFrame(EZTradeFrame) EZT.RedrawLootList = function() local yPos = 35 local yIncrement = 35 - local updatedLoot = {} - for _, lootItem in ipairs(myLoot) do + for i = 1, #myLoot do + local lootItem = myLoot[i] local itemId = GetItemInfoFromHyperlink(lootItem) + local itemName = C_Item.GetItemInfo(lootItem) + + -- Update longestLootString for width calculation + longestLootString = max(longestLootString, #itemName) + if findItem(itemId) then -- Keep the loot item if found updatedLoot[#updatedLoot + 1] = lootItem end end + --DevTools_Dump(myLoot) + --DevTools_Dump(updatedLoot) + myLoot = updatedLoot for _, rowFrame in ipairs(lootRowFrames) do @@ -158,18 +179,19 @@ EZT.RedrawLootList = function() rowFrame:SetPoint("TOPLEFT", EZTradeFrame, "TOPLEFT", 20, -yPos) yPos = yPos + yIncrement - if myLoot[i] then - local _, _, _, _, _, _, _, _, _, itemTexture = C_Item.GetItemInfo(myLoot[i]) + if lootItem then + local _, _, _, _, _, _, _, _, _, itemTexture = C_Item.GetItemInfo(lootItem) if rowFrame.icon then rowFrame.icon:SetTexture(itemTexture) else rowFrame.icon = rowFrame:CreateTexture(nil, "OVERLAY") + rowFrame.icon:SetTexture(itemTexture) rowFrame.icon:SetSize(32, 32) rowFrame.icon:SetPoint("LEFT", rowFrame, "LEFT", -3, 0) end - rowFrame.hyperlink = myLoot[i] + rowFrame.hyperlink = lootItem if not rowFrame.fontString then rowFrame.fontString = rowFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightMedium") @@ -177,13 +199,13 @@ EZT.RedrawLootList = function() end if windowOpen == 1 then - EZTradeFrame:SetSize(windowOpenSize, getRequiredHeight()) - EZTradeFrame:SetPoint("RIGHT", attachToFrame, "RIGHT", 255, 0) + EZTradeFrame:SetSize(getRequiredWidth(), getRequiredHeight()) + EZTradeFrame:SetPoint("TOPLEFT", attachToFrame, "TOPRIGHT", 0, 0) rowFrame:SetSize(200, 32) rowFrame.fontString:SetText(rowFrame.hyperlink) else - EZTradeFrame:SetSize(windowCloseSize, getRequiredHeight()) - EZTradeFrame:SetPoint("RIGHT", attachToFrame, "RIGHT", 110, 0) + EZTradeFrame:SetSize(windowClosedSize, getRequiredHeight()) + EZTradeFrame:SetPoint("TOPLEFT", attachToFrame, "TOPRIGHT", 0, 0) rowFrame:SetSize(32, 32) rowFrame.fontString:SetText("") end @@ -205,8 +227,10 @@ end EZT.OnTrade = function() EZT.RedrawLootList() - hideOnNoLoot() end EZT.OffTrade = function() -end + C_Timer.After(1, function() + EZT.RedrawLootList() + end) +end \ No newline at end of file