Advertisement
Guest User

Chat.lua

a guest
Apr 27th, 2014
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.48 KB | None | 0 0
  1. local MODULE_NAME = "Chat"
  2. local ADDON_NAME = LibStub("AceAddon-3.0"):GetAddon("BasicUI")
  3. local MODULE = ADDON_NAME:NewModule(MODULE_NAME, "AceEvent-3.0")
  4. local L = setmetatable({}, { __index = function(t,k)
  5. local v = tostring(k)
  6. rawset(t, k, v)
  7. return v
  8. end })
  9.  
  10. ------------------------------------------------------------------------
  11. -- Module Database
  12. ------------------------------------------------------------------------
  13.  
  14. local BASIC_BORDER = [[Interface\Tooltips\UI-Tooltip-Border]]
  15. local BASIC_BACKGROUND = [[Interface\DialogFrame\UI-DialogBox-Background-Dark]]
  16. local BASIC_STATUSBAR = [[Interface\TargetingFrame\UI-StatusBar]]
  17.  
  18. local db
  19. local defaults = {
  20. profile = {
  21. enable = true,
  22. disableFade = false,
  23. chatOutline = false,
  24. windowborder = false,
  25. enableborder = false,
  26.  
  27. -- Chat Media
  28. border = BASIC_BORDER,
  29. background = BASIC_BACKGROUND,
  30. editboxborder = BASIC_BORDER,
  31. editboxbackground = BASIC_BACKGROUND,
  32. sound = [[Interface\Addons\BasicUI\Media\Whisper.mp3]],
  33.  
  34. enableHyperlinkTooltip = true,
  35. enableBorderColoring = true,
  36.  
  37. tab = {
  38. fontSize = 15,
  39. fontOutline = true,
  40. normalColor = {r = 1, g = 1, b = 1},
  41. specialColor = {r = 1, g = 0, b = 1},
  42. selectedColor = {r = 0, g = 0.75, b = 1},
  43. },
  44. }
  45. }
  46.  
  47. ------------------------------------------------------------------------
  48. -- Module Functions
  49. ------------------------------------------------------------------------
  50.  
  51. local classColor
  52.  
  53. function MODULE:OnInitialize()
  54. self.db = ADDON_NAME.db:RegisterNamespace(MODULE_NAME, defaults)
  55. db = self.db.profile
  56.  
  57. local _, class = UnitClass("player")
  58. classColor = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  59.  
  60. self:SetEnabledState(ADDON_NAME:GetModuleEnabled(MODULE_NAME))
  61. end
  62.  
  63. function MODULE:OnEnable()
  64.  
  65. -- Chat Message Groups
  66. ChatFrame_RemoveAllMessageGroups(ChatFrame1)
  67. ChatFrame_AddMessageGroup(ChatFrame1, "SAY")
  68. ChatFrame_AddMessageGroup(ChatFrame1, "EMOTE")
  69. ChatFrame_AddMessageGroup(ChatFrame1, "YELL")
  70. ChatFrame_AddMessageGroup(ChatFrame1, "GUILD")
  71. ChatFrame_AddMessageGroup(ChatFrame1, "OFFICER")
  72. ChatFrame_AddMessageGroup(ChatFrame1, "GUILD_ACHIEVEMENT")
  73. ChatFrame_AddMessageGroup(ChatFrame1, "MONSTER_SAY")
  74. ChatFrame_AddMessageGroup(ChatFrame1, "MONSTER_EMOTE")
  75. ChatFrame_AddMessageGroup(ChatFrame1, "MONSTER_YELL")
  76. ChatFrame_AddMessageGroup(ChatFrame1, "MONSTER_BOSS_EMOTE")
  77. ChatFrame_AddMessageGroup(ChatFrame1, "PARTY")
  78. ChatFrame_AddMessageGroup(ChatFrame1, "PARTY_LEADER")
  79. ChatFrame_AddMessageGroup(ChatFrame1, "RAID")
  80. ChatFrame_AddMessageGroup(ChatFrame1, "RAID_LEADER")
  81. ChatFrame_AddMessageGroup(ChatFrame1, "RAID_WARNING")
  82. ChatFrame_AddMessageGroup(ChatFrame1, "INSTANCE_CHAT")
  83. ChatFrame_AddMessageGroup(ChatFrame1, "INSTANCE_CHAT_LEADER")
  84. ChatFrame_AddMessageGroup(ChatFrame1, "BATTLEGROUND")
  85. ChatFrame_AddMessageGroup(ChatFrame1, "BATTLEGROUND_LEADER")
  86. ChatFrame_AddMessageGroup(ChatFrame1, "BG_HORDE")
  87. ChatFrame_AddMessageGroup(ChatFrame1, "BG_ALLIANCE")
  88. ChatFrame_AddMessageGroup(ChatFrame1, "BG_NEUTRAL")
  89. ChatFrame_AddMessageGroup(ChatFrame1, "SYSTEM")
  90. ChatFrame_AddMessageGroup(ChatFrame1, "ERRORS")
  91. ChatFrame_AddMessageGroup(ChatFrame1, "AFK")
  92. ChatFrame_AddMessageGroup(ChatFrame1, "DND")
  93. ChatFrame_AddMessageGroup(ChatFrame1, "IGNORED")
  94. ChatFrame_AddMessageGroup(ChatFrame1, "ACHIEVEMENT")
  95. ChatFrame_AddMessageGroup(ChatFrame1, "COMBAT_FACTION_CHANGE")
  96. ChatFrame_AddMessageGroup(ChatFrame1, "SKILL")
  97. ChatFrame_AddMessageGroup(ChatFrame1, "LOOT")
  98. ChatFrame_AddMessageGroup(ChatFrame1, "MONEY")
  99. ChatFrame_AddMessageGroup(ChatFrame1, "COMBAT_XP_GAIN")
  100. ChatFrame_AddMessageGroup(ChatFrame1, "COMBAT_HONOR_GAIN")
  101. ChatFrame_AddMessageGroup(ChatFrame1, "COMBAT_GUILD_XP_GAIN")
  102. ChatFrame_AddMessageGroup(ChatFrame1, "BN_INLINE_TOAST_ALERT")
  103.  
  104.  
  105. ChatFrame_RemoveAllMessageGroups(ChatFrame3)
  106. ChatFrame_AddMessageGroup(ChatFrame3, "WHISPER")
  107. ChatFrame_AddMessageGroup(ChatFrame3, "BN_WHISPER")
  108. ChatFrame_AddMessageGroup(ChatFrame3, "BN_CONVERSATION")
  109.  
  110.  
  111.  
  112. -- enable classcolor automatically on login and on each character without doing /configure each time.
  113. ToggleChatColorNamesByClassGroup(true, "SAY")
  114. ToggleChatColorNamesByClassGroup(true, "EMOTE")
  115. ToggleChatColorNamesByClassGroup(true, "YELL")
  116. ToggleChatColorNamesByClassGroup(true, "GUILD")
  117. ToggleChatColorNamesByClassGroup(true, "OFFICER")
  118. ToggleChatColorNamesByClassGroup(true, "GUILD_ACHIEVEMENT")
  119. ToggleChatColorNamesByClassGroup(true, "ACHIEVEMENT")
  120. ToggleChatColorNamesByClassGroup(true, "WHISPER")
  121. ToggleChatColorNamesByClassGroup(true, "PARTY")
  122. ToggleChatColorNamesByClassGroup(true, "PARTY_LEADER")
  123. ToggleChatColorNamesByClassGroup(true, "RAID")
  124. ToggleChatColorNamesByClassGroup(true, "RAID_LEADER")
  125. ToggleChatColorNamesByClassGroup(true, "RAID_WARNING")
  126. ToggleChatColorNamesByClassGroup(true, "BATTLEGROUND")
  127. ToggleChatColorNamesByClassGroup(true, "BATTLEGROUND_LEADER")
  128. ToggleChatColorNamesByClassGroup(true, "INSTANCE_CHAT")
  129. ToggleChatColorNamesByClassGroup(true, "INSTANCE_CHAT_LEADER")
  130. ToggleChatColorNamesByClassGroup(true, "CHANNEL1")
  131. ToggleChatColorNamesByClassGroup(true, "CHANNEL2")
  132. ToggleChatColorNamesByClassGroup(true, "CHANNEL3")
  133. ToggleChatColorNamesByClassGroup(true, "CHANNEL4")
  134. ToggleChatColorNamesByClassGroup(true, "CHANNEL5")
  135. ToggleChatColorNamesByClassGroup(true, "CHANNEL6")
  136. ToggleChatColorNamesByClassGroup(true, "CHANNEL7")
  137. ToggleChatColorNamesByClassGroup(true, "CHANNEL8")
  138. ToggleChatColorNamesByClassGroup(true, "CHANNEL9")
  139. ToggleChatColorNamesByClassGroup(true, "CHANNEL10")
  140. ToggleChatColorNamesByClassGroup(true, "CHANNEL11")
  141.  
  142. local type = type
  143. local select = select
  144. local unpack = unpack
  145. local tostring = tostring
  146. local concat = table.concat
  147. local find = string.find
  148.  
  149. local gsub = string.gsub
  150. local format = string.format
  151.  
  152.  
  153. CHAT_FRAME_TAB_SELECTED_MOUSEOVER_ALPHA = 1
  154. CHAT_FRAME_TAB_SELECTED_NOMOUSE_ALPHA = 0
  155.  
  156. CHAT_FRAME_TAB_NORMAL_MOUSEOVER_ALPHA = 0.5
  157. CHAT_FRAME_TAB_NORMAL_NOMOUSE_ALPHA = 0
  158.  
  159.  
  160. CHAT_FONT_HEIGHTS = {
  161. [1] = 8,
  162. [2] = 9,
  163. [3] = 10,
  164. [4] = 11,
  165. [5] = 12,
  166. [6] = 13,
  167. [7] = 14,
  168. [8] = 15,
  169. [9] = 16,
  170. [10] = 17,
  171. [11] = 18,
  172. [12] = 19,
  173. [13] = 20,
  174. }
  175.  
  176.  
  177. CHAT_FLAG_AFK = '[AFK] '
  178. CHAT_FLAG_DND = '[DND] '
  179. CHAT_FLAG_GM = '[GM] '
  180.  
  181. CHAT_GUILD_GET = '(|Hchannel:Guild|hG|h) %s:\32'
  182. CHAT_OFFICER_GET = '(|Hchannel:o|hO|h) %s:\32'
  183.  
  184. CHAT_PARTY_GET = '(|Hchannel:party|hP|h) %s:\32'
  185. CHAT_PARTY_LEADER_GET = '(|Hchannel:party|hPL|h) %s:\32'
  186. CHAT_PARTY_GUIDE_GET = '(|Hchannel:party|hDG|h) %s:\32'
  187. CHAT_MONSTER_PARTY_GET = '(|Hchannel:raid|hR|h) %s:\32'
  188.  
  189. CHAT_RAID_GET = '(|Hchannel:raid|hR|h) %s:\32'
  190. CHAT_RAID_WARNING_GET = '(RW!) %s:\32'
  191. CHAT_RAID_LEADER_GET = '(|Hchannel:raid|hL|h) %s:\32'
  192.  
  193. CHAT_BATTLEGROUND_GET = '(|Hchannel:Battleground|hBG|h) %s:\32'
  194. CHAT_BATTLEGROUND_LEADER_GET = '(|Hchannel:Battleground|hBL|h) %s:\32'
  195.  
  196. CHAT_INSTANCE_CHAT_GET = '|Hchannel:INSTANCE_CHAT|h[I]|h %s:\32';
  197. CHAT_INSTANCE_CHAT_LEADER_GET = '|Hchannel:INSTANCE_CHAT|h[IL]|h %s:\32';
  198.  
  199.  
  200. local channelFormat
  201. do
  202. local a, b = '.*%[(.*)%].*', '%%[%1%%]'
  203. channelFormat = {
  204. [1] = {gsub(CHAT_BATTLEGROUND_GET, a, b), '[BG]'},
  205. [2] = {gsub(CHAT_BATTLEGROUND_LEADER_GET, a, b), '[BGL]'},
  206.  
  207. [3] = {gsub(CHAT_GUILD_GET, a, b), '[G]'},
  208. [4] = {gsub(CHAT_OFFICER_GET, a, b), '[O]'},
  209.  
  210. [5] = {gsub(CHAT_PARTY_GET, a, b), '[P]'},
  211. [6] = {gsub(CHAT_PARTY_LEADER_GET, a, b), '[PL]'},
  212. [7] = {gsub(CHAT_PARTY_GUIDE_GET, a, b), '[PL]'},
  213.  
  214. [8] = {gsub(CHAT_RAID_GET, a, b), '[R]'},
  215. [9] = {gsub(CHAT_RAID_LEADER_GET, a, b), '[RL]'},
  216. [10] = {gsub(CHAT_RAID_WARNING_GET, a, b), '[RW]'},
  217.  
  218. [11] = {gsub(CHAT_FLAG_AFK, a, b), '[AFK] '},
  219. [12] = {gsub(CHAT_FLAG_DND, a, b), '[DND] '},
  220. [13] = {gsub(CHAT_FLAG_GM, a, b), '[GM] '},
  221. }
  222. end
  223.  
  224.  
  225. local AddMessage = ChatFrame1.AddMessage
  226. local function FCF_AddMessage(self, text, ...)
  227. if (type(text) == 'string') then
  228. text = gsub(text, '(|HBNplayer.-|h)%[(.-)%]|h', '%1%2|h')
  229. text = gsub(text, '(|Hplayer.-|h)%[(.-)%]|h', '%1%2|h')
  230. text = gsub(text, '%[(%d0?)%. (.-)%]', '[%1]')
  231.  
  232.  
  233. for i = 1, #channelFormat do
  234. text = gsub(text, channelFormat[i][1], channelFormat[i][2])
  235. end
  236.  
  237. end
  238.  
  239. return AddMessage(self, text, ...)
  240. end
  241.  
  242. -- Modify the editbox
  243.  
  244. for k = 6, 11 do
  245. select(k, ChatFrame1EditBox:GetRegions()):SetTexture(nil)
  246. end
  247.  
  248. ChatFrame1EditBox:SetAltArrowKeyMode(false)
  249. ChatFrame1EditBox:ClearAllPoints()
  250. ChatFrame1EditBox:SetFont(ADDON_NAME.db.profile.media.fontNormal, ADDON_NAME.db.profile.media.fontSize)
  251. ChatFrame1EditBox:SetPoint('BOTTOMLEFT', ChatFrame1, 'TOPLEFT', 2, 33)
  252. ChatFrame1EditBox:SetPoint('BOTTOMRIGHT', ChatFrame1, 'TOPRIGHT', 0, 33)
  253. ChatFrame1EditBox:SetBackdrop({
  254. bgFile = db.editboxbackground,
  255. edgeFile = db.editboxborder,
  256. tile = true, tileSize = 16, edgeSize = 18,
  257. insets = {left = 3, right = 3, top = 2, bottom = 3},
  258. })
  259.  
  260.  
  261. ChatFrame1EditBox:SetBackdropColor(0, 0, 0, 0.5)
  262.  
  263.  
  264. -- Hide the menu and friend button
  265.  
  266. FriendsMicroButton:SetAlpha(0)
  267. FriendsMicroButton:EnableMouse(false)
  268. FriendsMicroButton:UnregisterAllEvents()
  269.  
  270. ChatFrameMenuButton:SetAlpha(0)
  271. ChatFrameMenuButton:EnableMouse(false)
  272.  
  273. -- Tab text colors for the tabs
  274.  
  275. hooksecurefunc('FCFTab_UpdateColors', function(self, selected)
  276. if (selected) then
  277. self:GetFontString():SetTextColor(0, 0.75, 1)
  278. else
  279. self:GetFontString():SetTextColor(1, 1, 1)
  280. end
  281. end)
  282.  
  283. -- Tab text fadeout
  284.  
  285. local origFCF_FadeOutChatFrame = FCF_FadeOutChatFrame
  286. local function FCF_FadeOutChatFrameHook(chatFrame)
  287. origFCF_FadeOutChatFrame(chatFrame)
  288.  
  289. local frameName = chatFrame:GetName()
  290. local chatTab = _G[frameName..'Tab']
  291. local tabGlow = _G[frameName..'TabGlow']
  292.  
  293. if (not tabGlow:IsShown()) then
  294. if (frameName.isDocked) then
  295. securecall('UIFrameFadeOut', chatTab, CHAT_FRAME_FADE_OUT_TIME, chatTab:GetAlpha(), CHAT_FRAME_TAB_NORMAL_NOMOUSE_ALPHA)
  296. else
  297. securecall('UIFrameFadeOut', chatTab, CHAT_FRAME_FADE_OUT_TIME, chatTab:GetAlpha(), CHAT_FRAME_TAB_NORMAL_NOMOUSE_ALPHA)
  298. end
  299. end
  300. end
  301. FCF_FadeOutChatFrame = FCF_FadeOutChatFrameHook
  302.  
  303. -- Improve mousewheel scrolling
  304.  
  305. hooksecurefunc('FloatingChatFrame_OnMouseScroll', function(self, direction)
  306. if (direction > 0) then
  307. if (IsShiftKeyDown()) then
  308. self:ScrollToTop()
  309. else
  310. self:ScrollUp()
  311. self:ScrollUp()
  312. end
  313. elseif (direction < 0) then
  314. if (IsShiftKeyDown()) then
  315. self:ScrollToBottom()
  316. else
  317. self:ScrollDown()
  318. self:ScrollDown()
  319. end
  320. end
  321.  
  322. if (db.enableBottomButton) then
  323. local buttonBottom = _G[self:GetName() .. 'ButtonFrameBottomButton']
  324. if (self:AtBottom()) then
  325. buttonBottom:SetAlpha(0)
  326. buttonBottom:EnableMouse(false)
  327. else
  328. buttonBottom:SetAlpha(0.7)
  329. buttonBottom:EnableMouse(true)
  330. end
  331. end
  332. end)
  333.  
  334. -- Reposit toast frame
  335.  
  336. BNToastFrame:HookScript('OnShow', function(self)
  337. BNToastFrame:ClearAllPoints()
  338. BNToastFrame:SetPoint('BOTTOMLEFT', ChatFrame1EditBox, 'TOPLEFT', 0, 15)
  339. end)
  340.  
  341. -- Modify the chat tabs
  342.  
  343. function SkinTab(self)
  344. local chat = _G[self]
  345.  
  346. local tab = _G[self..'Tab']
  347. for i = 1, select('#', tab:GetRegions()) do
  348. local texture = select(i, tab:GetRegions())
  349. if (texture and texture:GetObjectType() == 'Texture') then
  350. texture:SetTexture(nil)
  351. end
  352. end
  353.  
  354. local tabText = _G[self..'TabText']
  355. tabText:SetJustifyH('CENTER')
  356. tabText:SetWidth(60)
  357. if (db.tab.fontOutline) then
  358. tabText:SetFont(ADDON_NAME.db.profile.media.fontBold, ADDON_NAME.db.profile.media.fontSize, 'THINOUTLINE')
  359. tabText:SetShadowOffset(0, 0)
  360. else
  361. tabText:SetFont(ADDON_NAME.db.profile.media.fontBold, db.fontLarge)
  362. tabText:SetShadowOffset(1, -1)
  363. end
  364.  
  365. local a1, a2, a3, a4, a5 = tabText:GetPoint()
  366. tabText:SetPoint(a1, a2, a3, a4, 1)
  367.  
  368. local s1, s2, s3 = db.tab.specialColor.r, db.tab.specialColor.g, db.tab.specialColor.b
  369. local e1, e2, e3 = db.tab.selectedColor.r, db.tab.selectedColor.g, db.tab.selectedColor.b
  370. local n1, n2, n3 = db.tab.normalColor.r, db.tab.normalColor.g, db.tab.normalColor.b
  371.  
  372. local tabGlow = _G[self..'TabGlow']
  373. hooksecurefunc(tabGlow, 'Show', function()
  374. tabText:SetTextColor(s1, s2, s3, CHAT_FRAME_TAB_NORMAL_MOUSEOVER_ALPHA)
  375. end)
  376.  
  377. hooksecurefunc(tabGlow, 'Hide', function()
  378. tabText:SetTextColor(n1, n2, n3)
  379. end)
  380.  
  381. tab:SetScript('OnEnter', function()
  382. tabText:SetTextColor(s1, s2, s3, tabText:GetAlpha())
  383. end)
  384.  
  385. tab:SetScript('OnLeave', function()
  386. local hasNofication = tabGlow:IsShown()
  387.  
  388. local r, g, b
  389. if (_G[self] == SELECTED_CHAT_FRAME and chat.isDocked) then
  390. r, g, b = e1, e2, e3
  391. elseif (hasNofication) then
  392. r, g, b = s1, s2, s3
  393. else
  394. r, g, b = n1, n2, n3
  395. end
  396.  
  397. tabText:SetTextColor(r, g, b)
  398. end)
  399.  
  400. hooksecurefunc(tab, 'Show', function()
  401. if (not tab.wasShown) then
  402. local hasNofication = tabGlow:IsShown()
  403.  
  404. if (chat:IsMouseOver()) then
  405. tab:SetAlpha(CHAT_FRAME_TAB_NORMAL_MOUSEOVER_ALPHA)
  406. else
  407. tab:SetAlpha(CHAT_FRAME_TAB_NORMAL_NOMOUSE_ALPHA)
  408. end
  409.  
  410. local r, g, b
  411. if (_G[self] == SELECTED_CHAT_FRAME and chat.isDocked) then
  412. r, g, b = e1, e2, e3
  413. elseif (hasNofication) then
  414. r, g, b = s1, s2, s3
  415. else
  416. r, g, b = n1, n2, n3
  417. end
  418.  
  419. tabText:SetTextColor(r, g, b)
  420.  
  421. tab.wasShown = true
  422. end
  423. end)
  424. end
  425.  
  426. local function ModChat(self)
  427. local chat = _G[self]
  428.  
  429. if (not dbOutline) then
  430. chat:SetShadowOffset(1, -1)
  431. end
  432.  
  433. if (db.disableFade) then
  434. chat:SetFading(false)
  435. end
  436.  
  437. SkinTab(self)
  438.  
  439. local font, fontsize, fontflags = chat:GetFont()
  440. chat:SetFont(ADDON_NAME.db.profile.media.fontNormal, fontsize, dbOutline and 'THINOUTLINE' or fontflags)
  441. chat:SetClampedToScreen(false)
  442.  
  443. chat:SetClampRectInsets(0, 0, 0, 0)
  444. chat:SetMaxResize(UIParent:GetWidth(), UIParent:GetHeight())
  445. chat:SetMinResize(150, 25)
  446.  
  447. if (self ~= 'ChatFrame2') then
  448. chat.AddMessage = FCF_AddMessage
  449. end
  450.  
  451. local buttonUp = _G[self..'ButtonFrameUpButton']
  452. buttonUp:SetAlpha(0)
  453. buttonUp:EnableMouse(false)
  454.  
  455. local buttonDown = _G[self..'ButtonFrameDownButton']
  456. buttonDown:SetAlpha(0)
  457. buttonDown:EnableMouse(false)
  458.  
  459. local buttonBottom = _G[self..'ButtonFrameBottomButton']
  460. buttonBottom:SetAlpha(0)
  461. buttonBottom:EnableMouse(false)
  462.  
  463.  
  464. for _, texture in pairs({
  465. 'ButtonFrameBackground',
  466. 'ButtonFrameTopLeftTexture',
  467. 'ButtonFrameBottomLeftTexture',
  468. 'ButtonFrameTopRightTexture',
  469. 'ButtonFrameBottomRightTexture',
  470. 'ButtonFrameLeftTexture',
  471. 'ButtonFrameRightTexture',
  472. 'ButtonFrameBottomTexture',
  473. 'ButtonFrameTopTexture',
  474. }) do
  475. _G[self..texture]:SetTexture(nil)
  476. end
  477. end
  478.  
  479. local function SetChatStyle()
  480. for _, v in pairs(CHAT_FRAMES) do
  481. local chat = _G[v]
  482. if (chat and not chat.hasModification) then
  483. ModChat(chat:GetName())
  484.  
  485. local convButton = _G[chat:GetName()..'ConversationButton']
  486. if (convButton) then
  487. convButton:SetAlpha(0)
  488. convButton:EnableMouse(false)
  489. end
  490.  
  491. local chatMinimize = _G[chat:GetName()..'ButtonFrameMinimizeButton']
  492. if (chatMinimize) then
  493. chatMinimize:SetAlpha(0)
  494. chatMinimize:EnableMouse(0)
  495. end
  496.  
  497. chat.hasModification = true
  498. end
  499. end
  500. end
  501. hooksecurefunc('FCF_OpenTemporaryWindow', SetChatStyle)
  502. SetChatStyle()
  503.  
  504. -- Chat menu, just a middle click on the chatframe 1 tab
  505.  
  506. hooksecurefunc('ChatFrameMenu_UpdateAnchorPoint', function()
  507. if (FCF_GetButtonSide(DEFAULT_CHAT_FRAME) == 'right') then
  508. ChatMenu:ClearAllPoints()
  509. ChatMenu:SetPoint('BOTTOMRIGHT', ChatFrame1Tab, 'TOPLEFT')
  510. else
  511. ChatMenu:ClearAllPoints()
  512. ChatMenu:SetPoint('BOTTOMLEFT', ChatFrame1Tab, 'TOPRIGHT')
  513. end
  514. end)
  515.  
  516. ChatFrame1Tab:RegisterForClicks('AnyUp')
  517. ChatFrame1Tab:HookScript('OnClick', function(self, button)
  518. if (button == 'MiddleButton' or button == 'Button4' or button == 'Button5') then
  519. if (ChatMenu:IsShown()) then
  520. ChatMenu:Hide()
  521. else
  522. ChatMenu:Show()
  523. end
  524. else
  525. ChatMenu:Hide()
  526. end
  527. end)
  528.  
  529. -- Modify the gm chatframe and add a sound notification on incoming whispers
  530.  
  531. local f = CreateFrame('Frame')
  532. f:RegisterEvent('ADDON_LOADED')
  533. f:RegisterEvent('CHAT_MSG_WHISPER')
  534. f:RegisterEvent('CHAT_MSG_BN_WHISPER')
  535. f:SetScript('OnEvent', function(_, event)
  536. if (event == 'ADDON_LOADED' and arg1 == 'Blizzard_GMChatUI') then
  537. GMChatFrame:EnableMouseWheel(true)
  538. GMChatFrame:SetScript('OnMouseWheel', ChatFrame1:GetScript('OnMouseWheel'))
  539. GMChatFrame:SetHeight(200)
  540.  
  541. GMChatFrameUpButton:SetAlpha(0)
  542. GMChatFrameUpButton:EnableMouse(false)
  543.  
  544. GMChatFrameDownButton:SetAlpha(0)
  545. GMChatFrameDownButton:EnableMouse(false)
  546.  
  547. GMChatFrameBottomButton:SetAlpha(0)
  548. GMChatFrameBottomButton:EnableMouse(false)
  549. end
  550.  
  551. if (event == 'CHAT_MSG_WHISPER' or event == 'CHAT_MSG_BN_WHISPER') then
  552. PlaySoundFile(db.sound)
  553. end
  554. end)
  555.  
  556. local combatLog = {
  557. text = 'CombatLog',
  558. colorCode = '|cffFFD100',
  559. isNotRadio = true,
  560.  
  561. func = function()
  562. if (not LoggingCombat()) then
  563. LoggingCombat(true)
  564. DEFAULT_CHAT_FRAME:AddMessage(COMBATLOGENABLED, 1, 1, 0)
  565. else
  566. LoggingCombat(false)
  567. DEFAULT_CHAT_FRAME:AddMessage(COMBATLOGDISABLED, 1, 1, 0)
  568. end
  569. end,
  570.  
  571. checked = function()
  572. if (LoggingCombat()) then
  573. return true
  574. else
  575. return false
  576. end
  577. end
  578. }
  579.  
  580. local chatLog = {
  581. text = 'ChatLog',
  582. colorCode = '|cffFFD100',
  583. isNotRadio = true,
  584.  
  585. func = function()
  586. if (not LoggingChat()) then
  587. LoggingChat(true)
  588. DEFAULT_CHAT_FRAME:AddMessage(CHATLOGENABLED, 1, 1, 0)
  589. else
  590. LoggingChat(false)
  591. DEFAULT_CHAT_FRAME:AddMessage(CHATLOGDISABLED, 1, 1, 0)
  592. end
  593. end,
  594.  
  595. checked = function()
  596. if (LoggingChat()) then
  597. return true
  598. else
  599. return false
  600. end
  601. end
  602. }
  603.  
  604. local origFCF_Tab_OnClick = FCF_Tab_OnClick
  605. local function FCF_Tab_OnClickHook(chatTab, ...)
  606. origFCF_Tab_OnClick(chatTab, ...)
  607.  
  608. combatLog.arg1 = chatTab
  609. UIDropDownMenu_AddButton(combatLog)
  610.  
  611. chatLog.arg1 = chatTab
  612. UIDropDownMenu_AddButton(chatLog)
  613. end
  614. FCF_Tab_OnClick = FCF_Tab_OnClickHook
  615.  
  616.  
  617. -- Chat Copy
  618.  
  619. local f = CreateFrame('Frame', nil, UIParent)
  620. f:SetHeight(220)
  621. f:SetBackdropColor(0, 0, 0, 1)
  622. f:SetPoint('BOTTOMLEFT', ChatFrame1EditBox, 'TOPLEFT', 3, 10)
  623. f:SetPoint('BOTTOMRIGHT', ChatFrame1EditBox, 'TOPRIGHT', -3, 10)
  624. f:SetFrameStrata('DIALOG')
  625. f:SetBackdrop({
  626. bgFile = db.background,
  627. edgeFile = db.border,
  628. tile = true, tileSize = 16, edgeSize = 18,
  629. insets = {left = 3, right = 3, top = 3, bottom = 3
  630. }})
  631. f:SetBackdropBorderColor(classColor.r, classColor.g, classColor.b)
  632. f:Hide()
  633.  
  634. f.t = f:CreateFontString(nil, 'OVERLAY')
  635. f.t:SetFont(ADDON_NAME.db.profile.media.fontNormal, ADDON_NAME.db.profile.media.fontSize)
  636. f.t:SetPoint('TOPLEFT', f, 8, -8)
  637. f.t:SetTextColor(1, 1, 0)
  638. f.t:SetShadowOffset(1, -1)
  639. f.t:SetJustifyH('LEFT')
  640.  
  641. f.b = CreateFrame('EditBox', nil, f)
  642. f.b:SetMultiLine(true)
  643. f.b:SetMaxLetters(20000)
  644. f.b:SetSize(450, 270)
  645. f.b:SetScript('OnEscapePressed', function()
  646. f:Hide()
  647. end)
  648.  
  649. f.s = CreateFrame('ScrollFrame', '$parentScrollBar', f, 'UIPanelScrollFrameTemplate')
  650. f.s:SetPoint('TOPLEFT', f, 'TOPLEFT', 8, -30)
  651. f.s:SetPoint('BOTTOMRIGHT', f, 'BOTTOMRIGHT', -30, 8)
  652. f.s:SetScrollChild(f.b)
  653.  
  654. f.c = CreateFrame('Button', nil, f, 'UIPanelCloseButton')
  655. f.c:SetPoint('TOPRIGHT', f, 'TOPRIGHT', 0, -1)
  656.  
  657. local lines = {}
  658. local function GetChatLines(...)
  659. local count = 1
  660. for i = select('#', ...), 1, -1 do
  661. local region = select(i, ...)
  662. if (region:GetObjectType() == 'FontString') then
  663. lines[count] = tostring(region:GetText())
  664. count = count + 1
  665. end
  666. end
  667.  
  668. return count - 1
  669. end
  670.  
  671. local function copyChat(self)
  672. local chat = _G[self:GetName()]
  673. local _, fontSize = chat:GetFont()
  674.  
  675. FCF_SetChatWindowFontSize(self, chat, 0.1)
  676. local lineCount = GetChatLines(chat:GetRegions())
  677. FCF_SetChatWindowFontSize(self, chat, fontSize)
  678.  
  679. if (lineCount > 0) then
  680. ToggleFrame(f)
  681. f.t:SetText(chat:GetName())
  682.  
  683. local f1, f2, f3 = ChatFrame1:GetFont()
  684. f.b:SetFont(f1, f2, f3)
  685.  
  686. local text = concat(lines, '\n', 1, lineCount)
  687. f.b:SetText(text)
  688. end
  689. end
  690.  
  691. local function CreateCopyButton(self)
  692. self.Copy = CreateFrame('Button', nil, _G[self:GetName()])
  693. self.Copy:SetSize(20, 20)
  694. self.Copy:SetPoint('TOPRIGHT', self, -5, -5)
  695.  
  696. self.Copy:SetNormalTexture'Interface\\AddOns\\BasicUI\\Media\\textureCopyNormal'
  697. self.Copy:GetNormalTexture():SetSize(20, 20)
  698.  
  699. self.Copy:SetHighlightTexture'Interface\\AddOns\\BasicUI\\Media\\textureCopyHighlight'
  700. self.Copy:GetHighlightTexture():SetAllPoints(self.Copy:GetNormalTexture())
  701.  
  702. local tab = _G[self:GetName()..'Tab']
  703. hooksecurefunc(tab, 'SetAlpha', function()
  704. self.Copy:SetAlpha(tab:GetAlpha()*0.55)
  705. end)
  706.  
  707. self.Copy:SetScript('OnMouseDown', function(self)
  708. self:GetNormalTexture():ClearAllPoints()
  709. self:GetNormalTexture():SetPoint('CENTER', 1, -1)
  710. end)
  711.  
  712. self.Copy:SetScript('OnMouseUp', function()
  713. self.Copy:GetNormalTexture():ClearAllPoints()
  714. self.Copy:GetNormalTexture():SetPoint('CENTER')
  715.  
  716. if (self.Copy:IsMouseOver()) then
  717. copyChat(self)
  718. end
  719. end)
  720. end
  721.  
  722. local function EnableCopyButton()
  723. for _, v in pairs(CHAT_FRAMES) do
  724. local chat = _G[v]
  725. if (chat and not chat.Copy) then
  726. CreateCopyButton(chat)
  727. end
  728. end
  729. end
  730. hooksecurefunc('FCF_OpenTemporaryWindow', EnableCopyButton)
  731. EnableCopyButton()
  732.  
  733. -- Copy URL
  734.  
  735. local urlStyle = '|cffff00ff|Hurl:%1|h%1|h|r'
  736. local urlPatterns = {
  737. '(http://%S+)', -- http://xxx.com
  738. '(www%.%S+)', -- www.xxx.com/site/index.php
  739. '(%d+%.%d+%.%d+%.%d+:?%d*)', -- 192.168.1.1 / 192.168.1.1:1110
  740. }
  741.  
  742. local messageTypes = {
  743. 'CHAT_MSG_CHANNEL',
  744. 'CHAT_MSG_GUILD',
  745. 'CHAT_MSG_PARTY',
  746. 'CHAT_MSG_RAID',
  747. 'CHAT_MSG_SAY',
  748. 'CHAT_MSG_WHISPER',
  749. }
  750.  
  751. local function urlFilter(self, event, text, ...)
  752. for _, pattern in ipairs(urlPatterns) do
  753. local result, matches = gsub(text, pattern, urlStyle)
  754.  
  755. if (matches > 0) then
  756. return false, result, ...
  757. end
  758. end
  759. end
  760.  
  761. for _, event in ipairs(messageTypes) do
  762. ChatFrame_AddMessageEventFilter(event, urlFilter)
  763. end
  764.  
  765. local origSetItemRef = SetItemRef
  766. local currentLink
  767. local SetItemRefHook = function(link, text, button)
  768. if (link:sub(0, 3) == 'url') then
  769. currentLink = link:sub(5)
  770. StaticPopup_Show('UrlCopyDialog')
  771. return
  772. end
  773.  
  774. return origSetItemRef(link, text, button)
  775. end
  776.  
  777. SetItemRef = SetItemRefHook
  778.  
  779. StaticPopupDialogs['UrlCopyDialog'] = {
  780. text = 'URL',
  781. button2 = CLOSE,
  782. hasEditBox = 1,
  783. editBoxWidth = 250,
  784.  
  785. OnShow = function(frame)
  786. local editBox = _G[frame:GetName()..'EditBox']
  787. if (editBox) then
  788. editBox:SetText(currentLink)
  789. editBox:SetFocus()
  790. editBox:HighlightText(0)
  791. end
  792.  
  793. local button = _G[frame:GetName()..'Button2']
  794. if (button) then
  795. button:ClearAllPoints()
  796. button:SetWidth(100)
  797. button:SetPoint('CENTER', editBox, 'CENTER', 0, -30)
  798. end
  799. end,
  800.  
  801. EditBoxOnEscapePressed = function(frame)
  802. frame:GetParent():Hide()
  803. end,
  804.  
  805. timeout = 0,
  806. whileDead = 1,
  807. hideOnEscape = 1,
  808. maxLetters = 1024,
  809. }
  810. self:Refresh()
  811. end
  812.  
  813. function MODULE:Refresh()
  814.  
  815. if (db.enableBorderColoring) then
  816. hooksecurefunc('ChatEdit_UpdateHeader', function(editBox)
  817. local type = editBox:GetAttribute('chatType')
  818. if (not type) then
  819. return
  820. end
  821.  
  822. local info = ChatTypeInfo[type]
  823. ChatFrame1EditBox:SetBackdropBorderColor(info.r, info.g, info.b)
  824. end)
  825. else return
  826. end
  827.  
  828. if (db.enableHyperlinkTooltip) then
  829.  
  830. --[[
  831.  
  832. All Create for hyperlink.lua goes to Neal, ballagarba, and Tuks.
  833. Neav UI = http://www.wowinterface.com/downloads/info13981-NeavUI.html.
  834. Tukui = http://www.tukui.org/download.php.
  835. Edited by Cokedriver.
  836.  
  837. ]]
  838.  
  839. local _G = getfenv(0)
  840. local orig1, orig2 = {}, {}
  841. local GameTooltip = GameTooltip
  842.  
  843. local linktypes = {
  844. item = true,
  845. enchant = true,
  846. spell = true,
  847. quest = true,
  848. unit = true,
  849. talent = true,
  850. achievement = true,
  851. glyph = true
  852. }
  853.  
  854. local function OnHyperlinkEnter(frame, link, ...)
  855. local linktype = link:match('^([^:]+)')
  856. if (linktype and linktypes[linktype]) then
  857. GameTooltip:SetOwner(ChatFrame1, 'ANCHOR_CURSOR', 0, 20)
  858. GameTooltip:SetHyperlink(link)
  859. GameTooltip:Show()
  860. else
  861. GameTooltip:Hide()
  862. end
  863.  
  864. if (orig1[frame]) then
  865. return orig1[frame](frame, link, ...)
  866. end
  867. end
  868.  
  869. local function OnHyperlinkLeave(frame, ...)
  870. GameTooltip:Hide()
  871.  
  872. if (orig2[frame]) then
  873. return orig2[frame](frame, ...)
  874. end
  875. end
  876.  
  877. local function EnableItemLinkTooltip()
  878. for _, v in pairs(CHAT_FRAMES) do
  879. local chat = _G[v]
  880. if (chat and not chat.URLCopy) then
  881. orig1[chat] = chat:GetScript('OnHyperlinkEnter')
  882. chat:SetScript('OnHyperlinkEnter', OnHyperlinkEnter)
  883.  
  884. orig2[chat] = chat:GetScript('OnHyperlinkLeave')
  885. chat:SetScript('OnHyperlinkLeave', OnHyperlinkLeave)
  886. chat.URLCopy = true
  887. end
  888. end
  889. end
  890. hooksecurefunc('FCF_OpenTemporaryWindow', EnableItemLinkTooltip)
  891. EnableItemLinkTooltip()
  892. else
  893. return
  894. end
  895.  
  896. if (db.windowborder) then
  897. for i = 1, NUM_CHAT_WINDOWS do
  898. local cf = _G['ChatFrame'..i]
  899. local bg = CreateFrame("Frame", nil, cf);
  900. bg:SetFrameStrata("BACKGROUND");
  901.  
  902. if i == 2 then
  903. bg:SetPoint("TOPLEFT", -8, 32);
  904. else
  905. bg:SetPoint("TOPLEFT", -8, 8);
  906. end
  907. bg:SetPoint("BOTTOMRIGHT", 8, -12);
  908. bg:SetBackdrop({
  909. edgeFile = db.border,
  910. tile = true, tileSize = 16, edgeSize = 18,
  911. })
  912. bg:SetBackdropBorderColor(classColor.r, classColor.g, classColor.b)
  913. end
  914. else
  915. return
  916. end
  917. end
  918. ------------------------------------------------------------------------
  919. -- Module options
  920. ------------------------------------------------------------------------
  921.  
  922. local options
  923. function MODULE:GetOptions()
  924. if options then
  925. return options
  926. end
  927.  
  928. local function isModuleDisabled()
  929. return not ADDON_NAME:GetModuleEnabled(MODULE_NAME)
  930. end
  931.  
  932. options = {
  933. type = "group",
  934. name = L[MODULE_NAME],
  935. get = function(info) return db[ info[#info] ] end,
  936. set = function(info, value) db[ info[#info] ] = value; self:Refresh() end,
  937. disabled = isModuleDisabled(),
  938. args = {
  939. ---------------------------
  940. --Option Type Seperators
  941. sep1 = {
  942. type = "description",
  943. order = 2,
  944. name = " ",
  945. },
  946. sep2 = {
  947. type = "description",
  948. order = 3,
  949. name = " ",
  950. },
  951. sep3 = {
  952. type = "description",
  953. order = 4,
  954. name = " ",
  955. },
  956. sep4 = {
  957. type = "description",
  958. order = 5,
  959. name = " ",
  960. },
  961. ---------------------------
  962. reloadUI = {
  963. type = "execute",
  964. name = "Reload UI",
  965. desc = " ",
  966. order = 0,
  967. func = function()
  968. ReloadUI()
  969. end,
  970. },
  971. Text = {
  972. type = "description",
  973. order = 0,
  974. name = "When changes are made a reload of the UI is needed.",
  975. width = "full",
  976. },
  977. Text1 = {
  978. type = "description",
  979. order = 1,
  980. name = " ",
  981. width = "full",
  982. },
  983. enable = {
  984. type = "toggle",
  985. order = 1,
  986. name = L["Enable Chat Module"],
  987. width = "full",
  988. disabled = false,
  989. },
  990. windowborder = {
  991. type = "toggle",
  992. order = 2,
  993. name = L["Window Border"],
  994. desc = L["Enables Chat Window Border."],
  995. disabled = function() return isModuleDisabled() or not db.enable end,
  996. },
  997. disableFade = {
  998. type = "toggle",
  999. order = 2,
  1000. name = L["Disable Fade"],
  1001. desc = L["Disables Chat Fading."],
  1002. disabled = function() return isModuleDisabled() or not db.enable end,
  1003. },
  1004. chatOutline = {
  1005. type = "toggle",
  1006. order = 2,
  1007. name = L["Chat Outline"],
  1008. desc = L["Outlines the chat Text."],
  1009. disabled = function() return isModuleDisabled() or not db.enable end,
  1010. },
  1011. enableHyperlinkTooltip = {
  1012. type = "toggle",
  1013. order = 2,
  1014. name = L["Enable Hyplerlink Tooltip"],
  1015. desc = L["Enables the mouseover items in chat tooltip."],
  1016. disabled = function() return isModuleDisabled() or not db.enable end,
  1017. },
  1018. enableBorderColoring = {
  1019. type = "toggle",
  1020. order = 2,
  1021. name = L["Enable Editbox Channel Border Coloring"],
  1022. desc = L["Enables the coloring of the border to the edit box to match what channel you are typing in."],
  1023. disabled = function() return isModuleDisabled() or not db.enable end,
  1024. },
  1025. tab = {
  1026. type = "group",
  1027. order = 6,
  1028. name = L["Tabs"],
  1029. desc = L["Tab Font Settings."],
  1030. guiInline = true,
  1031. disabled = function() return isModuleDisabled() or not db.enable end,
  1032. get = function(info) return db.tab[ info[#info] ] end,
  1033. set = function(info, value) db.tab[ info[#info] ] = value; end,
  1034. args = {
  1035. ---------------------------
  1036. --Option Type Seperators
  1037. sep1 = {
  1038. type = "description",
  1039. order = 2,
  1040. name = " ",
  1041. },
  1042. sep2 = {
  1043. type = "description",
  1044. order = 3,
  1045. name = " ",
  1046. },
  1047. sep3 = {
  1048. type = "description",
  1049. order = 4,
  1050. name = " ",
  1051. },
  1052. sep4 = {
  1053. type = "description",
  1054. order = 5,
  1055. name = " ",
  1056. },
  1057. ---------------------------
  1058. fontSize = {
  1059. type = "range",
  1060. order = 5,
  1061. name = L["Tab Font Size"],
  1062. desc = L["Controls the size of the tab font"],
  1063. type = "range",
  1064. min = 9, max = 20, step = 1,
  1065. disabled = function() return isModuleDisabled() or not db.enable end,
  1066. },
  1067. fontOutline = {
  1068. type = "toggle",
  1069. order = 2,
  1070. name = L["Outline Tab Font"],
  1071. desc = L["Enables the outlineing of tab font."],
  1072. disabled = function() return isModuleDisabled() or not db.enable end,
  1073. },
  1074. normalColor = {
  1075. type = "color",
  1076. order = 4,
  1077. name = L["Tab Normal Color"],
  1078. desc = L["Picks the Normal Color of the Chat Tab."],
  1079. hasAlpha = false,
  1080. disabled = function() return isModuleDisabled() or not db.enable end,
  1081. get = function(info)
  1082. local hb = db.tab[ info[#info] ]
  1083. return hb.r, hb.g, hb.b
  1084. end,
  1085. set = function(info, r, g, b)
  1086. db.tab[ info[#info] ] = {}
  1087. local hb = db.tab[ info[#info] ]
  1088. hb.r, hb.g, hb.b = r, g, b
  1089. StaticPopup_Show("BASICUI_CFG_RELOAD")
  1090. end,
  1091. },
  1092. specialColor = {
  1093. type = "color",
  1094. order = 4,
  1095. name = L["Tab Special Color"],
  1096. desc = L["Picks the Special Color of the Chat Tab."],
  1097. hasAlpha = false,
  1098. disabled = function() return isModuleDisabled() or not db.enable end,
  1099. get = function(info)
  1100. local hb = db.tab[ info[#info] ]
  1101. return hb.r, hb.g, hb.b
  1102. end,
  1103. set = function(info, r, g, b)
  1104. db.tab[ info[#info] ] = {}
  1105. local hb = db.tab[ info[#info] ]
  1106. hb.r, hb.g, hb.b = r, g, b
  1107. StaticPopup_Show("BASICUI_CFG_RELOAD")
  1108. end,
  1109. },
  1110. selectedColor = {
  1111. type = "color",
  1112. order = 4,
  1113. name = L["Tab Selected Color"],
  1114. desc = L["Picks the Selected Color of the Chat Tab."],
  1115. hasAlpha = false,
  1116. disabled = function() return isModuleDisabled() or not db.enable end,
  1117. get = function(info)
  1118. local hb = db.tab[ info[#info] ]
  1119. return hb.r, hb.g, hb.b
  1120. end,
  1121. set = function(info, r, g, b)
  1122. db.tab[ info[#info] ] = {}
  1123. local hb = db.tab[ info[#info] ]
  1124. hb.r, hb.g, hb.b = r, g, b
  1125. StaticPopup_Show("BASICUI_CFG_RELOAD")
  1126. end,
  1127. },
  1128. },
  1129. },
  1130. },
  1131. }
  1132. return options
  1133. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement