Mercurial > wow > recipeprofit
view 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 |
line wrap: on
line source
local RecipeProfit = LibStub("AceAddon-3.0"):NewAddon("RecipeProfit") local GatherMate = LibStub("AceAddon-3.0"):GetAddon("GatherMate") local tabletest = {} local db = {} local safeRecipes = {} safer = safeRecipes RecipeProfit.db = db; function debugprint(val, indent) indent = indent or ""; if not(type(val) == "table") then print("Not table: " .. val) return end for k,v in pairs(val) do if(type(k) == "table" and type(v) == "table") then print(indent .. "table key: {") debugprint(k, indent .. " ") print(indent .. "} = {") debugprint(v, indent .. " ") print(indent .. "}") elseif(type(v) == "table") then print(indent .. k .. " = {") debugprint(v, indent .. " ") print(indent .. "}") else print(indent .. k .. " = " .. v) end end end local options = { type = "group", name = "RecipeProfit", -- addon name to import from, don't localize handler = {}, disabled = false, args = { opt = { order = 1, name = "Select Database", desc = "Show a different database", type = "group", guiInline = true, args = { faction = { order = 0, name = "Faction", desc = "Show a different database.", type = "select", values = { ["Alliance"] = "Alliance", ["Horde"] = "Horde", ["default"] = "Default", }, arg = "faction", }, safeBuy = { order = 1, name = "Safe Recipe Buy", desc = "Warn when buying a recipe not on the RecipeProfit list.", type = "select", values = { ["on"] = "On", ["off"]= "Off", }, arg = "safebuy", }, }, get = function(k) return db.profile[k.arg]; end, set = function(k, v) db.profile[k.arg] = v; RecipeProfit:DoMerge(); end, }, loadData = { order = 8, name = "Import Data", desc = "Load RecipeProfit and import the data to your database.", type = "execute", func = function() RecipeProfit:DoMerge() end }, } } local defaults = { faction = "default", safebuy = "on", } function RecipeProfit:OnInitialize() profile = profile or defaults for k, v in pairs(defaults) do profile[k] = profile[k] or v; end db.profile = profile db.storage = {} GatherMate:GetModule("Config"):RegisterModule("RecipeProfit", options) GatherMate:RegisterDBType("RecipeProfit", db.storage) GatherMate.db.profile.show["RecipeProfit"] = "always" GatherMate.nodeIDs["RecipeProfit"] = {} GatherMate.nodeTextures["RecipeProfit"] = {} GatherMate.nodeMinHarvest["RecipeProfit"] = {} nodes = GatherMate.nodeIDs["RecipeProfit"] for id, note in pairs(RECIPEPROFIT_alliance) do safeRecipes[note.item] = true; nodes[note.item.." - ("..note.vendor.." A)"] = id * 10 GatherMate.nodeTextures["RecipeProfit"][id * 10] = "Interface\\Icons\\INV_Scroll_05" end for id, note in pairs(RECIPEPROFIT_horde) do safeRecipes[note.item] = true; nodes[note.item.." - ("..note.vendor.." H)"] = id * 10 + 1 GatherMate.nodeTextures["RecipeProfit"][id * 10 + 1] = "Interface\\Icons\\INV_Scroll_05" end GatherMate.reverseNodeIDs["RecipeProfit"] = GatherMate:CreateReversedTable(nodes) GatherMate:GetModule("Config"):UpdateConfig() GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged") end function RecipeProfit:OnEnable() for i=1, MERCHANT_ITEMS_PER_PAGE, 1 do local buttonframe = _G["MerchantItem"..i]; buttonframe:HookScript("OnUpdate", function(self) local buttonName = _G[self:GetName().."Name"]; local link = GetMerchantItemLink(_G[self:GetName().."ItemButton"]:GetID()); local sName, sLink, iRarity, iLevel, iMinLevel, sType, sSubType, iStackCount = GetItemInfo(link) if(sType == "Recipe" and safeRecipes[sName]) then SetItemButtonNameFrameVertexColor(self, 0, 0, 1.0); SetItemButtonSlotVertexColor(self, 0, 0, 0.5); if(GetItemCount(link, true) == 0) then buttonName:SetTextColor(0,1,1); elseif(GetItemCount(link, true) < 5) then buttonName:SetTextColor(1,0,1); else buttonName:SetTextColor(1,0,0); end else buttonName:SetTextColor(GameFontHighlightSmallOutline:GetTextColor()); end end) RecipeProfit:DoMerge() end end local ids = {} function findGoodId(x, y) if ids[x.." "..y] then return findGoodId(x + .01, y) end ids[x.." "..y] = true return x, y end function RecipeProfit:DoMerge() ids = {} selectedDB = db.profile.faction == "Alliance" and RECIPEPROFIT_alliance or db.profile.faction == "default" and UnitFactionGroup("player") == "Alliance" and RECIPEPROFIT_alliance or RECIPEPROFIT_horde GatherMate:ClearDB("RecipeProfit") for id, note in pairs(selectedDB) do x, y = findGoodId(note.x, note.y) GatherMate:AddNode(note.map, x / 100, y / 100, "RecipeProfit", note.item.." - ("..note.vendor.." ".. (db.profile.faction == "Alliance" and "A" or "H") ..")") end GatherMate:SendMessage("GatherMateDataImport") GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged") end
