And so it begins...

This commit is contained in:
tekkub 2009-08-13 23:09:03 -06:00
commit c5dc724c85
6 changed files with 523 additions and 0 deletions

277
GnomishVendorShrinker.lua Normal file
View File

@ -0,0 +1,277 @@
local NUMROWS, ICONSIZE, GAP, SCROLLSTEP = 14, 17, 4, 5
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 BuyItem(self, fullstack)
local id = self:GetID()
local link = GetMerchantItemLink(id)
if not link then return end
local _, _, _, vendorStackSize, numAvailable = GetMerchantItemInfo(id)
local maxPurchase = GetMerchantItemMaxStack(id)
local _, _, _, _, _, _, _, itemStackSize = GetItemInfo(link)
local quantity = fullstack and itemStackSize/vendorStackSize or 1
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 OnEnter(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
if self.tiptext then GameTooltip:SetText(self.tiptext) else GameTooltip:SetMerchantCostItem(self.index, self.itemIndex) end
end
local function OnLeave()
GameTooltip:Hide()
ResetCursor()
end
local function GSC(cash)
if not cash then return end
local g, s, c = floor(cash/10000), floor((cash/100)%100), cash%100
if g > 0 and s == 0 and c == 0 then return string.format(" |cffffd700%d", g)
elseif g > 0 and c == 0 then return string.format(" |cffffd700%d.|cffc7c7cf%02d", g, s)
elseif g > 0 then return string.format(" |cffffd700%d.|cffc7c7cf%02d.|cffeda55f%02d", g, s, c)
elseif s > 0 and c == 0 then return string.format(" |cffc7c7cf%d", s)
elseif s > 0 then return string.format(" |cffc7c7cf%d.|cffeda55f%02d", s, c)
else return string.format(" |cffc7c7cf%d", c) end
end
local function SetValue(self, text, icon, tiptext)
self.text:SetText(text)
self.icon:SetTexture(icon)
self.tiptext, self.index, self.itemIndex = tiptext
if tiptext == HONOR_POINTS then
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)
f:SetPoint("RIGHT", anchor or frame.ItemPrice, "LEFT")
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)
for j=itemCount,1,-1 do
local f = frame:GetAltCurrencyFrame()
local texture, price = GetMerchantItemCostItem(i, j)
f:SetValue(price, texture)
f.index, f.itemIndex = i, j
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 rows = {}
for i=1,NUMROWS do
local row = CreateFrame('Button', nil, GVS) -- base frame
row:SetHeight(21)
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: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 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 ItemPrice = row:CreateFontString(nil, nil, "NumberFontNormalSmall")
ItemPrice:SetPoint('RIGHT', row, -2, 0)
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
local offset = 0
local function Refresh()
local n = GetMerchantNumItems()
for i,row in pairs(rows) do
local j = i + offset
if j > n then
row:Hide()
else
local name, itemTexture, itemPrice, itemStackCount, numAvailable, isUsable, extendedCost = GetMerchantItemInfo(j)
local link = GetMerchantItemLink(j)
local color = link and select(4, GetItemQualityColor(select(3, GetItemInfo(link)))) or "|cffffffff"
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
row.ItemPrice:SetText(GSC(itemPrice))
row.Price = itemPrice
end
if extendedCost and (itemPrice <= 0) then
row.ItemPrice:SetText()
row.Price = 0
elseif extendedCost and (itemPrice > 0) then
row.ItemPrice:SetText(GSC(itemPrice))
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
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)
GVS:SetScript("OnShow", function()
scrollbar:SetMinMaxValues(0, math.max(0, GetMerchantNumItems() - NUMROWS))
scrollbar:SetValue(0)
Refresh()
end)
-- 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
if GVS:IsShown() then Refresh() else GVS:Show() end
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")

16
GnomishVendorShrinker.toc Normal file
View File

@ -0,0 +1,16 @@
## Interface: 30200
## Title: GnomishVendorShrinker
## Notes: Compact scrolling vendor frame
## Author: Tekkub Stoutwrithe
## Version: Alpha
## X-Website: http://www.tekkub.net/
## X-Email: tekkub-wow@googlegroups.com
## X-Category: Misc
## LoadManagers: AddonLoader
## X-LoadOn-Merchant: true
tekKonfig\tekKonfig.xml
GnomishVendorShrinker.lua

30
tekKonfig/LibStub.lua Normal file
View File

@ -0,0 +1,30 @@
-- LibStub is a simple versioning stub meant for use in Libraries. http://www.wowace.com/wiki/LibStub for more info
-- LibStub is hereby placed in the Public Domain Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel, joshborke
local LIBSTUB_MAJOR, LIBSTUB_MINOR = "LibStub", 2 -- NEVER MAKE THIS AN SVN REVISION! IT NEEDS TO BE USABLE IN ALL REPOS!
local LibStub = _G[LIBSTUB_MAJOR]
if not LibStub or LibStub.minor < LIBSTUB_MINOR then
LibStub = LibStub or {libs = {}, minors = {} }
_G[LIBSTUB_MAJOR] = LibStub
LibStub.minor = LIBSTUB_MINOR
function LibStub:NewLibrary(major, minor)
assert(type(major) == "string", "Bad argument #2 to `NewLibrary' (string expected)")
minor = assert(tonumber(strmatch(minor, "%d+")), "Minor version must either be a number or contain a number.")
local oldminor = self.minors[major]
if oldminor and oldminor >= minor then return nil end
self.minors[major], self.libs[major] = minor, self.libs[major] or {}
return self.libs[major], oldminor
end
function LibStub:GetLibrary(major, silent)
if not self.libs[major] and not silent then
error(("Cannot find a library instance of %q."):format(tostring(major)), 2)
end
return self.libs[major], self.minors[major]
end
function LibStub:IterateLibraries() return pairs(self.libs) end
setmetatable(LibStub, { __call = LibStub.GetLibrary })
end

5
tekKonfig/tekKonfig.xml Normal file
View File

@ -0,0 +1,5 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/">
<Script file="LibStub.lua"/>
<Script file="tekKonfigScroll.lua"/>
<Script file="tekKonfigAboutPanel.lua"/>
</Ui>

View File

@ -0,0 +1,115 @@
local lib, oldminor = LibStub:NewLibrary("tekKonfig-AboutPanel", 5)
if not lib then return end
function lib.new(parent, addonname)
local frame = CreateFrame("Frame", nil, InterfaceOptionsFramePanelContainer)
frame.name, frame.parent, frame.addonname = parent and "About" or addonname, parent, addonname
frame:Hide()
frame:SetScript("OnShow", lib.OnShow)
InterfaceOptions_AddCategory(frame)
return frame
end
local editbox = CreateFrame('EditBox', nil, UIParent)
editbox:Hide()
editbox:SetAutoFocus(true)
editbox:SetHeight(32)
editbox:SetFontObject('GameFontHighlightSmall')
lib.editbox = editbox
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("OnEditFocusLost", editbox.Hide)
editbox:SetScript("OnEditFocusGained", editbox.HighlightText)
editbox:SetScript("OnTextChanged", function(self)
self:SetText(self:GetParent().val)
self:HighlightText()
end)
function lib.OpenEditbox(self)
editbox:SetText(self.val)
editbox:SetParent(self)
editbox:SetPoint("LEFT", self)
editbox:SetPoint("RIGHT", self)
editbox:Show()
end
local fields = {"Version", "Author", "X-Category", "X-License", "X-Email", "X-Website", "X-Credits"}
local haseditbox = {["Version"] = true, ["X-Website"] = true, ["X-Email"] = true}
local function HideTooltip() GameTooltip:Hide() end
local function ShowTooltip(self)
GameTooltip:SetOwner(self, "ANCHOR_TOPRIGHT")
GameTooltip:SetText("Click and press Ctrl-C to copy")
end
function lib.OnShow(frame)
local notes = GetAddOnMetadata(frame.addonname, "Notes")
local title = frame:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
title:SetPoint("TOPLEFT", 16, -16)
title:SetText((frame.parent or frame.addonname).." - About")
local subtitle = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
subtitle:SetHeight(32)
subtitle:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -8)
subtitle:SetPoint("RIGHT", parent, -32, 0)
subtitle:SetNonSpaceWrap(true)
subtitle:SetJustifyH("LEFT")
subtitle:SetJustifyV("TOP")
subtitle:SetText(notes)
local anchor
for _,field in pairs(fields) do
local val = GetAddOnMetadata(frame.addonname, field)
if val then
local title = frame:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
title:SetWidth(75)
if not anchor then title:SetPoint("TOPLEFT", subtitle, "BOTTOMLEFT", -2, -8)
else title:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", 0, -6) end
title:SetJustifyH("RIGHT")
title:SetText(field:gsub("X%-", ""))
local detail = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
detail:SetPoint("LEFT", title, "RIGHT", 4, 0)
detail:SetPoint("RIGHT", -16, 0)
detail:SetJustifyH("LEFT")
detail:SetText((haseditbox[field] and "|cff9999ff" or "").. val)
if haseditbox[field] then
local button = CreateFrame("Button", nil, frame)
button:SetAllPoints(detail)
button.val = val
button:SetScript("OnClick", lib.OpenEditbox)
button:SetScript("OnEnter", ShowTooltip)
button:SetScript("OnLeave", HideTooltip)
end
anchor = title
end
end
frame:SetScript("OnShow", nil)
end

View File

@ -0,0 +1,80 @@
local lib, oldminor = LibStub:NewLibrary("tekKonfig-Scroll", 2)
if not lib then return end
lib.bg = {
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
tileSize = 16,
edgeSize = 12,
insets = { left = 0, right = 0, top = 5, bottom = 5 }
}
-- Creates a scrollbar
-- Parent is required, offset and step are optional
function lib.new(parent, offset, step)
local f = CreateFrame("Slider", nil, parent)
f:SetWidth(16)
f:SetPoint("TOPRIGHT", 0 - (offset or 0), -16 - (offset or 0))
f:SetPoint("BOTTOMRIGHT", 0 - (offset or 0), 16 + (offset or 0))
local up = CreateFrame("Button", nil, f)
up:SetPoint("BOTTOM", f, "TOP")
up:SetWidth(16) up:SetHeight(16)
up:SetNormalTexture("Interface\\Buttons\\UI-ScrollBar-ScrollUpButton-Up")
up:SetPushedTexture("Interface\\Buttons\\UI-ScrollBar-ScrollUpButton-Down")
up:SetDisabledTexture("Interface\\Buttons\\UI-ScrollBar-ScrollUpButton-Disabled")
up:SetHighlightTexture("Interface\\Buttons\\UI-ScrollBar-ScrollUpButton-Highlight")
up:GetNormalTexture():SetTexCoord(1/4, 3/4, 1/4, 3/4)
up:GetPushedTexture():SetTexCoord(1/4, 3/4, 1/4, 3/4)
up:GetDisabledTexture():SetTexCoord(1/4, 3/4, 1/4, 3/4)
up:GetHighlightTexture():SetTexCoord(1/4, 3/4, 1/4, 3/4)
up:GetHighlightTexture():SetBlendMode("ADD")
up:SetScript("OnClick", function(self)
local parent = self:GetParent()
parent:SetValue(parent:GetValue() - (step or parent:GetHeight()/2))
PlaySound("UChatScrollButton")
end)
local down = CreateFrame("Button", nil, f)
down:SetPoint("TOP", f, "BOTTOM")
down:SetWidth(16) down:SetHeight(16)
down:SetNormalTexture("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Up")
down:SetPushedTexture("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Down")
down:SetDisabledTexture("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Disabled")
down:SetHighlightTexture("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Highlight")
down:GetNormalTexture():SetTexCoord(1/4, 3/4, 1/4, 3/4)
down:GetPushedTexture():SetTexCoord(1/4, 3/4, 1/4, 3/4)
down:GetDisabledTexture():SetTexCoord(1/4, 3/4, 1/4, 3/4)
down:GetHighlightTexture():SetTexCoord(1/4, 3/4, 1/4, 3/4)
down:GetHighlightTexture():SetBlendMode("ADD")
down:SetScript("OnClick", function(self)
local parent = self:GetParent()
parent:SetValue(parent:GetValue() + (step or parent:GetHeight()/2))
PlaySound("UChatScrollButton")
end)
f:SetThumbTexture("Interface\\Buttons\\UI-ScrollBar-Knob")
local thumb = f:GetThumbTexture()
thumb:SetWidth(16) thumb:SetHeight(24)
thumb:SetTexCoord(1/4, 3/4, 1/8, 7/8)
f:SetScript("OnValueChanged", function(self, value)
local min, max = self:GetMinMaxValues()
if value == min then up:Disable() else up:Enable() end
if value == max then down:Disable() else down:Enable() end
end)
local border = CreateFrame("Frame", nil, f)
border:SetPoint("TOPLEFT", up, -5, 5)
border:SetPoint("BOTTOMRIGHT", down, 5, -3)
border:SetBackdrop(lib.bg)
border:SetBackdropBorderColor(TOOLTIP_DEFAULT_COLOR.r, TOOLTIP_DEFAULT_COLOR.g, TOOLTIP_DEFAULT_COLOR.b, 0.5)
return f, up, down, border
end