PageRenderTime 84ms CodeModel.GetById 40ms app.highlight 13ms RepoModel.GetById 27ms app.codeStats 1ms

/Tukui/modules/chat/chatframes.lua

http://github.com/Asphyxia/Tukui
Lua | 222 lines | 178 code | 34 blank | 10 comment | 28 complexity | 5785f11d6c99772be622fb260832d754 MD5 | raw file
  1
  2local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  3if C["chat"].enable ~= true then return end
  4
  5local TukuiChat = CreateFrame("Frame")
  6local _G = _G
  7local origs = {}
  8local type = type
  9local dummy = T.dummy
 10
 11-- move these to kill.lua when implemented
 12FriendsMicroButton:Kill()
 13ChatFrameMenuButton:Kill()
 14
 15-- function to rename channel and other stuff
 16local AddMessage = function(self, text, ...)
 17	if(type(text) == "string") then
 18		text = text:gsub('|h%[(%d+)%. .-%]|h', '|h[%1]|h')
 19	end
 20	return origs[self](self, text, ...)
 21end
 22
 23-- Shortcut channel name
 24_G.CHAT_BATTLEGROUND_GET = "|Hchannel:Battleground|h"..L.chat_BATTLEGROUND_GET.."|h %s:\32"
 25_G.CHAT_BATTLEGROUND_LEADER_GET = "|Hchannel:Battleground|h"..L.chat_BATTLEGROUND_LEADER_GET.."|h %s:\32"
 26_G.CHAT_BN_WHISPER_GET = L.chat_BN_WHISPER_GET.." %s:\32"
 27_G.CHAT_GUILD_GET = "|Hchannel:Guild|h"..L.chat_GUILD_GET.."|h %s:\32"
 28_G.CHAT_OFFICER_GET = "|Hchannel:o|h"..L.chat_OFFICER_GET.."|h %s:\32"
 29_G.CHAT_PARTY_GET = "|Hchannel:Party|h"..L.chat_PARTY_GET.."|h %s:\32"
 30_G.CHAT_PARTY_GUIDE_GET = "|Hchannel:party|h"..L.chat_PARTY_GUIDE_GET.."|h %s:\32"
 31_G.CHAT_PARTY_LEADER_GET = "|Hchannel:party|h"..L.chat_PARTY_LEADER_GET.."|h %s:\32"
 32_G.CHAT_RAID_GET = "|Hchannel:raid|h"..L.chat_RAID_GET.."|h %s:\32"
 33_G.CHAT_RAID_LEADER_GET = "|Hchannel:raid|h"..L.chat_RAID_LEADER_GET.."|h %s:\32"
 34_G.CHAT_RAID_WARNING_GET = L.chat_RAID_WARNING_GET.." %s:\32"
 35_G.CHAT_SAY_GET = "%s:\32"
 36_G.CHAT_WHISPER_GET = L.chat_WHISPER_GET.." %s:\32"
 37_G.CHAT_YELL_GET = "%s:\32"
 38 
 39-- color afk, dnd, gm
 40_G.CHAT_FLAG_AFK = "|cffFF0000"..L.chat_FLAG_AFK.."|r "
 41_G.CHAT_FLAG_DND = "|cffE7E716"..L.chat_FLAG_DND.."|r "
 42_G.CHAT_FLAG_GM = "|cff4154F5"..L.chat_FLAG_GM.."|r "
 43
 44-- customize online/offline msg
 45_G.ERR_FRIEND_ONLINE_SS = "|Hplayer:%s|h[%s]|h "..L.chat_ERR_FRIEND_ONLINE_SS.."!"
 46_G.ERR_FRIEND_OFFLINE_S = "%s "..L.chat_ERR_FRIEND_OFFLINE_S.."!"
 47
 48-- set the chat style
 49local function StyleChat(frame)
 50	local id = frame:GetID()
 51	local chat = frame:GetName()
 52	local tab = _G[chat.."Tab"]
 53	local tabtext = _G[chat.."TabText"]
 54	local editbox = _G[chat.."EditBox"]
 55	
 56	tab:SetAlpha(1)
 57	tab.SetAlpha = T.dummy
 58	tab:HookScript("OnClick", function() editbox:Hide() end)
 59	
 60	if C["chat"].background ~= true then
 61		tabtext:Hide()
 62		tab:HookScript("OnEnter", function() tabtext:Show() end)
 63		tab:HookScript("OnLeave", function() tabtext:Hide() end)
 64	end
 65
 66	tabtext:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
 67	if id < 11 then
 68		tabtext:SetTextColor(unpack(C["datatext"].color))
 69		tabtext.SetTextColor = T.dummy
 70	end
 71	tabtext:SetShadowOffset(0, 0)
 72	tabtext:ClearAllPoints()
 73	tabtext:Point("CENTER", tab, "CENTER", 0, -2)
 74	
 75	_G[chat]:SetFont(C.media.font, 12)
 76	_G[chat]:SetClampRectInsets(0,0,0,0)
 77	_G[chat]:SetClampedToScreen(false)
 78	_G[chat]:SetFading(false)
 79
 80	for j = 1, #CHAT_FRAME_TEXTURES do
 81		_G[chat..CHAT_FRAME_TEXTURES[j]]:SetTexture(nil)
 82	end
 83
 84	local textures = {
 85		"TabLeft", "TabMiddle", "TabRight", "TabSelectedLeft", "TabSelectedMiddle", "TabSelectedRight", "TabHighlightLeft",	
 86		"TabHighlightMiddle", "TabHighlightRight", "TabSelectedLeft", "TabSelectedMiddle", "TabSelectedRight", "ButtonFrameUpButton", 
 87		"ButtonFrameDownButton", "ButtonFrameBottomButton", "ButtonFrameMinimizeButton", "ButtonFrame",
 88		"EditBoxFocusLeft", "EditBoxFocusMid", "EditBoxFocusRight",
 89	}
 90	
 91	for i = 1, getn(textures) do
 92		_G[chat..textures[i]]:Kill()
 93	end
 94	
 95	local a, b, c = select(6, editbox:GetRegions()) a:Kill() b:Kill() c:Kill()
 96
 97	editbox:SetAltArrowKeyMode(false)
 98	editbox:Hide()
 99	editbox:HookScript("OnEditFocusLost", function(self) self:Hide() end)
100	editbox:ClearAllPoints()
101	editbox:Point("TOPLEFT", TukuiInfoLeft, 2, -2)
102	editbox:Point("BOTTOMRIGHT", TukuiInfoLeft, -2, 2)	
103	
104	local EditBoxBackground = CreateFrame("frame", "TukuiChatEditBoxBackground", editbox)
105	EditBoxBackground:CreatePanel("Default", 1, 1, "LEFT", editbox, "LEFT", 0, 0)
106	EditBoxBackground:ClearAllPoints()
107	EditBoxBackground:SetAllPoints(TukuiInfoLeft)
108	EditBoxBackground:SetFrameStrata("LOW")
109	EditBoxBackground:SetFrameLevel(1)
110
111	local function colorize(r,g,b)
112		EditBoxBackground:SetBackdropBorderColor(r, g, b)
113	end
114
115	-- update border color according where we talk
116	hooksecurefunc("ChatEdit_UpdateHeader", function()
117		local type = editbox:GetAttribute("chatType")
118		if ( type == "CHANNEL" ) then
119		local id = GetChannelName(editbox:GetAttribute("channelTarget"))
120			if id == 0 then
121				colorize(unpack(C["media"].bordercolor))
122			else
123				colorize(ChatTypeInfo[type..id].r,ChatTypeInfo[type..id].g,ChatTypeInfo[type..id].b)
124			end
125		else
126			colorize(ChatTypeInfo[type].r,ChatTypeInfo[type].g,ChatTypeInfo[type].b)
127		end
128	end)
129	
130	if _G[chat] ~= _G["ChatFrame2"] then
131		origs[_G[chat]] = _G[chat].AddMessage
132		_G[chat].AddMessage = AddMessage
133	end
134
135	frame.skinned = true
136end
137
138-- Setup chatframes 1 to 10 on login.
139local function SetupChat(self)	
140	for i = 1, NUM_CHAT_WINDOWS do
141		local chat = _G[format("ChatFrame%s", i)]
142		local id = chat:GetID()
143		local _, fontsize = FCF_GetChatWindowInfo(id)
144
145		FCF_SetChatWindowFontSize(nil, chat, fontsize)
146
147		StyleChat(chat)
148	end
149
150	-- Remember last channel
151	ChatTypeInfo.WHISPER.sticky = 1
152	ChatTypeInfo.BN_WHISPER.sticky = 1
153	ChatTypeInfo.OFFICER.sticky = 1
154	ChatTypeInfo.RAID_WARNING.sticky = 1
155	ChatTypeInfo.CHANNEL.sticky = 1
156end
157
158local function ChatPosition(self)
159	for i = 1, NUM_CHAT_WINDOWS do
160		local chat = _G[format("ChatFrame%s", i)]
161		
162		if i == 1 then
163			chat:ClearAllPoints()
164			chat:Point("TOPLEFT", TukuiTabsLeftBackground, "BOTTOMLEFT", 0, -4)
165			chat:Point("BOTTOMRIGHT", TukuiInfoLeft, "TOPRIGHT", 0, 4)
166		elseif i == 4 then
167			if C["chat"].rightchat == true then
168				if not chat.isDocked then
169					chat:ClearAllPoints()
170					chat:Point("TOPLEFT", TukuiTabsRightBackground, "BOTTOMLEFT", 0, -4)
171					chat:Point("BOTTOMRIGHT", TukuiInfoRight, "TOPRIGHT", 0, 4)
172				else
173					FCF_UnDockFrame(chat)
174					FCF_SetTabPosition(chat, 0)
175					
176					chat:ClearAllPoints()
177					chat:Point("TOPLEFT", TukuiTabsRightBackground, "BOTTOMLEFT", 0, -4)
178					chat:Point("BOTTOMRIGHT", TukuiInfoRight, "TOPRIGHT", 0, 4)
179				end
180			else
181				FCF_DockFrame(chat)
182			end
183		end
184		FCF_SavePositionAndDimensions(chat)
185	end
186end
187hooksecurefunc("FCF_DockFrame", ChatPosition)
188hooksecurefunc("FCF_UnDockFrame", ChatPosition)
189
190local function ToastFramePosition(self)
191	BNToastFrame:HookScript("OnShow", function(self)
192		self:ClearAllPoints()
193		self:Point("BOTTOMLEFT", TukuiChatBackgroundLeft, "TOPLEFT", 0, 3)
194	end)
195end
196
197TukuiChat:RegisterEvent("ADDON_LOADED")
198TukuiChat:RegisterEvent("UPDATE_CHAT_WINDOWS")
199TukuiChat:RegisterEvent("PLAYER_ENTERING_WORLD")
200TukuiChat:SetScript("OnEvent", function(self, event, addon)
201	if event == "ADDON_LOADED" then
202		if addon == "Blizzard_CombatLog" then
203			self:UnregisterEvent("ADDON_LOADED")
204			SetupChat(self)
205		end
206	elseif event == "PLAYER_ENTERING_WORLD" then
207		ChatPosition(self)
208		ToastFramePosition(self)
209	elseif event == "UPDATE_CHAT_WINDOWS" then
210		ChatPosition(self)
211	end
212end)
213
214-- Setup temp chat (BN, WHISPER) when needed.
215local function SetupTempChat(id)
216	local frame = FCF_GetCurrentChatFrame()
217	
218	if frame.skinned == true then return end
219	
220	StyleChat(frame)
221end
222hooksecurefunc("FCF_OpenTemporaryWindow", SetupTempChat)