Thread Tools Display Modes
04-13-15, 08:04 AM   #1
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
Help with Tweaking oUF:Classic

I am using oUF:Classic as my base frame and tweaking them. I have two problems in the attached image, the first is trying to get the health right aligned and displaying the power on it's bar also right aligned. Second is the border, I cannot get it center around the frame. I am attaching my code (OK, oUF code with my hacks). What am I missing or doing wrong. Thanks.

Code:
--[[-------------------------------------------------------------------------
  Trond A Ekseth grants anyone the right to use this work for any purpose,
  without any conditions, unless such conditions are required by law.
---------------------------------------------------------------------------]]

local _TEXTURE = [[Interface\AddOns\oUF_Roc\textures\statusbar]]

local colors = setmetatable({
	health = {.45, .73, .27},
	power = setmetatable({
		['MANA'] = {.27, .53, .73},
		['RAGE'] = {.73, .27, .27},
	}, {__index = oUF.colors.power}),
}, {__index = oUF.colors})

local siValue = function(val)
	if(val >= 1e6) then
		return ('%.1f'):format(val / 1e6):gsub('%.', 'm')
	elseif(val >= 1e4) then
		return ("%.1f"):format(val / 1e3):gsub('%.', 'k')
	else
		return val
	end
end

oUF.Tags.Methods['roc:health'] = function(unit)
	if(not UnitIsConnected(unit) or UnitIsDead(unit) or UnitIsGhost(unit)) then return end
	return siValue(UnitHealth(unit)) .. '/' .. siValue(UnitHealthMax(unit))
end
oUF.Tags.Events['roc:health'] = oUF.Tags.Events.missinghp

oUF.Tags.Methods['roc:power'] = function(unit)
	local min, max = UnitPower(unit), UnitPowerMax(unit)
	if(min == 0 or max == 0 or not UnitIsConnected(unit) or UnitIsDead(unit) or UnitIsGhost(unit)) then return end

	return siValue(min) .. '/' .. siValue(max)
end
oUF.Tags.Events['roc:power'] = oUF.Tags.Events.missingpp

local PostUpdateHealth = function(health, unit, min, max)
	local self = health:GetParent()
	if(UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) or not UnitIsConnected(unit)) then
		self:SetBackdropBorderColor(.3, .3, .3)
	else
		local r, g, b = UnitSelectionColor(unit)
		self:SetBackdropBorderColor(r, g, b)
	end

	if(UnitIsDead(unit)) then
		health:SetValue(0)
	elseif(UnitIsGhost(unit)) then
		health:SetValue(0)
	end
end

local PostUpdatePower = function(power, unit,min, max)
	if(UnitIsDead(unit) or UnitIsGhost(unit)) then
		power:SetValue(0)
	end
end

local backdrop = {
	bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16,
	edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 8,
	insets = {left = 8, right = 8, top = 8, bottom = 8},
}

local Shared = function(self, unit, isSingle)
	self:SetScript("OnEnter", UnitFrame_OnEnter)
	self:SetScript("OnLeave", UnitFrame_OnLeave)

	self:RegisterForClicks"AnyUp"

	self:SetBackdrop(backdrop)
	self:SetBackdropColor(0, 0, 0, 1)
	self:SetBackdropBorderColor(.3, .3, .3, 1)

	-- Health bar
	local Health = CreateFrame("StatusBar", nil, self)
	Health:SetHeight(20)
	Health:SetStatusBarTexture(_TEXTURE)

	Health:SetPoint("TOP", 0, -8)
	Health:SetPoint("LEFT", 8, 0)
	Health:SetPoint('RIGHT', -8, -50)

	Health.frequentUpdates = true
	Health.colorDisconnected = true
	Health.colorTapping = true
	Health.colorSmooth = true

	Health.PostUpdate = PostUpdateHealth

	self.Health = Health

	local HealthPoints = Health:CreateFontString(nil, "OVERLAY", "GameFontNormal")
	HealthPoints:SetPoint("LEFT", Health, "RIGHT", 2, -1)
	HealthPoints:SetPoint("RIGHT", self, -6, -1)
	HealthPoints:SetJustifyH"CENTER"
	HealthPoints:SetFont(GameFontNormal:GetFont(), 13)
	HealthPoints:SetTextColor(1, 1, 1)

	self:Tag(HealthPoints, '[dead][offline][roc:health]')

	Health.value = HealthPoints

	-- Health bar background
	local HealthBackground = Health:CreateTexture(nil, "BORDER")
	HealthBackground:SetAllPoints(Health)
	HealthBackground:SetAlpha(.5)
	HealthBackground:SetTexture(_TEXTURE)
	Health.bg = HealthBackground
--[[
	local Castbar = CreateFrame("StatusBar", nil, self)
	Castbar:SetStatusBarTexture(_TEXTURE)
	Castbar:SetStatusBarColor(.73, 0, .27, .8)
	Castbar:SetAllPoints(Health)
	Castbar:SetToplevel(true)
	self.Castbar = Castbar
]]--
	-- Unit name
	local Name = Health:CreateFontString(nil, "OVERLAY", "GameFontNormal")
	Name:SetPoint("LEFT", 2, 2)
	Name:SetPoint("RIGHT", -2, -2)
	Name:SetPoint("TOP", 0, -2)
	Name:SetJustifyH"LEFT"
	Name:SetFont(GameFontNormal:GetFont(), 13)
	Name:SetTextColor(1, 1, 1)

	self:Tag(Name, '[name][roc:health]')
	self.Name = Name

	local Leader = self:CreateTexture(nil, "OVERLAY")
	Leader:SetSize(16, 16)
	Leader:SetPoint("BOTTOM", self, "TOP", 0, -7)
	self.Leader = Leader

	-- enable our colors
	self.colors = colors

	if(isSingle) then
		self:SetSize(260, 48)
	end
end

local DoAuras = function(self)
	-- Buffs
	local Buffs = CreateFrame("Frame", nil, self)
	Buffs:SetPoint("BOTTOM", self, "TOP")
	Buffs:SetPoint'LEFT'
	Buffs:SetPoint'RIGHT'
	Buffs:SetHeight(17)

	Buffs.size = 17
	Buffs.num = math.floor(self:GetWidth() / Buffs.size + .5)

	self.Buffs = Buffs

	-- Debuffs
	local Debuffs = CreateFrame("Frame", nil, self)
	Debuffs:SetPoint("TOP", self, "BOTTOM")
	Debuffs:SetPoint'LEFT'
	Debuffs:SetPoint'RIGHT'
	Debuffs:SetHeight(20)

	Debuffs.initialAnchor = "TOPLEFT"
	Debuffs.size = 20
	Debuffs.showDebuffType = true
	Debuffs.num = math.floor(self:GetWidth() / Debuffs.size + .5)

	self.Debuffs = Debuffs
end

local DoPower = function(self)
	-- Power bar
	local Power = CreateFrame("StatusBar", nil, self)
	Power:SetHeight(20)
	Power:SetStatusBarTexture(_TEXTURE)

	Power:SetPoint("BOTTOM", 0, -3)
	Power:SetPoint("LEFT", 8, 0)
	Power:SetPoint('RIGHT', -8, 0)

	Power.colorPower = true
	Power.frequentUpdates = true

	self.Power = Power

	-- Power bar background
	local PowerBackground = Power:CreateTexture(nil, "BORDER")
	PowerBackground:SetAllPoints(Power)
	PowerBackground:SetAlpha(.5)
	PowerBackground:SetTexture(_TEXTURE)
	Power.bg = PowerBackground

	local PowerPoints = Power:CreateFontString(nil, "OVERLAY", "GameFontNormal")
	PowerPoints:SetPoint("LEFT", Power, "RIGHT", 2, -1)
	PowerPoints:SetPoint("RIGHT", self, -6, -1)
	PowerPoints:SetJustifyH"CENTER"
	PowerPoints:SetFont(GameFontNormal:GetFont(), 13)
	PowerPoints:SetTextColor(1, 1, 1)
	self:Tag(PowerPoints, '[roc:power]')

	Power.value = PowerPoints

	Power.PostUpdate = PostUpdatePower

	-- Info string
	local Info = Power:CreateFontString(nil, "OVERLAY", "GameFontNormal")
	Info:SetPoint("LEFT", 2, -2)
	Info:SetPoint("RIGHT", -2, -2)
	Info:SetPoint("BOTTOM", 0, 3)
	Info:SetJustifyH"LEFT"
	Info:SetFont(GameFontNormal:GetFont(), 13)
	Info:SetTextColor(1, 1, 1)

	self:Tag(Info, 'L[level][shortclassification] [raidcolor][smartclass]')
	self.Info = Info
end

local UnitSpecific = {
	target = function(self, ...)
		Shared(self, ...)

		DoAuras(self)
		DoPower(self)
	end,

	targettarget = function(self, unit, isSingle)
		Shared(self, unit, isSingle)

		DoAuras(self)

		if(isSingle) then
			self:SetHeight(32)
		end
	end,
}

do
	local PLAYER_UPDATE_RESTING = function(self)
		if(IsResting()) then
			self:SetBackdropBorderColor(.3, .3, .8)
		else
			local r, g, b = UnitSelectionColor(self.unit)
			self:SetBackdropBorderColor(r, g, b)
		end
	end

	UnitSpecific.player = function(self, ...)
		Shared(self, ...)

		DoPower(self)

		self:RegisterEvent("PLAYER_UPDATE_RESTING", PLAYER_UPDATE_RESTING)
	end
end

do
	local range = {
		insideAlpha = 1,
		outsideAlpha = .5,
	}

	UnitSpecific.party = function(self, ...)
		Shared(self, ...)

		DoAuras(self)
		DoPower(self)

		self.Range = range
	end
end

oUF:RegisterStyle("roc", Shared)
for unit,layout in next, UnitSpecific do
	-- Capitalize the unit name, so it looks better.
	oUF:RegisterStyle('roc - ' .. unit:gsub("^%l", string.upper), layout)
end

-- A small helper to change the style into a unit specific, if it exists.
local spawnHelper = function(self, unit, ...)
	if(UnitSpecific[unit]) then
		self:SetActiveStyle('roc - ' .. unit:gsub("^%l", string.upper))
	else
		self:SetActiveStyle'roc'
	end

	local object = self:Spawn(unit)
	object:SetPoint(...)
	return object
end

oUF:Factory(function(self)
	local player = spawnHelper(self, 'player', "CENTER", -200, -380)
	spawnHelper(self, 'pet', 'TOP', player, 'BOTTOM', 0, -16)
	spawnHelper(self, 'target', "CENTER", 200, -380)
	spawnHelper(self, 'targettarget', "CENTER", 0, -250)

	self:SetActiveStyle'roc - Party'
	local party = self:SpawnHeader(nil, nil, 'raid,party',
		'showParty', true,
		'yOffset', -40,
		'xOffset', -40,
		'maxColumns', 2,
		'unitsPerColumn', 2,
		'columnAnchorPoint', 'LEFT',
		'columnSpacing', 15,

		'oUF-initialConfigFunction', [[
			self:SetWidth(260)
			self:SetHeight(48)
		]]
	)
	party:SetPoint("TOPLEFT", 30, -30)
end)
Attached Thumbnails
Click image for larger version

Name:	roc.jpg
Views:	230
Size:	24.1 KB
ID:	8564  
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote
04-13-15, 09:13 AM   #2
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
I am not an expert but a simply setup could be ?


Lua Code:
  1. local HealthPoints = Health:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  2. HealthPoints:SetFont(GameFontNormal:GetFont(), 13)
  3. HealthPoints:SetTextColor(1, 1, 1)
  4. HealthPoints:SetPoint('RIGHT',Health,'RIGHT', -5, 0 )
  5. self:Tag(HealthPoints, '[dead][offline][roc:health]')
  6. Health.value = HealthPoints

and it should print the value of the hp starting from the right border (-5,0).

Read about the Phanx answer to my question here too:
http://www.wowinterface.com/forums/s...d.php?p=308137
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote
04-13-15, 10:09 AM   #3
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
Thumbs up

Originally Posted by gmarco View Post
I am not an expert but a simply setup could be ?


Lua Code:
  1. local HealthPoints = Health:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  2. HealthPoints:SetFont(GameFontNormal:GetFont(), 13)
  3. HealthPoints:SetTextColor(1, 1, 1)
  4. HealthPoints:SetPoint('RIGHT',Health,'RIGHT', -5, 0 )
  5. self:Tag(HealthPoints, '[dead][offline][roc:health]')
  6. Health.value = HealthPoints

and it should print the value of the hp starting from the right border (-5,0).

Read about the Phanx answer to my question here too:
http://www.wowinterface.com/forums/s...d.php?p=308137
gmarco, that worked perfectly! I have to do some tweaking on the number format and of course the border issue. Thanks!
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote
04-13-15, 11:50 AM   #4
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
At the first I have tried to start my custom layout reading classic or lily (also because the wiki is not so much) but I find a them a bit more difficult to read and begin with than others layouts.

So I test a lot of others and at the end I have used the "Elen" layout to begin to study OUF because I have find it easier for me to begin and to understand even if the "self" construct is a thing I have to approch better ...

I simplified it a lot (also removing the things that Phanx and p3lim pointed me in the string management because I really didn't understand them :-) and then begin to rewrite my own simple layout :-)

For example... the border in this case is quite simple:

Lua Code:
  1. -- [other code here]
  2.  
  3. local backdrop = {
  4.     bgFile      = mediapath .. "back.tga",
  5.     insets = {top = -1, left = -1, bottom = -1, right = -1},
  6. }
  7.  
  8. local backdrop2 = {
  9.     bgFile      = mediapath .. "back.tga",
  10.     insets = {top = -1, left = -1, bottom = -1, right = -1},
  11. }
  12. local statusback = {
  13.     bgFile      = mediapath .. "statusbar.tga",
  14.     insets = {top = 0, left = 0, bottom = 0, right = 0},
  15. }
  16.  
  17. -- [other code here]
  18.  
  19. local cPlayer = function(self)
  20.         self:SetSize(250, 40)
  21.  
  22.         self.Back = CreateFrame('Frame', nil, self)
  23.         self.Back:SetPoint('TOPLEFT', self)
  24.         self.Back:SetWidth(250)
  25.         self.Back:SetHeight(51)    
  26.         self.Back:SetFrameStrata('BACKGROUND')
  27.         self.Back:SetBackdrop(backdrop)
  28.         self.Back:SetBackdropColor(0.05, 0.05, 0.05)   
  29.                
  30.         --: HEALTH BAR :--
  31.         self.Health = CreateFrame('StatusBar', nil, self)
  32.         self.Health:SetPoint('TOPLEFT', self)      
  33.         self.Health:SetWidth(250)
  34.         self.Health:SetHeight(25)          
  35.         self.Health:SetBackdrop(statusback)
  36.         self.Health:SetBackdropColor(0.165,0.165,0.165)
  37.         self.Health:SetFrameStrata('LOW')  
  38.         self.Health:SetStatusBarTexture(statusbar)     
  39.         self.Health.frequentUpdates = FreqUpdate
  40.         self.Health.Smooth = cSmooth
  41.         self.Health.colorClass = false
  42.         self.Health:SetStatusBarColor(START_green[1],START_green[2],START_green[3])
  43.                
  44.         --: POWER BAR :--
  45.         self.Power = CreateFrame('StatusBar', nil, self)
  46.         self.Power:SetPoint('TOPLEFT', self.Health, 'BOTTOMLEFT', 0, -1)
  47.         self.Power:SetHeight(25)
  48.         self.Power:SetWidth(250)
  49.         self.Power:SetBackdropColor(0.15,0.15,0.15)
  50.         self.Power:SetFrameStrata('LOW')
  51.         self.Power:SetStatusBarTexture(statusbar)
  52.         self.Power:SetStatusBarColor(0.28,0.28,0.28)
  53.         self.Power.frequentUpdates = FreqUpdate
  54.         self.Power.Smooth = cSmooth
  55.         self.Power.colorClass = false
  56.         self.Power.colorPower=true
  57.  
  58.     --:: PG NAME ::--  
  59.         self.Info = self.Health:CreateFontString(nil, 'OVERLAY')
  60.         self.Info:SetPoint('LEFT',self.Health,'LEFT', 5, 0)
  61.         self.Info:SetAlpha(1)
  62.         self.Info:SetFont( START_font , START_fs , '')
  63.         self:Tag(self.Info,'[name]')       
  64.        
  65.         --: HEALTH TEXT NUM :--
  66.         self.Health.Text = self.Health:CreateFontString(nil, 'OVERLAY')
  67.         self.Health.Text:SetFont( START_font , START_smfs , '')
  68.         self:Tag(self.Health.Text,'[gmarco:curhp]')
  69.         self.Health.Text.frequentUpdates = FreqUpdate
  70.         self.Health.Text:SetPoint('RIGHT',self.Health,'RIGHT', -5, 0 )
  71.        
  72.         --: POWER TEXT :--
  73.         self.Power.Text = self.Health:CreateFontString(nil, 'OVERLAY')
  74.         self.Power.Text:SetFont(START_font, START_smfs, '')
  75.         self.Power.Text.frequentUpdates = FreqUpdate
  76.         self:Tag(self.Power.Text,'[curpp]')
  77.         self.Power.Text:SetPoint('RIGHT',self.Power,'RIGHT', -5, 0)
  78.        
  79.         self:RegisterEvent("UNIT_THREAT_SITUATION_UPDATE", check_threat)
  80.  
  81. -- and then castbar etc etc ....

As you see :

self.Back:SetHeight(51) = self.Health:SetHeight(25) + 1 pixel from healthbar and powerbar + self.Power:SetHeight(25) .

The countour I think is made by:
insets = {top = -1, left = -1, bottom = -1, right = -1}

The result of this frame can be seen in my answer in the other link above.

Please let me know :-)
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.

Last edited by gmarco : 04-13-15 at 11:55 AM.
  Reply With Quote
04-13-15, 12:49 PM   #5
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
Again thank you! I have downloaded oUF:Elen and will look it over. My brain is starting to understand oUF better now.
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Help with Tweaking oUF:Classic


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