Thread: Jewelcrafting
View Single Post
05-05-13, 01:41 PM   #2
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Code:
local disabled = true
local button

local tip = CreateFrame('GameTooltip', 'GemStatsTip')
local line1 = tip:CreateFontString()
local line2 = tip:CreateFontString()
local line3 = tip:CreateFontString()

tip:AddFontStrings(tip:CreateFontString(), tip:CreateFontString())
tip:AddFontStrings(line1, tip:CreateFontString())
tip:AddFontStrings(line2, tip:CreateFontString())
tip:AddFontStrings(line3, tip:CreateFontString())

local JEWELCRAFTING_S = GetSpellInfo(25229)
local GEM_S = '%+[0-9]+.*'

local match = string.match

local function GetGemStats(id)
	tip:SetOwner(WorldFrame, 'ANCHOR_NONE')
	tip:SetTradeSkillItem(id)

	if(tip:IsShown()) then
		return match(line1:GetText() or '', GEM_S) or match(line2:GetText() or '', GEM_S) or match(line3:GetText() or '', GEM_S)
	end
end

local function Update()
	if(GetTradeSkillLine() ~= JEWELCRAFTING_S) then
		if(button) then
			button:Hide()
		end

		return
	else
		button:Show()
	end

	if(not IsTradeSkillReady()) then return end
	if(disabled) then return end

	local filterBar = TradeSkillFilterBar:IsShown()
	for index = 1, TRADE_SKILLS_DISPLAYED, 1 do
		local buttonIndex = filterBar and index + 1 or index

		local button = _G['TradeSkillSkill' .. buttonIndex]
		if(button) then
			local stats = GetGemStats(button:GetID())
			if(stats) then
				_G['TradeSkillSkill' .. buttonIndex .. 'Text']:SetText(stats)
			end
		end
	end
end

local f = CreateFrame('Frame')
f:RegisterEvent('ADDON_LOADED')
f:SetScript('OnEvent', function(self, event, name)
	if(name == 'Blizzard_TradeSkillUI') then
		button = CreateFrame('Button', 'SomeRandomButton123', TradeSkillFrame, 'UIPanelButtonTemplate')
		button:SetPoint('TOPRIGHT', TradeSkillFrameCloseButton, 'TOPLEFT', 4, -6)
		button:SetSize(22, 20)
		button:SetText('J')
		button:SetScript('OnClick', function()
			disabled = not disabled
			TradeSkillFrame_Update()
		end)

		hooksecurefunc('TradeSkillFrame_Update', Update)
	end
end)


Keep in mind you have to change JEWELCRAFTING_S to whatever "Jewelcrafting" is in your locale.
And the search function doesn't see this, it still looks for the name.

Last edited by p3lim : 05-07-13 at 01:50 PM.
  Reply With Quote