Quantcast
WoWInterface: SVN - fernir_UI - Rev 2 - /chat.lua

WoWInterface SVN fernir_UI

[/] [chat.lua] - Rev 2

Compare with Previous | Blame | View Log

-- variables
local settings = oUF_Settings

local gsub = string.gsub
local ipairs = _G.ipairs
local pairs = _G.pairs
local fmt = _G.string.format
local sub = _G.string.sub

local hooks = {}
local h
local buffer = {}
local lastMessageID = {0, 0, 0, 0, 0, 0, 0}
local bufferSize = 128
local _G = getfenv(0)
local date = date

local currentLink = nil
local ref = _G["SetItemRef"]

local tlds = {
   COM = true,
   UK = true,
   NET = true,
   INFO = true,
   CO = true,
   DE = true,
   FR = true,
   ES = true,
   BE = true,
   CC = true,
   US = true,
   KO = true,
   CH = true,
   TW = true,
   RU = true,
}

local style = "|cffffffff|Hurl:%s|h[%s]|h|r"
local tokennum, matchTable = 1, {}


--


--[[ Buttons ]]--

local dummy = function() end

ChatFrameMenuButton:Hide()                          -- Menu button

for i = 1, 7 do
    local u = _G["ChatFrame"..i.."UpButton"]        -- Scroll Up button
    u:Hide()                                        -- Delete these 2 lines if you don't want to hide this button
    u.Show = dummy                                  -- Delete these 2 lines if you don't want to hide this button
    local d = _G["ChatFrame"..i.."DownButton"]      -- Scroll Down button
    d:Hide()
    d.Show = dummy
    local b = _G["ChatFrame"..i.."BottomButton"]    -- Scroll to bottom button
    b:Hide()
    b.Show = dummy
end


--[[ Channel names ]]--

CHAT_GUILD_GET = "|Hchannel:Guild|h[G]|h %s "
CHAT_RAID_GET = "|Hchannel:raid|h[R]|h %s "
CHAT_PARTY_GET = "|Hchannel:Party|h[P]|h %s "
CHAT_RAID_WARNING_GET = "[RW] %s "
CHAT_RAID_LEADER_GET = "|Hchannel:raid|h[RL]|h %s "
CHAT_OFFICER_GET = "|Hchannel:o|h[O]|h %s "
CHAT_BATTLEGROUND_GET = "|Hchannel:Battleground|h[BG]|h %s "
CHAT_BATTLEGROUND_LEADER_GET = "|Hchannel:Battleground|h[BGL]|h %s "
CHAT_WHISPER_INFORM_GET = "To %s "
CHAT_WHISPER_GET = "From %s "
CHAT_SAY_GET = "%s "
CHAT_YELL_GET = "%s "

CHAT_FLAG_AFK = "[AFK] "
CHAT_FLAG_DND = "[DND] "
CHAT_FLAG_GM = "[GM] "

--[[ Editing custon channels here (general, trade etc) ]]
local str = "[%d|h] %3$s"         -- pattern. Returns "[1] [Name] text", where 1 is channel number.
local channel = function(...)
    return str:format(...)
end

--[[ Chat copy ]]--

local function AddMessage(frame, text, ...)
        text = text:gsub("|Hchannel:(%d+)|h%[?(.-)%]?|h.+(|Hplayer.+)", channel)

        if (text) then
                local chatFrameID = tonumber(strsub(frame:GetName(), 10))
                local messageID = lastMessageID[chatFrameID] + 1
                lastMessageID[chatFrameID] = messageID
                buffer[math.fmod(messageID - 1, bufferSize) + (1 + ((chatFrameID - 1) * bufferSize))] = text
                text = "|cffaabb00|Hcopybutton:"..chatFrameID..":"..messageID.."|h#|h|r "..text
                return hooks[frame](frame, text, ...)
        else
                return
        end
end

for i = 1, 7 do
        if(i ~= 2) then -- skip combatlog
                h = _G["ChatFrame"..i]
                hooks[h] = h.AddMessage
                h.AddMessage = AddMessage
        end
end

local ref = SetItemRef
SetItemRef = function(link, text, button)

        if sub(link, 1, 3) == "url" then
                currentLink = sub(link, 5)
                StaticPopup_Show("BCMUrlCopyDialog")
                return
        end
   
   if (strsub(link, 1, 11) ~= "copybutton:") then
     return ref(link, text, button)
   end

   local function strip(str)
    str = gsub(str, "|Hplayer:.-%[(.-)%]|h", "%1")
    str = gsub(str, "(|c%x%x%x%x%x%x%x%x(.-)|r)", function (full, text) 
       if not strmatch(text, "^|H.-|h$") then 
          return text 
       end
    end)
    return str
   end

   local chatFrameID, messageID = strmatch(link, "^copybutton:(%d+):(%d+)$")
   local text = strip(buffer[math.fmod(messageID - 1, bufferSize) + (1 + ((chatFrameID - 1) * bufferSize))])

   local editbox = _G["ChatFrameEditBox"]
   if text and editbox then
     editbox:SetText(text)
     editbox:Show()
     editbox:SetFocus()
   end
end


--[[ Editbox ]]--

local eb = ChatFrameEditBox
eb:ClearAllPoints()
eb:SetAltArrowKeyMode(false)
eb:SetPoint("BOTTOMLEFT",  ChatFrame1, "TOPLEFT", -5, 18)
eb:SetPoint("BOTTOMRIGHT", ChatFrame1, "TOPRIGHT", 5, 18)

local a, b, c = select(6, eb:GetRegions())
a:Hide(); b:Hide(); c:Hide()

local ebbg = eb:CreateTexture(nil, "BACKGROUND")
ebbg:SetPoint("BOTTOMRIGHT", -5, 5)
ebbg:SetPoint("TOPLEFT", 5, -5)
ebbg:SetTexture(0, 0, 0, .4)

--[[ Scroll ]]--

local scroll = function(self, dir)
    if(dir > 0) then
        if(IsShiftKeyDown()) then
            self:ScrollToTop()
        else
            self:ScrollUp()
        end
    elseif(dir < 0) then
        if(IsShiftKeyDown()) then
            self:ScrollToBottom()
        else
            self:ScrollDown()
        end
    end
end

for i = 1, 7 do
    local cf = _G["ChatFrame"..i]
    cf:EnableMouseWheel(true)
    cf:SetScript("OnMouseWheel", scroll)
end

--[[ Sticky ]] --

ChatTypeInfo["YELL"].sticky = 1
ChatTypeInfo["OFFICER"].sticky = 1
ChatTypeInfo["WHISPER"].sticky = 1
ChatTypeInfo["CHANNEL"].sticky = 1
ChatTypeInfo["RAID_WARNING"].sticky = 1


--[[ Url copy ]]--

local function RegisterMatch(text)
        local token = "\255\254\253"..tokennum.."\253\254\255"
        matchTable[token] = strreplace(text, "%", "%%")
        tokennum = tokennum + 1
        return token
end

local function Link(link, ...)
        if not link then
                return ""
        end
        return RegisterMatch(fmt(style, link, link))
end

local function Link_TLD(link, tld, ...)
        if not link or not tld then
                return ""
        end
        if tlds[strupper(tld)] then
        return RegisterMatch(fmt(style, link, link))
    else
        return RegisterMatch(link)
    end
end

local patterns = {
                -- X://Y url
        { pattern = "^(%a[%w%.+-]+://%S+)", matchfunc=Link},
        { pattern = "%f[%S](%a[%w%.+-]+://%S+)", matchfunc=Link},
                -- www.X.Y url
        { pattern = "^(www%.[%w_-%%]+%.%S+)", matchfunc=Link},
        { pattern = "%f[%S](www%.[%w_-%%]+%.%S+)", matchfunc=Link},
                -- X@Y.Z email
        { pattern = "(%S+@[%w_-%%%.]+%.(%a%a+))", matchfunc=Link_TLD},
                -- X.Y.Z/WWWWW url with path
        { pattern = "^([%w_-%%%.]+[%w_-%%]%.(%a%a+)/%S+)", matchfunc=Link_TLD},
        { pattern = "%f[%S]([%w_-%%%.]+[%w_-%%]%.(%a%a+)/%S+)", matchfunc=Link_TLD},
                -- X.Y.Z url
        { pattern = "^([%w_-%%%.]+[%w_-%%]%.(%a%a+))", matchfunc=Link_TLD},
        { pattern = "%f[%S]([%w_-%%%.]+[%w_-%%]%.(%a%a+))", matchfunc=Link_TLD},
}

local function filterFunc(self, event, msg, ...)
        for _, v in ipairs(patterns) do
                msg = gsub(msg, v.pattern, v.matchfunc)
        end
        for k,v in pairs(matchTable) do
                msg = gsub(msg, k, v)
                matchTable[k] = nil
        end
        return false, msg, ...
end

local function AddEvents()
        local events = {
                "CHAT_MSG_CHANNEL", "CHAT_MSG_YELL",
                "CHAT_MSG_GUILD", "CHAT_MSG_OFFICER",
                "CHAT_MSG_PARTY", "CHAT_MSG_RAID",
                "CHAT_MSG_RAID_LEADER",
                "CHAT_MSG_SAY", "CHAT_MSG_WHISPER",
        }
        for _,event in ipairs(events) do
                ChatFrame_AddMessageEventFilter(event, filterFunc)
        end
end

AddEvents()


--Popup Box
StaticPopupDialogs["BCMUrlCopyDialog"] = {
        text = "URL",
        button2 = TEXT(CLOSE),
        hasEditBox = 1,
        hasWideEditBox = 1,
        showAlert = 1,
        OnShow = function()
                local editBox = _G[this:GetName().."WideEditBox"]
                editBox:SetText(currentLink)
                editBox:SetFocus()
                editBox:HighlightText(0)
                local button = _G[this:GetName().."Button2"]
                button:ClearAllPoints()
                button:SetWidth(200)
                button:SetPoint("CENTER", editBox, "CENTER", 0, -30)
                _G[this:GetName().."AlertIcon"]:Hide()
        end,
        EditBoxOnEscapePressed = function() this:GetParent():Hide() end,
        timeout = 0,
        whileDead = 1,
        hideOnEscape = 1,
}


--[[ Extras ]]--
local chatsetup = CreateFrame("Frame")
chatsetup:RegisterEvent("PLAYER_ENTERING_WORLD")
chatsetup:SetScript("OnEvent", function(self, event)
   chatsetup:UnregisterEvent("PLAYER_ENTERING_WORLD")
   for i = 1, 7 do
      _G["ChatFrame"..i.."TabLeft"]:Hide()
      _G["ChatFrame"..i.."TabRight"]:Hide()
      _G["ChatFrame"..i.."TabMiddle"]:Hide()
      _G["ChatFrame"..i.."TabText"]:SetFont(settings.font, 12, "THINOUTLINE")
      
      _G["ChatFrame"..i.."ResizeRightTexture"]:SetAlpha(0)
      _G["ChatFrame"..i.."ResizeRightTexture"].SetAlpha = function() return end
                
      _G["ChatFrame"..i.."ResizeLeftTexture"]:SetAlpha(0)
      _G["ChatFrame"..i.."ResizeLeftTexture"].SetAlpha = function() return end
                
      _G["ChatFrame"..i.."ResizeTopTexture"]:SetAlpha(0)
      _G["ChatFrame"..i.."ResizeTopTexture"].SetAlpha = function() return end
      
                _G["ChatFrame"..i.."ResizeBottomTexture"]:SetAlpha(0)
                _G["ChatFrame"..i.."ResizeBottomTexture"].SetAlpha = function() return end
      
      _G["ChatFrame"..i.."ResizeTopRightTexture"]:SetAlpha(0)
      _G["ChatFrame"..i.."ResizeTopRightTexture"].SetAlpha = function() return end
                
      _G["ChatFrame"..i.."ResizeTopLeftTexture"]:SetAlpha(0)
      _G["ChatFrame"..i.."ResizeTopLeftTexture"].SetAlpha = function() return end
      
                _G["ChatFrame"..i.."ResizeBottomRightTexture"]:SetAlpha(0)
                _G["ChatFrame"..i.."ResizeBottomRightTexture"].SetAlpha = function() return end
      
                _G["ChatFrame"..i.."ResizeBottomLeftTexture"]:SetAlpha(0)
                _G["ChatFrame"..i.."ResizeBottomLeftTexture"].SetAlpha = function() return end
      
      _G["ChatFrame"..i.."Background"]:SetTexture(settings.texture)
      _G["ChatFrame"..i.."Background"].SetTexture = function() return end
      _G["ChatFrame"..i.."Background"]:SetAlpha(settings.chatalpha)
      _G["ChatFrame"..i.."Background"].SetAlpha = function() return end
      _G["ChatFrame"..i.."Background"]:SetVertexColor(unpack(settings.chatcolor))
      _G["ChatFrame"..i.."Background"].SetVertexColor = function() return end
                
                local bg = _G["ChatFrame"..i]:CreateTexture(nil, "BACKGROUND")
                bg:SetTexture(0,0,0)
                bg:SetPoint("TOPLEFT", _G["ChatFrame"..i], "TOPLEFT", -4, 5)
                bg:SetPoint("BOTTOMRIGHT", _G["ChatFrame"..i], "BOTTOMRIGHT", 4, -8)
   end
end)

Compare with Previous | Blame