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)
|
texts[self]:SetText(GetTextColor(price, (link or name)).. price)
|
||||||
|
|
||||||
self:Show()
|
self:Show()
|
||||||
|
|
||||||
local _, _, width, height = self:GetBoundsRect()
|
|
||||||
self:SetSize(width, height)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function ns.NewAltCurrencyItemFrame(parent)
|
function ns.NewAltCurrencyItemFrame(parent)
|
||||||
local frame = CreateFrame("Frame", nil, parent)
|
local frame = CreateFrame("Frame", nil, parent)
|
||||||
|
|
||||||
frame:SetSize(ICONSIZE, ICONSIZE)
|
frame:SetSize(ICONSIZE, ICONSIZE)
|
||||||
|
|
||||||
local text = frame:CreateFontString(nil, nil, "NumberFontNormalSmall")
|
local text = frame:CreateFontString(nil, nil, "NumberFontNormalSmall")
|
||||||
|
@ -70,6 +66,7 @@ function ns.NewAltCurrencyItemFrame(parent)
|
||||||
icons[frame] = icon
|
icons[frame] = icon
|
||||||
|
|
||||||
frame.SetValue = SetValue
|
frame.SetValue = SetValue
|
||||||
|
frame.SizeToFit = ns.SizeToFit
|
||||||
|
|
||||||
frame:EnableMouse(true)
|
frame:EnableMouse(true)
|
||||||
frame:SetScript("OnEnter", OnEnter)
|
frame:SetScript("OnEnter", OnEnter)
|
||||||
|
|
|
@ -22,9 +22,9 @@ GVS:Hide()
|
||||||
|
|
||||||
|
|
||||||
local function OnClick(self, button)
|
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 IsModifiedClick() then HandleModifiedItemClick(GetMerchantItemLink(self:GetID()))
|
||||||
elseif self.altcurrency then
|
elseif self.AltCurrency:IsShown() then
|
||||||
local id = self:GetID()
|
local id = self:GetID()
|
||||||
local link = GetMerchantItemLink(id)
|
local link = GetMerchantItemLink(id)
|
||||||
self.link, self.texture = GetMerchantItemLink(id), self.icon:GetTexture()
|
self.link, self.texture = GetMerchantItemLink(id), self.icon:GetTexture()
|
||||||
|
@ -77,30 +77,6 @@ local function PopoutSplitStack(self, qty)
|
||||||
end
|
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 ROWHEIGHT = 21
|
||||||
local rows = {}
|
local rows = {}
|
||||||
for i=1,NUMROWS do
|
for i=1,NUMROWS do
|
||||||
|
@ -137,11 +113,6 @@ for i=1,NUMROWS do
|
||||||
row.icon = icon:CreateTexture(nil, "BORDER")
|
row.icon = icon:CreateTexture(nil, "BORDER")
|
||||||
row.icon:SetAllPoints()
|
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)
|
local popout = CreateFrame("Button", nil, row)
|
||||||
popout:SetPoint("RIGHT")
|
popout:SetPoint("RIGHT")
|
||||||
popout:SetWidth(ROWHEIGHT/2) popout:SetHeight(ROWHEIGHT)
|
popout:SetWidth(ROWHEIGHT/2) popout:SetHeight(ROWHEIGHT)
|
||||||
|
@ -157,8 +128,15 @@ for i=1,NUMROWS do
|
||||||
ItemPrice:SetPoint('RIGHT', popout, "LEFT", -2, 0)
|
ItemPrice:SetPoint('RIGHT', popout, "LEFT", -2, 0)
|
||||||
row.ItemPrice = ItemPrice
|
row.ItemPrice = ItemPrice
|
||||||
|
|
||||||
row.altframes = {}
|
local AltCurrency = ns.NewAltCurrencyFrame(row)
|
||||||
row.AddAltCurrency, row.GetAltCurrencyFrame = AddAltCurrency, GetAltCurrencyFrame
|
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)
|
row:SetScript('OnEnter', function(self)
|
||||||
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
|
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
|
||||||
|
@ -178,6 +156,9 @@ end
|
||||||
|
|
||||||
|
|
||||||
local function ShowMerchantItem(row, i)
|
local function ShowMerchantItem(row, i)
|
||||||
|
row:SetID(i)
|
||||||
|
row:Show()
|
||||||
|
|
||||||
local name, itemTexture, itemPrice, itemStackCount, numAvailable, isUsable, extendedCost = GetMerchantItemInfo(i)
|
local name, itemTexture, itemPrice, itemStackCount, numAvailable, isUsable, extendedCost = GetMerchantItemInfo(i)
|
||||||
local link = GetMerchantItemLink(i)
|
local link = GetMerchantItemLink(i)
|
||||||
|
|
||||||
|
@ -190,10 +171,9 @@ local function ShowMerchantItem(row, i)
|
||||||
local textcolor = ns.GetRowTextColor(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 ""))
|
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:SetValue(i)
|
||||||
row.altcurrency = extendedCost
|
|
||||||
if extendedCost then
|
if extendedCost then
|
||||||
row:AddAltCurrency(i)
|
|
||||||
row.link, row.texture, row.extendedCost = link, itemTexture, true
|
row.link, row.texture, row.extendedCost = link, itemTexture, true
|
||||||
end
|
end
|
||||||
if itemPrice > 0 then
|
if itemPrice > 0 then
|
||||||
|
@ -201,19 +181,15 @@ local function ShowMerchantItem(row, i)
|
||||||
row.Price = itemPrice
|
row.Price = itemPrice
|
||||||
end
|
end
|
||||||
if extendedCost and (itemPrice <= 0) then
|
if extendedCost and (itemPrice <= 0) then
|
||||||
row.ItemPrice:SetText()
|
row.ItemPrice:SetText("")
|
||||||
row.Price = 0
|
row.Price = 0
|
||||||
elseif extendedCost and (itemPrice > 0) then
|
elseif extendedCost and (itemPrice > 0) then
|
||||||
row.ItemPrice:SetText(ns.GSC(itemPrice))
|
row.ItemPrice:SetText(ns.GSC(itemPrice))
|
||||||
else
|
else
|
||||||
row.ItemName:SetPoint("RIGHT", row.ItemPrice, "LEFT", -GAP, 0)
|
|
||||||
row.extendedCost = nil
|
row.extendedCost = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
row.icon:SetVertexColor(ns.GetRowVertexColor(i))
|
row.icon:SetVertexColor(ns.GetRowVertexColor(i))
|
||||||
|
|
||||||
row:SetID(i)
|
|
||||||
row:Show()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,12 +11,14 @@
|
||||||
## X-LoadOn-InterfaceOptions: GnomishVendorShrinker
|
## X-LoadOn-InterfaceOptions: GnomishVendorShrinker
|
||||||
|
|
||||||
externals\itemid.lua
|
externals\itemid.lua
|
||||||
|
externals\size_to_fit.lua
|
||||||
externals\tooltip_scanner.lua
|
externals\tooltip_scanner.lua
|
||||||
|
|
||||||
tekFunks\gsc.lua
|
tekFunks\gsc.lua
|
||||||
tekKonfig\tekKonfig.xml
|
tekKonfig\tekKonfig.xml
|
||||||
LibItemSearch-1.0.lua
|
LibItemSearch-1.0.lua
|
||||||
|
|
||||||
|
AltCurrency.lua
|
||||||
AltCurrencyItem.lua
|
AltCurrencyItem.lua
|
||||||
RowShader.lua
|
RowShader.lua
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
itemid.lua
|
itemid.lua
|
||||||
|
size_to_fit.lua
|
||||||
tooltip_scanner.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