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:
A.CreateHealth = function(f, unit) A.CreateHealthBar(f, unit); if unit == "player" or unit == "target" then A.CreateHealthText(f, unit); end end A.CreateHealthBar = function(f, unit) local Health = CreateFrame("StatusBar", f:GetName() .. "HealthBar", f); Health:SetFrameLevel(Health:GetFrameLevel() + 1); Health:SetStatusBarTexture(HEALTH_BAR); Health:SetStatusBarColor(0, 0, 0, 1); if unit == "player" then Health:SetPoint("TOPRIGHT", f, "TOPRIGHT", -1, -1); Health:SetSize(f:GetWidth() - 12, f:GetHeight() - 12); elseif unit == "target" then Health:SetPoint("TOPLEFT", f, "TOPLEFT", 1, -1); Health:SetSize(f:GetWidth() - 12, f:GetHeight() - 12); elseif unit == "targettarget" then Health:SetPoint("TOP", f, "TOP", 0, -1); Health:SetSize(f:GetWidth() - 22, f:GetHeight() - 12); end A.CreateBorder(Health, "Border", BACKDROP, {1, 1}, {"BOTTOMRIGHT", Health, "TOPLEFT", 0, 0}, {1, 0, 0, 1}); A.CreateBorder(Health, "Border", BACKDROP, {1, 1}, {"BOTTOMLEFT", Health, "TOPRIGHT", 0, 0}, {1, 0, 0, 1}); A.CreateBorder(Health, "Border", BACKDROP, {1, 1}, {"TOPRIGHT", Health, "BOTTOMLEFT", 0, 0}, {1, 0, 0, 1}); A.CreateBorder(Health, "Border", BACKDROP, {1, 1}, {"TOPLEFT", Health, "BOTTOMRIGHT", 0, 0}, {1, 0, 0, 1}); A.CreateBorder(Health, "Border", BACKDROP, {Health:GetWidth(), 1}, {"BOTTOM", Health, "TOP", 0, 0}, {1, 0, 0, 1}); A.CreateBorder(Health, "Border", BACKDROP, {Health:GetWidth(), 1}, {"TOP", Health, "BOTTOM", 0, 0}, {1, 0, 0, 1}); A.CreateBorder(Health, "Border", BACKDROP, {1, Health:GetHeight()}, {"RIGHT", Health, "LEFT", 0, 0}, {1, 0, 0, 1}); A.CreateBorder(Health, "Border", BACKDROP, {1, Health:GetHeight()}, {"LEFT", Health, "RIGHT", 0, 0}, {1, 0, 0, 1}); Health.bg = Health:CreateTexture(nil, "BACKGROUND"); Health.bg:SetAllPoints(true); Health.bg:SetTexture(BACKDROP); Health.bg:SetVertexColor(0.5, 0.5, 0.5, 1); f.Health = Health; f.Health.bg = Health.bg; end A.CreateHealthText = function(f, unit) local HealthValue = f:CreateFontString(f.Health:GetName() .. "Text", "OVERLAY"); HealthValue:SetFont(VALUE_FONT, 12); HealthValue:SetTextColor(1, 1, 1, 1); if unit == "player" then HealthValue:SetPoint("BOTTOMRIGHT", f.Health, "BOTTOMRIGHT", -1, 2); f:Tag(HealthValue, "[perhp]% | [curhp]"); else HealthValue:SetPoint("BOTTOMLEFT", f.Health, "BOTTOMLEFT", 0, 2); f:Tag(HealthValue, "[curhp] | [perhp]%"); end f.HealthValue = HealthValue; end A.CreatePower = function(f, unit) A.CreatePowerBar(f, unit); if unit == "player" or unit == "target" then A.CreatePowerText(f, unit); end end A.CreatePowerBar = function(f, unit) local Power = CreateFrame("StatusBar", f:GetName() .. "PowerBar", f); Power:SetFrameLevel(f.Health:GetFrameLevel() - 1); Power:SetStatusBarTexture(HEALTH_BAR); Power:SetStatusBarColor(1, 1, 1, 1); if unit == "player" then Power:SetPoint("BOTTOMLEFT", f, "BOTTOMLEFT", 1, 1); Power:SetSize(f:GetWidth() - 12, f:GetHeight() - 12); elseif unit == "target" then Power:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -1, 1); Power:SetSize(f:GetWidth() - 12, f:GetHeight() - 12); elseif unit == "targettarget" then Power:SetPoint("BOTTOM", f, "BOTTOM", 0, 1); Power:SetSize(f:GetWidth() - 2, f:GetHeight() - 12); end A.CreateBorder(Power, "Border", BACKDROP, {1, 1}, {"BOTTOMRIGHT", Power, "TOPLEFT", 0, 0}, {0, 0, 1, 1}); A.CreateBorder(Power, "Border", BACKDROP, {1, 1}, {"BOTTOMLEFT", Power, "TOPRIGHT", 0, 0}, {0, 0, 1, 1}); A.CreateBorder(Power, "Border", BACKDROP, {1, 1}, {"TOPRIGHT", Power, "BOTTOMLEFT", 0, 0}, {0, 0, 1, 1}); A.CreateBorder(Power, "Border", BACKDROP, {1, 1}, {"TOPLEFT", Power, "BOTTOMRIGHT", 0, 0}, {0, 0, 1, 1}); A.CreateBorder(Power, "Border", BACKDROP, {Power:GetWidth(), 1}, {"BOTTOM", Power, "TOP", 0, 0}, {0, 0, 1, 1}); A.CreateBorder(Power, "Border", BACKDROP, {Power:GetWidth(), 1}, {"TOP", Power, "BOTTOM", 0, 0}, {0, 0, 1, 1}); A.CreateBorder(Power, "Border", BACKDROP, {1, Power:GetHeight()}, {"RIGHT", Power, "LEFT", 0, 0}, {0, 0, 1, 1}); A.CreateBorder(Power, "Border", BACKDROP, {1, Power:GetHeight()}, {"LEFT", Power, "RIGHT", 0, 0}, {0, 0, 1, 1}); A.ApplyOptions(Power, "frequentUpdates"); f.Power = Power; end A.CreatePowerText = function(f, unit) 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.
|