Pull Alt Currency frame out into its own file
This commit is contained in:
parent
b608e8804b
commit
79f543afa0
|
@ -0,0 +1,48 @@
|
|||
|
||||
local myname, ns = ...
|
||||
|
||||
|
||||
local function NewItemFrame(self, i)
|
||||
local item = ns.NewAltCurrencyItemFrame(self.parent)
|
||||
|
||||
if i == 1 then
|
||||
item:SetPoint("LEFT")
|
||||
else
|
||||
item:SetPoint("LEFT", self[i-1], "RIGHT")
|
||||
end
|
||||
|
||||
self[i] = item
|
||||
return item
|
||||
end
|
||||
|
||||
|
||||
local itemframesets = {}
|
||||
local function SetValue(self, i)
|
||||
local items = itemframesets[self]
|
||||
for _,item in ipairs(items) do item:Hide() end
|
||||
|
||||
local num = GetMerchantItemCostInfo(i)
|
||||
self:SetShown(num > 0)
|
||||
|
||||
if num > 0 then
|
||||
for j=1,num do items[j]:SetValue(i, j) end
|
||||
self:SizeToFit()
|
||||
else
|
||||
self:SetWidth(0)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local frames = {}
|
||||
local MT = {__index = NewItemFrame}
|
||||
function ns.NewAltCurrencyFrame(parent)
|
||||
local frame = CreateFrame("Frame", nil, parent)
|
||||
frame:SetSize(1,1)
|
||||
|
||||
itemframesets[frame] = setmetatable({parent = frame}, MT)
|
||||
|
||||
frame.SetValue = SetValue
|
||||
frame.SizeToFit = ns.SizeToFit
|
||||
|
||||
return frame
|
||||
end
|
|
@ -49,15 +49,11 @@ local function SetValue(self, i, j)
|
|||
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")
|
||||
|
@ -70,6 +66,7 @@ function ns.NewAltCurrencyItemFrame(parent)
|
|||
icons[frame] = icon
|
||||
|
||||
frame.SetValue = SetValue
|
||||
frame.SizeToFit = ns.SizeToFit
|
||||
|
||||
frame:EnableMouse(true)
|
||||
frame:SetScript("OnEnter", OnEnter)
|
||||
|
|
|
@ -22,9 +22,9 @@ GVS:Hide()
|
|||
|
||||
|
||||
local function OnClick(self, button)
|
||||
if IsAltKeyDown() and not self.altcurrency then self:BuyItem(true)
|
||||
if IsAltKeyDown() and not self.AltCurrency:IsShown() then self:BuyItem(true)
|
||||
elseif IsModifiedClick() then HandleModifiedItemClick(GetMerchantItemLink(self:GetID()))
|
||||
elseif self.altcurrency then
|
||||
elseif self.AltCurrency:IsShown() then
|
||||
local id = self:GetID()
|
||||
local link = GetMerchantItemLink(id)
|
||||
self.link, self.texture = GetMerchantItemLink(id), self.icon:GetTexture()
|
||||
|
@ -77,30 +77,6 @@ local function PopoutSplitStack(self, qty)
|
|||
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]
|
||||
local item = ns.NewAltCurrencyItemFrame(frame)
|
||||
item:SetPoint("RIGHT", anchor or frame.ItemPrice, "LEFT")
|
||||
|
||||
table.insert(frame.altframes, item)
|
||||
return item
|
||||
end
|
||||
|
||||
|
||||
local function AddAltCurrency(frame, i)
|
||||
local lastframe = frame.ItemPrice
|
||||
for j=GetMerchantItemCostInfo(i),1,-1 do
|
||||
local f = frame:GetAltCurrencyFrame()
|
||||
local texture, price, link, name = GetMerchantItemCostItem(i, j)
|
||||
f:SetValue(i, j)
|
||||
lastframe = f
|
||||
end
|
||||
frame.ItemName:SetPoint("RIGHT", lastframe, "LEFT", -GAP, 0)
|
||||
end
|
||||
|
||||
|
||||
local ROWHEIGHT = 21
|
||||
local rows = {}
|
||||
for i=1,NUMROWS do
|
||||
|
@ -137,11 +113,6 @@ for i=1,NUMROWS do
|
|||
row.icon = icon:CreateTexture(nil, "BORDER")
|
||||
row.icon:SetAllPoints()
|
||||
|
||||
local ItemName = row:CreateFontString(nil, nil, "GameFontNormalSmall")
|
||||
ItemName:SetPoint('LEFT', icon, "RIGHT", GAP, 0)
|
||||
ItemName:SetJustifyH('LEFT')
|
||||
row.ItemName = ItemName
|
||||
|
||||
local popout = CreateFrame("Button", nil, row)
|
||||
popout:SetPoint("RIGHT")
|
||||
popout:SetWidth(ROWHEIGHT/2) popout:SetHeight(ROWHEIGHT)
|
||||
|
@ -157,8 +128,15 @@ for i=1,NUMROWS do
|
|||
ItemPrice:SetPoint('RIGHT', popout, "LEFT", -2, 0)
|
||||
row.ItemPrice = ItemPrice
|
||||
|
||||
row.altframes = {}
|
||||
row.AddAltCurrency, row.GetAltCurrencyFrame = AddAltCurrency, GetAltCurrencyFrame
|
||||
local AltCurrency = ns.NewAltCurrencyFrame(row)
|
||||
AltCurrency:SetPoint("RIGHT", ItemPrice, "LEFT")
|
||||
row.AltCurrency = AltCurrency
|
||||
|
||||
local ItemName = row:CreateFontString(nil, nil, "GameFontNormalSmall")
|
||||
ItemName:SetPoint("LEFT", icon, "RIGHT", GAP, 0)
|
||||
ItemName:SetPoint("RIGHT", AltCurrency, "LEFT", -GAP, 0)
|
||||
ItemName:SetJustifyH("LEFT")
|
||||
row.ItemName = ItemName
|
||||
|
||||
row:SetScript('OnEnter', function(self)
|
||||
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
|
||||
|
@ -178,6 +156,9 @@ end
|
|||
|
||||
|
||||
local function ShowMerchantItem(row, i)
|
||||
row:SetID(i)
|
||||
row:Show()
|
||||
|
||||
local name, itemTexture, itemPrice, itemStackCount, numAvailable, isUsable, extendedCost = GetMerchantItemInfo(i)
|
||||
local link = GetMerchantItemLink(i)
|
||||
|
||||
|
@ -190,10 +171,9 @@ local function ShowMerchantItem(row, i)
|
|||
local textcolor = ns.GetRowTextColor(i)
|
||||
row.ItemName:SetText((numAvailable > -1 and ("["..numAvailable.."] ") or "").. textcolor.. (name or "<Loading item data>").. (itemStackCount > 1 and ("|r x"..itemStackCount) or ""))
|
||||
|
||||
for i,v in pairs(row.altframes) do v:Hide() end
|
||||
row.altcurrency = extendedCost
|
||||
row.AltCurrency:SetValue(i)
|
||||
|
||||
if extendedCost then
|
||||
row:AddAltCurrency(i)
|
||||
row.link, row.texture, row.extendedCost = link, itemTexture, true
|
||||
end
|
||||
if itemPrice > 0 then
|
||||
|
@ -201,19 +181,15 @@ local function ShowMerchantItem(row, i)
|
|||
row.Price = itemPrice
|
||||
end
|
||||
if extendedCost and (itemPrice <= 0) then
|
||||
row.ItemPrice:SetText()
|
||||
row.ItemPrice:SetText("")
|
||||
row.Price = 0
|
||||
elseif extendedCost and (itemPrice > 0) then
|
||||
row.ItemPrice:SetText(ns.GSC(itemPrice))
|
||||
else
|
||||
row.ItemName:SetPoint("RIGHT", row.ItemPrice, "LEFT", -GAP, 0)
|
||||
row.extendedCost = nil
|
||||
end
|
||||
|
||||
row.icon:SetVertexColor(ns.GetRowVertexColor(i))
|
||||
|
||||
row:SetID(i)
|
||||
row:Show()
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -11,12 +11,14 @@
|
|||
## X-LoadOn-InterfaceOptions: GnomishVendorShrinker
|
||||
|
||||
externals\itemid.lua
|
||||
externals\size_to_fit.lua
|
||||
externals\tooltip_scanner.lua
|
||||
|
||||
tekFunks\gsc.lua
|
||||
tekKonfig\tekKonfig.xml
|
||||
LibItemSearch-1.0.lua
|
||||
|
||||
AltCurrency.lua
|
||||
AltCurrencyItem.lua
|
||||
RowShader.lua
|
||||
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
itemid.lua
|
||||
size_to_fit.lua
|
||||
tooltip_scanner.lua
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
|
||||
local myname, ns = ...
|
||||
|
||||
|
||||
-- Resize a frame to fit all its visible children. Useful for creating frames
|
||||
-- that adjust to their contents while reducing couping between those frames
|
||||
--
|
||||
-- Attach to a frame by using `frame.SizeToFit = ns.SizeToFit`. Call with colon
|
||||
-- syntax, i.e. `frame:SizeToFit()` on the eldest frame you want to resize.
|
||||
-- All children with this helper will be resized if they are currently shown.
|
||||
|
||||
|
||||
local function ResizeChildren(...)
|
||||
for i=1,select("#", ...) do
|
||||
local child = select(i, ...)
|
||||
if child.SizeToFit and child:IsShown() then child:SizeToFit() end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function ns.SizeToFit(self)
|
||||
-- The frame must be visible for `GetBoundsRect()` to work. That means it has
|
||||
-- to be "Shown" and have non-zero dimensions
|
||||
self:Show()
|
||||
self:SetSize(1, 1)
|
||||
|
||||
-- Child frames need to be resized first
|
||||
ResizeChildren(self:GetChildren())
|
||||
|
||||
-- Now resize ourself
|
||||
local _, _, width, height = self:GetBoundsRect()
|
||||
self:SetSize(width, height)
|
||||
end
|
Loading…
Reference in New Issue