local ADDON = ... -- Localization is good, mmkay local L = { HERBALISM = "Herbalism", LEFT_CLICK = "Left-click to cast %s.", MIDDLE_CLICK = "Middle-click for options.", RIGHT_CLICK = "Right-click to cast %s.", VISIT_TRAINER = "Visit a trainer to learn a profession!", VISIT_TRAINER_S = "Visit a trainer to learn %s!", } if GetLocale() == "deDE" then HERBALISM = "Kräuterkunde" LEFT_CLICK = "Linksklick, um %s zu wirken." MIDDLE_CLICK = "Mittelklick, um die Einstellungen anzuzeigen." RIGHT_CLICK = "Rechtsklick, um %s zu wirken." VISIT_TRAINER = "Besucht einen Lehrer, einen Beruf zu lernen!" VISIT_TRAINER_S = "Besucht einen Lehrer, %s zu lernen!" elseif GetLocale():match("^es") then HERBALISM = "Herboristería" LEFT_CLICK = "Clic izquierda para lanzar %s." MIDDLE_CLICK = "Clic medio para opciones." RIGHT_CLICK = "Clic derecho para lanzar %s." VISIT_TRAINER = "Visita un instructor para aprendar un profesión!" VISIT_TRAINER_S = "Visita un instructor para aprendar %s!" elseif GetLocale() == "frFR" then HERBALISM = "Herboristerie" elseif GetLocale() == "ptBR" then HERBALISM = "Herborismo" elseif GetLocale() == "ruRU" then HERBALISM = "Травничество" end -- itIT, zhCN, zhTW out of luck, blame Wowhead! -- Some constants to make things easier: local PRIMARY, SECONDARY, ARCHAEOLOGY, FISHING, COOKING, FIRSTAID = 1, 2, 3, 4, 5, 6 -- Table lookups are simpler and more easily extensible than if-else chains: local LEFT_CLICK_ACTIONS = { -- not listed = same as profession name [GetSpellInfo(2575)] = GetSpellInfo(2656), -- Mining -> Smelting [L.HERBALISM] = false, -- Herbalism (no matching spell, wow, so annoy) [GetSpellInfo(8613)] = false, -- Skinning } local RIGHT_CLICK_ACTIONS = { -- not listed = do nothing [GetSpellInfo(78670)] = GetSpellInfo(80451), -- Archaeology -> Survey [GetSpellInfo(2550)] = GetSpellInfo(818), -- Cooking -> Cooking Fire [GetSpellInfo(7411)] = GetSpellInfo(13262), -- Enchanting -> Disenchant [GetSpellInfo(45357)] = GetSpellInfo(51005), -- Inscription -> Milling [GetSpellInfo(25229)] = GetSpellInfo(31252), -- Jewelcrafting -> Prospecting } -- Secure button to handle events and enable clicking to open professions: local ProfessionBroker = CreateFrame("Button", "ProfessionBroker", UIParent, "SecureActionButtonTemplate") ProfessionBroker:RegisterForClicks("LeftButtonUp", "RightButtonUp") ProfessionBroker:SetAttribute("type1", "macro") ProfessionBroker:SetAttribute("type2", "macro") --local bg = ProfessionBroker:CreateTexture(nil, "OVERLAY") --bg:SetAllPoints(true) --bg:SetTexture(0, 1, 0, 0.25) ProfessionBroker.data = { [PRIMARY] = {}, [SECONDARY] = {}, [ARCHAEOLOGY] = {}, [FISHING] = {}, [COOKING] = {}, [FIRSTAID] = {} } -- Method to create a DataBroker object for a profession: do -- The do/end block keeps this function local to this scope, -- since it's only used in this method and doesn't need to -- be accessible anywhere else. local function GetTooltipPoint(this) local _, y = GetCursorPosition() if y * 2 > UIParent:GetHeight() then return "TOP", this, "BOTTOM", 0, -5 else return "BOTTOM", this, "TOP", 0, 5 end end function ProfessionBroker:CreateDataObject(which) --print("ProfessionBroker", "CreateDataObject", which) local profession = self.data[which] return LibStub("LibDataBroker-1.1"):NewDataObject(ADDON..which, { type = "data source", icon = "Interface\\Icons\\INV_Misc_QuestionMark", label = ADDON, text = UNKNOWN, OnEnter = function(this) local inCombat = not InCombatLockdown() --print("ProfessionBroker", "OnEnter", clickable, profession.name) if not inCombat and profession.id and (profession.action1 or profession.action2) then self:ClearAllPoints() self:SetAllPoints(this) self:SetFrameLevel(this:GetFrameLevel() + 1) self:SetAttribute("macrotext1", profession.action1) self:SetAttribute("macrotext2", profession.action2) self:SetScript("OnLeave", profession.plugin.OnLeave) self:Show() end GameTooltip:SetOwner(this, "ANCHOR_NONE") GameTooltip:SetPoint(GetTooltipPoint(this)) GameTooltip:AddLine(profession.name, HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b) if profession.tooltipText then GameTooltip:AddLine(profession.tooltipText, GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b) else if inCombat then GameTooltip:AddLine(SPELL_FAILED_AFFECTING_COMBAT, RED_FONT_COLOR.r, RED_FONT_COLOR.g, RED_FONT_COLOR.b) else if action1 then GameTooltip:AddLine(format(L.LEFT_CLICK, action1), NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b) end if action2 then GameTooltip:AddLine(format(L.RIGHT_CLICK, action2), NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b) end end end GameTooltip:AddLine(L.MIDDLE_CLICK, NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b) GameTooltip:Show() end, OnLeave = function(this) if this:IsMouseOver() then return end --print("ProfessionBroker", "OnLeave") self:ClearAllPoints() self:Hide() GameTooltip:Hide() end, OnClick = function(this, button) --print("ProfessionBroker", "OnClick", button) -- this should never happen end, }) end end function ProfessionBroker:UpdateProfession(which, id) --print("ProfessionBroker", "UpdateProfession", which, id) local profession = self.data[which] profession.id = id local plugin = profession.plugin if id then -- The player knows this profession! local name, icon, skillLevel, maxSkillLevel = GetProfessionInfo(id) --print(name, skillLevel, maxSkillLevel) -- Create the plugin if it didn't already exist if not plugin then plugin = self:CreateDataObject(which) profession.plugin = plugin end -- Update the plugin plugin.icon = icon plugin.label = name plugin.text = format("%d/%d", skillLevel, maxSkillLevel) -- Update the profession data profession.name = name profession.icon = icon profession.tooltipText = nil local action1 = LEFT_CLICK_ACTIONS[name] profession.action1 = action1 ~= false and format("/cast %s", action1 or name) or nil local action2 = RIGHT_CLICK_ACTIONS[name] profession.action2 = action2 and format("/cast %s", action2) or nil else -- The player does not know this profession. -- Clear the profession data profession.tooltipText = profession.name and format(L.VISIT_TRAINER_S, profession.name) or L.VISIT_TRAINER profession.name = nil profession.icon = nil profession.action1 = nil profession.action2 = nil -- Clear the plugin if there was one, leave the name if there was one to remind what was unlearned if plugin then plugin.icon = "Interface\\Icons\\INV_Misc_QuestionMark" plugin.text = UNKNOWN end end end ProfessionBroker:RegisterEvent("PLAYER_REGEN_DISABLED") -- need to hide the click button in combat ProfessionBroker:RegisterEvent("SKILL_LINES_CHANGED") -- update ProfessionBroker:SetScript("OnEvent", function(self, event) --print("ProfessionBroker", event) if event == "PLAYER_REGEN_DISABLED" then return self:Hide() end local primary, secondary, archaeology, fishing, cooking, firstAid = GetProfessions() self:UpdateProfession(PRIMARY, primary) self:UpdateProfession(SECONDARY, secondary) self:UpdateProfession(ARCHAEOLOGY, archaeology) self:UpdateProfession(FISHING, fishing) self:UpdateProfession(COOKING, cooking) self:UpdateProfession(FIRSTAID, firstAid) end)