mirror of
https://github.com/brues-code/pfUI.git
synced 2026-10-23 12:30:50 +00:00
autovendor: only sell one item per frame
This commit is contained in:
+102
-43
@@ -1,6 +1,7 @@
|
|||||||
pfUI:RegisterModule("autovendor", function ()
|
pfUI:RegisterModule("autovendor", function ()
|
||||||
pfUI.autovendor = CreateFrame("Frame", "pfMoneyUpdate", nil)
|
local scanlist = {}
|
||||||
pfUI.autovendor.RepairAllItems = function()
|
|
||||||
|
local function RepairAllItems()
|
||||||
local cost, possible = GetRepairAllCost()
|
local cost, possible = GetRepairAllCost()
|
||||||
if cost > 0 and possible then
|
if cost > 0 and possible then
|
||||||
DEFAULT_CHAT_FRAME:AddMessage("Your items have been repaired for " .. CreateGoldString(cost))
|
DEFAULT_CHAT_FRAME:AddMessage("Your items have been repaired for " .. CreateGoldString(cost))
|
||||||
@@ -8,87 +9,145 @@ pfUI:RegisterModule("autovendor", function ()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
pfUI.autovendor.SellAllGrey = function()
|
local function ScanGreyItems()
|
||||||
local price = 0
|
scanlist = {}
|
||||||
local count = 0
|
|
||||||
|
|
||||||
for bag = 0, 4, 1 do
|
for bag = 0, 4, 1 do
|
||||||
for slot = 1, GetContainerNumSlots(bag), 1 do
|
for slot = 1, GetContainerNumSlots(bag), 1 do
|
||||||
local name = GetContainerItemLink(bag,slot)
|
local name = GetContainerItemLink(bag,slot)
|
||||||
if name and string.find(name,"ff9d9d9d") then
|
if name and string.find(name,"ff9d9d9d") then
|
||||||
|
table.insert(scanlist, { bag, slot })
|
||||||
-- get value
|
|
||||||
local _, icount = GetContainerItemInfo(bag, slot)
|
|
||||||
local _, _, id = string.find(GetContainerItemLink(bag, slot), "item:(%d+):%d+:%d+:%d+")
|
|
||||||
if pfSellData[tonumber(id)] then
|
|
||||||
local _, _, sell, buy = strfind(pfSellData[tonumber(id)], "(.*),(.*)")
|
|
||||||
price = price + ( sell * ( icount or 1 ) )
|
|
||||||
count = count + 1
|
|
||||||
end
|
|
||||||
UseContainerItem(bag,slot)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if count > 0 then
|
local function GetNextGreyItem()
|
||||||
DEFAULT_CHAT_FRAME:AddMessage("Your vendor trash has been sold and you earned " .. CreateGoldString(price))
|
if scanlist[1] then
|
||||||
|
local bag, slot = scanlist[1][1], scanlist[1][2]
|
||||||
|
table.remove(scanlist, 1)
|
||||||
|
|
||||||
|
return bag, slot
|
||||||
|
else
|
||||||
|
return nil, nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
pfUI.autovendor:RegisterEvent("MERCHANT_SHOW")
|
local autovendor = CreateFrame("Frame", "pfMoneyUpdate", nil)
|
||||||
pfUI.autovendor:SetScript("OnEvent", function()
|
autovendor:Hide()
|
||||||
|
|
||||||
|
autovendor:SetScript("OnShow", function()
|
||||||
|
ScanGreyItems()
|
||||||
|
this.count = 0
|
||||||
|
this.price = 0
|
||||||
|
end)
|
||||||
|
|
||||||
|
autovendor:SetScript("OnUpdate", function()
|
||||||
|
local bag, slot = GetNextGreyItem()
|
||||||
|
|
||||||
|
if not bag or not slot then
|
||||||
|
this:Hide()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local name = GetContainerItemLink(bag,slot)
|
||||||
|
|
||||||
|
-- double check to only sell grey
|
||||||
|
if name and string.find(name,"ff9d9d9d") then
|
||||||
|
-- get value
|
||||||
|
local _, icount = GetContainerItemInfo(bag, slot)
|
||||||
|
local _, _, id = string.find(GetContainerItemLink(bag, slot), "item:(%d+):%d+:%d+:%d+")
|
||||||
|
if pfSellData[tonumber(id)] then
|
||||||
|
local _, _, sell, buy = strfind(pfSellData[tonumber(id)], "(.*),(.*)")
|
||||||
|
this.price = this.price + ( sell * ( icount or 1 ) )
|
||||||
|
this.count = this.count + 1
|
||||||
|
end
|
||||||
|
UseContainerItem(bag, slot)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
autovendor:SetScript("OnHide", function()
|
||||||
|
if this.count > 0 then
|
||||||
|
DEFAULT_CHAT_FRAME:AddMessage("Your vendor trash has been sold and you earned " .. CreateGoldString(this.price))
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
autovendor:RegisterEvent("MERCHANT_SHOW")
|
||||||
|
autovendor:RegisterEvent("MERCHANT_UPDATE")
|
||||||
|
autovendor:SetScript("OnEvent", function()
|
||||||
|
autovendor.button:Update()
|
||||||
|
|
||||||
if event == "MERCHANT_SHOW" then
|
if event == "MERCHANT_SHOW" then
|
||||||
if C["global"]["autorepair"] == "1" then
|
if C["global"]["autorepair"] == "1" then
|
||||||
pfUI.autovendor:RepairAllItems()
|
RepairAllItems()
|
||||||
end
|
end
|
||||||
|
|
||||||
if C["global"]["autosell"] == "1" then
|
if C["global"]["autosell"] == "1" then
|
||||||
pfUI.autovendor:SellAllGrey()
|
autovendor:Show()
|
||||||
end
|
end
|
||||||
|
|
||||||
MerchantRepairText:SetText("")
|
MerchantRepairText:SetText("")
|
||||||
if MerchantRepairItemButton:IsShown() then
|
if MerchantRepairItemButton:IsShown() then
|
||||||
pfUI.autovendor.button:ClearAllPoints()
|
autovendor.button:ClearAllPoints()
|
||||||
pfUI.autovendor.button:SetPoint("RIGHT", MerchantRepairItemButton, "LEFT", -2, 0)
|
autovendor.button:SetPoint("RIGHT", MerchantRepairItemButton, "LEFT", -2, 0)
|
||||||
else
|
else
|
||||||
pfUI.autovendor.button:ClearAllPoints()
|
autovendor.button:ClearAllPoints()
|
||||||
pfUI.autovendor.button:SetPoint("BOTTOMRIGHT", MerchantFrame, "BOTTOMLEFT", 172, 91)
|
autovendor.button:SetPoint("BOTTOMRIGHT", MerchantFrame, "BOTTOMLEFT", 172, 91)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- show button
|
-- Setup Autosell button
|
||||||
pfUI.autovendor.button = CreateFrame("Button", "pfMerchantpfUI.autovendor.buttonButton", MerchantFrame)
|
autovendor.button = CreateFrame("Button", "pfMerchantautovendor.buttonButton", MerchantFrame)
|
||||||
pfUI.autovendor.button:SetWidth(36)
|
autovendor.button:SetWidth(36)
|
||||||
pfUI.autovendor.button:SetHeight(36)
|
autovendor.button:SetHeight(36)
|
||||||
pfUI.autovendor.button.icon = pfUI.autovendor.button:CreateTexture("BORDER")
|
autovendor.button.icon = autovendor.button:CreateTexture("BORDER")
|
||||||
pfUI.autovendor.button.icon:SetAllPoints(pfUI.autovendor.button)
|
autovendor.button.icon:SetAllPoints(autovendor.button)
|
||||||
pfUI.autovendor.button.icon:SetTexture("Interface\\Icons\\Spell_Shadow_SacrificialShield")
|
autovendor.button.icon:SetTexture("Interface\\Icons\\Spell_Shadow_SacrificialShield")
|
||||||
pfUI.autovendor.button.icon:SetVertexColor(1,.8,.4)
|
autovendor.button.icon:SetVertexColor(1,.8,.4)
|
||||||
pfUI.autovendor.button:SetNormalTexture("")
|
autovendor.button:SetNormalTexture("")
|
||||||
pfUI.autovendor.button:SetPushedTexture("Interface\\Buttons\\UI-Quickslot-Depress")
|
autovendor.button:SetPushedTexture("Interface\\Buttons\\UI-Quickslot-Depress")
|
||||||
pfUI.autovendor.button:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square")
|
autovendor.button:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square")
|
||||||
pfUI.autovendor.button:SetScript("OnEnter", function()
|
autovendor.button:SetScript("OnEnter", function()
|
||||||
GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
|
GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
|
||||||
GameTooltip:SetText("Sell Grey Items");
|
GameTooltip:SetText("Sell Grey Items");
|
||||||
GameTooltip:Show();
|
GameTooltip:Show();
|
||||||
end)
|
end)
|
||||||
|
|
||||||
pfUI.autovendor.button:SetScript("OnLeave", function()
|
autovendor.button:SetScript("OnLeave", function()
|
||||||
GameTooltip:Hide();
|
GameTooltip:Hide();
|
||||||
end)
|
end)
|
||||||
|
|
||||||
pfUI.autovendor.button:SetScript("OnClick", function()
|
autovendor.button:SetScript("OnClick", function()
|
||||||
pfUI.autovendor:SellAllGrey()
|
autovendor:Show()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
autovendor.button.Update = function()
|
||||||
|
if not autovendor:IsVisible() then
|
||||||
|
|
||||||
|
ScanGreyItems()
|
||||||
|
|
||||||
|
if scanlist[1] then
|
||||||
|
autovendor.button:Enable()
|
||||||
|
autovendor.button.icon:SetVertexColor(1,.8,.4)
|
||||||
|
else
|
||||||
|
autovendor.button:Disable()
|
||||||
|
autovendor.button.icon:SetVertexColor(.5,.5,.5)
|
||||||
|
end
|
||||||
|
|
||||||
|
else
|
||||||
|
autovendor.button:Disable()
|
||||||
|
autovendor.button.icon:SetVertexColor(.5,.5,.5)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Hook MerchantFrame_Update
|
||||||
if not pfMerchantFrame_Update then
|
if not pfMerchantFrame_Update then
|
||||||
local pfMerchantFrame_Update = MerchantFrame_Update
|
local pfMerchantFrame_Update = MerchantFrame_Update
|
||||||
function _G.MerchantFrame_Update()
|
function _G.MerchantFrame_Update()
|
||||||
if MerchantFrame.selectedTab == 1 then
|
if MerchantFrame.selectedTab == 1 then
|
||||||
pfUI.autovendor.button:Show()
|
autovendor.button:Show()
|
||||||
else
|
else
|
||||||
pfUI.autovendor.button:Hide()
|
autovendor.button:Hide()
|
||||||
end
|
end
|
||||||
pfMerchantFrame_Update()
|
pfMerchantFrame_Update()
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user