Clean up MerchantItem a bit

This commit is contained in:
tekkub ʕ ´ᴥ` ʔ 2016-09-10 19:01:22 -06:00
parent 2d7d300124
commit f0aac0b382
1 changed files with 37 additions and 27 deletions

View File

@ -28,6 +28,29 @@ local function OnClick(self, button)
end end
local function OnDragStart(self, button)
MerchantFrame.extendedCost = nil
PickupMerchantItem(self:GetID())
if self.extendedCost then MerchantFrame.extendedCost = self end
end
local function OnEnter(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetMerchantItem(self:GetID())
GameTooltip_ShowCompareItem()
MerchantFrame.itemHover = self:GetID()
if IsModifiedClick("DRESSUP") then ShowInspectCursor() else ResetCursor() end
end
local function OnLeave()
GameTooltip:Hide()
ResetCursor()
MerchantFrame.itemHover = nil
end
function ns.Purchase(id, quantity) function ns.Purchase(id, quantity)
local _, _, _, _, available = GetMerchantItemInfo(id) local _, _, _, _, available = GetMerchantItemInfo(id)
local max = GetMerchantItemMaxStack(id) local max = GetMerchantItemMaxStack(id)
@ -65,9 +88,15 @@ local function SetValue(self, i)
self.backdrop:SetShown(shown) self.backdrop:SetShown(shown)
self.icon:SetTexture(itemTexture) self.icon:SetTexture(itemTexture)
self.icon:SetVertexColor(ns.GetRowVertexColor(i))
local textcolor = ns.GetRowTextColor(i) local textcolor = ns.GetRowTextColor(i)
self.ItemName:SetText((numAvailable > -1 and ("["..numAvailable.."] ") or "").. textcolor.. (name or "<Loading item data>").. (itemStackCount > 1 and ("|r x"..itemStackCount) or "")) local text =
(numAvailable > -1 and ("["..numAvailable.."] ") or "")..
textcolor..
(name or "<Loading item data>")..
(itemStackCount > 1 and ("|r x"..itemStackCount) or "")
self.ItemName:SetText(text)
self.AltCurrency:SetValue(i) self.AltCurrency:SetValue(i)
@ -86,8 +115,6 @@ local function SetValue(self, i)
else else
self.extendedCost = nil self.extendedCost = nil
end end
self.icon:SetVertexColor(ns.GetRowVertexColor(i))
end end
@ -95,19 +122,18 @@ function ns.NewMerchantItemFrame(parent)
local frame = CreateFrame("Button", nil, parent) local frame = CreateFrame("Button", nil, parent)
frame:SetHeight(HEIGHT) frame:SetHeight(HEIGHT)
frame.BuyItem = BuyItem
frame:SetHighlightTexture("Interface\\HelpFrame\\HelpFrameButton-Highlight") frame:SetHighlightTexture("Interface\\HelpFrame\\HelpFrameButton-Highlight")
frame:GetHighlightTexture():SetTexCoord(0, 1, 0, 0.578125) frame:GetHighlightTexture():SetTexCoord(0, 1, 0, 0.578125)
frame:RegisterForClicks("AnyUp") frame:RegisterForClicks("AnyUp")
frame:SetScript('OnClick', OnClick)
frame:RegisterForDrag("LeftButton") frame:RegisterForDrag("LeftButton")
frame:SetScript('OnDragStart', function(self, button) frame:SetScript("OnClick", OnClick)
MerchantFrame.extendedCost = nil frame:SetScript("OnDragStart", OnDragStart)
PickupMerchantItem(self:GetID()) frame:SetScript("OnEnter", OnEnter)
if self.extendedCost then MerchantFrame.extendedCost = self end frame:SetScript("OnLeave", OnLeave)
end)
frame.BuyItem = BuyItem
frame.SetValue = SetValue
local backdrop = frame:CreateTexture(nil, "BACKGROUND") local backdrop = frame:CreateTexture(nil, "BACKGROUND")
backdrop:SetAllPoints() backdrop:SetAllPoints()
@ -141,21 +167,5 @@ function ns.NewMerchantItemFrame(parent)
ItemName:SetJustifyH("LEFT") ItemName:SetJustifyH("LEFT")
frame.ItemName = ItemName frame.ItemName = ItemName
frame:SetScript('OnEnter', function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetMerchantItem(self:GetID())
GameTooltip_ShowCompareItem()
MerchantFrame.itemHover = self:GetID()
if IsModifiedClick("DRESSUP") then ShowInspectCursor() else ResetCursor() end
end)
frame:SetScript('OnLeave', function()
GameTooltip:Hide()
ResetCursor()
MerchantFrame.itemHover = nil
end)
frame.SetValue = SetValue
return frame return frame
end end