WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Create target 2D portrait (https://www.wowinterface.com/forums/showthread.php?t=57107)

SilverDragony 04-13-19 09:52 AM

Create target 2D portrait
 
Hi,

I try to create un portrait for player and target. I've created un code, te target portrait exists but there isn't image.

Code:

--Player Frame
local fp = CreateFrame("Button", "FarmootPlayerPortrait", UIParent, "SecureUnitButtonTemplate")
fp:SetSize(70, 70)
fp:SetPoint("CENTER", -100, -320)
fp:SetAttribute("unit", "player")
RegisterUnitWatch(fp)
fp:SetAttribute("toggleForVehicle", true)
fp:RegisterForClicks("AnyUp")
fp:SetAttribute("*type1", "target")
fp:SetAttribute("*type2", "togglemenu")
fp:SetAttribute("*type3", "assist")
fp.Texture = fp:CreateTexture("$parent_Texture", "BACKGROUND")
fp.Texture:SetAllPoints()
SetPortraitTexture(fp.Texture, "player")
fp.Border = fp:CreateTexture("$parent_Border", "BORDER")
fp.Border:SetPoint("TOPLEFT", -6, 4)
fp.Border:SetPoint("BOTTOMRIGHT", 6, -10)
fp.Border:SetTexture("Interface/PLAYERFRAME/UI-PlayerFrame-Deathknight-Ring")
fp.Border:SetVertexColor(1, 1, 0, 1)
fp:RegisterUnitEvent("UNIT_PORTRAIT_UPDATE", "player")
fp:SetScript("OnEvent", function(self) SetPortraitTexture(self.Texture, "player") end)

--Target Frame
local ft = CreateFrame("Button", "FarmootPlayerPortrait", UIParent, "SecureUnitButtonTemplate")
ft:SetSize(50, 50)
ft:SetPoint("CENTER", 180, 0)
ft:SetAttribute("unit", "target")
RegisterUnitWatch(ft)
ft:SetAttribute("toggleForVehicle", true)
ft:RegisterForClicks("AnyUp")
fp:SetAttribute("*type1", "target")
ft:SetAttribute("*type2", "togglemenu")
ft:SetAttribute("*type3", "assist")
ft.Texture = ft:CreateTexture("$parent_Texture", "BACKGROUND")
ft.Texture:SetAllPoints()
SetPortraitTexture(ft.Texture, "target")
ft.Border = ft:CreateTexture("$parent_Border", "BORDER")
ft.Border:SetPoint("TOPLEFT", -6, 4)
ft.Border:SetPoint("BOTTOMRIGHT", 6, -10)
ft.Border:SetTexture("Interface/PLAYERFRAME/UI-PlayerFrame-Deathknight-Ring")
ft.Border:SetVertexColor(1, 1, 0, 1)
ft:RegisterUnitEvent("UNIT_PORTRAIT_UPDATE", "target")
ft:SetScript("OnEvent", function(self) SetPortraitTexture(self.Texture, "target") end)

That's the code, do you know what's the problem for display the image of target portrait ?

Thank you for your help.

Fizzlemizz 04-13-19 10:07 AM

You need to change the portrait when your target changes (and you had one fp.xxx in your ft.xxx section)

Eg.
Lua Code:
  1. --Player Frame
  2. local fp = CreateFrame("Button", "FarmootPlayerPortrait", UIParent, "SecureUnitButtonTemplate")
  3. fp:SetSize(70, 70)
  4. fp:SetPoint("CENTER", -100, -320)
  5. fp:SetAttribute("unit", "player")
  6. RegisterUnitWatch(fp)
  7. fp:SetAttribute("toggleForVehicle", true)
  8. fp:RegisterForClicks("AnyUp")
  9. fp:SetAttribute("*type1", "target")
  10. fp:SetAttribute("*type2", "togglemenu")
  11. fp:SetAttribute("*type3", "assist")
  12. fp.Texture = fp:CreateTexture("$parent_Texture", "BACKGROUND")
  13. fp.Texture:SetAllPoints()
  14. SetPortraitTexture(fp.Texture, "player")
  15. fp.Border = fp:CreateTexture("$parent_Border", "BORDER")
  16. fp.Border:SetPoint("TOPLEFT", -6, 4)
  17. fp.Border:SetPoint("BOTTOMRIGHT", 6, -10)
  18. fp.Border:SetTexture("Interface/PLAYERFRAME/UI-PlayerFrame-Deathknight-Ring")
  19. fp.Border:SetVertexColor(1, 1, 0, 1)
  20. fp:RegisterUnitEvent("UNIT_PORTRAIT_UPDATE", "player")
  21. fp:RegisterEvent("PLAYER_TARGET_CHANGED") -- Added
  22. fp:SetScript("OnEvent", function(self)
  23.     if event == "UNIT_PORTRAIT_UPDATE" then
  24.         SetPortraitTexture(self.Texture, "player")
  25.     else
  26.         SetPortraitTexture(self.Target.Texture, "target") -- Added
  27.     end
  28. end)
  29.  
  30. --Target Frame
  31. local ft = CreateFrame("Button", "FarmootPlayerPortrait", UIParent, "SecureUnitButtonTemplate")
  32. fp.Target = ft -- Added
  33. ft:SetSize(50, 50)
  34. ft:SetPoint("CENTER", 180, 0)
  35. ft:SetAttribute("unit", "target")
  36. RegisterUnitWatch(ft)
  37. ft:SetAttribute("toggleForVehicle", true)
  38. ft:RegisterForClicks("AnyUp")
  39. ft:SetAttribute("*type1", "target")
  40. ft:SetAttribute("*type2", "togglemenu")
  41. ft:SetAttribute("*type3", "assist")
  42. ft.Texture = ft:CreateTexture("$parent_Texture", "BACKGROUND")
  43. ft.Texture:SetAllPoints()
  44. SetPortraitTexture(ft.Texture, "target")
  45. ft.Border = ft:CreateTexture("$parent_Border", "BORDER")
  46. ft.Border:SetPoint("TOPLEFT", -6, 4)
  47. ft.Border:SetPoint("BOTTOMRIGHT", 6, -10)
  48. ft.Border:SetTexture("Interface/PLAYERFRAME/UI-PlayerFrame-Deathknight-Ring")
  49. ft.Border:SetVertexColor(1, 1, 0, 1)
  50. ft:RegisterUnitEvent("UNIT_PORTRAIT_UPDATE", "target")
  51. ft:SetScript("OnEvent", function(self) SetPortraitTexture(self.Texture, "target")  end)

SDPhantom 04-13-19 04:09 PM

Quote:

Originally Posted by Fizzlemizz (Post 331917)
You need to change the portrait when your target changes (and you had one fp.xxx in your ft.xxx section)

You could achieve the same result just by having the target frame register for PLAYER_TARGET_CHANGED in addition to UNIT_PORTRAIT_UPDATE. The script should still be able to handle the event as-is. No need to change the player frame.

SilverDragony 04-13-19 04:11 PM

Thank you Fizzlemizz. I've changed a little for understand, but with your code, now this the player frame wish isn't displayed. I searched how to display it, but I don't find solution.

Fizzlemizz 04-13-19 04:21 PM

Quote:

Originally Posted by SDPhantom (Post 331919)
You could achieve the same result just by having the target frame register for PLAYER_TARGET_CHANGED in addition to UNIT_PORTRAIT_UPDATE. The script should still be able to handle the event as-is. No need to change the player frame.

You are indeed correct.

Fizzlemizz 04-13-19 04:22 PM

Quote:

Originally Posted by SilverDragony (Post 331922)
Thank you Fizzlemizz. I've changed a little for understand, but with your code, now this the player frame wish isn't displayed. I searched how to display it, but I don't find solution.

You should post the new code so we can see what might be happening.

SilverDragony 04-13-19 04:44 PM

I have this code :

Lua Code:
  1. --Player Frame
  2.     local fp = CreateFrame("Button", "FarmootPlayerPortrait", UIParent, "SecureUnitButtonTemplate")
  3.     fp:SetSize(60, 60)
  4.     fp:SetPoint("CENTER", -40, -350)
  5.     fp:SetAttribute("unit", "player")
  6.     RegisterUnitWatch(fp)
  7.     fp:SetAttribute("toggleForVehicle", true)
  8.     fp:RegisterForClicks("AnyUp")
  9.     fp:SetAttribute("*type1", "target")
  10.     fp:SetAttribute("*type2", "togglemenu")
  11.     fp:SetAttribute("*type3", "assist")
  12.     fp.Texture = fp:CreateTexture("$parent_Texture", "BACKGROUND")
  13.     fp.Texture:SetAllPoints()
  14.     SetPortraitTexture(fp.Texture, "player")
  15.     fp.Border = fp:CreateTexture("$parent_Border", "BORDER")
  16.     fp.Border:SetPoint("TOPLEFT", -6, 4)
  17.     fp.Border:SetPoint("BOTTOMRIGHT", 6, -10)
  18.     fp.Border:SetTexture("Interface/PLAYERFRAME/UI-PlayerFrame-Deathknight-Ring")
  19.     fp.Border:SetVertexColor(1, 1, 0, 1)
  20.     fp:RegisterUnitEvent("UNIT_PORTRAIT_UPDATE", "player")
  21.     fp:RegisterEvent("PLAYER_TARGET_CHANGED") -- based on suggestion of Fizzlemizz
  22.     fp:SetScript("OnEvent", function(self)
  23.         if event == "UNIT_PORTRAIT_UPDATE" or "PLAYER_TARGET_CHANGED" then -- based on suggestion of SDPhantom
  24.             SetPortraitTexture(self.Texture, "player")
  25.         else
  26.             SetPortraitTexture(self.Target.Texture, "target") -- based on suggestion of Fizzlemizz
  27.         end
  28.     end)
  29.      
  30.     --Target Frame
  31.     local ft = CreateFrame("Button", "FarmootPlayerPortrait", UIParent, "SecureUnitButtonTemplate")
  32.     fp.Target = ft -- based on suggestion of Fizzlemizz
  33.     ft:SetSize(60, 60)
  34.     ft:SetPoint("CENTER", 100, -350)
  35.     ft:SetAttribute("unit", "target")
  36.     RegisterUnitWatch(ft)
  37.     ft:SetAttribute("toggleForVehicle", true)
  38.     ft:RegisterForClicks("AnyUp")
  39.     ft:SetAttribute("*type1", "target")
  40.     ft:SetAttribute("*type2", "togglemenu")
  41.     ft:SetAttribute("*type3", "assist")
  42.     ft.Texture = ft:CreateTexture("$parent_Texture", "BACKGROUND")
  43.     ft.Texture:SetAllPoints()
  44.     SetPortraitTexture(ft.Texture, "target")
  45.     ft.Border = ft:CreateTexture("$parent_Border", "BORDER")
  46.     ft.Border:SetPoint("TOPLEFT", -6, 4)
  47.     ft.Border:SetPoint("BOTTOMRIGHT", 6, -10)
  48.     ft.Border:SetTexture("Interface/PLAYERFRAME/UI-PlayerFrame-Deathknight-Ring")
  49.     ft.Border:SetVertexColor(1, 1, 0, 1)
  50.     ft:RegisterUnitEvent("UNIT_PORTRAIT_UPDATE", "target")
  51.     ft:SetScript("OnEvent", function(self) SetPortraitTexture(self.Texture, "target")  end)

But with this code, I have player frame and not target frame^^

myrroddin 04-13-19 05:46 PM

Maybe I'm missing something (probably), but wouldn't naming both fp and ft "FarmootPlayerPortrait" –– ie: the same global name –– cause problems?

Wouldn't WoW complain that two frames with the same name exist?

JDoubleU00 04-13-19 05:59 PM

Quote:

Originally Posted by myrroddin (Post 331926)
Maybe I'm missing something (probably), but wouldn't naming both fp and ft "FarmootPlayerPortrait" –– ie: the same global name –– cause problems?

Wouldn't WoW complain that two frames with the same name exist?

Oh, you must have copied the code Fizzlemizz helped me with on the UI & Macro Forums. I'll have a look to see if I have a working copy handy. :D

Fizzlemizz 04-13-19 06:17 PM

WoW doesn't care if you overwrite (re-use) frame names, you'll just get the first one created using _G["FrameName"] or FrameName but using the local referernce will still differentiate them in your code.

I moved the PLAYER_TARGET_CHANGED event as per SDPhantom's suggestion down to the target frame to make it easier to read/understand ie. the Player frame doesn't now need to have a reference to the Target frame to make the change as it's all done in the Target frame.

Lua Code:
  1. --Player Frame
  2. local fp = CreateFrame("Button", "FarmootPlayerPortrait", UIParent, "SecureUnitButtonTemplate")
  3. fp:SetSize(60, 60)
  4. fp:SetPoint("CENTER", -40, -350)
  5. fp:SetAttribute("unit", "player")
  6. RegisterUnitWatch(fp)
  7. fp:SetAttribute("toggleForVehicle", true)
  8. fp:RegisterForClicks("AnyUp")
  9. fp:SetAttribute("*type1", "target")
  10. fp:SetAttribute("*type2", "togglemenu")
  11. fp:SetAttribute("*type3", "assist")
  12. fp.Texture = fp:CreateTexture("$parent_Texture", "BACKGROUND")
  13. fp.Texture:SetAllPoints()
  14. SetPortraitTexture(fp.Texture, "player")
  15. fp.Border = fp:CreateTexture("$parent_Border", "BORDER")
  16. fp.Border:SetPoint("TOPLEFT", -6, 4)
  17. fp.Border:SetPoint("BOTTOMRIGHT", 6, -10)
  18. fp.Border:SetTexture("Interface/PLAYERFRAME/UI-PlayerFrame-Deathknight-Ring")
  19. fp.Border:SetVertexColor(1, 1, 0, 1)
  20. fp:RegisterUnitEvent("UNIT_PORTRAIT_UPDATE", "player")
  21. fp:SetScript("OnEvent", function(self) SetPortraitTexture(self.Texture, "player") end)
  22.  
  23. --Target Frame
  24. local ft = CreateFrame("Button", "FarmootTargetPortrait", UIParent, "SecureUnitButtonTemplate")
  25. fp.Target = ft -- based on suggestion of Fizzlemizz
  26. ft:SetSize(60, 60)
  27. ft:SetPoint("CENTER", 100, -350)
  28. ft:SetAttribute("unit", "target")
  29. RegisterUnitWatch(ft)
  30. ft:SetAttribute("toggleForVehicle", true)
  31. ft:RegisterForClicks("AnyUp")
  32. ft:SetAttribute("*type1", "target")
  33. ft:SetAttribute("*type2", "togglemenu")
  34. ft:SetAttribute("*type3", "assist")
  35. ft.Texture = ft:CreateTexture("$parent_Texture", "BACKGROUND")
  36. ft.Texture:SetAllPoints()
  37. ft.Border = ft:CreateTexture("$parent_Border", "BORDER")
  38. ft.Border:SetPoint("TOPLEFT", -6, 4)
  39. ft.Border:SetPoint("BOTTOMRIGHT", 6, -10)
  40. ft.Border:SetTexture("Interface/PLAYERFRAME/UI-PlayerFrame-Deathknight-Ring")
  41. ft.Border:SetVertexColor(1, 1, 0, 1)
  42. ft:RegisterUnitEvent("UNIT_PORTRAIT_UPDATE", "target")
  43. ft:RegisterEvent("PLAYER_TARGET_CHANGED") -- based on suggestion of Fizzlemizz
  44. ft:SetScript("OnEvent", function(self) SetPortraitTexture(self.Texture, "target")  end)

SilverDragony 04-14-19 01:50 PM

Thank you for your help. That works ! :) I will continue to work on this code and will go back here if I've questions.

SilverDragony 04-16-19 05:06 AM

Hi,

I work on this code but I have another probleme. I realy liked your help on this post :) so I continue here.

I sursh to display a border for each classification, but I don't understand why my code doesn't work. Is there a problem is local function ?

Lua Code:
  1. --Target Classification
  2.     local default = "Interface/AddOns/ClassicPortrait/media/default"
  3.     local unitClassTextures = {
  4.         worldboss = "Interface/AddOns/ClassicPortrait/media/worldboss",
  5.         boss = "Interface/AddOns/ClassicPortrait/media/boss",
  6.         elite = "Interface/AddOns/ClassicPortrait/media/elite",
  7.         rare = "Interface/AddOns/ClassicPortrait/media/rare",
  8.         rareelite = "Interface/AddOns/ClassicPortrait/media/rareelite",
  9.     }
  10.      
  11.     local function OnEvent(self, event, ...)
  12.         if event == "PLAYER_TARGET_CHANGED" and UnitExists("target") then
  13.             self.Border:SetTexture( unitClassTextures[UnitClassification("target")] or default )
  14.         end
  15.     end
  16.      
  17.     local function CreateBorder(self)
  18.         local t = self.Border or self:CreateTexture(nil, "BACKGROUND", nil, -8)
  19.         self.Border = t
  20.      
  21.         ft:SetPoint("CENTER", 110, -350)
  22.         ft.Border = ft:CreateTexture("$parent_Border", "BORDER")
  23.         ft.Border:SetPoint("TOPLEFT", -6, 4)
  24.         ft.Border:SetPoint("BOTTOMRIGHT", 6, -10)
  25.         ft.Border:SetVertexColor(1, 1, 0, 1)
  26.      
  27.         self:RegisterEvent("PLAYER_TARGET_CHANGED")
  28.         self:HookScript("OnEvent", OnEvent)
  29.     end

I verify in game on an elite unit but the addons display nothing.

Thank again for your help and have a good day :)

Fizzlemizz 04-16-19 09:56 AM

Lua Code:
  1. local function CreateBorder(self)
  2.     local t = self.Border or self:CreateTexture(nil, "BACKGROUND", nil, -8)
  3.     self.Border = t
  4.      
  5.     ft:SetPoint("CENTER", 110, -350)
  6.     ft.Border = ft:CreateTexture("$parent_Border", "BORDER")
  7.     ft.Border:SetPoint("TOPLEFT", -6, 4)
  8.     ft.Border:SetPoint("BOTTOMRIGHT", 6, -10)
  9.     ft.Border:SetVertexColor(1, 1, 0, 1)
  10.      
  11.     self:RegisterEvent("PLAYER_TARGET_CHANGED")
  12.     self:HookScript("OnEvent", OnEvent)
  13. end

As well as at local t = ..., this function also is creating a new texture for ft.Border every time it is called
Code:

ft.Border = ft:CreateTexture("$parent_Border", "BORDER")
You adjust (SetPoint), create and color/adjust again ft but not t so self.Border (t) never gets placed anywhere on screen meaning you can't see the changes. For such a small amount of code you might get rid of "t" and "ft" and just use "self".

I'm not sure why you need to use the function and test if the self.Border texture exists if this is only for the target frame. If it's being called for multiple frames, especially if you have more functions like this, you are adding more and more hooks to OnEvent each time.

You might want to think about using a single frame to process all events (no hooks) and use that to make changes to the individual unit frames as required rather than multiple event handlers possibly processing the same event(s), not to mention keeping track of which handler(s) need updating when code changes.

SilverDragony 04-17-19 04:18 AM

I'm learning lua, and it's not obvious for me. I sursh on plurality forums but I don't understand why y code doesn't work. Actualy I have this :

Lua Code:
  1. --Player Frame
  2.     local fp = CreateFrame("Button", "FarmootPlayerPortrait", UIParent, "SecureUnitButtonTemplate")
  3.     fp:SetSize(70, 70)
  4.     fp:SetPoint("CENTER", -80, -350)
  5.     fp:SetAttribute("unit", "player")
  6.     RegisterUnitWatch(fp)
  7.     fp:SetAttribute("toggleForVehicle", true)
  8.     fp:RegisterForClicks("AnyUp")
  9.     fp:SetAttribute("*type1", "target")
  10.     fp:SetAttribute("*type2", "togglemenu")
  11.     fp:SetAttribute("*type3", "assist")
  12.     fp.Texture = fp:CreateTexture("$parent_Texture", "BACKGROUND")
  13.     fp.Texture:SetAllPoints()
  14.     SetPortraitTexture(fp.Texture, "player")
  15.     fp.Border = fp:CreateTexture("$parent_Border", "BORDER")
  16.     fp.Border:SetPoint("TOPLEFT", -6, 4)
  17.     fp.Border:SetPoint("BOTTOMRIGHT", 6, -10)
  18.     fp.Border:SetTexture("Interface/PLAYERFRAME/UI-PlayerFrame-Deathknight-Ring")
  19.     fp.Border:SetVertexColor(1, 1, 0, 1)
  20.     fp:RegisterUnitEvent("UNIT_PORTRAIT_UPDATE", "player")
  21.     fp:SetScript("OnEvent", function(self) SetPortraitTexture(self.Texture, "player") end)
  22.      
  23.     --Target Frame
  24.     local ft = CreateFrame("Button", "FarmootTargetPortrait", UIParent, "SecureUnitButtonTemplate")
  25.     fp.Target = ft -- based on suggestion of Fizzlemizz
  26.     ft:SetSize(70, 70)
  27.     ft:SetPoint("CENTER", 110, -350)
  28.     ft:SetAttribute("unit", "target")
  29.     RegisterUnitWatch(ft)
  30.     ft:SetAttribute("toggleForVehicle", true)
  31.     ft:RegisterForClicks("AnyUp")
  32.     ft:SetAttribute("*type1", "target")
  33.     ft:SetAttribute("*type2", "togglemenu")
  34.     ft:SetAttribute("*type3", "assist")
  35.     ft.Texture = ft:CreateTexture("$parent_Texture", "BACKGROUND")
  36.     ft.Texture:SetAllPoints()
  37.     ft.Border = ft:CreateTexture("$parent_Border", "BORDER")
  38.     ft.Border:SetPoint("TOPLEFT", -6, 4)
  39.     ft.Border:SetPoint("BOTTOMRIGHT", 6, -10)
  40.     ft.Border:SetTexture("Interface/PLAYERFRAME/UI-PlayerFrame-Deathknight-Ring")
  41.     ft.Border:SetVertexColor(1, 1, 0, 1)
  42.     ft:RegisterUnitEvent("UNIT_PORTRAIT_UPDATE", "target")
  43.     ft:RegisterEvent("PLAYER_TARGET_CHANGED") -- based on suggestion of Fizzlemizz
  44.     ft:SetScript("OnEvent", function(self) SetPortraitTexture(self.Texture, "target")  end)
  45.    
  46.     --Target Classification
  47.     local default = "Interface/AddOns/ClassicPortrait/media/default"
  48.     local uClassTextures = {
  49.         worldboss = "Interface/AddOns/ClassicPortrait/media/worldboss",
  50.         boss = "Interface/AddOns/ClassicPortrait/media/boss",
  51.         elite = "Interface/AddOns/ClassicPortrait/media/elite",
  52.         rare = "Interface/AddOns/ClassicPortrait/media/rare",
  53.         rareelite = "Interface/AddOns/ClassicPortrait/media/rareelite",
  54.     }
  55.     local uClass = UnitClassification("target")
  56.     local function OnEvent(self, event, ...)
  57.         if event == "PLAYER_TARGET_CHANGED" and UnitExists("target") then
  58.             self:SetTexture( unitClassTextures[UnitClassification("target")] or default )
  59.         end
  60.         self:RegisterEvent("PLAYER_TARGET_CHANGED")
  61.     end

This display portraits but not classification textutes. I deleted settings and keep those in --Target Frame. i try to follow your advice, but it not easy to write the code.

Fizzlemizz 04-17-19 10:56 AM

Your code above, the target frame (ft) is assigned an OnEvent script using:
Code:

ft:SetScript("OnEvent", function(self) SetPortraitTexture(self.Texture, "target")  end)
It didn't ever assign the OnEvent function (which would have required using a :HookScript or else it would have only replaced (overwritten) the original script that set the portrait texture if you had used SetScript).

This is an example using a single event frame (EventFrame) for all units rather than an OnEvent script for each unit frame. The separate event frame is not required eg. you could use the Player frame for all events, it just helps to make clearer what is happening.

You can add events to OnEventFunc and use it to update the units needed for that event.

Lua Code:
  1. --Target Classification
  2. local default = "Interface/AddOns/ClassicPortrait/media/default"
  3. local uClassTextures = {
  4.     worldboss = "Interface/AddOns/ClassicPortrait/media/worldboss",
  5.     boss = "Interface/AddOns/ClassicPortrait/media/boss",
  6.     elite = "Interface/AddOns/ClassicPortrait/media/elite",
  7.     rare = "Interface/AddOns/ClassicPortrait/media/rare",
  8.     rareelite = "Interface/AddOns/ClassicPortrait/media/rareelite",
  9. }
  10.  
  11. local UnitFrames = {} -- holder for unit frames created, Stored as UnitFrames[unit id] = frame
  12.  
  13. local fp = CreateFrame("Button", "FarmootPlayerPortrait", UIParent, "SecureUnitButtonTemplate")
  14. UnitFrames.player = fp -- add the player frame to the UnitFrames table
  15. fp:SetSize(70, 70)
  16. fp:SetPoint("CENTER", -80, -350)
  17. fp:SetAttribute("unit", "player")
  18. RegisterUnitWatch(fp)
  19. fp:SetAttribute("toggleForVehicle", true)
  20. fp:RegisterForClicks("AnyUp")
  21. fp:SetAttribute("*type1", "target")
  22. fp:SetAttribute("*type2", "togglemenu")
  23. fp:SetAttribute("*type3", "assist")
  24. fp.Texture = fp:CreateTexture("$parent_Texture", "BACKGROUND")
  25. fp.Texture:SetAllPoints()
  26. --SetPortraitTexture(fp.Texture, "player")
  27. fp.Border = fp:CreateTexture("$parent_Border", "BORDER")
  28. fp.Border:SetPoint("TOPLEFT", -6, 4)
  29. fp.Border:SetPoint("BOTTOMRIGHT", 6, -10)
  30. fp.Border:SetTexture("Interface/PLAYERFRAME/UI-PlayerFrame-Deathknight-Ring")
  31. fp.Border:SetVertexColor(1, 1, 0, 1)
  32.  
  33. --Target Frame
  34. local ft = CreateFrame("Button", "FarmootTargetPortrait", UIParent, "SecureUnitButtonTemplate")
  35. UnitFrames.target = ft -- add the target frame to the UnitFrames table
  36. ft:SetSize(70, 70)
  37. ft:SetPoint("CENTER", 110, -350)
  38. ft:SetAttribute("unit", "target")
  39. RegisterUnitWatch(ft)
  40. ft:SetAttribute("toggleForVehicle", true)
  41. ft:RegisterForClicks("AnyUp")
  42. ft:SetAttribute("*type1", "target")
  43. ft:SetAttribute("*type2", "togglemenu")
  44. ft:SetAttribute("*type3", "assist")
  45. ft.Texture = ft:CreateTexture("$parent_Texture", "BACKGROUND")
  46. ft.Texture:SetAllPoints()
  47. ft.Border = ft:CreateTexture("$parent_Border", "BORDER")
  48. ft.Border:SetPoint("TOPLEFT", -6, 4)
  49. ft.Border:SetPoint("BOTTOMRIGHT", 6, -10)
  50. ft.Border:SetVertexColor(1, 1, 0, 1)
  51.  
  52. local function OnEventFunc(self, event, ...)
  53.     local arg1 = ... -- add more args depending returns from on events used. UNIT_xxx events return the unit id ("player", "target" etc.) as arg1 (being first parameter of ...).
  54.     -- UnitFrames[arg1] eg. UnitFrames["player"]
  55.     if event == "UNIT_PORTRAIT_UPDATE" and UnitFrames[arg1] then
  56.         SetPortraitTexture(UnitFrames[arg1].Texture, arg1)
  57.     elseif event == "PLAYER_TARGET_CHANGED" and UnitExists("target") then
  58.         SetPortraitTexture(UnitFrames.target.Texture, "target")
  59.         UnitFrames.target.Border:SetTexture(uClassTextures[UnitClassification("target")] or default)
  60.     end
  61. end
  62. local EventFrame = CreateFrame("Frame")
  63. EventFrame:SetScript("OnEvent", OnEventFunc)
  64. EventFrame:RegisterEvent("UNIT_PORTRAIT_UPDATE")
  65. EventFrame:RegisterEvent("PLAYER_TARGET_CHANGED")


All times are GMT -6. The time now is 03:44 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI