Thread Tools Display Modes
03-24-15, 09:40 AM   #1
Maerlyns
A Murloc Raider
Join Date: Jul 2014
Posts: 4
oUF_Mu problem with class power and vehicle UI

Hey

Since the author of oUF_Mu seems not to be active anymore I hope you could help me.

Every time I leave a vehicle (for example the mounts of the Argent Tournament) my class power like Holy Power doesn't work correctly. If you download the normal files you'll see that the frame doesn't show up again. That's easily fixed with taking every power in the function "VehicleVisibilityUpdate" but now the frame shows up and if I gain one Holy Power the frame doesn't show me that. With DK runes it works great. I couldn't find any mistake but well, I'm not very good at LUA.

All I have found in the code was this:
Code:
--=================================--
-- class points bars
--=================================--

local function cpPositionCalc(width, count)				-- calculate the position of the first point
	return 1-floor((width+2)*count/2)
end

local function PostUpdateRune(runes, rune, rid, start, duration, ready)
	local runetype = GetRuneType(rid)
	local r, g, b = unpack(oUF.colors.runes[runetype])
	if ready then
		rune:SetStatusBarColor(r, g, b)
	else
		rune:SetStatusBarColor(r*.6, g*.6, b*.6)
	end
end

local function VehicleVisibilityUpdate(self, event, unit)
	local element = self.Runes and self.Runes or self.TotemBar or self.ClassIcons or self.CPoints
	for i = 1, #element do
		if UnitHasVehicleUI('player') then
			element[i]:Hide()
		else
			element[i]:Show()
		end
	end
end

local function ShadowOrbsVisibilityUpdate(self, event, ...)
	local orbs = self.ClassIcons
	for i = 1, 3 do
		if UnitHasVehicleUI('player') or GetSpecialization() ~= 3 then
			orbs[i]:Hide()
		else
			orbs[i]:Show()
		end
	end
end

local function classPointHelper(self, class, pinfo)
	local w, h, count = pinfo.size.w, pinfo.size.h, pinfo.count
	if count < 5 and class ~= 'SHAMAN' then count = 5 end
	local points = {}
	for i = 1, count do
		local point = CreateFrame('StatusBar', nil, self)
		point:SetSize(w-2, h-2)
		point:SetStatusBarTexture(cfg.powertex)
		point.bg = point:CreateTexture(nil, 'BACKGROUND')
		point.bg:SetAllPoints(point)
		point.border = mu.createBorder(point)
		if class == 'DEATHKNIGHT' then
			local runetype = GetRuneType(i)
			local r, g, b = unpack(oUF.colors.runes[runetype])
			point.bg:SetTexture(r, g, b, 0.75)
			point.bg.multiplier = .25
		elseif class == 'ROGUE' or class == 'DRUID' then
			point:SetStatusBarColor(unpack(cpcolor[i]))
		end
		points[i] = point
		if i == 1 then
			point:SetPoint('BOTTOMLEFT', UIParent, 'CENTER', cpPositionCalc(w, pinfo.count), -109)
		else
			point:SetPoint('LEFT', points[i-1], 'RIGHT', 4, 0)
		end
	end
	return points
end

local function ClassIconsPostUpdate(points, cur, max, changed)
	
	local r1, b1, g1, r2, b2, g2
	if pClass == 'PALADIN' then
		r1, g1, b1 = 0.82, 0.56, 0.18
		r2, g2, b2 = 0.9, 0.78, 0.21
	elseif pClass == 'PRIEST' then
		r1, g1, b1 = 0.48, 0.15, 0.93
		r2, g2, b2 = 0.62, 0.32, 0.98
	elseif pClass == 'MONK' then
		r1, g1, b1 = 0.3, 0.85, 0.51
		r2, g2, b2 = 0.56, 0.91, 0.78
	end
	
	for i = 1, max do
		local point = points[i]
		local minvalue, maxvalue = points[i]:GetMinMaxValues()
		if cur == max then
			point:SetStatusBarColor(r2, g2, b2)
			point:SetValue(maxvalue)
			point:Show()
		elseif i > cur then
			point:SetValue(minvalue)
			point:Show()
		else
			point:SetStatusBarColor(r1, g1, b1)
			point:SetValue(maxvalue)
			point:Show()
		end
	end

end

local function ClassIconsUpdateTexture(element)
	local r, g, b
	if pClass == 'PALADIN' then
		r, g, b = 0.82, 0.56, 0.18
	elseif pClass == 'PRIEST' then
		r, g, b = 0.52, 0.13, 0.93
	elseif pClass == 'MONK' then
		r, g, b = 0.3, 0.85, 0.51
	end
	
	for i = 1, #element do
		element[i]:SetMinMaxValues(0,1)
		element[i]['bg']:SetTexture(r*.25, g*.25, b*.25, .75)
	end
end

mu.classPoints = function(self)

	local pinfo
	if pClass == 'PALADIN' then
		pinfo = {
			count = UnitPowerMax('player', SPELL_POWER_HOLY_POWER),
			size = { w=26, h=12 },
		}
	elseif pClass == 'PRIEST' then
		pinfo = {
			count = 3,
			size = { w=30, h=12 },
		}
	elseif pClass == 'MONK' then
		pinfo = {
			count = UnitPowerMax('player', SPELL_POWER_CHI),
			size = { w=26, h=12 },
		}
	elseif pClass == 'DRUID' or pClass == 'ROGUE' then
		pinfo = {
			count = MAX_COMBO_POINTS,
			size = { w=26, h=12 },
		}
	elseif pClass == 'DEATHKNIGHT' then
		pinfo = {
			count = 6,
			size = { w=24, h=12 },
		}
	elseif pClass == 'SHAMAN' then
		pinfo = {
			count = 4,
			size = { w=30, h=12},
		}
	end
	
	local points = classPointHelper(self, pClass, pinfo)
	
	if mu.multicheck(pClass, 'PALADIN', 'PRIEST', 'MONK') then	
		self.ClassIcons = points
		self.ClassIcons.UpdateTexture = ClassIconsUpdateTexture
		self.ClassIcons.PostUpdate = ClassIconsPostUpdate
		self:RegisterEvent('UNIT_ENTERING_VEHICLE', VehicleVisibilityUpdate)
		self:RegisterEvent('UNIT_EXITED_VEHICLE', VehicleVisibilityUpdate)
	elseif pClass == 'DRUID' or pClass == 'ROGUE' then
		self.CPoints = points
		self:RegisterEvent('UNIT_ENTERING_VEHICLE', VehicleVisibilityUpdate)
		self:RegisterEvent('UNIT_EXITED_VEHICLE', VehicleVisibilityUpdate)
	elseif pClass == 'DEATHKNIGHT' then
		oUF.colors.runes = {
			{0.75, 0.21, 0.21},		-- blood
			{0.36, 0.72, 0.22},		-- unholy
			{0.18, 0.63, 0.79},		-- frost
			{0.67, 0.15, 0.75},		-- death
		}
		self.Runes = points
		self.Runes.PostUpdateType = PostUpdateRuneType
		self.Runes.PostUpdateRune = PostUpdateRune
		self:RegisterEvent('UNIT_ENTERING_VEHICLE', VehicleVisibilityUpdate)
		self:RegisterEvent('UNIT_EXITED_VEHICLE', VehicleVisibilityUpdate)
	elseif pClass == 'SHAMAN' then
		self.TotemBar = points
		self.TotemBar.Destroy = true
		self:RegisterEvent('UNIT_ENTERING_VEHICLE', VehicleVisibilityUpdate)
		self:RegisterEvent('UNIT_EXITED_VEHICLE', VehicleVisibilityUpdate)
	end
	if pClass == 'PRIEST' then
		self:RegisterEvent('PLAYER_ENTERING_WORLD', ShadowOrbsVisibilityUpdate)
		self:RegisterEvent('PLAYER_TALENT_UPDATE', ShadowOrbsVisibilityUpdate)
		self:RegisterEvent('ACTIVE_TALENT_GROUP_CHANGED', ShadowOrbsVisibilityUpdate)
		self:RegisterEvent('UNIT_ENTERING_VEHICLE', ShadowOrbsVisibilityUpdate)
		self:RegisterEvent('UNIT_EXITED_VEHICLE', ShadowOrbsVisibilityUpdate)
	end
end
Could you please help me find the incorrect parts in this code?
  Reply With Quote
03-24-15, 10:07 AM   #2
Munglunch
Premium Member
 
Munglunch's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Jun 2009
Posts: 34
Try this:

For your visibility handler I would revert the "VehicleVisibilityUpdate" function back to the default and add a second one specifically for the other class element types. Like this:

Lua Code:
  1. local function VehicleVisibilityUpdate(self, event, unit)
  2.     local element = self.Runes and self.Runes or self.TotemBar
  3.     for i = 1, #element do
  4.         if UnitHasVehicleUI('player') then
  5.             element[i]:Hide()
  6.         else
  7.             element[i]:Show()
  8.         end
  9.     end
  10. end
  11.  
  12. local function ClassIconsVehicleVisibilityUpdate(self, event, unit)
  13.     local element = self.CPoints and self.CPoints or self.ClassIcons
  14.     if(element and element.ForceUpdate) then
  15.         element:ForceUpdate()
  16.     end
  17. end

Then in the creation part of the code, simply use the new handler function accordingly:

Lua Code:
  1. mu.classPoints = function(self)
  2.  
  3.     local pinfo
  4.     if pClass == 'PALADIN' then
  5.         pinfo = {
  6.             count = UnitPowerMax('player', SPELL_POWER_HOLY_POWER),
  7.             size = { w=8, h=8 },
  8.         }
  9.     elseif pClass == 'PRIEST' then
  10.         pinfo = {
  11.             count = 3,
  12.             size = { w=8, h=8 },
  13.         }
  14.     elseif pClass == 'MONK' then
  15.         pinfo = {
  16.             count = UnitPowerMax('player', SPELL_POWER_CHI),
  17.             size = { w=8, h=8 },
  18.         }
  19.     elseif pClass == 'DRUID' or pClass == 'ROGUE' then
  20.         pinfo = {
  21.             count = MAX_COMBO_POINTS,
  22.             size = { w=8, h=8 },
  23.         }
  24.     elseif pClass == 'DEATHKNIGHT' then
  25.         pinfo = {
  26.             count = 6,
  27.             size = { w=14, h=8 },
  28.         }
  29.     elseif pClass == 'SHAMAN' then
  30.         pinfo = {
  31.             count = 4,
  32.             size = { w=12, h=8},
  33.         }
  34.     end
  35.    
  36.     local points = classPointHelper(self, pClass, pinfo)
  37.    
  38.     if mu.multicheck(pClass, 'PALADIN', 'PRIEST', 'MONK') then 
  39.         self.ClassIcons = points
  40.         self.ClassIcons.UpdateTexture = ClassIconsUpdateTexture
  41.         self.ClassIcons.PostUpdate = ClassIconsPostUpdate
  42.         self:RegisterEvent('UNIT_ENTERING_VEHICLE', ClassIconsVehicleVisibilityUpdate)
  43.         self:RegisterEvent('UNIT_EXITED_VEHICLE', ClassIconsVehicleVisibilityUpdate)
  44.     elseif pClass == 'DRUID' or pClass == 'ROGUE' then
  45.         self.CPoints = points
  46.         self:RegisterEvent('UNIT_ENTERING_VEHICLE', ClassIconsVehicleVisibilityUpdate)
  47.         self:RegisterEvent('UNIT_EXITED_VEHICLE', ClassIconsVehicleVisibilityUpdate)
  48.     elseif pClass == 'DEATHKNIGHT' then
  49.         oUF.colors.runes = {
  50.             {0.75, 0.21, 0.21},     -- blood
  51.             {0.36, 0.72, 0.22},     -- unholy
  52.             {0.18, 0.63, 0.79},     -- frost
  53.             {0.67, 0.15, 0.75},     -- death
  54.         }
  55.         self.Runes = points
  56.         self.Runes.PostUpdateType = PostUpdateRuneType
  57.         self.Runes.PostUpdateRune = PostUpdateRune
  58.         self:RegisterEvent('UNIT_ENTERING_VEHICLE', VehicleVisibilityUpdate)
  59.         self:RegisterEvent('UNIT_EXITED_VEHICLE', VehicleVisibilityUpdate)
  60.     elseif pClass == 'SHAMAN' then
  61.         self.TotemBar = points
  62.         self.TotemBar.Destroy = true
  63.         self:RegisterEvent('UNIT_ENTERING_VEHICLE', VehicleVisibilityUpdate)
  64.         self:RegisterEvent('UNIT_EXITED_VEHICLE', VehicleVisibilityUpdate)
  65.     end
  66.     if pClass == 'PRIEST' then
  67.         self:RegisterEvent('PLAYER_ENTERING_WORLD', ShadowOrbsVisibilityUpdate)
  68.         self:RegisterEvent('PLAYER_TALENT_UPDATE', ShadowOrbsVisibilityUpdate)
  69.         self:RegisterEvent('ACTIVE_TALENT_GROUP_CHANGED', ShadowOrbsVisibilityUpdate)
  70.         self:RegisterEvent('UNIT_ENTERING_VEHICLE', ShadowOrbsVisibilityUpdate)
  71.         self:RegisterEvent('UNIT_EXITED_VEHICLE', ShadowOrbsVisibilityUpdate)
  72.     end
  73. end

... hope this helps
  Reply With Quote
03-24-15, 11:13 AM   #3
Maerlyns
A Murloc Raider
Join Date: Jul 2014
Posts: 4
Thanks for your help but with your code the class points just don't show up again after leaving a vehicle.
  Reply With Quote
03-24-15, 07:08 PM   #4
Munglunch
Premium Member
 
Munglunch's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Jun 2009
Posts: 34
Originally Posted by Maerlyns View Post
Thanks for your help but with your code the class points just don't show up again after leaving a vehicle.

Well dang....

This may or may not help but I'm going to post it anyway, because it's bugging me.
It would probably be better to save the class resource bar's name and use it to accurately grab the element in the handler.
I also realized that BOTH the show/hide loop AND the ForceUpdate need to be fired during vehicle events.

This is what I came up with....

Lua Code:
  1. local function VehicleVisibilityUpdate(self, event, unit)
  2.     local resource = self.ClassResourceType
  3.     local element = self[resource]
  4.     if(not element) then return end
  5.     for i = 1, #element do
  6.         if UnitHasVehicleUI('player') then
  7.             element[i]:Hide()
  8.         else
  9.             element[i]:Show()
  10.         end
  11.     end
  12.     if(element.ForceUpdate) then
  13.         element:ForceUpdate()
  14.     end
  15. end

and

Lua Code:
  1. mu.classPoints = function(self)
  2.  
  3.     local pinfo
  4.     if pClass == 'PALADIN' then
  5.         pinfo = {
  6.             count = UnitPowerMax('player', SPELL_POWER_HOLY_POWER),
  7.             size = { w=8, h=8 },
  8.         }
  9.     elseif pClass == 'PRIEST' then
  10.         pinfo = {
  11.             count = 3,
  12.             size = { w=8, h=8 },
  13.         }
  14.     elseif pClass == 'MONK' then
  15.         pinfo = {
  16.             count = UnitPowerMax('player', SPELL_POWER_CHI),
  17.             size = { w=8, h=8 },
  18.         }
  19.     elseif pClass == 'DRUID' or pClass == 'ROGUE' then
  20.         pinfo = {
  21.             count = MAX_COMBO_POINTS,
  22.             size = { w=8, h=8 },
  23.         }
  24.     elseif pClass == 'DEATHKNIGHT' then
  25.         pinfo = {
  26.             count = 6,
  27.             size = { w=14, h=8 },
  28.         }
  29.     elseif pClass == 'SHAMAN' then
  30.         pinfo = {
  31.             count = 4,
  32.             size = { w=12, h=8},
  33.         }
  34.     end
  35.    
  36.     local points = classPointHelper(self, pClass, pinfo)
  37.    
  38.     if mu.multicheck(pClass, 'PALADIN', 'PRIEST', 'MONK') then
  39.         self.ClassResourceType = "ClassIcons"
  40.         self.ClassIcons = points
  41.         self.ClassIcons.UpdateTexture = ClassIconsUpdateTexture
  42.         self.ClassIcons.PostUpdate = ClassIconsPostUpdate
  43.         self:RegisterEvent('UNIT_ENTERING_VEHICLE', VehicleVisibilityUpdate)
  44.         self:RegisterEvent('UNIT_EXITED_VEHICLE', VehicleVisibilityUpdate)
  45.     elseif pClass == 'DRUID' or pClass == 'ROGUE' then
  46.         self.ClassResourceType = "CPoints"
  47.         self.CPoints = points
  48.         self:RegisterEvent('UNIT_ENTERING_VEHICLE', VehicleVisibilityUpdate)
  49.         self:RegisterEvent('UNIT_EXITED_VEHICLE', VehicleVisibilityUpdate)
  50.     elseif pClass == 'DEATHKNIGHT' then
  51.         self.ClassResourceType = "Runes"
  52.         oUF.colors.runes = {
  53.             {0.75, 0.21, 0.21},     -- blood
  54.             {0.36, 0.72, 0.22},     -- unholy
  55.             {0.18, 0.63, 0.79},     -- frost
  56.             {0.67, 0.15, 0.75},     -- death
  57.         }
  58.         self.Runes = points
  59.         self.Runes.PostUpdateType = PostUpdateRuneType
  60.         self.Runes.PostUpdateRune = PostUpdateRune
  61.         self:RegisterEvent('UNIT_ENTERING_VEHICLE', VehicleVisibilityUpdate)
  62.         self:RegisterEvent('UNIT_EXITED_VEHICLE', VehicleVisibilityUpdate)
  63.     elseif pClass == 'SHAMAN' then
  64.         self.ClassResourceType = "TotemBar"
  65.         self.TotemBar = points
  66.         self.TotemBar.Destroy = true
  67.         self:RegisterEvent('UNIT_ENTERING_VEHICLE', VehicleVisibilityUpdate)
  68.         self:RegisterEvent('UNIT_EXITED_VEHICLE', VehicleVisibilityUpdate)
  69.     end
  70.     if pClass == 'PRIEST' then
  71.         self:RegisterEvent('PLAYER_ENTERING_WORLD', ShadowOrbsVisibilityUpdate)
  72.         self:RegisterEvent('PLAYER_TALENT_UPDATE', ShadowOrbsVisibilityUpdate)
  73.         self:RegisterEvent('ACTIVE_TALENT_GROUP_CHANGED', ShadowOrbsVisibilityUpdate)
  74.         self:RegisterEvent('UNIT_ENTERING_VEHICLE', ShadowOrbsVisibilityUpdate)
  75.         self:RegisterEvent('UNIT_EXITED_VEHICLE', ShadowOrbsVisibilityUpdate)
  76.     end
  77. end
  Reply With Quote
03-25-15, 05:48 AM   #5
Maerlyns
A Murloc Raider
Join Date: Jul 2014
Posts: 4
Well, there isn't any change. It works well until I enter a vehicle. After I leave that the frame shows up but isn't working at all :/
  Reply With Quote
03-31-15, 04:43 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Why are you trying to do your own vehicle-related visibility checking in the first place? All of the elements you're working with hide themselves in/out of vehicles as appropriate, by default. Just let oUF handle it.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
04-01-15, 10:04 AM   #7
Maerlyns
A Murloc Raider
Join Date: Jul 2014
Posts: 4
Originally Posted by Phanx View Post
Why are you trying to do your own vehicle-related visibility checking in the first place? All of the elements you're working with hide themselves in/out of vehicles as appropriate, by default. Just let oUF handle it.
As I said, it's not my addon (and I just started learning some Lua lately), so I'm a little bit overstrained with all that oUF has to offer.

I will try the code without the visibility function but I just didn't know about that fact.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » oUF_Mu problem with class power and vehicle UI

Thread Tools
Display Modes

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