Quantcast
WoWInterface: SVN - Ara_Broker_Tradeskills - Blame - Rev 7 - /trunk/Ara_Broker_Tradeskills.lua

WoWInterface SVN Ara_Broker_Tradeskills

[/] [trunk/] [Ara_Broker_Tradeskills.lua] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 Aranarth-82994
-- TODO: save/restore skill filters if window is opened
2 Aranarth-82994
 
3 Aranarth-82994
local f = CreateFrame("Frame", "AraSkills", UIParent)
4 Aranarth-82994
local g = CreateFrame("Frame", nil, UIParent)
5 Aranarth-82994
local e = CreateFrame"Frame"
6 Aranarth-82994
local dropdown = CreateFrame("Frame", "AraSkillsDD", nil, "UIDropDownMenuTemplate")
7 Aranarth-82994
local dropdown_init, tipShown, nbEntries, Block_OnEnter
8 Aranarth-82994
 
9 Aranarth-82994
local config, realm, options, c
10 Aranarth-82994
local playerName, realmName = GetUnitName"player", GetRealmName()
11 Aranarth-82994
local CDs, shortcuts, workingFrame, prevAltSkill
12 Aranarth-82994
 
13 Aranarth-82994
local BUTTON_HEIGHT, ICON_SIZE, GAP, TEXT_OFFSET = 17, 15, 10, 4
14 Aranarth-82994
local PANEL, PROFESSION, COMBAT_SKILL, LINK, SECONDARY, SPELL_ID = 1, 2, 4, 8, 16, 256
15 Aranarth-82994
 
16 Aranarth-82994
local L = setmetatable( _G.ABTS_T or {}, { __index = function(t,k) return k end, __call = function(t,k) return t[k] end } )
17 Aranarth-82994
 
18 Aranarth-82994
local bit_band, date, format, strmatch, tonumber, wipe, ipairs, tremove, GetSkillLineInfo, GetSpellInfo, GetTradeSkillInfo, GetTradeSkillRecipeLink, tip =
19 Aranarth-82994
        bit.band, date, format, strmatch, tonumber, wipe, ipairs, tremove, GetSkillLineInfo, GetSpellInfo, GetTradeSkillInfo, GetTradeSkillRecipeLink
20 Aranarth-82994
 
21 Aranarth-82994
local skills = {
22 Aranarth-82994
        [L.Alchemy]=            PROFESSION +  2259*SPELL_ID + PANEL + LINK,
23 Aranarth-82994
        [L.Blacksmithing]=      PROFESSION +  2018*SPELL_ID + PANEL + LINK,
24 Aranarth-82994
        [L.Cooking]=            PROFESSION +  2550*SPELL_ID + PANEL + LINK + SECONDARY, -- campfire
25 Aranarth-82994
        [L.Enchanting]=         PROFESSION +  7411*SPELL_ID + PANEL + LINK, -- d/e
26 Aranarth-82994
        [L.Engineering]=        PROFESSION +  4036*SPELL_ID + PANEL + LINK,
27 Aranarth-82994
        [L"First Aid"]=         PROFESSION +  3273*SPELL_ID + PANEL + LINK + SECONDARY,
28 Aranarth-82994
        [L.Fishing]=            PROFESSION +  7620*SPELL_ID + SECONDARY,
29 Aranarth-82994
        [L.Herbalism]=          PROFESSION +  2366*SPELL_ID, -- track herbs
30 Aranarth-82994
        [L.Inscription]=        PROFESSION + 45357*SPELL_ID + PANEL + LINK, -- mill
31 Aranarth-82994
        [L.Jewelcrafting]=      PROFESSION + 25229*SPELL_ID + PANEL + LINK, -- prospect
32 Aranarth-82994
        [L.Leatherworking]=     PROFESSION +  2108*SPELL_ID + PANEL + LINK,
33 Aranarth-82994
        [L.Lockpicking]=        PROFESSION +  1804*SPELL_ID + SECONDARY,
34 Aranarth-82994
        [L.Runeforging]=        PROFESSION + 53428*SPELL_ID + PANEL + SECONDARY,
35 Aranarth-82994
        [L.Skinning]=           PROFESSION +  8613*SPELL_ID,
36 Aranarth-82994
        [L.Smelting]=           PROFESSION +  2580*SPELL_ID + PANEL, -- track minerals (icons: 2575=mining, 2580=smelting)
37 Aranarth-82994
        [L.Tailoring]=          PROFESSION +  3908*SPELL_ID + PANEL + LINK,
38 Aranarth-82994
        [L.Axes]=               COMBAT_SKILL,
39 Aranarth-82994
        [L.Bows]=               COMBAT_SKILL,
40 Aranarth-82994
        [L.Crossbows]=          COMBAT_SKILL,
41 Aranarth-82994
        [L.Daggers]=            COMBAT_SKILL,
42 Aranarth-82994
        [L.Defense]=            COMBAT_SKILL,
43 Aranarth-82994
        [L.Guns]=               COMBAT_SKILL,
44 Aranarth-82994
        [L.Maces]=              COMBAT_SKILL,
45 Aranarth-82994
        [L.Polearms]=           COMBAT_SKILL,
46 Aranarth-82994
        [L.Staves]=             COMBAT_SKILL,
47 Aranarth-82994
        [L.Swords]=             COMBAT_SKILL,
48 Aranarth-82994
        [L.Thrown]=             COMBAT_SKILL,
49 Aranarth-82994
        [L"Two-Handed Swords"]= COMBAT_SKILL,
50 Aranarth-82994
        [L"Two-Handed Axes"]=   COMBAT_SKILL,
51 Aranarth-82994
        [L"Two-Handed Maces"]=  COMBAT_SKILL,
52 Aranarth-82994
        [L.Unarmed]=            COMBAT_SKILL,
53 Aranarth-82994
        [L.Wands]=              COMBAT_SKILL,
54 Aranarth-82994
        None =                  0
55 Aranarth-82994
}
56 Aranarth-82994
local altNames = {
57 Aranarth-82994
        [L.Mining] =            L.Smelting,
58 Aranarth-82994
        [L.RuneforgingDN] =     L.Runeforging,
59 Aranarth-82994
}
60 Aranarth-82994
local altIcons = {
61 Aranarth-82994
        [L.Axes]=               "Interface\\Icons\\INV_Axe_44",
62 Aranarth-82994
        [L.Bows]=               "Interface\\Icons\\INV_Weapon_Bow_05",
63 Aranarth-82994
        [L.Crossbows]=          "Interface\\Icons\\INV_Weapon_Crossbow_01",
64 Aranarth-82994
        [L.Daggers]=            "Interface\\Icons\\Ability_SteelMelee",
65 Aranarth-82994
        [L.Defense]=            "Interface\\Icons\\INV_Shield_09",
66 Aranarth-82994
        [L.Guns]=               "Interface\\Icons\\INV_Weapon_Rifle_01",
67 Aranarth-82994
        [L.Maces]=              "Interface\\Icons\\INV_Mace_04",
68 Aranarth-82994
        [L.Polearms]=           "Interface\\Icons\\INV_Spear_06",
69 Aranarth-82994
        [L.Staves]=             "Interface\\Icons\\INV_Staff_08",
70 Aranarth-82994
        [L.Swords]=             "Interface\\Icons\\INV_Sword_14",
71 Aranarth-82994
        [L.Thrown]=             "Interface\\Icons\\Ability_Throw",
72 Aranarth-82994
        [L"Two-Handed Axes"]=   "Interface\\Icons\\INV_Axe_09",
73 Aranarth-82994
        [L"Two-Handed Maces"]=  "Interface\\Icons\\INV_Hammer_16",
74 Aranarth-82994
        [L"Two-Handed Swords"]= "Interface\\Icons\\INV_Sword_27",
75 Aranarth-82994
        [L.Unarmed]=            "Interface\\Icons\\Ability_Warrior_SecondWind",
76 Aranarth-82994
        [L.Wands]=              "Interface\\Icons\\INV_Wand_05",
77 Aranarth-82994
}
78 Aranarth-82994
local groupIcons = {
79 Aranarth-82994
        ["Transmutes"] = "Interface\\Icons\\Spell_Nature_ElementalPrecision_2"
80 Aranarth-82994
}
81 Aranarth-82994
 
82 Aranarth-82994
local HOUR, DAY = 3600, 86400
83 Aranarth-82994
local TRANSMUTE_G1 = { skill= L.Alchemy, CD=20*HOUR, group= "Transmutes" }
84 Aranarth-82994
 
85 Aranarth-82994
local watchedCDs = {
86 Aranarth-82994
        [11479]= TRANSMUTE_G1, -- Iron to Gold
87 Aranarth-82994
        [11480]= TRANSMUTE_G1, -- Mithril to Truesilver
88 Aranarth-82994
        [60350]= TRANSMUTE_G1, -- Titanium
89 Aranarth-82994
        [17559]= TRANSMUTE_G1, -- Air to Fire
90 Aranarth-82994
        [17566]= TRANSMUTE_G1, -- Earth to Life
91 Aranarth-82994
        [17561]= TRANSMUTE_G1, -- Earth to Water
92 Aranarth-82994
        [17560]= TRANSMUTE_G1, -- Fire to Earth
93 Aranarth-82994
        [17565]= TRANSMUTE_G1, -- Life to Earth
94 Aranarth-82994
        [17563]= TRANSMUTE_G1, -- Undeath to Earth
95 Aranarth-82994
        [17562]= TRANSMUTE_G1, -- Water to Air
96 Aranarth-82994
        [17564]= TRANSMUTE_G1, -- Water to Undeath
97 Aranarth-82994
        [28566]= TRANSMUTE_G1, -- Primal Air to Fire
98 Aranarth-82994
        [28585]= TRANSMUTE_G1, -- Primal Earth to Life
99 Aranarth-82994
        [28567]= TRANSMUTE_G1, -- Primal Earth to Water
100 Aranarth-82994
        [28568]= TRANSMUTE_G1, -- Primal Fire to Earth
101 Aranarth-82994
        [28583]= TRANSMUTE_G1, -- Primal Fire to Mana
102 Aranarth-82994
        [28584]= TRANSMUTE_G1, -- Primal Life to Earth
103 Aranarth-82994
        [28582]= TRANSMUTE_G1, -- Primal Mana to Fire
104 Aranarth-82994
        [28580]= TRANSMUTE_G1, -- Primal Shadow to Water
105 Aranarth-82994
        [28569]= TRANSMUTE_G1, -- Primal Water to Air
106 Aranarth-82994
        [28581]= TRANSMUTE_G1, -- Primal Water to Shadow
107 Aranarth-82994
        [53777]= TRANSMUTE_G1, -- Eternal Air to Earth
108 Aranarth-82994
        [52776]= TRANSMUTE_G1, -- Eternal Air to Water
109 Aranarth-82994
        [53781]= TRANSMUTE_G1, -- Eternal Earth to Air
110 Aranarth-82994
        [53782]= TRANSMUTE_G1, -- Eternal Earth to Shadow
111 Aranarth-82994
        [53775]= TRANSMUTE_G1, -- Eternal Fire to Life
112 Aranarth-82994
        [53774]= TRANSMUTE_G1, -- Eternal Fire to Water
113 Aranarth-82994
        [53773]= TRANSMUTE_G1, -- Eternal Life to Fire
114 Aranarth-82994
        [53771]= TRANSMUTE_G1, -- Eternal Life to Shadow
115 Aranarth-82994
        [54020]= TRANSMUTE_G1, -- Eternal Might
116 Aranarth-82994
        [53779]= TRANSMUTE_G1, -- Eternal Shadow to Earth
117 Aranarth-82994
        [52780]= TRANSMUTE_G1, -- Eternal Shadow to Life
118 Aranarth-82994
        [53783]= TRANSMUTE_G1, -- Eternal Water to Air
119 Aranarth-82994
        [53784]= TRANSMUTE_G1, -- Eternal Water to Fire
120 Aranarth-82994
        [28027]= { skill= L.Enchanting,         CD= 2*DAY         },    -- Prismatic Sphere
121 Aranarth-82994
        [28028]= { skill= L.Enchanting,         CD= 2*DAY         },    -- Void Sphere
122 Aranarth-82994
        [47280]= { skill= L.Jewelcrafting,      CD=       20*HOUR },    -- Brilliant Glass
123 Aranarth-82994
        [62242]= { skill= L.Jewelcrafting,      CD=       20*HOUR },    -- Icy Prism            -- NEW 3.0.8
124 Aranarth-82994
        [56002]= { skill= L.Tailoring,          CD= 3*DAY+20*HOUR },    -- Ebonweave
125 Aranarth-82994
        [56003]= { skill= L.Tailoring,          CD= 3*DAY+20*HOUR },    -- Spellweave
126 Aranarth-82994
        [56001]= { skill= L.Tailoring,          CD= 3*DAY+20*HOUR },    -- Moonshroud
127 Aranarth-82994
        [61288]= { skill= L.Inscription,        CD=       20*HOUR },    -- Minor Glyph RS
128 Aranarth-82994
        [61177]= { skill= L.Inscription,        CD=       20*HOUR },    -- Major Glyph RS
129 Aranarth-82994
        [55208]= { skill= L.Smelting,           CD=       20*HOUR },    -- Smelt Titansteel
130 Aranarth-82994
        [60893]= { skill= L.Alchemy,            CD= 2*DAY+20*HOUR },    -- Alchemy Research
131 Aranarth-82994
}
132 Aranarth-82994
 
133 Aranarth-82994
local watchedIndex, watchedSpell, watchedID, watchedIcon
134 Aranarth-82994
local orgDoTradeSkill = _G.DoTradeSkill
135 Aranarth-82994
 
136 Aranarth-82994
function DoTradeSkill(index, ...)
137 Aranarth-82994
        watchedID = tonumber( strmatch( GetTradeSkillRecipeLink(index), "enchant:(%d+)" ) )
138 Aranarth-82994
        if watchedCDs[watchedID] then
139 Aranarth-82994
                watchedIndex, watchedSpell, watchedIcon = index, GetTradeSkillInfo(index), GetTradeSkillIcon(index)
140 Aranarth-82994
                f:RegisterEvent"UNIT_SPELLCAST_SUCCEEDED"
141 Aranarth-82994
                f:RegisterEvent"UNIT_SPELLCAST_STOP"
142 Aranarth-82994
        end
143 Aranarth-82994
        return orgDoTradeSkill(index, ...)
144 Aranarth-82994
end
145 Aranarth-82994
 
146 Aranarth-82994
function f:UNIT_SPELLCAST_STOP(event, unit, spell)
147 Aranarth-82994
        if unit ~= "player" or spell ~= watchedSpell then return end
148 Aranarth-82994
        self:UnregisterEvent"UNIT_SPELLCAST_SUCCEEDED"
149 Aranarth-82994
        self:UnregisterEvent"UNIT_SPELLCAST_STOP"
150 Aranarth-82994
        if event ~= "UNIT_SPELLCAST_SUCCEEDED" then return end
151 Aranarth-82994
        local cd = watchedCDs[watchedID]
152 Aranarth-82994
        char[watchedID] = time() + cd.CD
153 Aranarth-82994
        if cd.group then config.names[cd.group] = watchedID end
154 Aranarth-82994
        config.icons[cd.group or watchedID] = watchedIcon
155 Aranarth-82994
        if config.displayCDs then e.timer = 0 end
156 Aranarth-82994
        if tipShown then Block_OnEnter(tipShown) end
157 Aranarth-82994
end
158 Aranarth-82994
f.UNIT_SPELLCAST_SUCCEEDED = f.UNIT_SPELLCAST_STOP
159 Aranarth-82994
 
160 Aranarth-82994
 
161 Aranarth-82994
local tables = {}
162 Aranarth-82994
 
163 Aranarth-82994
local function new(...)
164 Aranarth-82994
        local t = tremove(tables) or {}
165 Aranarth-82994
        for i = 1, select("#", ...), 2 do
166 Aranarth-82994
                local k, v = select(i, ...)
167 Aranarth-82994
                t[k] = v
168 Aranarth-82994
        end
169 Aranarth-82994
        return t
170 Aranarth-82994
end
171 Aranarth-82994
 
172 Aranarth-82994
local function del(t)
173 Aranarth-82994
        tables[#tables+1] = wipe(t)
174 Aranarth-82994
end
175 Aranarth-82994
 
176 Aranarth-82994
 
177 Aranarth-82994
local md, mx, xx, dd = 20*HOUR, 3*DAY+20*HOUR, { 86400, 3600, 60, 1 }, { L.d, L.h, L.m, L.s }
178 Aranarth-82994
local function SecondsToTime(s)
179 Aranarth-82994
        local p = s<md and s/md*.5 or s<mx and (s-md)/(mx-md)*.5+.5 or 1
180 Aranarth-82994
        local i = s>=86400 and 1 or s>=3600 and 2 or 3
181 Aranarth-82994
        return format( "|cff%.2x%.2x40%i%s %.2i%s|r",
182 Aranarth-82994
                p<.5 and 64+p*382 or 255, p<.5 and 255 or 446-p*382,
183 Aranarth-82994
                floor(s/xx[i]), dd[i], floor((s%xx[i])/xx[i+1]), dd[i+1] )
184 Aranarth-82994
end
185 Aranarth-82994
 
186 Aranarth-82994
local function ColorCurMax(cur,max,isProfession)
187 Aranarth-82994
        local pMax = isProfession and min(max/450,1) or 1
188 Aranarth-82994
        local pCur = isProfession and 1-min(sqrt(max-cur)/10,1) or 2/sqrt(max-cur+4)
189 Aranarth-82994
        return format( "|cff%.2x%.2x00%.3i|r / |cff%.2x%.2x00%.3i|r",
190 Aranarth-82994
                pCur<.5 and 255 or 510-pCur*510, pCur<.5 and pCur*510 or 255, cur,
191 Aranarth-82994
                pMax<.5 and 255 or 510-pMax*510, pMax<.5 and pMax*510 or 255, max )
192 Aranarth-82994
end
193 Aranarth-82994
 
194 Aranarth-82994
local function SortSkills(a, b)
195 Aranarth-82994
        if not a.isProfession == not b.isProfession then
196 Aranarth-82994
                if a.primary == b.primary then
197 Aranarth-82994
                        return a.displayName < b.displayName
198 Aranarth-82994
                else    return a.primary
199 Aranarth-82994
                end
200 Aranarth-82994
        else return a.isProfession end
201 Aranarth-82994
end
202 Aranarth-82994
 
203 Aranarth-82994
local function SortCooldowns(a, b)
204 Aranarth-82994
        if a.group and a.group == b.group then
205 Aranarth-82994
                return a.timeLeft > b.timeLeft
206 Aranarth-82994
        else    return a.name < b.name end
207 Aranarth-82994
end
208 Aranarth-82994
 
209 Aranarth-82994
local function SortShortcuts(a, b)
210 Aranarth-82994
        if a.skill == b.skill then
211 Aranarth-82994
                return a.name < b.name
212 Aranarth-82994
        else    return a.skill < b.skill end
213 Aranarth-82994
end
214 Aranarth-82994
 
215 Aranarth-82994
local function SortAltSkills(a, b)
216 Aranarth-82994
        local primA = bit_band( skills[a], SECONDARY ) == 0
217 Aranarth-82994
        local primB = bit_band( skills[b], SECONDARY ) == 0
218 Aranarth-82994
        if primA == primB then
219 Aranarth-82994
                return a < b
220 Aranarth-82994
        else    return primA end
221 Aranarth-82994
end
222 Aranarth-82994
 
223 Aranarth-82994
local function SortAlts(a, b)
224 Aranarth-82994
        return a.name < b.name
225 Aranarth-82994
end
226 Aranarth-82994
 
227 Aranarth-82994
 
228 Aranarth-82994
local function UpdateText()
229 Aranarth-82994
        f.block.icon = select(3, GetSpellInfo(char.skill or 0)) or "Interface\\Icons\\Achievement_Halloween_Witch_01"
230 4 Aranarth-82994
        if not config.displayCDs then f.block.text = " " .. (char.skill or _G.TRADE_SKILLS) end
231 3 Aranarth-82994
end
232 Aranarth-82994
 
233 Aranarth-82994
local orgAbandonSkill = _G.AbandonSkill
234 Aranarth-82994
function AbandonSkill(...)
235 Aranarth-82994
        if char.skill == GetSkillLineInfo(...) then char.skill=nil UpdateText() end
236 Aranarth-82994
        return orgAbandonSkill(...)
237 Aranarth-82994
end
238 Aranarth-82994
 
239 Aranarth-82994
local function CreateHL(frame)
240 Aranarth-82994
        local hl = frame:CreateTexture()
241 Aranarth-82994
        hl:SetTexture"Interface\\QuestFrame\\UI-QuestLogTitleHighlight"
242 Aranarth-82994
        hl:SetBlendMode"ADD"
243 Aranarth-82994
        hl:SetAlpha(0)
244 Aranarth-82994
        return hl
245 Aranarth-82994
end
246 Aranarth-82994
local highlight = CreateHL(f)
247 Aranarth-82994
local altLight = CreateHL(g)
248 Aranarth-82994
 
249 Aranarth-82994
 
250 Aranarth-82994
local function Tradeskill_OnClick(button, click)
251 Aranarth-82994
        if IsShiftKeyDown() and bit_band( skills[button.skill], LINK ) > 0 then
252 Aranarth-82994
                f.getLink = true
253 Aranarth-82994
                if TradeSkillFrame and TradeSkillFrame:IsShown() then
254 Aranarth-82994
                        f.keepOpen = true
255 Aranarth-82994
                        CloseTradeSkill()
256 Aranarth-82994
                end
257 Aranarth-82994
                f:RegisterEvent"TRADE_SKILL_SHOW"
258 Aranarth-82994
        elseif click == "RightButton" then
259 Aranarth-82994
                f.learnCD = true
260 Aranarth-82994
                if TradeSkillFrame and TradeSkillFrame:IsShown() then
261 Aranarth-82994
                        f.keepOpen = true
262 Aranarth-82994
                        CloseTradeSkill()
263 Aranarth-82994
                end
264 Aranarth-82994
                f:RegisterEvent"TRADE_SKILL_SHOW"
265 Aranarth-82994
        elseif click == "MiddleButton" then
266 Aranarth-82994
                char.show[button.skill] = not char.show[button.skill]
267 Aranarth-82994
                return Block_OnEnter(tipShown)
268 Aranarth-82994
        elseif bit_band( skills[button.skill], PANEL ) > 0 then
269 Aranarth-82994
                char.skill = button.skill
270 Aranarth-82994
                UpdateText()
271 Aranarth-82994
                button.fontLeft:SetTextColor(unpack(config.colors.selected))
272 Aranarth-82994
                if f.selected and f.selected ~= button then f.selected.fontLeft:SetTextColor(unpack(config.colors.activeName)) end
273 Aranarth-82994
                f.selected = button
274 Aranarth-82994
        else return end
275 Aranarth-82994
        CastSpellByName(button.skill)
276 Aranarth-82994
end
277 Aranarth-82994
 
278 Aranarth-82994
local function Cooldown_OnClick(button, click)
279 Aranarth-82994
        local group = watchedCDs[button.spellID].group
280 Aranarth-82994
        if click == "MiddleButton" then
281 Aranarth-82994
                local char = realm[button.owner]
282 Aranarth-82994
                if group then -- remove group
283 Aranarth-82994
                        for k, v in next, watchedCDs do
284 Aranarth-82994
                                if v.group == group then char[k] = nil end
285 Aranarth-82994
                        end
286 Aranarth-82994
                else
287 Aranarth-82994
                        char[button.spellID] = nil
288 Aranarth-82994
                end
289 Aranarth-82994
                Block_OnEnter(tipShown)
290 Aranarth-82994
        elseif click == "LeftButton" and IsControlKeyDown() then
291 Aranarth-82994
                f.alias, f.aliasID = button.fontLeft:GetText(), group or button.spellID
292 Aranarth-82994
                StaticPopup_Show("SET_ALIAS", config.names[button.spellID] or group)
293 Aranarth-82994
        else
294 Aranarth-82994
                f.doTradeSkill = click == "LeftButton" and not IsModifierKeyDown()
295 Aranarth-82994
                f.searchedSpellID = button.spellID
296 Aranarth-82994
                if TradeSkillFrame and TradeSkillFrame:IsShown() then CloseTradeSkill() end
297 Aranarth-82994
                f:RegisterEvent"TRADE_SKILL_SHOW"
298 Aranarth-82994
                CastSpellByName(button.skill)
299 Aranarth-82994
        end
300 Aranarth-82994
end
301 Aranarth-82994
 
302 Aranarth-82994
local function Shortcut_OnClick(button, click)
303 Aranarth-82994
        if IsControlKeyDown() then
304 Aranarth-82994
                f.alias, f.aliasID = button.fontLeft:GetText(), button.spellID
305 Aranarth-82994
                StaticPopup_Show("SET_ALIAS", config.names[button.spellID])
306 Aranarth-82994
        elseif click == "MiddleButton" then
307 Aranarth-82994
                char.shortcuts[button.spellID] = nil
308 Aranarth-82994
                Block_OnEnter(tipshown)
309 Aranarth-82994
        else
310 Aranarth-82994
                f.doTradeSkill = click == "LeftButton" and not IsModifierKeyDown()
311 Aranarth-82994
                f.searchedSpellID = button.spellID
312 Aranarth-82994
                f.shortcut = true
313 Aranarth-82994
                if TradeSkillFrame and TradeSkillFrame:IsShown() then CloseTradeSkill() end
314 Aranarth-82994
                f:RegisterEvent"TRADE_SKILL_SHOW"
315 Aranarth-82994
                CastSpellByName(button.skill)
316 Aranarth-82994
        end
317 Aranarth-82994
end
318 Aranarth-82994
 
319 Aranarth-82994
local function Link_OnClick(button, click)
320 Aranarth-82994
        if not button.link then return end
321 Aranarth-82994
        if IsModifierKeyDown() then
322 Aranarth-82994
                if not ChatEdit_InsertLink(button.link) then
323 Aranarth-82994
                        ChatFrameEditBox:Show()
324 Aranarth-82994
                        ChatEdit_InsertLink(button.link)
325 Aranarth-82994
                end
326 Aranarth-82994
        elseif click == "LeftButton" then
327 Aranarth-82994
                if button.skill == prevAltSkill and TradeSkillFrame and TradeSkillFrame:IsShown() then
328 Aranarth-82994
                        return CloseTradeSkill()
329 Aranarth-82994
                end
330 Aranarth-82994
                prevAltSkill = button.skill
331 Aranarth-82994
                SetItemRef(button.link:match"|H([^|]+)")
332 Aranarth-82994
        end
333 Aranarth-82994
end
334 Aranarth-82994
 
335 Aranarth-82994
local function ProfessionsBook_OnClick()
336 Aranarth-82994
        ProfessionsBook:ShowFrame()
337 Aranarth-82994
end
338 Aranarth-82994
 
339 Aranarth-82994
 
340 Aranarth-82994
local function Alt_OnEnter(self)
341 Aranarth-82994
        if self and self.light then
342 Aranarth-82994
                altLight:SetAllPoints(self)
343 Aranarth-82994
                altLight:SetAlpha(1)
344 Aranarth-82994
 
345 Aranarth-82994
                if config.hideTips then return end
346 Aranarth-82994
                local hasLink = bit_band( skills[self.skill], LINK ) > 0
347 Aranarth-82994
                if not( self.link or hasLink ) then return end
348 Aranarth-82994
 
349 Aranarth-82994
                tip:SetOwner(g, "ANCHOR_NONE")
350 Aranarth-82994
                local showRight = f:GetCenter() > UIParent:GetWidth()/2 and "RIGHT" or "LEFT"
351 Aranarth-82994
                local showBelow = select(2, g:GetCenter()) > UIParent:GetHeight()/2 and "TOP" or "BOTTOM"
352 Aranarth-82994
                tip:SetPoint(showBelow..showRight, g, (showBelow == "TOP" and "BOTTOM" or "TOP")..showRight )
353 Aranarth-82994
 
354 Aranarth-82994
                tip:AddLine(L.Hints)
355 Aranarth-82994
                if self.link then
356 Aranarth-82994
                        tip:AddLine(L"|cffff8020Click|r to toggle panel.", .2,1,.2)
357 Aranarth-82994
                        tip:AddLine(L"|cffff8020Shift+Click|r to link in chat.", .2,1,.2)
358 Aranarth-82994
                elseif hasLink then
359 Aranarth-82994
                        tip:AddLine(L"No link available. Open a character\ntradeskill panel to be able to access\nit from your other characters.", 1, .6, .2)
360 Aranarth-82994
                end
361 Aranarth-82994
                tip:Show()
362 Aranarth-82994
        end
363 Aranarth-82994
end
364 Aranarth-82994
 
365 Aranarth-82994
local function Alt_OnLeave(self)
366 Aranarth-82994
        altLight:ClearAllPoints()
367 Aranarth-82994
        if self and self.light then
368 Aranarth-82994
                altLight:SetAlpha(0)
369 Aranarth-82994
                tip:Hide()
370 Aranarth-82994
        end
371 Aranarth-82994
        if not MouseIsOver(f) and not MouseIsOver(g) then
372 Aranarth-82994
                tipShown = nil
373 Aranarth-82994
                f:Hide() g:Hide() tip:Hide()
374 Aranarth-82994
        end
375 Aranarth-82994
end
376 Aranarth-82994
 
377 Aranarth-82994
local function Menu_OnEnter(self)
378 Aranarth-82994
        if self and self.light then
379 Aranarth-82994
                highlight:SetAllPoints(self)
380 Aranarth-82994
                highlight:SetAlpha(1)
381 Aranarth-82994
                if config.hideTips or self.skill == "None" then return end
382 Aranarth-82994
                tip:SetOwner(f, "ANCHOR_NONE")
383 Aranarth-82994
                local showRight = f:GetCenter() > UIParent:GetWidth()/2 and "LEFT" or "RIGHT"
384 Aranarth-82994
                local showBelow = select(2, f:GetCenter()) > UIParent:GetHeight()/2 and "TOP" or "BOTTOM"
385 Aranarth-82994
                tip:SetPoint(showBelow..showRight, f, (showBelow == "TOP" and "BOTTOM" or "TOP")..showRight )
386 Aranarth-82994
                tip:AddLine(L.Hints)
387 Aranarth-82994
                if self.shortcut then
388 Aranarth-82994
                        tip:AddLine(L"|cffff8020Click|r to craft.", .2,1,.2)
389 Aranarth-82994
                        tip:AddLine(L"|cffff8020Right-Click|r to show in panel.", .2,1,.2)
390 Aranarth-82994
                        tip:AddLine(L"|cffff8020Control+Click|r to set an alias.", .2, 1, .2)
391 Aranarth-82994
                elseif self.spellID then
392 Aranarth-82994
                        tip:AddDoubleLine(L"Belongs to:", self.owner, 1,1,1,1,1,1)
393 Aranarth-82994
                        if self.owner == playerName and self.ready then
394 Aranarth-82994
                                tip:AddLine(L"|cffff8020Click|r to craft.", .2,1,.2)
395 Aranarth-82994
                                tip:AddLine(L"|cffff8020Right-Click|r to show CD in panel.", .2,1,.2)
396 Aranarth-82994
                        elseif char.show[watchedCDs[self.spellID].skill] ~= nil then
397 Aranarth-82994
                                tip:AddLine(L"|cffff8020Click|r to show CD in panel.", .2,1,.2)
398 Aranarth-82994
                        end
399 Aranarth-82994
                        tip:AddLine(L"|cffff8020Control+Click|r to set an alias.", .2, 1, .2)
400 Aranarth-82994
                else
401 Aranarth-82994
                        local hasPanel = bit_band( skills[self.skill], PANEL ) > 0
402 Aranarth-82994
                        local hasLink = bit_band( skills[self.skill], LINK ) > 0
403 Aranarth-82994
                        if hasPanel then tip:AddLine(L"|cffff8020Click|r to toggle panel.", .2,1,.2) end
404 Aranarth-82994
                        if hasLink then tip:AddLine(L"|cffff8020Shift+Click|r to link in chat.", .2,1,.2) end
405 Aranarth-82994
                        if hasPanel then tip:AddLine(L"|cffff8020Right-Click|r to scan for CDs.", .2,1,.2) end
406 Aranarth-82994
                end
407 Aranarth-82994
                tip:AddLine(L"|cffff8020Middle-Click|r to remove from list.", .2, 1, .2)
408 Aranarth-82994
                tip:Show()
409 Aranarth-82994
        end
410 Aranarth-82994
end
411 Aranarth-82994
 
412 Aranarth-82994
local function Menu_OnLeave(self)
413 Aranarth-82994
        highlight:ClearAllPoints()
414 Aranarth-82994
        if self and self.light then
415 Aranarth-82994
                highlight:SetAlpha(0)
416 Aranarth-82994
                tip:Hide()
417 Aranarth-82994
        end
418 Aranarth-82994
        if not MouseIsOver(f) and ( InCombatLockdown() or not MouseIsOver(g) ) then
419 Aranarth-82994
                tipShown = nil
420 Aranarth-82994
                f:Hide() g:Hide() tip:Hide()
421 Aranarth-82994
        end
422 Aranarth-82994
end
423 Aranarth-82994
 
424 Aranarth-82994
 
425 Aranarth-82994
local metatable = { __index = function(table, key)
426 Aranarth-82994
        local button = CreateFrame("Button", nil, workingFrame)
427 Aranarth-82994
        rawset(table, key, button)
428 Aranarth-82994
        button:RegisterForClicks"AnyUp"
429 Aranarth-82994
        button:SetHeight(BUTTON_HEIGHT)
430 Aranarth-82994
        button:SetPoint("TOPLEFT", workingFrame, "TOPLEFT", GAP, BUTTON_HEIGHT * (1-key) - GAP)
431 Aranarth-82994
        button:SetScript("OnEnter", workingFrame == f and Menu_OnEnter or Alt_OnEnter)
432 Aranarth-82994
        button:SetScript("OnLeave", workingFrame == f and Menu_OnLeave or Alt_OnLeave)
433 Aranarth-82994
        button.icon = button:CreateTexture(nil, "OVERLAY")
434 Aranarth-82994
        button.icon:SetWidth(ICON_SIZE) button.icon:SetHeight(ICON_SIZE)
435 Aranarth-82994
        button.icon:SetPoint("LEFT", button, "LEFT")
436 Aranarth-82994
        button.fontLeft = button:CreateFontString(nil, "OVERLAY", "SystemFont_Shadow_Med1")
437 Aranarth-82994
        button.fontLeft:SetPoint("LEFT", button, "LEFT", ICON_SIZE + TEXT_OFFSET, 0)
438 Aranarth-82994
        button.fontRight = button:CreateFontString(nil, "OVERLAY", "SystemFont_Shadow_Med1")
439 Aranarth-82994
        button.fontRight:SetPoint("RIGHT", button, "RIGHT")
440 Aranarth-82994
        return button
441 Aranarth-82994
end }
442 Aranarth-82994
 
443 Aranarth-82994
local buttons = setmetatable( {}, metatable )
444 Aranarth-82994
local altButtons = setmetatable( {}, metatable )
445 Aranarth-82994
 
446 Aranarth-82994
 
447 Aranarth-82994
local function AddEntry( buttons, icon, leftText, leftTextColor, rightText, rightTextColor, highlight )
448 Aranarth-82994
        nbEntries = nbEntries + 1
449 Aranarth-82994
        local button = buttons[nbEntries]
450 Aranarth-82994
        button.icon:SetTexture(icon or "")
451 Aranarth-82994
        if icon then button.icon:SetTexCoord(0.075, 0.925, 0.075, 0.925) end
452 Aranarth-82994
        button.fontLeft:SetText(leftText or "")
453 Aranarth-82994
        if leftTextColor then button.fontLeft:SetTextColor(unpack(leftTextColor)) end
454 Aranarth-82994
        button.fontRight:SetText(rightText or "")
455 Aranarth-82994
        if rightTextColor then button.fontRight:SetTextColor(unpack(rightTextColor)) end
456 Aranarth-82994
        button.light = highlight
457 Aranarth-82994
        button:Show()
458 Aranarth-82994
        return button, ICON_SIZE + TEXT_OFFSET + (leftText and button.fontLeft:GetStringWidth() or 0), rightText and button.fontRight:GetStringWidth() or 0
459 Aranarth-82994
end
460 Aranarth-82994
 
461 Aranarth-82994
 
462 Aranarth-82994
local function UpdateCDs()
463 Aranarth-82994
        local readyCDs = 0
464 Aranarth-82994
        local temp = new()
465 Aranarth-82994
        local dups = new()
466 Aranarth-82994
        local now = time()
467 Aranarth-82994
 
468 Aranarth-82994
        for i, v in next, CDs do
469 Aranarth-82994
                del(v)
470 Aranarth-82994
                CDs[i] = nil
471 Aranarth-82994
        end
472 Aranarth-82994
 
473 Aranarth-82994
        for char, data in next, realm do
474 Aranarth-82994
                for spellID, expireTime in next, data do
475 Aranarth-82994
                        if type(spellID)=="number" then
476 Aranarth-82994
                                local cd = watchedCDs[spellID]
477 7 Aranarth-82994
                                if cd then
478 Aranarth-82994
                                        temp[#temp+1] = new(
479 Aranarth-82994
                                                "name", cd.group and (config.aliases[cd.group] or cd.group) or config.aliases[spellID] or config.names[spellID] or GetSpellInfo(spellID),
480 Aranarth-82994
                                                "timeLeft", expireTime-now,
481 Aranarth-82994
                                                "char", char,
482 Aranarth-82994
                                                "spellID", spellID,
483 Aranarth-82994
                                                "skill", cd.skill,
484 Aranarth-82994
                                                "group", cd.group)
485 Aranarth-82994
                                end
486 3 Aranarth-82994
                        end
487 Aranarth-82994
                end
488 Aranarth-82994
        end
489 Aranarth-82994
        sort(temp, SortCooldowns)
490 Aranarth-82994
 
491 Aranarth-82994
        for i=1, #temp do
492 Aranarth-82994
                local cd = temp[i]
493 Aranarth-82994
                if not dups[cd.group] then
494 Aranarth-82994
                        CDs[#CDs+1] = cd
495 Aranarth-82994
                        if cd.timeLeft <= 0 then readyCDs = readyCDs + 1 end
496 Aranarth-82994
                end
497 Aranarth-82994
                if cd.group then dups[cd.group] = true end
498 Aranarth-82994
        end
499 Aranarth-82994
 
500 Aranarth-82994
        del(temp)
501 Aranarth-82994
        del(dups)
502 Aranarth-82994
 
503 Aranarth-82994
        if config.displayCDs then
504 Aranarth-82994
        --      local perc = readyCDs/totalCDs
505 Aranarth-82994
        --      f.block.text = format(" |cff%.2x%.2x00%i/%i|r CD%s", perc<.5 and 255 or 510-perc*510, perc<.5 and perc*510 or 255, readyCDs, totalCDs, totalCDs>0 and "s" or "")
506 Aranarth-82994
                f.block.text = format(" %i/%i CD%s", readyCDs, #CDs, #CDs>1 and "s" or "")
507 Aranarth-82994
        end
508 Aranarth-82994
end
509 Aranarth-82994
 
510 Aranarth-82994
local function SetMainPoint()
511 Aranarth-82994
 
512 Aranarth-82994
end
513 Aranarth-82994
 
514 Aranarth-82994
local function ShowAlts()
515 Aranarth-82994
        workingFrame = g
516 Aranarth-82994
        nbEntries = 0
517 Aranarth-82994
        altLight:SetVertexColor(unpack(config.colors.highlight))
518 Aranarth-82994
        local firstEntry, button = true
519 Aranarth-82994
        local itemLeftWidth, itemRightWidth, colRightWidth, colLeftWidth = 0, 0, 0, 0
520 Aranarth-82994
        local list, subList = new(), new()
521 Aranarth-82994
 
522 Aranarth-82994
        for charName, charData in next, realm do
523 Aranarth-82994
                if charName ~= playerName and charData.curSkills and next(charData.curSkills) then
524 Aranarth-82994
                        list[#list+1] = new("name",charName,"curSkills",charData.curSkills,"maxSkills",charData.maxSkills,"links",charData.links)
525 Aranarth-82994
                end
526 Aranarth-82994
        end
527 Aranarth-82994
        sort(list,SortAlts)
528 Aranarth-82994
        for _, char in ipairs(list) do
529 Aranarth-82994
                if firstEntry then firstEntry = false else AddEntry(altButtons) end
530 Aranarth-82994
                AddEntry( altButtons, "", char.name, config.colors.header )
531 Aranarth-82994
                for skill, value in next, char.maxSkills do
532 Aranarth-82994
                        if value > 1 then subList[#subList+1] = skill end
533 Aranarth-82994
                end
534 Aranarth-82994
        --      sort(subList)
535 Aranarth-82994
                sort(subList, SortAltSkills)
536 Aranarth-82994
                for _, skill in ipairs(subList) do
537 Aranarth-82994
                        local bitSkill = skills[skill]
538 Aranarth-82994
                        if not config.primaryOnly or bit_band(bitSkill, SECONDARY) == 0 then
539 Aranarth-82994
                                local hasLink = bit_band(bitSkill, LINK) > 0
540 Aranarth-82994
                                local color = hasLink and config.colors.activeName or config.colors.infoName
541 Aranarth-82994
                                local icon = select(3,GetSpellInfo(floor(bitSkill/SPELL_ID)))
542 Aranarth-82994
                                local strValues = ColorCurMax( char.curSkills[skill], char.maxSkills[skill], true )
543 Aranarth-82994
 
544 Aranarth-82994
                                button, itemLeftWidth, itemRightWidth = AddEntry( altButtons,
545 Aranarth-82994
                                        icon, skill, color, strValues, nil, hasLink)
546 Aranarth-82994
                                button:SetScript("OnClick", Link_OnClick)
547 Aranarth-82994
                                button.link = char.links and char.links[skill]
548 Aranarth-82994
                                button.skill = skill
549 Aranarth-82994
                                if itemLeftWidth > colLeftWidth then colLeftWidth = itemLeftWidth + GAP end
550 Aranarth-82994
                                if itemRightWidth > colRightWidth then colRightWidth = itemRightWidth end
551 Aranarth-82994
                        end
552 Aranarth-82994
                end
553 Aranarth-82994
                wipe(subList)
554 Aranarth-82994
        end
555 Aranarth-82994
        del(list)
556 Aranarth-82994
        del(subList)
557 Aranarth-82994
        g:Show()
558 Aranarth-82994
        if _G.Skinner then _G.Skinner:applySkin(g) end
559 Aranarth-82994
        if InCombatLockdown() then return end
560 Aranarth-82994
 
561 Aranarth-82994
        local maxWidth = colLeftWidth + colRightWidth
562 Aranarth-82994
        for i=1, nbEntries do altButtons[i]:SetWidth(maxWidth) end
563 Aranarth-82994
        g:SetWidth(maxWidth + GAP*2)
564 Aranarth-82994
        g:SetHeight(BUTTON_HEIGHT * nbEntries + GAP*2)
565 Aranarth-82994
 
566 Aranarth-82994
        local horiz = f:GetCenter() > UIParent:GetWidth()/2 and "RIGHT" or "LEFT"
567 Aranarth-82994
        local verti = select(2, f:GetCenter()) > UIParent:GetHeight()/2 and "TOP" or "BOTTOM"
568 Aranarth-82994
        g:ClearAllPoints()
569 Aranarth-82994
        g:SetPoint(verti..horiz, f, verti..(horiz=="LEFT"and"RIGHT"or"LEFT"))
570 Aranarth-82994
 
571 Aranarth-82994
        for i=nbEntries+1, #altButtons do altButtons[i]:Hide() end
572 Aranarth-82994
        if nbEntries == 0 then g:Hide() end
573 Aranarth-82994
end
574 Aranarth-82994
 
575 Aranarth-82994
 
576 Aranarth-82994
Block_OnEnter = function(self)
577 Aranarth-82994
        workingFrame = f
578 Aranarth-82994
        highlight:SetVertexColor(unpack(config.colors.highlight))
579 Aranarth-82994
        f:Show()
580 Aranarth-82994
        if InCombatLockdown() then return else CloseDropDownMenus() end
581 Aranarth-82994
        tipShown = tipShown or self
582 Aranarth-82994
        Menu_OnEnter(tipShown)
583 Aranarth-82994
        nbEntries = 0
584 Aranarth-82994
        local char = realm[playerName] -- dirty fix
585 Aranarth-82994
 
586 Aranarth-82994
        local firstCombatSkill, button, selectedSkillExists = true
587 Aranarth-82994
        local itemLeftWidth, itemRightWidth, colRightWidth, colLeftWidth, skillWidth, cdWidth = 0, 0, 0, 0
588 Aranarth-82994
 
589 Aranarth-82994
        UpdateCDs()
590 Aranarth-82994
        local showCDs, showProfessions, showCombatSkills, showShortcuts = min(#CDs,1), 0, 0, next(char.shortcuts) and 1 or 0
591 Aranarth-82994
        for k,v in next,f.skills do del(v) f.skills[k]=nil end
592 Aranarth-82994
 
593 Aranarth-82994
        ExpandSkillHeader(0)
594 Aranarth-82994
        for i=1, GetNumSkillLines() do
595 Aranarth-82994
                local displayName, skill, skillName, value, _, _, valueMax = GetSkillLineInfo(i)
596 Aranarth-82994
                skillName = altNames[displayName] or displayName
597 Aranarth-82994
                skill = skills[skillName]
598 Aranarth-82994
                if skill then
599 Aranarth-82994
                        local hasPanel, isProfession = bit_band(skill,PANEL)>0, bit_band(skill,PROFESSION)>0
600 Aranarth-82994
                        if char.show[skillName] == nil then char.show[skillName] = hasPanel end
601 Aranarth-82994
                        local show = (isProfession and not char.hideProfessions or not isProfession and not char.hideCombatSkills) and char.show[skillName]
602 Aranarth-82994
                        if show then if isProfession then showProfessions=1 else showCombatSkills=1 end end
603 Aranarth-82994
                        f.skills[#f.skills+1] = new(
604 Aranarth-82994
                                "displayName",  displayName,
605 Aranarth-82994
                                "skillName",    skillName,
606 Aranarth-82994
                                "isProfession", isProfession and floor(skill/SPELL_ID),
607 Aranarth-82994
                                "isCombatSkill",not isProfession,
608 Aranarth-82994
                                "hasPanel",     hasPanel,
609 Aranarth-82994
                                "color",        skillName==char.skill and config.colors.selected or hasPanel and config.colors.activeName or config.colors.infoName,
610 Aranarth-82994
                                "strValue",     valueMax <= 1 and "" or ColorCurMax(value,valueMax,isProfession),
611 Aranarth-82994
                                "show",         show,
612 Aranarth-82994
                                "primary",      bit_band(skill,SECONDARY) == 0)
613 Aranarth-82994
                        if isProfession then char.curSkills[skillName], char.maxSkills[skillName] = value, valueMax end
614 Aranarth-82994
                end
615 Aranarth-82994
        end
616 Aranarth-82994
        local nbHeaders = showProfessions + showCombatSkills + showCDs + showShortcuts
617 Aranarth-82994
 
618 Aranarth-82994
        sort(f.skills, SortSkills)
619 Aranarth-82994
        for i, v in ipairs(f.skills) do
620 Aranarth-82994
                if v.show then
621 Aranarth-82994
                        if nbEntries == 0 and showProfessions == 1 and nbHeaders > 1 then
622 4 Aranarth-82994
                                AddEntry(buttons, "", _G.TRADE_SKILLS, config.colors.header)
623 3 Aranarth-82994
                        end
624 Aranarth-82994
                        if v.isCombatSkill and firstCombatSkill and nbHeaders > 1 then
625 Aranarth-82994
                                firstCombatSkill = false
626 Aranarth-82994
                                if nbEntries > 0 then AddEntry(buttons) end
627 Aranarth-82994
                                AddEntry(buttons, "", L"Combat Skills", config.colors.header)
628 Aranarth-82994
                        end
629 Aranarth-82994
                        local texture = altIcons[v.skillName] or select(3,GetSpellInfo(v.isProfession)) or ""
630 Aranarth-82994
                        button, itemLeftWidth, itemRightWidth = AddEntry( buttons,
631 Aranarth-82994
                                texture, v.displayName, v.color, v.strValue,
632 Aranarth-82994
                                nil, true)
633 Aranarth-82994
                        button:SetScript("OnClick", Tradeskill_OnClick)
634 Aranarth-82994
                        button.skill, button.spellID, button.shortcut = v.skillName
635 Aranarth-82994
                        if v.color == config.colors.selected then f.selected = button end
636 Aranarth-82994
                        if itemLeftWidth > colLeftWidth then colLeftWidth = itemLeftWidth end
637 Aranarth-82994
                        if itemRightWidth > colRightWidth then colRightWidth = itemRightWidth end
638 Aranarth-82994
                end
639 Aranarth-82994
        end
640 Aranarth-82994
        skillWidth = colLeftWidth + colRightWidth
641 Aranarth-82994
        colRightWidth, colLeftWidth = 0, 0, 0, 0
642 Aranarth-82994
 
643 Aranarth-82994
        -- Cooldowns
644 Aranarth-82994
        local dups = new()
645 Aranarth-82994
        for index, data in ipairs(CDs) do
646 Aranarth-82994
                local group = data.group
647 Aranarth-82994
                if not group or not dups[group] then
648 Aranarth-82994
                        if group then dups[group] = true end
649 Aranarth-82994
                        if index == 1 then
650 Aranarth-82994
                                if nbEntries>0 then AddEntry(buttons) end
651 Aranarth-82994
                                if nbHeaders>1 then AddEntry(buttons, "", L.Cooldowns, config.colors.header) end
652 Aranarth-82994
                        end
653 Aranarth-82994
                        button, itemLeftWidth, itemRightWidth = AddEntry( buttons,
654 Aranarth-82994
                                config.icons[group or data.spellID] or config.names[group] and select(3,GetSpellInfo(config.names[group])) or groupIcons[group], data.name,
655 Aranarth-82994
                                data.char == playerName and config.colors.ownCD or config.colors.foreignCD,
656 Aranarth-82994
                                data.timeLeft<=0 and L"|cff20ff20Ready!|r" or SecondsToTime(data.timeLeft),
657 Aranarth-82994
                                nil, true )
658 Aranarth-82994
                        button:SetScript("OnClick", Cooldown_OnClick)
659 Aranarth-82994
                        button.skill, button.spellID, button.ready, button.owner, button.shortcut = data.skill, group and config.names[group] or data.spellID, data.timeLeft<=0, data.char
660 Aranarth-82994
                        if itemLeftWidth > colLeftWidth then colLeftWidth = itemLeftWidth end
661 Aranarth-82994
                        if itemRightWidth > colRightWidth then colRightWidth = itemRightWidth end
662 Aranarth-82994
                end
663 Aranarth-82994
        end
664 Aranarth-82994
        del(dups)
665 Aranarth-82994
        cdWidth = colLeftWidth + colRightWidth
666 Aranarth-82994
        colLeftWidth = 0
667 Aranarth-82994
 
668 Aranarth-82994
        -- Shortcuts
669 Aranarth-82994
        local shortcuts = new()
670 Aranarth-82994
        for spellID, skill in next, char.shortcuts do
671 Aranarth-82994
                shortcuts[#shortcuts+1] = new(
672 Aranarth-82994
                        "skill", skill,
673 Aranarth-82994
                        "name", config.aliases[spellID] or config.names[spellID],
674 Aranarth-82994
                        "spellID", spellID)
675 Aranarth-82994
        end
676 Aranarth-82994
        sort(shortcuts, SortShortcuts)
677 Aranarth-82994
        local firstShortcut = true
678 Aranarth-82994
        for _, shortcut in ipairs(shortcuts) do
679 Aranarth-82994
                if firstShortcut then
680 Aranarth-82994
                        firstShortcut = false
681 Aranarth-82994
                        if nbEntries>0 then AddEntry(buttons) end
682 Aranarth-82994
                        if nbHeaders>1 then AddEntry(buttons, "", L.Shortcuts, config.colors.header) end
683 Aranarth-82994
                end
684 Aranarth-82994
                button, itemLeftWidth = AddEntry( buttons,
685 Aranarth-82994
                        config.icons[shortcut.spellID], shortcut.name, config.colors.activeName, nil, nil, true )
686 Aranarth-82994
                if itemLeftWidth > colLeftWidth then colLeftWidth = itemLeftWidth end
687 Aranarth-82994
                button:SetScript("OnClick", Shortcut_OnClick)
688 Aranarth-82994
                button.skill, button.spellID, button.ready, button.shortcut = shortcut.skill, shortcut.spellID, true, true
689 Aranarth-82994
        end
690 Aranarth-82994
        del(shortcuts)
691 Aranarth-82994
 
692 Aranarth-82994
        -- ProfessionsBook
693 Aranarth-82994
        if ProfessionsBook then
694 Aranarth-82994
                if nbEntries>0 then AddEntry(buttons) end
695 Aranarth-82994
                if nbHeaders>1 then AddEntry(buttons, "", L"Miscellaneous", config.colors.header) end
696 Aranarth-82994
                button, itemLeftWidth = AddEntry( buttons, "Interface\\Spellbook\\Spellbook-Icon", "ProfessionsBook", config.colors.activeName, nil, nil, true )
697 Aranarth-82994
                button:SetScript("OnClick", ProfessionsBook_OnClick)
698 Aranarth-82994
                button.skill, button.spellID, button.ready, button.shortcut = "None"
699 Aranarth-82994
        end
700 Aranarth-82994
 
701 Aranarth-82994
        local maxWidth = math.max(skillWidth, cdWidth, colLeftWidth, itemLeftWidth) + GAP
702 Aranarth-82994
        for i=1, nbEntries do buttons[i]:SetWidth(maxWidth) end
703 Aranarth-82994
        f:SetWidth(maxWidth + GAP*2)
704 Aranarth-82994
        f:SetHeight(BUTTON_HEIGHT * nbEntries + GAP*2)
705 Aranarth-82994
        if _G.Skinner then _G.Skinner:applySkin(f) end
706 Aranarth-82994
 
707 Aranarth-82994
        local showBelow = select(2, tipShown:GetCenter()) > ( UIParent:GetHeight() / 2)
708 Aranarth-82994
        f:ClearAllPoints()
709 Aranarth-82994
        f:SetPoint(showBelow and "TOP" or "BOTTOM", tipShown, showBelow and "BOTTOM" or "TOP")
710 Aranarth-82994
 
711 Aranarth-82994
        for i=nbEntries+1, #buttons do buttons[i]:Hide() end
712 Aranarth-82994
        if nbEntries == 0 then f:Hide() elseif not config.hideAlts then
713 Aranarth-82994
                return InCombatLockdown() and g:Show() or ShowAlts()
714 Aranarth-82994
        end
715 Aranarth-82994
end
716 Aranarth-82994
 
717 Aranarth-82994
 
718 Aranarth-82994
local function Block_OnClick(self, click)
719 Aranarth-82994
        if click == "LeftButton" then
720 Aranarth-82994
                if skills[char.skill] then CastSpellByName(char.skill) end
721 Aranarth-82994
        elseif click == "RightButton" then
722 Aranarth-82994
                f:Hide() tip:Hide() g:Hide()
723 Aranarth-82994
                UIDropDownMenu_Initialize(dropdown, dropdown_init, "MENU")
724 Aranarth-82994
                ToggleDropDownMenu(1, nil, dropdown, self, 0, 0)
725 Aranarth-82994
        end
726 Aranarth-82994
end
727 Aranarth-82994
 
728 Aranarth-82994
 
729 Aranarth-82994
f.block = LibStub("LibDataBroker-1.1"):NewDataObject("|cFFFFB366Ara|r Tradeskills", {
730 Aranarth-82994
        type = "data source",
731 Aranarth-82994
        text = _G.TRADESKILLS,
732 Aranarth-82994
        icon = "",
733 Aranarth-82994
        OnEnter = Block_OnEnter,
734 Aranarth-82994
        OnLeave = Menu_OnLeave,
735 Aranarth-82994
        OnClick = Block_OnClick,
736 Aranarth-82994
} )
737 Aranarth-82994
 
738 Aranarth-82994
 
739 Aranarth-82994
function f:TRADE_SKILL_SHOW()
740 Aranarth-82994
        self:UnregisterEvent"TRADE_SKILL_SHOW"
741 Aranarth-82994
        if self.getLink then
742 Aranarth-82994
                self.getLink = nil
743 Aranarth-82994
                local link = GetTradeSkillListLink()
744 Aranarth-82994
                if not ChatEdit_InsertLink(link) then
745 Aranarth-82994
                        ChatFrameEditBox:Show()
746 Aranarth-82994
                        ChatEdit_InsertLink(link)
747 Aranarth-82994
                end
748 Aranarth-82994
                if self.keepOpen then self.keepOpen = nil else CloseTradeSkill() end
749 Aranarth-82994
                return
750 Aranarth-82994
        end
751 Aranarth-82994
        ExpandTradeSkillSubClass(0)
752 Aranarth-82994
        SetTradeSkillSubClassFilter(0,1,1)
753 Aranarth-82994
        SetTradeSkillInvSlotFilter(0,1,1)
754 Aranarth-82994
        TradeSkillOnlyShowMakeable(false)
755 Aranarth-82994
        if TradeSkillFrameAvailableFilterCheckButton then
756 Aranarth-82994
                TradeSkillFrameAvailableFilterCheckButton:SetChecked(false)
757 Aranarth-82994
        end
758 Aranarth-82994
        for i=1, GetNumTradeSkills() do
759 Aranarth-82994
                local itemName, itemType = GetTradeSkillInfo(i)
760 Aranarth-82994
                if itemType ~= "header" then
761 Aranarth-82994
                        local spellID = tonumber(strmatch(GetTradeSkillRecipeLink(i), "enchant:(%d+)"))
762 Aranarth-82994
                        local cd = watchedCDs[spellID]
763 Aranarth-82994
                        if spellID == self.searchedSpellID and (cd or self.shortcut) then
764 Aranarth-82994
                                SelectTradeSkill(i)
765 Aranarth-82994
                                TradeSkillFrame_SetSelection(i)
766 Aranarth-82994
                                if self.doTradeSkill and not GetTradeSkillCooldown(i) then
767 Aranarth-82994
                                        DoTradeSkill(i)
768 Aranarth-82994
                                        CloseTradeSkill() -- TODO: don't close if it was open
769 Aranarth-82994
                                else
770 Aranarth-82994
                                        TradeSkillListScrollFrame:SetVerticalScroll(max(i-5,0)*TradeSkillSkill1:GetHeight())
771 Aranarth-82994
                                end
772 Aranarth-82994
                                self.searchedSpellID, self.doTradeSkill, self.shortcut = nil
773 Aranarth-82994
                                break
774 Aranarth-82994
                        end
775 Aranarth-82994
                        if cd and self.learnCD then
776 Aranarth-82994
                                local timeLeft = GetTradeSkillCooldown(i) or 0
777 Aranarth-82994
                                if timeLeft>0 or config.addReadyCD then
778 Aranarth-82994
                                        char[spellID] = time() + timeLeft
779 Aranarth-82994
                                        if not cd.group then
780 Aranarth-82994
                                                config.icons[spellID] = GetTradeSkillIcon(i)
781 Aranarth-82994
                                                config.names[spellID] = itemName
782 Aranarth-82994
                                        end
783 Aranarth-82994
                                end
784 Aranarth-82994
                        end
785 Aranarth-82994
                end
786 Aranarth-82994
        end
787 Aranarth-82994
        if self.learnCD then
788 Aranarth-82994
                if self.keepOpen then self.keepOpen = nil else CloseTradeSkill() end
789 Aranarth-82994
                self.learnCD = nil
790 Aranarth-82994
        end
791 Aranarth-82994
        if tipShown then Block_OnEnter(tipShown) end
792 Aranarth-82994
end
793 Aranarth-82994
 
794 Aranarth-82994
 
795 Aranarth-82994
function f:SetAlias(alias)
796 Aranarth-82994
        config.aliases[self.aliasID] = alias ~= "" and alias or nil
797 Aranarth-82994
        if tipShown then Block_OnEnter(tipShown)end
798 Aranarth-82994
end
799 Aranarth-82994
 
800 Aranarth-82994
function f:PLAYER_LOGOUT()
801 Aranarth-82994
        for i=1, GetNumSkillLines() do
802 Aranarth-82994
                local displayName, skill, skillName, value, _, _, valueMax = GetSkillLineInfo(i)
803 Aranarth-82994
                skillName = altNames[displayName] or displayName
804 Aranarth-82994
                skill = skills[skillName]
805 Aranarth-82994
                if skill then
806 Aranarth-82994
                        if bit_band(skill,PROFESSION) == 0 then break end
807 Aranarth-82994
                        char.curSkills[skillName], char.maxSkills[skillName] = value, valueMax
808 Aranarth-82994
                end
809 Aranarth-82994
        end
810 Aranarth-82994
end
811 Aranarth-82994
 
812 Aranarth-82994
------------------------------[[  options  ]]------------------------------
813 Aranarth-82994
 
814 Aranarth-82994
local function DisplayCD_OnUpdate(self, elapsed)
815 Aranarth-82994
        self.timer = self.timer - elapsed
816 Aranarth-82994
        if self.timer > 0 then return end
817 Aranarth-82994
        self.timer = 60
818 Aranarth-82994
        UpdateCDs()
819 Aranarth-82994
end
820 Aranarth-82994
 
821 Aranarth-82994
local function SetOption(self, t, v, c) t[v] = not t[v] end
822 Aranarth-82994
local function ColorPickerChange()      c[1], c[2], c[3] = ColorPickerFrame:GetColorRGB() end
823 Aranarth-82994
local function ColorPickerCancel(prev)  c[1], c[2], c[3] = unpack(prev) end
824 Aranarth-82994
local function OpenColorPicker(self, col)
825 Aranarth-82994
        c = config.colors[col]
826 Aranarth-82994
        ColorPickerFrame.func = ColorPickerChange
827 Aranarth-82994
        ColorPickerFrame.cancelFunc = ColorPickerCancel
828 Aranarth-82994
        ColorPickerFrame.previousValues = {unpack(c)}
829 Aranarth-82994
        ColorPickerFrame:SetColorRGB( c[1], c[2], c[3] )
830 Aranarth-82994
        ColorPickerFrame:Show()
831 Aranarth-82994
end
832 Aranarth-82994
 
833 Aranarth-82994
local function RemoveChar(self, char)
834 Aranarth-82994
        realm[char] = nil
835 Aranarth-82994
        print( "|cFFFFB366Ara|cffffff00BrokerTradeskills: "..format(L"|cff8080ff%s|r has been removed.",char) )
836 Aranarth-82994
end
837 Aranarth-82994
 
838 Aranarth-82994
function f:ADDON_LOADED(event, addon)
839 Aranarth-82994
        if addon ~= "Ara_Broker_Tradeskills" then return end
840 Aranarth-82994
 
841 Aranarth-82994
        AraTradeskillsDB = AraTradeskillsDB or {icons={},names={},aliases={},colors={ header={1,1,1}, activeName={1,.82,0}, infoName={.6,.5,0}, selected={.9,0.45,.1}, highlight={1,.8,0}, ownCD={1,.82,0}, foreignCD={.6,.5,0} }}
842 Aranarth-82994
        config = AraTradeskillsDB
843 Aranarth-82994
        config.colors.activeVal, config.colors.infoVal = nil -- get rid of old config values
844 Aranarth-82994
        if not config[realmName] then config[realmName] = {} end
845 Aranarth-82994
        realm = config[realmName]
846 Aranarth-82994
        if not realm[playerName] then realm[playerName] = {show={}} end
847 Aranarth-82994
        char = realm[playerName]
848 Aranarth-82994
        if not char.shortcuts then char.shortcuts = {} end -- r14
849 Aranarth-82994
        if not char.curSkills then char.curSkills, char.maxSkills = {}, {} end
850 Aranarth-82994
        if not char.links then char.links = {} end -- r25
851 Aranarth-82994
        CDs = new()
852 Aranarth-82994
        if config.displayCDs then
853 Aranarth-82994
                e.timer = 0
854 Aranarth-82994
                e:SetScript("OnUpdate", DisplayCD_OnUpdate)
855 Aranarth-82994
        end
856 Aranarth-82994
 
857 Aranarth-82994
        options = {
858 Aranarth-82994
                { text = format("|cFFFFB366Ara|r Broker Tradeskills (%s)", GetAddOnMetadata("Ara_Broker_Tradeskills", "Version")), isTitle = true },
859 Aranarth-82994
                { text = _G.TRADE_SKILLS, submenu = "isProfession", scope=char, var="hideProfessions", inv=true },
860 Aranarth-82994
                { text = L"Combat Skills", submenu = "isCombatSkill", scope=char, var="hideCombatSkills", inv=true },
861 Aranarth-82994
                { text = L"Include |cff20ff20Ready!|r CDs when scanning", scope=config, var="addReadyCD" },
862 Aranarth-82994
                { text = L"Show hints", scope=config, var="hideTips", inv=true },
863 Aranarth-82994
                { text = L"Show alt. skills", scope=config, var="hideAlts", inv=true },
864 Aranarth-82994
                { text = L"Show alt. primary skills only", scope=config, var="primaryOnly" },
865 Aranarth-82994
                { text = L"Remove an alt.", submenu="alts" },
866 Aranarth-82994
                { text = L"Display number of Ready CD", func=
867 Aranarth-82994
                        function()
868 Aranarth-82994
                                config.displayCDs = not config.displayCDs
869 Aranarth-82994
                                e.timer = 0
870 Aranarth-82994
                                e:SetScript("OnUpdate", config.displayCDs and DisplayCD_OnUpdate or nil)
871 Aranarth-82994
                                UpdateText()
872 Aranarth-82994
                        end, checked=function() return config.displayCDs end },
873 Aranarth-82994
                { text = L.Colors, submenu = {
874 Aranarth-82994
                        { text = L"Header", colorPick = "header" },
875 Aranarth-82994
                        { text = L"Interactive skill name", colorPick = "activeName" },
876 Aranarth-82994
                        { text = L"Last selected skill", colorPick = "selected" },
877 Aranarth-82994
                        { text = L"Informative skill name", colorPick = "infoName" },
878 Aranarth-82994
                        { text = L"Player CD", colorPick = "ownCD" },
879 Aranarth-82994
                        { text = L"Other player CD", colorPick = "foreignCD" },
880 Aranarth-82994
                        { text = L"Highlight", colorPick = "highlight" }, },
881 Aranarth-82994
                },
882 Aranarth-82994
        }
883 Aranarth-82994
        dropdown_init = function(self, level)
884 Aranarth-82994
                level = level or 1
885 Aranarth-82994
                local options = level>1 and UIDROPDOWNMENU_MENU_VALUE or options
886 Aranarth-82994
                if options == "alts" then
887 Aranarth-82994
                        for char in next, realm do
888 Aranarth-82994
                                if char ~= playerName then
889 Aranarth-82994
                                        local info = UIDropDownMenu_CreateInfo()
890 Aranarth-82994
                                        info.text, info.notCheckable = char, true
891 Aranarth-82994
                                        info.func, info.arg1 = RemoveChar, char
892 Aranarth-82994
                                        UIDropDownMenu_AddButton( info, level )
893 Aranarth-82994
                                end
894 Aranarth-82994
                        end
895 Aranarth-82994
                        return
896 Aranarth-82994
                end
897 Aranarth-82994
                local custom = type(options)~="table"
898 Aranarth-82994
                for i, v in ipairs(custom and f.skills or options) do
899 Aranarth-82994
                        if not custom or v[options] then
900 Aranarth-82994
                                local info = UIDropDownMenu_CreateInfo()
901 Aranarth-82994
                                info.text = custom and format("|cff%.2x%.2x%.2x%s|r", v.color[1]*255, v.color[2]*255, v.color[3]*255, v.displayName) or v.text
902 Aranarth-82994
                                info.isTitle, info.value, info.hasArrow = v.isTitle, v.submenu, v.submenu ~= nil
903 Aranarth-82994
                                if custom then
904 Aranarth-82994
                                        info.checked = char.show[v.skillName]
905 Aranarth-82994
                                        info.func, info.arg1, info.arg2 = SetOption, char.show, v.skillName
906 Aranarth-82994
                                elseif v.scope then
907 Aranarth-82994
                                        info.checked = v.inv and not v.scope[v.var] or not v.inv and v.scope[v.var]
908 Aranarth-82994
                                        info.func, info.arg1, info.arg2, info.tooltipText = SetOption, v.scope, v.var, v.inv
909 Aranarth-82994
                                elseif v.colorPick then
910 Aranarth-82994
                                        info.hasColorSwatch, info.notCheckable = true, true
911 Aranarth-82994
                                        info.r, info.g, info.b = unpack(config.colors[v.colorPick])
912 Aranarth-82994
                                        info.func, info.arg1 = OpenColorPicker, v.colorPick
913 Aranarth-82994
                                else
914 Aranarth-82994
                                        info.func, info.checked = v.func, v.checked
915 Aranarth-82994
                                end
916 Aranarth-82994
                                info.keepShownOnClick = info.func
917 Aranarth-82994
                                UIDropDownMenu_AddButton( info, level )
918 Aranarth-82994
                        end
919 Aranarth-82994
                end
920 Aranarth-82994
        end
921 Aranarth-82994
 
922 Aranarth-82994
        local popup = {
923 Aranarth-82994
                text = L"Set an alias for \"%s\".\nLeave blank to reset.",
924 Aranarth-82994
                OnAccept = function(self) AraSkills:SetAlias(self.wideEditBox:GetText()) end,
925 Aranarth-82994
                OnShow = function(self) self.wideEditBox:SetText(AraSkills.alias) self.wideEditBox:SetFocus() end,
926 Aranarth-82994
                EditBoxOnEnterPressed = function(self)
927 Aranarth-82994
                        local parent = self:GetParent()
928 Aranarth-82994
                        AraSkills:SetAlias(parent.wideEditBox:GetText())
929 Aranarth-82994
                        parent:Hide()
930 Aranarth-82994
                end,
931 Aranarth-82994
        }
932 Aranarth-82994
        for k, v in next, StaticPopupDialogs.SET_FRIENDNOTE do
933 Aranarth-82994
                if not popup[k] then popup[k] = v end
934 Aranarth-82994
        end
935 Aranarth-82994
        StaticPopupDialogs.SET_ALIAS = popup
936 Aranarth-82994
        tip = _G.GameTooltip
937 Aranarth-82994
 
938 Aranarth-82994
        self.skills = {}
939 Aranarth-82994
        self:SetFrameStrata"TOOLTIP"
940 Aranarth-82994
        self:SetClampedToScreen(true)
941 Aranarth-82994
        self:EnableMouse(true)
942 Aranarth-82994
        self:SetScript("OnEnter", Menu_OnEnter)
943 Aranarth-82994
        self:SetScript("OnLeave", Menu_OnLeave)
944 Aranarth-82994
        self:RegisterEvent"PLAYER_LOGOUT"
945 Aranarth-82994
 
946 Aranarth-82994
        g:SetFrameStrata"TOOLTIP"
947 Aranarth-82994
        g:EnableMouse(true)
948 Aranarth-82994
        g:SetScript("OnEnter", Alt_OnEnter)
949 Aranarth-82994
        g:SetScript("OnLeave", Alt_OnLeave)
950 Aranarth-82994
 
951 Aranarth-82994
        local backdrop = { bgFile="Interface\\Buttons\\WHITE8X8", edgeFile="Interface\\Tooltips\\UI-Tooltip-Border",
952 Aranarth-82994
                tile=true, tileSize=12, edgeSize=12, insets = { left=2, right=2, top=2, bottom=2 } }
953 Aranarth-82994
        self:SetBackdrop(backdrop)
954 Aranarth-82994
        self:SetBackdropColor(0, 0, 0, .75)
955 Aranarth-82994
        g:SetBackdrop(backdrop)
956 Aranarth-82994
        g:SetBackdropColor(0, 0, 0, .75)
957 4 Aranarth-82994
 
958 Aranarth-82994
        if IsLoggedIn() then UpdateText() else
959 Aranarth-82994
                f.PLAYER_ENTERING_WORLD = UpdateText
960 Aranarth-82994
                f:RegisterEvent"PLAYER_ENTERING_WORLD"
961 Aranarth-82994
        end
962 Aranarth-82994
        self:UnregisterEvent(event)
963 Aranarth-82994
        self.ADDON_LOADED = nil
964 3 Aranarth-82994
end
965 Aranarth-82994
 
966 Aranarth-82994
 
967 Aranarth-82994
e:RegisterEvent"TRADE_SKILL_SHOW"
968 Aranarth-82994
 
969 Aranarth-82994
e:SetScript("OnEvent", function()
970 Aranarth-82994
        LoadAddOn"Blizzard_TradeSkillUI"
971 Aranarth-82994
 
972 Aranarth-82994
        local b = TradeSkillSkillIcon
973 Aranarth-82994
        local TS_OnEnter = b:GetScript"OnEnter"
974 Aranarth-82994
        local TS_OnLeave = b:GetScript"OnLeave"
975 Aranarth-82994
        local TS_OnClick = b:GetScript"OnClick"
976 Aranarth-82994
 
977 Aranarth-82994
        local OrgSetItem = GameTooltip.SetTradeSkillItem
978 Aranarth-82994
        local function NewSetItem(...)
979 Aranarth-82994
                OrgSetItem(...)
980 Aranarth-82994
                GameTooltip:AddLine("\n"..L"|cffff8040Click|r to create a shortcut.", .2, 1, .2)
981 Aranarth-82994
                GameTooltip:Show()
982 Aranarth-82994
        end
983 Aranarth-82994
 
984 Aranarth-82994
        b:SetScript("OnEnter", function(self, ...)
985 Aranarth-82994
                GameTooltip.SetTradeSkillItem = NewSetItem
986 Aranarth-82994
                TS_OnEnter(self, ...)
987 Aranarth-82994
        end)
988 Aranarth-82994
        b:SetScript("OnLeave", function(...)
989 Aranarth-82994
                TS_OnLeave(...)
990 Aranarth-82994
                GameTooltip.SetTradeSkillItem = OrgSetItem
991 Aranarth-82994
        end)
992 Aranarth-82994
        b:SetScript("OnClick", function(self,button,...)
993 Aranarth-82994
                TS_OnClick(self,button,...)
994 Aranarth-82994
                if not IsModifierKeyDown() and button == "LeftButton" then
995 Aranarth-82994
                        local index = TradeSkillFrame.selectedSkill
996 Aranarth-82994
                        local spellID = tonumber(strmatch(GetTradeSkillRecipeLink(index), "enchant:(%d+)"))
997 Aranarth-82994
                        local skill = GetTradeSkillLine()
998 Aranarth-82994
                        char.shortcuts[spellID] = altNames[skill] or skill
999 Aranarth-82994
                        config.names[spellID] = GetTradeSkillInfo(index)
1000 Aranarth-82994
                        config.icons[spellID] = GetTradeSkillIcon(index)
1001 Aranarth-82994
                        print("|cFFFFB366Ara|cffffff00BrokerTradeskills: "..format(L"|cff8080ff%s|r|cffffff00 added to shortcuts.",config.names[spellID]))
1002 Aranarth-82994
                end
1003 Aranarth-82994
        end)
1004 Aranarth-82994
 
1005 Aranarth-82994
        local function OnEvent()
1006 Aranarth-82994
                if not IsTradeSkillLinked() then
1007 Aranarth-82994
                        local skill = GetTradeSkillLine()
1008 Aranarth-82994
                        char.links[ altNames[skill] or skill ] = GetTradeSkillListLink()
1009 Aranarth-82994
                end
1010 Aranarth-82994
        end
1011 Aranarth-82994
        e:SetScript("OnEvent", OnEvent)
1012 Aranarth-82994
        OnEvent()
1013 Aranarth-82994
end)
1014 Aranarth-82994
 
1015 Aranarth-82994
f:SetScript("OnEvent", function(self, event, ...) return self[event](self, event, ...) end)
1016 Aranarth-82994
f:RegisterEvent"ADDON_LOADED"