View Single Post
07-24-16, 07:48 PM   #12
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
I have tried both Resike's and Vrul's approach and they both worked perfectly !

So... I did move on to next step to display unit's health text on top of the health bar and it's having the issue.

Lua Code:
  1. A.CreateHealth = function(f, unit)
  2.     A.CreateHealthBar(f, unit);
  3.  
  4.     if unit == "player" or unit == "target" then
  5.         A.CreateHealthText(f, unit);
  6.     end
  7. end
  8.  
  9. A.CreateHealthBar = function(f, unit)
  10.     local Health = CreateFrame("StatusBar", f:GetName() .. "HealthBar", f);
  11.     Health:SetFrameLevel(Health:GetFrameLevel() + 1);
  12.     Health:SetStatusBarTexture(HEALTH_BAR);
  13.     Health:SetStatusBarColor(0, 0, 0, 1);
  14.  
  15.     if unit == "player" then
  16.         Health:SetPoint("TOPRIGHT", f, "TOPRIGHT", -1, -1);
  17.         Health:SetSize(f:GetWidth() - 12, f:GetHeight() - 12);
  18.     elseif unit == "target" then
  19.         Health:SetPoint("TOPLEFT", f, "TOPLEFT", 1, -1);
  20.         Health:SetSize(f:GetWidth() - 12, f:GetHeight() - 12);
  21.     elseif unit == "targettarget" then
  22.         Health:SetPoint("TOP", f, "TOP", 0, -1);
  23.         Health:SetSize(f:GetWidth() - 22, f:GetHeight() - 12);
  24.     end
  25.  
  26.     A.CreateBorder(Health, "Border", BACKDROP, {1, 1}, {"BOTTOMRIGHT", Health, "TOPLEFT", 0, 0}, {1, 0, 0, 1});
  27.     A.CreateBorder(Health, "Border", BACKDROP, {1, 1}, {"BOTTOMLEFT", Health, "TOPRIGHT", 0, 0}, {1, 0, 0, 1});
  28.     A.CreateBorder(Health, "Border", BACKDROP, {1, 1}, {"TOPRIGHT", Health, "BOTTOMLEFT", 0, 0}, {1, 0, 0, 1});
  29.     A.CreateBorder(Health, "Border", BACKDROP, {1, 1}, {"TOPLEFT", Health, "BOTTOMRIGHT", 0, 0}, {1, 0, 0, 1});
  30.     A.CreateBorder(Health, "Border", BACKDROP, {Health:GetWidth(), 1}, {"BOTTOM", Health, "TOP", 0, 0}, {1, 0, 0, 1});
  31.     A.CreateBorder(Health, "Border", BACKDROP, {Health:GetWidth(), 1}, {"TOP", Health, "BOTTOM", 0, 0}, {1, 0, 0, 1});
  32.     A.CreateBorder(Health, "Border", BACKDROP, {1, Health:GetHeight()}, {"RIGHT", Health, "LEFT", 0, 0}, {1, 0, 0, 1});
  33.     A.CreateBorder(Health, "Border", BACKDROP, {1, Health:GetHeight()}, {"LEFT", Health, "RIGHT", 0, 0}, {1, 0, 0, 1});
  34.  
  35.     Health.bg = Health:CreateTexture(nil, "BACKGROUND");
  36.     Health.bg:SetAllPoints(true);
  37.     Health.bg:SetTexture(BACKDROP);
  38.     Health.bg:SetVertexColor(0.5, 0.5, 0.5, 1);
  39.  
  40.     f.Health = Health;
  41.     f.Health.bg = Health.bg;
  42. end
  43.  
  44. A.CreateHealthText = function(f, unit)
  45.     local HealthValue = f:CreateFontString(f.Health:GetName() .. "Text", "OVERLAY");
  46.     HealthValue:SetFont(VALUE_FONT, 12);
  47.     HealthValue:SetTextColor(1, 1, 1, 1);
  48.  
  49.     if unit == "player" then
  50.         HealthValue:SetPoint("BOTTOMRIGHT", f.Health, "BOTTOMRIGHT", -1, 2);
  51.  
  52.         f:Tag(HealthValue, "[perhp]% | [curhp]");
  53.     else
  54.         HealthValue:SetPoint("BOTTOMLEFT", f.Health, "BOTTOMLEFT", 0, 2);
  55.  
  56.         f:Tag(HealthValue, "[curhp] | [perhp]%");
  57.     end
  58.  
  59.     f.HealthValue = HealthValue;
  60. end
  61.  
  62. A.CreatePower = function(f, unit)
  63.     A.CreatePowerBar(f, unit);
  64.  
  65.     if unit == "player" or unit == "target" then
  66.         A.CreatePowerText(f, unit);
  67.     end
  68. end
  69.  
  70. A.CreatePowerBar = function(f, unit)
  71.     local Power = CreateFrame("StatusBar", f:GetName() .. "PowerBar", f);
  72.     Power:SetFrameLevel(f.Health:GetFrameLevel() - 1);
  73.     Power:SetStatusBarTexture(HEALTH_BAR);
  74.     Power:SetStatusBarColor(1, 1, 1, 1);
  75.  
  76.     if unit == "player" then
  77.         Power:SetPoint("BOTTOMLEFT", f, "BOTTOMLEFT", 1, 1);
  78.         Power:SetSize(f:GetWidth() - 12, f:GetHeight() - 12);
  79.     elseif unit == "target" then
  80.         Power:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -1, 1);
  81.         Power:SetSize(f:GetWidth() - 12, f:GetHeight() - 12);
  82.     elseif unit == "targettarget" then
  83.         Power:SetPoint("BOTTOM", f, "BOTTOM", 0, 1);
  84.         Power:SetSize(f:GetWidth() - 2, f:GetHeight() - 12);
  85.     end
  86.  
  87.     A.CreateBorder(Power, "Border", BACKDROP, {1, 1}, {"BOTTOMRIGHT", Power, "TOPLEFT", 0, 0}, {0, 0, 1, 1});
  88.     A.CreateBorder(Power, "Border", BACKDROP, {1, 1}, {"BOTTOMLEFT", Power, "TOPRIGHT", 0, 0}, {0, 0, 1, 1});
  89.     A.CreateBorder(Power, "Border", BACKDROP, {1, 1}, {"TOPRIGHT", Power, "BOTTOMLEFT", 0, 0}, {0, 0, 1, 1});
  90.     A.CreateBorder(Power, "Border", BACKDROP, {1, 1}, {"TOPLEFT", Power, "BOTTOMRIGHT", 0, 0}, {0, 0, 1, 1});
  91.     A.CreateBorder(Power, "Border", BACKDROP, {Power:GetWidth(), 1}, {"BOTTOM", Power, "TOP", 0, 0}, {0, 0, 1, 1});
  92.     A.CreateBorder(Power, "Border", BACKDROP, {Power:GetWidth(), 1}, {"TOP", Power, "BOTTOM", 0, 0}, {0, 0, 1, 1});
  93.     A.CreateBorder(Power, "Border", BACKDROP, {1, Power:GetHeight()}, {"RIGHT", Power, "LEFT", 0, 0}, {0, 0, 1, 1});
  94.     A.CreateBorder(Power, "Border", BACKDROP, {1, Power:GetHeight()}, {"LEFT", Power, "RIGHT", 0, 0}, {0, 0, 1, 1});
  95.  
  96.     A.ApplyOptions(Power, "frequentUpdates");
  97.  
  98.     f.Power = Power;
  99. end
  100.  
  101. A.CreatePowerText = function(f, unit)
  102.  
  103. end

A.CreateHealthText function is the one that creates the health text and here's the result.



The health text is surely created as I could've find it via '/fstack', but it is hidden at the back.

I have made few guesses on what is causing this issue.

1. Because Health frame is set to have higher frame level than its parent frame, so that the health text is not drawn on Health frame. Thus, I did comment out

Health:SetFrameLevel(Health:GetFrameLevel() + 1);

but it did not seem to be working.

2. Because the HealthValue is the child of base frame, f, not Health frame, f.Health.

Actually, changing

f:CreateFontString(f.Health:GetName() .. "Text", "OVERLAY");

to

f.Health:CreateFontString(f.Health:GetName() .. "Text", "OVERLAY");

did solve the trick, but I personally think this is not a good coding in terms of memory efficiency(?).

Could I get some advice regarding this?

Last edited by Layback_ : 07-24-16 at 08:03 PM.
  Reply With Quote