Accessing fontstring from secure snippet
Hello. I'm trying to implement simple raid frames. Here's what I've come up with so far:
XML: XML Code:
Lua Code:
It works with static label, but I'm struggling to set name dynamically. I've commented line that does not work. As far as I understood, self refers to frame handle and this frame handle does not have "name" key (which I expected to be set from XML parentKey attribute). I tried to use self:GetFrameRef("name"), but it returns null. I guess I have to register it earlier, but I can't figure out how do I do that. UnitName is not available either, so I'm further confused atm. I guess, I'm doing something seriously wrong. If possible, I prefer to keep XML for UI layouts instead of coding it all with Lua. Also, if possible, it should work in combat (so people entering/leaving raid won't brake frames, that's why I'm using SecureGroupHeaderTemplate). |
Fontstrings and textures are not secure; you update them through unrestricted code to reflect the current state of the secure frame.
You can think of the visible parts of your unit frame as something separate that sits on top of the secure, clickable portion underneath. Decoration. |
It seems that the proper way to update unit information is OnAttributeChanged handler. Something like
Lua Code:
|
Quote:
The proper way is to register for specific events that indicate specific information changes, and update only the relevant portions of your frame when they fire. For example, update the name string when UNIT_NAME_UPDATE fires; the level string when UNIT_LEVEL fires; the health bar when UNIT_HEALTH, UNIT_HEALTH_FREQUENT, or UNIT_MAXHEALTH fire; etc. See the unit events list on Wowpedia for a list of relevant events. Also, use RegisterUnitEvent(event, unit) instead of RegisterEvent(event) so that your frame only receives events for the unit it's displaying. For some frames, you'd also want to update everything when certain events fire -- for example, for a target frame, you'd need to listen for PLAYER_TARGET_CHANGED to know when you selected a different target, since e.g. UNIT_NAME_UPDATE doesn't fire in that case (the unit's name didn't change when you targeted it!). Finally, "*target" units (targettarget, focustarget, raid12pettarget, etc.) don't fire unit events at all, so you just have to update everything in an OnUpdate handler. You can look at how oUF handles these events for an example. |
Thanks. Currently I'm making specifically raid frames (or party frames if I'm in party) based on SecureGroupHeaderTemplate and they seem to work with OnAttributeChanged way. If someone joins, each unit frame updates with new unit, if someone leaves, last frame updates with null unit, etc. At least from my limited testing with some people joining and leaving. Here's my snippet:
Lua Code:
PS UNIT_HEALTH_FREQUENT is so weird. Combat log events arriving 200-300 ms earlier than UNIT_HEALTH_FREQUENT so parsing combat log would make unit frames a bit more responsive, but it's quite a headache, why WoW implemented this way I just don't understand, it's not even about throttling, a single npc swinging me every few seconds still shows the same lag between combat log event and UNIT_HEALTH_FREQUENT event. And with heals this problem is not present, I'm receiving UNIT_HEALTH_FREQUENT exactly at the same time as heal combat log event. |
All times are GMT -6. The time now is 03:02 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI