annotate core.lua @ 8:5a0fa30712da

RecipeProfit options added to GatherMate interface
author Aaron Bregger
date Thu, 12 Aug 2010 15:39:27 -0500
parents 6d25e5522e0f
children 20e2aefac1b0
rev   line source
Aaron@4 1 --[[--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))
Aaron@4 2
Aaron@4 3 RecipeProfit by -[@project-author@]-
Aaron@4 4
Aaron@4 5 Rev: @project-revision@
Aaron@4 6 Updated: @file-date-iso@
Aaron@4 7
Aaron@4 8 --))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))
Aaron@4 9
Aaron@4 10 http://www.wrathguides.com/
Aaron@4 11
Aaron@4 12 --]]--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))
Aaron@4 13
Aaron@4 14 local RecipeProfit = LibStub("AceAddon-3.0"):NewAddon("RecipeProfit")
Aaron@0 15 local GatherMate = LibStub("AceAddon-3.0"):GetAddon("GatherMate")
Aaron@0 16 local tabletest = {}
Aaron@7 17 db = {}
Aaron@1 18 local safeRecipes = {}
Aaron@1 19 safer = safeRecipes
Aaron@0 20 RecipeProfit.db = db;
Aaron@0 21
Aaron@7 22 local function deepcopy(object)
Aaron@7 23 local lookup_table = {}
Aaron@7 24 local function _copy(object)
Aaron@7 25 if type(object) ~= "table" then
Aaron@7 26 return object
Aaron@7 27 elseif lookup_table[object] then
Aaron@7 28 return lookup_table[object]
Aaron@7 29 end
Aaron@7 30 local new_table = {}
Aaron@7 31 lookup_table[object] = new_table
Aaron@7 32 for index, value in pairs(object) do
Aaron@7 33 new_table[_copy(index)] = _copy(value)
Aaron@7 34 end
Aaron@7 35 return setmetatable(new_table, getmetatable(object))
Aaron@7 36 end
Aaron@7 37 return _copy(object)
Aaron@7 38 end
Aaron@1 39
Aaron@0 40 function debugprint(val, indent)
Aaron@0 41 indent = indent or "";
Aaron@0 42 if not(type(val) == "table") then
Aaron@0 43 print("Not table: " .. val)
Aaron@0 44 return
Aaron@0 45 end
Aaron@0 46
Aaron@0 47 for k,v in pairs(val) do
Aaron@0 48 if(type(k) == "table" and type(v) == "table") then
Aaron@0 49 print(indent .. "table key: {")
Aaron@0 50 debugprint(k, indent .. " ")
Aaron@0 51 print(indent .. "} = {")
Aaron@0 52 debugprint(v, indent .. " ")
Aaron@0 53 print(indent .. "}")
Aaron@0 54 elseif(type(v) == "table") then
Aaron@0 55 print(indent .. k .. " = {")
Aaron@0 56 debugprint(v, indent .. " ")
Aaron@0 57 print(indent .. "}")
Aaron@0 58 else
Aaron@0 59 print(indent .. k .. " = " .. v)
Aaron@0 60 end
Aaron@0 61 end
Aaron@0 62 end
Aaron@8 63
Aaron@7 64 local defaultProfile = {
Aaron@7 65 ["show"] = {
Aaron@7 66 ["RecipeProfit"] = "always",
Aaron@7 67 ["Herb Gathering"] = "never",
Aaron@7 68 ["Extract Gas"] = "never",
Aaron@7 69 ["Fishing"] = "never",
Aaron@7 70 ["Mining"] = "never",
Aaron@7 71 ["Treasure"] = "never",
Aaron@7 72 },
Aaron@8 73 ["trackShow"] = "active",
Aaron@7 74 }
Aaron@0 75
Aaron@0 76 local options = {
Aaron@0 77 type = "group",
Aaron@0 78 name = "RecipeProfit", -- addon name to import from, don't localize
Aaron@0 79 handler = {},
Aaron@0 80 disabled = false,
Aaron@0 81 args = {
Aaron@1 82 opt = {
Aaron@0 83 order = 1,
Aaron@0 84 name = "Select Database",
Aaron@0 85 desc = "Show a different database",
Aaron@0 86 type = "group",
Aaron@0 87 guiInline = true,
Aaron@0 88 args = {
Aaron@0 89 faction = {
Aaron@0 90 order = 0,
Aaron@0 91 name = "Faction",
Aaron@0 92 desc = "Show a different database.",
Aaron@0 93 type = "select",
Aaron@0 94 values = {
Aaron@0 95 ["Alliance"] = "Alliance",
Aaron@0 96 ["Horde"] = "Horde",
Aaron@1 97 ["default"] = "Default",
Aaron@0 98 },
Aaron@0 99 arg = "faction",
Aaron@0 100 },
Aaron@1 101
Aaron@1 102 safeBuy = {
Aaron@1 103 order = 1,
Aaron@1 104 name = "Safe Recipe Buy",
Aaron@1 105 desc = "Warn when buying a recipe not on the RecipeProfit list.",
Aaron@1 106 type = "select",
Aaron@1 107 values = {
Aaron@7 108 --["on"] = "On",
Aaron@1 109 ["off"]= "Off",
Aaron@1 110 },
Aaron@1 111 arg = "safebuy",
Aaron@1 112 },
Aaron@0 113 },
Aaron@1 114 get = function(k) return db.profile[k.arg]; end,
Aaron@0 115 set = function(k, v) db.profile[k.arg] = v; RecipeProfit:DoMerge(); end,
Aaron@0 116 },
Aaron@0 117 loadData = {
Aaron@0 118 order = 8,
Aaron@0 119 name = "Import Data",
Aaron@0 120 desc = "Load RecipeProfit and import the data to your database.",
Aaron@0 121 type = "execute",
Aaron@0 122 func = function()
Aaron@0 123 RecipeProfit:DoMerge()
Aaron@0 124 end
Aaron@0 125 },
Aaron@7 126 loadProfile = {
Aaron@7 127 order = 9,
Aaron@7 128 name = "Load RecipeProfit Profile",
Aaron@7 129 desc = "Loads the RecipeProfit Profile into Gathermate for easy recipe tracking.",
Aaron@7 130 type = "execute",
Aaron@7 131 func = function()
Aaron@7 132 GatherMate.db.profiles["RecipeProfit"] = GatherMate.db.profiles["RecipeProfit"] or {}
Aaron@7 133 gmdb = GatherMate.db.profiles["RecipeProfit"]
Aaron@7 134 for k, v in pairs(defaultProfile) do
Aaron@7 135 gmdb[k] = v;
Aaron@7 136 end
Aaron@7 137 GatherMate:SendMessage("OnProfileChanged");
Aaron@7 138 GatherMate:GetModule("Config"):UpdateConfig()
Aaron@7 139 GatherMate:SendMessage("GatherMateConfigChanged")
Aaron@7 140 GatherMate.db:SetProfile("RecipeProfit")
Aaron@7 141 end
Aaron@7 142 },
Aaron@0 143 }
Aaron@0 144 }
Aaron@0 145
Aaron@0 146 local defaults = {
Aaron@1 147 faction = "default",
Aaron@1 148 safebuy = "on",
Aaron@0 149 }
Aaron@0 150
Aaron@0 151 function RecipeProfit:OnInitialize()
Aaron@0 152 profile = profile or defaults
Aaron@7 153
Aaron@1 154 for k, v in pairs(defaults) do
Aaron@1 155 profile[k] = profile[k] or v;
Aaron@1 156 end
Aaron@1 157
Aaron@0 158 db.profile = profile
Aaron@0 159 db.storage = {}
Aaron@0 160
Aaron@0 161 GatherMate:GetModule("Config"):RegisterModule("RecipeProfit", options)
Aaron@0 162 GatherMate:RegisterDBType("RecipeProfit", db.storage)
Aaron@8 163 GatherMate.db.profile.show["RecipeProfit"] = GatherMate.db.profile.show["RecipeProfit"] or "always"
Aaron@0 164 GatherMate.nodeIDs["RecipeProfit"] = {}
Aaron@0 165 GatherMate.nodeTextures["RecipeProfit"] = {}
Aaron@0 166 GatherMate.nodeMinHarvest["RecipeProfit"] = {}
Aaron@0 167 nodes = GatherMate.nodeIDs["RecipeProfit"]
Aaron@0 168
Aaron@0 169 for id, note in pairs(RECIPEPROFIT_alliance) do
Aaron@1 170 safeRecipes[note.item] = true;
Aaron@0 171 nodes[note.item.." - ("..note.vendor.." A)"] = id * 10
Aaron@0 172 GatherMate.nodeTextures["RecipeProfit"][id * 10] = "Interface\\Icons\\INV_Scroll_05"
Aaron@0 173 end
Aaron@0 174
Aaron@0 175 for id, note in pairs(RECIPEPROFIT_horde) do
Aaron@1 176 safeRecipes[note.item] = true;
Aaron@0 177 nodes[note.item.." - ("..note.vendor.." H)"] = id * 10 + 1
Aaron@0 178 GatherMate.nodeTextures["RecipeProfit"][id * 10 + 1] = "Interface\\Icons\\INV_Scroll_05"
Aaron@0 179 end
Aaron@0 180
Aaron@0 181 GatherMate.reverseNodeIDs["RecipeProfit"] = GatherMate:CreateReversedTable(nodes)
Aaron@8 182
Aaron@8 183 GatherMate:GetModule("Config").options.args.display.args.general.args.showGroup.args["showRecipeProfit"] = {
Aaron@8 184 order = 6,
Aaron@8 185 name = "Show RecipeProfit nodes.",
Aaron@8 186 desc = "Toggle showing nodes added by RecipeProfit.",
Aaron@8 187 type = "select",
Aaron@8 188 values = {
Aaron@8 189 ["always"] = "Always show",
Aaron@8 190 ["never"] = "Never show",
Aaron@8 191 },
Aaron@8 192 arg = "RecipeProfit",
Aaron@8 193 }
Aaron@8 194
Aaron@8 195 GatherMate:GetModule("Config").options.args.display.args.general.args.iconGroup.args.tracking.args["showRecipeProfit"] = {
Aaron@8 196 order = 6.5,
Aaron@8 197 name = "RecipeProfit",
Aaron@8 198 desc = "Color of the tracking circle.",
Aaron@8 199 type = "color",
Aaron@8 200 hasAlpha = true,
Aaron@8 201 arg = "RecipeProfit",
Aaron@8 202 }
Aaron@8 203
Aaron@0 204 GatherMate:GetModule("Config"):UpdateConfig()
Aaron@0 205 GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged")
Aaron@0 206 end
Aaron@0 207
Aaron@0 208 function RecipeProfit:OnEnable()
Aaron@1 209 for i=1, MERCHANT_ITEMS_PER_PAGE, 1 do
Aaron@1 210 local buttonframe = _G["MerchantItem"..i];
Aaron@1 211 buttonframe:HookScript("OnUpdate", function(self)
Aaron@1 212 local buttonName = _G[self:GetName().."Name"];
Aaron@1 213 local link = GetMerchantItemLink(_G[self:GetName().."ItemButton"]:GetID());
Aaron@2 214 if(not link) then
Aaron@2 215 return;
Aaron@2 216 end
Aaron@2 217
Aaron@1 218 local sName, sLink, iRarity, iLevel, iMinLevel, sType, sSubType, iStackCount = GetItemInfo(link)
Aaron@1 219
Aaron@1 220 if(sType == "Recipe" and safeRecipes[sName]) then
Aaron@1 221 SetItemButtonNameFrameVertexColor(self, 0, 0, 1.0);
Aaron@1 222 SetItemButtonSlotVertexColor(self, 0, 0, 0.5);
Aaron@2 223 buttonName:SetText("* " .. sName)
Aaron@1 224 if(GetItemCount(link, true) == 0) then
Aaron@1 225 buttonName:SetTextColor(0,1,1);
Aaron@1 226 elseif(GetItemCount(link, true) < 5) then
Aaron@1 227 buttonName:SetTextColor(1,0,1);
Aaron@1 228 else
Aaron@1 229 buttonName:SetTextColor(1,0,0);
Aaron@1 230 end
Aaron@1 231 else
Aaron@1 232 buttonName:SetTextColor(GameFontHighlightSmallOutline:GetTextColor());
Aaron@1 233 end
Aaron@1 234 end)
Aaron@1 235
Aaron@7 236
Aaron@1 237 end
Aaron@7 238
Aaron@7 239 RecipeProfit:DoMerge()
Aaron@0 240 end
Aaron@0 241
Aaron@0 242 local ids = {}
Aaron@0 243 function findGoodId(x, y)
Aaron@0 244 if ids[x.." "..y] then
Aaron@0 245 return findGoodId(x + .01, y)
Aaron@0 246 end
Aaron@0 247
Aaron@0 248 ids[x.." "..y] = true
Aaron@0 249 return x, y
Aaron@0 250 end
Aaron@0 251
Aaron@0 252 function RecipeProfit:DoMerge()
Aaron@0 253 ids = {}
Aaron@7 254 selectedDB = (db.profile.faction == "Alliance" or
Aaron@7 255 db.profile.faction == "default" and UnitFactionGroup("player") == "Alliance") and
Aaron@1 256 RECIPEPROFIT_alliance or RECIPEPROFIT_horde
Aaron@0 257 GatherMate:ClearDB("RecipeProfit")
Aaron@1 258 for id, note in pairs(selectedDB) do
Aaron@0 259 x, y = findGoodId(note.x, note.y)
Aaron@0 260 GatherMate:AddNode(note.map, x / 100, y / 100, "RecipeProfit",
Aaron@7 261 note.item.." - ("..note.vendor.." "..
Aaron@7 262 ((db.profile.faction == "Alliance" or db.profile.faction == "default" and
Aaron@7 263 UnitFactionGroup("player") == "Alliance") and "A" or "H") ..")")
Aaron@0 264 end
Aaron@0 265
Aaron@0 266 GatherMate:SendMessage("GatherMateDataImport")
Aaron@0 267 GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged")
Aaron@0 268 end