From 546ce6287c72edf5e2f55b31eae7ad2ebce7c1ac Mon Sep 17 00:00:00 2001 From: shagu Date: Sun, 23 Apr 2017 20:25:14 +0200 Subject: [PATCH] autovendor: auto sell- and repair module --- api/config.lua | 2 + modules/autovendor.lua | 96 ++++++++++++++++++++++++++++++++++++++++++ modules/gui.lua | 2 + pfUI.toc | 1 + 4 files changed, 101 insertions(+) create mode 100644 modules/autovendor.lua diff --git a/api/config.lua b/api/config.lua index 95bcc6cf..8541fafc 100644 --- a/api/config.lua +++ b/api/config.lua @@ -35,6 +35,8 @@ function pfUI:LoadConfig() pfUI:UpdateConfig("global", nil, "hidebuff", "0") pfUI:UpdateConfig("global", nil, "hidewbuff", "0") pfUI:UpdateConfig("global", nil, "twentyfour", "1") + pfUI:UpdateConfig("global", nil, "autosell", "0") + pfUI:UpdateConfig("global", nil, "autorepair", "0") pfUI:UpdateConfig("appearance", "border", "background", "0,0,0,1") pfUI:UpdateConfig("appearance", "border", "color", "0.3,0.3,0.3,1") diff --git a/modules/autovendor.lua b/modules/autovendor.lua new file mode 100644 index 00000000..45a5a019 --- /dev/null +++ b/modules/autovendor.lua @@ -0,0 +1,96 @@ +pfUI:RegisterModule("autovendor", function () + pfUI.autovendor = CreateFrame("Frame", "pfMoneyUpdate", nil) + pfUI.autovendor.RepairAllItems = function() + local cost, possible = GetRepairAllCost() + if cost > 0 and possible then + DEFAULT_CHAT_FRAME:AddMessage("Your items have been repaired for " .. CreateGoldString(cost)) + RepairAllItems() + end + end + + pfUI.autovendor.SellAllGrey = function() + local price = 0 + local count = 0 + + for bag = 0, 4, 1 do + for slot = 1, GetContainerNumSlots(bag), 1 do + local name = GetContainerItemLink(bag,slot) + 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)], "(.*),(.*)") + price = price + ( sell * ( icount or 1 ) ) + count = count + 1 + end + UseContainerItem(bag,slot) + end + end + end + + if count > 0 then + DEFAULT_CHAT_FRAME:AddMessage("Your vendor trash has been sold and you earned " .. CreateGoldString(price)) + end + end + + pfUI.autovendor:RegisterEvent("MERCHANT_SHOW") + pfUI.autovendor:SetScript("OnEvent", function() + if event == "MERCHANT_SHOW" then + if C["global"]["autorepair"] == "1" then + pfUI.autovendor:RepairAllItems() + end + + if C["global"]["autosell"] == "1" then + pfUI.autovendor:SellAllGrey() + end + + MerchantRepairText:SetText("") + if MerchantRepairItemButton:IsShown() then + pfUI.autovendor.button:ClearAllPoints() + pfUI.autovendor.button:SetPoint("RIGHT", MerchantRepairItemButton, "LEFT", -2, 0) + else + pfUI.autovendor.button:ClearAllPoints() + pfUI.autovendor.button:SetPoint("BOTTOMRIGHT", MerchantFrame, "BOTTOMLEFT", 172, 91) + end + end + end) + + -- show button + pfUI.autovendor.button = CreateFrame("Button", "pfMerchantpfUI.autovendor.buttonButton", MerchantFrame) + pfUI.autovendor.button:SetWidth(36) + pfUI.autovendor.button:SetHeight(36) + pfUI.autovendor.button.icon = pfUI.autovendor.button:CreateTexture("BORDER") + pfUI.autovendor.button.icon:SetAllPoints(pfUI.autovendor.button) + pfUI.autovendor.button.icon:SetTexture("Interface\\Icons\\Spell_Shadow_SacrificialShield") + pfUI.autovendor.button.icon:SetVertexColor(1,.8,.4) + pfUI.autovendor.button:SetNormalTexture("") + pfUI.autovendor.button:SetPushedTexture("Interface\\Buttons\\UI-Quickslot-Depress") + pfUI.autovendor.button:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square") + pfUI.autovendor.button:SetScript("OnEnter", function() + GameTooltip:SetOwner(this, "ANCHOR_RIGHT"); + GameTooltip:SetText("Sell Grey Items"); + GameTooltip:Show(); + end) + + pfUI.autovendor.button:SetScript("OnLeave", function() + GameTooltip:Hide(); + end) + + pfUI.autovendor.button:SetScript("OnClick", function() + pfUI.autovendor:SellAllGrey() + end) + + if not pfMerchantFrame_Update then + local pfMerchantFrame_Update = MerchantFrame_Update + function _G.MerchantFrame_Update() + if MerchantFrame.selectedTab == 1 then + pfUI.autovendor.button:Show() + else + pfUI.autovendor.button:Hide() + end + pfMerchantFrame_Update() + end + end +end) diff --git a/modules/gui.lua b/modules/gui.lua index 3e4ae80d..419f7569 100644 --- a/modules/gui.lua +++ b/modules/gui.lua @@ -741,6 +741,8 @@ pfUI:RegisterModule("gui", function () pfUI.gui:CreateConfig(pfUI.gui.global, "Disable Minimap Buffs", C.global, "hidebuff", "checkbox") pfUI.gui:CreateConfig(pfUI.gui.global, "Disable Minimap Weapon Buffs", C.global, "hidewbuff", "checkbox") pfUI.gui:CreateConfig(pfUI.gui.global, "Enable 24h Clock", C.global, "twentyfour", "checkbox") + pfUI.gui:CreateConfig(pfUI.gui.global, "Auto Sell Grey Items", C.global, "autosell", "checkbox") + pfUI.gui:CreateConfig(pfUI.gui.global, "Auto Repair Items", C.global, "autorepair", "checkbox") pfUI.gui:CreateConfig(pfUI.gui.global, "Profile", nil, nil, "header") local values = {} diff --git a/pfUI.toc b/pfUI.toc index 8f8d6215..5ec77303 100644 --- a/pfUI.toc +++ b/pfUI.toc @@ -49,6 +49,7 @@ modules\castbar.lua modules\skin.lua modules\xpbar.lua modules\autoshift.lua +modules\autovendor.lua modules\bags.lua modules\cooldown.lua modules\tooltip.lua