09-16-14, 01:53 PM | #1 |
!Beautycase getting started
Hey there.
How do i start with beautycase? In the addon description it says: First: DONT'T put the code snippets into the beautycase file. Create a little addons and put the code in its .lua file. I just found a video where the guy did put it directly into the code of every addon. Could someone provide me a little lua snipped of how it have to look that i can simply insert the Code:
myFrame:CreateBorder(borderSize) I for example tryed: Bagnon:CreateBorder(12,1,1,1) BagnonFrameinvnetory:CreateBorder(12,1,1,1) BagnonFrame:CreateBorder(12,1,1,1) Bagnon:CreateBorder(12,1,1,1) BagnonFramebank:CreateBorder(12,1,1,1) And simply bot them at "the end of the lua file" as it was exmplained in some comments. Everything did just end up with lua errors. Last edited by Lightbound : 09-16-14 at 02:16 PM. |
|
09-16-14, 11:49 PM | #2 |
You can put the code in each addon, but the problem with that is that you'll have to remember to re-do it every time each addon is updated. Using a separate addon is better.
For Bagnon (and some other addons) the problem is that they don't create their frames until they're actually needed. So for example, BagnonFrameinventory (which has a typo in your code, BTW) does not exist before the first time you open your bags. For these types of addons, you'll have to find the function in their code that creates the frames, and hook that function in your code: Code:
if Bagnon then -- Add a border to each frame as Bagnon creates it: hooksecurefunc(Bagnon, "CreateFrame", function(Bagnon, id) -- Get a reference to the frame object: local frame = Bagnon.frames[id] -- Add your border: frame:CreateBorder(12,1,1,1) end) end Code:
## OptionalDependencies: Bagnon, SomeOtherAddon, YetAnotherAddon Code:
Minimap:CreateBorder(12,1,1,1) -- OK because Blizzard frames are created before any addons load if Recount_MainWindow then -- don't forget to add Recount to the OptionalDependencies too! Recount_MainWindow:CreateBorder(12,1,1,1) end
__________________
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. |
|
09-17-14, 10:45 PM | #3 |
Could you explain me how your day looks like? You did answer on nearly every question i got with a huge amount of informations. You got a bunch of addons running with properly a bunch of tickets each day o.o.
Ill try it out after some sleep but i got a short question flashing through my mind while remembering what you wrote. If i remember right you said that blizzard frames get created at the start and are always there so easy to hook. I tryed to give my skinned blizzard ui some borders but on some frames. For example .. the Guildframe. If i check it with Fstack i get nearly everywhere around it "GuildFrame" than "GuildMainFrame", "GuildNewPerksFrame", "GuildFrameInsert" and so on. I can clearly see that these frames are named but it seems like its a bit more difficult than i thought. Yesterday where i started to skin my Ui i was like ok, Blizz frames are easy to skin with a border i just need to get a bit into bagnon and than its cool. Anyways. Ill take a nap and than read again what you wrote and try it out |
|
09-18-14, 07:00 PM | #4 |
Sorry for the double post but i got further questions and i dont know if posts on WoWInt. get flagged as "with new content" if i edit my last post.
I tryed the stuff now on Xloot. This is your example: Lua Code:
So by default i did rename every Bagnon into XLoot because, this is the addon Now i need to understand the Lua. "hooksecurefunc" does as i understand it hook functions. Simple as that im not sure what is the other stuff? (Bagnon [AddOn Name], "CreateFrame" [name of the func?] function [to tell the hooksecurefunc that is has to hook a function?] (Bagnon [AddOn Name], id [no clue what it is. Maybe if there are more than 1 function with the same name] The secound part with the reference to the frame object is as i understand it the way we tell the hooksecurefunc where the frames to hook are located? so in the XLoot. Lua i found this: Lua Code:
It is like on the top of the lua script, contains "frame = CreateFrame("Frame") and stuff like "OnEvent" that basicly means if a Event (loot window or something like this) does popup it gets created through this function. With that lets call it "interpretation" of the lua code and informations i found my result does look like: Lua Code:
I got this Lua Error: Lua Code:
So im not realy sure how to handle the error message. I can definitly see a "CreateFrame" function in the XLoot.lua and since "hooksecurefunc():" is a part of the lua code i cant even imagine whats wrong here. |
|
09-18-14, 09:43 PM | #5 | |||||
For example, there's at least one place where they literally run 30+ if/elseif checks to convert a string to all-caps instead of just calling string.upper one time.
There are two ways to use hooksecurefunc. For global functions: Code:
hooksecurefunction(CastSpellByName, function(name) print("You cast a spell by name:", name) end) Code:
hooksecurefunction(MinimapZoneText, "SetText", function(self, text) print("The minimap zone text is now showing:", text) end) Code:
function Bagnon:CreateFrame(id) print(self == Bagnon) -- prints "true" end Code:
function Bagnon.CreateFrame(self, id) print(self == Bagnon) -- prints "true" end http://www.wowinterface.com/forums/s...573#post295573
1. The XLoot addon defines a table or frame object with a global name of "XLoot". 2. The XLoot addon defines a function as a method on that object with the name of "CreateFrame". 3. That method receives two arguments, the first being a reference to the "XLoot" object, and the second being something that identifies the frame being created. 4. There is a table defined as under the "frames" key on the "XLoot" object (eg. XLoot.frames = {}). 5. The identifier passed to the XLoot:CreateFrame method is used as a key in that table, and its value is a reference to the frame that was created. Since XLoot is a completely separate addon from Bagnon, and is not written by the same author, it's extremely unlikely that its frame creation code is exactly the same as Bagnon's frame creation code. After a quick look at XLoot's code, I can tell you that you don't need to hook anything. XLoot only creates one loot frame (whereas Bagnon creates an inventory frame and a bank frame and possibly more frames depending on your settings) and it creates it right away when the addon loads (whereas Bagnon doesn't create any frames until you want to see them). In XLoot_Frame\Frames.lua, in the main chunk (outside of any functions, so it's executed as soon as the file is read): Code:
local XLootFrame = CreateFrame("Frame", "XLootFrame", UIParent) 1. Creates a frame object with the type "Frame" (as opposed to "Button" or "ScrollFrame" etc.) 2. Gives that object the global name "XLootFrame". 3. Parents that object to the already-existing frame with the global name "UIParent" (by reference, not by name). 4. Assigns a reference to the new object to the local variable "XLootFrame". So, since that line is executed and the frame is created right away, all your addon needs to do is: 1. Add XLoot_Frame to its optional dependencies to make sure XLoot_Frame loads before your addon if it's installed. 2. Check if XLootFrame exists (if it doesn't at this point, then the addon isn't installed). 3. Add a border to the frame: Code:
if XLootFrame then XLootFrame:AddBorder( YOUR BORDER PROPERTIES HERE) end Code:
local addonFuncs = {} addonFuncs["Bagnon"] = function() hooksecurefunc(Bagnon, "CreateFrame", function(Bagnon, id) -- code here, I'm too lazy to scroll down and copy/paste it end) end addonFuncs["XLoot_Frame"] = function() XLootFrame:AddBorder( ARGUMENTS GO HERE ) end for addon, func in pairs(addonFuncs) do -- Check for addons that were already loaded before yours: if IsAddOnLoaded(addon) then -- Run the function now: func() -- Remove it from the queue: addonFuncs[addon] = nil else -- Check for addons that aren't installed or aren't enabled: local _, _, _, enabled, loadable = GetAddOnInfo(addon) if not enabled or not loadable then -- Remove it from the queue: addonFuncs[addon] = nil end end -- If any addons are still in the queue, listen for addon loading events: if next(addonFuncs) then local eventFrame = CreateFrame("Frame") eventFrame:RegisterEvent("ADDON_LOADED") eventFrame:SetScript("OnEvent", function(self, event, addon) local func = addonFuncs[addon] if func then func() addonFuncs[addon] = nil end if not next(addonFuncs) then -- Clean up and send everything to the garbage collector self:UnregisterEvent(event) self:SetScript("OnEvent", nil) addonFuncs = nil end end) end
__________________
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. Last edited by Phanx : 09-19-14 at 09:51 PM. |
||||||
09-19-14, 01:36 AM | #6 | |
Holy ... thats a whole bunch of text! Beside the topic realated informations i learned a lot of things. To be fair i didnt even started to learn anything in Lua / WoW Api but i got that i dont know:
As i can say it looks a bit different. If i guess right frames are created in .xml and "what stuff does" in the .lua so its a bit like .lua = .html, .xml = .css. Overall ill try that xloot skinning out. After that i properly just need to skin the other blizzard frames and do some last modifications and than i have to check the licenses and so on of all the addons im using and ask the authors if i can use them for my "UI" or "UI Pack" however you want to call it. And after this is done and my basic ui is ready ill start to rebuild it bymyself step by step without any real 3. party addon. Not even sure if i will be able to finish it untill world of warcraft will die since it is a bunch of work and will properly need years >.< So. Today ill finally sleep a bit and think about how ill start to learn the whole stuff. I mean yea there are a lot of informations for free around there but im 100% sure i can read every information ic an find in the next 3 months and wont even be able to write a chat print addon blind without copy paste. Rly annoying to lose the ability to learn something by your self just with the informations you get in the internet and to be honest. I would feel realy retarded if i try to write addons and just open threads on wowinterface for every thing i cant find a solution for. Anyways, again thanks for that huge answer. Ill properly should check all your recent forum posts since they are like always usefull. Sometimes my worse english is struggeling a bit. I definitly do understand it better than i speak (seems to be usuall if i compare it to .lua ) but ye. Thanks for taking the time to answer me! |
||
09-19-14, 04:42 AM | #7 | ||||
How a table looks compared with a frame
A frame is really just a table with some special properties. Anything you can do with a table, you can also do with a frame: Code:
-- make a table: local t = {} -- add a key with a value: t["cat"] = "meow" -- add an indexed value: table.insert(t, "Look, a value!") -- add another indexed value: table.insert(t, "Another value!") -- sort the indexed values by alphabet: table.sort(t) -- print the indexed values in order: for i = 1, #t do print(t) end -- print all the values (indexed and keyed): for k, v in pairs(t) do print(k, "=", v) end -- remove all the values: table.wipe(t) Code:
local t = CreateFrame("Frame") Code:
local t = CreateFrame("Frame") print(type(t[0])) -- prints "userdata" Code:
local t = CreateFrame("Frame") t:SetParent(WorldFrame) -- this works t[0] = "LOL I BROKE IT" t:SetParent(UIParent) -- now it doesn't work Technically "userdata" is a fancy way of saying "a pointer to something that only exists in the C code outside of the Lua scripting environment" since Lua is a scripting language running inside a program written in C (actually I think WoW is in C# but that doesn't matter for this demonstration) just like JavaScript is a scripting language running inside your web browser, or your web browser runs inside your operating system (probably Windows) etc. Anyway, metatables are probably beyond the scope of what you'll be doing in the near future, but they're not actually that complicated, so if you're interested I can explain that a bit more. ------------------------------ What a Method realy does with a frame The short answer: Nothing. The long answer: A method is just a function, but it's defined in a special way so that it's attached to a table (maybe a frame, maybe some other kind of UI object, or maybe just a plain old table). Code:
local WhatAnimalsDo = { ["cats"] = "chase lasers", ["dogs"] = "chase squirrels", ["goats"] = "jump on things", } function WhatAnimalsDo:Explain(who) local what = self[who] print("Did you know that", who, what, "?") end Code:
function WhatAnimalsDo.Explain(self, who) local what = self[who] print("Did you know that", who, what, "?") end Code:
WhatAnimalsDo.Explain("cats") -- note the dot! But if you call it like this, it works: Code:
WhatAnimalsDo:Explain("cats") -- colon! Code:
WhatAnimalsDo.Explain(WhatAnimalsDo, "cats") So, as you can see, a method doesn't "do" anything with the table it's defined on, unless you do something with it inside the function. It's just a special way of writing functions that attach them to tables/frames/other objects, and "magically" pass references to the object. ------------------------------ What local variables do Assuming you already know what a variable is, the "local" keyword just limits where a variable exists. If you write: Code:
MyVariable = 5 Code:
local MyVariable = 5 Code:
local function PrintMyVariable() print(MyVariable) end local MyVariable = 5 PrintMyVariable() Code:
do local x = 10 print(x) end print(x) Code:
local x = 10 print(x) do local x = x * 2 print(x) end print(x) You can think of scopes like those Russian nesting dolls, made out of one-way glass. If you're in between dolls, you can see outward to see what's in all the bigger dolls, but you can't see inward to see what's in the smaller dolls. Functions also create scopes, as do loops of all kinds (for, while, repeat), and basic control structures like if, elseif, and else. As a general rule, you should always define your variable in the narrowest (or lowest, or the smallest doll) scope that's needed. This keeps your code readable, helps avoid unexpected conflicts if you use the same variable name in different scopes for different purposes, and avoids wasting memory by holding onto values that are no longer needed (since any variables that are local to a scope are effectively erased at the end of the scope). ------------------------------
__________________
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. |
|||||
09-19-14, 06:36 AM | #8 | |
I think Hearthstone was made using the Unity engine, which allows you to program the game in C# and other .NET languages. When I looked at Hearthstone's files a while back, they definitely looked like a .NET application rather than a native one. Back to the topic of the thread, that was quite a nice explanation of those concepts. Last edited by Choonstertwo : 09-19-14 at 06:44 AM. |
||
09-19-14, 12:41 PM | #9 |
Damn Phanx you drive ma crazy. Thanks for all the advices and informations! I guess i can start learning lua in around 1 week. Ill definitly tell you after i'd understand that world of warcraft dev if/elseif example cause for now i dont even get whats wrong with it or how i could get the same result in a other way .
Ill come back to that bunch of snippeds in the week ill start learning lua and the wow api so ye, for now i just want to tell you that i tryed your addon check / border modification snipped. Lua Code:
Since you missed a [/code] at the end of your post i thought there is something missing. the Error code was: Code:
1x LightboundUI\LightboundUI-v1.0.1.lua:46: "end" expected (to close "for" at line 13) near "<eof>" Lua Code:
and Lua Code:
Also played with the Arguments. Borders wont appear. |
|
09-19-14, 10:04 PM | #10 |
Well, this won't work:
Code:
addonFuncs["Bagnon"] = function() hooksecurefunc(Bagnon, "CreateFrame", function(Bagnon, id) frame:CreateBorder(13,20,20,20, 2) end) end As for the other part, try adding some print statements so you can see what's going on: Code:
addonFuncs["XLoot_Frame"] = function() print("addonFuncs: XLoot_Frame") XLootFrame:AddBorder(50,20,20,20, 2) end Code:
if IsAddOnLoaded(addon) then -- Run the function now: print(addon, "already loaded, running now...") func() Code:
eventFrame:SetScript("OnEvent", function(self, event, addon) local func = addonFuncs[addon] if func then print(addon, "just loaded, running now...") func() (Also fixed the missing /code tag in my last post, so if you re-copy you'll have correctly indented code.)
__________________
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. |
|
09-22-14, 03:36 AM | #11 |
Just finished reading this thread and had to say thanks to Phanx for his knowledge and well written explanations. Was checking the forums for changes for WoD and saw this thread and had to read it.
__________________
"There's no such thing as too many addons." Lothaer My Authored Addons HOME OF THE FREE, BECAUSE OF THE BRAVE
|
|
09-22-14, 06:25 AM | #12 |
Fixed that for you.
__________________
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. |
|
WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » !Beautycase getting started |
«
Previous Thread
|
Next Thread
»
|
Thread Tools | |
Display Modes | |
|
|