local ADDON = ...
local ActiveSpec = GetSpecialization()
local ACTSPEC = {}
local fontName, fontHeight, fontFlags = GameFontNormal:GetFont()
local btn = {}
local num_lines = 9
local btn_o = 5
local btn_h = fontHeight + 4
local line_v = - btn_h
local line_o = btn_o + 4
local frame_w = 190
local frame_h = abs(num_lines * line_v) + 10
local btn_w = frame_w - btn_o - 2
local line_o2 = frame_w/2
local string_format = string.format
local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
local dataobj = ldb:NewDataObject(ADDON, {
type = "data source",
icon = "Interface\\Icons\\INV_Misc_QuestionMark.blp",
text = "None"
})
local Menu = CreateFrame('Frame', nil, UIParent)
Menu:SetClampedToScreen(true)
Menu:SetSize(frame_w,frame_h)
Menu:Hide()
Menu:SetScript('OnLeave', Menu.Hide)
Menu:SetBackdrop({
bgFile = "Interface/DialogFrame/UI-DialogBox-Background",
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
tile = true, tileSize = 32, edgeSize = 16,
insets = { left = 5, right = 5, top = 5, bottom = 5 }
})
local talent_desc = Menu:CreateFontString("talent_desc")
talent_desc:SetPoint("TOPLEFT", Menu,"TOPLEFT",line_o, line_v)
talent_desc:SetFont(fontName, fontHeight)
talent_desc:SetTextColor(1,0.8,0,1)
talent_desc:SetText("Spec config: ")
local talent_value = Menu:CreateFontString("talent_value")
talent_value:SetPoint("TOPLEFT", Menu,"TOPLEFT",line_o2, line_v)
talent_value:SetFont(fontName, fontHeight)
talent_value:SetTextColor(0,1,0,1)
local lclick_desc = Menu:CreateFontString("lclick_desc")
lclick_desc:SetPoint("TOPLEFT", Menu,"TOPLEFT",line_o, 7*line_v)
lclick_desc:SetFont(fontName, fontHeight)
lclick_desc:SetTextColor(1,0.8,0,1)
lclick_desc:SetText("Left Click: ")
local lclick_value = Menu:CreateFontString("lclick_value")
lclick_value:SetPoint("TOPLEFT", Menu,"TOPLEFT",line_o2, 7*line_v)
lclick_value:SetFont(fontName, fontHeight)
lclick_value:SetTextColor(0,1,0,1)
lclick_value:SetText("Change Spec")
local rclick_desc = Menu:CreateFontString("rclick_desc")
rclick_desc:SetPoint("TOPLEFT", Menu,"TOPLEFT",line_o, 8*line_v)
rclick_desc:SetFont(fontName, fontHeight)
rclick_desc:SetTextColor(1,0.8,0,1)
rclick_desc:SetText("Right Click: ")
local rclick_value = Menu:CreateFontString("rclick_value")
rclick_value:SetPoint("TOPLEFT", Menu,"TOPLEFT",line_o2, 8*line_v)
rclick_value:SetFont(fontName, fontHeight)
rclick_value:SetTextColor(0,1,0,1)
rclick_value:SetText("Open Talents")
local function BuildActiveSpec()
local ptalenttree = {}
local ActiveSpec = GetSpecialization()
if ActiveSpec then
local id, name, description, icon, background, role = GetSpecializationInfo(ActiveSpec)
ACTSPEC = { id = id, name = name, description = description, icon = icon , background = background, role = role }
end
for i=1, GetMaxTalentTier() do
for j=1, 3 do
if select(4, GetTalentInfo(i,j,1)) == true then
ptalenttree[i] = j
end
end
end
ACTSPEC["tree"] = table.concat(ptalenttree,".")
end
local function UpdateLDB()
local currentSpec = GetSpecialization()
if currentSpec ~= nil then
local id, name, description, icon, background, role = GetSpecializationInfo(currentSpec)
dataobj.text = name
dataobj.icon = icon
else
dataobj.icon = "Interface\\Icons\\INV_Misc_QuestionMark.blp"
dataobj.text = "None"
end
end
local function BuildMenu()
for index=1,GetNumSpecializations() do
local id, name, description, icon, background, role = GetSpecializationInfo(index)
btn[index]=CreateFrame("Button", nil, Menu)
btn[index]:SetPoint("TOP", btn_o, -20 + (index * line_v))
btn[index]:SetWidth(btn_w)
btn[index]:SetHeight(btn_h)
btn[index]:SetNormalFontObject("GameFontNormal")
btn[index]:SetHighlightTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
local text = btn[index]:CreateFontString(ADDON .. "btn_font", nil, "GameFontNormal")
text:SetAllPoints(true)
text:SetJustifyH("LEFT")
text:SetJustifyV("MIDDLE")
text:SetTextColor(1,1,1,1)
btn[index]:SetFontString(text);
btn[index]:SetText(string.format("|T%s:0|t %s",icon,name))
btn[index]:SetScript("OnClick",
function()
Menu:Hide()
SetSpecialization(index)
end)
end
end
local frame = CreateFrame("Frame")
frame:RegisterEvent('ACTIVE_TALENT_GROUP_CHANGED')
frame:RegisterEvent('PLAYER_SPECIALIZATION_CHANGED')
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:SetScript("OnEvent", function(self, event, ...)
BuildActiveSpec()
UpdateLDB()
if event == "PLAYER_ENTERING_WORLD" then
BuildMenu()
end
end
)
function dataobj.OnClick(self, button)
if InCombatLockdown() then
return
end
if button == "RightButton" then
ToggleTalentFrame()
end
if button == "LeftButton" then
if(Menu:IsShown()) then
Menu:Hide()
else
talent_value:SetText(ACTSPEC["tree"])
-- position code taken from Broker_Equipment by p3lim
Menu:ClearAllPoints()
Menu:SetPoint('TOP', self, 'BOTTOM') -- temporary anchor
local sideAnchor = ''
if(Menu:GetRight() > GetScreenWidth()) then
sideAnchor = 'RIGHT'
elseif(Menu:GetLeft() <= 0) then
sideAnchor = 'LEFT'
end
Menu:ClearAllPoints()
if(Menu:GetBottom() <= 0) then
Menu:SetPoint('BOTTOM' .. sideAnchor, self, 'TOP' .. sideAnchor)
else
Menu:SetPoint('TOP' .. sideAnchor, self, 'BOTTOM' .. sideAnchor)
end
Menu:Show()
end
end
end