View Single Post
09-20-20, 07:59 PM   #6
draikos
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 4
Thanks a lot for the replies and help guys. Xrystal - thank you, helps me understand what was going wrong and I was able to look into the right area. Fizzlemizz thank you for helping me with the code as well.
I have had to modify it slightly as the Text font wasn't actually updating to the values I wanted. The modification below:
Lua Code:
  1. local function UpdateTHF()
  2.     TalkingHeadFrame.BackgroundFrame:SetAlpha(0) -- adjust the TH frame
  3.     TalkingHeadFrame.MainFrame.CloseButton:Hide()
  4.  
  5.     TalkingHeadFrame.NameFrame.Name:SetTextColor(1, 0.82, 0.02)
  6.     TalkingHeadFrame.NameFrame.Name:SetShadowColor(0, 0, 0, 1)
  7.     TalkingHeadFrame.NameFrame.Name:SetShadowOffset(2, -2)
  8.  
  9.     TalkingHeadFrame.TextFrame.Text:SetTextColor(255,255,255)
  10.     TalkingHeadFrame.TextFrame.Text:SetShadowColor(0, 0, 0, 1)
  11.     TalkingHeadFrame.TextFrame.Text:SetShadowOffset(2, -2)
  12. end
  13.  
  14. local function main(self, event, ...)
  15.     local addon = ... -- Check for the addon that has just loaded
  16.     if addon ~= "Blizzard_TalkingHeadUI" then return end -- Not the TH addon so scram
  17.    
  18.     self:UnregisterAllEvents() -- Is the TH addon so we no longer need to check for addons loading
  19.     TalkingHeadFrame:HookScript("OnShow", UpdateTHF);
  20.     UpdateTHF();
  21. end
  22.  
  23. local f = CreateFrame("Frame") -- frame to listen for the registered event(s)
  24. f:RegisterEvent("ADDON_LOADED")
  25. f:SetScript("OnEvent", main)

With the above - the first time the Talking Head appears - the styling is perfect. Any subsequent messages do not appear to retain the "Text" styling but keeps the
Lua Code:
  1. TalkingHeadFrame.BackgroundFrame:SetAlpha(0) -- adjust the TH frame
  2. TalkingHeadFrame.MainFrame.CloseButton:Hide()

I have looked at how other AddOn authors have modified the TH frame and using their methods I was able to style it correctly (although a lot of the code is "merged together" with my styling so I may not be doing this efficiently).
Below is my completed one - any recommendations or improvements will be much appreciated.

Lua Code:
  1. -- Event handler table.
  2. local OnEvent = {};
  3. -- TalkingHeadFrame hook variables.
  4. local AddOn_Loaded, Hooked = false, false;
  5.  
  6. local function UpdateTHF()
  7.     if(AddOn_Loaded) then
  8.         TalkingHeadFrame.MainFrame.CloseButton:Hide()
  9.         TalkingHeadFrame.NameFrame.Name:SetTextColor(1, 0.82, 0.02)
  10.         TalkingHeadFrame.NameFrame.Name:SetShadowColor(0, 0, 0, 1)
  11.         TalkingHeadFrame.NameFrame.Name:SetShadowOffset(2, -2)
  12.  
  13.         TalkingHeadFrame.TextFrame.Text:SetTextColor(255,255,255)
  14.         TalkingHeadFrame.TextFrame.Text:SetShadowColor(0, 0, 0, 1)
  15.         TalkingHeadFrame.TextFrame.Text:SetShadowOffset(2, -2)
  16.         TalkingHeadFrame.BackgroundFrame:SetAlpha(0)
  17.     end
  18. end
  19.  
  20. -- Fires when the talking head appears.
  21. OnEvent["TALKINGHEAD_REQUESTED"] = function(self, ...)
  22.     if TalkingHeadFrame then
  23.         TalkingHeadFrame:HookScript("OnShow", UpdateTHF);
  24.         UpdateTHF();
  25.     end
  26. end
  27.  
  28. local function Initialize()
  29.     -- Event frame
  30.     local frame = CreateFrame("Frame");
  31.     frame:SetScript("OnEvent", function(self, event, ...) OnEvent[event](self, ...); end);
  32.     for event, func in pairs(OnEvent) do
  33.         frame:RegisterEvent(event);
  34.     end
  35.    
  36.     AddOn_Loaded = true;
  37. end
  38.  
  39. Initialize();
  Reply With Quote