Mercurial > wow > askmrrobot
comparison Shopping.lua @ 124:e31b02b24488
Updated for 8.0 pre-patch and BfA.
| author | yellowfive |
|---|---|
| date | Tue, 17 Jul 2018 09:57:39 -0700 |
| parents | f1da233629be |
| children | 318c93e0cd6b |
comparison
equal
deleted
inserted
replaced
| 123:7a6364917f86 | 124:e31b02b24488 |
|---|---|
| 57 if name then | 57 if name then |
| 58 QueryAuctionItems(name) | 58 QueryAuctionItems(name) |
| 59 end | 59 end |
| 60 end | 60 end |
| 61 | 61 |
| 62 | |
| 62 function Amr:ShowShopWindow() | 63 function Amr:ShowShopWindow() |
| 64 | |
| 63 if not _frameShop then | 65 if not _frameShop then |
| 64 _frameShop = AceGUI:Create("AmrUiFrame") | 66 _frameShop = AceGUI:Create("AmrUiFrame") |
| 65 _frameShop:SetStatusTable(Amr.db.profile.shopWindow) -- window position is remembered in db | 67 _frameShop:SetStatusTable(Amr.db.profile.shopWindow) -- window position is remembered in db |
| 66 _frameShop:SetCallback("OnClose", onShopFrameClose) | 68 _frameShop:SetCallback("OnClose", onShopFrameClose) |
| 67 _frameShop:SetLayout("None") | 69 _frameShop:SetLayout("None") |
| 74 local scale = tonumber(Amr.db.profile.options.uiScale) | 76 local scale = tonumber(Amr.db.profile.options.uiScale) |
| 75 _frameShop:SetScale(scale) | 77 _frameShop:SetScale(scale) |
| 76 end | 78 end |
| 77 | 79 |
| 78 local lbl = AceGUI:Create("AmrUiLabel") | 80 local lbl = AceGUI:Create("AmrUiLabel") |
| 81 _frameShop:AddChild(lbl) | |
| 79 lbl:SetWidth(400) | 82 lbl:SetWidth(400) |
| 80 lbl:SetFont(Amr.CreateFont("Bold", 28, Amr.Colors.White)) | 83 lbl:SetFont(Amr.CreateFont("Bold", 28, Amr.Colors.White)) |
| 81 lbl:SetText(L.ShopTitle) | 84 lbl:SetText(L.ShopTitle) |
| 82 lbl:SetWordWrap(false) | 85 lbl:SetWordWrap(false) |
| 83 lbl:SetJustifyH("CENTER") | 86 lbl:SetJustifyH("CENTER") |
| 84 lbl:SetPoint("TOP", _frameShop.content, "TOP", 0, 30) | 87 lbl:SetPoint("TOP", _frameShop.content, "TOP", 0, 30) |
| 85 _frameShop:AddChild(lbl) | |
| 86 | 88 |
| 87 lbl:SetCallback("OnMouseDown", function(widget) _frameShop:StartMove() end) | 89 lbl:SetCallback("OnMouseDown", function(widget) _frameShop:StartMove() end) |
| 88 lbl:SetCallback("OnMouseUp", function(widget) _frameShop:EndMove() end) | 90 lbl:SetCallback("OnMouseUp", function(widget) _frameShop:EndMove() end) |
| 89 | 91 |
| 90 -- player picker | 92 -- player picker |
| 91 _cboPlayers = AceGUI:Create("AmrUiDropDown") | 93 _cboPlayers = AceGUI:Create("AmrUiDropDown") |
| 92 _cboPlayers:SetWidth(400) | 94 _cboPlayers:SetWidth(400) |
| 95 _frameShop:AddChild(_cboPlayers) | |
| 93 _cboPlayers:SetPoint("TOPLEFT", _frameShop.content, "TOPLEFT", 0, -30) | 96 _cboPlayers:SetPoint("TOPLEFT", _frameShop.content, "TOPLEFT", 0, -30) |
| 94 _frameShop:AddChild(_cboPlayers) | |
| 95 | 97 |
| 96 -- spec pickers | 98 -- spec pickers |
| 97 _chk1 = AceGUI:Create("AmrUiCheckBox") | 99 _chk1 = AceGUI:Create("AmrUiCheckBox") |
| 98 _chk1:SetPoint("TOPLEFT", _cboPlayers.frame, "BOTTOMLEFT", 0, -20) | |
| 99 _chk1:SetUserData("spec", 1) | 100 _chk1:SetUserData("spec", 1) |
| 100 _chk1:SetCallback("OnClick", onSpecClick) | 101 _chk1:SetCallback("OnClick", onSpecClick) |
| 101 _frameShop:AddChild(_chk1) | 102 _frameShop:AddChild(_chk1) |
| 103 _chk1:SetPoint("TOPLEFT", _cboPlayers.frame, "BOTTOMLEFT", 0, -20) | |
| 102 | 104 |
| 103 _chk2 = AceGUI:Create("AmrUiCheckBox") | 105 _chk2 = AceGUI:Create("AmrUiCheckBox") |
| 104 _chk2:SetPoint("LEFT", _chk1.frame, "RIGHT", 30, 0) | |
| 105 _chk2:SetUserData("spec", 2) | 106 _chk2:SetUserData("spec", 2) |
| 106 _chk2:SetCallback("OnClick", onSpecClick) | 107 _chk2:SetCallback("OnClick", onSpecClick) |
| 107 _frameShop:AddChild(_chk2) | 108 _frameShop:AddChild(_chk2) |
| 109 _chk2:SetPoint("LEFT", _chk1.frame, "RIGHT", 30, 0) | |
| 108 | 110 |
| 109 _chk3 = AceGUI:Create("AmrUiCheckBox") | 111 _chk3 = AceGUI:Create("AmrUiCheckBox") |
| 110 _chk3:SetPoint("LEFT", _chk2.frame, "RIGHT", 30, 0) | |
| 111 _chk3:SetUserData("spec", 3) | 112 _chk3:SetUserData("spec", 3) |
| 112 _chk3:SetCallback("OnClick", onSpecClick) | 113 _chk3:SetCallback("OnClick", onSpecClick) |
| 113 _frameShop:AddChild(_chk3) | 114 _frameShop:AddChild(_chk3) |
| 115 _chk3:SetPoint("LEFT", _chk2.frame, "RIGHT", 30, 0) | |
| 114 | 116 |
| 115 _chk4 = AceGUI:Create("AmrUiCheckBox") | 117 _chk4 = AceGUI:Create("AmrUiCheckBox") |
| 116 _chk4:SetPoint("LEFT", _chk3.frame, "RIGHT", 30, 0) | |
| 117 _chk4:SetUserData("spec", 4) | 118 _chk4:SetUserData("spec", 4) |
| 118 _chk4:SetCallback("OnClick", onSpecClick) | 119 _chk4:SetCallback("OnClick", onSpecClick) |
| 119 _frameShop:AddChild(_chk4) | 120 _frameShop:AddChild(_chk4) |
| 121 _chk4:SetPoint("LEFT", _chk3.frame, "RIGHT", 30, 0) | |
| 120 | 122 |
| 121 _panelContent = AceGUI:Create("AmrUiPanel") | 123 _panelContent = AceGUI:Create("AmrUiPanel") |
| 122 _panelContent:SetLayout("None") | 124 _panelContent:SetLayout("None") |
| 123 _panelContent:SetTransparent() | 125 _panelContent:SetTransparent() |
| 126 _frameShop:AddChild(_panelContent) | |
| 124 _panelContent:SetPoint("TOPLEFT", _chk1.frame, "BOTTOMLEFT", 0, -10) | 127 _panelContent:SetPoint("TOPLEFT", _chk1.frame, "BOTTOMLEFT", 0, -10) |
| 125 _panelContent:SetPoint("BOTTOMRIGHT", _frameShop.content, "BOTTOMRIGHT") | 128 _panelContent:SetPoint("BOTTOMRIGHT", _frameShop.content, "BOTTOMRIGHT") |
| 126 _frameShop:AddChild(_panelContent) | |
| 127 | 129 |
| 128 -- update shopping list data | 130 -- update shopping list data |
| 129 local player = Amr:ExportCharacter() | 131 local player = Amr:ExportCharacter() |
| 130 Amr:UpdateShoppingData(player) | 132 Amr:UpdateShoppingData(player) |
| 131 | 133 |
| 166 panel:SetWidth(w) | 168 panel:SetWidth(w) |
| 167 panel:SetHeight(40) | 169 panel:SetHeight(40) |
| 168 scroll:AddChild(panel) | 170 scroll:AddChild(panel) |
| 169 | 171 |
| 170 local lbl = AceGUI:Create("AmrUiLabel") | 172 local lbl = AceGUI:Create("AmrUiLabel") |
| 173 panel:AddChild(lbl) | |
| 171 lbl:SetWidth(w) | 174 lbl:SetWidth(w) |
| 172 lbl:SetFont(Amr.CreateFont("Regular", 18, Amr.Colors.TextHeaderActive)) | 175 lbl:SetFont(Amr.CreateFont("Regular", 18, Amr.Colors.TextHeaderActive)) |
| 173 lbl:SetText(header) | 176 lbl:SetText(header) |
| 174 lbl:SetPoint("BOTTOMLEFT", panel.content, "BOTTOMLEFT") | 177 lbl:SetPoint("BOTTOMLEFT", panel.content, "BOTTOMLEFT") |
| 175 panel:AddChild(lbl) | |
| 176 | 178 |
| 177 for itemId, count in pairs(list) do | 179 for itemId, count in pairs(list) do |
| 178 panel = AceGUI:Create("AmrUiPanel") | 180 panel = AceGUI:Create("AmrUiPanel") |
| 179 panel:SetLayout("None") | 181 panel:SetLayout("None") |
| 180 panel:SetTransparent() | 182 panel:SetTransparent() |
| 181 panel:SetWidth(w) | 183 panel:SetWidth(w) |
| 182 panel:SetHeight(30) | 184 panel:SetHeight(30) |
| 183 scroll:AddChild(panel) | 185 scroll:AddChild(panel) |
| 184 | 186 |
| 185 lbl = AceGUI:Create("AmrUiLabel") | 187 lbl = AceGUI:Create("AmrUiLabel") |
| 188 panel:AddChild(lbl) | |
| 186 lbl:SetWidth(40) | 189 lbl:SetWidth(40) |
| 187 lbl:SetWordWrap(false) | 190 lbl:SetWordWrap(false) |
| 188 lbl:SetFont(Amr.CreateFont("Bold", 20, Amr.Colors.White)) | 191 lbl:SetFont(Amr.CreateFont("Bold", 20, Amr.Colors.White)) |
| 189 lbl:SetText(count .. "x") | 192 lbl:SetText(count .. "x") |
| 190 lbl:SetPoint("LEFT", panel.content, "LEFT") | 193 lbl:SetPoint("LEFT", panel.content, "LEFT") |
| 191 panel:AddChild(lbl) | |
| 192 | 194 |
| 193 local icon = AceGUI:Create("AmrUiIcon") | 195 local icon = AceGUI:Create("AmrUiIcon") |
| 194 icon:SetBorderWidth(1) | 196 icon:SetBorderWidth(1) |
| 195 icon:SetIconBorderColor(Amr.Colors.White) | 197 icon:SetIconBorderColor(Amr.Colors.White) |
| 196 icon:SetWidth(18) | 198 icon:SetWidth(18) |
| 197 icon:SetHeight(18) | 199 icon:SetHeight(18) |
| 200 panel:AddChild(icon) | |
| 198 icon:SetPoint("LEFT", lbl.frame, "RIGHT", 5, 0) | 201 icon:SetPoint("LEFT", lbl.frame, "RIGHT", 5, 0) |
| 199 panel:AddChild(icon) | |
| 200 | 202 |
| 201 local btn = AceGUI:Create("AmrUiTextButton") | 203 local btn = AceGUI:Create("AmrUiTextButton") |
| 202 btn:SetWidth(w - 30 - 18 - 15) | 204 btn:SetWidth(w - 30 - 18 - 15) |
| 203 btn:SetJustifyH("LEFT") | 205 btn:SetJustifyH("LEFT") |
| 204 btn:SetWordWrap(false) | 206 btn:SetWordWrap(false) |
| 205 btn:SetFont(Amr.CreateFont("Bold", 14, Amr.Colors.White)) | 207 btn:SetFont(Amr.CreateFont("Bold", 14, Amr.Colors.White)) |
| 206 btn:SetHoverFont(Amr.CreateFont("Bold", 14, Amr.Colors.White)) | 208 btn:SetHoverFont(Amr.CreateFont("Bold", 14, Amr.Colors.White)) |
| 207 btn:SetPoint("LEFT", icon.frame, "RIGHT", 5, 0) | |
| 208 btn:SetCallback("OnClick", onItemClick) | 209 btn:SetCallback("OnClick", onItemClick) |
| 209 panel:AddChild(btn) | 210 panel:AddChild(btn) |
| 211 btn:SetPoint("LEFT", icon.frame, "RIGHT", 5, 0) | |
| 210 | 212 |
| 211 Amr.GetItemInfo(itemId, function(obj, name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture) | 213 Amr.GetItemInfo(itemId, function(obj, name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture) |
| 212 -- set icon, name, and a tooltip | 214 -- set icon, name, and a tooltip |
| 213 obj.itemIcon:SetIcon(texture) | 215 obj.itemIcon:SetIcon(texture) |
| 214 obj.itemText:SetText(link:gsub("%[", ""):gsub("%]", "")) | 216 obj.itemText:SetText(link:gsub("%[", ""):gsub("%]", "")) |
| 226 local list = Amr.db.char.BagItemsAndCounts | 228 local list = Amr.db.char.BagItemsAndCounts |
| 227 if list and list[itemId] then | 229 if list and list[itemId] then |
| 228 ret = ret + list[itemId] | 230 ret = ret + list[itemId] |
| 229 end | 231 end |
| 230 | 232 |
| 231 list = Amr.db.char.BankItemsAndCounts | 233 local bankBags = Amr.db.char.BankItemsAndCounts |
| 232 if list and list[itemId] then | 234 if bankBags then |
| 233 ret = ret + list[itemId] | 235 for bagId,bagList in pairs(bankBags) do |
| 236 if bagList[itemId] then | |
| 237 ret = ret + bagList[itemId] | |
| 238 end | |
| 239 end | |
| 234 end | 240 end |
| 235 | 241 |
| 236 return ret | 242 return ret |
| 237 end | 243 end |
| 238 | 244 |
| 277 local data = Amr.db.global.Shopping[_selectedPlayer] | 283 local data = Amr.db.global.Shopping[_selectedPlayer] |
| 278 if not data then | 284 if not data then |
| 279 _panelContent:SetLayout("None") | 285 _panelContent:SetLayout("None") |
| 280 | 286 |
| 281 local lbl = AceGUI:Create("AmrUiLabel") | 287 local lbl = AceGUI:Create("AmrUiLabel") |
| 288 _panelContent:AddChild(lbl) | |
| 282 lbl:SetFont(Amr.CreateFont("Italic", 18, Amr.Colors.TextTan)) | 289 lbl:SetFont(Amr.CreateFont("Italic", 18, Amr.Colors.TextTan)) |
| 283 lbl:SetText(L.ShopEmpty) | 290 lbl:SetText(L.ShopEmpty) |
| 284 lbl:SetJustifyH("CENTER") | 291 lbl:SetJustifyH("CENTER") |
| 285 lbl:SetPoint("TOP", _panelContent.content, "TOP", 0, -30) | 292 lbl:SetPoint("TOP", _panelContent.content, "TOP", 0, -30) |
| 286 _panelContent:AddChild(lbl) | |
| 287 else | 293 else |
| 288 local allStuff = { gems = {}, enchants = {}, materials = {} } | 294 local allStuff = { gems = {}, enchants = {}, materials = {} } |
| 289 local hasStuff = false | 295 local hasStuff = false |
| 290 local visited = {} | 296 local visited = {} |
| 291 | 297 |
| 352 end | 358 end |
| 353 end | 359 end |
| 354 | 360 |
| 355 end | 361 end |
| 356 | 362 |
| 357 -- compare gear to everything the player owns, and return the minimum gems/enchants/materials needed to optimize, grouped by inventory ID so that we can combine multiple specs without double-counting | 363 -- compare gear to everything the player owns, and return the minimum gems/enchants/materials needed to optimize, |
| 364 -- grouped by inventory ID so that we can combine multiple specs without double-counting | |
| 358 local function getShoppingData(player, gear, spec) | 365 local function getShoppingData(player, gear, spec) |
| 359 | 366 |
| 360 local ret = {} | 367 local ret = {} |
| 361 | 368 |
| 362 -- used to prevent considering the same item twice | 369 -- used to prevent considering the same item twice |
| 363 local usedItems = {} | 370 local usedItems = {} |
| 364 | 371 |
| 365 for slotId, optimalItem in pairs(gear) do | 372 for slotId, optimalItem in pairs(gear) do |
| 366 local matchItemLink, matchItem = Amr:FindMatchingItem(optimalItem, player, usedItems) | 373 local matchItem = Amr:FindMatchingItem(optimalItem, player, usedItems) |
| 367 local itemInfo = Amr.db.char.ExtraItemData[spec][optimalItem.id] | |
| 368 local inventoryId = optimalItem.inventoryId or -1 | 374 local inventoryId = optimalItem.inventoryId or -1 |
| 369 | 375 |
| 370 -- find gem/enchant differences on the best-matching item | 376 -- find gem/enchant differences on the best-matching item |
| 371 | 377 |
| 372 -- gems, but skip artifact relics (will have relicBonusIds set) | 378 -- gems |
| 373 if not optimalItem.relicBonusIds and itemInfo and itemInfo.socketColors then | 379 if not optimalItem.relicBonusIds and (not matchItem or not matchItem.relicBonusIds) then |
| 374 for i = 1, #itemInfo.socketColors do | 380 for i = 1, 3 do |
| 375 local g = optimalItem.gemIds[i] | 381 local g = optimalItem.gemIds[i] |
| 376 local isGemEquipped = g ~= 0 and matchItem and matchItem.gemIds and matchItem.gemIds[i] == g | 382 local isGemEquipped = g ~= 0 and matchItem and matchItem.gemIds and matchItem.gemIds[i] == g |
| 377 | 383 |
| 378 if not isGemEquipped then | 384 if not isGemEquipped then |
| 379 if not ret[inventoryId] then | 385 if not ret[inventoryId] then |
| 388 if optimalItem.enchantId and optimalItem.enchantId ~= 0 then | 394 if optimalItem.enchantId and optimalItem.enchantId ~= 0 then |
| 389 local e = optimalItem.enchantId | 395 local e = optimalItem.enchantId |
| 390 local isEnchantEquipped = matchItem and matchItem.enchantId and matchItem.enchantId == e | 396 local isEnchantEquipped = matchItem and matchItem.enchantId and matchItem.enchantId == e |
| 391 | 397 |
| 392 if not isEnchantEquipped then | 398 if not isEnchantEquipped then |
| 393 -- enchant info, look in all spec extra info cache | 399 -- enchant info |
| 394 local enchInfo = nil | 400 local enchInfo = Amr.db.char.ExtraEnchantData[e] |
| 395 for specPos = 1,4 do | |
| 396 if Amr.db.char.ExtraEnchantData[specPos] then | |
| 397 enchInfo = Amr.db.char.ExtraEnchantData[specPos][e] | |
| 398 if enchInfo then break end | |
| 399 end | |
| 400 end | |
| 401 | |
| 402 if enchInfo then | 401 if enchInfo then |
| 403 if not ret[inventoryId] then | 402 if not ret[inventoryId] then |
| 404 ret[inventoryId] = { gems = {}, enchants = {}, materials = {} } | 403 ret[inventoryId] = { gems = {}, enchants = {}, materials = {} } |
| 405 end | 404 end |
| 406 incrementTableItem(ret[inventoryId].enchants, enchInfo.itemId, 1) | 405 incrementTableItem(ret[inventoryId].enchants, enchInfo.itemId, 1) |
| 426 specs = player.Specs | 425 specs = player.Specs |
| 427 } | 426 } |
| 428 | 427 |
| 429 local enchantItemIdToId = {} | 428 local enchantItemIdToId = {} |
| 430 | 429 |
| 431 for spec, gear in pairs(Amr.db.char.GearSets) do | 430 for i, spec in ipairs(required.specs) do |
| 432 required.stuff[spec] = getShoppingData(player, gear, spec) | 431 local gear = Amr.db.char.GearSets[spec] |
| 432 if gear then | |
| 433 required.stuff[i] = getShoppingData(player, gear, spec) | |
| 434 else | |
| 435 required.stuff[i] = {} | |
| 436 end | |
| 433 end | 437 end |
| 434 | 438 |
| 435 Amr.db.global.Shopping[player.Name .. "-" .. player.Realm] = required | 439 Amr.db.global.Shopping[player.Name .. "-" .. player.Realm] = required |
| 436 end | 440 end |
| 437 | 441 |
