Pull alt currency frame out into it's own file

This commit is contained in:
tekkub ʕ ´ᴥ` ʔ 2016-09-08 22:51:21 -06:00
parent 9c853b301e
commit b608e8804b
3 changed files with 88 additions and 56 deletions

79
AltCurrencyItem.lua Normal file
View File

@ -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

View File

@ -77,63 +77,15 @@ local function PopoutSplitStack(self, qty)
end 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) local function GetAltCurrencyFrame(frame)
for i,v in ipairs(frame.altframes) do if not v:IsShown() then return v end end 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 anchor = #frame.altframes > 0 and frame.altframes[#frame.altframes]
local f = CreateFrame('Frame', nil, frame) local item = ns.NewAltCurrencyItemFrame(frame)
f:SetWidth(ICONSIZE) f:SetHeight(ICONSIZE) item:SetPoint("RIGHT", anchor or frame.ItemPrice, "LEFT")
f:SetPoint("RIGHT", anchor or frame.ItemPrice, "LEFT")
f.icon = f:CreateTexture() table.insert(frame.altframes, item)
f.icon:SetWidth(ICONSIZE) f.icon:SetHeight(ICONSIZE) return item
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
end end
@ -142,9 +94,8 @@ local function AddAltCurrency(frame, i)
for j=GetMerchantItemCostInfo(i),1,-1 do for j=GetMerchantItemCostInfo(i),1,-1 do
local f = frame:GetAltCurrencyFrame() local f = frame:GetAltCurrencyFrame()
local texture, price, link, name = GetMerchantItemCostItem(i, j) local texture, price, link, name = GetMerchantItemCostItem(i, j)
f:SetValue(price, texture, link or name) f:SetValue(i, j)
f.index, f.itemIndex, f.link = i, j lastframe = f
lastframe = f.text
end end
frame.ItemName:SetPoint("RIGHT", lastframe, "LEFT", -GAP, 0) frame.ItemName:SetPoint("RIGHT", lastframe, "LEFT", -GAP, 0)
end end

View File

@ -17,6 +17,8 @@ tekFunks\gsc.lua
tekKonfig\tekKonfig.xml tekKonfig\tekKonfig.xml
LibItemSearch-1.0.lua LibItemSearch-1.0.lua
AltCurrencyItem.lua
RowShader.lua RowShader.lua
KnownScanner.lua KnownScanner.lua
GnomishVendorShrinker.lua GnomishVendorShrinker.lua