From 2d7d300124ae0978595443a6d979a48e1c0bcfd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tekkub=20=CA=95=20=C2=B4=E1=B4=A5=60=20=CA=94?= Date: Sat, 10 Sep 2016 19:00:35 -0600 Subject: [PATCH] Pull qty popout into its own file --- GnomishVendorShrinker.toc | 1 + frames/MerchantItem.lua | 43 ++++++++------------------------------- frames/QtyPopout.lua | 37 +++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 34 deletions(-) create mode 100644 frames/QtyPopout.lua diff --git a/GnomishVendorShrinker.toc b/GnomishVendorShrinker.toc index 5816cd3..ef2c3b9 100644 --- a/GnomishVendorShrinker.toc +++ b/GnomishVendorShrinker.toc @@ -22,6 +22,7 @@ LibItemSearch-1.0.lua frames\AltCurrency.lua frames\AltCurrencyItem.lua frames\MerchantItem.lua +frames\QtyPopout.lua frames\RowShader.lua frames\SearchField.lua diff --git a/frames/MerchantItem.lua b/frames/MerchantItem.lua index e3f165b..1ae7390 100644 --- a/frames/MerchantItem.lua +++ b/frames/MerchantItem.lua @@ -23,33 +23,19 @@ local function OnClick(self, button) MerchantFrame_ConfirmExtendedItemCost(self) else - self:BuyItem() + self:BuyItem() end end -local function PopoutOnClick(self, button) - local id = self:GetParent():GetID() - local link = GetMerchantItemLink(id) - if not link then return end +function ns.Purchase(id, quantity) + local _, _, _, _, available = GetMerchantItemInfo(id) + local max = GetMerchantItemMaxStack(id) - local _, _, _, vendorStackSize, numAvailable = GetMerchantItemInfo(id) - local maxPurchase = GetMerchantItemMaxStack(id) - local _, _, _, _, _, _, _, itemStackSize = GetItemInfo(link) - - local size = numAvailable > 0 and numAvailable or itemStackSize - OpenStackSplitFrame(250, self, "LEFT", "RIGHT") -end - - -local function Purchase(id, quantity) - local _, _, _, vendorStackSize, numAvailable = GetMerchantItemInfo(id) - local maxPurchase = GetMerchantItemMaxStack(id) - - if numAvailable > 0 and numAvailable < quantity then quantity = numAvailable end + if available > 0 and available < quantity then quantity = available end local purchased = 0 while purchased < quantity do - local buyamount = math.min(maxPurchase, quantity - purchased) + local buyamount = math.min(max, quantity - purchased) purchased = purchased + buyamount BuyMerchantItem(id, buyamount) end @@ -63,12 +49,7 @@ local function BuyItem(self, fullstack) local _, _, _, vendorStackSize = GetMerchantItemInfo(id) local _, _, _, _, _, _, _, itemStackSize = GetItemInfo(link) - Purchase(id, fullstack and itemStackSize or vendorStackSize or 1) -end - - -local function PopoutSplitStack(self, qty) - Purchase(self:GetParent():GetID(), qty) + ns.Purchase(id, fullstack and itemStackSize or vendorStackSize or 1) end @@ -141,15 +122,9 @@ function ns.NewMerchantItemFrame(parent) frame.icon = icon:CreateTexture(nil, "BORDER") frame.icon:SetAllPoints() - local popout = CreateFrame("Button", nil, frame) + local popout = ns.NewQtyPopoutFrame(frame) popout:SetPoint("RIGHT") - popout:SetWidth(HEIGHT/2) popout:SetHeight(HEIGHT) - popout:SetNormalTexture("Interface\\PaperDollInfoFrame\\UI-GearManager-FlyoutButton") - popout:SetHighlightTexture("Interface\\PaperDollInfoFrame\\UI-GearManager-FlyoutButton") - popout:GetNormalTexture():SetTexCoord(0.15625, 0.5, 0.84375, 0.5, 0.15625, 0, 0.84375, 0) - popout:GetHighlightTexture():SetTexCoord(0.15625, 1, 0.84375, 1, 0.15625, 0.5, 0.84375, 0.5) - popout:SetScript("OnClick", PopoutOnClick) - popout.SplitStack = PopoutSplitStack + popout:SetSize(HEIGHT/2, HEIGHT) frame.popout = popout local ItemPrice = frame:CreateFontString(nil, nil, "NumberFontNormal") diff --git a/frames/QtyPopout.lua b/frames/QtyPopout.lua new file mode 100644 index 0000000..382c769 --- /dev/null +++ b/frames/QtyPopout.lua @@ -0,0 +1,37 @@ + +local myname, ns = ... + + +local function OnClick(self, button) + local id = self:GetParent():GetID() + local link = GetMerchantItemLink(id) + if not link then return end + + local _, _, _, vendorStackSize, numAvailable = GetMerchantItemInfo(id) + local maxPurchase = GetMerchantItemMaxStack(id) + local _, _, _, _, _, _, _, itemStackSize = GetItemInfo(link) + + local size = numAvailable > 0 and numAvailable or itemStackSize + OpenStackSplitFrame(250, self, "LEFT", "RIGHT") +end + + +local function PopoutSplitStack(self, qty) + ns.Purchase(self:GetParent():GetID(), qty) +end + + +function ns.NewQtyPopoutFrame(parent) + local frame = CreateFrame("Button", nil, parent) + + frame:SetNormalTexture("Interface\\PaperDollInfoFrame\\UI-GearManager-FlyoutButton") + frame:SetHighlightTexture("Interface\\PaperDollInfoFrame\\UI-GearManager-FlyoutButton") + frame:GetNormalTexture():SetTexCoord(0.15625, 0.5, 0.84375, 0.5, 0.15625, 0, 0.84375, 0) + frame:GetHighlightTexture():SetTexCoord(0.15625, 1, 0.84375, 1, 0.15625, 0.5, 0.84375, 0.5) + + frame:SetScript("OnClick", OnClick) + + frame.SplitStack = PopoutSplitStack + + return frame +end