06-15-10, 08:44 AM | #1 |
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:
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:
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... |
|
06-15-10, 09:30 AM | #2 |
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) Code:
frame.unit = "party" .. i Code:
function GrimUI.PartyStyle1NameTextEvents(self) if UnitExists(self.unit) == 1 then self.nameText:SetFormattedText("%s", UnitName(self.unit)) end self:ApplyNameColoring() end |
|
06-15-10, 10:03 AM | #3 |
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. Last edited by Grimsin : 06-15-10 at 10:16 AM. |
|
06-15-10, 11:55 AM | #4 |
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? Last edited by Grimsin : 06-15-10 at 12:02 PM. |
|
06-15-10, 01:19 PM | #5 | |
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 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 |
||
06-15-10, 01:28 PM | #6 |
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:
Last edited by Grimsin : 06-15-10 at 01:37 PM. |
|
06-15-10, 01:33 PM | #7 | |
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
__________________
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. |
||
06-15-10, 01:38 PM | #8 |
__________________
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. |
|
06-15-10, 01:41 PM | #9 |
BEEEEEEEP
Yes you can. Try this for example: Code:
CreateFrame("Frame", "$parentTest", UIParent) print(UIParentTest) @vrul: GTFO from my avatar
__________________
Three things are certain, Death, taxes and site not found, You, victim of one. |
|
06-15-10, 01:51 PM | #10 |
*ahem*
manners.... |
|
06-15-10, 02:28 PM | #11 |
okay so i can add this to my frame creation part and create the font strings?
frame.HealthBorder.percentPartyHText = CreateFontString(nil, "OVERLAY", "GameFontNormalSmall") and what about textures? does this count? frame.PedestalFrame.texture = frame.PedestalFrame:CreateTexture() Last edited by Grimsin : 06-15-10 at 02:31 PM. |
|
06-15-10, 02:45 PM | #12 |
okay heres what i got going now, hopefully thats all valid for the textures and the fonts?
lua Code:
|
|
06-15-10, 03:29 PM | #13 |
okay here we go... i think i got the idea... this is where im at right now. anyone see anything wrong with what im doing? i have not tested it yet about to do so although i know other problems exists in the code beyond this that will most likely prevent me from seeing if this will work... anyhow heres what i got goin on.
lua Code:
|
|
06-15-10, 03:35 PM | #14 |
What looks strange is that there's so many "sub-frames" being created. A lot of things could probably just be FontStrings or Textures can't they ?
__________________
I stopped playing back World of Warcraft in 2010 and I have no plans on returning. This is a dead account and if you want to continue any of my addons or make a fork then feel free to do so. This is your permission slip. If you need to contact me, do so on Twitter @v6ooo Best regards, v6. |
|
06-15-10, 03:53 PM | #15 |
hmm well as far as i know most of them are necisary in order to do the dif frame styles. also in order to make text set positioning right ive found its best to make a frame just for the text that you can then anchor to each side and top of then use justify and itll make test always span one direction or the other according to its setpoint and itll autotrunct beyond its frames setpoints
|
|
06-15-10, 04:20 PM | #16 |
got a problem... i think.
so if i use the self in a function that is responding to events and the function is only used in the onevent script of a frame that is outside the initial frame creation code.... it wont recognize self as the party frames right? the partyframe has to run the code somehow? like i fixed the name coloring code to read as follows i think this is how it should be set up per everyone's instructions ill do my best to show it here in proper order... so here is the name coloring code lua Code:
now here is the function thats been made to call it lua Code:
now here is what calls that function lua Code:
now here is ultimately where i think the big mistake is and maybe it is as easy as parenting the event frames to the party frames in some way? or adding them to the frame creation part? im not sure how that would go... but here is what it is currently, clearly it has no link with the partyframes themselves other then to initiate the event scripts lua Code:
|
|
06-15-10, 04:48 PM | #17 |
What you could also do is have the individual frames monitor their own events.
Eg: HealthBar:RegisterEvent("UNIT_HEALTH") ManaBar:RegisterEvent("UNIT_MANA") etc
__________________
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 |
|
06-15-10, 04:57 PM | #18 | ||
What Xrystal said is the easiest way to handle multiple frames; let them handle their own events.
And for the "self error"; You're doing it wrong here. You're not passing self as the first argument.
No point creating the small extra function, this also passes all arguments.
__________________
I stopped playing back World of Warcraft in 2010 and I have no plans on returning. This is a dead account and if you want to continue any of my addons or make a fork then feel free to do so. This is your permission slip. If you need to contact me, do so on Twitter @v6ooo Best regards, v6. Last edited by v6o : 06-15-10 at 05:02 PM. |
|||
06-15-10, 04:58 PM | #19 |
yea i think that is how i just did it, although i was under the idea that events only fire to uiparent and you cant register events to a frame that does not parent to UIParent but... were gonna try having the events on their individual frames. i think in theory this will make it so that the frames will fire for only events that should trigger them rather then say every frame updating its target because party member 1 changed targets. i could be wrong on all of this though... maybe Vrul will chime in again soon.
|
|
06-15-10, 05:02 PM | #20 |
i changed it up totally think this is what Xrystal was talking about
the frame creation lua Code:
here is the event registration to each frame lua Code:
here is the new setscript lua Code:
Last edited by Grimsin : 06-15-10 at 05:05 PM. |
|
WoWInterface » Developer Discussions » Lua/XML Help » breaking it down. |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|