Topic Question on UnitFrames addon
Does anyone know a really cleanly coded Unit Frames addon? I'm looking for one to try and understand the inner working of how the textures are being moved. I understand the UNIT_HEALTH event is firing and the addon is calculating the percentage drop in health by getting the max and current health and then sending an update to the frame, but I'm not sure how to set the texture or repaint it.
Again. Nice, cleanly coded Unit Frames addon for me to get my hands dirty with.
Unit Frames use StatusBar objects (created with CreateFrame("StatusBar", ...)) to display health/mana bars. All you need to do is use the :SetMinMaxValues method when the unit's max health changes to set the bounds of the bar then use the :SetValue method when the unit's current health changes to change the size of the texture.
You can see the relevant StatusBar methods here:
As for a unit frame AddOn to look at, you could try the default UI (specifically TextStatusBar.lua/xml, PlayFrame.lua/xml and TargetFrame.lua/xml), oUF (which is a framework rather than a stand-alone AddOn) or PitBull4.
To extract Blizzard's interface code, you can follow these instructions:
You can also view it online here:
WoW Programming tends to be a bit slow to update its interface code. Go-Hero is quicker to update and has a few features that WoW Programming doesn't, like function links and the ability to navigate directly to a file or function from the search feature.
Edited by Choonster on 12/4/12 8:14 AM (PST)
Sure, you'd just have do a bit more of the updating manually. Create a texture for the bar and another for the arrow then every time the unit's health changes, anchor the arrow texture (current_hp/max_hp) * bar_width units to the right of the bar's left edge.
Something like this (the forums aren't wide enough to display the comments properly, you should copy/paste it into your text/code editor of choice):