From b608e8804b5822b60508321ffd27e4a931e82953 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: Thu, 8 Sep 2016 22:51:21 -0600 Subject: [PATCH] Pull alt currency frame out into it's own file --- AltCurrencyItem.lua | 79 +++++++++++++++++++++++++++++++++++++++ GnomishVendorShrinker.lua | 63 ++++--------------------------- GnomishVendorShrinker.toc | 2 + 3 files changed, 88 insertions(+), 56 deletions(-) create mode 100644 AltCurrencyItem.lua diff --git a/AltCurrencyItem.lua b/AltCurrencyItem.lua new file mode 100644 index 0000000..8c4501a --- /dev/null +++ b/AltCurrencyItem.lua @@ -0,0 +1,79 @@ + +local myname, ns = ... + + +local ICONSIZE, PADDING = 17, 2 +local icons, texts = {}, {} +local indexes, ids = {}, {} + + +local function OnEnter(self) + GameTooltip:SetOwner(self, "ANCHOR_RIGHT") + GameTooltip:SetMerchantCostItem(indexes[self], ids[self]) +end + + +local function OnLeave() + GameTooltip:Hide() + ResetCursor() +end + + +local function GetCurencyCount(item) + for i=1,GetCurrencyListSize() do + local name, _, _, _, _, count = GetCurrencyListInfo(i) + if item == name then return count end + end +end + + +local function GetQtyOwned(item) + local id = ns.ids[item] + if id then return GetItemCount(id, true) or 0 end + + return GetCurencyCount(item) or 0 +end + + +local function GetTextColor(price, link) + if link and (GetQtyOwned(link) < price) then return "|cffff9999" end + return "" +end + + +local function SetValue(self, i, j) + indexes[self], ids[self] = i, j + + local texture, price, link, name = GetMerchantItemCostItem(i, j) + icons[self]:SetTexture(texture) + texts[self]:SetText(GetTextColor(price, (link or name)).. price) + + self:Show() + + local _, _, width, height = self:GetBoundsRect() + self:SetSize(width, height) +end + + +function ns.NewAltCurrencyItemFrame(parent) + local frame = CreateFrame("Frame", nil, parent) + + frame:SetSize(ICONSIZE, ICONSIZE) + + local text = frame:CreateFontString(nil, nil, "NumberFontNormalSmall") + text:SetPoint("LEFT") + texts[frame] = text + + local icon = frame:CreateTexture() + icon:SetSize(ICONSIZE, ICONSIZE) + icon:SetPoint("LEFT", text, "RIGHT", PADDING, 0) + icons[frame] = icon + + frame.SetValue = SetValue + + frame:EnableMouse(true) + frame:SetScript("OnEnter", OnEnter) + frame:SetScript("OnLeave", OnLeave) + + return frame +end diff --git a/GnomishVendorShrinker.lua b/GnomishVendorShrinker.lua index d2293a8..82bdb03 100644 --- a/GnomishVendorShrinker.lua +++ b/GnomishVendorShrinker.lua @@ -77,63 +77,15 @@ local function PopoutSplitStack(self, qty) end -local function OnEnter(self) - GameTooltip:SetOwner(self, "ANCHOR_RIGHT") - if self.link then GameTooltip:SetHyperlink(self.link) else GameTooltip:SetMerchantCostItem(self.index, self.itemIndex) end -end - - -local function OnLeave() - GameTooltip:Hide() - ResetCursor() -end - - -local function GetCurencyCount(item) - for i=1,GetCurrencyListSize() do - local name, _, _, _, _, count = GetCurrencyListInfo(i) - if item == name then return count end - end -end - - -local function SetValue(self, text, icon, link) - local color = "" - local id = link and link:match("item:(%d+)") - self.link, self.index, self.itemIndex = nil - if id then self.link = link end - if id and (GetItemCount(id, true) or 0) < text or link and not id and (GetCurencyCount(link) or 0) < text then - color = "|cffff9999" - end - self.text:SetText(color..text) - self.icon:SetTexture(icon) - self:Show() -end - - local function GetAltCurrencyFrame(frame) for i,v in ipairs(frame.altframes) do if not v:IsShown() then return v end end - local anchor = #frame.altframes > 0 and frame.altframes[#frame.altframes].text - local f = CreateFrame('Frame', nil, frame) - f:SetWidth(ICONSIZE) f:SetHeight(ICONSIZE) - f:SetPoint("RIGHT", anchor or frame.ItemPrice, "LEFT") + local anchor = #frame.altframes > 0 and frame.altframes[#frame.altframes] + local item = ns.NewAltCurrencyItemFrame(frame) + item:SetPoint("RIGHT", anchor or frame.ItemPrice, "LEFT") - f.icon = f:CreateTexture() - f.icon:SetWidth(ICONSIZE) f.icon:SetHeight(ICONSIZE) - f.icon:SetPoint("RIGHT") - - f.text = f:CreateFontString(nil, nil, "NumberFontNormalSmall") - f.text:SetPoint("RIGHT", f.icon, "LEFT", -GAP/2, 0) - - f.SetValue = SetValue - - f:EnableMouse(true) - f:SetScript("OnEnter", OnEnter) - f:SetScript("OnLeave", OnLeave) - - table.insert(frame.altframes, f) - return f + table.insert(frame.altframes, item) + return item end @@ -142,9 +94,8 @@ local function AddAltCurrency(frame, i) for j=GetMerchantItemCostInfo(i),1,-1 do local f = frame:GetAltCurrencyFrame() local texture, price, link, name = GetMerchantItemCostItem(i, j) - f:SetValue(price, texture, link or name) - f.index, f.itemIndex, f.link = i, j - lastframe = f.text + f:SetValue(i, j) + lastframe = f end frame.ItemName:SetPoint("RIGHT", lastframe, "LEFT", -GAP, 0) end diff --git a/GnomishVendorShrinker.toc b/GnomishVendorShrinker.toc index 6338a21..47d0bac 100644 --- a/GnomishVendorShrinker.toc +++ b/GnomishVendorShrinker.toc @@ -17,6 +17,8 @@ tekFunks\gsc.lua tekKonfig\tekKonfig.xml LibItemSearch-1.0.lua +AltCurrencyItem.lua RowShader.lua + KnownScanner.lua GnomishVendorShrinker.lua