Thread Tools Display Modes
11-25-10, 10:34 AM   #1
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
Hud status bar questions.

Okay so i have been fiddling around and i can not for the life of me figure out how it is people get status bars that are not just straight. Like IceHud and DHUD. Someone point me in the right direction? I tried things like using setmask and simple setstatus bar textures with my status bar masks but they dont fill the way you would think... the texture appears to grow rather then "fill" the background texture.
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
11-25-10, 11:30 AM   #2
Dawn
A Molten Giant
 
Dawn's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 918
Try to use

yourbar:GetStatusBarTexture():SetHorizTile(true / false)

While you can set it to true or false. True should work, iirc.

And you need a texture with an alpha channel or a transparent blp, ofc.
__________________
Rock: "We're sub-standard DPS. Nerf Paper, Scissors are fine."
Paper: "OMG, WTF, Scissors!"
Scissors: "Rock is OP and Paper are QQers. We need PvP buffs."

"neeh the game wont be remembered as the game who made blizz the most money, it will be remembered as the game who had the most QQ'ers that just couldnt quit the game for some reason..."

  Reply With Quote
11-25-10, 12:44 PM   #3
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
is there a setvertictile to?
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
11-25-10, 01:03 PM   #4
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
Hmm i think i need to use the animation system for what im after...
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
11-25-10, 01:33 PM   #5
Dawn
A Molten Giant
 
Dawn's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 918
Yes that works for vertical, too.

Texture:SetVertTile()
__________________
Rock: "We're sub-standard DPS. Nerf Paper, Scissors are fine."
Paper: "OMG, WTF, Scissors!"
Scissors: "Rock is OP and Paper are QQers. We need PvP buffs."

"neeh the game wont be remembered as the game who made blizz the most money, it will be remembered as the game who had the most QQ'ers that just couldnt quit the game for some reason..."

  Reply With Quote
11-25-10, 01:40 PM   #6
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
its still not working like it should. If you have a curved background and you want it to look like it fills up how do you do that?
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
11-28-10, 01:01 PM   #7
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
what if we change the math from turning it into a percent to making it the actual number. That would be most accurate and i think it is why it fills before it should... when it hits a less then 1% amount it shows it filled all the way. so from 0 - 0.99% the bar is filled... or instead of changing it from percent add a decimal to the number system so that it reads the 0.01 - 0.99% which would also make it more accurate... not as accurate as the actual number. Im good with the theory just not so good with the actual math in code

edit - my numbers are off it would actually be when the bar displays 99.00- 99.99% i would imagine although i have not tested it the same will go for the low end. ex. your bar will show empty before you actually die when it trys to display the 0.99-0.01%

edit - another thought... the math system most likely rounds percents that do not have decimals in the equation. My guess is its right at 99.50% that it shows filled and that last .50 gets lost.

yet another edit - thinking about it and trying to come up with a solution i realized the heal prediction bar is most likely off by the same .xx% amounts.

yet again... - im not positive i understand this entirely but would it be as simple as changing local hppcnt=hcur/math.max(1,hmax); to local hppcnt=hcur/math.max(0.01,hmax);

And no its not at 99.50% its more like 95%
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]

Last edited by Grimsin : 11-28-10 at 01:17 PM.
  Reply With Quote
11-28-10, 03:11 PM   #8
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
same issue with the pet bars only a lot worse since they are much smaller textures but the same canvas size. The problem is not with the numbers and %'s but with the texture getting its top origin from the canvas edge..


Okay... one last variable needs to be added to the function. One that allows you to set the texture edge offset. So lets say your ( is 250 pixels top to bottom but your canvas itself is 256, as all textures have to be powers of 2, the new variable would allow for one to set the graphic within the textures offset... hmmm crap well depending on the orientation of the bar you would actually need 4 settings. For my bar layout i only need the top to bottom settings but yea.... need another variable to accommodate for textures that do not fill the canvas size. The way things are right now what ever the difference is between the graphic and the texture canvas edges is being lost.

Is there any limit to the number of variables passed to a function? hope not lol...
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]

Last edited by Grimsin : 11-28-10 at 03:23 PM.
  Reply With Quote
11-28-10, 05:02 PM   #9
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
I was talking about the UI texture object that you load the image into, and with health and mana at 40k+ starting at 80, you'd have to have a pretty large chunk taken out of your pool before the bar can even move one pixel. Also be aware of any transparent pixels padding the bar in the actual image, they'd be read in as part of the bar too.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
11-28-10, 05:19 PM   #10
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
Originally Posted by SDPhantom View Post
I was talking about the UI texture object that you load the image into, and with health and mana at 40k+ starting at 80, you'd have to have a pretty large chunk taken out of your pool before the bar can even move one pixel. Also be aware of any transparent pixels padding the bar in the actual image, they'd be read in as part of the bar too.
Yea the problem is the padding is reading as part of the bar. That is the whole problem it would appear. Question is how to figure in that padding distance because unfortunately i can not remove it all. It should be possible to add another variable to the function that allows you to enter the padding offsets to the calculation. This is what things are looking like right now in whole. I know its doable. It should be as simple as adding the padding offsets to the texcoord settings somewhere.

lua Code:
  1. local addonName, addon = ...
  2.  
  3. addon:RegisterDefaultSetting("hudShow", true)
  4. addon:RegisterDefaultSetting("hudWidth", 100)
  5. addon:RegisterDefaultSetting("hudHeight", 100)
  6. addon:RegisterDefaultSetting("hudScale", 1)
  7.  
  8. local GHudMain = CreateFrame("Frame", "GHudMain", UIParent)
  9.  
  10. GHudMain:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
  11. GHudMain:SetHeight(3)
  12. GHudMain:SetWidth(3)
  13.  
  14. GHudMain:RegisterEvent("PLAYER_TARGET_CHANGED")
  15. GHudMain:RegisterEvent("UNIT_PET", "player")
  16. GHudMain:SetScript("OnEvent", function(event)
  17.     addon:SetHudBackgrounds()
  18. end)
  19.  
  20. function addon:SetupGHud()
  21.     if addon.settings.hudShow then
  22.         GHudMain:Show()
  23.     else
  24.         GHudMain:Hide()
  25.     end
  26. end
  27.  
  28. function addon:GHudScale()
  29.     GHudMain:SetScale(addon.settings.hudScale)
  30. end
  31.  
  32. --[[-----------------------------------------------------------------------------
  33. The IMPORTANT PART! Bar fill function, dont f with this.
  34. -------------------------------------------------------------------------------]]
  35. function addon:SetBarValue(bar,val1,val2, topoff, bottomoff, rightoff, leftoff, flipH,flipV)-- Accepts 3 values, bar texture, start value, and end value
  36.     --  Keep the values within a 0-1 range
  37.     val1=math.min(math.max(val1,0),1);
  38.     val2=math.min(math.max(val2,0),1);
  39.     --  Sometimes textures glitch when trying to set a width or height of 0, so handle it here
  40.     if val1==val2 then
  41.         bar:Hide();
  42.         return;
  43.     else
  44.         bar:Show();
  45.     end
  46.     --  Set our low and high values
  47.     local low,high = math.min(val1,val2),math.max(val1,val2);
  48.    
  49.    
  50.     if bottomoff ~= 0 then
  51.         --low = math.min(val1-bottomoff,val2-bottomoff)
  52.     end
  53.     if topoff ~= 0 then
  54.         --high = math.max(val1-topoff,val2-topoff);
  55.     end
  56.     if rightoff ~= 0 then
  57.    
  58.     end
  59.     if leftoff ~= 0 then
  60.    
  61.     end
  62.    
  63.     --  Find our parent width and height
  64.     local parent=bar:GetParent();
  65.     local w,h=parent:GetWidth(),parent:GetHeight();
  66.     --  Get our point set, we'll use this to get our bar orientation
  67.     local point=bar:GetPoint(1);
  68.     if not point then return; end-- Handle if point isn't set, perhaps cleared?
  69.     --  These are our temp origin variables (note one of these pairs can have both vars nil, just use default texcoords for those)
  70.     local origL=point:find("LEFT$");
  71.     local origR=point:find("RIGHT$");
  72.     local origT=point:find("^TOP");
  73.     local origB=point:find("^BOTTOM");
  74.     --  Reset point (logic nightmare)
  75.     bar:SetPoint(point
  76.         ,(origL or origR) and (origL and low*w or -low*w) or 0--    X offset
  77.         ,(origT or origB) and (origB and low*h or -low*h) or 0--    Y offset
  78.     );
  79.     --  Texcoord/Size set (this is actually the easy part)
  80.     local l,r,t,b = 0,1,0,1;--    Texcoords are in the range of 0-1 with their origin at top left
  81.     if origL then
  82.         l,r = low, high;
  83.     elseif origR then
  84.         l,r = 1-high,1-low;
  85.     end
  86.     if origT then
  87.         t,b = low,high;
  88.     elseif origB then
  89.         t,b = 1-high,1-low;
  90.     end
  91.     --  Process flip (affects which side the bar piece is drawn from too)
  92.     if flipH then l,r=1-l,1-r; end
  93.     if flipV then t,b=1-t,1-b; end
  94.    
  95.     bar:SetTexCoord(l,r,t,b);
  96.     bar:SetWidth(w*math.abs(r-l));
  97.     --bar:SetWidth(w*(r-l));
  98.     bar:SetHeight(h*math.abs(b-t));
  99.     --bar:SetHeight(h*(b-t));
  100. end
  101.  
  102. --[[-----------------------------------------------------------------------------
  103. Main Bar Creations
  104. -------------------------------------------------------------------------------]]
  105. local PlayerHBar = CreateFrame("Frame",nil, GHudMain);
  106. local PlayerMBar = CreateFrame("Frame",nil, GHudMain);
  107. local TargetHBar = CreateFrame("Frame",nil, GHudMain);
  108. local TargetMBar = CreateFrame("Frame",nil, GHudMain);
  109. local PPetHBar = CreateFrame("Frame",nil, GHudMain);
  110. local PPetMBar = CreateFrame("Frame",nil, GHudMain);
  111.  
  112. function addon:LayoutHudBars()
  113.     PlayerHBar:ClearAllPoints()
  114.     PlayerHBar:SetPoint("RIGHT", GHudMain, "LEFT", - addon.settings.hudWidth, addon.settings.hudHeight);-- Place frame wherever
  115.     PlayerMBar:ClearAllPoints()
  116.     PlayerMBar:SetPoint("LEFT", GHudMain, "RIGHT", addon.settings.hudWidth, addon.settings.hudHeight);
  117.    
  118.     TargetHBar:ClearAllPoints()
  119.     TargetHBar:SetPoint("RIGHT", GHudMain, "LEFT", - addon.settings.hudWidth, addon.settings.hudHeight);-- Place frame wherever
  120.     TargetMBar:ClearAllPoints()
  121.     TargetMBar:SetPoint("LEFT", GHudMain, "RIGHT", addon.settings.hudWidth, addon.settings.hudHeight);
  122.  
  123.     PPetHBar:ClearAllPoints()
  124.     PPetHBar:SetPoint("RIGHT", GHudMain, "LEFT", - addon.settings.hudWidth, addon.settings.hudHeight);-- Place frame wherever
  125.     PPetMBar:ClearAllPoints()
  126.     PPetMBar:SetPoint("LEFT", GHudMain, "RIGHT", addon.settings.hudWidth, addon.settings.hudHeight);
  127. end
  128.  
  129. PlayerHBar:SetWidth(128);--Width
  130. PlayerHBar:SetHeight(256);--Height
  131.  
  132. PlayerMBar:SetWidth(128);--Width
  133. PlayerMBar:SetHeight(256);--Height
  134.  
  135. TargetHBar:SetWidth(128);--Width
  136. TargetHBar:SetHeight(256);--Height
  137.  
  138. TargetMBar:SetWidth(128);--Width
  139. TargetMBar:SetHeight(256);--Height
  140.  
  141. PPetHBar:SetWidth(128);--Width
  142. PPetHBar:SetHeight(256);--Height
  143.  
  144. PPetMBar:SetWidth(128);--Width
  145. PPetMBar:SetHeight(256);--Height
  146.  
  147.  
  148. --  Note: It's generally a good idea to use the same dimensions as your image file for your frame size
  149.  
  150. function addon:SetHudBackgrounds()
  151.     if UnitExists("target") then
  152.         if UnitExists("pet") then
  153.             PlayerHBar.Background:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\bg_21p");--   Your bar image
  154.             PlayerMBar.Background:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\bg_21p");--Your bar image
  155.         else
  156.             PlayerHBar.Background:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\bg_21");--   Your bar image
  157.             PlayerMBar.Background:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\bg_21");--Your bar image
  158.         end
  159.     else
  160.         if UnitExists("pet") then
  161.             PlayerHBar.Background:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\bg_1p");--   Your bar image
  162.             PlayerMBar.Background:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\bg_1p");--Your bar image
  163.         else
  164.             PlayerHBar.Background:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\bg_1");--   Your bar image
  165.             PlayerMBar.Background:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\bg_1");--Your bar image
  166.         end
  167.     end
  168. end
  169.  
  170. --Left Side
  171. --  Background texture
  172. PlayerHBar.Background = PlayerHBar:CreateTexture(nil,"BACKGROUND");
  173. PlayerHBar.Background:SetAllPoints(PlayerHBar);--We want the texture spread to match the dimensions of the frame.
  174. PlayerHBar.Background:SetAlpha(0.25)--Special suprize (black background at a quarter alpha)
  175.  
  176. --Right Side
  177. --  Background texture
  178. PlayerMBar.Background = PlayerMBar:CreateTexture(nil,"BACKGROUND");
  179. PlayerMBar.Background:SetAllPoints(PlayerMBar);--We want the texture spread to match the dimensions of the frame.
  180. PlayerMBar.Background:SetAlpha(0.25)
  181. PlayerMBar.Background:SetTexCoord(1,0,0,1)
  182.  
  183.  
  184.  
  185. --[[-----------------------------------------------------------------------------
  186. Player Bars
  187. -------------------------------------------------------------------------------]]
  188. PlayerHBar.HealthBar = PlayerHBar:CreateTexture(nil,"ARTWORK");--Notice the change in layers, this makes the bar draw on top of the background
  189. PlayerHBar.HealthBar:SetPoint("BOTTOM");--We need only one point set, in this example, the bar fills toward the right, so we need it left-aligned
  190. PlayerHBar.HealthBar:SetWidth(128);--Match frame width for now
  191. PlayerHBar.HealthBar:SetHeight(256);--Match frame height for now
  192. PlayerHBar.HealthBar:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\1");--Be sure to use the same image or one derived from the background
  193.  
  194. -- Player Mana Texture
  195. PlayerMBar.ManaBar = PlayerMBar:CreateTexture(nil,"ARTWORK");--Notice the change in layers, this makes the bar draw on top of the background
  196. PlayerMBar.ManaBar:SetPoint("BOTTOM");--We need only one point set, in this example, the bar fills toward the right, so we need it left-aligned
  197. PlayerMBar.ManaBar:SetWidth(128);--Match frame width for now
  198. PlayerMBar.ManaBar:SetHeight(256);--Match frame height for now
  199. PlayerMBar.ManaBar:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\1");--Be sure to use the same image or one derived from the background
  200.  
  201. --  Heal prediction texture (this'll be my example of a partial bar)
  202. PlayerHBar.HealBar = PlayerHBar:CreateTexture(nil,"ARTWORK");--         Use the same layer as Healthbar
  203. PlayerHBar.HealBar:SetPoint("BOTTOM");--                   Use the same point for the HealthBar
  204. PlayerHBar.HealBar:SetWidth(128);--                    Match frame width for now
  205. PlayerHBar.HealBar:SetHeight(256);--                    Match frame height for now
  206. PlayerHBar.HealBar:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\1");--  Be sure to use the same image or one derived from the background
  207.  
  208. PlayerHBar:RegisterEvent("PLAYER_ENTERING_WORLD");
  209. PlayerHBar:RegisterEvent("UNIT_HEALTH", "player");
  210. PlayerHBar:RegisterEvent("UNIT_HEALTH_PREDICTION");
  211.  
  212. PlayerHBar:SetScript("OnEvent",function(self,event)
  213.     --  Stop handler if unit not player
  214.     --if not UnitIsUnit(unit,"player") then return; end
  215.     local hcur,hmax,heal=UnitHealth("player"),UnitHealthMax("player"),UnitGetIncomingHeals("player") or 0;--    UnitGetIncomingHeals() can return nil for unsupported units
  216.     local hppcnt=hcur/math.max(1,hmax);
  217.     local healpcnt=heal/math.max(1,hmax);
  218.     --  Set our bars (notice the HealBar is a partial bar since it has a start value greater than zero)
  219.     addon:SetBarValue(self.HealthBar,0,hppcnt, 0, 0, 0, 0);
  220.     addon:SetBarValue(self.HealBar,hppcnt,hppcnt+healpcnt, 0, 0, 0, 0);
  221.     --  Color HealthBar (we're keeping HealBar white)
  222.     --  This color formula ranges in color from green, to yellow, to red
  223.     self.HealthBar:SetVertexColor(math.min(2-2*hppcnt,1),math.min(2*hppcnt,1),0);
  224.  
  225. end)
  226.  
  227. PlayerMBar:RegisterEvent("PLAYER_ENTERING_WORLD");
  228. PlayerMBar:RegisterEvent("UNIT_POWER", "player");
  229.  
  230. PlayerMBar:SetScript("OnEvent",function(self,event)
  231.     local pcur, pmax, ptype = UnitPower("player"), UnitPowerMax("player"), UnitPowerType("player");
  232.     local mppcnt = pcur/math.max(1,pmax);
  233.     --  Set our bars (notice the HealBar is a partial bar since it has a start value greater than zero)
  234.     addon:SetBarValue(self.ManaBar,0,mppcnt, 0, 0, 0, 0, "flipH");
  235.     --  Color HealthBar (we're keeping HealBar white)
  236.      if ptype == 0 then
  237.         self.ManaBar:SetVertexColor(.556, .556, .921, 1)
  238.     elseif ptype == 1 or 2 or 3 or 6 then
  239.         self.ManaBar:SetVertexColor(.656, .456, .456, 1)
  240.     end
  241. end)
  242.  
  243. --[[-----------------------------------------------------------------------------
  244. Target Bars
  245. -------------------------------------------------------------------------------]]
  246. TargetHBar.HealthBar = TargetHBar:CreateTexture(nil,"ARTWORK");--Notice the change in layers, this makes the bar draw on top of the background
  247. TargetHBar.HealthBar:SetPoint("BOTTOM");--We need only one point set, in this example, the bar fills toward the right, so we need it left-aligned
  248. TargetHBar.HealthBar:SetWidth(128);--Match frame width for now
  249. TargetHBar.HealthBar:SetHeight(256);--Match frame height for now
  250. TargetHBar.HealthBar:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\2");--Be sure to use the same image or one derived from the background
  251.  
  252. -- Player Mana Texture
  253. TargetMBar.ManaBar = TargetMBar:CreateTexture(nil,"ARTWORK");
  254. TargetMBar.ManaBar:SetPoint("BOTTOM");--We need only one point set, in this example, the bar fills toward the right, so we need it left-aligned
  255. TargetMBar.ManaBar:SetWidth(128);--Match frame width for now
  256. TargetMBar.ManaBar:SetHeight(256);--Match frame height for now
  257. TargetMBar.ManaBar:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\2");--Be sure to use the same image or one derived from the background
  258.  
  259. TargetHBar:RegisterEvent("PLAYER_ENTERING_WORLD");
  260. TargetHBar:RegisterEvent("PLAYER_TARGET_CHANGED");
  261. TargetHBar:RegisterEvent("UNIT_HEALTH", "target");
  262. TargetHBar:RegisterEvent("UNIT_HEALTH_PREDICTION", "target");
  263.  
  264. TargetHBar:SetScript("OnEvent",function(self,event)
  265.     --  Stop handler if unit not player
  266.     --if not UnitIsUnit(unit,"player") then return; end
  267.     local hcur,hmax,heal=UnitHealth("target"),UnitHealthMax("target"),UnitGetIncomingHeals("target") or 0;--    UnitGetIncomingHeals() can return nil for unsupported units
  268.     local hppcnt=hcur/math.max(1,hmax);
  269.     local healpcnt=heal/math.max(1,hmax);
  270.     --  Set our bars (notice the HealBar is a partial bar since it has a start value greater than zero)
  271.     addon:SetBarValue(self.HealthBar,0,hppcnt, 0, 0, 0, 0);
  272.     --addon:SetBarValue(self.HealBar,hppcnt,hppcnt+healpcnt);
  273.  
  274.     self.HealthBar:SetVertexColor(math.min(2-2*hppcnt,1),math.min(2*hppcnt,1),0);
  275.  
  276. end)
  277.  
  278. TargetMBar:RegisterEvent("PLAYER_ENTERING_WORLD");
  279. TargetMBar:RegisterEvent("PLAYER_TARGET_CHANGED");
  280. TargetMBar:RegisterEvent("UNIT_POWER", "target");
  281.  
  282. TargetMBar:SetScript("OnEvent",function(self,event)
  283.     local pcur, pmax, ptype = UnitPower("target"), UnitPowerMax("target"), UnitPowerType("target");
  284.     local mppcnt = pcur/math.max(1,pmax);
  285.     --  Set our bars (notice the HealBar is a partial bar since it has a start value greater than zero)
  286.     addon:SetBarValue(self.ManaBar,0,mppcnt, 0, 0, 0, 0, "flipH");
  287.     --  Color HealthBar (we're keeping HealBar white)
  288.      if ptype == 0 then
  289.         self.ManaBar:SetVertexColor(.556, .556, .921, 1)
  290.     elseif ptype == 1 or 2 or 3 or 6 then
  291.         self.ManaBar:SetVertexColor(.656, .456, .456, 1)
  292.     end
  293. end)
  294.  
  295. --[[-----------------------------------------------------------------------------
  296. Pet Bars
  297. -------------------------------------------------------------------------------]]
  298. PPetHBar.HealthBar = PPetHBar:CreateTexture(nil,"ARTWORK");--Notice the change in layers, this makes the bar draw on top of the background
  299. PPetHBar.HealthBar:SetPoint("BOTTOM");--We need only one point set, in this example, the bar fills toward the right, so we need it left-aligned
  300. PPetHBar.HealthBar:SetWidth(128);--Match frame width for now
  301. PPetHBar.HealthBar:SetHeight(256);--Match frame height for now
  302. PPetHBar.HealthBar:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\p1");--Be sure to use the same image or one derived from the background
  303.  
  304. -- Player Mana Texture
  305. PPetMBar.ManaBar = PPetMBar:CreateTexture(nil,"ARTWORK");
  306. PPetMBar.ManaBar:SetPoint("BOTTOM");--We need only one point set, in this example, the bar fills toward the right, so we need it left-aligned
  307. PPetMBar.ManaBar:SetWidth(128);--Match frame width for now
  308. PPetMBar.ManaBar:SetHeight(256);--Match frame height for now
  309. PPetMBar.ManaBar:SetTexture("Interface\\AddOns\\GrimUI\\HudSkins\\p1");--Be sure to use the same image or one derived from the background
  310.  
  311. PPetHBar:RegisterEvent("PLAYER_ENTERING_WORLD");
  312. PPetHBar:RegisterEvent("PLAYER_TARGET_CHANGED");
  313. PPetHBar:RegisterEvent("UNIT_HEALTH", "pet")
  314. PPetHBar:RegisterEvent("UNIT_LEVEL", "pet")
  315. PPetHBar:RegisterEvent("UNIT_AURA", "pet")
  316. PPetHBar:RegisterEvent("UNIT_MAXHEALTH", "pet")
  317. PPetHBar:RegisterEvent("PLAYER_PET_CHANGED")
  318. PPetHBar:RegisterEvent("UNIT_PET", "player")
  319. PPetHBar:RegisterEvent("UNIT_HEALTH_PREDICTION", "pet");
  320.  
  321. PPetHBar:SetScript("OnEvent",function(self,event)
  322.     --  Stop handler if unit not player
  323.     --if not UnitIsUnit(unit,"player") then return; end
  324.     local hcur,hmax,heal=UnitHealth("pet"),UnitHealthMax("pet"),UnitGetIncomingHeals("pet") or 0;--    UnitGetIncomingHeals() can return nil for unsupported units
  325.     local hppcnt=hcur/math.max(1,hmax);
  326.     local healpcnt=heal/math.max(1,hmax);
  327.     --  Set our bars (notice the HealBar is a partial bar since it has a start value greater than zero)
  328.     addon:SetBarValue(self.HealthBar,0,hppcnt, 175, 25, 0, 0);
  329.     --addon:SetBarValue(self.HealBar,hppcnt,hppcnt+healpcnt);
  330.  
  331.     self.HealthBar:SetVertexColor(math.min(2-2*hppcnt,1),math.min(2*hppcnt,1),0);
  332.  
  333. end)
  334.  
  335. PPetMBar:RegisterEvent("PLAYER_ENTERING_WORLD");
  336. PPetMBar:RegisterEvent("UNIT_HEALTH", "pet")
  337. PPetMBar:RegisterEvent("UNIT_LEVEL", "pet")
  338. PPetMBar:RegisterEvent("UNIT_MANA", "pet")
  339. PPetMBar:RegisterEvent("UNIT_AURA", "pet")
  340. PPetMBar:RegisterEvent("UNIT_DISPLAYPOWER", "pet")
  341. PPetMBar:RegisterEvent("UNIT_ENERGY", "pet")
  342. PPetMBar:RegisterEvent("UNIT_MAXENERGY", "pet")
  343. PPetMBar:RegisterEvent("UNIT_MAXMANA", "pet")
  344.  
  345. PPetMBar:RegisterEvent("PET_UI_UPDATE");
  346. PPetMBar:RegisterEvent("PLAYER_TARGET_CHANGED");
  347. PPetMBar:RegisterEvent("UNIT_POWER", "pet");
  348.  
  349. PPetMBar:SetScript("OnEvent",function(self,event)
  350.     local pcur, pmax, ptype = UnitPower("pet"), UnitPowerMax("pet"), UnitPowerType("pet");
  351.     local mppcnt = pcur/math.max(1,pmax);
  352.     --  Set our bars (notice the HealBar is a partial bar since it has a start value greater than zero)
  353.     addon:SetBarValue(self.ManaBar,0,mppcnt, 175, 25, 0, 0,"flipH");
  354.     --  Color HealthBar (we're keeping HealBar white)
  355.      if ptype == 0 then
  356.         self.ManaBar:SetVertexColor(.556, .556, .921, 1)
  357.     elseif ptype == 1 or 2 or 3 or 6 then
  358.         self.ManaBar:SetVertexColor(.656, .456, .456, 1)
  359.     end
  360. end)
  361. --[[-----------------------------------------------------------------------------
  362. Addon Loaded Initialize
  363. -------------------------------------------------------------------------------]]
  364. addon.RegisterEvent("HUD-Initialize", 'ADDON_LOADED', function(self, event)
  365.     addon.UnregisterEvent(self, event)
  366.     addon:SetupGHud()
  367.     addon:LayoutHudBars()
  368.     addon:SetupGHud()
  369.     addon:SetHudBackgrounds()
  370. end)
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
11-28-10, 06:43 PM   #11
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Here's the modified function. The default values for the arguments noted below will apply if an argument is missing or is nil. Values marked required are as such.

Syntax:
SetBarValue(bar,val1,val2,flipH,flipV,cropx1,cropx2,cropy1,cropy2)

bar = Bar texture (required)
val1, val2 = Upper and lower values for the bar to be drawn (default 0)
flipH, flipV = Boolean true/false, flips texture horizontally/vertically if true (default false)
cropx1, cropx2, cropy1, cropy2 = Crop values, swapping high and low values within the xy pairs will not affect flipping (default 0, 1, 0, 1)


lua Code:
  1. local function SetBarValue(bar,val1,val2,flipH,flipV,cropx1,cropx2,cropy1,cropy2)-- Accepts 9 values, bar texture, start value, end value, flip flags, and crop offsets (any value exceptbar can be nil)
  2. --  Keep the values within a 0-1 range
  3.     val1=math.min(math.max(val1 or 0,0),1);
  4.     val2=math.min(math.max(val2 or 0,0),1);
  5.  
  6. --  Sometimes textures glitch when trying to set a width or height of 0, so handle it here
  7.     if val1==val2 then
  8.         bar:Hide();
  9.         return;
  10.     else
  11.         bar:Show();
  12.     end
  13.  
  14. --  Texture crop/padding
  15.     cropx1=math.min(math.max(cropx1 or 0,0),1);
  16.     cropx2=math.min(math.max(cropx2 or 1,0),1);
  17.     cropy1=math.min(math.max(cropy1 or 0,0),1);
  18.     cropy2=math.min(math.max(cropy2 or 1,0),1);
  19.  
  20. --  Set our low and high values
  21.     local low,high=math.min(val1,val2),math.max(val1,val2);
  22.  
  23. --  Find our parent width and height
  24.     local parent=bar:GetParent();
  25.     local pw,ph=parent:GetWidth(),parent:GetHeight();
  26.  
  27. --  Get our point set, we'll use this to get our bar orientation
  28.     local point=bar:GetPoint(1);
  29.     if not point then return; end-- Handle if point isn't set, perhaps cleared?
  30.  
  31. --  These are our temp origin variables (note one of these pairs can have both vars nil, just use default texcoords for those)
  32.     local origL=point:find("LEFT$");
  33.     local origR=point:find("RIGHT$");
  34.     local origT=point:find("^TOP");
  35.     local origB=point:find("^BOTTOM");
  36.  
  37. --  Reset point
  38.     bar:SetPoint(point
  39.         ,(origL or origR) and (origL and low*pw or -low*pw) or 0--  X offset
  40.         ,(origT or origB) and (origB and low*ph or -low*ph) or 0--  Y offset
  41.     );
  42.  
  43. --  Texcoord calc
  44.     local l,r,t,b=0,1,0,1;--    Texcoords are in the range of 0-1 with their origin at top left
  45.     if origL then
  46.         l,r=low,high;
  47.     elseif origR then
  48.         l,r=1-high,1-low;
  49.     end
  50.     if origT then
  51.         t,b=low,high;
  52.     elseif origB then
  53.         t,b=1-high,1-low;
  54.     end
  55.  
  56. --  Process flip (affects which side the bar piece is drawn from too)
  57.     if flipH then l,r=1-l,1-r; end
  58.     if flipV then t,b=1-t,1-b; end
  59.  
  60. --  Constrain to crop size
  61.     local cropL,cropR,cropT,cropB=math.min(cropx1,cropx2),math.max(cropx1,cropx2),math.min(cropy1,cropy2),math.max(cropy1,cropy2);
  62.     local cropW,cropH=cropR-cropL,cropB-cropT;
  63.     l,r,t,b=l*cropW+cropL,r*cropW+cropL,t*cropH+cropT,b*cropH+cropT;
  64.  
  65. --  Apply texcord/size
  66.     bar:SetTexCoord(l,r,t,b);
  67.     bar:SetWidth(pw*((origL or origR) and math.abs(high-low) or 1));
  68.     bar:SetHeight(ph*((origT or origB) and math.abs(high-low) or 1));
  69. end
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Hud status bar questions.


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