From 09b78da7b704841363fd3d9a0a9f6dadf31388fe Mon Sep 17 00:00:00 2001 From: torhal Date: Wed, 18 Nov 2009 03:52:08 +0000 Subject: [PATCH] Re-worked addon:GetTextDump() to re-use the "text_table" and "acquire_list" tables between calls, and also to assign flag states using the ACQUIRE_NAMES table instead of an ifelse chain. In addon:OnInitialize(): Added some separators between the options tables. Removed addon:ResetSearch(): It was only ever used in the OnClick handler of ARL_ClearButton, so its code now resides there. Changed a plethora of syntax in ARLFrame.lua. --- ARLFrame.lua | 80 ++++++++++++---------- AckisRecipeList.lua | 190 +++++++++++++++++++++++++++------------------------ 2 files changed, 147 insertions(+), 123 deletions(-) diff --git a/ARLFrame.lua b/ARLFrame.lua index 7a86828..5b3dd9c 100644 --- a/ARLFrame.lua +++ b/ARLFrame.lua @@ -1030,7 +1030,9 @@ local function GenerateTooltipContent(owner, rIndex) -- loop through acquire methods, display each for k, v in pairs(recipeDB[rIndex]["Acquire"]) do - if (v["Type"] == A_TRAINER) then + local acquire_type = v["Type"] + + if acquire_type == A_TRAINER then -- Trainer: TrainerName -- TrainerZone TrainerCoords local trnr = trainerDB[v["ID"]] @@ -1039,13 +1041,16 @@ local function GenerateTooltipContent(owner, rIndex) clr1 = addon:hexcolor("TRAINER") -- Don't display trainers if it's opposite faction local displaytt = false + if (trnr["Faction"] == factionHorde) then clr2 = addon:hexcolor("HORDE") + if (playerFaction == factionHorde) then displaytt = true end elseif (trnr["Faction"] == factionAlliance) then clr2 = addon:hexcolor("ALLIANCE") + if (playerFaction == factionAlliance) then displaytt = true end @@ -1065,7 +1070,7 @@ local function GenerateTooltipContent(owner, rIndex) clr2 = addon:hexcolor("HIGH") ttAdd(1, -2, 1, trnr["Location"], clr1, cStr, clr2) end - elseif (v["Type"] == A_VENDOR) then + elseif acquire_type == A_VENDOR then -- Vendor: VendorName -- VendorZone VendorCoords local vndr = vendorDB[v["ID"]] @@ -1095,7 +1100,7 @@ local function GenerateTooltipContent(owner, rIndex) displaytt = true end - if (displaytt) then + if displaytt then if (vndr["Coordx"] ~= 0) and (vndr["Coordy"] ~= 0) then cStr = "(" .. vndr["Coordx"] .. ", " .. vndr["Coordy"] .. ")" end @@ -1107,7 +1112,7 @@ local function GenerateTooltipContent(owner, rIndex) elseif faction then ttAdd(0, -1, 0, faction.." "..L["Vendor"], clr1) end - elseif (v["Type"] == A_MOB) then + elseif acquire_type == A_MOB then -- Mob Drop: Mob Name -- MoBZ MobCoords local mob = mobDB[v["ID"]] @@ -1123,7 +1128,7 @@ local function GenerateTooltipContent(owner, rIndex) clr1 = addon:hexcolor("NORMAL") clr2 = addon:hexcolor("HIGH") ttAdd(1, -2, 1, mob["Location"], clr1, cStr, clr2) - elseif (v["Type"] == A_QUEST) then + elseif acquire_type == A_QUEST then -- Quest: QuestName -- QuestZone QuestCoords local qst = questDB[v["ID"]] @@ -1153,8 +1158,9 @@ local function GenerateTooltipContent(owner, rIndex) displaytt = true end - if (displaytt) then + if displaytt then local cStr = "" + if (qst["Coordx"] ~= 0) and (qst["Coordy"] ~= 0) then cStr = "(" .. qst["Coordx"] .. ", " .. qst["Coordy"] .. ")" end @@ -1167,13 +1173,13 @@ local function GenerateTooltipContent(owner, rIndex) ttAdd(0, -1, 0, faction.." "..L["Quest"], clr1) end end - elseif (v["Type"] == A_SEASONAL) then + elseif acquire_type == A_SEASONAL then -- Seasonal: SeasonEventName local ssnname = seasonDB[v["ID"]]["Name"] clr1 = addon:hexcolor("SEASON") ttAdd(0, -1, 0, SEASONAL_CATEGORY, clr1, ssnname, clr1) - elseif (v["Type"] == A_REPUTATION) then + elseif acquire_type == A_REPUTATION then -- Reputation: Faction -- FactionLevel RepVendor -- RepVendorZone RepVendorCoords @@ -1210,14 +1216,16 @@ local function GenerateTooltipContent(owner, rIndex) end local displaytt = false - if (repvndr["Faction"] == factionHorde) then + if repvndr["Faction"] == factionHorde then clr2 = addon:hexcolor("HORDE") - if (playerFaction == factionHorde) then + + if playerFaction == factionHorde then displaytt = true end - elseif (repvndr["Faction"] == factionAlliance) then + elseif repvndr["Faction"] == factionAlliance then clr2 = addon:hexcolor("ALLIANCE") - if (playerFaction == factionAlliance) then + + if playerFaction == factionAlliance then displaytt = true end else @@ -1225,13 +1233,13 @@ local function GenerateTooltipContent(owner, rIndex) displaytt = true end - if (displaytt) then + if displaytt then ttAdd(1, -2, 0, rStr, clr1, repvndr["Name"], clr2) clr1 = addon:hexcolor("NORMAL") clr2 = addon:hexcolor("HIGH") ttAdd(2, -2, 1, repvndr["Location"], clr1, cStr, clr2) end - elseif (v["Type"] == A_WORLD_DROP) then + elseif acquire_type == A_WORLD_DROP then -- World Drop RarityLevel if (v["ID"] == 1) then clr1 = addon:hexcolor("COMMON") @@ -1245,11 +1253,11 @@ local function GenerateTooltipContent(owner, rIndex) clr1 = addon:hexcolor("NORMAL") end ttAdd(0, -1, 0, L["World Drop"], clr1) - elseif (v["Type"] == A_CUSTOM) then + elseif acquire_type == A_CUSTOM then local customname = customDB[v["ID"]]["Name"] ttAdd(0, -1, 0, customname, addon:hexcolor("NORMAL")) - elseif (v["Type"] == A_PVP) then + elseif acquire_type == A_PVP then -- Vendor: VendorName -- VendorZone VendorCoords local vndr = vendorDB[v["ID"]] @@ -1279,11 +1287,10 @@ local function GenerateTooltipContent(owner, rIndex) displaytt = true end - if (displaytt) then - if (vndr["Coordx"] ~= 0) and (vndr["Coordy"] ~= 0) then + if displaytt then + if vndr["Coordx"] ~= 0 and vndr["Coordy"] ~= 0 then cStr = "(" .. vndr["Coordx"] .. ", " .. vndr["Coordy"] .. ")" end - ttAdd(0, -1, 0, L["Vendor"], clr1, vndr["Name"], clr2) clr1 = addon:hexcolor("NORMAL") clr2 = addon:hexcolor("HIGH") @@ -1309,11 +1316,10 @@ local function GenerateTooltipContent(owner, rIndex) if addon.db.profile.worldmap or addon.db.profile.minimap then ttAdd(0, -1, 0, L["CTRL_SHIFT_CLICK"], clr1) end - arlTooltip:Show() -- If we have the spell link tooltip, link it to the acquire tooltip. - if (spellTooltipLocation ~= L["Off"]) and (spellLink) then + if spellTooltipLocation ~= L["Off"] and spellLink then SetSpellTooltip(arlTooltip, spellTooltipLocation, spellLink) else arlSpellTooltip:Hide() @@ -1932,12 +1938,13 @@ local function expandEntry(dsIndex) -- Need to loop through the available acquires and put them all in for k, v in pairs(recipeDB[recipeIndex]["Acquire"]) do -- Initialize the first line here, since every type below will have one. + local acquire_type = v["Type"] local t = AcquireTable() t.IsRecipe = false t.sID = recipeIndex t.IsExpanded = true - if (v["Type"] == A_TRAINER) and obtainDB.trainer then + if acquire_type == A_TRAINER and obtainDB.trainer then local trainer = trainerDB[v["ID"]] if CheckDisplayFaction(filterDB, trainer["Faction"]) then @@ -1972,7 +1979,7 @@ local function expandEntry(dsIndex) -- Right now PVP obtained items are located on vendors so they have the vendor and pvp flag. -- We need to display the vendor in the drop down if we want to see vendors or if we want to see PVP -- This allows us to select PVP only and to see just the PVP recipes - elseif (v["Type"] == A_VENDOR) and (obtainDB.vendor or obtainDB.pvp) then + elseif acquire_type == A_VENDOR and (obtainDB.vendor or obtainDB.pvp) then local vendor = vendorDB[v["ID"]] if CheckDisplayFaction(filterDB, vendor["Faction"]) then @@ -2005,7 +2012,7 @@ local function expandEntry(dsIndex) dsIndex = dsIndex + 1 end -- Mobs can be in instances, raids, or specific mob related drops. - elseif (v["Type"] == A_MOB) and (obtainDB.mobdrop or obtainDB.instance or obtainDB.raid) then + elseif acquire_type == A_MOB and (obtainDB.mobdrop or obtainDB.instance or obtainDB.raid) then local mob = mobDB[v["ID"]] t.String = pad .. addon:MobDrop(L["Mob Drop"] .. " : ") .. addon:Red(mob["Name"]) @@ -2025,7 +2032,7 @@ local function expandEntry(dsIndex) tinsert(DisplayStrings, dsIndex, t) dsIndex = dsIndex + 1 - elseif (v["Type"] == A_QUEST) and obtainDB.quest then + elseif acquire_type == A_QUEST and obtainDB.quest then local quest = questDB[v["ID"]] if CheckDisplayFaction(filterDB, quest["Faction"]) then @@ -2057,11 +2064,11 @@ local function expandEntry(dsIndex) tinsert(DisplayStrings, dsIndex, t) dsIndex = dsIndex + 1 end - elseif (v["Type"] == A_SEASONAL) and obtainDB.seasonal then + elseif acquire_type == A_SEASONAL and obtainDB.seasonal then t.String = pad .. addon:Season(SEASONAL_CATEGORY .. " : " .. seasonDB[v["ID"]]["Name"]) tinsert(DisplayStrings, dsIndex, t) dsIndex = dsIndex + 1 - elseif (v["Type"] == A_REPUTATION) then -- Need to check if we're displaying the currently id'd rep or not as well + elseif acquire_type == A_REPUTATION then -- Need to check if we're displaying the currently id'd rep or not as well -- Reputation Obtain -- Rep: ID, Faction -- RepLevel = 0 (Neutral), 1 (Friendly), 2 (Honored), 3 (Revered), 4 (Exalted) @@ -2115,15 +2122,15 @@ local function expandEntry(dsIndex) tinsert(DisplayStrings, dsIndex, t) dsIndex = dsIndex + 1 end - elseif (v["Type"] == A_WORLD_DROP) and obtainDB.worlddrop then + elseif acquire_type == A_WORLD_DROP and obtainDB.worlddrop then t.String = pad .. addon:RarityColor(v["ID"] + 1, L["World Drop"]) tinsert(DisplayStrings, dsIndex, t) dsIndex = dsIndex + 1 - elseif (v["Type"] == A_CUSTOM) then + elseif acquire_type == A_CUSTOM then t.String = pad .. addon:Normal(customDB[v["ID"]]["Name"]) tinsert(DisplayStrings, dsIndex, t) dsIndex = dsIndex + 1 - elseif (v["Type"] == A_PVP) and obtainDB.pvp then + elseif acquire_type == A_PVP and obtainDB.pvp then local vendor = vendorDB[v["ID"]] if CheckDisplayFaction(filterDB, vendor["Faction"]) then @@ -2155,12 +2162,12 @@ local function expandEntry(dsIndex) tinsert(DisplayStrings, dsIndex, t) dsIndex = dsIndex + 1 end - --@alpha@ - elseif (v["Type"] > A_MAX) then -- We have an acquire type we aren't sure how to deal with. - t.String = "Unhandled Acquire Case - Type: " .. v["Type"] + --@alpha@ + elseif acquire_type > A_MAX then -- We have an acquire type we aren't sure how to deal with. + t.String = "Unhandled Acquire Case - Type: " .. acquire_type tinsert(DisplayStrings, dsIndex, t) dsIndex = dsIndex + 1 - --@end-alpha@ + --@end-alpha@ end end return dsIndex @@ -3403,7 +3410,10 @@ function addon:InitializeFrame() "GameFontHighlightSmall", "", "CENTER", L["CLEAR_DESC"], 3) ARL_ClearButton:SetScript("OnClick", function() - addon:ResetSearch(recipeDB) + -- Reset the search flags + for index in pairs(recipeDB) do + recipeDB[index]["Search"] = true + end ARL_SearchText:SetText(L["SEARCH_BOX_DESC"]) -- Make sure our expand all button is set to expandall diff --git a/AckisRecipeList.lua b/AckisRecipeList.lua index 3526ed0..6cb51f1 100644 --- a/AckisRecipeList.lua +++ b/AckisRecipeList.lua @@ -171,7 +171,9 @@ function addon:OnInitialize() tradeskill = {}, }, profile = { + ------------------------------------------------------------------------------- -- Frame options + ------------------------------------------------------------------------------- frameopts = { offsetx = 0, offsety = 0, @@ -182,10 +184,14 @@ function addon:OnInitialize() fontsize = 11, }, + ------------------------------------------------------------------------------- -- Sorting Options + ------------------------------------------------------------------------------- sorting = "SkillAsc", + ------------------------------------------------------------------------------- -- Display Options + ------------------------------------------------------------------------------- includefiltered = false, includeexcluded = false, closeguionskillclose = false, @@ -205,12 +211,18 @@ function addon:OnInitialize() mapmob = true, mapquest = true, + ------------------------------------------------------------------------------- -- Recipe Exclusion + ------------------------------------------------------------------------------- exclusionlist = {}, + ------------------------------------------------------------------------------- -- Filter Options + ------------------------------------------------------------------------------- filters = { + ------------------------------------------------------------------------------- -- General Filters + ------------------------------------------------------------------------------- general = { faction = true, specialty = false, @@ -218,7 +230,9 @@ function addon:OnInitialize() known = false, unknown = true, }, - -- Obtain Options + ------------------------------------------------------------------------------- + -- Obtain Filters + ------------------------------------------------------------------------------- obtain = { trainer = true, vendor = true, @@ -234,7 +248,9 @@ function addon:OnInitialize() bc = true, wrath = true, }, + ------------------------------------------------------------------------------- -- Item Filters (Armor/Weapon) + ------------------------------------------------------------------------------- item = { armor = { cloth = true, @@ -265,19 +281,27 @@ function addon:OnInitialize() gun = true, }, }, + ------------------------------------------------------------------------------- + -- Binding Filters + ------------------------------------------------------------------------------- binding = { itemboe = true, itembop = true, recipebop = true, recipeboe = true, }, + ------------------------------------------------------------------------------- + -- Player Role Filters + ------------------------------------------------------------------------------- player = { melee = true, tank = true, healer = true, caster = true, }, - -- Reputation Options + ------------------------------------------------------------------------------- + -- Reputation Filters + ------------------------------------------------------------------------------- rep = { aldor = true, scryer = true, @@ -313,7 +337,9 @@ function addon:OnInitialize() wrathcommon5 = true, ashenverdict = true, }, - -- Classes + ------------------------------------------------------------------------------- + -- Class Filters + ------------------------------------------------------------------------------- classes = { deathknight = true, druid = true, @@ -1399,7 +1425,8 @@ do playerData.recipes_known = recipes_known playerData.recipes_total_filtered = recipes_total_filtered playerData.recipes_known_filtered = recipes_known_filtered - end + end + end -- do ------------------------------------------------------------------------------- @@ -1648,104 +1675,91 @@ function addon:ClearExclusionList() end ------------------------------------------------------------------------------- --- Searching Functions -------------------------------------------------------------------------------- ----Goes through the recipe database and resets all the search flags -function addon:ResetSearch(RecipeDB) - for SpellID in pairs(RecipeDB) do - RecipeDB[SpellID]["Search"] = true - end -end - -------------------------------------------------------------------------------- -- Text dumping functions ------------------------------------------------------------------------------- ----Scans through the recipe database providing a string of comma separated values for all recipe information -function addon:GetTextDump(RecipeDB, profession) +do + ------------------------------------------------------------------------------- + -- Provides a string of comma separated values for all recipe information + ------------------------------------------------------------------------------- local text_table = {} + local acquire_list = {} + + local ACQUIRE_NAMES = { + [A_TRAINER] = "Trainer", + [A_VENDOR] = "Vendor", + [A_MOB] = "Mob Drop", + [A_QUEST] = "Quest", + [A_SEASONAL] = "Seasonal", + [A_REPUTATION] = "Reputation", + [A_WORLD_DROP] = "World Drop", + [A_CUSTOM] = "Custom", + } + + function addon:GetTextDump(RecipeDB, profession) + twipe(text_table) + + tinsert(text_table, strformat("Ackis Recipe List Text Dump for %s. ", profession)) + tinsert(text_table, "Text output of all recipes and acquire information. Output is in the form of comma separated values.\n") + tinsert(text_table, "Spell ID,Recipe Name,Skill Level,ARL Filter Flags,Acquire Methods,Known\n") - -- Add a header to the text table - tinsert(text_table, strformat("Ackis Recipe List Text Dump for %s. ", profession)) - tinsert(text_table, "Text output of all recipes and acquire information. Output is in the form of comma separated values.\n") - tinsert(text_table, "Spell ID,Recipe Name,Skill Level,ARL Filter Flags,Acquire Methods,Known\n") - - for SpellID in pairs(RecipeDB) do - local recipe_prof = GetSpellInfo(RecipeDB[SpellID]["Profession"]) - - if recipe_prof == profession then - -- Add Spell ID, Name and Skill Level to the list - tinsert(text_table, SpellID) - tinsert(text_table, ",") - tinsert(text_table, RecipeDB[SpellID]["Name"]) - tinsert(text_table, ",") - tinsert(text_table, RecipeDB[SpellID]["Level"]) - tinsert(text_table, ",\"") - - -- Add in all the filter flags - local recipe_flags = RecipeDB[SpellID]["Flags"] - local prev - - -- Find out which flags are marked as "true" - for i = 1, NUM_FLAGS, 1 do + for SpellID in pairs(RecipeDB) do + local recipe_prof = GetSpellInfo(RecipeDB[SpellID]["Profession"]) + + if recipe_prof == profession then + -- Add Spell ID, Name and Skill Level to the list + tinsert(text_table, SpellID) + tinsert(text_table, ",") + tinsert(text_table, RecipeDB[SpellID]["Name"]) + tinsert(text_table, ",") + tinsert(text_table, RecipeDB[SpellID]["Level"]) + tinsert(text_table, ",\"") + + -- Add in all the filter flags + local recipe_flags = RecipeDB[SpellID]["Flags"] + local prev + + -- Find out which flags are marked as "true" + for i = 1, NUM_FLAGS, 1 do if recipe_flags[i] then - if prev then - tinsert(text_table, ",") - end + if prev then + tinsert(text_table, ",") + end tinsert(text_table, i) prev = true + end end - end - tinsert(text_table, "\",\"") - - -- Find out which unique acquire methods we have - local acquire = RecipeDB[SpellID]["Acquire"] - local acquire_list = {} - - for i in pairs(acquire) do - local acquire_type = acquire[i]["Type"] - - if acquire_type == 1 then - acquire_list["Trainer"] = true - elseif acquire_type == 2 then - acquire_list["Vendor"] = true - elseif acquire_type == 3 then - acquire_list["Mob Drop"] = true - elseif acquire_type == 4 then - acquire_list["Quest"] = true - elseif acquire_type == 5 then - acquire_list["Seasonal"] = true - elseif acquire_type == 6 then - acquire_list["Reputation"] = true - elseif acquire_type == 7 then - acquire_list["World Drop"] = true - elseif acquire_type == 8 then - acquire_list["Custom"] = true + tinsert(text_table, "\",\"") + + -- Find out which unique acquire methods we have + local acquire = RecipeDB[SpellID]["Acquire"] + twipe(acquire_list) + + for i in pairs(acquire) do + local acquire_type = acquire[i]["Type"] + + acquire_list[ACQUIRE_NAMES[acquire_type]] = true end - end - -- Add all the acquire methods in - prev = false - for i in pairs(acquire_list) do - if prev then - tinsert(text_table, ",") - end - tinsert(text_table, i) - prev = true - end + -- Add all the acquire methods in + prev = false - if (RecipeDB[SpellID]["Known"]) then - tinsert(text_table, "\",true\n") - else - tinsert(text_table, "\",false\n") + for i in pairs(acquire_list) do + if prev then + tinsert(text_table, ",") + end + tinsert(text_table, i) + prev = true + end + + if (RecipeDB[SpellID]["Known"]) then + tinsert(text_table, "\",true\n") + else + tinsert(text_table, "\",false\n") + end end end + return tconcat(text_table, "") end - return tconcat(text_table, "") -end - -do - - local GetItemInfo = GetItemInfo ---Dumps all the info about a recipe out to chat function addon:DumpRecipe(SpellID) -- 1.7.9.5