Same as j3rem1e.
I have been asking this few months ago and zork tried his best to enlighten me, but I was so stupid to understand his effort...
I was damn busy for last couple of months finishing my work and finally back here to solve this old problem.
Tried with haste's method:
Lua Code:
Health:SetReverseFill(true)
Health.PostUpdate = function(Health, unit, min, max)
Health:SetValue(max - Health:GetValue())
end
as well as Monolit's method which I modified a bit to match my taste:
(BUT, I definitely left a contribution comment!)
Lua Code:
A.CreateHealthBar = function(f, unit)
local Health;
if unit == "player" or unit == "targettarget" then
Health = CreateFrame("StatusBar", f:GetName() .. "HealthBar", f);
elseif unit == "target" then
Health = A.ReverseStatusBar(f);
Health.PostUpdate = A.PostUpdateHealth;
end
Health:SetFrameLevel(Health:GetFrameLevel() + 1);
Health:SetStatusBarTexture(HEALTH_BAR);
Health:SetStatusBarColor(0.85, 0.86, 0.84, 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
Health.bg = Health:CreateTexture(nil, "BACKGROUND");
Health.bg:SetAllPoints(true);
Health.bg:SetTexture(BACKDROP);
Health.bg:SetVertexColor(0.08, 0.08, 0.08, 1);
f.Health = Health;
f.Health.bg = Health.bg;
end
-- Thanks to Monolit from WoWInterface for sharing this code!
local StatusBarUpdaterOnUpdate;
local StatusBarOnChanged;
A.ReverseStatusBar = function(f, unit)
local statusbar = CreateFrame("Statusbar", f:GetName() .. "HealthBar", f);
statusbar.updater = CreateFrame("Frame", nil, statusbar);
statusbar.updater:Hide();
statusbar.updater:SetScript("OnUpdate", StatusBarUpdaterOnUpdate);
statusbar:SetScript("OnSizeChanged", StatusBarOnChanged);
statusbar:SetScript("OnValueChanged", StatusBarOnChanged);
statusbar:SetScript("OnMinMaxChanged", StatusBarOnChanged);
return statusbar;
end
StatusBarUpdaterOnUpdate = function(updater)
updater:Hide();
local b = updater:GetParent();
local tex = b:GetStatusBarTexture();
tex:ClearAllPoints();
tex:SetPoint("BOTTOMRIGHT");
tex:SetPoint("TOPLEFT", b, "TOPRIGHT", (b:GetValue() / select(2, b:GetMinMaxValues()) - 1) * b:GetWidth(), 0);
local d = select(2, b:GetMinMaxValues());
local x;
if d ~= 0 then
x = (b:GetValue() / (d - 1)) * b:GetWidth();
end
tex:SetPoint("TOPLEFT", b, "TOPRIGHT", x, 0);
end
StatusBarOnChanged = function(statusbar)
statusbar.updater:Show();
end
A.PostUpdateHealth = function(statusbar, unit, min, max)
if UnitIsDeadOrGhost(unit) then
statusbar:SetValue(0);
end
end
Unfortunately, those two approaches does not seem to work for me either...
Could we please get some help regarding this?
Thank you!