Thread Tools Display Modes
10-27-09, 01:13 AM   #1
ahhnam
A Murloc Raider
Join Date: Aug 2009
Posts: 6
New to creating oUF needs help

I am pretty new to programming so for the past week I was looking into other people's oUF files to try to get a basic understanding of what to do and come up with something that doesn't seem to work properly and I can't really figure out why and was just wondering if anyone can give me some pointers. Thank you.

Code:
-- Framework

local function Func(self, unit)
	self.colors = colors
	self.menu = menu
	
	self:RegisterForClicks('anyup')
	self:SetAttribute('*type2', 'menu')
	
	self:SetScript('OnEnter', UnitFrame_OnEnter)
	self:SetScript('OnLeave', UnitFrame_OnLeave)
	
	self:SetBackdrop(backdrop)
	self:SetBackdropColor(0, 0, 0)

-- Health Frame
	
	self.Health = CreateFrame('StatusBar', nil, self)
	self.Health:SetHeight(20)
	self.Health:SetWidth(200)
	self.Health:SetPoint("TOPLEFT")
	self.Health:SetPoint("TOPRIGHT")
	self.Health:SetStatusBarTexture(minimalist)
	self.Health.frequentUpdates = true
	self.Health.colorSmooth = true
	self.Health.colorClass = true
	
	self.Health.bg = self.Health:CreateTexture(nil, 'BORDER')
	self.Health.bg:SetAllPoints(self.Health)
	self.Health.bg:SetTexture(0.3, 0.3, 0.3)
--

-- Power Frame

	self.Power = CreateFrame('StatusBar', nil, self)
	self.Power:SetHeight(3)
	self.Power:SetWidth(200)
	self.Power:SetPoint("TOPLEFT", self.Health, "BOTTOMLEFT", 0, -3)
	self.Power:SetPoint("TOPRIGHT", self.Health, "BOTTOMRIGHT", 0, -3)
	self.Power.colorSmooth = true
	self.Power.frequentUpdates = true
	self.Power.colorPower = true
--

end

oUF:RegisterStyle('3xp', Func)
oUF:SetActiveStyle('3xp')

oUF:Spawn('player'):SetPoint('CENTER', UIParent, -220, -250)
Yep that's it, I tried to see if I can get the basic working before going further and so far it's still failing.
  Reply With Quote
10-27-09, 06:28 AM   #2
Dawn
A Molten Giant
 
Dawn's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 918
You really should not start from scratch if you are new to oUF, imho. I would crab one of the existing layouts and modify them to your need or at least look at oUF_Classic and/or oUF_Lilly which are so to say "official" layouts for reference, by haste.

Besides of that your layout is TO basic, you need to add a little more to actually spawn some frames.
  Reply With Quote
10-27-09, 07:44 AM   #3
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
Originally Posted by ahhnam View Post
Yep that's it, I tried to see if I can get the basic working before going further and so far it's still failing.
Is that the entire code or are you posting just a part of it?
What errors are you getting?
  Reply With Quote
10-27-09, 07:59 AM   #4
Dawn
A Molten Giant
 
Dawn's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 918
It's pretty much possible that this code doesn't produce much or any errors. At least it's shouldn't show anything in game.
  Reply With Quote
10-27-09, 11:40 AM   #5
ahhnam
A Murloc Raider
Join Date: Aug 2009
Posts: 6
I see, yea that was sort of the problem lol nothing would show up, I thought that maybe at least it would show my own hp and power bars but I guess not. Anyway thanks for your help, I'll add more to it first before posting again, this is sort of like a side project thing for me so I understand lua a little better. =)
  Reply With Quote
10-27-09, 12:13 PM   #6
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
your frame is missing initial height/width.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
10-27-09, 12:59 PM   #7
Beladona
A Molten Giant
 
Beladona's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 539
for starters, you need to set the size of the frame itself, either by anchoring two opposing points, or doing a SetWidth and SetHeight on it. I would recommend the latter:

self:SetWidth(200);
self:SetHeight(26);

next, you are setting the width and height of the health and power bars. But then you are also setting the TOPLEFT and TOPRIGHT points. Doing this means you don't need SetWidth. So you may as well remove that, and just keep the SetHeight for each bar. They will already be a width of 200, since that is the width of your frame and you are anchoring the TOPLEFT and TOPRIGHT to the TOPLEFT and TOPRIGHT of your frame anyway.

Next, nowhere do I see you define colors, menu, backdrop, or minimalist. One assumes you aren't showing us all of your code, but I don't like to assume, so I would make sure you have those defined somewhere in your file.
  Reply With Quote
10-27-09, 01:11 PM   #8
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
Using SetWidth / SetHeight isn't recommended. You'll get some taint warnings doing that on the party frames.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
10-28-09, 01:40 AM   #9
ahhnam
A Murloc Raider
Join Date: Aug 2009
Posts: 6
First off, thank you for all your replies and I took the advice and took Classic as a guide and edited a lot of the codes from inside and looks something like this. It's really messy right now and I still don't have a good enough understanding to what I am doing but it's a start.

As for questions,
1. I'm trying to create cast bars using ouf_p3lim as a guideline and so far what I did with it doesn't seem to function at all and I can't seem to figure out what's going on and what I am missing from it.

Code:
local texture = [[Interface\AddOns\oUF_Classic\media\minimalist]]
local height, width = 47, 260
local gray = {.3, .3, .3}

local colors = setmetatable({
	power = setmetatable({
		['MANA'] = {72/255, 188/255, 200/255},
		['RAGE'] = {1, 69/255, 0},
		['RUNIC_POWER'] = {238/255, 59/255, 59/255},
		['ENERGY'] = {238/255, 201/255, 0},
	}, {__index = oUF.colors.power}),
}, {__index = oUF.colors})

local menu = function(self)
	local unit = self.unit:sub(1, -2)
	local cunit = self.unit:gsub("(.)", string.upper, 1)

	if(unit == "party" or unit == "partypet") then
		ToggleDropDownMenu(1, nil, _G["PartyMemberFrame"..self.id.."DropDown"], "cursor", 0, 0)
	elseif(_G[cunit.."FrameDropDown"]) then
		ToggleDropDownMenu(1, nil, _G[cunit.."FrameDropDown"], "cursor", 0, 0)
	end
end

if(not oUF.Tags['[happiness]']) then
	oUF.Tags['[happiness]'] = function(unit)
		local happiness
		if(unit == 'pet') then
			happiness = GetPetHappiness()
			if(happiness == 1) then
				happiness = ":<"
			elseif(happiness == 2) then
				happiness = ":|"
			elseif(happiness == 3) then
				happiness = ":D"
			end
		end

		return happiness or ''
	end

	oUF.TagEvents['[happiness]'] = 'UNIT_HAPPINESS'
end

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

local PostUpdateHealth = function(self, event, unit, bar, min, max)
	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
		bar:SetValue(0)
		bar.value:SetText"Dead"
	elseif(UnitIsGhost(unit)) then
		bar:SetValue(0)
		bar.value:SetText"Ghost"
	elseif(not UnitIsConnected(unit)) then
		bar.value:SetText"Offline"
	else
		bar.value:SetFormattedText('%s/%s', siValue(min), siValue(max))
	end
end

local PostUpdatePower = function(self, event, unit, bar, min, max)
	if(min == 0) then
		bar.value:SetText()
	elseif(UnitIsDead(unit) or UnitIsGhost(unit)) then
		bar:SetValue(0)
	elseif(not UnitIsConnected(unit)) then
		bar.value:SetText()
	else
		bar.value:SetFormattedText('%s/%s', siValue(min), siValue(max))
	end
end

local function castTime(self, duration)
	if(self.channeling) then
		self.Time:SetFormattedText('%.1f ', duration)
	elseif(self.casting) then
		self.Time:SetFormattedText('%.1f ', self.max - duration)
	end
end

local function castIcon(self, event, unit)
	local castbar = self.Castbar
	if(castbar.interrupt) then
		castbar.Button:SetBackdropColor(0, 0.9, 1)
	else
		castbar.Button:SetBackdropColor(0, 0, 0)
	end
end

local backdrop = {
	bgFile = [=[Interface\ChatFrame\ChatFrameBackground]=],
	insets = {top = -1, bottom = -1, left = -1, right = -1}
}
	--Frame
local func = function(settings, self, unit)

	self.menu = menu
	self.colors = colors

	self:SetScript("OnEnter", UnitFrame_OnEnter)
	self:SetScript("OnLeave", UnitFrame_OnLeave)

	self:RegisterForClicks"anyup"
	self:SetAttribute("*type2", "menu")
	
	self:SetBackdrop(backdrop)
	self:SetBackdropColor(0, 0, 0, 1)
	self:SetBackdropBorderColor(.3, .3, .3, 1)

	-- Health bar
	
	local hp = CreateFrame("StatusBar", nil, self)
	hp:SetHeight(20)
	if(unit == "target" or unit == "player") then
		self:SetAttribute('initial-height', 34)
		self:SetAttribute('initial-width', 200)
	else
		self:SetAttribute('initial-height', 20)
		self:SetAttribute('initial-width', 150)
	end
	hp:SetStatusBarTexture(texture)
	hp:SetStatusBarColor(0.25, 0.25, 0.35)

	hp:SetPoint("TOP", 0, 0)
	hp:SetPoint("LEFT", 0, 0)
	
	hp.frequentUpdates = true
	hp.colorDisconnected = true
	hp.colorTapping = true
	hp.colorHappiness = true
	hp.colorSmooth = true
	hp.colorClass = true

	self.Health = hp
	
	-- Health Font
	if(unit == "player" or unit == "target") then
		local hpfont = hp:CreateFontString(nil, "OVERLAY")
		if(unit == "player") then
			hpfont:SetPoint("LEFT", hp, "RIGHT", 2, 0)
		else
			hpfont:SetPoint("RIGHT", hp, "LEFT", -2, 0)
		end
		hpfont:SetFont(GameFontNormal:GetFont(), 11)
		hpfont:SetTextColor(1, 1, 1)
	
	self.Health.value = hpfont
	
	self.PostUpdateHealth = PostUpdateHealth
	end
	
	-- Health bg
	local hpbg = hp:CreateTexture(nil, "BORDER")
	hpbg:SetAllPoints(hp)
	hpbg:SetTexture(0, 0, 0)
	hp.bg=hpbg

	-- Power Bar
	if(unit == "player" or unit == "target") then
		local pb = CreateFrame("StatusBar", nil, self)
		pb:SetHeight(14)
		pb:SetStatusBarTexture(texture)
	
		pb:SetPoint("TOPRIGHT", hp, "BOTTOMRIGHT", 0, -1)
		pb:SetPoint("TOPLEFT", hp, "BOTTOMLEFT", 0, -1)

		pb.colorPower = true
		pb.Smooth = true
		pb.frequentUpdates = true
	
		self.Power = pb
	
	-- Power bg
		local pbbg = pb:CreateTexture(nil, "BORDER")
		pbbg:SetAllPoints(pb)
		pbbg:SetTexture(0, 0, 0)
		pb.bg = pbbg
	
	-- Power Font
		local pbfont = hp:CreateFontString(nil, "OVERLAY")
		if(unit == "player") then
			pbfont:SetPoint("LEFT", pb, "RIGHT", 2, 0)
		else
			pbfont:SetPoint("RIGHT", pb, "LEFT", -2, 0)
		end
		pbfont:SetFont(GameFontNormal:GetFont(), 11)
		pbfont:SetTextColor(1, 1, 1)
	
		pb.value = pbfont
	
		self.PostUpdatePower = PostUpdatePower
	end
	
	-- Unit name
	if(unit == "focus" or unit == "targettarget") then
		local name = hp:CreateFontString(nil, "OVERLAY", "GameFontNormal")
		name:SetPoint("LEFT", 2, -1)
		name:SetPoint("RIGHT", -2, 0)
		name:SetJustifyH"LEFT"
		name:SetFont(GameFontNormal:GetFont(), 11)
		name:SetTextColor(1, 1, 1)

		self:Tag(name, '[name]')
		self.Name = name
	end
	
	-- Cast Bar
	if(unit == "player" or unit == "target") then
		
		self.Castbar = cb
		
		cb = CreateFrame("StatusBar", nil, self)
		cb:SetWidth(200)
		cb:SetHeight(16)
		cb:SetStatusBarTexture(texture)
		cb:SetBackdrop(backdrop)
		
		cb.bg = cb:CreateTexture(nil, "BORDER")
		cb.bg:SetAllPoints(cb)
		cb.bg:SetTexture(0.3, 0.3, 0.3)
		
		cb.Text = cb:CreateFontString(nil, "OVERLAY", "GameFontNormal")
		cb.Text:SetPoint("LEFT", 2, 1)
		
		cb.CustomTimeText = castTime
		cb.Time = cb:CreateFontString(nil, "OVERLAY", "GameFontNormal")
		cb.Time:SetPoint("RIGHT", -2, 1)
		
		cb.Button = CreateFrame("Frame", nil, cb)
		cb.Button:SetHeight(21)
		cb.Button:SetWidth(21)
		cb.Button:SetBackdrop(backdrop)
		
		cb.Icon = cb.Button:CreateTexture(nil, "ARTWORK")
		cb.Icon:SetAllPoints(cb.Button)
		
		self.PostCastStart = castIcon
		self.PostChannelStart = castIcon
		
		if(unit == "player") then
			cb:SetPoint("CENTER", -100, -330)
			cb.Button:SetPoint("BOTTOMRIGHT", cb, "BOTTOMLEFT", -4, 0)
		else
			cb:SetPoint("CENTER", -100, -300)
			cb.Button:SetPoint("BOTTOMRIGHT", cb, "BOTTOMLEFT", -4, 0)
		end
	end
end

oUF:RegisterStyle("Classic", setmetatable({
	["initial-width"] = width,
	["initial-height"] = height,
}, {__call = func}))

oUF:SetActiveStyle"Classic"

-- Spawn
oUF:Spawn("player"):SetPoint("CENTER", -200, -270)
oUF:Spawn("target"):SetPoint("CENTER", 200, -270)
oUF:Spawn("focus"):SetPoint("TOPLEFT", oUF.units.player, "BOTTOMLEFT", 0, -4)
oUF:Spawn("targettarget"):SetPoint("TOPRIGHT", oUF.units.target, "BOTTOMRIGHT", 0, -4)
Sorry for the noob questions and thanks in advance.
  Reply With Quote
10-28-09, 01:45 AM   #10
wurmfood
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 122
Take the "self.Castbar = cb" and put it at the end of the code where you define cb. Otherwise, when it's assigned, cb is nil and so is your castbar.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » New to creating oUF needs help


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