Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
WoW
Talk
English
Views
Read
Edit
History
More
Search
Navigation
Home
Random page
Help using wiki
Editions
for WoW
for WildStar
for Solar2D
Documentation
for WoW
for WildStar
Reference
WoW
⦁ FrameXML
⦁ AddOns
⦁ API
⦁ WoW Lua
WildStar
⦁ AddOns
⦁ API
⦁ WildStar Lua
Engine
Tools
What links here
Related changes
Special pages
Page information
Site
Recent Changes
Editing
WoW:Earth (AddOn)/Using earth to create a QuestLog
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Rendering Complex Trees == However, we're no slaves to simplicity, we're real coders, out to make life easier for our users. So we persist on, to make it even better. The first step is to convert our data-tree into an enhanced tree. The enhanced tree format for [[Earth (AddOn)]] is pretty complicated, but you can find out more about it by reading the EarthTree.lua file. Let's write a function to make an enhanced tree out of the simple one: -- Converts Quest Trees into Enhanced Tree -- function PartyQuests_ConvertQuestTreeToEnhancedTree(questTree, funcList) local enhancedTree = {}; for zone,questList in questTree do local zoneQuests = {}; zoneQuests.title = zone; zoneQuests.children = {}; for k,quest in questList do local entry = {}; entry.title = quest.title; entry.right = quest.tag; entry.tooltip = quest.level; entry.onClick = function (a) Sea.io.printTable(a) end; table.insert(zoneQuests.children,entry); end zoneQuests.right = table.getn(zoneQuests.children); zoneQuests.tooltip = table.getn(zoneQuests.children); table.insert(enhancedTree,zoneQuests); end return enhancedTree; end [[Image:Earth_tutorial_2.jpg|thumb|Wow, it looks like a real quest log.]] Then, change the function to use the LoadEnhanced call: function PartyQuests_OnQuestClick(a) -- Do something here end function PartyQuests_LoadGui () local frame = PartyQuestsFrame; local tree = PartyQuests_GetPlayerQuestTree(); local eTree = PartyQuests_ConvertQuestTreeToEnhancedTree(tree, {onClick=PartyQuests_OnQuestClick} ); -- Load up the data EarthTree_LoadEnhanced( getglobal(frame:GetName().."Tree"), eTree ); -- Draw the data EarthTree_UpdateFrame( getglobal(frame:GetName().."Tree") ); end There. This is a lot to soak up, but basically, every entry in the [[Earth EnhancedTree]] format has an entry called "children", which determines what elements go inside of it. "title" is the main text, "right" is the extra text on the right, "tooltip" is what appears when you mouse it over and onClick is what happens when you click it! Here's the result: Ooh! That was nice. However, it was kind of bland. All that white. So lets spice it up with some color. We're going to use the function the default QuestLog uses to set its colors. That will ensure we don't need to change our code if Blizzard changes theirs. [[Image:Earth_tutorial_3.jpg|thumb|Description]] -- Converts Quest Trees into Enhanced Tree -- function PartyQuests_ConvertQuestTreeToEnhancedTree(questTree, funcList) local enhancedTree = {}; -- Loop through the zone list for zone,questList in questTree do local zoneQuests = {}; zoneQuests.title = zone; zoneQuests.children = {}; -- Loop through the quest list for k,quest in questList do local entry = {}; entry.title = quest.title; entry.right = quest.tag; entry.tooltip = quest.level; -- Lets add some color '''''entry.titleColor = GetDifficultyColor(quest.level);''''' -- Add the event handlers entry.onClick = function (a) Sea.io.printTable(a) end; table.insert(zoneQuests.children,entry); end zoneQuests.right = table.getn(zoneQuests.children); zoneQuests.tooltip = table.getn(zoneQuests.children); table.insert(enhancedTree,zoneQuests); end return enhancedTree; end Doesn't that look pretty? But it still not enough. We need to complete this masterpiece by improving upon the original. Let's make use of that spiffy localization.lua file. Open it up and add the following: PARTYQUESTS_QUEST_TITLE = "\[%s\] %s"; PARTYQUESTS_QUEST_TITLE_TAG = "(%s)"; These are a couple of formatting strings that will help us make the Enhanced Tree look even better. "string.format" is another really nice function, that you can find more about over at http://www.lua.org, check out their documentation. These strings allow us to format those tags we'd like changed very quickly. Plus, if a different country prefers to use a different format, we can update it just by changing the localization.lua file. [[Image:Earth_tutorial_4.jpg|thumb|Beautiful. Simply Beautiful!]] -- Converts Quest Trees into Enhanced Tree -- function PartyQuests_ConvertQuestTreeToEnhancedTree(questTree, funcList) local enhancedTree = {}; -- Loop through the zone list for zone,questList in questTree do local zoneQuests = {}; zoneQuests.title = zone; zoneQuests.children = {}; -- Loop through the quest list for k,quest in questList do local entry = {}; -- Add the format strings here: -- Format it into [12] Quest of Danger '''''entry.title = string.format(PARTYQUESTS_QUEST_TITLE, quest.level, quest.title); ''''' -- Pretty up the (Elite) '''''if ( quest.tag ) then entry.right = string.format(PARTYQUESTS_QUEST_TITLE_TAG, quest.tag); end''''' -- Add a simple tooltip entry.tooltip = quest.level; -- Lets add some color entry.titleColor = GetDifficultyColor(quest.level); -- Add the event handlers entry.onClick = function (a) Sea.io.printTable(a) end; table.insert(zoneQuests.children,entry); end zoneQuests.right = table.getn(zoneQuests.children); zoneQuests.tooltip = table.getn(zoneQuests.children); table.insert(enhancedTree,zoneQuests); end return enhancedTree; end Beautiful. A work of art and it only took us about an hour to do. If you'd like to extend this work, you can set all of those onClick entries to do something more advanced than just print out a message. Likewise, you can make checkboxes show up by adding "checked=true" to each entry.
Summary:
Please note that all contributions to AddOn Studio are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
AddOn Studio Wiki:Copyrights
for details).
Submissions must be written by you, or copied from a public domain or similar free resource (see
AddOn Studio Wiki:Copyrights
for details).
Cancel
Editing help
(opens in new window)