local addon, ns = ...
local cfg = ns.cfg
local unpack = unpack
--------------------------------------------------------------
if not cfg.show.tradeSkill then return end
local proffessions = {
['ALCHEMY'] = {"Alchemical Catalyst", "Secrets of Draenor Alchemy", "Northrend Alchemy Research"},
['BLACKSMITHING'] = {"Truesteel Ignot", "Secrets of Draenor Blacksmithing"},
['ENCHANTING'] = {"Temporal Crystal", "Secrets of Draenor Enchanting"},
['ENGINEERING'] = {"Gearsoring Parts", "Secrets of Draenor Engineering"},
['INSCRIPTION'] = {"War Paints", "Secrets of Draenor Inscription","Draenor Merchant Order"},
['JEWEL CRAFTING'] = {"Taladite Crystal", "Secrets of Draenor Jewelcrafting"},
['LEATHERWORKING'] = {"Burnished Leather", "Secrets of Draenor Leatherworking"},
['TAILORING'] = {"Hexweave Cloth", "Secrets of Draenor Tailoring"},
}
local prof1OnCooldown = false
local prof2OnCooldown = false
local tradeSkillFrame = CreateFrame("Frame",nil, cfg.SXUIframe)
tradeSkillFrame:SetPoint("LEFT", cfg.SXUIframe, "CENTER", 120,0)
tradeSkillFrame:SetSize(16, 16)
---------------------------------------------------------------------
local primaryTradeSkillFrame = CreateFrame("BUTTON",nil, tradeSkillFrame)
primaryTradeSkillFrame:SetSize(16, 16)
primaryTradeSkillFrame:SetPoint("LEFT")
primaryTradeSkillFrame:EnableMouse(true)
primaryTradeSkillFrame:RegisterForClicks("AnyUp")
local primaryTradeSkillIcon = primaryTradeSkillFrame:CreateTexture(nil,"OVERLAY",nil,7)
primaryTradeSkillIcon:SetSize(16, 16)
primaryTradeSkillIcon:SetPoint("LEFT")
primaryTradeSkillIcon:SetVertexColor(unpack(cfg.color.normal))
local primaryTradeSkillText = primaryTradeSkillFrame:CreateFontString(nil, "OVERLAY")
primaryTradeSkillText:SetFont(cfg.font, cfg.core.normalFontSize)
primaryTradeSkillText:SetPoint("RIGHT",primaryTradeSkillFrame,2,0 )
primaryTradeSkillText:SetTextColor(unpack(cfg.color.normal))
local primaryTradeSkillStatusbar = CreateFrame("StatusBar", nil, primaryTradeSkillFrame)
primaryTradeSkillStatusbar:SetStatusBarTexture(1,1,1)
primaryTradeSkillStatusbar:SetStatusBarColor(unpack(cfg.color.normal))
primaryTradeSkillStatusbar:SetPoint("TOPLEFT", primaryTradeSkillText, "BOTTOMLEFT",0,-2)
local primaryTradeSkillStatusbarBG = primaryTradeSkillStatusbar:CreateTexture(nil,"BACKGROUND",nil,7)
primaryTradeSkillStatusbarBG:SetPoint("TOPLEFT", primaryTradeSkillText, "BOTTOMLEFT",0,-2)
primaryTradeSkillStatusbarBG:SetTexture(unpack(cfg.color.inactive))
primaryTradeSkillFrame:SetScript("OnEnter", function()
if InCombatLockdown() then return end
GameTooltip:SetOwner(tradeSkillFrame, cfg.tooltipPos)
for i=1,GetNumTradeSkills() do
local cooldown = GetTradeSkillCooldown(i)
if cooldown then
local name = GetTradeSkillInfo(i)
GameTooltip:AddDoubleLine(name, SecondsToTime(cooldown), 1, 1, 0, 1, 1, 1)
end
end
primaryTradeSkillIcon:SetVertexColor(unpack(cfg.color.hover))
primaryTradeSkillStatusbar:SetStatusBarColor(unpack(cfg.color.hover))
GameTooltip:Show()
end)
primaryTradeSkillFrame:SetScript("OnLeave", function()
if prof1OnCooldown then
primaryTradeSkillIcon:SetVertexColor(unpack(cfg.color.inactive))
primaryTradeSkillText:SetTextColor(unpack(cfg.color.inactive))
else
primaryTradeSkillIcon:SetVertexColor(unpack(cfg.color.normal))
primaryTradeSkillText:SetTextColor(unpack(cfg.color.normal))
end
primaryTradeSkillStatusbar:SetStatusBarColor(unpack(cfg.color.normal))
if ( GameTooltip:IsShown() ) then GameTooltip:Hide() end
end)
primaryTradeSkillFrame:SetScript("OnClick", function(self, button, down)
if InCombatLockdown() then return end
if button == "LeftButton" then
local prof1, prof2 = GetProfessions()
if prof1 then
if (GetProfessionInfo(prof1) == ('Herbalism')) then
ToggleSpellBook(BOOKTYPE_PROFESSION)
elseif(GetProfessionInfo(prof1) == ('Skinning')) then
ToggleSpellBook(BOOKTYPE_PROFESSION)
elseif(GetProfessionInfo(prof1) == ('Mining')) then
CastSpellByName("Smelting")
else
CastSpellByName((GetProfessionInfo(prof1)))
end
end
elseif button == "RightButton" then
ToggleSpellBook(BOOKTYPE_PROFESSION)
end
end)
---------------------------------------------------------------------
local secondaryTradeSkillFrame = CreateFrame("BUTTON",nil, tradeSkillFrame)
secondaryTradeSkillFrame:SetPoint("RIGHT")
secondaryTradeSkillFrame:SetSize(16, 16)
secondaryTradeSkillFrame:EnableMouse(true)
secondaryTradeSkillFrame:RegisterForClicks("AnyUp")
local secondaryTradeSkillIcon = secondaryTradeSkillFrame:CreateTexture(nil,"OVERLAY",nil,7)
secondaryTradeSkillIcon:SetSize(16, 16)
secondaryTradeSkillIcon:SetPoint("LEFT")
secondaryTradeSkillIcon:SetVertexColor(unpack(cfg.color.normal))
local secondaryTradeSkillText = secondaryTradeSkillFrame:CreateFontString(nil, "OVERLAY")
secondaryTradeSkillText:SetFont(cfg.font, cfg.core.normalFontSize)
secondaryTradeSkillText:SetPoint("LEFT", secondaryTradeSkillIcon,"RIGHT",2,0)
secondaryTradeSkillText:SetTextColor(unpack(cfg.color.normal))
local secondaryTradeSkillStatusbar = CreateFrame("StatusBar", nil, secondaryTradeSkillFrame)
secondaryTradeSkillStatusbar:SetStatusBarTexture(1,1,1)
secondaryTradeSkillStatusbar:SetStatusBarColor(unpack(cfg.color.normal))
secondaryTradeSkillStatusbar:SetPoint("TOPLEFT", secondaryTradeSkillText, "BOTTOMLEFT",0,-2)
local secondaryTradeSkillStatusbarBG = secondaryTradeSkillStatusbar:CreateTexture(nil,"BACKGROUND",nil,7)
secondaryTradeSkillStatusbarBG:SetPoint("TOPLEFT", secondaryTradeSkillText, "BOTTOMLEFT",0,-2)
secondaryTradeSkillStatusbarBG:SetTexture(unpack(cfg.color.inactive))
secondaryTradeSkillFrame:SetScript("OnEnter", function()
if InCombatLockdown() then return end
GameTooltip:SetOwner(tradeSkillFrame, cfg.tooltipPos)
for i=1,GetNumTradeSkills() do
local cooldown = GetTradeSkillCooldown(i)
if cooldown then
local name = GetTradeSkillInfo(i)
GameTooltip:AddDoubleLine(name, SecondsToTime(cooldown), 1, 1, 0, 1, 1, 1)
end
end
secondaryTradeSkillIcon:SetVertexColor(unpack(cfg.color.hover))
secondaryTradeSkillStatusbar:SetStatusBarColor(unpack(cfg.color.hover))
GameTooltip:Show()
end)
secondaryTradeSkillFrame:SetScript("OnLeave", function()
if prof2OnCooldown then
secondaryTradeSkillIcon:SetVertexColor(unpack(cfg.color.inactive))
secondaryTradeSkillText:SetTextColor(unpack(cfg.color.inactive))
else
secondaryTradeSkillIcon:SetVertexColor(unpack(cfg.color.normal))
secondaryTradeSkillText:SetTextColor(unpack(cfg.color.normal))
end
secondaryTradeSkillStatusbar:SetStatusBarColor(unpack(cfg.color.normal))
if ( GameTooltip:IsShown() ) then GameTooltip:Hide() end
end)
secondaryTradeSkillFrame:SetScript("OnClick", function(self, button, down)
if InCombatLockdown() then return end
if button == "LeftButton" then
local prof1, prof2 = GetProfessions()
if prof2 then
if (GetProfessionInfo(prof2) == ('Herbalism')) then
ToggleSpellBook(BOOKTYPE_PROFESSION)
elseif(GetProfessionInfo(prof2) == ('Skinning')) then
ToggleSpellBook(BOOKTYPE_PROFESSION)
elseif(GetProfessionInfo(prof2) == ('Mining')) then
CastSpellByName("Smelting")
else
CastSpellByName((GetProfessionInfo(prof2)))
end
end
elseif button == "RightButton" then
ToggleSpellBook(BOOKTYPE_PROFESSION)
end
end)
---------------------------------------------------------------------
local eventframe = CreateFrame("Frame")
eventframe:RegisterEvent("PLAYER_ENTERING_WORLD")
eventframe:RegisterEvent("TRADE_SKILL_UPDATE")
eventframe:RegisterEvent("TRAINER_CLOSED")
eventframe:RegisterEvent("SPELLS_CHANGED")
eventframe:RegisterUnitEvent("UNIT_SPELLCAST_STOP", "player")
eventframe:SetScript("OnEvent", function(self,event, ...)
local prof1, prof2 = GetProfessions()
if prof1 then
local prof1Name, _, prof1Rank, prof1MaxRank = GetProfessionInfo(prof1)
prof1Name = string.upper(prof1Name)
primaryTradeSkillText:SetText(prof1Name)
primaryTradeSkillIcon:SetTexture(cfg.mediaFolder.."profession\\"..prof1Name)
if prof1Rank == prof1MaxRank then
primaryTradeSkillStatusbar:Hide()
else
primaryTradeSkillStatusbar:SetMinMaxValues(0, prof1MaxRank)
primaryTradeSkillStatusbar:SetValue(prof1Rank)
end
primaryTradeSkillFrame:SetSize(primaryTradeSkillText:GetStringWidth()+18, 16)
primaryTradeSkillStatusbar:SetSize(primaryTradeSkillText:GetStringWidth(),3)
primaryTradeSkillStatusbarBG:SetSize(primaryTradeSkillText:GetStringWidth(),3)
primaryTradeSkillFrame:Show()
primaryTradeSkillFrame:EnableMouse(true)
for i=1,GetNumTradeSkills() do
local cooldown = GetTradeSkillCooldown(i)
if cooldown then
local name = GetTradeSkillInfo(i)
for k, v in pairs(proffessions) do
for u = 1, #v do
if k == prof1Name then
if v[u] == name then
if not prof1OnCooldown then prof1OnCooldown = true end
primaryTradeSkillIcon:SetVertexColor(unpack(cfg.color.inactive))
primaryTradeSkillText:SetTextColor(unpack(cfg.color.inactive))
end
else
primaryTradeSkillIcon:SetVertexColor(unpack(cfg.color.normal))
primaryTradeSkillText:SetTextColor(unpack(cfg.color.normal))
end
end
end
end
end
else
primaryTradeSkillFrame:Hide()
primaryTradeSkillFrame:EnableMouse(false)
end
if prof2 then
local prof2Name, _, rank, maxRank = GetProfessionInfo(prof2)
prof2Name = string.upper(prof2Name)
secondaryTradeSkillText:SetText(prof2Name)
secondaryTradeSkillIcon:SetTexture(cfg.mediaFolder.."profession\\"..prof2Name)
if rank == maxRank then
secondaryTradeSkillStatusbar:Hide()
end
secondaryTradeSkillStatusbar:SetMinMaxValues(0, maxRank)
secondaryTradeSkillStatusbar:SetValue(rank)
secondaryTradeSkillFrame:SetSize(secondaryTradeSkillText:GetStringWidth()+18, 16)
secondaryTradeSkillStatusbar:SetSize(secondaryTradeSkillText:GetStringWidth(),3)
secondaryTradeSkillStatusbarBG:SetSize(secondaryTradeSkillText:GetStringWidth(),3)
secondaryTradeSkillFrame:Show()
secondaryTradeSkillFrame:EnableMouse(true)
for i=1,GetNumTradeSkills() do
local cooldown = GetTradeSkillCooldown(i)
if cooldown then
local name = GetTradeSkillInfo(i)
for k, v in pairs(proffessions) do
for u = 1, #v do
if k == prof2Name then
if v[u] == name then
if not prof2OnCooldown then prof2OnCooldown = true end
secondaryTradeSkillIcon:SetVertexColor(unpack(cfg.color.inactive))
secondaryTradeSkillText:SetTextColor(unpack(cfg.color.inactive))
else
secondaryTradeSkillIcon:SetVertexColor(unpack(cfg.color.normal))
secondaryTradeSkillText:SetTextColor(unpack(cfg.color.normal))
end
end
end
end
end
end
end
tradeSkillFrame:SetSize((primaryTradeSkillFrame:GetWidth())+(secondaryTradeSkillFrame:GetWidth()+4), 16)
end)