tekkub / panda

WoW Addon - Prospecting and Disenchanting Aide

This URL has Read+Write access

panda / ButtonFactory.lua
100644 126 lines (97 sloc) 4.1 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126

local HideTooltip, ShowTooltip, GS, G = Panda.HideTooltip, Panda.ShowTooltip, Panda.GS, Panda.G
local auc = LibStub("tekAucQuery")
 
 
local UNK = "Interface\\Icons\\INV_Misc_QuestionMark"
local server = GetRealmName().." "..UnitFactionGroup("player")
 
 
local function OnEvent(self)
local count = GetItemCount(self.id)
self.count:SetText(count > 0 and count or "")
if self.text then self.text:SetText(GS(auc[self.id])) end
 
 
if ForSaleByOwnerDB then
local count, name = 0, GetItemInfo(self.id)
for char,vals in pairs(ForSaleByOwnerDB[server]) do count = count + (vals[name] or 0) end
self.ahcount:SetText(count ~= 0 and count or "")
end
end
 
 
local function OnHide(self) self:UnregisterEvent("BAG_UPDATE") end
local function OnShow(self)
self:RegisterEvent("BAG_UPDATE")
OnEvent(self)
end
 
 
function Panda.CraftMacro(name, id)
return "/run if IsShiftKeyDown() then ChatEdit_InsertLink('"..select(2, GetItemInfo(id)).."') end\n"..
"/stopmacro [mod:shift]\n"..
"/run CloseTradeSkill()\n/cast "..name.."\n"..
"/run for i=1,GetNumTradeSkills() do local l = GetTradeSkillItemLink(i) if l and l:match('item:"..id..":') then TradeSkillFrame_SetSelection(i); DoTradeSkill(i, IsAltKeyDown() and select(3, GetTradeSkillInfo(i)) or 1) end end\n"..
"/run if not IsAltKeyDown() then CloseTradeSkill() end"
end
 
 
function Panda.ButtonFactory(parent, id, secure, notext, ...)
local f = CreateFrame(secure and "CheckButton" or "Frame", nil, parent, secure and "SecureActionButtonTemplate")
local name, link, _, _, _, _, _, _, _, texture = GetItemInfo(id)
f.link, f.id, f.name = link, id, name or ""
 
f:SetHeight(32)
f:SetWidth(32)
if not secure then f:EnableMouse() end
if select("#", ...) > 0 then f:SetPoint(...) end
f:SetScript("OnEnter", ShowTooltip)
f:SetScript("OnLeave", HideTooltip)
f:SetScript("OnShow", OnShow)
f:SetScript("OnHide", OnHide)
f:SetScript("OnEvent", OnEvent)
 
local icon = f:CreateTexture(nil, "ARTWORK")
icon:SetAllPoints(f)
icon:SetTexture(texture or UNK)
f.icon = icon
 
if not notext then
f.text = f:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
f.text:SetPoint("TOP", icon, "BOTTOM")
end
 
local count = f:CreateFontString(nil, "ARTWORK", "NumberFontNormalSmall")
count:SetPoint("BOTTOMRIGHT", icon, "BOTTOMRIGHT", -2, 2)
f.count = count
 
f.ahcount = f:CreateFontString(nil, "ARTWORK", "NumberFontNormalSmall")
f.ahcount:SetPoint("TOPRIGHT", icon, "TOPRIGHT", -2, -2)
 
-- Thanks to oglow for this method
local border = f:CreateTexture(nil, "OVERLAY")
border:SetTexture("Interface\\Buttons\\UI-ActionButton-Border")
border:SetBlendMode("ADD")
border:SetAlpha(.5)
border:Hide()
 
border:SetPoint('CENTER', f, 'CENTER', 0, 1)
border:SetWidth(f:GetWidth() * 2 - 5)
border:SetHeight(f:GetHeight() * 2 - 5)
f.border = border
 
if secure and name then
if type(secure) == "function" then
secure(f)
else
f:SetAttribute("type", "macro")
f:SetAttribute("macrotext", Panda.CraftMacro(secure, id))
end
end
 
if f:IsVisible() then OnShow(f) end
 
return f
end
 
 
function Panda.RefreshButtonFactory(parent, tradeskill, ...)
local b = CreateFrame("Button", nil, parent, "SecureActionButtonTemplate")
b:SetPoint(...)
b:SetWidth(80) b:SetHeight(22)
 
-- Fonts --
b:SetDisabledFontObject(GameFontDisable)
b:SetHighlightFontObject(GameFontHighlight)
b:SetNormalFontObject(GameFontNormal)
 
-- Textures --
b:SetNormalTexture("Interface\\Buttons\\UI-Panel-Button-Up")
b:SetPushedTexture("Interface\\Buttons\\UI-Panel-Button-Down")
b:SetHighlightTexture("Interface\\Buttons\\UI-Panel-Button-Highlight")
b:SetDisabledTexture("Interface\\Buttons\\UI-Panel-Button-Disabled")
b:GetNormalTexture():SetTexCoord(0, 0.625, 0, 0.6875)
b:GetPushedTexture():SetTexCoord(0, 0.625, 0, 0.6875)
b:GetHighlightTexture():SetTexCoord(0, 0.625, 0, 0.6875)
b:GetDisabledTexture():SetTexCoord(0, 0.625, 0, 0.6875)
b:GetHighlightTexture():SetBlendMode("ADD")
 
b:SetText("Refresh")
b:SetAttribute("type", "macro")
b:SetAttribute("macrotext", "/run CloseTradeSkill()\n/cast "..tradeskill.."\n/run CloseTradeSkill()")
 
return b
end