annotate core.lua @ 1:dceccfaf0a50

Added highlighting of recipeprofit recipes to main build. Recipes now show with a blueish background and have cyan text if you do not have any of them in your backpack or bank, magenta text if you have less than 5, and red text if you have 5 or more. This makes it easy to avoid buying items you don't want.
author Aaron Bregger
date Wed, 11 Aug 2010 23:40:11 -0500
parents 25906be72a8b
children 050ca47f9138
rev   line source
Aaron@0 1 local RecipeProfit = LibStub("AceAddon-3.0"):NewAddon("RecipeProfit")
Aaron@0 2 local GatherMate = LibStub("AceAddon-3.0"):GetAddon("GatherMate")
Aaron@0 3 local tabletest = {}
Aaron@0 4 local db = {}
Aaron@1 5 local safeRecipes = {}
Aaron@1 6 safer = safeRecipes
Aaron@0 7 RecipeProfit.db = db;
Aaron@0 8
Aaron@1 9
Aaron@0 10 function debugprint(val, indent)
Aaron@0 11 indent = indent or "";
Aaron@0 12 if not(type(val) == "table") then
Aaron@0 13 print("Not table: " .. val)
Aaron@0 14 return
Aaron@0 15 end
Aaron@0 16
Aaron@0 17 for k,v in pairs(val) do
Aaron@0 18 if(type(k) == "table" and type(v) == "table") then
Aaron@0 19 print(indent .. "table key: {")
Aaron@0 20 debugprint(k, indent .. " ")
Aaron@0 21 print(indent .. "} = {")
Aaron@0 22 debugprint(v, indent .. " ")
Aaron@0 23 print(indent .. "}")
Aaron@0 24 elseif(type(v) == "table") then
Aaron@0 25 print(indent .. k .. " = {")
Aaron@0 26 debugprint(v, indent .. " ")
Aaron@0 27 print(indent .. "}")
Aaron@0 28 else
Aaron@0 29 print(indent .. k .. " = " .. v)
Aaron@0 30 end
Aaron@0 31 end
Aaron@0 32 end
Aaron@0 33
Aaron@0 34 local options = {
Aaron@0 35 type = "group",
Aaron@0 36 name = "RecipeProfit", -- addon name to import from, don't localize
Aaron@0 37 handler = {},
Aaron@0 38 disabled = false,
Aaron@0 39 args = {
Aaron@1 40 opt = {
Aaron@0 41 order = 1,
Aaron@0 42 name = "Select Database",
Aaron@0 43 desc = "Show a different database",
Aaron@0 44 type = "group",
Aaron@0 45 guiInline = true,
Aaron@0 46 args = {
Aaron@0 47 faction = {
Aaron@0 48 order = 0,
Aaron@0 49 name = "Faction",
Aaron@0 50 desc = "Show a different database.",
Aaron@0 51 type = "select",
Aaron@0 52 values = {
Aaron@0 53 ["Alliance"] = "Alliance",
Aaron@0 54 ["Horde"] = "Horde",
Aaron@1 55 ["default"] = "Default",
Aaron@0 56 },
Aaron@0 57 arg = "faction",
Aaron@0 58 },
Aaron@1 59
Aaron@1 60 safeBuy = {
Aaron@1 61 order = 1,
Aaron@1 62 name = "Safe Recipe Buy",
Aaron@1 63 desc = "Warn when buying a recipe not on the RecipeProfit list.",
Aaron@1 64 type = "select",
Aaron@1 65 values = {
Aaron@1 66 ["on"] = "On",
Aaron@1 67 ["off"]= "Off",
Aaron@1 68 },
Aaron@1 69 arg = "safebuy",
Aaron@1 70 },
Aaron@0 71 },
Aaron@1 72 get = function(k) return db.profile[k.arg]; end,
Aaron@0 73 set = function(k, v) db.profile[k.arg] = v; RecipeProfit:DoMerge(); end,
Aaron@0 74 },
Aaron@0 75 loadData = {
Aaron@0 76 order = 8,
Aaron@0 77 name = "Import Data",
Aaron@0 78 desc = "Load RecipeProfit and import the data to your database.",
Aaron@0 79 type = "execute",
Aaron@0 80 func = function()
Aaron@0 81 RecipeProfit:DoMerge()
Aaron@0 82 end
Aaron@0 83 },
Aaron@0 84 }
Aaron@0 85 }
Aaron@0 86
Aaron@0 87 local defaults = {
Aaron@1 88 faction = "default",
Aaron@1 89 safebuy = "on",
Aaron@0 90 }
Aaron@0 91
Aaron@0 92 function RecipeProfit:OnInitialize()
Aaron@0 93 profile = profile or defaults
Aaron@1 94 for k, v in pairs(defaults) do
Aaron@1 95 profile[k] = profile[k] or v;
Aaron@1 96 end
Aaron@1 97
Aaron@0 98 db.profile = profile
Aaron@0 99 db.storage = {}
Aaron@0 100
Aaron@0 101 GatherMate:GetModule("Config"):RegisterModule("RecipeProfit", options)
Aaron@0 102 GatherMate:RegisterDBType("RecipeProfit", db.storage)
Aaron@0 103 GatherMate.db.profile.show["RecipeProfit"] = "always"
Aaron@0 104 GatherMate.nodeIDs["RecipeProfit"] = {}
Aaron@0 105 GatherMate.nodeTextures["RecipeProfit"] = {}
Aaron@0 106 GatherMate.nodeMinHarvest["RecipeProfit"] = {}
Aaron@0 107 nodes = GatherMate.nodeIDs["RecipeProfit"]
Aaron@0 108
Aaron@0 109 for id, note in pairs(RECIPEPROFIT_alliance) do
Aaron@1 110 safeRecipes[note.item] = true;
Aaron@0 111 nodes[note.item.." - ("..note.vendor.." A)"] = id * 10
Aaron@0 112 GatherMate.nodeTextures["RecipeProfit"][id * 10] = "Interface\\Icons\\INV_Scroll_05"
Aaron@0 113 end
Aaron@0 114
Aaron@0 115 for id, note in pairs(RECIPEPROFIT_horde) do
Aaron@1 116 safeRecipes[note.item] = true;
Aaron@0 117 nodes[note.item.." - ("..note.vendor.." H)"] = id * 10 + 1
Aaron@0 118 GatherMate.nodeTextures["RecipeProfit"][id * 10 + 1] = "Interface\\Icons\\INV_Scroll_05"
Aaron@0 119 end
Aaron@0 120
Aaron@0 121 GatherMate.reverseNodeIDs["RecipeProfit"] = GatherMate:CreateReversedTable(nodes)
Aaron@0 122 GatherMate:GetModule("Config"):UpdateConfig()
Aaron@0 123
Aaron@0 124 GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged")
Aaron@0 125 end
Aaron@0 126
Aaron@0 127 function RecipeProfit:OnEnable()
Aaron@1 128 for i=1, MERCHANT_ITEMS_PER_PAGE, 1 do
Aaron@1 129 local buttonframe = _G["MerchantItem"..i];
Aaron@1 130 buttonframe:HookScript("OnUpdate", function(self)
Aaron@1 131 local buttonName = _G[self:GetName().."Name"];
Aaron@1 132 local link = GetMerchantItemLink(_G[self:GetName().."ItemButton"]:GetID());
Aaron@1 133 local sName, sLink, iRarity, iLevel, iMinLevel, sType, sSubType, iStackCount = GetItemInfo(link)
Aaron@1 134
Aaron@1 135 if(sType == "Recipe" and safeRecipes[sName]) then
Aaron@1 136 SetItemButtonNameFrameVertexColor(self, 0, 0, 1.0);
Aaron@1 137 SetItemButtonSlotVertexColor(self, 0, 0, 0.5);
Aaron@1 138 if(GetItemCount(link, true) == 0) then
Aaron@1 139 buttonName:SetTextColor(0,1,1);
Aaron@1 140 elseif(GetItemCount(link, true) < 5) then
Aaron@1 141 buttonName:SetTextColor(1,0,1);
Aaron@1 142 else
Aaron@1 143 buttonName:SetTextColor(1,0,0);
Aaron@1 144 end
Aaron@1 145 else
Aaron@1 146 buttonName:SetTextColor(GameFontHighlightSmallOutline:GetTextColor());
Aaron@1 147 end
Aaron@1 148 end)
Aaron@1 149
Aaron@1 150 RecipeProfit:DoMerge()
Aaron@1 151 end
Aaron@0 152 end
Aaron@0 153
Aaron@0 154 local ids = {}
Aaron@0 155 function findGoodId(x, y)
Aaron@0 156 if ids[x.." "..y] then
Aaron@0 157 return findGoodId(x + .01, y)
Aaron@0 158 end
Aaron@0 159
Aaron@0 160 ids[x.." "..y] = true
Aaron@0 161 return x, y
Aaron@0 162 end
Aaron@0 163
Aaron@0 164 function RecipeProfit:DoMerge()
Aaron@0 165 ids = {}
Aaron@1 166 selectedDB = db.profile.faction == "Alliance" and RECIPEPROFIT_alliance or
Aaron@1 167 db.profile.faction == "default" and UnitFactionGroup("player") == "Alliance" and
Aaron@1 168 RECIPEPROFIT_alliance or RECIPEPROFIT_horde
Aaron@0 169 GatherMate:ClearDB("RecipeProfit")
Aaron@1 170 for id, note in pairs(selectedDB) do
Aaron@0 171 x, y = findGoodId(note.x, note.y)
Aaron@0 172 GatherMate:AddNode(note.map, x / 100, y / 100, "RecipeProfit",
Aaron@0 173 note.item.." - ("..note.vendor.." ".. (db.profile.faction == "Alliance" and "A" or "H") ..")")
Aaron@0 174 end
Aaron@0 175
Aaron@0 176 GatherMate:SendMessage("GatherMateDataImport")
Aaron@0 177 GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged")
Aaron@0 178 end