annotate core.lua @ 9:20e2aefac1b0

Bugfix involving highlight of merchant frame text
author Aaron Bregger
date Thu, 12 Aug 2010 17:43:48 -0500
parents 5a0fa30712da
children 5ae9ffe0cc2d
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@9 14 local RecipeProfit = LibStub("AceAddon-3.0"):NewAddon("RecipeProfit", "AceEvent-3.0")
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@9 208 function button_update(self)
Aaron@9 209 local buttonName = _G[self:GetName().."Name"];
Aaron@9 210 local link = GetMerchantItemLink(_G[self:GetName().."ItemButton"]:GetID());
Aaron@9 211 if(not link) then
Aaron@9 212 return;
Aaron@9 213 end
Aaron@9 214
Aaron@9 215 local sName, sLink, iRarity, iLevel, iMinLevel, sType, sSubType, iStackCount = GetItemInfo(link)
Aaron@9 216
Aaron@9 217 if(sType == "Recipe" and safeRecipes[sName]) then
Aaron@9 218 SetItemButtonNameFrameVertexColor(self, 0, 0, 1.0);
Aaron@9 219 SetItemButtonSlotVertexColor(self, 0, 0, 0.5);
Aaron@9 220 buttonName:SetText("* " .. sName)
Aaron@9 221 if(GetItemCount(link, true) == 0) then
Aaron@9 222 buttonName:SetTextColor(0,1,1);
Aaron@9 223 elseif(GetItemCount(link, true) < 5) then
Aaron@9 224 buttonName:SetTextColor(1,0,1);
Aaron@9 225 else
Aaron@9 226 buttonName:SetTextColor(1,0,0);
Aaron@9 227 end
Aaron@9 228 else
Aaron@9 229 buttonName:SetTextColor(GameFontNormalSmall:GetTextColor());
Aaron@9 230 end
Aaron@9 231 end
Aaron@9 232
Aaron@9 233 function RecipeProfit:UpdateButtons(event)
Aaron@9 234 --print("UpdateButtons", event)
Aaron@1 235 for i=1, MERCHANT_ITEMS_PER_PAGE, 1 do
Aaron@1 236 local buttonframe = _G["MerchantItem"..i];
Aaron@9 237 local index = (((MerchantFrame.page - 1) * MERCHANT_ITEMS_PER_PAGE) + i);
Aaron@9 238 --print(index)
Aaron@9 239 if index <= GetMerchantNumItems() then
Aaron@9 240 button_update(buttonframe)
Aaron@9 241 else
Aaron@9 242 --print(i, index, GetMerchantNumItems())
Aaron@9 243 local itemButton = _G["MerchantItem"..i.."ItemButton"];
Aaron@9 244 local merchantButton = _G["MerchantItem"..i];
Aaron@9 245 itemButton.price = nil;
Aaron@9 246 itemButton.hasItem = nil;
Aaron@9 247 itemButton:Hide();
Aaron@9 248 SetItemButtonNameFrameVertexColor(merchantButton, 0.5, 0.5, 0.5);
Aaron@9 249 SetItemButtonSlotVertexColor(merchantButton,0.4, 0.4, 0.4);
Aaron@9 250 _G["MerchantItem"..i.."Name"]:SetText("");
Aaron@9 251 _G["MerchantItem"..i.."MoneyFrame"]:Hide();
Aaron@9 252 _G["MerchantItem"..i.."AltCurrencyFrame"]:Hide();
Aaron@9 253 end
Aaron@9 254 end
Aaron@9 255 end
Aaron@9 256
Aaron@1 257
Aaron@9 258 function RecipeProfit:OnEnable()
Aaron@7 259
Aaron@9 260 _G["MerchantPrevPageButton"]:HookScript("OnClick", self.UpdateButtons)
Aaron@9 261 _G["MerchantNextPageButton"]:HookScript("OnClick", self.UpdateButtons)
Aaron@9 262
Aaron@9 263 self:RegisterEvent("MERCHANT_SHOW", "UpdateButtons")
Aaron@9 264 self:RegisterEvent("MERCHANT_UPDATE", "UpdateButtons")
Aaron@7 265
Aaron@7 266 RecipeProfit:DoMerge()
Aaron@0 267 end
Aaron@0 268
Aaron@0 269 local ids = {}
Aaron@0 270 function findGoodId(x, y)
Aaron@0 271 if ids[x.." "..y] then
Aaron@0 272 return findGoodId(x + .01, y)
Aaron@0 273 end
Aaron@0 274
Aaron@0 275 ids[x.." "..y] = true
Aaron@0 276 return x, y
Aaron@0 277 end
Aaron@0 278
Aaron@0 279 function RecipeProfit:DoMerge()
Aaron@0 280 ids = {}
Aaron@7 281 selectedDB = (db.profile.faction == "Alliance" or
Aaron@7 282 db.profile.faction == "default" and UnitFactionGroup("player") == "Alliance") and
Aaron@1 283 RECIPEPROFIT_alliance or RECIPEPROFIT_horde
Aaron@0 284 GatherMate:ClearDB("RecipeProfit")
Aaron@1 285 for id, note in pairs(selectedDB) do
Aaron@0 286 x, y = findGoodId(note.x, note.y)
Aaron@0 287 GatherMate:AddNode(note.map, x / 100, y / 100, "RecipeProfit",
Aaron@7 288 note.item.." - ("..note.vendor.." "..
Aaron@7 289 ((db.profile.faction == "Alliance" or db.profile.faction == "default" and
Aaron@7 290 UnitFactionGroup("player") == "Alliance") and "A" or "H") ..")")
Aaron@0 291 end
Aaron@0 292
Aaron@0 293 GatherMate:SendMessage("GatherMateDataImport")
Aaron@0 294 GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged")
Aaron@0 295 end