Mercurial > wow > recipeprofit
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 0:25906be72a8b | 1:dceccfaf0a50 |
|---|---|
| 1 local RecipeProfit = LibStub("AceAddon-3.0"):NewAddon("RecipeProfit") | 1 local RecipeProfit = LibStub("AceAddon-3.0"):NewAddon("RecipeProfit") |
| 2 local GatherMate = LibStub("AceAddon-3.0"):GetAddon("GatherMate") | 2 local GatherMate = LibStub("AceAddon-3.0"):GetAddon("GatherMate") |
| 3 local tabletest = {} | 3 local tabletest = {} |
| 4 local db = {} | 4 local db = {} |
| 5 local safeRecipes = {} | |
| 6 safer = safeRecipes | |
| 5 RecipeProfit.db = db; | 7 RecipeProfit.db = db; |
| 8 | |
| 6 | 9 |
| 7 function debugprint(val, indent) | 10 function debugprint(val, indent) |
| 8 indent = indent or ""; | 11 indent = indent or ""; |
| 9 if not(type(val) == "table") then | 12 if not(type(val) == "table") then |
| 10 print("Not table: " .. val) | 13 print("Not table: " .. val) |
| 32 type = "group", | 35 type = "group", |
| 33 name = "RecipeProfit", -- addon name to import from, don't localize | 36 name = "RecipeProfit", -- addon name to import from, don't localize |
| 34 handler = {}, | 37 handler = {}, |
| 35 disabled = false, | 38 disabled = false, |
| 36 args = { | 39 args = { |
| 37 faction = { | 40 opt = { |
| 38 order = 1, | 41 order = 1, |
| 39 name = "Select Database", | 42 name = "Select Database", |
| 40 desc = "Show a different database", | 43 desc = "Show a different database", |
| 41 type = "group", | 44 type = "group", |
| 42 guiInline = true, | 45 guiInline = true, |
| 47 desc = "Show a different database.", | 50 desc = "Show a different database.", |
| 48 type = "select", | 51 type = "select", |
| 49 values = { | 52 values = { |
| 50 ["Alliance"] = "Alliance", | 53 ["Alliance"] = "Alliance", |
| 51 ["Horde"] = "Horde", | 54 ["Horde"] = "Horde", |
| 52 ["default"] = "Default (Determined By Character)", | 55 ["default"] = "Default", |
| 53 }, | 56 }, |
| 54 arg = "faction", | 57 arg = "faction", |
| 55 }, | 58 }, |
| 59 | |
| 60 safeBuy = { | |
| 61 order = 1, | |
| 62 name = "Safe Recipe Buy", | |
| 63 desc = "Warn when buying a recipe not on the RecipeProfit list.", | |
| 64 type = "select", | |
| 65 values = { | |
| 66 ["on"] = "On", | |
| 67 ["off"]= "Off", | |
| 68 }, | |
| 69 arg = "safebuy", | |
| 70 }, | |
| 56 }, | 71 }, |
| 57 get = function(k) print(k); return db.profile[k.arg]; end, | 72 get = function(k) return db.profile[k.arg]; end, |
| 58 set = function(k, v) db.profile[k.arg] = v; RecipeProfit:DoMerge(); end, | 73 set = function(k, v) db.profile[k.arg] = v; RecipeProfit:DoMerge(); end, |
| 59 }, | 74 }, |
| 60 loadData = { | 75 loadData = { |
| 61 order = 8, | 76 order = 8, |
| 62 name = "Import Data", | 77 name = "Import Data", |
| 68 }, | 83 }, |
| 69 } | 84 } |
| 70 } | 85 } |
| 71 | 86 |
| 72 local defaults = { | 87 local defaults = { |
| 73 faction = nil, | 88 faction = "default", |
| 89 safebuy = "on", | |
| 74 } | 90 } |
| 75 | 91 |
| 76 function RecipeProfit:OnInitialize() | 92 function RecipeProfit:OnInitialize() |
| 77 profile = profile or defaults | 93 profile = profile or defaults |
| 94 for k, v in pairs(defaults) do | |
| 95 profile[k] = profile[k] or v; | |
| 96 end | |
| 97 | |
| 78 db.profile = profile | 98 db.profile = profile |
| 79 db.storage = {} | 99 db.storage = {} |
| 80 | 100 |
| 81 GatherMate:GetModule("Config"):RegisterModule("RecipeProfit", options) | 101 GatherMate:GetModule("Config"):RegisterModule("RecipeProfit", options) |
| 82 GatherMate:RegisterDBType("RecipeProfit", db.storage) | 102 GatherMate:RegisterDBType("RecipeProfit", db.storage) |
| 85 GatherMate.nodeTextures["RecipeProfit"] = {} | 105 GatherMate.nodeTextures["RecipeProfit"] = {} |
| 86 GatherMate.nodeMinHarvest["RecipeProfit"] = {} | 106 GatherMate.nodeMinHarvest["RecipeProfit"] = {} |
| 87 nodes = GatherMate.nodeIDs["RecipeProfit"] | 107 nodes = GatherMate.nodeIDs["RecipeProfit"] |
| 88 | 108 |
| 89 for id, note in pairs(RECIPEPROFIT_alliance) do | 109 for id, note in pairs(RECIPEPROFIT_alliance) do |
| 110 safeRecipes[note.item] = true; | |
| 90 nodes[note.item.." - ("..note.vendor.." A)"] = id * 10 | 111 nodes[note.item.." - ("..note.vendor.." A)"] = id * 10 |
| 91 GatherMate.nodeTextures["RecipeProfit"][id * 10] = "Interface\\Icons\\INV_Scroll_05" | 112 GatherMate.nodeTextures["RecipeProfit"][id * 10] = "Interface\\Icons\\INV_Scroll_05" |
| 92 end | 113 end |
| 93 | 114 |
| 94 for id, note in pairs(RECIPEPROFIT_horde) do | 115 for id, note in pairs(RECIPEPROFIT_horde) do |
| 116 safeRecipes[note.item] = true; | |
| 95 nodes[note.item.." - ("..note.vendor.." H)"] = id * 10 + 1 | 117 nodes[note.item.." - ("..note.vendor.." H)"] = id * 10 + 1 |
| 96 GatherMate.nodeTextures["RecipeProfit"][id * 10 + 1] = "Interface\\Icons\\INV_Scroll_05" | 118 GatherMate.nodeTextures["RecipeProfit"][id * 10 + 1] = "Interface\\Icons\\INV_Scroll_05" |
| 97 end | 119 end |
| 98 | 120 |
| 99 GatherMate.reverseNodeIDs["RecipeProfit"] = GatherMate:CreateReversedTable(nodes) | 121 GatherMate.reverseNodeIDs["RecipeProfit"] = GatherMate:CreateReversedTable(nodes) |
| 101 | 123 |
| 102 GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged") | 124 GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged") |
| 103 end | 125 end |
| 104 | 126 |
| 105 function RecipeProfit:OnEnable() | 127 function RecipeProfit:OnEnable() |
| 106 db.profile.faction = db.profile.faction or UnitFactionGroup("player") | 128 for i=1, MERCHANT_ITEMS_PER_PAGE, 1 do |
| 107 | 129 local buttonframe = _G["MerchantItem"..i]; |
| 108 RecipeProfit:DoMerge() | 130 buttonframe:HookScript("OnUpdate", function(self) |
| 131 local buttonName = _G[self:GetName().."Name"]; | |
| 132 local link = GetMerchantItemLink(_G[self:GetName().."ItemButton"]:GetID()); | |
| 133 local sName, sLink, iRarity, iLevel, iMinLevel, sType, sSubType, iStackCount = GetItemInfo(link) | |
| 134 | |
| 135 if(sType == "Recipe" and safeRecipes[sName]) then | |
| 136 SetItemButtonNameFrameVertexColor(self, 0, 0, 1.0); | |
| 137 SetItemButtonSlotVertexColor(self, 0, 0, 0.5); | |
| 138 if(GetItemCount(link, true) == 0) then | |
| 139 buttonName:SetTextColor(0,1,1); | |
| 140 elseif(GetItemCount(link, true) < 5) then | |
| 141 buttonName:SetTextColor(1,0,1); | |
| 142 else | |
| 143 buttonName:SetTextColor(1,0,0); | |
| 144 end | |
| 145 else | |
| 146 buttonName:SetTextColor(GameFontHighlightSmallOutline:GetTextColor()); | |
| 147 end | |
| 148 end) | |
| 149 | |
| 150 RecipeProfit:DoMerge() | |
| 151 end | |
| 109 end | 152 end |
| 110 | 153 |
| 111 local ids = {} | 154 local ids = {} |
| 112 function findGoodId(x, y) | 155 function findGoodId(x, y) |
| 113 if ids[x.." "..y] then | 156 if ids[x.." "..y] then |
| 118 return x, y | 161 return x, y |
| 119 end | 162 end |
| 120 | 163 |
| 121 function RecipeProfit:DoMerge() | 164 function RecipeProfit:DoMerge() |
| 122 ids = {} | 165 ids = {} |
| 166 selectedDB = db.profile.faction == "Alliance" and RECIPEPROFIT_alliance or | |
| 167 db.profile.faction == "default" and UnitFactionGroup("player") == "Alliance" and | |
| 168 RECIPEPROFIT_alliance or RECIPEPROFIT_horde | |
| 123 GatherMate:ClearDB("RecipeProfit") | 169 GatherMate:ClearDB("RecipeProfit") |
| 124 for id, note in pairs(db.profile.faction == "Alliance" and RECIPEPROFIT_alliance or RECIPEPROFIT_horde) do | 170 for id, note in pairs(selectedDB) do |
| 125 x, y = findGoodId(note.x, note.y) | 171 x, y = findGoodId(note.x, note.y) |
| 126 GatherMate:AddNode(note.map, x / 100, y / 100, "RecipeProfit", | 172 GatherMate:AddNode(note.map, x / 100, y / 100, "RecipeProfit", |
| 127 note.item.." - ("..note.vendor.." ".. (db.profile.faction == "Alliance" and "A" or "H") ..")") | 173 note.item.." - ("..note.vendor.." ".. (db.profile.faction == "Alliance" and "A" or "H") ..")") |
| 128 end | 174 end |
| 129 | 175 |
