comparison Gear.lua @ 89:6bbe64d587b4 v42

Improved artifact/relic reading, gear display. Now creates equipment manager sets when you use button or command to equip a set.
author yellowfive
date Sun, 18 Sep 2016 21:24:08 -0700
parents fe0bc2f32851
children b8e9664d3229
comparison
equal deleted inserted replaced
88:b3ff336fad77 89:6bbe64d587b4
219 if optimalItemLink then 219 if optimalItemLink then
220 Amr.GetItemInfo(optimalItemLink, function(obj, name, link, quality, iLevel) 220 Amr.GetItemInfo(optimalItemLink, function(obj, name, link, quality, iLevel)
221 -- set item name, tooltip, and ilvl 221 -- set item name, tooltip, and ilvl
222 obj.nameLabel:SetText(link:gsub("%[", ""):gsub("%]", "")) 222 obj.nameLabel:SetText(link:gsub("%[", ""):gsub("%]", ""))
223 Amr:SetItemTooltip(obj.nameLabel, link) 223 Amr:SetItemTooltip(obj.nameLabel, link)
224 obj.ilvlLabel:SetText(iLevel) 224
225 -- the game's info gives the wrong item level, so we have to scan for it
226 iLevel = (quality ~= 6 or optimalItem.relicBonusIds) and Amr.GetItemLevel(nil, nil, link) or ""
227 obj.ilvlLabel:SetText(iLevel)
228
225 end, { ilvlLabel = lblIlvl, nameLabel = lblItem }) 229 end, { ilvlLabel = lblIlvl, nameLabel = lblItem })
226 end 230 end
227 231
228 -- modifications 232 -- modifications
229 if optimalItem then 233 if optimalItem then
230 local itemInfo = Amr.db.char.ExtraItemData[spec][optimalItem.id] 234 local itemInfo = Amr.db.char.ExtraItemData[spec][optimalItem.id]
231 235
232 -- gems 236 -- gems
233 if itemInfo and itemInfo.socketColors then 237 if itemInfo and itemInfo.socketColors then
238 local prevSocket = nil
234 for i = 1, #itemInfo.socketColors do 239 for i = 1, #itemInfo.socketColors do
235 local g = optimalItem.gemIds[i] 240 local g = optimalItem.gemIds[i]
236 local isGemEquipped = g ~= 0 and matchItem and matchItem.gemIds and matchItem.gemIds[i] == g 241 local isGemEquipped = g ~= 0 and matchItem and matchItem.gemIds and matchItem.gemIds[i] == g
237 242
238 -- highlight for gem that doesn't match 243 -- highlight for gem that doesn't match
239 local socketBorder = AceGUI:Create("AmrUiPanel") 244 local socketBorder = AceGUI:Create("AmrUiPanel")
240 socketBorder:SetLayout("None") 245 socketBorder:SetLayout("None")
241 socketBorder:SetBackgroundColor(Amr.Colors.Black, isGemEquipped and 0 or 1) 246 socketBorder:SetBackgroundColor(Amr.Colors.Black, isGemEquipped and 0 or 1)
242 socketBorder:SetWidth(26) 247 socketBorder:SetWidth(26)
243 socketBorder:SetHeight(26) 248 socketBorder:SetHeight(26)
244 socketBorder:SetPoint("LEFT", lblItem.frame, "RIGHT", 30, 0) 249 if not prevSocket then
250 socketBorder:SetPoint("LEFT", lblItem.frame, "RIGHT", 30, 0)
251 else
252 socketBorder:SetPoint("LEFT", prevSocket.frame, "RIGHT", 2, 0)
253 end
245 if isGemEquipped then 254 if isGemEquipped then
246 socketBorder:SetAlpha(0.3) 255 socketBorder:SetAlpha(0.3)
247 end 256 end
248 panelMods:AddChild(socketBorder) 257 panelMods:AddChild(socketBorder)
249 258
266 275
267 -- get icon for optimized gem 276 -- get icon for optimized gem
268 if g ~= 0 then 277 if g ~= 0 then
269 local gemInfo = Amr.db.char.ExtraGemData[spec][g] 278 local gemInfo = Amr.db.char.ExtraGemData[spec][g]
270 if gemInfo then 279 if gemInfo then
271 Amr.GetItemInfo(gemInfo.id, function(obj, name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture) 280 local gident = gemInfo.id
281 if optimalItem.relicBonusIds then
282 gident = Amr.CreateItemLink({ id = gemInfo.id, enchantId = 0, gemIds = {0,0,0,0}, suffixId = 0, bonusIds = optimalItem.relicBonusIds[i]})
283 end
284 Amr.GetItemInfo(gident, function(obj, name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture)
272 -- set icon and a tooltip 285 -- set icon and a tooltip
273 obj:SetIcon(texture) 286 obj:SetIcon(texture)
274 Amr:SetItemTooltip(obj, link) 287 Amr:SetItemTooltip(obj, link)
275 end, socketIcon) 288 end, socketIcon)
276 end 289 end
277 end 290 end
291
292 prevSocket = socketBorder
278 end 293 end
279 end 294 end
280 295
281 -- enchant 296 -- enchant
282 if optimalItem.enchantId and optimalItem.enchantId ~= 0 then 297 if optimalItem.enchantId and optimalItem.enchantId ~= 0 then
376 t:SetPoint("TOPLEFT", container.content, "TOPLEFT", 144, -30) 391 t:SetPoint("TOPLEFT", container.content, "TOPLEFT", 144, -30)
377 t:SetPoint("BOTTOMRIGHT", container.content, "BOTTOMRIGHT") 392 t:SetPoint("BOTTOMRIGHT", container.content, "BOTTOMRIGHT")
378 container:AddChild(t) 393 container:AddChild(t)
379 _gearTabs = t; 394 _gearTabs = t;
380 395
381 --[[
382 local btnShop = AceGUI:Create("AmrUiButton") 396 local btnShop = AceGUI:Create("AmrUiButton")
383 btnShop:SetText(L.GearButtonShop) 397 btnShop:SetText(L.GearButtonShop)
384 btnShop:SetBackgroundColor(Amr.Colors.Blue) 398 btnShop:SetBackgroundColor(Amr.Colors.Blue)
385 btnShop:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.White)) 399 btnShop:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.White))
386 btnShop:SetWidth(245) 400 btnShop:SetWidth(245)
387 btnShop:SetHeight(26) 401 btnShop:SetHeight(26)
388 btnShop:SetPoint("TOPRIGHT", container.content, "TOPRIGHT", -20, -25) 402 btnShop:SetPoint("TOPRIGHT", container.content, "TOPRIGHT", -20, -25)
389 btnShop:SetCallback("OnClick", function(widget) Amr:ShowShopWindow() end) 403 btnShop:SetCallback("OnClick", function(widget) Amr:ShowShopWindow() end)
390 container:AddChild(btnShop) 404 container:AddChild(btnShop)
391 ]]
392 405
393 if not _activeTab then 406 if not _activeTab then
394 _activeTab = tostring(GetSpecialization()) 407 _activeTab = tostring(GetSpecialization())
395 end 408 end
396 409
421 -- Gear Set Management 434 -- Gear Set Management
422 ------------------------------------------------------------------------------------------------ 435 ------------------------------------------------------------------------------------------------
423 local _waitingForSpec = 0 436 local _waitingForSpec = 0
424 local _waitingForItemLock = nil 437 local _waitingForItemLock = nil
425 local _pendingEquip = nil 438 local _pendingEquip = nil
439 local _pendingRemove = nil
426 440
427 -- scan a bag for the best matching item 441 -- scan a bag for the best matching item
428 local function scanBagForItem(item, bagId, bestItem, bestDiff, bestLink) 442 local function scanBagForItem(item, bagId, bestItem, bestDiff, bestLink)
429 local numSlots = GetContainerNumSlots(bagId) 443 local numSlots = GetContainerNumSlots(bagId)
430 for slotId = 1, numSlots do 444 for slotId = 1, numSlots do
443 end 457 end
444 end 458 end
445 return bestItem, bestDiff, bestLink 459 return bestItem, bestDiff, bestLink
446 end 460 end
447 461
462 local function onEquipGearSetComplete()
463 -- create an equipment manager set
464 local specId, specName = GetSpecializationInfo(GetSpecialization())
465
466 local item = Amr.ParseItemLink(GetInventoryItemLink("player", INVSLOT_MAINHAND))
467 if not item or not Amr.ArtifactIdToSpecNumber[item.id] then
468 item = Amr.ParseItemLink(GetInventoryItemLink("player", INVSLOT_OFFHAND))
469 if item and not Amr.ArtifactIdToSpecNumber[item.id] then
470 item = nil
471 end
472 end
473 if item then
474 Amr.GetItemInfo(item.id, function(customArg, name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture)
475 SaveEquipmentSet("AMR " .. specName, texture)
476 end)
477 end
478 end
479
448 -- find the first empty slot in the player's backpack+bags 480 -- find the first empty slot in the player's backpack+bags
449 local function findFirstEmptyBagSlot() 481 local function findFirstEmptyBagSlot()
450 482
451 local bagIds = {} 483 local bagIds = {}
452 table.insert(bagIds, BACKPACK_CONTAINER) 484 table.insert(bagIds, BACKPACK_CONTAINER)
582 end 614 end
583 end 615 end
584 616
585 end 617 end
586 618
619 local function removeNextItem()
620 if not _pendingRemove then return end
621
622 local list = _pendingRemove.slotsToRemove
623 local slot = list[#list - _pendingRemove.remaining + 1]
624
625 -- find first empty bag slot
626 local invBag, invSlot = findFirstEmptyBagSlot()
627 if not invBag then
628 -- stop if bags are too full
629 Amr:Print(L.GearEquipErrorBagFull)
630 _pendingRemove = nil
631 _pendingEquip = nil
632 return
633 end
634
635 PickupInventoryItem(slot)
636 PickupContainerItem(invBag, invSlot)
637
638 -- set flag so that when we clear cursor and release the item lock, we can respond to the event and continue
639 _waitingForItemLock = {
640 bagId = invBag,
641 slotId = invSlot,
642 isRemove = true
643 }
644
645 ClearCursor()
646 end
647
587 local function onItemUnlocked(bagId, slotId) 648 local function onItemUnlocked(bagId, slotId)
588 649
589 if _waitingForItemLock then 650 if _waitingForItemLock then
590 -- waiting on a move from bank to bags to complete, just continue as normal afterwards 651 -- waiting on a move from bank to bags to complete, or waiting on removing an item to complete, just continue as normal afterwards
591 if bagId == _waitingForItemLock.bagId and slotId == _waitingForItemLock.slotId then 652 if bagId == _waitingForItemLock.bagId and slotId == _waitingForItemLock.slotId then
653 local isremove = _waitingForItemLock.isRemove
592 _waitingForItemLock = nil 654 _waitingForItemLock = nil
593 tryEquipNextItem() 655
656 if isremove then
657 _pendingRemove.remaining = _pendingRemove.remaining - 1
658 if _pendingRemove.remaining > 0 then
659 removeNextItem()
660 else
661 -- we have removed all items that we want to remove, now do the equip
662 _pendingRemove = nil
663 tryEquipNextItem()
664 end
665 else
666 tryEquipNextItem()
667 end
594 end 668 end
595 669
596 elseif _pendingEquip and _pendingEquip.destSlot then 670 elseif _pendingEquip and _pendingEquip.destSlot then
597 -- waiting on an item swap to complete successfully so that we can go on to the next item 671 -- waiting on an item swap to complete successfully so that we can go on to the next item
598 672
679 end 753 end
680 end 754 end
681 end 755 end
682 756
683 if remaining > 0 then 757 if remaining > 0 then
758 -- if this is not our first try, then remove weapons before starting
759 local toRemove = {}
760 local removesRemaining = 0
761 if _pendingEquip and _pendingEquip.tries > 0 then
762 for slotId, item in pairs(itemsToEquip) do
763 if slotId == 16 or slotId == 17 then
764 table.insert(toRemove, slotId)
765 removesRemaining = removesRemaining + 1
766 end
767 end
768 end
769
684 _pendingEquip = { 770 _pendingEquip = {
685 tries = _pendingEquip and _pendingEquip.spec == spec and _pendingEquip.tries or 0, 771 tries = _pendingEquip and _pendingEquip.spec == spec and _pendingEquip.tries or 0,
686 spec = spec, 772 spec = spec,
687 itemsToEquip = itemsToEquip, 773 itemsToEquip = itemsToEquip,
688 remaining = remaining, 774 remaining = remaining,
694 for slotId, item in pairs(_pendingEquip.itemsToEquip) do 780 for slotId, item in pairs(_pendingEquip.itemsToEquip) do
695 _pendingEquip.nextSlot = slotId 781 _pendingEquip.nextSlot = slotId
696 break 782 break
697 end 783 end
698 784
699 tryEquipNextItem() 785 if removesRemaining > 0 then
786 _pendingRemove = {
787 slotsToRemove = toRemove,
788 remaining = removesRemaining
789 }
790 removeNextItem()
791 else
792 tryEquipNextItem()
793 end
700 else 794 else
701 _pendingEquip = nil 795 _pendingEquip = nil
796 onEquipGearSetComplete()
702 end 797 end
703 end 798 end
704 799
705 local function onActiveTalentGroupChanged() 800 local function onActiveTalentGroupChanged()
706 801