Thread Tools Display Modes
12-18-14, 03:46 AM   #1
Lights
A Murloc Raider
Join Date: Dec 2014
Posts: 4
Texture @ Health Percent - Weak Auras (Or Lua?)

Hey!

I've recently begun trying to bring a UI concept into the game, but I've hit my first stump. I've looked for help on other locations but, ultimately, wasn't able to find an answer, but I saw quite a few mentions of this site being knowledgeable.

I wanted to use large numbers as a means of tracking my own health but, due to WoW's font-size restriction bit, I've tried to create a work around. I created a texture of each digit and aimed to have Weak Auras display each digit in its corresponding numerical place when the player's health reached a specific value. For example, at 80 health, there would be an "8" in the tens position and a "0" in the ones position. I used multiple triggers for each digit, such as "Health = 10", "Health = 20', etc., for zero. Unfortunately, this didn't work, and nothing displayed at all. (But the textures appear fine when configuring, etc, so it's not an importing error)

One helpful poster from another forum mentioned that this could be due to the trigger being read as "Health = 10.00%" at that exact value and not at, say, 10.25% health. This seemed very logical, but creating this in Weak Auras with the preset triggering capabilities (to my knowledge) would require using two triggers of "Health >= 10%" and "Health < 11%" and using the "All Triggers" functionality. Unfortunately, this would require creating a Weak Auras texture for each value, 1-100.


Thus, I assumed there would be a much easier way to create this using some kind of "or" custom trigger in Weak Auras along the lines of:

"10 <= X < 11 /or/ 20 <= X < 21 /or/ " etc.

Of course, I have no idea how I'd go about doing something like that, so I wanted to ask those that are substantially more knowledgeable on this subject.


Any help is greatly appreciated & thank you in advance!
  Reply With Quote
12-18-14, 04:03 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I can't help with WeakAuras as I've never used it, but if you wanted to just write your own addon, you could probably use the code in Blizzard's FrameXML/Timer.lua as a base.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
12-18-14, 05:47 PM   #3
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Make 3 textures, one for each digit you want to display.

On UNIT_HEALTH_FREQUENT or UNIT_HEALTH round your health percentage to the nearest integer, format it as a string and loop over the characters with string.sub to figure out which digit should be displayed by which texture.
  Reply With Quote
12-19-14, 04:23 AM   #4
Lights
A Murloc Raider
Join Date: Dec 2014
Posts: 4
Thank you both for the replies!

Unfortunately, I know literally nothing about Lua. I can't really follow what's going on in the linked .lua file, and I'm not quite sure what UNIT_HEALTH_FREQUENT & UNIT_HEALTH are - I assume some sort of events / triggers for the "custom" portion of Weak Auras?

I'd appreciate it if you could help me understand what these UNIT_HEALTH bits mean, or guide me to a place where I can understand them.

Again, thank you for the help, but my complete and utter lack of knowledge on this topic renders me confused. ):
  Reply With Quote
12-19-14, 10:06 AM   #5
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
If you want to do this entirely in weak auras, the way I would do it is create a separate aura for each digit.

Make a trigger for each one so that they're updated every time the player's health changes.

Each digit should have a function that determines what number it should be displaying every time that trigger happens.

You'll have to figure out where to put this since I don't use weak auras, but the function should look something like this..
Lua Code:
  1. function()
  2.     local whichDigit = 1
  3.     local percentStr = format('%03d', (UnitHealth('player') / UnitHealthMax('player') + 0.005) * 100)
  4.     return percentStr:sub(whichDigit, whichDigit)
  5. end

Just change "whichDigit" to 1, 2 or 3 depending on whether the aura should be displaying the first, second or third digit.

That function will display leading zeros, so you'll end up with "005" for 5%, if you want to hide the textures that represent leading zeros you'll need another trigger to hide them.

This function will return true if the digit is not a leading zero and false if it is, you should be able to use it to determine whether the texture should be shown or hidden.
Lua Code:
  1. function()
  2.     local whichDigit = 1 -- change this to which digit this function represents (1, 2 or 3)
  3.     local percentStr = format('%03d', (UnitHealth('player') / UnitHealthMax('player') + 0.005) * 100)
  4.     local leadingNumbers = 0 -- sum of digits from the left including this one
  5.     for i = 1, whichDigit do
  6.         leadingNumbers = leadingNumbers + percentStr:sub(i, i)
  7.     end
  8.     return leadingNumbers > 0 -- true if this should be displayed, false if it shouldn't
  9. end
  Reply With Quote
12-19-14, 01:36 PM   #6
Lights
A Murloc Raider
Join Date: Dec 2014
Posts: 4
I'd want to create it using whatever method is easier for you (Which I assume is through its own files), as you're the one helping me. The only reason I opened with Weak Auras is because I assumed it was easier, which was a silly mistake on my part, so scratch Weak Auras entirely.

With that in mind, I'm not sure how I'd go about creating files or organizing these code bits specifically for this function, but I'm sure that's easily Google-able if it's a lot of information.

So, I suppose the next question would be: what more do I need to add to now get the textures to display according to that string? I hope I'm not asking too much - Sorry! ):



Also, I completely forgot to mention in the original post, oops, but (for design purposes), I'd want full health (or from whatever percent value gets rounded to 100) to display as 99 & for single digit values to show their 0. Therefore, there wouldn't be a third digit place for the 1xx or 0xx at all, and the display would read 00, 01, 02, etc to the max of 99.


Again, thank you very much for the help.
  Reply With Quote
12-19-14, 05:46 PM   #7
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
What about http://www.wowinterface.com/download...-oUF_Text.html?
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote
12-19-14, 08:39 PM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by rocnroll View Post
Based on the name and screenshot it is in fact using text, which will not solve the problem OP is trying to solve, which is that text in WoW can't be bigger than 32px.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
12-20-14, 12:28 AM   #9
Tim
A Rage Talon Dragon Guard
 
Tim's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 309
oUF_Hank uses a texture and texcoords to display health numbers. It won't help the op that much since he/she has no clue how to code not to mention it hasn't been updated since middle of 2011.
  Reply With Quote
12-20-14, 11:24 AM   #10
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
I've thrown together something. It's untested though. So I am not sure if it will work out of the box.

Paste the code into http://addon.bool.no
Name your new addon "BigHealth".
Create a new image (see http://wow.gamepedia.com/TGA_files if you're running into problems) with the name digits.tga (eg. width 1024px, height 128px) and save it into your new addon (BigHealth) folder. Edit the image to contain the numbers from 0 to 9 from left to right. Each number should have a size of ~ 102 x 128 (w/h) pixels. The resulting image should look like "0123456789".

The addon will create a movable frame with 3 textures showing numbers. The number texture is taken from the appropiate area of the texture file.

Lua Code:
  1. local xPosition = 0
  2. local yPosition = 0
  3. local digitHeight = 100
  4. local digitWidth = 50
  5.  
  6. local AddonName, Addon = ...
  7.  
  8. function Addon:CreateHealthFrame()
  9.  
  10.     Addon.HealthFrame = CreateFrame("Frame", "HealthFrame", UIParent)
  11.    
  12.     Addon.HealthFrame:SetFrameStrata("HIGH")
  13.     Addon.HealthFrame:SetPoint("CENTER", UIParent, "CENTER", xPosition, yPosition)
  14.     Addon.HealthFrame:SetHeight(digitHeight)
  15.     Addon.HealthFrame:SetWidth(digitWidth * 3)
  16.     Addon.HealthFrame:SetBackdrop({bgFile="Interface\\Tooltips\\UI-Tooltip-Background", edgeFile="", tile = false, tileSize = 1, edgeSize = 10, insets = { left = 0, right = 0, top = 0, bottom = 0 }})
  17.     Addon.HealthFrame:SetBackdropColor(0, 0, 0, 1)
  18.    
  19.     Addon.HealthFrame:SetClampedToScreen(true)
  20.     Addon.HealthFrame:SetScript("OnDragStart", function(self)
  21.         self:StartMoving()
  22.     end)
  23.     Addon.HealthFrame:SetScript("OnDragStop", function(self)
  24.         self:StopMovingOrSizing()
  25.     end)
  26.     Addon.HealthFrame:SetMovable(true)
  27.     Addon.HealthFrame:RegisterForDrag("LeftButton")
  28.     Addon.HealthFrame:EnableMouse(true)
  29.    
  30.     Addon.HealthFrame.digit1 = HealthFrame:CreateTexture("Digit1","ARTWORK")
  31.     Addon.HealthFrame.digit1:SetPoint("TOPLEFT", HealthFrame, "TOPLEFT", 0, 0)
  32.     Addon.HealthFrame.digit1:SetHeight(digitHeight)
  33.     Addon.HealthFrame.digit1:SetWidth(digitWidth)
  34.     Addon.HealthFrame.digit1:SetTexture("Interface\\Addons\BigHealth\\digits.tga")
  35.  
  36.     Addon.HealthFrame.digit2 = HealthFrame:CreateTexture("Digit2","ARTWORK")
  37.     Addon.HealthFrame.digit2:SetPoint("TOPLEFT", HealthFrame, "TOPLEFT", digitWidth, 0)
  38.     Addon.HealthFrame.digit2:SetHeight(digitHeight)
  39.     Addon.HealthFrame.digit2:SetWidth(digitWidth)
  40.     Addon.HealthFrame.digit2:SetTexture("Interface\\Addons\BigHealth\\digits.tga")
  41.  
  42.     Addon.HealthFrame.digit3 = HealthFrame:CreateTexture("Digit3","ARTWORK")
  43.     Addon.HealthFrame.digit3:SetPoint("TOPLEFT", HealthFrame, "TOPLEFT", digitWidth * 2, 0)
  44.     Addon.HealthFrame.digit3:SetHeight(digitHeight)
  45.     Addon.HealthFrame.digit3:SetWidth(digitWidth)
  46.     Addon.HealthFrame.digit3:SetTexture("Interface\\Addons\BigHealth\\digits.tga")
  47.    
  48.     Addon.HealthFrame:SetScript("OnEvent", function(pSelf, pEvent, pUnitID)
  49.  
  50.         if pUnitID == "player" then
  51.        
  52.             local tHealth = UnitHealth("player")
  53.             local percentStr = format('%03d', (tHealth / tHealth + 0.005) * 100)
  54.            
  55.             pSelf.digit1:SetTexCoord(percentStr:sub(1, 1) / 10, (percentStr:sub(1, 1) / 10) + 0.1, 1, 0)
  56.             pSelf.digit2:SetTexCoord(percentStr:sub(2, 2) / 10, (percentStr:sub(2, 2) / 10) + 0.1, 1, 0)
  57.             pSelf.digit3:SetTexCoord(percentStr:sub(3, 3) / 10, (percentStr:sub(3, 3) / 10) + 0.1, 1, 0)
  58.        
  59.         end
  60.        
  61.     end)
  62.    
  63.     HealthFrame:RegisterEvent("UNIT_HEALTH")
  64.    
  65. end
  66.  
  67. Addon:CreateHealthFrame()

Last edited by Duugu : 12-20-14 at 11:33 AM.
  Reply With Quote
12-27-14, 04:32 PM   #11
Lights
A Murloc Raider
Join Date: Dec 2014
Posts: 4
Sorry for not responding sooner, I've been super busy with Christmas-related stuff! (Happy Holidays!!)

Anywho,

Thank you Duugu for the code. I tried to get it to work, but I had some weird bits occur.
First of all, prior to my health changing at all, the full .tga is loaded into each digit space. Or, there is a "0123456789" re-sized and condensed into each position. After taking damage, the display shows numbers, but it displays 100 regardless of my health percent and, for some reason, is upside down? I had a good chuckle out of it being upside down, but I'm clueless as to why that occurred.


And thank you for the oUF_Hank reference, Tim. I'll see if I can figure it out and change values around, if it works without any updates.


Thanks again!
  Reply With Quote
12-27-14, 06:55 PM   #12
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Originally Posted by Lights View Post
Thank you Duugu for the code. I tried to get it to work, but I had some weird bits occur.
First of all, prior to my health changing at all, the full .tga is loaded into each digit space. Or, there is a "0123456789" re-sized and condensed into each position. After taking damage, the display shows numbers, but it displays 100 regardless of my health percent and, for some reason, is upside down? I had a good chuckle out of it being upside down, but I'm clueless as to why that occurred.
Well, my subscription is expired and there's no PTR. Maybe someone else can fix this for you. Sorry. :/
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Texture @ Health Percent - Weak Auras (Or Lua?)

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