Thread Tools Display Modes
10-31-18, 12:35 AM   #1
Lyak
A Cyclonian
Join Date: Jul 2018
Posts: 46
Nameplate's castbar won't change its texture

Hi all,

I've been a user of kui nameplate, but have recently decided to work on my private nameplate addon which I honestly don't know why LOL..........

Anyways!

I have started to working on media updates like font, statusbar texture, etc as my first job.

Everything is working fine except from the statusbar texture of castbar.

Please have a look at the code.
Lua Code:
  1. ------------------------------------------
  2. -- Variable
  3. ------------------------------------------
  4.  
  5. local LSM = LibStub("LibSharedMedia-3.0");
  6. local fontA = LSM:Fetch("font", "fontA");
  7. local textureB = LSM:Fetch("statusbar", "textureB");
  8.  
  9. local UpdateMedia;
  10. local CreateAuraFrame;
  11. local CreateHealthText;
  12.  
  13. local OnEvent;
  14.  
  15. ------------------------------------------
  16. -- Function
  17. ------------------------------------------
  18.  
  19. function UpdateMedia(nameplate)
  20.     local unitFrame = nameplate.UnitFrame;
  21.  
  22.     local name = unitFrame.name;
  23.     if (name) then
  24.         name:SetFont(fontA, 14, "OUTLINE");
  25.     end
  26.  
  27.     local healthBar = unitFrame.healthBar;
  28.     if (healthBar) then
  29.         healthBar:SetStatusBarTexture(textureB);
  30.     end
  31.  
  32.     local castBar = unitFrame.castBar;
  33.     if (castBar) then
  34.         castBar:SetStatusBarTexture(textureB);
  35.  
  36.         castBar.Text:SetFont(fontA, 12, "OUTLINE");
  37.     end
  38. end
  39.  
  40. function OnEvent(self, event, ...)
  41.     if (event == "NAME_PLATE_CREATED") then
  42.         local nameplate = ...;
  43.         if (nameplate and nameplate.UnitFrame) then
  44.             UpdateMedia(nameplate);
  45.             -- CreateAuraFrame(nameplate);
  46.             -- CreateHealthText(nameplate);
  47.         end
  48.     end
  49. end
  50.  
  51. local handler = CreateFrame("Frame");
  52. handler:RegisterEvent("NAME_PLATE_CREATED");
  53. handler:RegisterEvent("NAME_PLATE_UNIT_ADDED");
  54. handler:RegisterEvent("NAME_PLATE_UNIT_REMOVED");
  55. handler:SetScript("OnEvent", OnEvent);

It looks like Blizzard's code is keep updating the castbar's texture which I dug into, but failed

Could anyone please correct me if I am getting it wrong?

As always, thank you in advance!

Last edited by Lyak : 10-31-18 at 12:37 AM.
  Reply With Quote
11-01-18, 01:10 AM   #2
Lyak
A Cyclonian
Join Date: Jul 2018
Posts: 46
I've also tried something like this:

Lua Code:
  1. ------------------------------------------
  2. -- Variable
  3. ------------------------------------------
  4.  
  5. local LSM = LibStub("LibSharedMedia-3.0");
  6. local fontA = LSM:Fetch("font", "fontA");
  7. local textureB = LSM:Fetch("statusbar", "textureB");
  8.  
  9. local UpdateMedia;
  10. local CreateAuraFrame;
  11. local CreateHealthText;
  12.  
  13. local OnEvent;
  14.  
  15. ------------------------------------------
  16. -- Function
  17. ------------------------------------------
  18.  
  19. function UpdateMedia(nameplate)
  20.     local unitFrame = nameplate.UnitFrame;
  21.  
  22.     local name = unitFrame.name;
  23.     if (name) then
  24.         name:SetFont(fontA, 14, "OUTLINE");
  25.     end
  26.  
  27.     local healthBar = unitFrame.healthBar;
  28.     if (healthBar) then
  29.         healthBar:SetStatusBarTexture(textureB);
  30.     end
  31.  
  32.     local castBar = unitFrame.castBar;
  33.     if (castBar) then
  34.         castBar._SetStatusBarTexture = castBar.SetStatusBarTexture;
  35.         castBar:SetStatusBarTexture(textureB);
  36.         castBar.SetStatusBarTexture = function(...) end;
  37.  
  38.         castBar.Text:SetFont(fontA, 12, "OUTLINE");
  39.     end
  40. end
  41.  
  42. function OnEvent(self, event, ...)
  43.     if (event == "NAME_PLATE_CREATED") then
  44.         local nameplate = ...;
  45.         if (nameplate and nameplate.UnitFrame) then
  46.             UpdateMedia(nameplate);
  47.             -- CreateAuraFrame(nameplate);
  48.             -- CreateHealthText(nameplate);
  49.         end
  50.     end
  51. end
  52.  
  53. local handler = CreateFrame("Frame");
  54. handler:RegisterEvent("NAME_PLATE_CREATED");
  55. handler:RegisterEvent("NAME_PLATE_UNIT_ADDED");
  56. handler:RegisterEvent("NAME_PLATE_UNIT_REMOVED");
  57. handler:SetScript("OnEvent", OnEvent);

So, on nameplate creation, the SetStatusBarTexture is backed up with a name _SetStatusBarTexture, call SetStatusBarTexture then SetStatusBarTexture is now set to empty function.

This worked fine when the player is not in the combat, but once the player is in the combat, it causes the following error.

Code:
1x [ADDON_ACTION_BLOCKED] AddOn 'LyakNameplate' tried to call the protected function 'SetTargetClampingInsets()'
Would there be any secure way to tweak the texture of nameplate's castbar...?
  Reply With Quote
11-01-18, 09:01 AM   #3
jeruku
A Cobalt Mageweaver
 
jeruku's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 223
In this case you may need to change the texture every time it is set by the default UI. This can be achieved using the funciton hooksecurefunc. Otherwise you will keep tainting the UI.

This work around is provided you can not find where it keeps resetting the texture. If you happen to know where/how it is being reset there may be some other options.

Lua Code:
  1. -- So instead of:
  2. -- castBar.SetStatusBarTexture = function(...) end
  3.     -- You'd use:
  4.     local redundant
  5.     hooksecurefunc(castBar, "SetStatusBarTexture", function(self, ...)
  6.         if not redundant then
  7.             redundant = true
  8.             self:SetStatusBarTexture(textureB)
  9.             redundant = false
  10.         end
  11.     end)
__________________
"I have not failed, I simply found 10,000 ways that did not work." - Thomas Edison

Last edited by jeruku : 11-01-18 at 09:02 AM. Reason: typo
  Reply With Quote
11-03-18, 03:26 AM   #4
Lyak
A Cyclonian
Join Date: Jul 2018
Posts: 46
Hi jeruku,

Yeah, I am currently using hooksecurefunc as a temporary solution although I didn't update this thread.
(Sorry was damn tired and didn't have much time to update here )

I am keep trying to find the best solution for this

Last edited by Lyak : 11-03-18 at 04:33 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Nameplate's castbar won't change its texture

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