04-13-19, 09:52 AM | #1 |
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) Thank you for your help. |
|
04-13-19, 10:07 AM | #2 |
You need to change the portrait when your target changes (and you had one fp.xxx in your ft.xxx section)
Eg. Lua Code:
__________________
Fizzlemizz Maintainer of Discord Unit Frames and Discord Art. Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus. Last edited by Fizzlemizz : 04-13-19 at 10:44 AM. |
|
04-13-19, 04:09 PM | #3 | |
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.
__________________
WoWInterface AddOns
|
||
04-13-19, 04:11 PM | #4 |
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.
|
|
04-13-19, 04:21 PM | #5 |
You are indeed correct.
__________________
Fizzlemizz Maintainer of Discord Unit Frames and Discord Art. Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus. |
|
04-13-19, 04:22 PM | #6 |
You should post the new code so we can see what might be happening.
__________________
Fizzlemizz Maintainer of Discord Unit Frames and Discord Art. Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus. |
|
04-13-19, 04:44 PM | #7 |
I have this code :
Lua Code:
But with this code, I have player frame and not target frame^^ |
|
04-13-19, 05:46 PM | #8 |
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? |
|
04-13-19, 05:59 PM | #9 |
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.
|
|
04-13-19, 06:17 PM | #10 |
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:
__________________
Fizzlemizz Maintainer of Discord Unit Frames and Discord Art. Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus. Last edited by Fizzlemizz : 04-13-19 at 06:54 PM. |
|
04-14-19, 01:50 PM | #11 |
Thank you for your help. That works ! I will continue to work on this code and will go back here if I've questions.
|
|
04-16-19, 05:06 AM | #12 |
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:
I verify in game on an elite unit but the addons display nothing. Thank again for your help and have a good day |
|
04-16-19, 09:56 AM | #13 |
Lua Code:
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") 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.
__________________
Fizzlemizz Maintainer of Discord Unit Frames and Discord Art. Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus. Last edited by Fizzlemizz : 04-16-19 at 01:31 PM. |
|
04-17-19, 04:18 AM | #14 |
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:
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. |
|
04-17-19, 10:56 AM | #15 |
Your code above, the target frame (ft) is assigned an OnEvent script using:
Code:
ft:SetScript("OnEvent", function(self) SetPortraitTexture(self.Texture, "target") end) 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:
__________________
Fizzlemizz Maintainer of Discord Unit Frames and Discord Art. Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus. Last edited by Fizzlemizz : 04-17-19 at 02:01 PM. |
|
WoWInterface » Developer Discussions » Lua/XML Help » Create target 2D portrait |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|