Alright, I'm tightening up the last few things for this - so I'll probably be posting a couple of my standing issues in the next couple of days for stuff I've yet to fix even after a lot of fiddling.
I modified the chat bubbles a while back to display names over the top (based on code from BubbleBobble) and it's all more or less working, but I have two things i'd like to fix.
Firstly, there's an issue where new bubbles that pop up will still display names from older messages. You can sort of see what I mean
here. Do I need to introduce some kind of method that wipes information after the function is activated each time or something?
Secondly, how do I hide
realm names? There's a small function I wrote (or more likely, "procured" then bludgeoned) but it doesn't seem to be working - though there's no errors to speak of.
Here's the code:
Lua Code:
-- events table
local events = {
CHAT_MSG_SAY = "chatBubbles",
CHAT_MSG_YELL = "chatBubbles",
CHAT_MSG_PARTY = "chatBubblesParty",
CHAT_MSG_PARTY_LEADER = "chatBubblesParty",
CHAT_MSG_MONSTER_SAY = "chatBubbles",
CHAT_MSG_MONSTER_YELL = "chatBubbles",
CHAT_MSG_MONSTER_PARTY = "chatBubblesParty",
}
-- hides realm names
local function hideRealmName(self, event, msg, sender, ...)
local realmName = string.gsub(GetRealmName(), " ", "")
if msg:find("-" .. realmName) then
return false, gsub(msg, "%-"..realmName, ""), sender, ...
end
end
local function styleBubble(frame)
for i = 1, frame:GetNumRegions() do
local region = select(i, frame:GetRegions())
local pn = {region:GetPoint()}
if (region:GetObjectType()=="Texture") then
region:SetDrawLayer("OVERLAY")
region:ClearAllPoints()
-- fix the gap between bubble and tail texture by nudging up the yoffset
region:SetPoint(pn[1],pn[2],pn[3],pn[4], pn[5]+2)
elseif (region:GetObjectType()=="FontString") then
frame.textstring = region
end
end
frame:SetBackdrop({
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = nil,
edgeSize = 0,
insets = {
left = 5, right = 5, top = 5, bottom = 5;
}
})
frame:SetBackdropColor(0, 0, 0, 0.8)
frame:CreateBeautyBorder(22)
frame:SetBeautyBorderColor(r, g, b)
frame:SetScale(.95)
frame.sender = frame:CreateFontString()
frame.sender:SetPoint("BOTTOMRIGHT", frame, "TOPRIGHT", -7, 2)
frame.sender:SetFont(STANDARD_TEXT_FONT, 13)
frame.sender:SetShadowOffset(1.7,-1.2)
frame.sender:SetShadowColor(0,0,0)
frame.sender:SetJustifyH("RIGHT")
end
local function UpdateNameBubble(frame, guid, name)
local class
if (guid~= nil) and (guid~="") then
_, class, _, _, _, _ = GetPlayerInfoByGUID(guid)
end
if name then
local color = RAID_CLASS_COLORS[class] or { r = 1, g = .8, b = 0 }
frame.sender:SetText(("|cFF%2x%2x%2x%s|r"):format(color.r*255, color.g*255, color.b*255, name))
if (frame:GetWidth() < frame.sender:GetWidth()) then
frame.textstring:SetWidth(frame.sender:GetWidth() + 10)
end
end
end
local function isChatBubble(frame)
if frame:GetName() then return end
if not frame:GetRegions() then return end
return frame:GetRegions():GetTexture()==("Interface\\Tooltips\\ChatBubble-Background")
end
local bubbleHook = CreateFrame("Frame")
for event, cvar in pairs(events) do
bubbleHook:RegisterEvent(event)
end
bubbleHook:SetScript("OnEvent", function(self, event, msg, sender, _, _, _, _, _, _, _, _, _, guid)
if GetCVarBool(events[event]) then
local last = 0
local numKids = 0
hideRealmName(self, event, msg, sender)
bubbleHook:SetScript("OnUpdate", function(self, elapsed)
last = last + elapsed
if last > .1 then
last = 0
local newNumKids = WorldFrame:GetNumChildren()
if newNumKids ~= numKids then
for i=numKids + 1, newNumKids do
local frame = select(i, WorldFrame:GetChildren())
if isChatBubble(frame) then
styleBubble(frame)
UpdateNameBubble(frame, guid, sender)
end
end
numKids = newNumKids
end
end
end)
end
end)