Thread Tools Display Modes
09-20-20, 10:25 AM   #1
draikos
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 4
Creating first addon - Talking Head Frame - Help please

Hi all,

I'm quite impressed with how ElvUI has styled the Talking Head Frame and wanted to do something similar but use the vanilla wow ui.

I'm very new to LUA coding and this is my first addon creation for WoW and would really like to get it working. I have tested the codes below in-game using the "/run XX" to see if it would have the desired changes I want - and it does! I noticed it has to be reapplied each time the Talking Head Frame is loaded. I though it would be best to include this in an addon rather than macro format hence why I wanted to create this addon.
Below is my code - it would be very much appreciated if you can assist with getting this working or perhaps someone create this option in their own addon or something similar.
Any help is much appreciated thanks!

Code:
local TalkingHeadFrame = CreateFrame("FRAME","THF")
local TALKINGHEAD_OPEN = "TALKINGHEAD_REQUESTED"

local function main(frame, event, ...)
	if event == 'TALKINGHEAD_REQUESTED' then
		TalkingHeadFrame.BackgroundFrame:SetAlpha(0)
		TalkingHeadFrame.MainFrame.CloseButton:Hide()

		TalkingHeadFrame.NameFrame.Name:SetTextColor(1, 0.82, 0.02)
		TalkingHeadFrame.NameFrame.Name:SetShadowColor(0, 0, 0, 1)
		TalkingHeadFrame.NameFrame.Name:SetShadowOffset(2, -2)

		TalkingHeadFrame.TextFrame.Text:SetTextColor(255,255,255)
		TalkingHeadFrame.TextFrame.Text:SetShadowColor(0, 0, 0, 1)
		TalkingHeadFrame.TextFrame.Text:SetShadowOffset(2, -2)
	end
end

TalkingHeadFrame:RegisterEvent(TALKINGHEAD_OPEN)
TalkingHeadFrame:SetScript("OnEvent", main)
  Reply With Quote
09-20-20, 11:49 AM   #2
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 320
You could try this: https://addon.bool.no/
It will convert whatever lua code into an addon.
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote
09-20-20, 05:20 PM   #3
draikos
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 4
Originally Posted by LudiusMaximus View Post
You could try this: https://addon.bool.no/
It will convert whatever lua code into an addon.
I have tried that - didn't quite do the job. It would probably help if I mention the error I am getting (below).

Code:
Message: ...terface\AddOns\TalkingHeadFrame\TalkingHeadFrame.lua:6: attempt to index field 'BackgroundFrame' (a nil value)
Time: Mon Sep 21 08:49:24 2020
Count: 1
Stack: ...terface\AddOns\TalkingHeadFrame\TalkingHeadFrame.lua:6: attempt to index field 'BackgroundFrame' (a nil value)
[string "@Interface\AddOns\TalkingHeadFrame\TalkingHeadFrame.lua"]:6: in function <...terface\AddOns\TalkingHeadFrame\TalkingHeadFrame.lua:4>

Locals: frame = THF {
 0 = <userdata>
}
event = "TALKINGHEAD_REQUESTED"
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = "attempt to index field 'BackgroundFrame' (a nil value)"
TalkingHeadFrame = THF {
 0 = <userdata>
}
  Reply With Quote
09-20-20, 05:30 PM   #4
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
You are creating a new TalkingHeadFrame basic frame. ( First Line )

You are then trying to adjust contents that don't exist as you haven't created them. ( Inside the event function ).


If you have grabbed code from the ElvUI addon make sure you haven't missed any file content that are used by the code you have utilised from the addon. Such as an XML code block that defines the frame, or the creation code that defines the frame layout in the lua file.
__________________
  Reply With Quote
09-20-20, 06:27 PM   #5
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
As Xrystal noted, you need to adjust the TH frame from the Blizzard addon, not one you've created.

Lua Code:
  1. local function main(self, event, ...)
  2.     local addon = ... -- Check for the addon that has just loaded
  3.     if addon ~= "Blizzard_TalkingHeadUI" then return end -- Not the TH addon so scram
  4.    
  5.     self:UnregisterAllEvents() -- Is the TH addon so we no longer need to check for addons loading
  6.    
  7.     TalkingHeadFrame.BackgroundFrame:SetAlpha(0) -- adjust the TH frame
  8.     TalkingHeadFrame.MainFrame.CloseButton:Hide()
  9.  
  10.     TalkingHeadFrame.NameFrame.Name:SetTextColor(1, 0.82, 0.02)
  11.     TalkingHeadFrame.NameFrame.Name:SetShadowColor(0, 0, 0, 1)
  12.     TalkingHeadFrame.NameFrame.Name:SetShadowOffset(2, -2)
  13.  
  14.     TalkingHeadFrame.TextFrame.Text:SetTextColor(255,255,255)
  15.     TalkingHeadFrame.TextFrame.Text:SetShadowColor(0, 0, 0, 1)
  16.     TalkingHeadFrame.TextFrame.Text:SetShadowOffset(2, -2)
  17. end
  18.  
  19. local f = CreateFrame("Frame") -- frame to listen for the registered event(s)
  20. f:RegisterEvent("ADDON_LOADED")
  21. f:SetScript("OnEvent", main)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
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
09-20-20, 08:31 PM   #7
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
If you are running any other addon(s) that alter the TH frame, they might be "undoing" your code.

With what you have, it's probably easier to reduce all the code (after making a copy) to just:

Lua Code:
  1. TalkingHeadFrame.MainFrame.CloseButton:Hide()
  2. TalkingHeadFrame.BackgroundFrame:SetAlpha(0)
  3.  
  4. TalkingHeadFrame:HookScript("OnShow", function(self)
  5.     self.NameFrame.Name:SetTextColor(1, 0.82, 0.02)
  6.     self.NameFrame.Name:SetShadowColor(0, 0, 0, 1)
  7.     self.NameFrame.Name:SetShadowOffset(2, -2)
  8.  
  9.     self.TextFrame.Text:SetTextColor(255,255,255)
  10.     self.TextFrame.Text:SetShadowColor(0, 0, 0, 1)
  11.     self.TextFrame.Text:SetShadowOffset(2, -2)
  12. end)

and add the following to your addons .toc file:
Code:
## LoadOnDemand: 1
## LoadWith: Blizzard_TalkingHeadUI
This will automatically load the addon when the TH addon loads and hook the OnShow function only once (your other code adds a new hook every time the event is called).

You only need the other "plumbing" if the addon will be doing other things as well.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 09-20-20 at 08:35 PM.
  Reply With Quote
09-20-20, 10:06 PM   #8
draikos
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 4
Fizzlemizz thanks so much for helping with that!
Definitely helped cut down a lot of the additional lines I had added in. It still didn't update the "subsequent" messages from the Talking Head Frame. I was able to resolve this by changing the Hook script to a "hooksecurefunc" instead and use the function "TalkingHeadFrame_PlayCurrent" to update the text each time.

Lua Code:
  1. TalkingHeadFrame.MainFrame.CloseButton:Hide()
  2. TalkingHeadFrame.BackgroundFrame:SetAlpha(0)
  3.  
  4. hooksecurefunc("TalkingHeadFrame_PlayCurrent", function()
  5.     TalkingHeadFrame.MainFrame.CloseButton:Hide()
  6.     TalkingHeadFrame.NameFrame.Name:SetTextColor(1, 0.82, 0.02)
  7.     TalkingHeadFrame.NameFrame.Name:SetShadowColor(0, 0, 0, 1)
  8.     TalkingHeadFrame.NameFrame.Name:SetShadowOffset(2, -2)
  9.  
  10.     TalkingHeadFrame.TextFrame.Text:SetTextColor(255,255,255)
  11.     TalkingHeadFrame.TextFrame.Text:SetShadowColor(0, 0, 0, 1)
  12.     TalkingHeadFrame.TextFrame.Text:SetShadowOffset(2, -2)
  13.     TalkingHeadFrame.BackgroundFrame:SetAlpha(0)
  14. end)

Last edited by draikos : 09-20-20 at 10:09 PM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Creating first addon - Talking Head Frame - Help please

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off