GnomishVendorShrinker/GnomishVendorShrinker.lua

398 lines
12 KiB
Lua
Raw Normal View History

2009-08-14 05:09:03 +00:00
2010-05-02 22:20:55 +00:00
local myname, ns = ...
2010-10-03 23:15:21 +00:00
ns.IHASCAT = select(4, GetBuildInfo()) >= 40000
2010-05-02 22:20:55 +00:00
2009-08-14 05:09:03 +00:00
local NUMROWS, ICONSIZE, GAP, SCROLLSTEP = 14, 17, 4, 5
local HONOR_POINTS, ARENA_POINTS = "|cffffffff|Hitem:43308:0:0:0:0:0:0:0:0|h[Honor Points]|h|r", "|cffffffff|Hitem:43307:0:0:0:0:0:0:0:0|h[Arena Points]|h|r"
2009-08-14 05:09:03 +00:00
for _,f in pairs{MerchantNextPageButton, MerchantPrevPageButton, MerchantPageText} do
f:Hide()
f.Show = f.Hide
end
local GVS = CreateFrame("frame", nil, MerchantFrame)
GVS:SetWidth(315)
GVS:SetHeight(294)
GVS:SetPoint("TOPLEFT", 21, -77)
GVS:SetScript("OnEvent", function(self, event, ...) if self[event] then return self[event](self, event, ...) end end)
GVS:Hide()
local function OnClick(self, button)
if IsAltKeyDown() and not self.altcurrency then self:BuyItem(true)
elseif IsModifiedClick() then HandleModifiedItemClick(GetMerchantItemLink(self:GetID()))
elseif self.altcurrency then
local id = self:GetID()
local link = GetMerchantItemLink(id)
self.link, self.texture = GetMerchantItemLink(id), self.icon:GetTexture()
MerchantFrame_ConfirmExtendedItemCost(self)
else self:BuyItem() end
end
local function PopoutOnClick(self, button)
local id = self:GetParent():GetID()
2009-08-14 05:09:03 +00:00
local link = GetMerchantItemLink(id)
if not link then return end
local _, _, _, vendorStackSize, numAvailable = GetMerchantItemInfo(id)
local maxPurchase = GetMerchantItemMaxStack(id)
local _, _, _, _, _, _, _, itemStackSize = GetItemInfo(link)
local size = numAvailable > 0 and numAvailable or itemStackSize
-- OpenStackSplitFrame(size, self, "LEFT", "RIGHT")
OpenStackSplitFrame(250, self, "LEFT", "RIGHT")
end
local function Purchase(id, quantity)
local _, _, _, vendorStackSize, numAvailable = GetMerchantItemInfo(id)
local maxPurchase = GetMerchantItemMaxStack(id)
2009-08-14 05:09:03 +00:00
if numAvailable > 0 and numAvailable < quantity then quantity = numAvailable end
local purchased = 0
while purchased < quantity do
local buyamount = math.min(maxPurchase, quantity - purchased)
purchased = purchased + buyamount
BuyMerchantItem(id, buyamount)
end
end
local function BuyItem(self, fullstack)
local id = self:GetID()
local link = GetMerchantItemLink(id)
if not link then return end
2010-10-15 05:09:52 +00:00
local _, _, _, vendorStackSize = GetMerchantItemInfo(id)
local _, _, _, _, _, _, _, itemStackSize = GetItemInfo(link)
Purchase(id, fullstack and itemStackSize or vendorStackSize or 1)
end
local function PopoutSplitStack(self, qty)
Purchase(self:GetParent():GetID(), qty)
end
2009-08-14 05:09:03 +00:00
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
2009-08-14 05:09:03 +00:00
end
local function OnLeave()
GameTooltip:Hide()
ResetCursor()
end
local function SetValue(self, text, icon, link)
2009-08-14 05:09:03 +00:00
self.text:SetText(text)
self.icon:SetTexture(icon)
self.link, self.index, self.itemIndex = link
if link == HONOR_POINTS then
2009-08-14 05:09:03 +00:00
self.icon:SetPoint("RIGHT", -2, 0)
self.text:SetPoint("RIGHT", self.icon, "LEFT", -GAP/2 + 2, 0)
else
self.icon:SetPoint("RIGHT")
self.text:SetPoint("RIGHT", self.icon, "LEFT", -GAP/2, 0)
end
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)
2009-08-27 07:53:55 +00:00
f:SetPoint("RIGHT", anchor or frame.ItemPrice, "LEFT")
2009-08-14 05:09:03 +00:00
f.icon = f:CreateTexture()
f.icon:SetWidth(ICONSIZE) f.icon:SetHeight(ICONSIZE)
f.text = f:CreateFontString(nil, nil, "NumberFontNormalSmall")
f.SetValue = SetValue
f:EnableMouse(true)
f:SetScript("OnEnter", OnEnter)
f:SetScript("OnLeave", OnLeave)
table.insert(frame.altframes, f)
return f
end
local function AddAltCurrency(frame, i)
local lastframe = frame.ItemPrice
local honorPoints, arenaPoints, itemCount = GetMerchantItemCostInfo(i)
2010-10-03 23:15:21 +00:00
if ns.IHASCAT then itemCount, honorPoints, arenaPoints = honorPoints, 0, 0 end
2009-08-14 05:09:03 +00:00
for j=itemCount,1,-1 do
local f = frame:GetAltCurrencyFrame()
local texture, price = GetMerchantItemCostItem(i, j)
f:SetValue(price, texture)
f.index, f.itemIndex, f.link = i, j
2009-08-14 05:09:03 +00:00
lastframe = f.text
end
if arenaPoints > 0 then
local f = frame:GetAltCurrencyFrame()
f:SetValue(arenaPoints, "Interface\\PVPFrame\\PVP-ArenaPoints-Icon", ARENA_POINTS)
lastframe = f.text
end
if honorPoints > 0 then
local f = frame:GetAltCurrencyFrame()
f:SetValue(honorPoints, "Interface\\PVPFrame\\PVP-Currency-".. UnitFactionGroup("player"), HONOR_POINTS)
lastframe = f.text
end
frame.ItemName:SetPoint("RIGHT", lastframe, "LEFT", -GAP, 0)
end
local ROWHEIGHT = 21
2009-08-14 05:09:03 +00:00
local rows = {}
for i=1,NUMROWS do
local row = CreateFrame('Button', nil, GVS) -- base frame
row:SetHeight(ROWHEIGHT)
2009-08-14 05:09:03 +00:00
row:SetPoint("TOP", i == 1 and GVS or rows[i-1], i == 1 and "TOP" or "BOTTOM")
row:SetPoint("LEFT")
row:SetPoint("RIGHT", -19, 0)
row.BuyItem = BuyItem
row:SetHighlightTexture("Interface\\HelpFrame\\HelpFrameButton-Highlight")
row:GetHighlightTexture():SetTexCoord(0, 1, 0, 0.578125)
row:RegisterForClicks("AnyUp")
2009-08-14 05:09:03 +00:00
row:SetScript('OnClick', OnClick)
row:SetScript('OnDragStart', function(self, button)
MerchantFrame.extendedCost = nil
PickupMerchantItem(self:GetID())
if self.extendedCost then MerchantFrame.extendedCost = self end
end)
local backdrop = row:CreateTexture(nil, "BACKGROUND")
backdrop:SetAllPoints()
backdrop:SetTexture("Interface\\Tooltips\\UI-Tooltip-Background")
row.backdrop = backdrop
2009-08-14 05:09:03 +00:00
local icon = CreateFrame('Frame', nil, row)
icon:SetHeight(ICONSIZE)
icon:SetWidth(ICONSIZE)
icon:SetPoint('LEFT', 2, 0)
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)
popout:SetNormalTexture("Interface\\PaperDollInfoFrame\\UI-GearManager-FlyoutButton")
popout:SetHighlightTexture("Interface\\PaperDollInfoFrame\\UI-GearManager-FlyoutButton")
popout:GetNormalTexture():SetTexCoord(0.15625, 0.5, 0.84375, 0.5, 0.15625, 0, 0.84375, 0)
popout:GetHighlightTexture():SetTexCoord(0.15625, 1, 0.84375, 1, 0.15625, 0.5, 0.84375, 0.5)
popout:SetScript("OnClick", PopoutOnClick)
popout.SplitStack = PopoutSplitStack
row.popout = popout
2010-05-02 22:20:55 +00:00
local ItemPrice = row:CreateFontString(nil, nil, "NumberFontNormal")
ItemPrice:SetPoint('RIGHT', popout, "LEFT", -2, 0)
2009-08-14 05:09:03 +00:00
row.ItemPrice = ItemPrice
row.altframes = {}
row.AddAltCurrency, row.GetAltCurrencyFrame = AddAltCurrency, GetAltCurrencyFrame
row: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)
row:SetScript('OnLeave', function()
GameTooltip:Hide()
ResetCursor()
MerchantFrame.itemHover = nil
end)
rows[i] = row
end
2010-04-26 03:49:19 +00:00
local default_grad = {0,1,0,0.75, 0,1,0,0} -- green
local grads = setmetatable({
red = {1,0,0,0.75, 1,0,0,0},
[1] = {1,1,1,0.75, 1,1,1,0}, -- white
[2] = default_grad, -- green
[3] = {0.5,0.5,1,1, 0,0,1,0}, -- blue
[4] = {1,0,1,0.75, 1,0,1,0}, -- purple
[7] = {1,.75,.5,0.75, 1,.75,.5,0}, -- heirloom
}, {__index = function(t,i) t[i] = default_grad return default_grad end})
local _, _, _, _, _, _, _, _, RECIPE = GetAuctionItemClasses()
local quality_colors = setmetatable({}, {__index = function() return "|cffffffff" end})
for i=1,7 do quality_colors[i] = select(4, GetItemQualityColor(i)) end
2009-08-14 05:09:03 +00:00
local offset = 0
2009-08-16 01:43:17 +00:00
local searchstring
2009-08-14 05:09:03 +00:00
local function Refresh()
local n = GetMerchantNumItems()
for i,row in pairs(rows) do
local j = i + offset
if j > n then
row:Hide()
else
row.backdrop:Hide()
2009-08-14 05:09:03 +00:00
local name, itemTexture, itemPrice, itemStackCount, numAvailable, isUsable, extendedCost = GetMerchantItemInfo(j)
local link = GetMerchantItemLink(j)
local color = quality_colors.default
if link then
local name, link2, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(link)
color = quality_colors[quality]
2010-05-02 22:20:55 +00:00
if class == RECIPE and not ns.knowns[link] then
2010-04-26 03:49:19 +00:00
row.backdrop:SetGradientAlpha("HORIZONTAL", unpack(grads[quality]))
row.backdrop:Show()
end
end
if not isUsable then
2010-04-26 03:49:19 +00:00
row.backdrop:SetGradientAlpha("HORIZONTAL", unpack(grads.red))
row.backdrop:Show()
end
2009-08-14 05:09:03 +00:00
2009-08-30 01:10:16 +00:00
row:SetAlpha(searchstring and name and not name:lower():match(searchstring) and 0.5 or 1)
2009-08-16 01:43:17 +00:00
2009-08-14 05:09:03 +00:00
row.icon:SetTexture(itemTexture)
row.ItemName:SetText((numAvailable > -1 and ("["..numAvailable.."] ") or "").. color.. (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
if extendedCost then
row:AddAltCurrency(j)
row.link, row.texture, row.extendedCost = link, itemTexture, true
end
if itemPrice > 0 then
2010-05-02 22:20:55 +00:00
row.ItemPrice:SetText(ns.GSC(itemPrice))
2009-08-14 05:09:03 +00:00
row.Price = itemPrice
end
if extendedCost and (itemPrice <= 0) then
row.ItemPrice:SetText()
row.Price = 0
elseif extendedCost and (itemPrice > 0) then
2010-05-02 22:20:55 +00:00
row.ItemPrice:SetText(ns.GSC(itemPrice))
2009-08-14 05:09:03 +00:00
else
row.ItemName:SetPoint("RIGHT", row.ItemPrice, "LEFT", -GAP, 0)
row.extendedCost = nil
end
if isUsable then row.icon:SetVertexColor(1, 1, 1) else row.icon:SetVertexColor(.9, 0, 0) end
row:SetID(j)
row:Show()
end
end
end
2009-08-16 01:43:17 +00:00
local editbox = CreateFrame('EditBox', nil, GVS)
editbox:SetAutoFocus(false)
editbox:SetPoint("TOPLEFT", GVS, "BOTTOMLEFT", 0, -51)
editbox:SetWidth(160)
editbox:SetHeight(32)
editbox:SetFontObject('GameFontHighlightSmall')
local left = editbox:CreateTexture(nil, "BACKGROUND")
left:SetWidth(8) left:SetHeight(20)
left:SetPoint("LEFT", -5, 0)
left:SetTexture("Interface\\Common\\Common-Input-Border")
left:SetTexCoord(0, 0.0625, 0, 0.625)
local right = editbox:CreateTexture(nil, "BACKGROUND")
right:SetWidth(8) right:SetHeight(20)
right:SetPoint("RIGHT", 0, 0)
right:SetTexture("Interface\\Common\\Common-Input-Border")
right:SetTexCoord(0.9375, 1, 0, 0.625)
local center = editbox:CreateTexture(nil, "BACKGROUND")
center:SetHeight(20)
center:SetPoint("RIGHT", right, "LEFT", 0, 0)
center:SetPoint("LEFT", left, "RIGHT", 0, 0)
center:SetTexture("Interface\\Common\\Common-Input-Border")
center:SetTexCoord(0.0625, 0.9375, 0, 0.625)
editbox:SetScript("OnEscapePressed", editbox.ClearFocus)
editbox:SetScript("OnEnterPressed", editbox.ClearFocus)
editbox:SetScript("OnEditFocusGained", function(self)
if not searchstring then
self:SetText("")
self:SetTextColor(1,1,1,1)
end
end)
editbox:SetScript("OnEditFocusLost", function(self)
if self:GetText() == "" then
self:SetText("Search...")
self:SetTextColor(0.75, 0.75, 0.75, 1)
end
end)
editbox:SetScript("OnTextChanged", function(self)
local t = self:GetText()
searchstring = t ~= "" and t ~= "Search..." and t:lower() or nil
Refresh()
end)
editbox:SetScript("OnShow", function(self)
self:SetText("Search...")
self:SetTextColor(0.75, 0.75, 0.75, 1)
end)
2009-08-14 05:09:03 +00:00
local scrollbar = LibStub("tekKonfig-Scroll").new(GVS, 0, SCROLLSTEP)
local f = scrollbar:GetScript("OnValueChanged")
scrollbar:SetScript("OnValueChanged", function(self, value, ...)
offset = math.floor(value)
Refresh()
return f(self, value, ...)
end)
local offset = 0
GVS:EnableMouseWheel(true)
GVS:SetScript("OnMouseWheel", function(self, value) scrollbar:SetValue(scrollbar:GetValue() - value * SCROLLSTEP) end)
2009-12-21 01:16:08 +00:00
GVS:SetScript("OnShow", function(self, noreset)
local max = math.max(0, GetMerchantNumItems() - NUMROWS)
scrollbar:SetMinMaxValues(0, max)
scrollbar:SetValue(noreset and math.min(scrollbar:GetValue(), max) or 0)
2009-08-14 05:09:03 +00:00
Refresh()
end)
2009-08-28 03:12:58 +00:00
GVS:SetScript("OnHide", function() if StackSplitFrame:IsVisible() then StackSplitFrame:Hide() end end)
2009-08-14 05:09:03 +00:00
-- Reanchor the buyback button, it acts weird when switching tabs otherwise...
MerchantBuyBackItem:ClearAllPoints()
MerchantBuyBackItem:SetPoint("BOTTOMLEFT", 189, 90)
local function Show()
for i=1,12 do _G["MerchantItem"..i]:Hide() end
2009-12-21 01:16:08 +00:00
if GVS:IsShown() then GVS:GetScript("OnShow")(GVS, true) else GVS:Show() end
2009-08-14 05:09:03 +00:00
end
hooksecurefunc("MerchantFrame_UpdateMerchantInfo", Show)
hooksecurefunc("MerchantFrame_UpdateBuybackInfo", function()
GVS:Hide()
for i=1,12 do _G["MerchantItem"..i]:Show() end
end)
if MerchantFrame:IsVisible() and MerchantFrame.selectedTab == 1 then Show() end
LibStub("tekKonfig-AboutPanel").new(nil, "GnomishVendorShrinker")