Thread Tools Display Modes
06-15-10, 08:44 AM   #1
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
breaking it down.

Okay upon everyone's suggestion im attempting to shorten code.

best way i can see especially when needing to do something for 4 sets of frames all the time, is to use local function blahblah(i) where i = the partyframe number. The problem or question i have is how to tag certain lines when trying to use ..i.. like the following...

lua Code:
  1. local function Party1Style1NameTextEvents()
  2.     local Party1Exists = UnitExists("Party1")
  3.     if Party1Exists == 1 then
  4.         local Party1Name = UnitName("Party1")
  5.         local Party1NameStr = ("%s"):format(Party1Name)
  6.         Party1NameText:SetText(Party1NameStr)
  7.     end
  8.         GrimUI.Party1NameColoring()
  9. end
  10. GrimUI.Party1Style1NameTextEvents = Party1Style1NameTextEvents

ultimately i need everywhere it says Party1 to read Party..i..

ive been successful in breaking down somethings but the tag is different for certain things... like the following
lua Code:
  1. CreateFrame('Frame', "Party"..i.."PedestalFrame", _G["GUI_Party"..i.."Frame"])

the one version is a already made frame... the other is the new frame. one needs _G and [] the other does not. there is a handful of other things not frame name or current frame id like to change 1 to a variable to shorten the 4x repeated party frame creation...
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
06-15-10, 09:30 AM   #2
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
Not every component of the unit frame needs to be named (global). Why not just:
Code:
local frame = Create("Frame", "GUI_Party" .. i .. ''Frame", UIParent, "SecureUnitButtonTemplate")
frame.pedestal = Create("Frame", nil, frame)
I would also save the unit with the frame so that you don't have to keep concating it:
Code:
frame.unit = "party" .. i
Then you could do something such as:
Code:
function GrimUI.PartyStyle1NameTextEvents(self)
    if UnitExists(self.unit) == 1 then
        self.nameText:SetFormattedText("%s", UnitName(self.unit))
    end
    self:ApplyNameColoring()
end
  Reply With Quote
06-15-10, 10:03 AM   #3
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
part of the problem is i dont think the frame.pedestal part will work because the style selection function looks for Party1PedestalFrame to do a bunch of things to that frame...

what really makes this complicated is the style1 and style2 functions... whitch is why i global named so many things because when i do local and dont set a name for something in its global name space ("frame", namethatgoesinGnamespace, parent, inherit)

it does not seem able to find the right stuff later for the style functions. although i have this idea on the tip of my tongue and i think its what you would say to do... lol... what i think needs to be done is i remove the party1 part from all the stuff in the style function and replace it with frame.* something i think im a little unclear on when it comes to frame creation. So lets say i do what you had posted above, and cargor also sent me a chunk of code that appears to do the same thing, it looks as though it makes the pedestal frame but never separates it other then the frame its originally created by IE frame.pedestal so what im wondering about is when it makes the 2nd frame.pedestal for party2 technically pedestal frame will have the same name as party1. so when you do the frame. is that making it a child of party1 frame? and is it going to know that the pedestal frame for party1 is dif then the one for party two even though they have the same name? edit -- or no name at all?

also i take it that "party" .. i is another means of setting the variable, just like for other things its "..i.."? and frame.unit is that like setting the unit attrib? i dont understand how that translates to local Party1Exists = UnitExists("Party1")? edit-- i see now how it hooks the unit.
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]

Last edited by Grimsin : 06-15-10 at 10:16 AM.
  Reply With Quote
06-15-10, 11:55 AM   #4
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
even though frame is local it can be used through out all my functions if i put those first two in a function?

also just noticed you only use create? not createframe?
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]

Last edited by Grimsin : 06-15-10 at 12:02 PM.
  Reply With Quote
06-15-10, 01:19 PM   #5
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
Originally Posted by Grimsin View Post
even though frame is local it can be used through out all my functions if i put those first two in a function?

also just noticed you only use create? not createframe?
The "Create" should be "CreateFrame" I just goofed on that.

As for all the other stuff. Its object oriented. You make a generic function that creates your object and have generic functions that work on those object. The idea is to only code specifically to what the object is in general but not to any one particular member of the set.

So you do (just a rough example):
Code:
flocal function ApplyNameColoring(self)
	self.nameText:SetTextColor(1, 1, 1, 1)
end

local function PartyStyle1NameTextEvents(self)
    if UnitExists(self.unit) == 1 then
        self.nameText:SetFormattedText("%s", UnitName(self.unit))
    end
    self:ApplyNameColoring()
end

function GrimUI.CreatePartyFrame(id)
	local frame = CreateFrame('Button', 'GrimUIPartyFrame' .. id, 'SecureUnitButtonTemplate')
	frame.healthBar = CreateFrame('StatusBar', nil, frame)
	frame.manaBar = CreateFrame('StatusBar', nil, frame)
	frame.nameText = CreateFontString(nil, 'ARTWORK')
	frame.pedestal = CreateFrame('Frame', nil, frame)
	frame.unit = 'party' .. id

	frame.ApplyNameColoring = ApplyNameColoring

	return frame
end

for id = 1, 4 do
	GrimUI.CreatePartyFrame(id)
end
Each party frame is created and is completely separate from the other. The only thing they share is their methods. When you do GrimUIPartyButton1:ApplyNameColoring() the first argument that is passed is the frame for GrimUIPartyFrame1 and in the function for ApplyNameColoring you see that the first argument is named self. So when you do self.unit it will be the value that matches the party frame you called it with.

If you want to access the pedestal frame for party member 3 you would do GrimUIPartyFrame3.pedestal. Or if you wanted to perform roughly the same operation on all four party frame pedestals then:
Code:
for id = 1, 4 do
	local frame = _G['GrimUIPartyFrame' .. id]
	local pedestal = frame.pedestal
	pedestal:ClearAllPoints()
	pedestal:SetPoint('BOTTOMLEFT', frame.healthBar, 'BOTTOMRIGHT', 3, 0)
	pedestal:SetPoint('BOTTOMRIGHT', frame.manaBar, 'BOTTOMLEFT', -3, 0)
	pedestal:SetHeight(20)
end
  Reply With Quote
06-15-10, 01:28 PM   #6
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
its becoming clearer and clearer... working on redoing things still a couple complicated parts. Can the frame.blahblah be doubled over again for creating textures like frame.PedestalFrame.texture ? for doing the fontstrings and textures?

here is what i have going on so far for my base frame creation using what you posted this morning. im starting to just comment out my old stuff so i can see what i changed it from-to to get a better idea of whats going on. is what i have so far correct? this creates each party frame and all of each ones individual sub frames correct? edit -- and = 1, 4 do stands for 1-4?

lua Code:
  1. local function createPartyFrames(i)
  2.     -- Main Frame
  3.     local frame = CreateFrame("Frame", "GUI_Party" .. i .. "Frame", UIParent, "SecureUnitButtonTemplate")
  4.     frame.unit = "party" .. i
  5.     -- Pedestal Frame
  6.     --CreateFrame('Frame', "Party"..i.."PedestalFrame", _G["GUI_Party"..i.."Frame"])
  7.     frame.PedestalFrame = CreateFrame("Frame", nil, frame)
  8.     -- Health Bar
  9.     --CreateFrame('Button', "Party"..i.."HealthBorder", _G["GUI_Party"..i.."Frame"], "SecureActionButtonTemplate")
  10.     frame.HealthBorder = CreateFrame("button", nil, frame)
  11.     --CreateFrame("StatusBar", "Party"..i.."HealthBar", _G["GUI_Party"..i.."Frame"], "TextStatusBar")
  12.     frame.HealthBar = CreateFrame("StatusBar", nil, frame)
  13.     --CreateFrame("Frame", "Party"..i.."HealthNumTxtFrame", _G["GUI_Party"..i.."Frame"])
  14.     frame.HealthNumTxtFrame = CreateFrame("Frame", nil, frame)
  15.    
  16.     -- Mana Bar
  17.     --CreateFrame('Button', "Party"..i.."ManaBorder", _G["GUI_Party"..i.."Frame"], "SecureActionButtonTemplate")
  18.     frame.ManaBorder = CreateFrame("button", nil, frame)
  19.     --CreateFrame("StatusBar", "Party"..i.."ManaBar", _G["GUI_Party"..i.."Frame"], "TextStatusBar")
  20.     frame.ManaBar = CreateFrame("StatusBar", nil, frame)
  21.     --CreateFrame("Frame", "Party"..i.."ManaNumTxtFrame", _G["GUI_Party"..i.."Frame"])
  22.     frame.ManaNumTxtFrame = CreateFrame("Frame", nil, frame)
  23.    
  24.     -- Misc Frames
  25.     --CreateFrame("button", "Party"..i.."InfoTextFrame", _G["GUI_Party"..i.."Frame"], "SecureActionButtonTemplate")
  26.     frame.InfoTextFrame = CreateFrame("button", nil, frame)
  27.     --CreateFrame("Frame", "Party"..i.."LetterFrame", _G["GUI_Party"..i.."Frame"])
  28.     frame.LetterFrame = CreateFrame("Frame", nil, frame)
  29.     --CreateFrame("Frame", "Party"..i.."LeaderFrame", _G["GUI_Party"..i.."Frame"])
  30.     frame.LeaderFrame = CreateFrame("Frame", nil, frame)
  31.     --CreateFrame("Frame", "Party"..i.."pvpIconFrame", _G["GUI_Party"..i.."Frame"])
  32.     frame.pvpIconFrame = CreateFrame("Frame", nil, frame)
  33.     --CreateFrame("Frame", "Party"..i.."offDeadGhostTxtFrame", _G["GUI_Party"..i.."Frame"])
  34.     frame.offDeadGhostTxtFrame = CreateFrame("Frame", nil, frame)
  35.     -- Target Bar
  36.     --CreateFrame("frame", "targetOfParty"..i.."Frame", _G["GUI_Party"..i.."Frame"])
  37.     frame.targetOfFrame = CreateFrame("Frame", nil, frame)
  38.     --CreateFrame("button", "targetOfParty"..i.."ClickFrame", _G["GUI_Party"..i.."Frame"], "SecureActionButtonTemplate")
  39.     frame.targetOfClickFrame = CreateFrame("button", nil, frame)
  40. end
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]

Last edited by Grimsin : 06-15-10 at 01:37 PM.
  Reply With Quote
06-15-10, 01:33 PM   #7
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
hmm, couldn't you use "$parentPedestal" etc

EG.

Code:
function CreatePartyFrame(id)   
   local f = CreateFrame("Frame","Party"..id,..)
   f.PartyID = "Party"..id
   f.Pedestal = CreateFrame("Frame","$parentPedestal",f,...)
   f.Pet = CreateFrame("Frame","$parentPet",f,...)
   etc
   return f
end

CreatePartyFrame(1)
CreatePartyFrame(2)
etc

EDIT: Just read your last post, and yes that is similar to how I deal with frames within frames. And yes, you can drill down further and access sub frames of sub frames like frame.pedestal.texture.overlay.etc

Originally Posted by Grimsin View Post
part of the problem is i dont think the frame.pedestal part will work because the style selection function looks for Party1PedestalFrame to do a bunch of things to that frame...

what really makes this complicated is the style1 and style2 functions... whitch is why i global named so many things because when i do local and dont set a name for something in its global name space ("frame", namethatgoesinGnamespace, parent, inherit)

it does not seem able to find the right stuff later for the style functions. although i have this idea on the tip of my tongue and i think its what you would say to do... lol... what i think needs to be done is i remove the party1 part from all the stuff in the style function and replace it with frame.* something i think im a little unclear on when it comes to frame creation. So lets say i do what you had posted above, and cargor also sent me a chunk of code that appears to do the same thing, it looks as though it makes the pedestal frame but never separates it other then the frame its originally created by IE frame.pedestal so what im wondering about is when it makes the 2nd frame.pedestal for party2 technically pedestal frame will have the same name as party1. so when you do the frame. is that making it a child of party1 frame? and is it going to know that the pedestal frame for party1 is dif then the one for party two even though they have the same name? edit -- or no name at all?

also i take it that "party" .. i is another means of setting the variable, just like for other things its "..i.."? and frame.unit is that like setting the unit attrib? i dont understand how that translates to local Party1Exists = UnitExists("Party1")? edit-- i see now how it hooks the unit.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818

Last edited by Xrystal : 06-15-10 at 01:35 PM.
  Reply With Quote
06-15-10, 01:38 PM   #8
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Originally Posted by Xrystal View Post
hmm, couldn't you use "$parentPedestal" etc
<snip>
No. This isn't XML.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
06-15-10, 01:41 PM   #9
nightcracker
A Molten Giant
 
nightcracker's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 716
Originally Posted by Torhal View Post
No. This isn't XML.
BEEEEEEEP

Yes you can.

Try this for example:
Code:
CreateFrame("Frame", "$parentTest", UIParent)
print(UIParentTest)
Except for creating a virtual frame and making bindings EVERYTHING in XML can be done in Lua.

@vrul: GTFO from my avatar
__________________
Three things are certain,
Death, taxes and site not found,
You, victim of one.
  Reply With Quote
06-16-10, 10:36 AM   #10
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
All 4 files involved with this maybe itll alliviate some confusion if it can all be seen... noticed Vrul that you made a new function for the registerevents? didnt dbl check if it matched the one in the core ornot but... this way it all can be seen.

GrimUICore.lua -- http://www.pastey.net/137744 -- this is the very first file in my UI to load. Loads variable defaults, sets up a few tables and loads addon wide util functions.

PartyFrames.lua -- http://www.pastey.net/137745 -- obviously the party frames. loads after GrimUICore. includes changes i made this morn to what Vrul posted.

MoveFrames.lua -- http://www.pastey.net/137747 -- moves a lot of frames including the GrimPlayerFrame and Partyframes. Loads after PartyFrames.

GrimUIOptions.lua -- http://www.pastey.net/137748 -- Last file in the whole addon to load controls all of the few options currently available accross all files, primarily involves playerframe and party frame for both GrimUI and Bliz frames. by options i mean options actually in the OptionsPanel.


oh btw... the current GrimUI release the partyframes function perfectly except the option to switch styles is not available there... you would have to change the variable in the wtf by hand to make it switch lol. But the frames function as intended minus the raid hide/show part but yea the frame movement functions right. and the file is still a monster lol

edit-- so after a lot of testing and reading i have it narrowed down to 3 things wrong i think. the frame movement is not loading its saved position as it should because of the layoutinitiate() function. The events are not registering no completly sure why, and the dropdown menus need to have various parents rather then parented to the grimpartyframe which i may have under control, target drop down is showing the party member drop down rather then target drop to to... 3 problems position loading, events registration and dropdowns. pretty good considering i dont know what im doing and vrul was doing it half blind

edit-- oh and yes im well aware that style2 to is borked i have not even begun to fix that part
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]

Last edited by Grimsin : 06-16-10 at 11:46 AM.
  Reply With Quote
06-16-10, 11:50 AM   #11
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
i know this is just throwing another monkey wrench into the issue but that force hide show function i had... idealy an unregister module function or turn of module option that unloads the whole partyframe module would be best. i dont know if thats possible... and would most likely involve a reload to actually unload it entirely. im sure of that... to get rid of the frames already created before the module is unregistered...
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
06-16-10, 11:54 AM   #12
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
Originally Posted by Grimsin View Post
i know this is just throwing another monkey wrench into the issue but that force hide show function i had... idealy an unregister module function or turn of module option that unloads the whole partyframe module would be best. i dont know if thats possible... and would most likely involve a reload to actually unload it entirely. im sure of that... to get rid of the frames already created before the module is unregistered...
Once a frame is made you are stuck with it until a reload. It can be changed to work how you said though, just give me some time to look it all over again.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » breaking it down.


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