Thread Tools Display Modes
07-21-16, 12:20 PM   #21
j3rem1e
A Defias Bandit
Join Date: Oct 2014
Posts: 2
I reopen a really old thread, but with the 7.0 patch, the "ReverseBar" function doesn't work, and I don't have any idea why. Calling "tex:SetPoint" with any parameters doesn't seem to have any effect.

I am using a custom fork of oUF_Mono witch use this function :

lua Code:
  1. local ReverseBar
  2. do
  3.     local UpdaterOnUpdate = function(Updater)
  4.         Updater:Hide()
  5.         local b = Updater:GetParent()
  6.         local tex = b:GetStatusBarTexture()
  7.         tex:ClearAllPoints()
  8.         tex:SetPoint("BOTTOMRIGHT")
  9.         tex:SetPoint("TOPLEFT", b, "TOPRIGHT", (b:GetValue()/select(2,b:GetMinMaxValues())-1)*b:GetWidth(), 0)
  10.     end
  11.     local OnChanged = function(bar)
  12.         bar.Updater:Show()
  13.     end
  14.     function ReverseBar(f)
  15.         local bar = CreateFrame("StatusBar", nil, f)
  16.         bar.Updater = CreateFrame("Frame", nil, bar)
  17.         bar.Updater:Hide()
  18.         bar.Updater:SetScript("OnUpdate", UpdaterOnUpdate)
  19.         bar:SetScript("OnSizeChanged", OnChanged)
  20.         bar:SetScript("OnValueChanged", OnChanged)
  21.         bar:SetScript("OnMinMaxChanged", OnChanged)
  22.         return bar;
  23.     end
  24. end

Using ReverseFill doesn't work either, because of the Smooth plugin : calling SetValue in a PostUpdate callback make the bar going from right to left continually. I'll try to hack this plugin, but this solution doesn't look very good to me.

Any help appreciated, and I apologize for my bad english :-)
  Reply With Quote
07-25-16, 05:20 AM   #22
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
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:
  1. Health:SetReverseFill(true)
  2. Health.PostUpdate = function(Health, unit, min, max)
  3.    Health:SetValue(max - Health:GetValue())
  4. 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:
  1. A.CreateHealthBar = function(f, unit)
  2.     local Health;
  3.  
  4.     if unit == "player" or unit == "targettarget" then
  5.         Health = CreateFrame("StatusBar", f:GetName() .. "HealthBar", f);
  6.     elseif unit == "target" then
  7.         Health = A.ReverseStatusBar(f);
  8.         Health.PostUpdate = A.PostUpdateHealth;
  9.     end
  10.  
  11.     Health:SetFrameLevel(Health:GetFrameLevel() + 1);
  12.     Health:SetStatusBarTexture(HEALTH_BAR);
  13.     Health:SetStatusBarColor(0.85, 0.86, 0.84, 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.     Health.bg = Health:CreateTexture(nil, "BACKGROUND");
  27.     Health.bg:SetAllPoints(true);
  28.     Health.bg:SetTexture(BACKDROP);
  29.     Health.bg:SetVertexColor(0.08, 0.08, 0.08, 1);
  30.  
  31.     f.Health = Health;
  32.     f.Health.bg = Health.bg;
  33. end
  34.  
  35. -- Thanks to Monolit from WoWInterface for sharing this code!
  36. local StatusBarUpdaterOnUpdate;
  37. local StatusBarOnChanged;
  38. A.ReverseStatusBar = function(f, unit)
  39.     local statusbar = CreateFrame("Statusbar", f:GetName() .. "HealthBar", f);
  40.     statusbar.updater = CreateFrame("Frame", nil, statusbar);
  41.     statusbar.updater:Hide();
  42.     statusbar.updater:SetScript("OnUpdate", StatusBarUpdaterOnUpdate);
  43.  
  44.     statusbar:SetScript("OnSizeChanged", StatusBarOnChanged);
  45.     statusbar:SetScript("OnValueChanged", StatusBarOnChanged);
  46.     statusbar:SetScript("OnMinMaxChanged", StatusBarOnChanged);
  47.  
  48.     return statusbar;
  49. end
  50.  
  51. StatusBarUpdaterOnUpdate = function(updater)
  52.     updater:Hide();
  53.  
  54.     local b = updater:GetParent();
  55.  
  56.     local tex = b:GetStatusBarTexture();
  57.     tex:ClearAllPoints();
  58.     tex:SetPoint("BOTTOMRIGHT");
  59.     tex:SetPoint("TOPLEFT", b, "TOPRIGHT", (b:GetValue() / select(2, b:GetMinMaxValues()) - 1) * b:GetWidth(), 0);
  60.  
  61.     local d = select(2, b:GetMinMaxValues());
  62.  
  63.     local x;
  64.  
  65.     if d ~= 0 then
  66.         x = (b:GetValue() / (d - 1)) * b:GetWidth();
  67.     end
  68.  
  69.     tex:SetPoint("TOPLEFT", b, "TOPRIGHT", x, 0);
  70. end
  71.  
  72. StatusBarOnChanged = function(statusbar)
  73.     statusbar.updater:Show();
  74. end
  75.  
  76. A.PostUpdateHealth = function(statusbar, unit, min, max)
  77.     if UnitIsDeadOrGhost(unit) then
  78.         statusbar:SetValue(0);
  79.     end
  80. end

Unfortunately, those two approaches does not seem to work for me either...

Could we please get some help regarding this?

Thank you!

Last edited by Layback_ : 07-25-16 at 05:27 AM.
  Reply With Quote
07-26-16, 10:01 AM   #23
j3rem1e
A Defias Bandit
Join Date: Oct 2014
Posts: 2
If this can help you, I have fixed oUF_Mono by using the following function. Probably not the prettiest things to do as I am not an addon coder, but at least, it works and it's compatible with the Smooth plugin :-)

Code:
local ReverseBar
  do
	local ReverseSetValue = function(self, value)
		local minv, maxv = self:GetMinMaxValues();
		self.__value = value;
		self:__setValue(maxv - value);
	end
	local ReverseGetValue = function(self)
		return self.__value;
	end
	function ReverseBar(f)
		s = CreateFrame("StatusBar", nil, f) 
		s:SetReverseFill(true)
		s.__setValue = s.SetValue;
		s.SetValue = ReverseSetValue;
		s.__value = s:GetValue();
		s.GetValue = ReverseGetValue;
		return s;
	end
  end
  Reply With Quote
07-26-16, 07:13 PM   #24
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Originally Posted by j3rem1e View Post
If this can help you, I have fixed oUF_Mono by using the following function. Probably not the prettiest things to do as I am not an addon coder, but at least, it works and it's compatible with the Smooth plugin :-)

Code:
local ReverseBar
  do
	local ReverseSetValue = function(self, value)
		local minv, maxv = self:GetMinMaxValues();
		self.__value = value;
		self:__setValue(maxv - value);
	end
	local ReverseGetValue = function(self)
		return self.__value;
	end
	function ReverseBar(f)
		s = CreateFrame("StatusBar", nil, f) 
		s:SetReverseFill(true)
		s.__setValue = s.SetValue;
		s.SetValue = ReverseSetValue;
		s.__value = s:GetValue();
		s.GetValue = ReverseGetValue;
		return s;
	end
  end
Sweet!

I'll have a go with it

Thank you !!
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » reverse status bars (again)


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