Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ADDON, private = ...
- local f = CreateFrame("Frame", ADDON, InterfaceOptionsFramePanelContainer)
- local db = { -- default values
- [2825] = "RAID", -- Bloodlust
- [32182] = "RAID", -- Heroism
- [80353] = "RAID", -- Time Warp
- [13159] = "RAID", -- Aspect of Fail
- [41450] = "RAID", -- Blessing of Piss me off
- [73325] = "RAID", -- Leap of Fail
- [34477] = "RAID", -- MD
- [20736] = "RAID", -- Distracting Shot
- [62124] = "RAID", -- Reckoning * paladin
- [56222] = "RAID", -- Dark Command
- [49576] = "RAID", -- Death Grip
- [2649] = "RAID", -- Generic hunter growl
- [39270] = "RAID", -- main target growl
- [103128] = "RAID", -- suffering
- }
- local L = {
- ANNOUNCE_MESSAGE = "%1$s used %2$s!",
- SOMEONES_PET = "%s's pet",
- ADD_SPELL = "Add Spell",
- ADD_SPELL_DESC = "Use this dialog to add a new spell to be announced.",
- ADD_SPELL_HELP = "Enter the numeric ID of the spell you want to add. If you don't know the ID, look up the spell on Wowhead.com and copy the number out of the spell page URL.",
- ADD_SPELL_INVALID = "That is not a valid spell ID!",
- DELETE_SPELL = "Delete Spell",
- DELETE_SPELL_DESC = "Permanently remove this spell from this list. If you only want to disable it temporarily, change the channel to NONE instead.",
- }
- local ChannelNames = {
- NONE = NONE,
- SELF = PLAYER,
- SAY = CHAT_MSG_SAY,
- PARTY = CHAT_MSG_PARTY,
- RAID = CHAT_MSG_RAID,
- }
- local orderedChannels = { "NONE", "SELF", "SAY", "PARTY", "RAID" }
- local unitOwner = {}
- for i = 1, MAX_PARTY_MEMBERS do
- local unit = "party"..i
- unitOwner[unit], unitOwner["partypet"..i] = unit, unit
- end
- for i = 1, MAX_RAID_MEMBERS do
- local unit = "raid"..i
- unitOwner[unit], unitOwner["raidpet"..i] = unit, unit
- end
- -------------------------------------------------------------------------
- -- Event handling
- f:RegisterEvent("PLAYER_LOGIN")
- f:SetScript("OnEvent", function(self, event)
- NoTrollDB = NoTrollDB or db
- db = NoTrollDB
- for id in pairs(db) do
- if not GetSpellInfo(id) then
- print("Invalid spell in db:", id)
- end
- end
- self:UnregisterEvent("PLAYER_LOGIN")
- self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
- self:SetScript("OnEvent", function(self, event, unit, _, _, _, spellID)
- local channel = db[spellID]
- if not channel or channel == "NONE" then return end
- local caster = unitOwner[unit]
- if not caster or UnitIsUnit(caster, "player") then return end
- self:Announce(channel, spellID, caster)
- end)
- end)
- -------------------------------------------------------------------------
- -- Announce logic
- local last = {}
- function f:Announce(channel, spellID, caster, target)
- local now = GetTime()
- if last[caster] and (now - last[caster]) < 1 then return end
- last[caster] = now
- --[[ If you're still seeing duplicates, remove the previous block and uncomment this block:
- local guid, now = UnitGUID(caster), GetTime()
- if last[guid] and (now - last[guid]) < 1 then return end
- last[guid] = now
- ]]
- local spellLink = GetSpellLink(spellID)
- local playerName = GetUnitName(caster, true)
- if channel == "SELF" then
- -- Clickable player links in self messages
- local playerLink = "|Hplayer:"..playerName.."|h["..playerName.."]|h"
- if isPet then
- playerLink = format(L.SOMEONES_PET, playerLink)
- end
- print("|cffffff9a[NoTroll]|r", format(L.ANNOUNCE_MESSAGE, playerLink, spellLink))
- else
- -- Can't send player links to channels
- if isPet then
- playerName = format(L.SOMEONES_PET, playerName)
- end
- SendChatMessage(format(L.ANNOUNCE_MESSAGE, playerName, spellLink), channel)
- end
- end
- -------------------------------------------------------------------------
- -- Make player names in channel messages from the addon
- -- clickable in your local chat frame.
- local ANNOUNCE_PATTERN = L.ANNOUNCE_MESSAGE:gsub("%%1$s", "(.+)"):gsub("%%2$s", ".+")
- function f.AddLocalMessageLinks(frame, event, message, ...)
- local playerName = strmatch(message, ANNOUNCE_PATTERN)
- if playerName then
- local playerLink = "|Hplayer:"..playerName.."|h["..playerName.."]|h"
- message = gsub(message, playerName, playerLink)
- return false, message, ...
- end
- end
- ChatFrame_AddMessageEventFilter("CHAT_MSG_PARTY", f.AddLocalMessageLinks)
- ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID", f.AddLocalMessageLinks)
- ChatFrame_AddMessageEventFilter("CHAT_MSG_SAY", f.AddLocalMessageLinks)
- -------------------------------------------------------------------------
- -- Options panel
- f:Hide()
- f:SetScript("OnShow", function(self)
- local RefreshOptions
- local title = self:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
- title:SetPoint("TOPLEFT", 16, -16)
- title:SetPoint("TOPRIGHT", -32, -16)
- title:SetJustifyH("LEFT")
- title:SetText(self.name)
- self.Title = Title
- local notes = self:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
- notes:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -8)
- notes:SetPoint("TOPRIGHT", title, "BOTTOMRIGHT", 0, -8)
- notes:SetHeight(32)
- notes:SetJustifyH("LEFT")
- notes:SetJustifyV("TOP")
- notes:SetText(GetAddOnMetadata(ADDON, "Notes"))
- self.Notes = Notes
- local scrollFrame = CreateFrame("ScrollFrame", "$parentScrollFrame", self, "UIPanelScrollFrameTemplate")
- scrollFrame:SetPoint("TOPLEFT", notes, "BOTTOMLEFT", 0, -16)
- scrollFrame:SetPoint("BOTTOMRIGHT", -38, 16)
- self.ScrollFrame = scrollFrame
- scrollFrame.ScrollBar:EnableMouseWheel(true)
- scrollFrame.ScrollBar:SetScript("OnMouseWheel", function(self, delta)
- ScrollFrameTemplate_OnMouseWheel(scrollFrame, delta)
- end)
- local barBG = scrollFrame:CreateTexture(nil, "BACKGROUND", nil, -6)
- barBG:SetPoint("TOP")
- barBG:SetPoint("RIGHT", 25, 0)
- barBG:SetPoint("BOTTOM")
- barBG:SetWidth(26)
- barBG:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-ScrollBar")
- barBG:SetTexCoord(0, 0.45, 0.1640625, 1)
- barBG:SetAlpha(0.5)
- scrollFrame.ScrollBar.bg = barBG
- local scrollChild = CreateFrame("Frame", nil, scrollFrame)
- scrollChild:SetSize(scrollFrame:GetWidth(), 100)
- scrollFrame.ScrollChild = scrollChild
- scrollFrame:SetScrollChild(scrollChild)
- scrollFrame:SetScript("OnSizeChanged", function(self)
- scrollChild:SetWidth(self:GetWidth())
- end)
- --------------------------------------------------------------------
- local dialog = CreateFrame("Frame", nil, self)
- dialog:SetPoint("TOPLEFT", notes, "BOTTOMLEFT", 0, -16)
- dialog:SetPoint("BOTTOMRIGHT", -16, 16)
- dialog:SetBackdrop({ edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 16 })
- dialog:SetBackdropBorderColor(1, 0.82, 0, 0.8)
- self.Dialog = dialog
- dialog.bg = dialog:CreateTexture(nil, "BACKGROUND")
- dialog.bg:SetPoint("BOTTOMLEFT", 3, 3)
- dialog.bg:SetPoint("TOPRIGHT", -3, -3)
- dialog.bg:SetTexture("Interface\\FrameGeneral\\UI-Background-Rock", true, true)
- dialog.bg:SetHorizTile(true)
- dialog.bg:SetVertTile(true)
- dialog.bg:SetVertexColor(0.4, 0.4, 0.4, 0.8)
- dialog:Hide()
- dialog:SetScript("OnShow", function(self)
- self:GetParent().ScrollFrame:Hide()
- self.EditBox:SetText("")
- self.Text:SetText("")
- self.EditBox:SetFocus()
- end)
- dialog:SetScript("OnHide", function(self)
- self:GetParent().ScrollFrame:Show()
- self.EditBox:SetText("")
- self.Text:SetText("")
- RefreshOptions()
- end)
- local dialogTitle = dialog:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
- dialogTitle:SetPoint("TOPLEFT", 16, -16)
- dialogTitle:SetText(L.ADD_SPELL)
- dialog.Title = dialogTitle
- local dialogNotes = dialog:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
- dialogNotes:SetPoint("TOPLEFT", dialogTitle, "BOTTOMLEFT", 0, -8)
- dialogNotes:SetPoint("RIGHT", -32, 0)
- dialogNotes:SetHeight(16)
- dialogNotes:SetJustifyH("LEFT")
- dialogNotes:SetJustifyV("TOP")
- dialogNotes:SetText(L.ADD_SPELL_DESC)
- local dialogBox = CreateFrame("EditBox", "$parentEditBox", dialog, "InputBoxTemplate")
- dialogBox:SetPoint("TOPLEFT", dialogNotes, "BOTTOMLEFT", 6, -12)
- dialogBox:SetSize(160, 24)
- dialogBox:SetAltArrowKeyMode(false)
- dialogBox:SetAutoFocus(false)
- dialogBox:SetMaxLetters(6)
- dialogBox:SetNumeric(true)
- dialog.EditBox = dialogBox
- dialogBox:SetScript("OnTextChanged", function(self, userInput)
- if not userInput then return end
- local spell = self:GetNumber()
- if spell == 0 then
- dialog.Text:SetText("")
- dialog.Button:SetEnabled(false)
- return
- end
- local name, _, icon = GetSpellInfo(spell)
- if name and icon then
- dialog.Text:SetFormattedText("|T%s:0|t %s", icon, name)
- dialog.Button:SetEnabled(true)
- else
- dialog.Text:SetText(RED_FONT_COLOR_CODE .. L.ADD_SPELL_INVALID .. "|r")
- dialog.Button:Disable()
- end
- end)
- dialogBox:SetScript("OnEnterPressed", function(self)
- if not dialog.Button:IsEnabled() then return end
- local id = self:GetNumber()
- if id and id > 0 and GetSpellInfo(id) then
- db[id] = "RAID"
- dialog:Hide()
- end
- end)
- local dialogButton = CreateFrame("Button", "$parentAddButton", dialog, "UIPanelButtonTemplate")
- dialogButton:SetPoint("LEFT", dialogBox, "RIGHT", 12, 0)
- dialogButton:SetWidth(80)
- dialogButton:SetText(OKAY)
- dialogButton:SetScript("OnClick", function()
- dialogBox:GetScript("OnEnterPressed")(dialogBox)
- end)
- dialog.Button = dialogButton
- local dialogText = dialog:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
- dialogText:SetPoint("LEFT", dialogButton, "RIGHT", 12, 0)
- dialogText:SetPoint("RIGHT", dialog, -16, 0)
- dialogText:SetJustifyH("LEFT")
- dialogText:SetJustifyV("TOP")
- dialogText:SetText("")
- dialog.Text = dialogText
- local dialogHelp = dialog:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
- dialogHelp:SetPoint("TOPLEFT", dialogBox, "BOTTOMLEFT", -6, -16)
- dialogHelp:SetPoint("RIGHT", dialog, -16, 0)
- dialogHelp:SetHeight(32)
- dialogHelp:SetJustifyH("LEFT")
- dialogHelp:SetJustifyV("TOP")
- dialogHelp:SetNonSpaceWrap(true)
- dialogHelp:SetText(L.ADD_SPELL_HELP)
- dialog.HelpText = dialogHelp
- --------------------------------------------------------------------
- local add = CreateFrame("Button", "$parentPanelButton", self, "UIPanelButtonTemplate")
- add:SetPoint("TOPRIGHT", title, "BOTTOMRIGHT", 0, -8)
- add:SetSize(160, 32)
- add:SetText("|TInterface\\LFGFRAME\\LFGROLE_BW:0:0:0:0:64:16:48:64:0:16:255:255:153|t " .. L.ADD_SPELL)
- self.AddButton = add
- notes:SetPoint("TOPRIGHT", add, "TOPLEFT", -24, 0)
- add:SetScript("OnClick", function(self)
- if dialog:IsShown() then
- dialog:Hide()
- self:SetText("|TInterface\\LFGFRAME\\LFGROLE_BW:0:0:0:0:64:16:48:64:0:16:255:255:153|t " .. L.ADD_SPELL)
- else
- dialog:Show()
- self:SetText(CANCEL)
- end
- end)
- --------------------------------------------------------------------
- local function Row_OnEnter(self)
- self.name:SetTextColor(1, 1, 1)
- self.highlight:Show()
- GameTooltip:SetOwner(self, "ANCHOR_NONE")
- GameTooltip:SetPoint("TOPRIGHT", self, "TOPLEFT")
- GameTooltip:SetSpellByID(self.id)
- GameTooltip:Show()
- end
- local function Row_OnLeave(self)
- self.name:SetTextColor(1, 0.82, 0)
- self.highlight:Hide()
- GameTooltip:Hide()
- end
- local function Row_OnHide(self)
- self.id = 0
- self.icon:SetTexture(nil)
- self.name:SetText("")
- self.channel.valueText:SetText("")
- end
- -- Delete button functions:
- local function Delete_OnClick(self)
- if GameTooltip:IsOwned(self) then
- GameTooltip:Hide()
- end
- local id = self:GetParent().id
- db[id] = nil
- RefreshOptions()
- end
- local function Delete_OnEnter(self)
- GameTooltip:SetOwner(self, "ANCHOR_LEFT")
- GameTooltip:SetText(L.DELETE_SPELL)
- GameTooltip:AddLine(L.DELETE_SPELL_DESC, 1, 1, 1, true)
- GameTooltip:Show()
- end
- -- Filter dropdown functions:
- local CURRENT_SPELL, CURRENT_DROPDOWN
- local function Dropdown_ClickFunc(info)
- db[CURRENT_SPELL] = info.value
- CURRENT_DROPDOWN:SetValue(info.value, ChannelNames[info.value])
- end
- local function Dropdown_Initialize(self, level) -- self is the dropdown menu
- if not level then return end
- CURRENT_DROPDOWN = self:GetParent()
- CURRENT_SPELL = CURRENT_DROPDOWN:GetParent().id
- local selected = db[CURRENT_SPELL]
- local info = UIDropDownMenu_CreateInfo()
- for i = 1, #orderedChannels do
- local k = orderedChannels[i]
- info.text = ChannelNames[k]
- info.value = k
- info.checked = k == selected
- info.func = Dropdown_ClickFunc
- UIDropDownMenu_AddButton(info, level)
- end
- end
- local function Dropdown_OnEnter(self)
- Row_OnEnter(self:GetParent())
- end
- local function Dropdown_OnLeave(self)
- Row_OnLeave(self:GetParent())
- end
- -- Rows:
- local rows = setmetatable({}, { __index = function(t, i)
- local row = CreateFrame("Frame", nil, scrollChild)
- row:SetHeight(40)
- row:SetPoint("LEFT")
- row:SetPoint("RIGHT")
- if i > 1 then
- row:SetPoint("TOP", t[i-1], "BOTTOM", 0, -4)
- else
- row:SetPoint("TOP")
- end
- row:EnableMouse(true)
- row:SetScript("OnEnter", Row_OnEnter)
- row:SetScript("OnLeave", Row_OnLeave)
- row:EnableMouseWheel(true)
- row:SetScript("OnMouseWheel", function(self, delta)
- ScrollFrameTemplate_OnMouseWheel(scrollFrame, delta)
- end)
- local highlight = row:CreateTexture(nil, "BACKGROUND")
- highlight:SetAllPoints(true)
- highlight:SetBlendMode("ADD")
- highlight:SetTexture([[Interface\QuestFrame\UI-QuestLogTitleHighlight]])
- highlight:SetVertexColor(0.2, 0.4, 0.8)
- highlight:Hide()
- row.highlight = highlight
- local delete = CreateFrame("Button", "$parentDelete"..i, row, "UIPanelCloseButton")
- delete:SetPoint("LEFT", -2, -1)
- delete:SetSize(32, 32)
- delete:SetScript("OnClick", Delete_OnClick)
- delete:SetScript("OnEnter", Delete_OnEnter)
- delete:SetScript("OnLeave", GameTooltip_Hide)
- row.delete = delete
- local icon = row:CreateTexture(nil, "ARTWORK")
- icon:SetPoint("LEFT", delete, "RIGHT", 2, 0)
- icon:SetSize(32, 32)
- icon:SetTexCoord(0.1, 0.9, 0.1, 0.9)
- row.icon = icon
- local name = row:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
- name:SetPoint("LEFT", icon, "RIGHT", 8, 0)
- row.name = name
- local channel = LibStub("PhanxConfig-Dropdown"):New(row, nil, nil, Dropdown_Initialize)
- channel:SetPoint("RIGHT", 0, 5)
- channel:SetWidth(200)
- channel.OnEnter = Dropdown_OnEnter
- channel.OnLeave = Dropdown_OnLeave
- row.channel = channel
- t[i] = row
- return row
- end })
- self.rows = rows
- --------------------------------------------------------------------
- -- OnShow for self:
- local pool = {}
- local sortedSpells = {}
- local sortFunc = function(a, b)
- return a.name < b.name or (a.name == b.name and a.id < b.id)
- end
- function RefreshOptions()
- for i = #sortedSpells, 1, -1 do
- pool[tremove(sortedSpells, i)] = true
- end
- for id, channel in pairs(db) do
- local name, _, icon = GetSpellInfo(id)
- if name and icon then
- local spell = next(pool) or {}
- pool[spell] = nil
- spell.name = name
- spell.icon = icon
- spell.id = id
- spell.channel = channel
- tinsert(sortedSpells, spell)
- end
- end
- sort(sortedSpells, sortFunc)
- if #sortedSpells > 0 then
- local height = 0
- for i = 1, #sortedSpells do
- local spell = sortedSpells[i]
- local row = rows[i]
- row.id = spell.id
- row.name:SetText(spell.name)
- row.icon:SetTexture(spell.icon)
- row.channel:SetValue(spell.channel, ChannelNames[spell.channel])
- row:Show()
- height = height + 4 + row:GetHeight()
- end
- for i = #sortedSpells + 1, #rows do
- rows[i]:Hide()
- end
- scrollChild:SetHeight(height)
- add:Show()
- else
- for i = 1, #rows do
- rows[i]:Hide()
- end
- scrollChild:SetHeight(100)
- dialog:Show()
- add:Hide()
- end
- end
- self:SetScript("OnShow", nil)
- self.refresh = RefreshOptions
- RefreshOptions()
- end)
- f.name = GetAddOnMetadata(ADDON, "Title")
- InterfaceOptions_AddCategory(f)
- _G["SLASH_"..ADDON.."1"] = "/notroll"
- SlashCmdList[ADDON] = function()
- InterfaceOptionsFrame_OpenToCategory(f)
- InterfaceOptionsFrame_OpenToCategory(f)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement