-- Vendor Flag: marks bag items that Auctionator just warned would earn more at -- a vendor, so they can be found again at the merchant. local ADDON_NAME = ... local FLAG_SECONDS = 10 * 60 -- Item key -> time() at which the flag runs out. local flags local hooked = {} -- Every item button Auctionator's selling tab has created so far. local auctionButtons = {} -- Item ID plus suffix, so "of the Bear" and "of the Eagle" are told apart. local function ItemKey(link) local id, suffix = link:match("item:(%d+):[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:|]*)") if id then return id .. ":" .. suffix end end local function SecondsLeft(link) local key = flags and link and ItemKey(link) local expires = key and flags[key] if not expires then return nil end local left = expires - time() if left <= 0 then flags[key] = nil return nil end return left end local function MinutesText(left) return math.ceil(left / 60) .. "m" end local function ApplyMark(button, link) local left = SecondsLeft(link) if not left then if button.vfTint then button.vfTint:Hide() button.vfText:Hide() end return end if not button.vfTint then button.vfTint = button:CreateTexture(nil, "OVERLAY", nil, 6) button.vfTint:SetAllPoints() button.vfTint:SetColorTexture(1, 0.82, 0, 0.35) button.vfText = button:CreateFontString(nil, "OVERLAY", "NumberFontNormalSmall") button.vfText:SetPoint("TOPRIGHT", button, "TOPRIGHT", -2, -3) button.vfText:SetTextColor(1, 0.82, 0) end button.vfText:SetText(MinutesText(left)) button.vfTint:Show() button.vfText:Show() end local function UpdateButton(button) ApplyMark(button, C_Container.GetContainerItemLink(button:GetBagID(), button:GetID())) end local function UpdateFrame(frame) for _, button in frame:EnumerateValidItems() do UpdateButton(button) end end local function EachBagFrame(callback) for i = 1, 20 do local frame = _G["ContainerFrame" .. i] if frame then callback(frame) end end if ContainerFrameCombinedBags then callback(ContainerFrameCombinedBags) end end local function UpdateOpenBags() EachBagFrame(function(frame) if frame:IsShown() then UpdateFrame(frame) end end) for button in pairs(auctionButtons) do if button:IsVisible() then ApplyMark(button, button.itemInfo and button.itemInfo.itemLink) end end end local function HookBagFrames() EachBagFrame(function(frame) if frame.UpdateItems and not hooked[frame] then hooked[frame] = true hooksecurefunc(frame, "UpdateItems", UpdateFrame) end end) end -- Auctionator's frames copy these mixins when the auction house first opens, -- which is always after this file has run. if AuctionatorGroupsViewItemMixin then hooksecurefunc(AuctionatorGroupsViewItemMixin, "SetItemInfo", function(button, info) auctionButtons[button] = true ApplyMark(button, info and info.itemLink) end) end if AuctionatorSaleItemMixin and AuctionatorSaleItemMixin.GetConfirmationMessage then local original = AuctionatorSaleItemMixin.GetConfirmationMessage AuctionatorSaleItemMixin.GetConfirmationMessage = function(self, ...) local message = original(self, ...) if message and message == AUCTIONATOR_L_CONFIRM_POST_BELOW_VENDOR and self.itemInfo and self.itemInfo.itemLink and flags then local key = ItemKey(self.itemInfo.itemLink) if key then flags[key] = time() + FLAG_SECONDS UpdateOpenBags() end end return message end end TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Item, function(tooltip) if tooltip ~= GameTooltip and tooltip ~= ItemRefTooltip then return end local _, link = tooltip:GetItem() local left = SecondsLeft(link) if left then tooltip:AddLine("Vendor beats auction (" .. MinutesText(left) .. " left)", 1, 0.82, 0) tooltip:Show() end end) local frame = CreateFrame("Frame") frame:RegisterEvent("ADDON_LOADED") frame:RegisterEvent("PLAYER_LOGIN") frame:RegisterEvent("BAG_UPDATE_DELAYED") frame:SetScript("OnEvent", function(_, event, arg1) if event == "ADDON_LOADED" then if arg1 == ADDON_NAME then VendorFlagDB = VendorFlagDB or {} flags = VendorFlagDB end elseif event == "PLAYER_LOGIN" then HookBagFrames() C_Timer.NewTicker(15, UpdateOpenBags) else UpdateOpenBags() end end) -- /vf lists what is currently flagged. SLASH_VENDORFLAG1 = "/vf" SlashCmdList.VENDORFLAG = function() local found = false for key, expires in pairs(flags or {}) do local left = expires - time() if left > 0 then found = true DEFAULT_CHAT_FRAME:AddMessage("|cffffd100VendorFlag:|r " .. key .. " " .. MinutesText(left)) end end if not found then DEFAULT_CHAT_FRAME:AddMessage("|cffffd100VendorFlag:|r nothing flagged") end end