add chat bubble names

This commit is contained in:
Crum
2018-11-24 16:11:28 -06:00
parent 500bb5ea38
commit 9963d5fa60
4 changed files with 333 additions and 253 deletions
+167 -113
View File
@@ -6,10 +6,16 @@ local CC = E:GetModule("ClassCache");
--Cache global variables
--Lua functions
local select, unpack, type = select, unpack, type
local format, gsub, match, gmatch = string.format, string.gsub, string.match, string.gmatch
local strlower = strlower
local gsub, gmatch, format, lower, match = string.gsub, string.gmatch, string.format, string.lower, string.match
local strlower, split = strlower, string.split
--WoW API / Variables
local CreateFrame = CreateFrame
local WorldFrame = WorldFrame
local WorldGetChildren = WorldFrame.GetChildren
local RAID_CLASS_COLORS = RAID_CLASS_COLORS
--Message cache
local messageToSender = {}
function M:UpdateBubbleBorder()
if not this.text then return end
@@ -26,13 +32,21 @@ function M:UpdateBubbleBorder()
end
end
local text = this.text:GetText()
if this.Name then
this.Name:SetText("") --Always reset it
if text and E.private.general.chatBubbleName then
M:AddChatBubbleName(this, messageToSender[text])
end
end
if E.private.chat.enable and E.private.general.classCache and E.private.general.classColorMentionsSpeech then
local classColorTable, isFirstWord, rebuiltString, lowerCaseWord, tempWord, wordMatch, classMatch
local text = this.text:GetText()
if text and match(text, "%s-[^%s]+%s*") then
for word in gmatch(text, "%s-[^%s]+%s*") do
if text and match(text, "%s-%S+%s*") then
for word in gmatch(text, "%s-%S+%s*") do
tempWord = gsub(word, "^[%s%p]-([^%s%p]+)([%-]?[^%s%p]-)[%s%p]*$","%1%2")
lowerCaseWord = strlower(tempWord)
lowerCaseWord = lower(tempWord)
classMatch = CC:GetCacheTable()[E.myrealm][tempWord]
wordMatch = classMatch and lowerCaseWord
@@ -57,6 +71,22 @@ function M:UpdateBubbleBorder()
end
end
function M:AddChatBubbleName(chatBubble, name)
if not name then return end
local defaultColor, color = "|cffffffff"
local name, realm = split("-", name)
local class = CC:GetClassByName(name, realm)
if class then
color = (CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[class] and E:RGBToHex(CUSTOM_CLASS_COLORS[class].r, CUSTOM_CLASS_COLORS[class].g, CUSTOM_CLASS_COLORS[class].b)) or (RAID_CLASS_COLORS[class] and E:RGBToHex(RAID_CLASS_COLORS[class].r, RAID_CLASS_COLORS[class].g, RAID_CLASS_COLORS[class].b))
else
color = defaultColor
end
chatBubble.Name:SetText(format("%s%s|r", color, name))
end
function M:SkinBubble(frame)
local mult = E.mult * UIParent:GetScale()
for i = 1, frame:GetNumRegions() do
@@ -68,136 +98,160 @@ function M:SkinBubble(frame)
end
end
if frame.text then
if E.private.general.chatBubbles == "backdrop" then
if E.PixelMode then
E:SetTemplate(frame, "Transparent", true)
frame:SetBackdropColor(unpack(E.media.backdropfadecolor))
frame:SetBackdropBorderColor(0, 0, 0)
else
frame:SetBackdrop(nil)
end
local name = frame:CreateFontString(nil, "OVERLAY")
if E.private.general.chatBubbles == "backdrop" then
name:SetPoint("TOPLEFT", 5, 19)
else
name:SetPoint("TOPLEFT", 5, 6)
end
name:SetPoint("BOTTOMRIGHT", frame, "TOPRIGHT", -5, -5)
name:SetJustifyH("LEFT")
E:FontTemplate(name, E.LSM:Fetch("font", E.private.general.chatBubbleFont), E.private.general.chatBubbleFontSize * 0.85, E.private.general.chatBubbleFontOutline)
frame.Name = name
local r, g, b = frame.text:GetTextColor()
if not E.PixelMode then
if not frame.backdrop then
frame.backdrop = frame:CreateTexture(nil, "BACKGROUND")
frame.backdrop:SetAllPoints(frame)
frame.backdrop:SetTexture(unpack(E.media.backdropfadecolor))
frame.bordertop = frame:CreateTexture(nil, "OVERLAY")
E:Point(frame.bordertop, "TOPLEFT", frame, "TOPLEFT", -mult*2, mult*2)
E:Point(frame.bordertop, "TOPRIGHT", frame, "TOPRIGHT", mult*2, mult*2)
E:Height(frame.bordertop, mult)
frame.bordertop:SetTexture(r, g, b)
frame.bordertop.backdrop = frame:CreateTexture(nil, "BORDER")
E:Point(frame.bordertop.backdrop, "TOPLEFT", frame.bordertop, "TOPLEFT", -mult, mult)
E:Point(frame.bordertop.backdrop, "TOPRIGHT", frame.bordertop, "TOPRIGHT", mult, mult)
E:Height(frame.bordertop.backdrop, mult * 3)
frame.bordertop.backdrop:SetTexture(0, 0, 0)
frame.borderbottom = frame:CreateTexture(nil, "OVERLAY")
E:Point(frame.borderbottom, "BOTTOMLEFT", frame, "BOTTOMLEFT", -mult*2, -mult*2)
E:Point(frame.borderbottom, "BOTTOMRIGHT", frame, "BOTTOMRIGHT", mult*2, -mult*2)
E:Height(frame.borderbottom, mult)
frame.borderbottom:SetTexture(r, g, b)
frame.borderbottom.backdrop = frame:CreateTexture(nil, "BORDER")
E:Point(frame.borderbottom.backdrop, "BOTTOMLEFT", frame.borderbottom, "BOTTOMLEFT", -mult, -mult)
E:Point(frame.borderbottom.backdrop, "BOTTOMRIGHT", frame.borderbottom, "BOTTOMRIGHT", mult, -mult)
E:Height(frame.borderbottom.backdrop, mult * 3)
frame.borderbottom.backdrop:SetTexture(0, 0, 0)
frame.borderleft = frame:CreateTexture(nil, "OVERLAY")
E:Point(frame.borderleft, "TOPLEFT", frame, "TOPLEFT", -mult*2, mult*2)
E:Point(frame.borderleft, "BOTTOMLEFT", frame, "BOTTOMLEFT", mult*2, -mult*2)
E:Width(frame.borderleft, mult)
frame.borderleft:SetTexture(r, g, b)
frame.borderleft.backdrop = frame:CreateTexture(nil, "BORDER")
E:Point(frame.borderleft.backdrop, "TOPLEFT", frame.borderleft, "TOPLEFT", -mult, mult)
E:Point(frame.borderleft.backdrop, "BOTTOMLEFT", frame.borderleft, "BOTTOMLEFT", -mult, -mult)
E:Width(frame.borderleft.backdrop, mult * 3)
frame.borderleft.backdrop:SetTexture(0, 0, 0)
frame.borderright = frame:CreateTexture(nil, "OVERLAY")
E:Point(frame.borderright, "TOPRIGHT", frame, "TOPRIGHT", mult*2, mult*2)
E:Point(frame.borderright, "BOTTOMRIGHT", frame, "BOTTOMRIGHT", -mult*2, -mult*2)
E:Width(frame.borderright, mult)
frame.borderright:SetTexture(r, g, b)
frame.borderright.backdrop = frame:CreateTexture(nil, "BORDER")
E:Point(frame.borderright.backdrop, "TOPRIGHT", frame.borderright, "TOPRIGHT", mult, mult)
E:Point(frame.borderright.backdrop, "BOTTOMRIGHT", frame.borderright, "BOTTOMRIGHT", mult, -mult)
E:Width(frame.borderright.backdrop, mult * 3)
frame.borderright.backdrop:SetTexture(0, 0, 0)
end
else
frame:SetBackdropColor(unpack(E.media.backdropfadecolor))
frame:SetBackdropBorderColor(r, g, b)
end
E:FontTemplate(frame.text, E.LSM:Fetch("font", E.private.general.chatBubbleFont), E.private.general.chatBubbleFontSize, E.private.general.chatBubbleFontOutline)
elseif E.private.general.chatBubbles == "backdrop_noborder" then
if E.private.general.chatBubbles == "backdrop" then
if E.PixelMode then
frame:SetBackdrop({
bgFile = E["media"].blankTex,
edgeFile = E["media"].blankTex,
tile = false, tileSize = 0, edgeSize = mult,
insets = {left = 0, right = 0, top = 0, bottom = 0}
})
frame:SetBackdropColor(unpack(E.media.backdropfadecolor))
frame:SetBackdropBorderColor(0, 0, 0)
else
frame:SetBackdrop(nil)
if not frame.backdrop then
frame.backdrop = frame:CreateTexture(nil, "ARTWORK")
E:SetInside(frame.backdrop, frame, 4, 4)
frame.backdrop:SetTexture(unpack(E.media.backdropfadecolor))
end
E:FontTemplate(frame.text, E.LSM:Fetch("font", E.private.general.chatBubbleFont), E.private.general.chatBubbleFontSize, E.private.general.chatBubbleFontOutline)
frame:SetClampedToScreen(false)
elseif E.private.general.chatBubbles == "nobackdrop" then
frame:SetBackdrop(nil)
E:FontTemplate(frame.text, E.LSM:Fetch("font", E.private.general.chatBubbleFont), E.private.general.chatBubbleFontSize, E.private.general.chatBubbleFontOutline)
frame:SetClampedToScreen(false)
end
local r, g, b = frame.text:GetTextColor()
if not E.PixelMode then
frame.backdrop = frame:CreateTexture(nil, "BACKGROUND")
frame.backdrop:SetAllPoints(frame)
frame.backdrop:SetTexture(unpack(E.media.backdropfadecolor))
frame.bordertop = frame:CreateTexture(nil, "ARTWORK")
frame.bordertop:SetPoint("TOPLEFT", frame, "TOPLEFT", -mult*2, mult*2)
frame.bordertop:SetPoint("TOPRIGHT", frame, "TOPRIGHT", mult*2, mult*2)
frame.bordertop:SetHeight(mult)
frame.bordertop:SetTexture(r, g, b)
frame.bordertop.backdrop = frame:CreateTexture(nil, "BORDER")
frame.bordertop.backdrop:SetPoint("TOPLEFT", frame.bordertop, "TOPLEFT", -mult, mult)
frame.bordertop.backdrop:SetPoint("TOPRIGHT", frame.bordertop, "TOPRIGHT", mult, mult)
frame.bordertop.backdrop:SetHeight(mult * 3)
frame.bordertop.backdrop:SetTexture(0, 0, 0)
frame.borderbottom = frame:CreateTexture(nil, "ARTWORK")
frame.borderbottom:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", -mult*2, -mult*2)
frame.borderbottom:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", mult*2, -mult*2)
frame.borderbottom:SetHeight(mult)
frame.borderbottom:SetTexture(r, g, b)
frame.borderbottom.backdrop = frame:CreateTexture(nil, "BORDER")
frame.borderbottom.backdrop:SetPoint("BOTTOMLEFT", frame.borderbottom, "BOTTOMLEFT", -mult, -mult)
frame.borderbottom.backdrop:SetPoint("BOTTOMRIGHT", frame.borderbottom, "BOTTOMRIGHT", mult, -mult)
frame.borderbottom.backdrop:SetHeight(mult * 3)
frame.borderbottom.backdrop:SetTexture(0, 0, 0)
frame.borderleft = frame:CreateTexture(nil, "ARTWORK")
frame.borderleft:SetPoint("TOPLEFT", frame, "TOPLEFT", -mult*2, mult*2)
frame.borderleft:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", mult*2, -mult*2)
frame.borderleft:SetWidth(mult)
frame.borderleft:SetTexture(r, g, b)
frame.borderleft.backdrop = frame:CreateTexture(nil, "BORDER")
frame.borderleft.backdrop:SetPoint("TOPLEFT", frame.borderleft, "TOPLEFT", -mult, mult)
frame.borderleft.backdrop:SetPoint("BOTTOMLEFT", frame.borderleft, "BOTTOMLEFT", -mult, -mult)
frame.borderleft.backdrop:SetWidth(mult * 3)
frame.borderleft.backdrop:SetTexture(0, 0, 0)
frame.borderright = frame:CreateTexture(nil, "ARTWORK")
frame.borderright:SetPoint("TOPRIGHT", frame, "TOPRIGHT", mult*2, mult*2)
frame.borderright:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -mult*2, -mult*2)
frame.borderright:SetWidth(mult)
frame.borderright:SetTexture(r, g, b)
frame.borderright.backdrop = frame:CreateTexture(nil, "BORDER")
frame.borderright.backdrop:SetPoint("TOPRIGHT", frame.borderright, "TOPRIGHT", mult, mult)
frame.borderright.backdrop:SetPoint("BOTTOMRIGHT", frame.borderright, "BOTTOMRIGHT", mult, -mult)
frame.borderright.backdrop:SetWidth(mult * 3)
frame.borderright.backdrop:SetTexture(0, 0, 0)
else
frame:SetBackdropColor(unpack(E.media.backdropfadecolor))
frame:SetBackdropBorderColor(r, g, b)
end
E:FontTemplate(frame.text, E.LSM:Fetch("font", E.private.general.chatBubbleFont), E.private.general.chatBubbleFontSize, E.private.general.chatBubbleFontOutline);
elseif E.private.general.chatBubbles == "backdrop_noborder" then
frame:SetBackdrop(nil)
frame.backdrop = frame:CreateTexture(nil, "ARTWORK")
E:SetInside(frame.backdrop, frame, 4, 4)
frame.backdrop:SetTexture(unpack(E.media.backdropfadecolor))
E:FontTemplate(frame.text, E.LSM:Fetch("font", E.private.general.chatBubbleFont), E.private.general.chatBubbleFontSize, E.private.general.chatBubbleFontOutline)
frame:SetClampedToScreen(false)
elseif E.private.general.chatBubbles == "nobackdrop" then
frame:SetBackdrop(nil)
E:FontTemplate(frame.text, E.LSM:Fetch("font", E.private.general.chatBubbleFont), E.private.general.chatBubbleFontSize, E.private.general.chatBubbleFontOutline)
frame:SetClampedToScreen(false)
frame.Name:Hide()
end
HookScript(frame, "OnShow", M.UpdateBubbleBorder)
frame:SetFrameStrata("DIALOG")
M.UpdateBubbleBorder(frame)
frame.isBubblePowered = true
frame.isSkinnedElvUI = true
end
function M:IsChatBubble(frame)
for i = 1, frame:GetNumRegions() do
local region = select(i, frame:GetRegions())
if region.GetTexture and region:GetTexture() and type(region:GetTexture() == "string" and strlower(region:GetTexture()) == [[interface\tooltips\chatbubble-background]]) then return true end
if region.GetTexture and region:GetTexture() and type(region:GetTexture() == "string") and strlower(region:GetTexture()) == [[interface\tooltips\chatbubble-background]] then return true end
end
return false
end
local function ChatBubble_OnEvent()
if not E.private.general.chatBubbleName then return end
messageToSender[arg1] = arg2
end
local numChildren = 0
function M:LoadChatBubbles()
if E.private.general.bubbles == false then
E.private.general.chatBubbles = "disabled"
E.private.general.bubbles = nil
local function ChatBubble_OnUpdate()
if not M.BubbleFrame.lastupdate then
M.BubbleFrame.lastupdate = -2 -- wait 2 seconds before hooking frames
end
if E.private.general.chatBubbles == "disabled" then return end
M.BubbleFrame.lastupdate = M.BubbleFrame.lastupdate + arg1
if M.BubbleFrame.lastupdate < .1 then return end
M.BubbleFrame.lastupdate = 0
local frame = CreateFrame("Frame")
frame.lastupdate = -2
local count = select("#", WorldGetChildren(WorldFrame))
if count ~= numChildren then
for i = numChildren + 1, count do
local frame = select(i, WorldGetChildren(WorldFrame))
frame:SetScript("OnUpdate", function()
this.lastupdate = this.lastupdate + arg1
if this.lastupdate < .1 then return end
this.lastupdate = 0
local count = WorldFrame:GetNumChildren()
if count ~= numChildren then
for i = numChildren + 1, count do
local frame = select(i, WorldFrame:GetChildren())
if frame.GetObjectType and frame:GetObjectType() == "Frame" and M:IsChatBubble(frame) then
if M:IsChatBubble(frame) then
if not frame.isSkinnedElvUI then
M:SkinBubble(frame)
end
end
numChildren = count
end
end)
end
numChildren = count
end
end
function M:LoadChatBubbles()
if E.private.general.chatBubbles == "disabled" then return end
self.BubbleFrame = CreateFrame("Frame")
self.BubbleFrame:RegisterEvent("CHAT_MSG_SAY")
self.BubbleFrame:RegisterEvent("CHAT_MSG_YELL")
self.BubbleFrame:RegisterEvent("CHAT_MSG_PARTY")
self.BubbleFrame:RegisterEvent("CHAT_MSG_MONSTER_SAY")
self.BubbleFrame:RegisterEvent("CHAT_MSG_MONSTER_YELL")
self.BubbleFrame:SetScript("OnEvent", ChatBubble_OnEvent)
self.BubbleFrame:SetScript("OnUpdate", ChatBubble_OnUpdate)
end