WoWInterface SVN fernir_UI

[/] [chat.lua] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 Wildbreath-135052
-- variables
2 Wildbreath-135052
local settings = oUF_Settings
3 Wildbreath-135052
 
4 Wildbreath-135052
local gsub = string.gsub
5 Wildbreath-135052
local ipairs = _G.ipairs
6 Wildbreath-135052
local pairs = _G.pairs
7 Wildbreath-135052
local fmt = _G.string.format
8 Wildbreath-135052
local sub = _G.string.sub
9 Wildbreath-135052
 
10 Wildbreath-135052
local hooks = {}
11 Wildbreath-135052
local h
12 Wildbreath-135052
local buffer = {}
13 Wildbreath-135052
local lastMessageID = {0, 0, 0, 0, 0, 0, 0}
14 Wildbreath-135052
local bufferSize = 128
15 Wildbreath-135052
local _G = getfenv(0)
16 Wildbreath-135052
local date = date
17 Wildbreath-135052
 
18 Wildbreath-135052
local currentLink = nil
19 Wildbreath-135052
local ref = _G["SetItemRef"]
20 Wildbreath-135052
 
21 Wildbreath-135052
local tlds = {
22 Wildbreath-135052
   COM = true,
23 Wildbreath-135052
   UK = true,
24 Wildbreath-135052
   NET = true,
25 Wildbreath-135052
   INFO = true,
26 Wildbreath-135052
   CO = true,
27 Wildbreath-135052
   DE = true,
28 Wildbreath-135052
   FR = true,
29 Wildbreath-135052
   ES = true,
30 Wildbreath-135052
   BE = true,
31 Wildbreath-135052
   CC = true,
32 Wildbreath-135052
   US = true,
33 Wildbreath-135052
   KO = true,
34 Wildbreath-135052
   CH = true,
35 Wildbreath-135052
   TW = true,
36 Wildbreath-135052
   RU = true,
37 Wildbreath-135052
}
38 Wildbreath-135052
 
39 Wildbreath-135052
local style = "|cffffffff|Hurl:%s|h[%s]|h|r"
40 Wildbreath-135052
local tokennum, matchTable = 1, {}
41 Wildbreath-135052
 
42 Wildbreath-135052
 
43 Wildbreath-135052
--
44 Wildbreath-135052
 
45 Wildbreath-135052
 
46 Wildbreath-135052
--[[ Buttons ]]--
47 Wildbreath-135052
 
48 Wildbreath-135052
local dummy = function() end
49 Wildbreath-135052
 
50 Wildbreath-135052
ChatFrameMenuButton:Hide()                          -- Menu button
51 Wildbreath-135052
 
52 Wildbreath-135052
for i = 1, 7 do
53 Wildbreath-135052
    local u = _G["ChatFrame"..i.."UpButton"]        -- Scroll Up button
54 Wildbreath-135052
    u:Hide()                                        -- Delete these 2 lines if you don't want to hide this button
55 Wildbreath-135052
    u.Show = dummy                                  -- Delete these 2 lines if you don't want to hide this button
56 Wildbreath-135052
    local d = _G["ChatFrame"..i.."DownButton"]      -- Scroll Down button
57 Wildbreath-135052
    d:Hide()
58 Wildbreath-135052
    d.Show = dummy
59 Wildbreath-135052
    local b = _G["ChatFrame"..i.."BottomButton"]    -- Scroll to bottom button
60 Wildbreath-135052
    b:Hide()
61 Wildbreath-135052
    b.Show = dummy
62 Wildbreath-135052
end
63 Wildbreath-135052
 
64 Wildbreath-135052
 
65 Wildbreath-135052
--[[ Channel names ]]--
66 Wildbreath-135052
 
67 Wildbreath-135052
CHAT_GUILD_GET = "|Hchannel:Guild|h[G]|h %s "
68 Wildbreath-135052
CHAT_RAID_GET = "|Hchannel:raid|h[R]|h %s "
69 Wildbreath-135052
CHAT_PARTY_GET = "|Hchannel:Party|h[P]|h %s "
70 Wildbreath-135052
CHAT_RAID_WARNING_GET = "[RW] %s "
71 Wildbreath-135052
CHAT_RAID_LEADER_GET = "|Hchannel:raid|h[RL]|h %s "
72 Wildbreath-135052
CHAT_OFFICER_GET = "|Hchannel:o|h[O]|h %s "
73 Wildbreath-135052
CHAT_BATTLEGROUND_GET = "|Hchannel:Battleground|h[BG]|h %s "
74 Wildbreath-135052
CHAT_BATTLEGROUND_LEADER_GET = "|Hchannel:Battleground|h[BGL]|h %s "
75 Wildbreath-135052
CHAT_WHISPER_INFORM_GET = "To %s "
76 Wildbreath-135052
CHAT_WHISPER_GET = "From %s "
77 Wildbreath-135052
CHAT_SAY_GET = "%s "
78 Wildbreath-135052
CHAT_YELL_GET = "%s "
79 Wildbreath-135052
 
80 Wildbreath-135052
CHAT_FLAG_AFK = "[AFK] "
81 Wildbreath-135052
CHAT_FLAG_DND = "[DND] "
82 Wildbreath-135052
CHAT_FLAG_GM = "[GM] "
83 Wildbreath-135052
 
84 Wildbreath-135052
--[[ Editing custon channels here (general, trade etc) ]]
85 Wildbreath-135052
local str = "[%d|h] %3$s"         -- pattern. Returns "[1] [Name] text", where 1 is channel number.
86 Wildbreath-135052
local channel = function(...)
87 Wildbreath-135052
    return str:format(...)
88 Wildbreath-135052
end
89 Wildbreath-135052
 
90 Wildbreath-135052
--[[ Chat copy ]]--
91 Wildbreath-135052
 
92 Wildbreath-135052
local function AddMessage(frame, text, ...)
93 Wildbreath-135052
        text = text:gsub("|Hchannel:(%d+)|h%[?(.-)%]?|h.+(|Hplayer.+)", channel)
94 Wildbreath-135052
 
95 Wildbreath-135052
        if (text) then
96 Wildbreath-135052
                local chatFrameID = tonumber(strsub(frame:GetName(), 10))
97 Wildbreath-135052
                local messageID = lastMessageID[chatFrameID] + 1
98 Wildbreath-135052
                lastMessageID[chatFrameID] = messageID
99 Wildbreath-135052
                buffer[math.fmod(messageID - 1, bufferSize) + (1 + ((chatFrameID - 1) * bufferSize))] = text
100 Wildbreath-135052
                text = "|cffaabb00|Hcopybutton:"..chatFrameID..":"..messageID.."|h#|h|r "..text
101 Wildbreath-135052
                return hooks[frame](frame, text, ...)
102 Wildbreath-135052
        else
103 Wildbreath-135052
                return
104 Wildbreath-135052
        end
105 Wildbreath-135052
end
106 Wildbreath-135052
 
107 Wildbreath-135052
for i = 1, 7 do
108 Wildbreath-135052
        if(i ~= 2) then -- skip combatlog
109 Wildbreath-135052
                h = _G["ChatFrame"..i]
110 Wildbreath-135052
                hooks[h] = h.AddMessage
111 Wildbreath-135052
                h.AddMessage = AddMessage
112 Wildbreath-135052
        end
113 Wildbreath-135052
end
114 Wildbreath-135052
 
115 Wildbreath-135052
local ref = SetItemRef
116 Wildbreath-135052
SetItemRef = function(link, text, button)
117 Wildbreath-135052
 
118 Wildbreath-135052
        if sub(link, 1, 3) == "url" then
119 Wildbreath-135052
                currentLink = sub(link, 5)
120 Wildbreath-135052
                StaticPopup_Show("BCMUrlCopyDialog")
121 Wildbreath-135052
                return
122 Wildbreath-135052
        end
123 Wildbreath-135052
 
124 Wildbreath-135052
   if (strsub(link, 1, 11) ~= "copybutton:") then
125 Wildbreath-135052
     return ref(link, text, button)
126 Wildbreath-135052
   end
127 Wildbreath-135052
 
128 Wildbreath-135052
   local function strip(str)
129 Wildbreath-135052
    str = gsub(str, "|Hplayer:.-%[(.-)%]|h", "%1")
130 Wildbreath-135052
    str = gsub(str, "(|c%x%x%x%x%x%x%x%x(.-)|r)", function (full, text)
131 Wildbreath-135052
       if not strmatch(text, "^|H.-|h$") then
132 Wildbreath-135052
          return text
133 Wildbreath-135052
       end
134 Wildbreath-135052
    end)
135 Wildbreath-135052
    return str
136 Wildbreath-135052
   end
137 Wildbreath-135052
 
138 Wildbreath-135052
   local chatFrameID, messageID = strmatch(link, "^copybutton:(%d+):(%d+)$")
139 Wildbreath-135052
   local text = strip(buffer[math.fmod(messageID - 1, bufferSize) + (1 + ((chatFrameID - 1) * bufferSize))])
140 Wildbreath-135052
 
141 Wildbreath-135052
   local editbox = _G["ChatFrameEditBox"]
142 Wildbreath-135052
   if text and editbox then
143 Wildbreath-135052
     editbox:SetText(text)
144 Wildbreath-135052
     editbox:Show()
145 Wildbreath-135052
     editbox:SetFocus()
146 Wildbreath-135052
   end
147 Wildbreath-135052
end
148 Wildbreath-135052
 
149 Wildbreath-135052
 
150 Wildbreath-135052
--[[ Editbox ]]--
151 Wildbreath-135052
 
152 Wildbreath-135052
local eb = ChatFrameEditBox
153 Wildbreath-135052
eb:ClearAllPoints()
154 Wildbreath-135052
eb:SetAltArrowKeyMode(false)
155 Wildbreath-135052
eb:SetPoint("BOTTOMLEFT",  ChatFrame1, "TOPLEFT", -5, 18)
156 Wildbreath-135052
eb:SetPoint("BOTTOMRIGHT", ChatFrame1, "TOPRIGHT", 5, 18)
157 Wildbreath-135052
 
158 Wildbreath-135052
local a, b, c = select(6, eb:GetRegions())
159 Wildbreath-135052
a:Hide(); b:Hide(); c:Hide()
160 Wildbreath-135052
 
161 Wildbreath-135052
local ebbg = eb:CreateTexture(nil, "BACKGROUND")
162 Wildbreath-135052
ebbg:SetPoint("BOTTOMRIGHT", -5, 5)
163 Wildbreath-135052
ebbg:SetPoint("TOPLEFT", 5, -5)
164 Wildbreath-135052
ebbg:SetTexture(0, 0, 0, .4)
165 Wildbreath-135052
 
166 Wildbreath-135052
--[[ Scroll ]]--
167 Wildbreath-135052
 
168 Wildbreath-135052
local scroll = function(self, dir)
169 Wildbreath-135052
    if(dir > 0) then
170 Wildbreath-135052
        if(IsShiftKeyDown()) then
171 Wildbreath-135052
            self:ScrollToTop()
172 Wildbreath-135052
        else
173 Wildbreath-135052
            self:ScrollUp()
174 Wildbreath-135052
        end
175 Wildbreath-135052
    elseif(dir < 0) then
176 Wildbreath-135052
        if(IsShiftKeyDown()) then
177 Wildbreath-135052
            self:ScrollToBottom()
178 Wildbreath-135052
        else
179 Wildbreath-135052
            self:ScrollDown()
180 Wildbreath-135052
        end
181 Wildbreath-135052
    end
182 Wildbreath-135052
end
183 Wildbreath-135052
 
184 Wildbreath-135052
for i = 1, 7 do
185 Wildbreath-135052
    local cf = _G["ChatFrame"..i]
186 Wildbreath-135052
    cf:EnableMouseWheel(true)
187 Wildbreath-135052
    cf:SetScript("OnMouseWheel", scroll)
188 Wildbreath-135052
end
189 Wildbreath-135052
 
190 Wildbreath-135052
--[[ Sticky ]] --
191 Wildbreath-135052
 
192 Wildbreath-135052
ChatTypeInfo["YELL"].sticky = 1
193 Wildbreath-135052
ChatTypeInfo["OFFICER"].sticky = 1
194 Wildbreath-135052
ChatTypeInfo["WHISPER"].sticky = 1
195 Wildbreath-135052
ChatTypeInfo["CHANNEL"].sticky = 1
196 Wildbreath-135052
ChatTypeInfo["RAID_WARNING"].sticky = 1
197 Wildbreath-135052
 
198 Wildbreath-135052
 
199 Wildbreath-135052
--[[ Url copy ]]--
200 Wildbreath-135052
 
201 Wildbreath-135052
local function RegisterMatch(text)
202 Wildbreath-135052
        local token = "\255\254\253"..tokennum.."\253\254\255"
203 Wildbreath-135052
        matchTable[token] = strreplace(text, "%", "%%")
204 Wildbreath-135052
        tokennum = tokennum + 1
205 Wildbreath-135052
        return token
206 Wildbreath-135052
end
207 Wildbreath-135052
 
208 Wildbreath-135052
local function Link(link, ...)
209 Wildbreath-135052
        if not link then
210 Wildbreath-135052
                return ""
211 Wildbreath-135052
        end
212 Wildbreath-135052
        return RegisterMatch(fmt(style, link, link))
213 Wildbreath-135052
end
214 Wildbreath-135052
 
215 Wildbreath-135052
local function Link_TLD(link, tld, ...)
216 Wildbreath-135052
        if not link or not tld then
217 Wildbreath-135052
                return ""
218 Wildbreath-135052
        end
219 Wildbreath-135052
        if tlds[strupper(tld)] then
220 Wildbreath-135052
        return RegisterMatch(fmt(style, link, link))
221 Wildbreath-135052
    else
222 Wildbreath-135052
        return RegisterMatch(link)
223 Wildbreath-135052
    end
224 Wildbreath-135052
end
225 Wildbreath-135052
 
226 Wildbreath-135052
local patterns = {
227 Wildbreath-135052
                -- X://Y url
228 Wildbreath-135052
        { pattern = "^(%a[%w%.+-]+://%S+)", matchfunc=Link},
229 Wildbreath-135052
        { pattern = "%f[%S](%a[%w%.+-]+://%S+)", matchfunc=Link},
230 Wildbreath-135052
                -- www.X.Y url
231 Wildbreath-135052
        { pattern = "^(www%.[%w_-%%]+%.%S+)", matchfunc=Link},
232 Wildbreath-135052
        { pattern = "%f[%S](www%.[%w_-%%]+%.%S+)", matchfunc=Link},
233 Wildbreath-135052
                -- X@Y.Z email
234 Wildbreath-135052
        { pattern = "(%S+@[%w_-%%%.]+%.(%a%a+))", matchfunc=Link_TLD},
235 Wildbreath-135052
                -- X.Y.Z/WWWWW url with path
236 Wildbreath-135052
        { pattern = "^([%w_-%%%.]+[%w_-%%]%.(%a%a+)/%S+)", matchfunc=Link_TLD},
237 Wildbreath-135052
        { pattern = "%f[%S]([%w_-%%%.]+[%w_-%%]%.(%a%a+)/%S+)", matchfunc=Link_TLD},
238 Wildbreath-135052
                -- X.Y.Z url
239 Wildbreath-135052
        { pattern = "^([%w_-%%%.]+[%w_-%%]%.(%a%a+))", matchfunc=Link_TLD},
240 Wildbreath-135052
        { pattern = "%f[%S]([%w_-%%%.]+[%w_-%%]%.(%a%a+))", matchfunc=Link_TLD},
241 Wildbreath-135052
}
242 Wildbreath-135052
 
243 Wildbreath-135052
local function filterFunc(self, event, msg, ...)
244 Wildbreath-135052
        for _, v in ipairs(patterns) do
245 Wildbreath-135052
                msg = gsub(msg, v.pattern, v.matchfunc)
246 Wildbreath-135052
        end
247 Wildbreath-135052
        for k,v in pairs(matchTable) do
248 Wildbreath-135052
                msg = gsub(msg, k, v)
249 Wildbreath-135052
                matchTable[k] = nil
250 Wildbreath-135052
        end
251 Wildbreath-135052
        return false, msg, ...
252 Wildbreath-135052
end
253 Wildbreath-135052
 
254 Wildbreath-135052
local function AddEvents()
255 Wildbreath-135052
        local events = {
256 Wildbreath-135052
                "CHAT_MSG_CHANNEL", "CHAT_MSG_YELL",
257 Wildbreath-135052
                "CHAT_MSG_GUILD", "CHAT_MSG_OFFICER",
258 Wildbreath-135052
                "CHAT_MSG_PARTY", "CHAT_MSG_RAID",
259 Wildbreath-135052
                "CHAT_MSG_RAID_LEADER",
260 Wildbreath-135052
                "CHAT_MSG_SAY", "CHAT_MSG_WHISPER",
261 Wildbreath-135052
        }
262 Wildbreath-135052
        for _,event in ipairs(events) do
263 Wildbreath-135052
                ChatFrame_AddMessageEventFilter(event, filterFunc)
264 Wildbreath-135052
        end
265 Wildbreath-135052
end
266 Wildbreath-135052
 
267 Wildbreath-135052
AddEvents()
268 Wildbreath-135052
 
269 Wildbreath-135052
 
270 Wildbreath-135052
--Popup Box
271 Wildbreath-135052
StaticPopupDialogs["BCMUrlCopyDialog"] = {
272 Wildbreath-135052
        text = "URL",
273 Wildbreath-135052
        button2 = TEXT(CLOSE),
274 Wildbreath-135052
        hasEditBox = 1,
275 Wildbreath-135052
        hasWideEditBox = 1,
276 Wildbreath-135052
        showAlert = 1,
277 Wildbreath-135052
        OnShow = function()
278 Wildbreath-135052
                local editBox = _G[this:GetName().."WideEditBox"]
279 Wildbreath-135052
                editBox:SetText(currentLink)
280 Wildbreath-135052
                editBox:SetFocus()
281 Wildbreath-135052
                editBox:HighlightText(0)
282 Wildbreath-135052
                local button = _G[this:GetName().."Button2"]
283 Wildbreath-135052
                button:ClearAllPoints()
284 Wildbreath-135052
                button:SetWidth(200)
285 Wildbreath-135052
                button:SetPoint("CENTER", editBox, "CENTER", 0, -30)
286 Wildbreath-135052
                _G[this:GetName().."AlertIcon"]:Hide()
287 Wildbreath-135052
        end,
288 Wildbreath-135052
        EditBoxOnEscapePressed = function() this:GetParent():Hide() end,
289 Wildbreath-135052
        timeout = 0,
290 Wildbreath-135052
        whileDead = 1,
291 Wildbreath-135052
        hideOnEscape = 1,
292 Wildbreath-135052
}
293 Wildbreath-135052
 
294 Wildbreath-135052
 
295 Wildbreath-135052
--[[ Extras ]]--
296 Wildbreath-135052
local chatsetup = CreateFrame("Frame")
297 Wildbreath-135052
chatsetup:RegisterEvent("PLAYER_ENTERING_WORLD")
298 Wildbreath-135052
chatsetup:SetScript("OnEvent", function(self, event)
299 Wildbreath-135052
   chatsetup:UnregisterEvent("PLAYER_ENTERING_WORLD")
300 Wildbreath-135052
   for i = 1, 7 do
301 Wildbreath-135052
      _G["ChatFrame"..i.."TabLeft"]:Hide()
302 Wildbreath-135052
      _G["ChatFrame"..i.."TabRight"]:Hide()
303 Wildbreath-135052
      _G["ChatFrame"..i.."TabMiddle"]:Hide()
304 Wildbreath-135052
      _G["ChatFrame"..i.."TabText"]:SetFont(settings.font, 12, "THINOUTLINE")
305 Wildbreath-135052
 
306 Wildbreath-135052
      _G["ChatFrame"..i.."ResizeRightTexture"]:SetAlpha(0)
307 Wildbreath-135052
      _G["ChatFrame"..i.."ResizeRightTexture"].SetAlpha = function() return end
308 Wildbreath-135052
 
309 Wildbreath-135052
      _G["ChatFrame"..i.."ResizeLeftTexture"]:SetAlpha(0)
310 Wildbreath-135052
      _G["ChatFrame"..i.."ResizeLeftTexture"].SetAlpha = function() return end
311 Wildbreath-135052
 
312 Wildbreath-135052
      _G["ChatFrame"..i.."ResizeTopTexture"]:SetAlpha(0)
313 Wildbreath-135052
      _G["ChatFrame"..i.."ResizeTopTexture"].SetAlpha = function() return end
314 Wildbreath-135052
 
315 Wildbreath-135052
                _G["ChatFrame"..i.."ResizeBottomTexture"]:SetAlpha(0)
316 Wildbreath-135052
                _G["ChatFrame"..i.."ResizeBottomTexture"].SetAlpha = function() return end
317 Wildbreath-135052
 
318 Wildbreath-135052
      _G["ChatFrame"..i.."ResizeTopRightTexture"]:SetAlpha(0)
319 Wildbreath-135052
      _G["ChatFrame"..i.."ResizeTopRightTexture"].SetAlpha = function() return end
320 Wildbreath-135052
 
321 Wildbreath-135052
      _G["ChatFrame"..i.."ResizeTopLeftTexture"]:SetAlpha(0)
322 Wildbreath-135052
      _G["ChatFrame"..i.."ResizeTopLeftTexture"].SetAlpha = function() return end
323 Wildbreath-135052
 
324 Wildbreath-135052
                _G["ChatFrame"..i.."ResizeBottomRightTexture"]:SetAlpha(0)
325 Wildbreath-135052
                _G["ChatFrame"..i.."ResizeBottomRightTexture"].SetAlpha = function() return end
326 Wildbreath-135052
 
327 Wildbreath-135052
                _G["ChatFrame"..i.."ResizeBottomLeftTexture"]:SetAlpha(0)
328 Wildbreath-135052
                _G["ChatFrame"..i.."ResizeBottomLeftTexture"].SetAlpha = function() return end
329 Wildbreath-135052
 
330 Wildbreath-135052
      _G["ChatFrame"..i.."Background"]:SetTexture(settings.texture)
331 Wildbreath-135052
      _G["ChatFrame"..i.."Background"].SetTexture = function() return end
332 Wildbreath-135052
      _G["ChatFrame"..i.."Background"]:SetAlpha(settings.chatalpha)
333 Wildbreath-135052
      _G["ChatFrame"..i.."Background"].SetAlpha = function() return end
334 Wildbreath-135052
      _G["ChatFrame"..i.."Background"]:SetVertexColor(unpack(settings.chatcolor))
335 Wildbreath-135052
      _G["ChatFrame"..i.."Background"].SetVertexColor = function() return end
336 Wildbreath-135052
 
337 Wildbreath-135052
                local bg = _G["ChatFrame"..i]:CreateTexture(nil, "BACKGROUND")
338 Wildbreath-135052
                bg:SetTexture(0,0,0)
339 Wildbreath-135052
                bg:SetPoint("TOPLEFT", _G["ChatFrame"..i], "TOPLEFT", -4, 5)
340 Wildbreath-135052
                bg:SetPoint("BOTTOMRIGHT", _G["ChatFrame"..i], "BOTTOMRIGHT", 4, -8)
341 Wildbreath-135052
   end
342 Wildbreath-135052
end)